/* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "host/libs/confui/host_renderer.h" #include "host/libs/config/cuttlefish_config.h" namespace cuttlefish { namespace confui { static teeui::Color alfaCombineChannel(std::uint32_t shift, double alfa, teeui::Color a, teeui::Color b) { a >>= shift; a &= 0xff; b >>= shift; b &= 0xff; double acc = alfa * a + (1 - alfa) * b; if (acc <= 0) return 0; std::uint32_t result = acc; if (result > 255) return 255 << shift; return result << shift; } std::unique_ptr ConfUiRenderer::GenerateRenderer( const std::uint32_t display, const std::string& confirmation_msg, const std::string& locale, const bool inverted, const bool magnified) { ConfUiRenderer* raw_ptr = new ConfUiRenderer(display, confirmation_msg, locale, inverted, magnified); if (raw_ptr && raw_ptr->IsSetUpSuccessful()) { return std::unique_ptr(raw_ptr); } return nullptr; } static int GetDpi(const int display_num = 0) { auto config = CuttlefishConfig::Get(); CHECK(config) << "Config is Missing"; auto display_configs = config->display_configs(); CHECK_GT(display_configs.size(), display_num) << "Invalid display number " << display_num; return display_configs[display_num].dpi; } /** * device configuration * * ctx_{# of pixels in 1 mm, # of pixels per 1 density independent pixels} * * The numbers are, however, to fit for the host webRTC local/remote clients * in general, not necessarily the supposedly guest device (e.g. Auto, phone, * etc) * * In general, for a normal PC, roughly ctx_(6.45211, 400.0/412.0) is a good * combination for the default DPI, 320. If we want to see the impact * of the change in the guest DPI, we could adjust the combination above * proportionally * */ ConfUiRenderer::ConfUiRenderer(const std::uint32_t display, const std::string& confirmation_msg, const std::string& locale, const bool inverted, const bool magnified) : display_num_{display}, lang_id_{locale}, prompt_text_{confirmation_msg}, current_height_{ScreenConnectorInfo::ScreenHeight(display_num_)}, current_width_{ScreenConnectorInfo::ScreenWidth(display_num_)}, is_inverted_(inverted), is_magnified_(magnified), ctx_(6.45211 * GetDpi() / 320.0, 400.0 / 412.0 * GetDpi() / 320.0), is_setup_well_(false) { SetDeviceContext(current_width_, current_height_, is_inverted_, is_magnified_); layout_ = teeui::instantiateLayout(teeui::ConfUILayout(), ctx_); if (auto error = UpdateLocale()) { ConfUiLog(ERROR) << "Update Translation Error: " << Enum2Base(error.code()); // is_setup_well_ = false; return; } UpdateColorScheme(is_inverted_); SetText(prompt_text_); is_setup_well_ = true; } teeui::Error ConfUiRenderer::UpdateLocale() { using teeui::Error; teeui::localization::selectLangId(lang_id_.c_str()); if (auto error = UpdateTranslations()) { return error; } return Error::OK; } template teeui::Error ConfUiRenderer::UpdateString() { using namespace teeui; const char* str; auto& label = std::get