• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 #pragma once
17 
18 #include <android-base/logging.h>
19 #include "common/libs/utils/result.h"
20 #include "host/frontend/webrtc/cvd_video_frame_buffer.h"
21 #include "host/frontend/webrtc/display_handler.h"
22 #include "host/frontend/webrtc/libdevice/video_sink.h"
23 #include "host/libs/screen_connector/screen_connector.h"
24 
25 namespace cuttlefish {
26 class DisplayHandler;
27 
28 class CompositionManager {
29  public:
30   struct DisplayOverlay {
31     int src_vm_index;
32     int src_display_index;
33   };
34 
35   ~CompositionManager();
36   static Result<std::unique_ptr<CompositionManager>> Create();
37 
38   void OnDisplayCreated(const DisplayCreatedEvent& event);
39   void OnFrame(std::uint32_t display_number, std::uint32_t frame_width,
40                std::uint32_t frame_height, std::uint32_t frame_fourcc_format,
41                std::uint32_t frame_stride_bytes, std::uint8_t* frame_pixels);
42 
43   void ComposeFrame(int display_index,
44                     std::shared_ptr<CvdVideoFrameBuffer> buffer);
45 
46  private:
47   explicit CompositionManager(
48       int cluster_index, std::string& group_uuid,
49       std::map<int, std::vector<DisplayOverlay>>& overlays);
50 
51   class LastFrameInfo {
52    public:
LastFrameInfo()53     LastFrameInfo() {}
LastFrameInfo(std::uint32_t display_number,std::uint32_t frame_width,std::uint32_t frame_height,std::uint32_t frame_fourcc_format,std::uint32_t frame_stride_bytes,std::uint8_t * frame_pixels)54     LastFrameInfo(std::uint32_t display_number, std::uint32_t frame_width,
55                   std::uint32_t frame_height, std::uint32_t frame_fourcc_format,
56                   std::uint32_t frame_stride_bytes,
57                   std::uint8_t* frame_pixels) {
58       display_number_ = display_number;
59       frame_width_ = frame_width;
60       frame_height_ = frame_height;
61       frame_fourcc_format_ = frame_fourcc_format;
62       frame_stride_bytes_ = frame_stride_bytes;
63       frame_pixels_ = frame_pixels;
64     }
65     std::uint32_t display_number_;
66     std::uint32_t frame_width_;
67     std::uint32_t frame_height_;
68     std::uint32_t frame_fourcc_format_;
69     std::uint32_t frame_stride_bytes_;
70     std::uint8_t* frame_pixels_;
71   };
72   static std::map<int, std::vector<CompositionManager::DisplayOverlay>>
73   ParseOverlays(std::vector<std::string> overlay_items);
74   std::uint8_t* AlphaBlendLayers(std::uint8_t* frame_pixels, int display,
75                                  int frame_width, int frame_height);
76   void ComposeFrame(int display, int width, int height,
77                     std::uint32_t frame_fourcc_format,
78                     std::uint32_t frame_stride_bytes,
79                     std::shared_ptr<CvdVideoFrameBuffer> buffer);
80   DisplayRingBufferManager display_ring_buffer_manager_;
81   int cluster_index_;
82   std::string group_uuid_;
83   std::map<int, std::vector<DisplayOverlay>> cfg_overlays_;
84   std::map<int, LastFrameInfo> last_frame_info_map_;
85   std::map<int, std::vector<std::uint8_t>> frame_work_buffer_;
86 };
87 
88 }  // namespace cuttlefish