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 "PowerAdvisor/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     // Size of the display in pixels
40     ui::Size pixels = ui::kInvalidSize;
41 
42     // True if this display should be considered secure
43     bool isSecure = false;
44 
45     // True if this display should be considered protected, as in this display should render DRM
46     // content.
47     bool isProtected = false;
48 
49     // True if this display has picture processing hardware and pipelines.
50     bool hasPictureProcessing = false;
51 
52     // The number of layer-specific picture-processing pipelines.
53     int32_t maxLayerPictureProfiles = 0;
54 
55     // Optional pointer to the power advisor interface, if one is needed for
56     // this display.
57     adpf::PowerAdvisor* powerAdvisor = nullptr;
58 
59     // Debugging. Human readable name for the display.
60     std::string name;
61 };
62 
63 /**
64  * A helper for setting up a DisplayCreationArgs value in-line.
65  * Prefer this builder over raw structure initialization.
66  */
67 class DisplayCreationArgsBuilder {
68 public:
build()69     DisplayCreationArgs build() { return std::move(mArgs); }
70 
setId(DisplayId id)71     DisplayCreationArgsBuilder& setId(DisplayId id) {
72         mArgs.id = id;
73         return *this;
74     }
75 
setPixels(ui::Size pixels)76     DisplayCreationArgsBuilder& setPixels(ui::Size pixels) {
77         mArgs.pixels = pixels;
78         return *this;
79     }
80 
setIsSecure(bool isSecure)81     DisplayCreationArgsBuilder& setIsSecure(bool isSecure) {
82         mArgs.isSecure = isSecure;
83         return *this;
84     }
85 
setIsProtected(bool isProtected)86     DisplayCreationArgsBuilder& setIsProtected(bool isProtected) {
87         mArgs.isProtected = isProtected;
88         return *this;
89     }
90 
setHasPictureProcessing(bool hasPictureProcessing)91     DisplayCreationArgsBuilder& setHasPictureProcessing(bool hasPictureProcessing) {
92         mArgs.hasPictureProcessing = hasPictureProcessing;
93         return *this;
94     }
95 
setMaxLayerPictureProfiles(int32_t maxLayerPictureProfiles)96     DisplayCreationArgsBuilder& setMaxLayerPictureProfiles(int32_t maxLayerPictureProfiles) {
97         mArgs.maxLayerPictureProfiles = maxLayerPictureProfiles;
98         return *this;
99     }
100 
setPowerAdvisor(adpf::PowerAdvisor * powerAdvisor)101     DisplayCreationArgsBuilder& setPowerAdvisor(adpf::PowerAdvisor* powerAdvisor) {
102         mArgs.powerAdvisor = powerAdvisor;
103         return *this;
104     }
105 
setName(std::string name)106     DisplayCreationArgsBuilder& setName(std::string name) {
107         mArgs.name = std::move(name);
108         return *this;
109     }
110 
111 private:
112     DisplayCreationArgs mArgs;
113 };
114 
115 } // namespace android::compositionengine
116