1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright 2016 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #pragma once 18*38e8c45fSAndroid Build Coastguard Worker 19*38e8c45fSAndroid Build Coastguard Worker #include "ComposerHal.h" 20*38e8c45fSAndroid Build Coastguard Worker 21*38e8c45fSAndroid Build Coastguard Worker #include <optional> 22*38e8c45fSAndroid Build Coastguard Worker #include <string> 23*38e8c45fSAndroid Build Coastguard Worker #include <unordered_map> 24*38e8c45fSAndroid Build Coastguard Worker #include <utility> 25*38e8c45fSAndroid Build Coastguard Worker #include <vector> 26*38e8c45fSAndroid Build Coastguard Worker 27*38e8c45fSAndroid Build Coastguard Worker // TODO(b/129481165): remove the #pragma below and fix conversion issues 28*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic push 29*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic ignored "-Wconversion" 30*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic ignored "-Wextra" 31*38e8c45fSAndroid Build Coastguard Worker 32*38e8c45fSAndroid Build Coastguard Worker #include <composer-command-buffer/2.4/ComposerCommandBuffer.h> 33*38e8c45fSAndroid Build Coastguard Worker #include <gui/BufferQueue.h> 34*38e8c45fSAndroid Build Coastguard Worker #include <gui/HdrMetadata.h> 35*38e8c45fSAndroid Build Coastguard Worker #include <math/mat4.h> 36*38e8c45fSAndroid Build Coastguard Worker #include <ui/DisplayedFrameStats.h> 37*38e8c45fSAndroid Build Coastguard Worker #include <ui/GraphicBuffer.h> 38*38e8c45fSAndroid Build Coastguard Worker #include <utils/StrongPointer.h> 39*38e8c45fSAndroid Build Coastguard Worker 40*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/Composition.h> 41*38e8c45fSAndroid Build Coastguard Worker 42*38e8c45fSAndroid Build Coastguard Worker // TODO(b/129481165): remove the #pragma below and fix conversion issues 43*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" 44*38e8c45fSAndroid Build Coastguard Worker 45*38e8c45fSAndroid Build Coastguard Worker namespace android::Hwc2 { 46*38e8c45fSAndroid Build Coastguard Worker 47*38e8c45fSAndroid Build Coastguard Worker namespace types = hardware::graphics::common; 48*38e8c45fSAndroid Build Coastguard Worker 49*38e8c45fSAndroid Build Coastguard Worker namespace V2_1 = hardware::graphics::composer::V2_1; 50*38e8c45fSAndroid Build Coastguard Worker namespace V2_2 = hardware::graphics::composer::V2_2; 51*38e8c45fSAndroid Build Coastguard Worker namespace V2_3 = hardware::graphics::composer::V2_3; 52*38e8c45fSAndroid Build Coastguard Worker namespace V2_4 = hardware::graphics::composer::V2_4; 53*38e8c45fSAndroid Build Coastguard Worker 54*38e8c45fSAndroid Build Coastguard Worker using types::V1_0::ColorTransform; 55*38e8c45fSAndroid Build Coastguard Worker using types::V1_0::Transform; 56*38e8c45fSAndroid Build Coastguard Worker using types::V1_1::RenderIntent; 57*38e8c45fSAndroid Build Coastguard Worker using types::V1_2::ColorMode; 58*38e8c45fSAndroid Build Coastguard Worker using types::V1_2::Dataspace; 59*38e8c45fSAndroid Build Coastguard Worker using types::V1_2::PixelFormat; 60*38e8c45fSAndroid Build Coastguard Worker 61*38e8c45fSAndroid Build Coastguard Worker using V2_1::Config; 62*38e8c45fSAndroid Build Coastguard Worker using V2_1::Display; 63*38e8c45fSAndroid Build Coastguard Worker using V2_1::Layer; 64*38e8c45fSAndroid Build Coastguard Worker using V2_4::CommandReaderBase; 65*38e8c45fSAndroid Build Coastguard Worker using V2_4::CommandWriterBase; 66*38e8c45fSAndroid Build Coastguard Worker using V2_4::IComposer; 67*38e8c45fSAndroid Build Coastguard Worker using V2_4::IComposerCallback; 68*38e8c45fSAndroid Build Coastguard Worker using V2_4::IComposerClient; 69*38e8c45fSAndroid Build Coastguard Worker using V2_4::VsyncPeriodChangeTimeline; 70*38e8c45fSAndroid Build Coastguard Worker using V2_4::VsyncPeriodNanos; 71*38e8c45fSAndroid Build Coastguard Worker using PerFrameMetadata = IComposerClient::PerFrameMetadata; 72*38e8c45fSAndroid Build Coastguard Worker using PerFrameMetadataKey = IComposerClient::PerFrameMetadataKey; 73*38e8c45fSAndroid Build Coastguard Worker using PerFrameMetadataBlob = IComposerClient::PerFrameMetadataBlob; 74*38e8c45fSAndroid Build Coastguard Worker 75*38e8c45fSAndroid Build Coastguard Worker class CommandReader : public CommandReaderBase { 76*38e8c45fSAndroid Build Coastguard Worker public: 77*38e8c45fSAndroid Build Coastguard Worker ~CommandReader(); 78*38e8c45fSAndroid Build Coastguard Worker 79*38e8c45fSAndroid Build Coastguard Worker // Parse and execute commands from the command queue. The commands are 80*38e8c45fSAndroid Build Coastguard Worker // actually return values from the server and will be saved in ReturnData. 81*38e8c45fSAndroid Build Coastguard Worker Error parse(); 82*38e8c45fSAndroid Build Coastguard Worker 83*38e8c45fSAndroid Build Coastguard Worker // Get and clear saved errors. 84*38e8c45fSAndroid Build Coastguard Worker struct CommandError { 85*38e8c45fSAndroid Build Coastguard Worker uint32_t location; 86*38e8c45fSAndroid Build Coastguard Worker Error error; 87*38e8c45fSAndroid Build Coastguard Worker }; 88*38e8c45fSAndroid Build Coastguard Worker std::vector<CommandError> takeErrors(); 89*38e8c45fSAndroid Build Coastguard Worker 90*38e8c45fSAndroid Build Coastguard Worker bool hasChanges(Display display, uint32_t* outNumChangedCompositionTypes, 91*38e8c45fSAndroid Build Coastguard Worker uint32_t* outNumLayerRequestMasks) const; 92*38e8c45fSAndroid Build Coastguard Worker 93*38e8c45fSAndroid Build Coastguard Worker // Get and clear saved changed composition types. 94*38e8c45fSAndroid Build Coastguard Worker void takeChangedCompositionTypes( 95*38e8c45fSAndroid Build Coastguard Worker Display display, std::vector<Layer>* outLayers, 96*38e8c45fSAndroid Build Coastguard Worker std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes); 97*38e8c45fSAndroid Build Coastguard Worker 98*38e8c45fSAndroid Build Coastguard Worker // Get and clear saved display requests. 99*38e8c45fSAndroid Build Coastguard Worker void takeDisplayRequests(Display display, uint32_t* outDisplayRequestMask, 100*38e8c45fSAndroid Build Coastguard Worker std::vector<Layer>* outLayers, 101*38e8c45fSAndroid Build Coastguard Worker std::vector<uint32_t>* outLayerRequestMasks); 102*38e8c45fSAndroid Build Coastguard Worker 103*38e8c45fSAndroid Build Coastguard Worker // Get and clear saved release fences. 104*38e8c45fSAndroid Build Coastguard Worker void takeReleaseFences(Display display, std::vector<Layer>* outLayers, 105*38e8c45fSAndroid Build Coastguard Worker std::vector<int>* outReleaseFences); 106*38e8c45fSAndroid Build Coastguard Worker 107*38e8c45fSAndroid Build Coastguard Worker // Get and clear saved present fence. 108*38e8c45fSAndroid Build Coastguard Worker void takePresentFence(Display display, int* outPresentFence); 109*38e8c45fSAndroid Build Coastguard Worker 110*38e8c45fSAndroid Build Coastguard Worker // Get what stage succeeded during PresentOrValidate: Present or Validate 111*38e8c45fSAndroid Build Coastguard Worker void takePresentOrValidateStage(Display display, uint32_t* state); 112*38e8c45fSAndroid Build Coastguard Worker 113*38e8c45fSAndroid Build Coastguard Worker // Get the client target properties requested by hardware composer. 114*38e8c45fSAndroid Build Coastguard Worker void takeClientTargetProperty(Display display, 115*38e8c45fSAndroid Build Coastguard Worker IComposerClient::ClientTargetProperty* outClientTargetProperty); 116*38e8c45fSAndroid Build Coastguard Worker 117*38e8c45fSAndroid Build Coastguard Worker private: 118*38e8c45fSAndroid Build Coastguard Worker void resetData(); 119*38e8c45fSAndroid Build Coastguard Worker 120*38e8c45fSAndroid Build Coastguard Worker bool parseSelectDisplay(uint16_t length); 121*38e8c45fSAndroid Build Coastguard Worker bool parseSetError(uint16_t length); 122*38e8c45fSAndroid Build Coastguard Worker bool parseSetChangedCompositionTypes(uint16_t length); 123*38e8c45fSAndroid Build Coastguard Worker bool parseSetDisplayRequests(uint16_t length); 124*38e8c45fSAndroid Build Coastguard Worker bool parseSetPresentFence(uint16_t length); 125*38e8c45fSAndroid Build Coastguard Worker bool parseSetReleaseFences(uint16_t length); 126*38e8c45fSAndroid Build Coastguard Worker bool parseSetPresentOrValidateDisplayResult(uint16_t length); 127*38e8c45fSAndroid Build Coastguard Worker bool parseSetClientTargetProperty(uint16_t length); 128*38e8c45fSAndroid Build Coastguard Worker 129*38e8c45fSAndroid Build Coastguard Worker struct ReturnData { 130*38e8c45fSAndroid Build Coastguard Worker uint32_t displayRequests = 0; 131*38e8c45fSAndroid Build Coastguard Worker 132*38e8c45fSAndroid Build Coastguard Worker std::vector<Layer> changedLayers; 133*38e8c45fSAndroid Build Coastguard Worker std::vector<aidl::android::hardware::graphics::composer3::Composition> compositionTypes; 134*38e8c45fSAndroid Build Coastguard Worker 135*38e8c45fSAndroid Build Coastguard Worker std::vector<Layer> requestedLayers; 136*38e8c45fSAndroid Build Coastguard Worker std::vector<uint32_t> requestMasks; 137*38e8c45fSAndroid Build Coastguard Worker 138*38e8c45fSAndroid Build Coastguard Worker int presentFence = -1; 139*38e8c45fSAndroid Build Coastguard Worker 140*38e8c45fSAndroid Build Coastguard Worker std::vector<Layer> releasedLayers; 141*38e8c45fSAndroid Build Coastguard Worker std::vector<int> releaseFences; 142*38e8c45fSAndroid Build Coastguard Worker 143*38e8c45fSAndroid Build Coastguard Worker uint32_t presentOrValidateState; 144*38e8c45fSAndroid Build Coastguard Worker 145*38e8c45fSAndroid Build Coastguard Worker // Composer 2.4 implementation can return a client target property 146*38e8c45fSAndroid Build Coastguard Worker // structure to indicate the client target properties that hardware 147*38e8c45fSAndroid Build Coastguard Worker // composer requests. The composer client must change the client target 148*38e8c45fSAndroid Build Coastguard Worker // properties to match this request. 149*38e8c45fSAndroid Build Coastguard Worker IComposerClient::ClientTargetProperty clientTargetProperty{PixelFormat::RGBA_8888, 150*38e8c45fSAndroid Build Coastguard Worker Dataspace::UNKNOWN}; 151*38e8c45fSAndroid Build Coastguard Worker }; 152*38e8c45fSAndroid Build Coastguard Worker 153*38e8c45fSAndroid Build Coastguard Worker std::vector<CommandError> mErrors; 154*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<Display, ReturnData> mReturnData; 155*38e8c45fSAndroid Build Coastguard Worker 156*38e8c45fSAndroid Build Coastguard Worker // When SELECT_DISPLAY is parsed, this is updated to point to the 157*38e8c45fSAndroid Build Coastguard Worker // display's return data in mReturnData. We use it to avoid repeated 158*38e8c45fSAndroid Build Coastguard Worker // map lookups. 159*38e8c45fSAndroid Build Coastguard Worker ReturnData* mCurrentReturnData; 160*38e8c45fSAndroid Build Coastguard Worker }; 161*38e8c45fSAndroid Build Coastguard Worker 162*38e8c45fSAndroid Build Coastguard Worker // Composer is a wrapper to IComposer, a proxy to server-side composer. 163*38e8c45fSAndroid Build Coastguard Worker class HidlComposer final : public Composer { 164*38e8c45fSAndroid Build Coastguard Worker public: 165*38e8c45fSAndroid Build Coastguard Worker explicit HidlComposer(const std::string& serviceName); 166*38e8c45fSAndroid Build Coastguard Worker ~HidlComposer() override; 167*38e8c45fSAndroid Build Coastguard Worker 168*38e8c45fSAndroid Build Coastguard Worker bool isSupported(OptionalFeature) const; 169*38e8c45fSAndroid Build Coastguard Worker bool isVrrSupported() const; 170*38e8c45fSAndroid Build Coastguard Worker 171*38e8c45fSAndroid Build Coastguard Worker std::vector<aidl::android::hardware::graphics::composer3::Capability> getCapabilities() 172*38e8c45fSAndroid Build Coastguard Worker override; 173*38e8c45fSAndroid Build Coastguard Worker std::string dumpDebugInfo() override; 174*38e8c45fSAndroid Build Coastguard Worker 175*38e8c45fSAndroid Build Coastguard Worker void registerCallback(HWC2::ComposerCallback& callback) override; 176*38e8c45fSAndroid Build Coastguard Worker 177*38e8c45fSAndroid Build Coastguard Worker // Explicitly flush all pending commands in the command buffer. 178*38e8c45fSAndroid Build Coastguard Worker Error executeCommands(Display) override; 179*38e8c45fSAndroid Build Coastguard Worker 180*38e8c45fSAndroid Build Coastguard Worker uint32_t getMaxVirtualDisplayCount() override; 181*38e8c45fSAndroid Build Coastguard Worker Error createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format, 182*38e8c45fSAndroid Build Coastguard Worker Display* outDisplay) override; 183*38e8c45fSAndroid Build Coastguard Worker Error destroyVirtualDisplay(Display display) override; 184*38e8c45fSAndroid Build Coastguard Worker 185*38e8c45fSAndroid Build Coastguard Worker Error acceptDisplayChanges(Display display) override; 186*38e8c45fSAndroid Build Coastguard Worker 187*38e8c45fSAndroid Build Coastguard Worker Error createLayer(Display display, Layer* outLayer) override; 188*38e8c45fSAndroid Build Coastguard Worker Error destroyLayer(Display display, Layer layer) override; 189*38e8c45fSAndroid Build Coastguard Worker 190*38e8c45fSAndroid Build Coastguard Worker Error getActiveConfig(Display display, Config* outConfig) override; 191*38e8c45fSAndroid Build Coastguard Worker Error getChangedCompositionTypes( 192*38e8c45fSAndroid Build Coastguard Worker Display display, std::vector<Layer>* outLayers, 193*38e8c45fSAndroid Build Coastguard Worker std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) 194*38e8c45fSAndroid Build Coastguard Worker override; 195*38e8c45fSAndroid Build Coastguard Worker Error getColorModes(Display display, std::vector<ColorMode>* outModes) override; 196*38e8c45fSAndroid Build Coastguard Worker Error getDisplayAttribute(Display display, Config config, IComposerClient::Attribute attribute, 197*38e8c45fSAndroid Build Coastguard Worker int32_t* outValue) override; 198*38e8c45fSAndroid Build Coastguard Worker Error getDisplayConfigs(Display display, std::vector<Config>* outConfigs); 199*38e8c45fSAndroid Build Coastguard Worker Error getDisplayConfigurations(Display, int32_t maxFrameIntervalNs, 200*38e8c45fSAndroid Build Coastguard Worker std::vector<DisplayConfiguration>*); 201*38e8c45fSAndroid Build Coastguard Worker Error getDisplayName(Display display, std::string* outName) override; 202*38e8c45fSAndroid Build Coastguard Worker 203*38e8c45fSAndroid Build Coastguard Worker Error getDisplayRequests(Display display, uint32_t* outDisplayRequestMask, 204*38e8c45fSAndroid Build Coastguard Worker std::vector<Layer>* outLayers, 205*38e8c45fSAndroid Build Coastguard Worker std::vector<uint32_t>* outLayerRequestMasks) override; 206*38e8c45fSAndroid Build Coastguard Worker 207*38e8c45fSAndroid Build Coastguard Worker Error getDozeSupport(Display display, bool* outSupport) override; 208*38e8c45fSAndroid Build Coastguard Worker Error hasDisplayIdleTimerCapability(Display display, bool* outSupport) override; 209*38e8c45fSAndroid Build Coastguard Worker Error getHdrCapabilities(Display display, std::vector<Hdr>* outHdrTypes, float* outMaxLuminance, 210*38e8c45fSAndroid Build Coastguard Worker float* outMaxAverageLuminance, float* outMinLuminance) override; 211*38e8c45fSAndroid Build Coastguard Worker Error getOverlaySupport(aidl::android::hardware::graphics::composer3::OverlayProperties* 212*38e8c45fSAndroid Build Coastguard Worker outProperties) override; 213*38e8c45fSAndroid Build Coastguard Worker 214*38e8c45fSAndroid Build Coastguard Worker Error getReleaseFences(Display display, std::vector<Layer>* outLayers, 215*38e8c45fSAndroid Build Coastguard Worker std::vector<int>* outReleaseFences) override; 216*38e8c45fSAndroid Build Coastguard Worker 217*38e8c45fSAndroid Build Coastguard Worker Error presentDisplay(Display display, int* outPresentFence) override; 218*38e8c45fSAndroid Build Coastguard Worker 219*38e8c45fSAndroid Build Coastguard Worker Error setActiveConfig(Display display, Config config) override; 220*38e8c45fSAndroid Build Coastguard Worker 221*38e8c45fSAndroid Build Coastguard Worker /* 222*38e8c45fSAndroid Build Coastguard Worker * The composer caches client targets internally. When target is nullptr, 223*38e8c45fSAndroid Build Coastguard Worker * the composer uses slot to look up the client target from its cache. 224*38e8c45fSAndroid Build Coastguard Worker * When target is not nullptr, the cache is updated with the new target. 225*38e8c45fSAndroid Build Coastguard Worker */ 226*38e8c45fSAndroid Build Coastguard Worker Error setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target, 227*38e8c45fSAndroid Build Coastguard Worker int acquireFence, Dataspace dataspace, 228*38e8c45fSAndroid Build Coastguard Worker const std::vector<IComposerClient::Rect>& damage, 229*38e8c45fSAndroid Build Coastguard Worker float hdrSdrRatio) override; 230*38e8c45fSAndroid Build Coastguard Worker Error setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) override; 231*38e8c45fSAndroid Build Coastguard Worker Error setColorTransform(Display display, const float* matrix) override; 232*38e8c45fSAndroid Build Coastguard Worker Error setOutputBuffer(Display display, const native_handle_t* buffer, 233*38e8c45fSAndroid Build Coastguard Worker int releaseFence) override; 234*38e8c45fSAndroid Build Coastguard Worker Error setPowerMode(Display display, IComposerClient::PowerMode mode) override; 235*38e8c45fSAndroid Build Coastguard Worker Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled) override; 236*38e8c45fSAndroid Build Coastguard Worker 237*38e8c45fSAndroid Build Coastguard Worker Error setClientTargetSlotCount(Display display) override; 238*38e8c45fSAndroid Build Coastguard Worker 239*38e8c45fSAndroid Build Coastguard Worker Error validateDisplay(Display display, nsecs_t expectedPresentTime, int32_t frameIntervalNs, 240*38e8c45fSAndroid Build Coastguard Worker uint32_t* outNumTypes, uint32_t* outNumRequests) override; 241*38e8c45fSAndroid Build Coastguard Worker 242*38e8c45fSAndroid Build Coastguard Worker Error presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime, 243*38e8c45fSAndroid Build Coastguard Worker int32_t frameIntervalNs, uint32_t* outNumTypes, 244*38e8c45fSAndroid Build Coastguard Worker uint32_t* outNumRequests, int* outPresentFence, 245*38e8c45fSAndroid Build Coastguard Worker uint32_t* state) override; 246*38e8c45fSAndroid Build Coastguard Worker 247*38e8c45fSAndroid Build Coastguard Worker Error setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) override; 248*38e8c45fSAndroid Build Coastguard Worker /* see setClientTarget for the purpose of slot */ 249*38e8c45fSAndroid Build Coastguard Worker Error setLayerBuffer(Display display, Layer layer, uint32_t slot, 250*38e8c45fSAndroid Build Coastguard Worker const sp<GraphicBuffer>& buffer, int acquireFence) override; 251*38e8c45fSAndroid Build Coastguard Worker Error setLayerBufferSlotsToClear(Display display, Layer layer, 252*38e8c45fSAndroid Build Coastguard Worker const std::vector<uint32_t>& slotsToClear, 253*38e8c45fSAndroid Build Coastguard Worker uint32_t activeBufferSlot) override; 254*38e8c45fSAndroid Build Coastguard Worker Error setLayerSurfaceDamage(Display display, Layer layer, 255*38e8c45fSAndroid Build Coastguard Worker const std::vector<IComposerClient::Rect>& damage) override; 256*38e8c45fSAndroid Build Coastguard Worker Error setLayerBlendMode(Display display, Layer layer, IComposerClient::BlendMode mode) override; 257*38e8c45fSAndroid Build Coastguard Worker Error setLayerColor(Display display, Layer layer, 258*38e8c45fSAndroid Build Coastguard Worker const aidl::android::hardware::graphics::composer3::Color& color) override; 259*38e8c45fSAndroid Build Coastguard Worker Error setLayerCompositionType( 260*38e8c45fSAndroid Build Coastguard Worker Display display, Layer layer, 261*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::Composition type) override; 262*38e8c45fSAndroid Build Coastguard Worker Error setLayerDataspace(Display display, Layer layer, Dataspace dataspace) override; 263*38e8c45fSAndroid Build Coastguard Worker Error setLayerDisplayFrame(Display display, Layer layer, 264*38e8c45fSAndroid Build Coastguard Worker const IComposerClient::Rect& frame) override; 265*38e8c45fSAndroid Build Coastguard Worker Error setLayerPlaneAlpha(Display display, Layer layer, float alpha) override; 266*38e8c45fSAndroid Build Coastguard Worker Error setLayerSidebandStream(Display display, Layer layer, 267*38e8c45fSAndroid Build Coastguard Worker const native_handle_t* stream) override; 268*38e8c45fSAndroid Build Coastguard Worker Error setLayerSourceCrop(Display display, Layer layer, 269*38e8c45fSAndroid Build Coastguard Worker const IComposerClient::FRect& crop) override; 270*38e8c45fSAndroid Build Coastguard Worker Error setLayerTransform(Display display, Layer layer, Transform transform) override; 271*38e8c45fSAndroid Build Coastguard Worker Error setLayerVisibleRegion(Display display, Layer layer, 272*38e8c45fSAndroid Build Coastguard Worker const std::vector<IComposerClient::Rect>& visible) override; 273*38e8c45fSAndroid Build Coastguard Worker Error setLayerZOrder(Display display, Layer layer, uint32_t z) override; 274*38e8c45fSAndroid Build Coastguard Worker 275*38e8c45fSAndroid Build Coastguard Worker // Composer HAL 2.2 276*38e8c45fSAndroid Build Coastguard Worker Error setLayerPerFrameMetadata( 277*38e8c45fSAndroid Build Coastguard Worker Display display, Layer layer, 278*38e8c45fSAndroid Build Coastguard Worker const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) override; 279*38e8c45fSAndroid Build Coastguard Worker std::vector<IComposerClient::PerFrameMetadataKey> getPerFrameMetadataKeys( 280*38e8c45fSAndroid Build Coastguard Worker Display display) override; 281*38e8c45fSAndroid Build Coastguard Worker Error getRenderIntents(Display display, ColorMode colorMode, 282*38e8c45fSAndroid Build Coastguard Worker std::vector<RenderIntent>* outRenderIntents) override; 283*38e8c45fSAndroid Build Coastguard Worker Error getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) override; 284*38e8c45fSAndroid Build Coastguard Worker 285*38e8c45fSAndroid Build Coastguard Worker // Composer HAL 2.3 286*38e8c45fSAndroid Build Coastguard Worker Error getDisplayIdentificationData(Display display, uint8_t* outPort, 287*38e8c45fSAndroid Build Coastguard Worker std::vector<uint8_t>* outData) override; 288*38e8c45fSAndroid Build Coastguard Worker Error setLayerColorTransform(Display display, Layer layer, const float* matrix) override; 289*38e8c45fSAndroid Build Coastguard Worker Error getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat, 290*38e8c45fSAndroid Build Coastguard Worker Dataspace* outDataspace, 291*38e8c45fSAndroid Build Coastguard Worker uint8_t* outComponentMask) override; 292*38e8c45fSAndroid Build Coastguard Worker Error setDisplayContentSamplingEnabled(Display display, bool enabled, uint8_t componentMask, 293*38e8c45fSAndroid Build Coastguard Worker uint64_t maxFrames) override; 294*38e8c45fSAndroid Build Coastguard Worker Error getDisplayedContentSample(Display display, uint64_t maxFrames, uint64_t timestamp, 295*38e8c45fSAndroid Build Coastguard Worker DisplayedFrameStats* outStats) override; 296*38e8c45fSAndroid Build Coastguard Worker Error setLayerPerFrameMetadataBlobs( 297*38e8c45fSAndroid Build Coastguard Worker Display display, Layer layer, 298*38e8c45fSAndroid Build Coastguard Worker const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) override; 299*38e8c45fSAndroid Build Coastguard Worker Error setDisplayBrightness(Display display, float brightness, float brightnessNits, 300*38e8c45fSAndroid Build Coastguard Worker const DisplayBrightnessOptions& options) override; 301*38e8c45fSAndroid Build Coastguard Worker 302*38e8c45fSAndroid Build Coastguard Worker // Composer HAL 2.4 303*38e8c45fSAndroid Build Coastguard Worker Error getDisplayCapabilities( 304*38e8c45fSAndroid Build Coastguard Worker Display display, 305*38e8c45fSAndroid Build Coastguard Worker std::vector<aidl::android::hardware::graphics::composer3::DisplayCapability>* 306*38e8c45fSAndroid Build Coastguard Worker outCapabilities) override; 307*38e8c45fSAndroid Build Coastguard Worker V2_4::Error getDisplayConnectionType(Display display, 308*38e8c45fSAndroid Build Coastguard Worker IComposerClient::DisplayConnectionType* outType) override; 309*38e8c45fSAndroid Build Coastguard Worker V2_4::Error getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) override; 310*38e8c45fSAndroid Build Coastguard Worker Error setActiveConfigWithConstraints( 311*38e8c45fSAndroid Build Coastguard Worker Display display, Config config, 312*38e8c45fSAndroid Build Coastguard Worker const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints, 313*38e8c45fSAndroid Build Coastguard Worker VsyncPeriodChangeTimeline* outTimeline) override; 314*38e8c45fSAndroid Build Coastguard Worker V2_4::Error setAutoLowLatencyMode(Display displayId, bool on) override; 315*38e8c45fSAndroid Build Coastguard Worker V2_4::Error getSupportedContentTypes( 316*38e8c45fSAndroid Build Coastguard Worker Display displayId, 317*38e8c45fSAndroid Build Coastguard Worker std::vector<IComposerClient::ContentType>* outSupportedContentTypes) override; 318*38e8c45fSAndroid Build Coastguard Worker V2_4::Error setContentType(Display displayId, 319*38e8c45fSAndroid Build Coastguard Worker IComposerClient::ContentType contentType) override; 320*38e8c45fSAndroid Build Coastguard Worker V2_4::Error setLayerGenericMetadata(Display display, Layer layer, const std::string& key, 321*38e8c45fSAndroid Build Coastguard Worker bool mandatory, const std::vector<uint8_t>& value) override; 322*38e8c45fSAndroid Build Coastguard Worker V2_4::Error getLayerGenericMetadataKeys( 323*38e8c45fSAndroid Build Coastguard Worker std::vector<IComposerClient::LayerGenericMetadataKey>* outKeys) override; 324*38e8c45fSAndroid Build Coastguard Worker Error getClientTargetProperty( 325*38e8c45fSAndroid Build Coastguard Worker Display display, 326*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness* 327*38e8c45fSAndroid Build Coastguard Worker outClientTargetProperty) override; 328*38e8c45fSAndroid Build Coastguard Worker 329*38e8c45fSAndroid Build Coastguard Worker // AIDL Composer HAL 330*38e8c45fSAndroid Build Coastguard Worker Error setLayerBrightness(Display display, Layer layer, float brightness) override; 331*38e8c45fSAndroid Build Coastguard Worker Error setLayerBlockingRegion(Display display, Layer layer, 332*38e8c45fSAndroid Build Coastguard Worker const std::vector<IComposerClient::Rect>& blocking) override; 333*38e8c45fSAndroid Build Coastguard Worker Error setBootDisplayConfig(Display displayId, Config) override; 334*38e8c45fSAndroid Build Coastguard Worker Error clearBootDisplayConfig(Display displayId) override; 335*38e8c45fSAndroid Build Coastguard Worker Error getPreferredBootDisplayConfig(Display displayId, Config*) override; 336*38e8c45fSAndroid Build Coastguard Worker Error getDisplayDecorationSupport( 337*38e8c45fSAndroid Build Coastguard Worker Display display, 338*38e8c45fSAndroid Build Coastguard Worker std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* 339*38e8c45fSAndroid Build Coastguard Worker support) override; 340*38e8c45fSAndroid Build Coastguard Worker Error setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) override; 341*38e8c45fSAndroid Build Coastguard Worker 342*38e8c45fSAndroid Build Coastguard Worker Error getPhysicalDisplayOrientation(Display displayId, 343*38e8c45fSAndroid Build Coastguard Worker AidlTransform* outDisplayOrientation) override; 344*38e8c45fSAndroid Build Coastguard Worker void onHotplugConnect(Display) override; 345*38e8c45fSAndroid Build Coastguard Worker void onHotplugDisconnect(Display) override; 346*38e8c45fSAndroid Build Coastguard Worker Error getHdrConversionCapabilities( 347*38e8c45fSAndroid Build Coastguard Worker std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability>*) 348*38e8c45fSAndroid Build Coastguard Worker override; 349*38e8c45fSAndroid Build Coastguard Worker Error setHdrConversionStrategy(aidl::android::hardware::graphics::common::HdrConversionStrategy, 350*38e8c45fSAndroid Build Coastguard Worker Hdr*) override; 351*38e8c45fSAndroid Build Coastguard Worker Error setRefreshRateChangedCallbackDebugEnabled(Display, bool) override; 352*38e8c45fSAndroid Build Coastguard Worker Error notifyExpectedPresent(Display, nsecs_t, int32_t) override; 353*38e8c45fSAndroid Build Coastguard Worker Error getRequestedLuts( 354*38e8c45fSAndroid Build Coastguard Worker Display, std::vector<Layer>*, 355*38e8c45fSAndroid Build Coastguard Worker std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>*) 356*38e8c45fSAndroid Build Coastguard Worker override; 357*38e8c45fSAndroid Build Coastguard Worker Error setLayerLuts(Display, Layer, 358*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::Luts&) override; 359*38e8c45fSAndroid Build Coastguard Worker Error getMaxLayerPictureProfiles(Display, int32_t* outMaxProfiles) override; 360*38e8c45fSAndroid Build Coastguard Worker Error setDisplayPictureProfileId(Display, PictureProfileId) override; 361*38e8c45fSAndroid Build Coastguard Worker Error setLayerPictureProfileId(Display, Layer, PictureProfileId) override; 362*38e8c45fSAndroid Build Coastguard Worker 363*38e8c45fSAndroid Build Coastguard Worker private: 364*38e8c45fSAndroid Build Coastguard Worker class CommandWriter : public CommandWriterBase { 365*38e8c45fSAndroid Build Coastguard Worker public: CommandWriter(uint32_t initialMaxSize)366*38e8c45fSAndroid Build Coastguard Worker explicit CommandWriter(uint32_t initialMaxSize) : CommandWriterBase(initialMaxSize) {} ~CommandWriter()367*38e8c45fSAndroid Build Coastguard Worker ~CommandWriter() override {} 368*38e8c45fSAndroid Build Coastguard Worker }; 369*38e8c45fSAndroid Build Coastguard Worker 370*38e8c45fSAndroid Build Coastguard Worker void registerCallback(const sp<IComposerCallback>& callback); 371*38e8c45fSAndroid Build Coastguard Worker 372*38e8c45fSAndroid Build Coastguard Worker // Many public functions above simply write a command into the command 373*38e8c45fSAndroid Build Coastguard Worker // queue to batch the calls. validateDisplay and presentDisplay will call 374*38e8c45fSAndroid Build Coastguard Worker // this function to execute the command queue. 375*38e8c45fSAndroid Build Coastguard Worker Error execute(); 376*38e8c45fSAndroid Build Coastguard Worker 377*38e8c45fSAndroid Build Coastguard Worker sp<V2_1::IComposer> mComposer; 378*38e8c45fSAndroid Build Coastguard Worker 379*38e8c45fSAndroid Build Coastguard Worker sp<V2_1::IComposerClient> mClient; 380*38e8c45fSAndroid Build Coastguard Worker sp<V2_2::IComposerClient> mClient_2_2; 381*38e8c45fSAndroid Build Coastguard Worker sp<V2_3::IComposerClient> mClient_2_3; 382*38e8c45fSAndroid Build Coastguard Worker sp<IComposerClient> mClient_2_4; 383*38e8c45fSAndroid Build Coastguard Worker 384*38e8c45fSAndroid Build Coastguard Worker // Buffer slots for layers are cleared by setting the slot buffer to this buffer. 385*38e8c45fSAndroid Build Coastguard Worker sp<GraphicBuffer> mClearSlotBuffer; 386*38e8c45fSAndroid Build Coastguard Worker 387*38e8c45fSAndroid Build Coastguard Worker // 64KiB minus a small space for metadata such as read/write pointers 388*38e8c45fSAndroid Build Coastguard Worker static constexpr size_t kWriterInitialSize = 64 * 1024 / sizeof(uint32_t) - 16; 389*38e8c45fSAndroid Build Coastguard Worker // Max number of buffers that may be cached for a given layer 390*38e8c45fSAndroid Build Coastguard Worker // We obtain this number by: 391*38e8c45fSAndroid Build Coastguard Worker // 1. Tightly coupling this cache to the max size of BufferQueue 392*38e8c45fSAndroid Build Coastguard Worker // 2. Adding an additional slot for the layer caching feature in SurfaceFlinger (see: Planner.h) 393*38e8c45fSAndroid Build Coastguard Worker static const constexpr uint32_t kMaxLayerBufferCount = BufferQueue::NUM_BUFFER_SLOTS + 1; 394*38e8c45fSAndroid Build Coastguard Worker CommandWriter mWriter; 395*38e8c45fSAndroid Build Coastguard Worker CommandReader mReader; 396*38e8c45fSAndroid Build Coastguard Worker }; 397*38e8c45fSAndroid Build Coastguard Worker 398*38e8c45fSAndroid Build Coastguard Worker } // namespace android::Hwc2 399