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