• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "aidl/android/hardware/graphics/composer3/DimmingStage.h"
21 
22 #include <math/mat4.h>
23 #include <ui/FenceTime.h>
24 
25 // TODO(b/129481165): remove the #pragma below and fix conversion issues
26 #pragma clang diagnostic push
27 #pragma clang diagnostic ignored "-Wconversion"
28 #pragma clang diagnostic ignored "-Wextra"
29 
30 #include <ui/GraphicTypes.h>
31 
32 // TODO(b/129481165): remove the #pragma below and fix conversion issues
33 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
34 
35 #include <compositionengine/CompositionRefreshArgs.h>
36 #include <compositionengine/ProjectionSpace.h>
37 #include <ui/LayerStack.h>
38 #include <ui/Rect.h>
39 #include <ui/Region.h>
40 #include <ui/Transform.h>
41 
42 #include "DisplayHardware/HWComposer.h"
43 
44 namespace android {
45 
46 namespace compositionengine::impl {
47 
48 struct OutputCompositionState {
49     // If false, composition will not be performed for this display
50     bool isEnabled{false};
51 
52     // If false, this output is not considered secure
53     bool isSecure{false};
54 
55     // If false, this output is not considered protected
56     bool isProtected{false};
57 
58     // If true, the current frame on this output uses client composition
59     bool usesClientComposition{false};
60 
61     // If true, the current frame on this output uses device composition
62     bool usesDeviceComposition{false};
63 
64     // If true, the client target should be flipped when performing client composition
65     bool flipClientTarget{false};
66 
67     // If true, the current frame reused the buffer from a previous client composition
68     bool reusedClientComposition{false};
69 
70     // The conditions for including a layer on this output
71     ui::LayerFilter layerFilter;
72 
73     // The common space for all layers in the layer stack. layerStackSpace.content is the Rect
74     // which gets projected on the display. The orientation of this space is always ROTATION_0.
75     ProjectionSpace layerStackSpace;
76 
77     // Oriented physical display space. It will have the same size as displaySpace oriented to
78     // match the orientation of layerStackSpace. The orientation of this space is always ROTATION_0.
79     ProjectionSpace orientedDisplaySpace;
80 
81     // The space of the framebuffer. Its bounds match the size of the framebuffer and its
82     // orientation matches the orientation of the display. Typically the framebuffer space will
83     // be identical to the physical display space.
84     ProjectionSpace framebufferSpace;
85 
86     // The space of the physical display. It is as big as the currently active display mode. The
87     // content in this space can be rotated.
88     ProjectionSpace displaySpace;
89 
90     // Transformation from layerStackSpace to displaySpace
91     ui::Transform transform;
92 
93     // If true, RenderEngine filtering should be enabled
94     bool needsFiltering{false};
95 
96     // The logical coordinates for the dirty region for the display.
97     // dirtyRegion is semi-persistent state. Dirty rectangles are added to it
98     // by the FE until composition happens, at which point it is cleared.
99     Region dirtyRegion;
100 
101     // The logical coordinates for the undefined region for the display.
102     // The undefined region is internal to the composition engine. It is
103     // updated every time the geometry changes.
104     Region undefinedRegion;
105 
106     // True if the last composition frame had visible layers
107     bool lastCompositionHadVisibleLayers{false};
108 
109     // The color transform matrix to apply
110     mat4 colorTransformMatrix;
111 
112     // Current active color mode
113     ui::ColorMode colorMode{ui::ColorMode::NATIVE};
114 
115     // Current active render intent
116     ui::RenderIntent renderIntent{ui::RenderIntent::COLORIMETRIC};
117 
118     // Current active dataspace
119     ui::Dataspace dataspace{ui::Dataspace::UNKNOWN};
120 
121     std::optional<android::HWComposer::DeviceRequestedChanges> previousDeviceRequestedChanges{};
122 
123     bool previousDeviceRequestedSuccess = false;
124 
125     // Optional.
126     // The earliest time to send the present command to the HAL
127     std::optional<std::chrono::steady_clock::time_point> earliestPresentTime;
128 
129     // The expected time for the next present
130     nsecs_t expectedPresentTime{0};
131 
132     // The frameInterval for the next present
133     Fps frameInterval{};
134 
135     // Current display brightness
136     float displayBrightnessNits{-1.f};
137 
138     // SDR white point
139     float sdrWhitePointNits{-1.f};
140 
141     // Brightness of the client target, normalized to display brightness
142     float clientTargetBrightness{1.f};
143 
144     // Stage in which the client target should apply dimming
145     aidl::android::hardware::graphics::composer3::DimmingStage clientTargetDimmingStage{
146             aidl::android::hardware::graphics::composer3::DimmingStage::NONE};
147 
148     // Display brightness that will take effect this frame.
149     // This is slightly distinct from nits, in that nits cannot be passed to hw composer.
150     std::optional<float> displayBrightness = std::nullopt;
151 
152     enum class CompositionStrategyPredictionState : uint32_t {
153         // Composition strategy prediction did not run for this frame.
154         DISABLED = 0,
155         // Composition strategy predicted successfully for this frame.
156         SUCCESS = 1,
157         // Composition strategy prediction failed for this frame.
158         FAIL = 2,
159 
160         ftl_last = FAIL
161     };
162 
163     CompositionStrategyPredictionState strategyPrediction =
164             CompositionStrategyPredictionState::DISABLED;
165 
166     bool treat170mAsSrgb = false;
167 
168     uint64_t lastOutputLayerHash = 0;
169     uint64_t outputLayerHash = 0;
170 
171     ICEPowerCallback* powerCallback = nullptr;
172 
173     // Debugging
174     void dump(std::string& result) const;
175 };
176 
177 } // namespace compositionengine::impl
178 } // namespace android
179