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