1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <cstdint> 20 #include <functional> 21 #include <memory> 22 #include <string> 23 #include <tuple> 24 #include <vector> 25 26 #include <android-base/logging.h> 27 #include <freetype/ftglyph.h> // $(croot)/external/freetype 28 #include <fruit/fruit.h> 29 #include <teeui/utils.h> // $(croot)/system/teeui/libteeui/.../include 30 31 #include "common/libs/confui/confui.h" 32 #include "common/libs/utils/result.h" 33 #include "host/libs/confui/layouts/layout.h" 34 #include "host/libs/confui/server_common.h" 35 #include "host/libs/screen_connector/screen_connector.h" 36 37 namespace cuttlefish { 38 namespace confui { 39 class TeeUiFrameWrapper { 40 public: TeeUiFrameWrapper(const int w,const int h,const teeui::Color color)41 TeeUiFrameWrapper(const int w, const int h, const teeui::Color color) 42 : w_(w), h_(h), teeui_frame_(ScreenSizeInBytes(w, h), color) {} 43 TeeUiFrameWrapper() = delete; data()44 auto data() { return teeui_frame_.data(); } Width()45 int Width() const { return w_; } Height()46 int Height() const { return h_; } IsEmpty()47 bool IsEmpty() const { return teeui_frame_.empty(); } Size()48 auto Size() const { return teeui_frame_.size(); } 49 auto& operator[](const int idx) { return teeui_frame_[idx]; } ScreenStrideBytes()50 std::uint32_t ScreenStrideBytes() const { 51 return ScreenConnectorInfo::ComputeScreenStrideBytes(w_); 52 } 53 54 private: ScreenSizeInBytes(const int w,const int h)55 static std::uint32_t ScreenSizeInBytes(const int w, const int h) { 56 return ScreenConnectorInfo::ComputeScreenSizeInBytes(w, h); 57 } 58 59 int w_; 60 int h_; 61 TeeUiFrame teeui_frame_; 62 }; 63 64 class ConfUiRendererImpl; 65 class ConfUiRenderer { 66 public: 67 INJECT(ConfUiRenderer(ScreenConnectorFrameRenderer& screen_connector)); 68 ~ConfUiRenderer(); 69 Result<void> RenderDialog(const std::uint32_t display_num, 70 const std::string& prompt_text, 71 const std::string& locale, 72 const std::vector<teeui::UIOption>& ui_options); 73 bool IsInConfirm(const std::uint32_t x, const std::uint32_t y); 74 bool IsInCancel(const std::uint32_t x, const std::uint32_t y); 75 76 private: 77 bool IsInverted(const std::vector<teeui::UIOption>& ui_options) const; 78 bool IsMagnified(const std::vector<teeui::UIOption>& ui_options) const; 79 ScreenConnectorFrameRenderer& screen_connector_; 80 std::unique_ptr<ConfUiRendererImpl> renderer_impl_; 81 }; 82 83 } // end of namespace confui 84 } // end of namespace cuttlefish 85