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 <renderengine/BorderRenderInfo.h> 38 #include <ui/LayerStack.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 true, the current frame on this output uses client composition 57 bool usesClientComposition{false}; 58 59 // If true, the current frame on this output uses device composition 60 bool usesDeviceComposition{false}; 61 62 // If true, the client target should be flipped when performing client composition 63 bool flipClientTarget{false}; 64 65 // If true, the current frame reused the buffer from a previous client composition 66 bool reusedClientComposition{false}; 67 68 // The conditions for including a layer on this output 69 ui::LayerFilter layerFilter; 70 71 // The common space for all layers in the layer stack. layerStackSpace.content is the Rect 72 // which gets projected on the display. The orientation of this space is always ROTATION_0. 73 ProjectionSpace layerStackSpace; 74 75 // Oriented physical display space. It will have the same size as displaySpace oriented to 76 // match the orientation of layerStackSpace. The orientation of this space is always ROTATION_0. 77 ProjectionSpace orientedDisplaySpace; 78 79 // The space of the framebuffer. Its bounds match the size of the framebuffer and its 80 // orientation matches the orientation of the display. Typically the framebuffer space will 81 // be identical to the physical display space. 82 ProjectionSpace framebufferSpace; 83 84 // The space of the physical display. It is as big as the currently active display mode. The 85 // content in this space can be rotated. 86 ProjectionSpace displaySpace; 87 88 // Transformation from layerStackSpace to displaySpace 89 ui::Transform transform; 90 91 // If true, RenderEngine filtering should be enabled 92 bool needsFiltering{false}; 93 94 // The logical coordinates for the dirty region for the display. 95 // dirtyRegion is semi-persistent state. Dirty rectangles are added to it 96 // by the FE until composition happens, at which point it is cleared. 97 Region dirtyRegion; 98 99 // The logical coordinates for the undefined region for the display. 100 // The undefined region is internal to the composition engine. It is 101 // updated every time the geometry changes. 102 Region undefinedRegion; 103 104 // True if the last composition frame had visible layers 105 bool lastCompositionHadVisibleLayers{false}; 106 107 // The color transform matrix to apply 108 mat4 colorTransformMatrix; 109 110 // Current active color mode 111 ui::ColorMode colorMode{ui::ColorMode::NATIVE}; 112 113 // Current active render intent 114 ui::RenderIntent renderIntent{ui::RenderIntent::COLORIMETRIC}; 115 116 // Current active dataspace 117 ui::Dataspace dataspace{ui::Dataspace::UNKNOWN}; 118 119 // Current target dataspace 120 ui::Dataspace targetDataspace{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 // Current display brightness 134 float displayBrightnessNits{-1.f}; 135 136 // SDR white point 137 float sdrWhitePointNits{-1.f}; 138 139 // Brightness of the client target, normalized to display brightness 140 float clientTargetBrightness{1.f}; 141 142 // Stage in which the client target should apply dimming 143 aidl::android::hardware::graphics::composer3::DimmingStage clientTargetDimmingStage{ 144 aidl::android::hardware::graphics::composer3::DimmingStage::NONE}; 145 146 // Display brightness that will take effect this frame. 147 // This is slightly distinct from nits, in that nits cannot be passed to hw composer. 148 std::optional<float> displayBrightness = std::nullopt; 149 150 enum class CompositionStrategyPredictionState : uint32_t { 151 // Composition strategy prediction did not run for this frame. 152 DISABLED = 0, 153 // Composition strategy predicted successfully for this frame. 154 SUCCESS = 1, 155 // Composition strategy prediction failed for this frame. 156 FAIL = 2, 157 158 ftl_last = FAIL 159 }; 160 161 CompositionStrategyPredictionState strategyPrediction = 162 CompositionStrategyPredictionState::DISABLED; 163 164 bool treat170mAsSrgb = false; 165 166 std::vector<renderengine::BorderRenderInfo> borderInfoList; 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