1 /*
2  * Copyright 2019 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 <optional>
21 #include <string>
22 
23 #include <ui/DisplayInfo.h>
24 #include <ui/PixelFormat.h>
25 #include <ui/Size.h>
26 
27 #include "DisplayHardware/DisplayIdentification.h"
28 #include "DisplayHardware/PowerAdvisor.h"
29 
30 namespace android::compositionengine {
31 
32 class CompositionEngine;
33 
34 /**
35  * A parameter object for creating Display instances
36  */
37 struct DisplayCreationArgs {
38     struct Physical {
39         DisplayId id;
40         DisplayConnectionType type;
41     };
42 
43     // Required for physical displays. Gives the HWC display id for the existing
44     // display along with the connection type.
45     std::optional<Physical> physical;
46 
47     // Size of the display in pixels
48     ui::Size pixels = ui::Size::INVALID;
49 
50     // Pixel format of the display
51     ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN);
52 
53     // True if virtual displays should be created with the HWC API if possible
54     bool useHwcVirtualDisplays = false;
55 
56     // True if this display should be considered secure
57     bool isSecure = false;
58 
59     // Gives the initial layer stack id to be used for the display
60     uint32_t layerStackId = ~0u;
61 
62     // Optional pointer to the power advisor interface, if one is needed for
63     // this display.
64     Hwc2::PowerAdvisor* powerAdvisor = nullptr;
65 
66     // Debugging. Human readable name for the display.
67     std::string name;
68 };
69 
70 /**
71  * A helper for setting up a DisplayCreationArgs value in-line.
72  * Prefer this builder over raw structure initialization.
73  */
74 class DisplayCreationArgsBuilder {
75 public:
build()76     DisplayCreationArgs build() { return std::move(mArgs); }
77 
setPhysical(DisplayCreationArgs::Physical physical)78     DisplayCreationArgsBuilder& setPhysical(DisplayCreationArgs::Physical physical) {
79         mArgs.physical = physical;
80         return *this;
81     }
82 
setPixels(ui::Size pixels)83     DisplayCreationArgsBuilder& setPixels(ui::Size pixels) {
84         mArgs.pixels = pixels;
85         return *this;
86     }
87 
setPixelFormat(ui::PixelFormat pixelFormat)88     DisplayCreationArgsBuilder& setPixelFormat(ui::PixelFormat pixelFormat) {
89         mArgs.pixelFormat = pixelFormat;
90         return *this;
91     }
92 
setUseHwcVirtualDisplays(bool useHwcVirtualDisplays)93     DisplayCreationArgsBuilder& setUseHwcVirtualDisplays(bool useHwcVirtualDisplays) {
94         mArgs.useHwcVirtualDisplays = useHwcVirtualDisplays;
95         return *this;
96     }
97 
setIsSecure(bool isSecure)98     DisplayCreationArgsBuilder& setIsSecure(bool isSecure) {
99         mArgs.isSecure = isSecure;
100         return *this;
101     }
102 
setLayerStackId(uint32_t layerStackId)103     DisplayCreationArgsBuilder& setLayerStackId(uint32_t layerStackId) {
104         mArgs.layerStackId = layerStackId;
105         return *this;
106     }
107 
setPowerAdvisor(Hwc2::PowerAdvisor * powerAdvisor)108     DisplayCreationArgsBuilder& setPowerAdvisor(Hwc2::PowerAdvisor* powerAdvisor) {
109         mArgs.powerAdvisor = powerAdvisor;
110         return *this;
111     }
112 
setName(std::string name)113     DisplayCreationArgsBuilder& setName(std::string name) {
114         mArgs.name = std::move(name);
115         return *this;
116     }
117 
118 private:
119     DisplayCreationArgs mArgs;
120 };
121 
122 } // namespace android::compositionengine
123