1 /* 2 * Copyright 2016 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 <memory> 20 21 // TODO(b/129481165): remove the #pragma below and fix conversion issues 22 #pragma clang diagnostic push 23 #pragma clang diagnostic ignored "-Wconversion" 24 #pragma clang diagnostic ignored "-Wextra" 25 26 #include <composer-command-buffer/2.4/ComposerCommandBuffer.h> 27 #include <gui/BufferQueue.h> 28 #include <gui/HdrMetadata.h> 29 #include <math/mat4.h> 30 #include <ui/DisplayedFrameStats.h> 31 #include <ui/GraphicBuffer.h> 32 #include <utils/StrongPointer.h> 33 34 #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> 35 #include <aidl/android/hardware/graphics/composer3/Capability.h> 36 #include <aidl/android/hardware/graphics/composer3/ClientTargetPropertyWithBrightness.h> 37 #include <aidl/android/hardware/graphics/composer3/Color.h> 38 #include <aidl/android/hardware/graphics/composer3/Composition.h> 39 #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> 40 #include <aidl/android/hardware/graphics/composer3/IComposerCallback.h> 41 42 #include <aidl/android/hardware/graphics/common/Transform.h> 43 #include <optional> 44 45 // TODO(b/129481165): remove the #pragma below and fix conversion issues 46 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" 47 48 namespace android { 49 namespace HWC2 { 50 struct ComposerCallback; 51 } // namespace HWC2 52 53 namespace Hwc2 { 54 55 namespace types = hardware::graphics::common; 56 57 namespace V2_1 = hardware::graphics::composer::V2_1; 58 namespace V2_2 = hardware::graphics::composer::V2_2; 59 namespace V2_3 = hardware::graphics::composer::V2_3; 60 namespace V2_4 = hardware::graphics::composer::V2_4; 61 namespace V3_0 = ::aidl::android::hardware::graphics::composer3; 62 63 using types::V1_0::ColorTransform; 64 using types::V1_0::Transform; 65 using types::V1_1::RenderIntent; 66 using types::V1_2::ColorMode; 67 using types::V1_2::Dataspace; 68 using types::V1_2::Hdr; 69 using types::V1_2::PixelFormat; 70 71 using V2_1::Config; 72 using V2_1::Display; 73 using V2_1::Error; 74 using V2_1::Layer; 75 using V2_4::CommandReaderBase; 76 using V2_4::CommandWriterBase; 77 using V2_4::IComposer; 78 using V2_4::IComposerCallback; 79 using V2_4::IComposerClient; 80 using V2_4::VsyncPeriodChangeTimeline; 81 using V2_4::VsyncPeriodNanos; 82 using PerFrameMetadata = IComposerClient::PerFrameMetadata; 83 using PerFrameMetadataKey = IComposerClient::PerFrameMetadataKey; 84 using PerFrameMetadataBlob = IComposerClient::PerFrameMetadataBlob; 85 using AidlTransform = ::aidl::android::hardware::graphics::common::Transform; 86 87 class Composer { 88 public: 89 static std::unique_ptr<Composer> create(const std::string& serviceName); 90 91 virtual ~Composer() = 0; 92 93 enum class OptionalFeature { 94 RefreshRateSwitching, 95 ExpectedPresentTime, 96 // Whether setDisplayBrightness is able to be applied as part of a display command. 97 DisplayBrightnessCommand, 98 KernelIdleTimer, 99 PhysicalDisplayOrientation, 100 }; 101 102 virtual bool isSupported(OptionalFeature) const = 0; 103 104 virtual std::vector<aidl::android::hardware::graphics::composer3::Capability> 105 getCapabilities() = 0; 106 virtual std::string dumpDebugInfo() = 0; 107 108 virtual void registerCallback(HWC2::ComposerCallback& callback) = 0; 109 110 // Reset all pending commands in the command buffer. Useful if you want to 111 // skip a frame but have already queued some commands. 112 virtual void resetCommands() = 0; 113 114 // Explicitly flush all pending commands in the command buffer. 115 virtual Error executeCommands() = 0; 116 117 virtual uint32_t getMaxVirtualDisplayCount() = 0; 118 virtual Error createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat*, 119 Display* outDisplay) = 0; 120 virtual Error destroyVirtualDisplay(Display display) = 0; 121 122 virtual Error acceptDisplayChanges(Display display) = 0; 123 124 virtual Error createLayer(Display display, Layer* outLayer) = 0; 125 virtual Error destroyLayer(Display display, Layer layer) = 0; 126 127 virtual Error getActiveConfig(Display display, Config* outConfig) = 0; 128 virtual Error getChangedCompositionTypes(Display display, std::vector<Layer>* outLayers, 129 std::vector<V3_0::Composition>* outTypes) = 0; 130 virtual Error getColorModes(Display display, std::vector<ColorMode>* outModes) = 0; 131 virtual Error getDisplayAttribute(Display display, Config config, 132 IComposerClient::Attribute attribute, int32_t* outValue) = 0; 133 virtual Error getDisplayConfigs(Display display, std::vector<Config>* outConfigs) = 0; 134 virtual Error getDisplayName(Display display, std::string* outName) = 0; 135 136 virtual Error getDisplayRequests(Display display, uint32_t* outDisplayRequestMask, 137 std::vector<Layer>* outLayers, 138 std::vector<uint32_t>* outLayerRequestMasks) = 0; 139 140 virtual Error getDozeSupport(Display display, bool* outSupport) = 0; 141 virtual Error hasDisplayIdleTimerCapability(Display display, bool* outSupport) = 0; 142 virtual Error getHdrCapabilities(Display display, std::vector<Hdr>* outTypes, 143 float* outMaxLuminance, float* outMaxAverageLuminance, 144 float* outMinLuminance) = 0; 145 146 virtual Error getReleaseFences(Display display, std::vector<Layer>* outLayers, 147 std::vector<int>* outReleaseFences) = 0; 148 149 virtual Error presentDisplay(Display display, int* outPresentFence) = 0; 150 151 virtual Error setActiveConfig(Display display, Config config) = 0; 152 153 /* 154 * The composer caches client targets internally. When target is nullptr, 155 * the composer uses slot to look up the client target from its cache. 156 * When target is not nullptr, the cache is updated with the new target. 157 */ 158 virtual Error setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target, 159 int acquireFence, Dataspace dataspace, 160 const std::vector<IComposerClient::Rect>& damage) = 0; 161 virtual Error setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) = 0; 162 virtual Error setColorTransform(Display display, const float* matrix) = 0; 163 virtual Error setOutputBuffer(Display display, const native_handle_t* buffer, 164 int releaseFence) = 0; 165 virtual Error setPowerMode(Display display, IComposerClient::PowerMode mode) = 0; 166 virtual Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled) = 0; 167 168 virtual Error setClientTargetSlotCount(Display display) = 0; 169 170 virtual Error validateDisplay(Display display, nsecs_t expectedPresentTime, 171 uint32_t* outNumTypes, uint32_t* outNumRequests) = 0; 172 173 virtual Error presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime, 174 uint32_t* outNumTypes, uint32_t* outNumRequests, 175 int* outPresentFence, uint32_t* state) = 0; 176 177 virtual Error setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) = 0; 178 /* see setClientTarget for the purpose of slot */ 179 virtual Error setLayerBuffer(Display display, Layer layer, uint32_t slot, 180 const sp<GraphicBuffer>& buffer, int acquireFence) = 0; 181 virtual Error setLayerSurfaceDamage(Display display, Layer layer, 182 const std::vector<IComposerClient::Rect>& damage) = 0; 183 virtual Error setLayerBlendMode(Display display, Layer layer, 184 IComposerClient::BlendMode mode) = 0; 185 virtual Error setLayerColor( 186 Display display, Layer layer, 187 const aidl::android::hardware::graphics::composer3::Color& color) = 0; 188 virtual Error setLayerCompositionType( 189 Display display, Layer layer, 190 aidl::android::hardware::graphics::composer3::Composition type) = 0; 191 virtual Error setLayerDataspace(Display display, Layer layer, Dataspace dataspace) = 0; 192 virtual Error setLayerDisplayFrame(Display display, Layer layer, 193 const IComposerClient::Rect& frame) = 0; 194 virtual Error setLayerPlaneAlpha(Display display, Layer layer, float alpha) = 0; 195 virtual Error setLayerSidebandStream(Display display, Layer layer, 196 const native_handle_t* stream) = 0; 197 virtual Error setLayerSourceCrop(Display display, Layer layer, 198 const IComposerClient::FRect& crop) = 0; 199 virtual Error setLayerTransform(Display display, Layer layer, Transform transform) = 0; 200 virtual Error setLayerVisibleRegion(Display display, Layer layer, 201 const std::vector<IComposerClient::Rect>& visible) = 0; 202 virtual Error setLayerZOrder(Display display, Layer layer, uint32_t z) = 0; 203 204 // Composer HAL 2.2 205 virtual Error setLayerPerFrameMetadata( 206 Display display, Layer layer, 207 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) = 0; 208 virtual std::vector<IComposerClient::PerFrameMetadataKey> getPerFrameMetadataKeys( 209 Display display) = 0; 210 virtual Error getRenderIntents(Display display, ColorMode colorMode, 211 std::vector<RenderIntent>* outRenderIntents) = 0; 212 virtual Error getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) = 0; 213 214 // Composer HAL 2.3 215 virtual Error getDisplayIdentificationData(Display display, uint8_t* outPort, 216 std::vector<uint8_t>* outData) = 0; 217 virtual Error setLayerColorTransform(Display display, Layer layer, 218 const float* matrix) = 0; 219 virtual Error getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat, 220 Dataspace* outDataspace, 221 uint8_t* outComponentMask) = 0; 222 virtual Error setDisplayContentSamplingEnabled(Display display, bool enabled, 223 uint8_t componentMask, uint64_t maxFrames) = 0; 224 virtual Error getDisplayedContentSample(Display display, uint64_t maxFrames, uint64_t timestamp, 225 DisplayedFrameStats* outStats) = 0; 226 virtual Error setLayerPerFrameMetadataBlobs( 227 Display display, Layer layer, const std::vector<PerFrameMetadataBlob>& metadata) = 0; 228 // Options for setting the display brightness 229 struct DisplayBrightnessOptions { 230 // If true, then immediately submits a brightness change request to composer. Otherwise, 231 // submission of the brightness change may be deferred until presenting the next frame. 232 // applyImmediately should only be false if OptionalFeature::DisplayBrightnessCommand is 233 // supported. 234 bool applyImmediately = true; 235 236 bool operator==(const DisplayBrightnessOptions& other) const { 237 return applyImmediately == other.applyImmediately; 238 } 239 }; 240 virtual Error setDisplayBrightness(Display display, float brightness, float brightnessNits, 241 const DisplayBrightnessOptions& options) = 0; 242 243 // Composer HAL 2.4 244 virtual Error getDisplayCapabilities(Display display, 245 std::vector<V3_0::DisplayCapability>* outCapabilities) = 0; 246 virtual V2_4::Error getDisplayConnectionType( 247 Display display, IComposerClient::DisplayConnectionType* outType) = 0; 248 virtual V2_4::Error getDisplayVsyncPeriod(Display display, 249 VsyncPeriodNanos* outVsyncPeriod) = 0; 250 virtual V2_4::Error setActiveConfigWithConstraints( 251 Display display, Config config, 252 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints, 253 VsyncPeriodChangeTimeline* outTimeline) = 0; 254 255 virtual V2_4::Error setAutoLowLatencyMode(Display displayId, bool on) = 0; 256 virtual V2_4::Error getSupportedContentTypes( 257 Display displayId, 258 std::vector<IComposerClient::ContentType>* outSupportedContentTypes) = 0; 259 virtual V2_4::Error setContentType(Display displayId, 260 IComposerClient::ContentType contentType) = 0; 261 virtual V2_4::Error setLayerGenericMetadata(Display display, Layer layer, 262 const std::string& key, bool mandatory, 263 const std::vector<uint8_t>& value) = 0; 264 virtual V2_4::Error getLayerGenericMetadataKeys( 265 std::vector<IComposerClient::LayerGenericMetadataKey>* outKeys) = 0; 266 267 virtual Error getClientTargetProperty( 268 Display display, V3_0::ClientTargetPropertyWithBrightness* outClientTargetProperty) = 0; 269 270 // AIDL Composer 271 virtual Error setLayerBrightness(Display display, Layer layer, float brightness) = 0; 272 virtual Error setLayerBlockingRegion(Display display, Layer layer, 273 const std::vector<IComposerClient::Rect>& blocking) = 0; 274 virtual Error setBootDisplayConfig(Display displayId, Config) = 0; 275 virtual Error clearBootDisplayConfig(Display displayId) = 0; 276 virtual Error getPreferredBootDisplayConfig(Display displayId, Config*) = 0; 277 virtual Error getDisplayDecorationSupport( 278 Display display, 279 std::optional<::aidl::android::hardware::graphics::common::DisplayDecorationSupport>* 280 support) = 0; 281 virtual Error setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) = 0; 282 virtual Error getPhysicalDisplayOrientation(Display displayId, 283 AidlTransform* outDisplayOrientation) = 0; 284 }; 285 286 } // namespace Hwc2 287 } // namespace android 288