• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 
22 #include <android-base/logging.h>
23 
24 #include "common/libs/utils/size_utils.h"
25 #include "host/libs/config/cuttlefish_config.h"
26 
27 namespace cuttlefish {
28 
29 template<typename T>
30 struct is_movable {
31   static constexpr const bool value =
32       std::is_move_constructible<T>::value &&
33       std::is_move_assignable<T>::value;
34 };
35 
36 // this callback type is going directly to socket-based or wayland ScreenConnector
37 using GenerateProcessedFrameCallbackImpl =
38     std::function<void(std::uint32_t /*display_number*/,      //
39                        std::uint32_t /*frame_width*/,         //
40                        std::uint32_t /*frame_height*/,        //
41                        std::uint32_t /*frame_stride_bytes*/,  //
42                        std::uint8_t* /*frame_pixels*/)>;
43 
44 struct ScreenConnectorInfo {
45   // functions are intended to be inlined
BytesPerPixelScreenConnectorInfo46   static constexpr std::uint32_t BytesPerPixel() { return 4; }
ScreenCountScreenConnectorInfo47   static std::uint32_t ScreenCount() {
48     auto config = ChkAndGetConfig();
49     auto display_configs = config->display_configs();
50     return static_cast<std::uint32_t>(display_configs.size());
51   }
ScreenHeightScreenConnectorInfo52   static std::uint32_t ScreenHeight(std::uint32_t display_number) {
53     auto config = ChkAndGetConfig();
54     auto display_configs = config->display_configs();
55     CHECK_GT(display_configs.size(), display_number);
56     return display_configs[display_number].height;
57   }
ScreenWidthScreenConnectorInfo58   static std::uint32_t ScreenWidth(std::uint32_t display_number) {
59     auto config = ChkAndGetConfig();
60     auto display_configs = config->display_configs();
61     CHECK_GE(display_configs.size(), display_number);
62     return display_configs[display_number].width;
63   }
ComputeScreenStrideBytesScreenConnectorInfo64   static std::uint32_t ComputeScreenStrideBytes(const std::uint32_t w) {
65     return AlignToPowerOf2(w * BytesPerPixel(), 4);
66   }
ComputeScreenSizeInBytesScreenConnectorInfo67   static std::uint32_t ComputeScreenSizeInBytes(const std::uint32_t w,
68                                                 const std::uint32_t h) {
69     return ComputeScreenStrideBytes(w) * h;
70   }
ScreenStrideBytesScreenConnectorInfo71   static std::uint32_t ScreenStrideBytes(const std::uint32_t display_number) {
72     return ComputeScreenStrideBytes(ScreenWidth(display_number));
73   }
ScreenSizeInBytesScreenConnectorInfo74   static std::uint32_t ScreenSizeInBytes(const std::uint32_t display_number) {
75     return ComputeScreenStrideBytes(ScreenWidth(display_number)) *
76            ScreenHeight(display_number);
77   }
78 
79  private:
80   static auto ChkAndGetConfig() -> decltype(cuttlefish::CuttlefishConfig::Get()) {
81     auto config = cuttlefish::CuttlefishConfig::Get();
82     CHECK(config) << "Config is Missing";
83     return config;
84   }
85 };
86 
87 struct ScreenConnectorFrameRenderer {
88   virtual bool RenderConfirmationUi(std::uint32_t display_number,
89                                     std::uint32_t frame_width,
90                                     std::uint32_t frame_height,
91                                     std::uint32_t frame_stride_bytes,
92                                     std::uint8_t* frame_bytes) = 0;
93   virtual bool IsCallbackSet() const = 0;
94   virtual ~ScreenConnectorFrameRenderer() = default;
95 };
96 
97 // this is inherited by the data type that represents the processed frame
98 // being moved around.
99 struct ScreenConnectorFrameInfo {
100   std::uint32_t display_number_;
101   bool is_success_;
102 };
103 
104 }  // namespace cuttlefish
105