• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ANDROID_HWC_COMPOSER_H
18 #define ANDROID_HWC_COMPOSER_H
19 
20 #include <functional>
21 #include <unordered_map>
22 #include <vector>
23 
24 #include "Common.h"
25 
26 namespace android {
27 class Device;
28 class Display;
29 
30 class Composer {
31  public:
~Composer()32   virtual ~Composer() {}
33 
34   using HotplugCallback = std::function<void(
35       bool /*connected*/, uint32_t /*id*/, uint32_t /*width*/,
36       uint32_t /*height*/, uint32_t /*dpiX*/, uint32_t /*dpiY*/,
37       uint32_t /*refreshRate*/)>;
38 
39   virtual HWC2::Error init(const HotplugCallback& cb) = 0;
40 
41   using AddDisplayToDeviceFunction =
42       std::function<HWC2::Error(std::unique_ptr<Display>)>;
43 
44   // Queries Cuttlefish/Goldfish/System configurations and creates displays
45   // for the given Device.
46   virtual HWC2::Error createDisplays(
47       Device* device,
48       const AddDisplayToDeviceFunction& addDisplayToDeviceFn) = 0;
49 
50   virtual HWC2::Error createDisplay(
51       Device* device, uint32_t displayId, uint32_t width, uint32_t height,
52       uint32_t dpiX, uint32_t dpiY, uint32_t refreshRateHz,
53       const AddDisplayToDeviceFunction& addDisplayToDeviceFn) = 0;
54 
55   virtual HWC2::Error onDisplayDestroy(Display* display) = 0;
56 
57   virtual HWC2::Error onDisplayClientTargetSet(Display* display) = 0;
58 
59   // Determines if this composer can compose the given layers and requests
60   // changes for layers that can't not be composed.
61   virtual HWC2::Error validateDisplay(
62       Display* display, std::unordered_map<hwc2_layer_t, HWC2::Composition>*
63                             outLayerCompositionChanges) = 0;
64 
65   // Performs the actual composition of layers and presents the composed result
66   // to the display.
67   virtual HWC2::Error presentDisplay(Display* display,
68                                      int32_t* outPresentFence) = 0;
69 };
70 
71 }  // namespace android
72 
73 #endif
74