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/DisplayId.h>
24 #include <ui/Size.h>
25 #include <ui/StaticDisplayInfo.h>
26 
27 #include "DisplayHardware/PowerAdvisor.h"
28 
29 namespace android::compositionengine {
30 
31 class CompositionEngine;
32 
33 /**
34  * A parameter object for creating Display instances
35  */
36 struct DisplayCreationArgs {
37     DisplayId id;
38 
39     // Unset for virtual displays
40     std::optional<ui::DisplayConnectionType> connectionType;
41 
42     // Size of the display in pixels
43     ui::Size pixels = ui::Size::INVALID;
44 
45     // True if this display should be considered secure
46     bool isSecure = false;
47 
48     // Gives the initial layer stack id to be used for the display
49     uint32_t layerStackId = ~0u;
50 
51     // Optional pointer to the power advisor interface, if one is needed for
52     // this display.
53     Hwc2::PowerAdvisor* powerAdvisor = nullptr;
54 
55     // Debugging. Human readable name for the display.
56     std::string name;
57 };
58 
59 /**
60  * A helper for setting up a DisplayCreationArgs value in-line.
61  * Prefer this builder over raw structure initialization.
62  */
63 class DisplayCreationArgsBuilder {
64 public:
build()65     DisplayCreationArgs build() { return std::move(mArgs); }
66 
setId(DisplayId id)67     DisplayCreationArgsBuilder& setId(DisplayId id) {
68         mArgs.id = id;
69         return *this;
70     }
71 
setConnectionType(ui::DisplayConnectionType connectionType)72     DisplayCreationArgsBuilder& setConnectionType(ui::DisplayConnectionType connectionType) {
73         mArgs.connectionType = connectionType;
74         return *this;
75     }
76 
setPixels(ui::Size pixels)77     DisplayCreationArgsBuilder& setPixels(ui::Size pixels) {
78         mArgs.pixels = pixels;
79         return *this;
80     }
81 
setIsSecure(bool isSecure)82     DisplayCreationArgsBuilder& setIsSecure(bool isSecure) {
83         mArgs.isSecure = isSecure;
84         return *this;
85     }
86 
setLayerStackId(uint32_t layerStackId)87     DisplayCreationArgsBuilder& setLayerStackId(uint32_t layerStackId) {
88         mArgs.layerStackId = layerStackId;
89         return *this;
90     }
91 
setPowerAdvisor(Hwc2::PowerAdvisor * powerAdvisor)92     DisplayCreationArgsBuilder& setPowerAdvisor(Hwc2::PowerAdvisor* powerAdvisor) {
93         mArgs.powerAdvisor = powerAdvisor;
94         return *this;
95     }
96 
setName(std::string name)97     DisplayCreationArgsBuilder& setName(std::string name) {
98         mArgs.name = std::move(name);
99         return *this;
100     }
101 
102 private:
103     DisplayCreationArgs mArgs;
104 };
105 
106 } // namespace android::compositionengine
107