1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2010 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 <cstdint> 20*38e8c45fSAndroid Build Coastguard Worker #include <memory> 21*38e8c45fSAndroid Build Coastguard Worker #include <mutex> 22*38e8c45fSAndroid Build Coastguard Worker #include <optional> 23*38e8c45fSAndroid Build Coastguard Worker #include <unordered_map> 24*38e8c45fSAndroid Build Coastguard Worker #include <unordered_set> 25*38e8c45fSAndroid Build Coastguard Worker #include <vector> 26*38e8c45fSAndroid Build Coastguard Worker 27*38e8c45fSAndroid Build Coastguard Worker #include <android-base/thread_annotations.h> 28*38e8c45fSAndroid Build Coastguard Worker #include <ftl/expected.h> 29*38e8c45fSAndroid Build Coastguard Worker #include <ftl/future.h> 30*38e8c45fSAndroid Build Coastguard Worker #include <ui/DisplayIdentification.h> 31*38e8c45fSAndroid Build Coastguard Worker #include <ui/FenceTime.h> 32*38e8c45fSAndroid Build Coastguard Worker #include <ui/PictureProfileHandle.h> 33*38e8c45fSAndroid Build Coastguard Worker 34*38e8c45fSAndroid Build Coastguard Worker // TODO(b/129481165): remove the #pragma below and fix conversion issues 35*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic push 36*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic ignored "-Wconversion" 37*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic ignored "-Wextra" 38*38e8c45fSAndroid Build Coastguard Worker #include <ui/GraphicTypes.h> 39*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" 40*38e8c45fSAndroid Build Coastguard Worker 41*38e8c45fSAndroid Build Coastguard Worker #include <utils/StrongPointer.h> 42*38e8c45fSAndroid Build Coastguard Worker #include <utils/Timers.h> 43*38e8c45fSAndroid Build Coastguard Worker 44*38e8c45fSAndroid Build Coastguard Worker #include "DisplayMode.h" 45*38e8c45fSAndroid Build Coastguard Worker #include "HWC2.h" 46*38e8c45fSAndroid Build Coastguard Worker #include "Hal.h" 47*38e8c45fSAndroid Build Coastguard Worker 48*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> 49*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/common/Hdr.h> 50*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/common/HdrConversionCapability.h> 51*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/common/HdrConversionStrategy.h> 52*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/Capability.h> 53*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/ClientTargetPropertyWithBrightness.h> 54*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/Composition.h> 55*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> 56*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/DisplayLuts.h> 57*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/LutProperties.h> 58*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/OutputType.h> 59*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/OverlayProperties.h> 60*38e8c45fSAndroid Build Coastguard Worker 61*38e8c45fSAndroid Build Coastguard Worker namespace android { 62*38e8c45fSAndroid Build Coastguard Worker 63*38e8c45fSAndroid Build Coastguard Worker namespace hal = hardware::graphics::composer::hal; 64*38e8c45fSAndroid Build Coastguard Worker 65*38e8c45fSAndroid Build Coastguard Worker struct DisplayedFrameStats; 66*38e8c45fSAndroid Build Coastguard Worker class GraphicBuffer; 67*38e8c45fSAndroid Build Coastguard Worker class TestableSurfaceFlinger; 68*38e8c45fSAndroid Build Coastguard Worker struct HWComposerTest; 69*38e8c45fSAndroid Build Coastguard Worker struct CompositionInfo; 70*38e8c45fSAndroid Build Coastguard Worker class PictureProfileHandle; 71*38e8c45fSAndroid Build Coastguard Worker 72*38e8c45fSAndroid Build Coastguard Worker namespace Hwc2 { 73*38e8c45fSAndroid Build Coastguard Worker class Composer; 74*38e8c45fSAndroid Build Coastguard Worker } // namespace Hwc2 75*38e8c45fSAndroid Build Coastguard Worker 76*38e8c45fSAndroid Build Coastguard Worker namespace compositionengine { 77*38e8c45fSAndroid Build Coastguard Worker class Output; 78*38e8c45fSAndroid Build Coastguard Worker } // namespace compositionengine 79*38e8c45fSAndroid Build Coastguard Worker 80*38e8c45fSAndroid Build Coastguard Worker struct KnownHWCGenericLayerMetadata { 81*38e8c45fSAndroid Build Coastguard Worker const char* name; 82*38e8c45fSAndroid Build Coastguard Worker const uint32_t id; 83*38e8c45fSAndroid Build Coastguard Worker }; 84*38e8c45fSAndroid Build Coastguard Worker 85*38e8c45fSAndroid Build Coastguard Worker // See the comment for SurfaceFlinger::getHwComposer for the thread safety rules for accessing 86*38e8c45fSAndroid Build Coastguard Worker // this class. 87*38e8c45fSAndroid Build Coastguard Worker class HWComposer { 88*38e8c45fSAndroid Build Coastguard Worker public: 89*38e8c45fSAndroid Build Coastguard Worker struct DeviceRequestedChanges { 90*38e8c45fSAndroid Build Coastguard Worker using ChangedTypes = 91*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<HWC2::Layer*, 92*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::Composition>; 93*38e8c45fSAndroid Build Coastguard Worker using ClientTargetProperty = 94*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness; 95*38e8c45fSAndroid Build Coastguard Worker using DisplayRequests = hal::DisplayRequest; 96*38e8c45fSAndroid Build Coastguard Worker using LayerRequests = std::unordered_map<HWC2::Layer*, hal::LayerRequest>; 97*38e8c45fSAndroid Build Coastguard Worker using LutProperties = aidl::android::hardware::graphics::composer3::LutProperties; 98*38e8c45fSAndroid Build Coastguard Worker using LayerLuts = HWC2::Display::LayerLuts; 99*38e8c45fSAndroid Build Coastguard Worker 100*38e8c45fSAndroid Build Coastguard Worker ChangedTypes changedTypes; 101*38e8c45fSAndroid Build Coastguard Worker DisplayRequests displayRequests; 102*38e8c45fSAndroid Build Coastguard Worker LayerRequests layerRequests; 103*38e8c45fSAndroid Build Coastguard Worker ClientTargetProperty clientTargetProperty; 104*38e8c45fSAndroid Build Coastguard Worker LayerLuts layerLuts; 105*38e8c45fSAndroid Build Coastguard Worker }; 106*38e8c45fSAndroid Build Coastguard Worker 107*38e8c45fSAndroid Build Coastguard Worker struct HWCDisplayMode { 108*38e8c45fSAndroid Build Coastguard Worker hal::HWConfigId hwcId; 109*38e8c45fSAndroid Build Coastguard Worker int32_t width = -1; 110*38e8c45fSAndroid Build Coastguard Worker int32_t height = -1; 111*38e8c45fSAndroid Build Coastguard Worker nsecs_t vsyncPeriod = -1; 112*38e8c45fSAndroid Build Coastguard Worker float dpiX = -1.f; 113*38e8c45fSAndroid Build Coastguard Worker float dpiY = -1.f; 114*38e8c45fSAndroid Build Coastguard Worker int32_t configGroup = -1; 115*38e8c45fSAndroid Build Coastguard Worker std::optional<hal::VrrConfig> vrrConfig; 116*38e8c45fSAndroid Build Coastguard Worker OutputType hdrOutputType; 117*38e8c45fSAndroid Build Coastguard Worker 118*38e8c45fSAndroid Build Coastguard Worker friend std::ostream& operator<<(std::ostream& os, const HWCDisplayMode& mode) { 119*38e8c45fSAndroid Build Coastguard Worker return os << "id=" << mode.hwcId << " res=" << mode.width << "x" << mode.height 120*38e8c45fSAndroid Build Coastguard Worker << " vsyncPeriod=" << mode.vsyncPeriod << " dpi=" << mode.dpiX << "x" 121*38e8c45fSAndroid Build Coastguard Worker << mode.dpiY << " group=" << mode.configGroup 122*38e8c45fSAndroid Build Coastguard Worker << " vrrConfig=" << to_string(mode.vrrConfig).c_str() 123*38e8c45fSAndroid Build Coastguard Worker << " hdrOutputType=" << toString(mode.hdrOutputType); 124*38e8c45fSAndroid Build Coastguard Worker } 125*38e8c45fSAndroid Build Coastguard Worker }; 126*38e8c45fSAndroid Build Coastguard Worker 127*38e8c45fSAndroid Build Coastguard Worker virtual ~HWComposer(); 128*38e8c45fSAndroid Build Coastguard Worker 129*38e8c45fSAndroid Build Coastguard Worker virtual void setCallback(HWC2::ComposerCallback&) = 0; 130*38e8c45fSAndroid Build Coastguard Worker 131*38e8c45fSAndroid Build Coastguard Worker virtual bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort, 132*38e8c45fSAndroid Build Coastguard Worker DisplayIdentificationData* outData) const = 0; 133*38e8c45fSAndroid Build Coastguard Worker 134*38e8c45fSAndroid Build Coastguard Worker virtual bool hasCapability(aidl::android::hardware::graphics::composer3::Capability) const = 0; 135*38e8c45fSAndroid Build Coastguard Worker virtual bool hasDisplayCapability( 136*38e8c45fSAndroid Build Coastguard Worker HalDisplayId, 137*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::DisplayCapability) const = 0; 138*38e8c45fSAndroid Build Coastguard Worker 139*38e8c45fSAndroid Build Coastguard Worker virtual size_t getMaxVirtualDisplayCount() const = 0; 140*38e8c45fSAndroid Build Coastguard Worker virtual size_t getMaxVirtualDisplayDimension() const = 0; 141*38e8c45fSAndroid Build Coastguard Worker 142*38e8c45fSAndroid Build Coastguard Worker // Attempts to allocate a virtual display on the HWC. The maximum number of virtual displays 143*38e8c45fSAndroid Build Coastguard Worker // supported by the HWC can be queried in advance, but allocation may fail for other reasons. 144*38e8c45fSAndroid Build Coastguard Worker virtual bool allocateVirtualDisplay(HalVirtualDisplayId, ui::Size, ui::PixelFormat*) = 0; 145*38e8c45fSAndroid Build Coastguard Worker 146*38e8c45fSAndroid Build Coastguard Worker virtual void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId, 147*38e8c45fSAndroid Build Coastguard Worker std::optional<ui::Size> physicalSize) = 0; 148*38e8c45fSAndroid Build Coastguard Worker 149*38e8c45fSAndroid Build Coastguard Worker // Attempts to create a new layer on this display 150*38e8c45fSAndroid Build Coastguard Worker virtual std::shared_ptr<HWC2::Layer> createLayer(HalDisplayId) = 0; 151*38e8c45fSAndroid Build Coastguard Worker 152*38e8c45fSAndroid Build Coastguard Worker // Gets any required composition change requests from the HWC device. 153*38e8c45fSAndroid Build Coastguard Worker // 154*38e8c45fSAndroid Build Coastguard Worker // Note that frameUsesClientComposition must be set correctly based on 155*38e8c45fSAndroid Build Coastguard Worker // whether the current frame appears to use client composition. If it is 156*38e8c45fSAndroid Build Coastguard Worker // false some internal optimizations are allowed to present the display 157*38e8c45fSAndroid Build Coastguard Worker // with fewer handshakes, but this does not work if client composition is 158*38e8c45fSAndroid Build Coastguard Worker // expected. 159*38e8c45fSAndroid Build Coastguard Worker virtual status_t getDeviceCompositionChanges( 160*38e8c45fSAndroid Build Coastguard Worker HalDisplayId, bool frameUsesClientComposition, 161*38e8c45fSAndroid Build Coastguard Worker std::optional<std::chrono::steady_clock::time_point> earliestPresentTime, 162*38e8c45fSAndroid Build Coastguard Worker nsecs_t expectedPresentTime, Fps frameInterval, 163*38e8c45fSAndroid Build Coastguard Worker std::optional<DeviceRequestedChanges>* outChanges) = 0; 164*38e8c45fSAndroid Build Coastguard Worker 165*38e8c45fSAndroid Build Coastguard Worker virtual status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence, 166*38e8c45fSAndroid Build Coastguard Worker const sp<GraphicBuffer>& target, ui::Dataspace, 167*38e8c45fSAndroid Build Coastguard Worker float hdrSdrRatio) = 0; 168*38e8c45fSAndroid Build Coastguard Worker 169*38e8c45fSAndroid Build Coastguard Worker // Present layers to the display and read releaseFences. 170*38e8c45fSAndroid Build Coastguard Worker virtual status_t presentAndGetReleaseFences( 171*38e8c45fSAndroid Build Coastguard Worker HalDisplayId, 172*38e8c45fSAndroid Build Coastguard Worker std::optional<std::chrono::steady_clock::time_point> earliestPresentTime) = 0; 173*38e8c45fSAndroid Build Coastguard Worker 174*38e8c45fSAndroid Build Coastguard Worker virtual status_t executeCommands(HalDisplayId) = 0; 175*38e8c45fSAndroid Build Coastguard Worker 176*38e8c45fSAndroid Build Coastguard Worker // set power mode 177*38e8c45fSAndroid Build Coastguard Worker virtual status_t setPowerMode(PhysicalDisplayId, hal::PowerMode) = 0; 178*38e8c45fSAndroid Build Coastguard Worker 179*38e8c45fSAndroid Build Coastguard Worker // Sets a color transform to be applied to the result of composition 180*38e8c45fSAndroid Build Coastguard Worker virtual status_t setColorTransform(HalDisplayId, const mat4& transform) = 0; 181*38e8c45fSAndroid Build Coastguard Worker 182*38e8c45fSAndroid Build Coastguard Worker // reset state when a display is disconnected 183*38e8c45fSAndroid Build Coastguard Worker virtual void disconnectDisplay(HalDisplayId) = 0; 184*38e8c45fSAndroid Build Coastguard Worker 185*38e8c45fSAndroid Build Coastguard Worker // Get the present fence/timestamp received from the last call to present. 186*38e8c45fSAndroid Build Coastguard Worker virtual sp<Fence> getPresentFence(HalDisplayId) const = 0; 187*38e8c45fSAndroid Build Coastguard Worker virtual nsecs_t getPresentTimestamp(PhysicalDisplayId) const = 0; 188*38e8c45fSAndroid Build Coastguard Worker 189*38e8c45fSAndroid Build Coastguard Worker // Get last release fence for the given layer 190*38e8c45fSAndroid Build Coastguard Worker virtual sp<Fence> getLayerReleaseFence(HalDisplayId, HWC2::Layer*) const = 0; 191*38e8c45fSAndroid Build Coastguard Worker 192*38e8c45fSAndroid Build Coastguard Worker // Set the output buffer and acquire fence for a virtual display. 193*38e8c45fSAndroid Build Coastguard Worker virtual status_t setOutputBuffer(HalVirtualDisplayId, const sp<Fence>& acquireFence, 194*38e8c45fSAndroid Build Coastguard Worker const sp<GraphicBuffer>& buffer) = 0; 195*38e8c45fSAndroid Build Coastguard Worker 196*38e8c45fSAndroid Build Coastguard Worker // After SurfaceFlinger has retrieved the release fences for all the frames, 197*38e8c45fSAndroid Build Coastguard Worker // it can call this to clear the shared pointers in the release fence map 198*38e8c45fSAndroid Build Coastguard Worker virtual void clearReleaseFences(HalDisplayId) = 0; 199*38e8c45fSAndroid Build Coastguard Worker 200*38e8c45fSAndroid Build Coastguard Worker // Fetches the HDR capabilities of the given display 201*38e8c45fSAndroid Build Coastguard Worker virtual status_t getHdrCapabilities(HalDisplayId, HdrCapabilities* outCapabilities) = 0; 202*38e8c45fSAndroid Build Coastguard Worker 203*38e8c45fSAndroid Build Coastguard Worker virtual const aidl::android::hardware::graphics::composer3::OverlayProperties& 204*38e8c45fSAndroid Build Coastguard Worker getOverlaySupport() const = 0; 205*38e8c45fSAndroid Build Coastguard Worker 206*38e8c45fSAndroid Build Coastguard Worker virtual int32_t getSupportedPerFrameMetadata(HalDisplayId) const = 0; 207*38e8c45fSAndroid Build Coastguard Worker 208*38e8c45fSAndroid Build Coastguard Worker // Returns the available RenderIntent of the given display. 209*38e8c45fSAndroid Build Coastguard Worker virtual std::vector<ui::RenderIntent> getRenderIntents(HalDisplayId, ui::ColorMode) const = 0; 210*38e8c45fSAndroid Build Coastguard Worker 211*38e8c45fSAndroid Build Coastguard Worker virtual mat4 getDataspaceSaturationMatrix(HalDisplayId, ui::Dataspace) = 0; 212*38e8c45fSAndroid Build Coastguard Worker 213*38e8c45fSAndroid Build Coastguard Worker // Returns the attributes of the color sampling engine. 214*38e8c45fSAndroid Build Coastguard Worker virtual status_t getDisplayedContentSamplingAttributes(HalDisplayId, ui::PixelFormat* outFormat, 215*38e8c45fSAndroid Build Coastguard Worker ui::Dataspace* outDataspace, 216*38e8c45fSAndroid Build Coastguard Worker uint8_t* outComponentMask) = 0; 217*38e8c45fSAndroid Build Coastguard Worker virtual status_t setDisplayContentSamplingEnabled(HalDisplayId, bool enabled, 218*38e8c45fSAndroid Build Coastguard Worker uint8_t componentMask, 219*38e8c45fSAndroid Build Coastguard Worker uint64_t maxFrames) = 0; 220*38e8c45fSAndroid Build Coastguard Worker virtual status_t getDisplayedContentSample(HalDisplayId, uint64_t maxFrames, uint64_t timestamp, 221*38e8c45fSAndroid Build Coastguard Worker DisplayedFrameStats* outStats) = 0; 222*38e8c45fSAndroid Build Coastguard Worker 223*38e8c45fSAndroid Build Coastguard Worker // Sets the brightness of a display. 224*38e8c45fSAndroid Build Coastguard Worker virtual ftl::Future<status_t> setDisplayBrightness( 225*38e8c45fSAndroid Build Coastguard Worker PhysicalDisplayId, float brightness, float brightnessNits, 226*38e8c45fSAndroid Build Coastguard Worker const Hwc2::Composer::DisplayBrightnessOptions&) = 0; 227*38e8c45fSAndroid Build Coastguard Worker 228*38e8c45fSAndroid Build Coastguard Worker // Get whether the display skipped validation on the latest present 229*38e8c45fSAndroid Build Coastguard Worker virtual bool getValidateSkipped(HalDisplayId displayId) const = 0; 230*38e8c45fSAndroid Build Coastguard Worker 231*38e8c45fSAndroid Build Coastguard Worker // Events handling --------------------------------------------------------- 232*38e8c45fSAndroid Build Coastguard Worker 233*38e8c45fSAndroid Build Coastguard Worker // Returns stable display ID (and display name on connection of new or previously disconnected 234*38e8c45fSAndroid Build Coastguard Worker // display), or std::nullopt if hotplug event was ignored. 235*38e8c45fSAndroid Build Coastguard Worker // This function is called from SurfaceFlinger. 236*38e8c45fSAndroid Build Coastguard Worker virtual std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId, 237*38e8c45fSAndroid Build Coastguard Worker hal::Connection) = 0; 238*38e8c45fSAndroid Build Coastguard Worker 239*38e8c45fSAndroid Build Coastguard Worker // If true we'll update the DeviceProductInfo on subsequent hotplug connected events. 240*38e8c45fSAndroid Build Coastguard Worker // TODO(b/157555476): Remove when the framework has proper support for headless mode 241*38e8c45fSAndroid Build Coastguard Worker virtual bool updatesDeviceProductInfoOnHotplugReconnect() const = 0; 242*38e8c45fSAndroid Build Coastguard Worker 243*38e8c45fSAndroid Build Coastguard Worker // Called when a vsync happens. If the vsync is valid, returns the 244*38e8c45fSAndroid Build Coastguard Worker // corresponding PhysicalDisplayId. Otherwise returns nullopt. 245*38e8c45fSAndroid Build Coastguard Worker virtual std::optional<PhysicalDisplayId> onVsync(hal::HWDisplayId, nsecs_t timestamp) = 0; 246*38e8c45fSAndroid Build Coastguard Worker 247*38e8c45fSAndroid Build Coastguard Worker virtual void setVsyncEnabled(PhysicalDisplayId, hal::Vsync enabled) = 0; 248*38e8c45fSAndroid Build Coastguard Worker 249*38e8c45fSAndroid Build Coastguard Worker virtual bool isConnected(PhysicalDisplayId) const = 0; 250*38e8c45fSAndroid Build Coastguard Worker 251*38e8c45fSAndroid Build Coastguard Worker virtual std::vector<HWCDisplayMode> getModes(PhysicalDisplayId, 252*38e8c45fSAndroid Build Coastguard Worker int32_t maxFrameIntervalNs) const = 0; 253*38e8c45fSAndroid Build Coastguard Worker 254*38e8c45fSAndroid Build Coastguard Worker virtual ftl::Expected<hal::HWConfigId, status_t> getActiveMode(PhysicalDisplayId) const = 0; 255*38e8c45fSAndroid Build Coastguard Worker 256*38e8c45fSAndroid Build Coastguard Worker virtual std::vector<ui::ColorMode> getColorModes(PhysicalDisplayId) const = 0; 257*38e8c45fSAndroid Build Coastguard Worker 258*38e8c45fSAndroid Build Coastguard Worker virtual status_t setActiveColorMode(PhysicalDisplayId, ui::ColorMode mode, 259*38e8c45fSAndroid Build Coastguard Worker ui::RenderIntent) = 0; 260*38e8c45fSAndroid Build Coastguard Worker 261*38e8c45fSAndroid Build Coastguard Worker // Composer 2.4 262*38e8c45fSAndroid Build Coastguard Worker virtual ui::DisplayConnectionType getDisplayConnectionType(PhysicalDisplayId) const = 0; 263*38e8c45fSAndroid Build Coastguard Worker virtual bool isVsyncPeriodSwitchSupported(PhysicalDisplayId) const = 0; 264*38e8c45fSAndroid Build Coastguard Worker virtual ftl::Expected<nsecs_t, status_t> getDisplayVsyncPeriod(PhysicalDisplayId) const = 0; 265*38e8c45fSAndroid Build Coastguard Worker virtual status_t setActiveModeWithConstraints(PhysicalDisplayId, hal::HWConfigId, 266*38e8c45fSAndroid Build Coastguard Worker const hal::VsyncPeriodChangeConstraints&, 267*38e8c45fSAndroid Build Coastguard Worker hal::VsyncPeriodChangeTimeline* outTimeline) = 0; 268*38e8c45fSAndroid Build Coastguard Worker virtual status_t setAutoLowLatencyMode(PhysicalDisplayId, bool on) = 0; 269*38e8c45fSAndroid Build Coastguard Worker virtual status_t getSupportedContentTypes( 270*38e8c45fSAndroid Build Coastguard Worker PhysicalDisplayId, std::vector<hal::ContentType>* outSupportedContentTypes) const = 0; 271*38e8c45fSAndroid Build Coastguard Worker supportsContentType(PhysicalDisplayId displayId,hal::ContentType type)272*38e8c45fSAndroid Build Coastguard Worker bool supportsContentType(PhysicalDisplayId displayId, hal::ContentType type) const { 273*38e8c45fSAndroid Build Coastguard Worker std::vector<hal::ContentType> types; 274*38e8c45fSAndroid Build Coastguard Worker return getSupportedContentTypes(displayId, &types) == NO_ERROR && 275*38e8c45fSAndroid Build Coastguard Worker std::find(types.begin(), types.end(), type) != types.end(); 276*38e8c45fSAndroid Build Coastguard Worker } 277*38e8c45fSAndroid Build Coastguard Worker 278*38e8c45fSAndroid Build Coastguard Worker virtual status_t setContentType(PhysicalDisplayId, hal::ContentType) = 0; 279*38e8c45fSAndroid Build Coastguard Worker 280*38e8c45fSAndroid Build Coastguard Worker virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() 281*38e8c45fSAndroid Build Coastguard Worker const = 0; 282*38e8c45fSAndroid Build Coastguard Worker 283*38e8c45fSAndroid Build Coastguard Worker virtual void dump(std::string& out) const = 0; 284*38e8c45fSAndroid Build Coastguard Worker 285*38e8c45fSAndroid Build Coastguard Worker virtual void dumpOverlayProperties(std::string& out) const = 0; 286*38e8c45fSAndroid Build Coastguard Worker 287*38e8c45fSAndroid Build Coastguard Worker virtual Hwc2::Composer* getComposer() const = 0; 288*38e8c45fSAndroid Build Coastguard Worker 289*38e8c45fSAndroid Build Coastguard Worker // Returns the first display connected at boot. Its connection via HWComposer::onHotplug, 290*38e8c45fSAndroid Build Coastguard Worker // which in practice is immediately after HWComposer construction, must occur before any 291*38e8c45fSAndroid Build Coastguard Worker // call to this function. 292*38e8c45fSAndroid Build Coastguard Worker // The primary display can be temporarily disconnected from the perspective 293*38e8c45fSAndroid Build Coastguard Worker // of this class. Callers must not call getPrimaryHwcDisplayId() or getPrimaryDisplayId() 294*38e8c45fSAndroid Build Coastguard Worker // if isHeadless(). 295*38e8c45fSAndroid Build Coastguard Worker // 296*38e8c45fSAndroid Build Coastguard Worker // TODO(b/182939859): Remove special cases for primary display. 297*38e8c45fSAndroid Build Coastguard Worker virtual hal::HWDisplayId getPrimaryHwcDisplayId() const = 0; 298*38e8c45fSAndroid Build Coastguard Worker virtual PhysicalDisplayId getPrimaryDisplayId() const = 0; 299*38e8c45fSAndroid Build Coastguard Worker virtual bool isHeadless() const = 0; 300*38e8c45fSAndroid Build Coastguard Worker 301*38e8c45fSAndroid Build Coastguard Worker virtual std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const = 0; 302*38e8c45fSAndroid Build Coastguard Worker virtual std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const = 0; 303*38e8c45fSAndroid Build Coastguard Worker 304*38e8c45fSAndroid Build Coastguard Worker // AIDL Composer 305*38e8c45fSAndroid Build Coastguard Worker virtual status_t setBootDisplayMode(PhysicalDisplayId, hal::HWConfigId) = 0; 306*38e8c45fSAndroid Build Coastguard Worker virtual status_t clearBootDisplayMode(PhysicalDisplayId) = 0; 307*38e8c45fSAndroid Build Coastguard Worker virtual std::optional<hal::HWConfigId> getPreferredBootDisplayMode(PhysicalDisplayId) = 0; 308*38e8c45fSAndroid Build Coastguard Worker virtual status_t getDisplayDecorationSupport( 309*38e8c45fSAndroid Build Coastguard Worker PhysicalDisplayId, 310*38e8c45fSAndroid Build Coastguard Worker std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* 311*38e8c45fSAndroid Build Coastguard Worker support) = 0; 312*38e8c45fSAndroid Build Coastguard Worker virtual status_t setIdleTimerEnabled(PhysicalDisplayId, std::chrono::milliseconds timeout) = 0; 313*38e8c45fSAndroid Build Coastguard Worker virtual bool hasDisplayIdleTimerCapability(PhysicalDisplayId) const = 0; 314*38e8c45fSAndroid Build Coastguard Worker virtual Hwc2::AidlTransform getPhysicalDisplayOrientation(PhysicalDisplayId) const = 0; 315*38e8c45fSAndroid Build Coastguard Worker virtual std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability> 316*38e8c45fSAndroid Build Coastguard Worker getHdrConversionCapabilities() const = 0; 317*38e8c45fSAndroid Build Coastguard Worker virtual status_t setHdrConversionStrategy( 318*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::common::HdrConversionStrategy, 319*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::common::Hdr*) = 0; 320*38e8c45fSAndroid Build Coastguard Worker virtual status_t setRefreshRateChangedCallbackDebugEnabled(PhysicalDisplayId, bool enabled) = 0; 321*38e8c45fSAndroid Build Coastguard Worker virtual status_t notifyExpectedPresent(PhysicalDisplayId, TimePoint expectedPresentTime, 322*38e8c45fSAndroid Build Coastguard Worker Fps frameInterval) = 0; 323*38e8c45fSAndroid Build Coastguard Worker virtual HWC2::Display::LutFileDescriptorMapper& getLutFileDescriptorMapper() = 0; 324*38e8c45fSAndroid Build Coastguard Worker virtual int32_t getMaxLayerPictureProfiles(PhysicalDisplayId) = 0; 325*38e8c45fSAndroid Build Coastguard Worker virtual status_t setDisplayPictureProfileHandle(PhysicalDisplayId, 326*38e8c45fSAndroid Build Coastguard Worker const PictureProfileHandle& handle) = 0; 327*38e8c45fSAndroid Build Coastguard Worker }; 328*38e8c45fSAndroid Build Coastguard Worker 329*38e8c45fSAndroid Build Coastguard Worker static inline bool operator==(const android::HWComposer::DeviceRequestedChanges& lhs, 330*38e8c45fSAndroid Build Coastguard Worker const android::HWComposer::DeviceRequestedChanges& rhs) { 331*38e8c45fSAndroid Build Coastguard Worker return lhs.changedTypes == rhs.changedTypes && lhs.displayRequests == rhs.displayRequests && 332*38e8c45fSAndroid Build Coastguard Worker lhs.layerRequests == rhs.layerRequests && 333*38e8c45fSAndroid Build Coastguard Worker lhs.clientTargetProperty == rhs.clientTargetProperty && lhs.layerLuts == rhs.layerLuts; 334*38e8c45fSAndroid Build Coastguard Worker } 335*38e8c45fSAndroid Build Coastguard Worker 336*38e8c45fSAndroid Build Coastguard Worker namespace impl { 337*38e8c45fSAndroid Build Coastguard Worker 338*38e8c45fSAndroid Build Coastguard Worker class HWComposer final : public android::HWComposer { 339*38e8c45fSAndroid Build Coastguard Worker public: 340*38e8c45fSAndroid Build Coastguard Worker explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer); 341*38e8c45fSAndroid Build Coastguard Worker explicit HWComposer(const std::string& composerServiceName); 342*38e8c45fSAndroid Build Coastguard Worker 343*38e8c45fSAndroid Build Coastguard Worker ~HWComposer() override; 344*38e8c45fSAndroid Build Coastguard Worker 345*38e8c45fSAndroid Build Coastguard Worker void setCallback(HWC2::ComposerCallback&) override; 346*38e8c45fSAndroid Build Coastguard Worker 347*38e8c45fSAndroid Build Coastguard Worker bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort, 348*38e8c45fSAndroid Build Coastguard Worker DisplayIdentificationData* outData) const override; 349*38e8c45fSAndroid Build Coastguard Worker 350*38e8c45fSAndroid Build Coastguard Worker bool hasCapability(aidl::android::hardware::graphics::composer3::Capability) const override; 351*38e8c45fSAndroid Build Coastguard Worker bool hasDisplayCapability( 352*38e8c45fSAndroid Build Coastguard Worker HalDisplayId, 353*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::DisplayCapability) const override; 354*38e8c45fSAndroid Build Coastguard Worker 355*38e8c45fSAndroid Build Coastguard Worker size_t getMaxVirtualDisplayCount() const override; 356*38e8c45fSAndroid Build Coastguard Worker size_t getMaxVirtualDisplayDimension() const override; 357*38e8c45fSAndroid Build Coastguard Worker 358*38e8c45fSAndroid Build Coastguard Worker bool allocateVirtualDisplay(HalVirtualDisplayId, ui::Size, ui::PixelFormat*) override; 359*38e8c45fSAndroid Build Coastguard Worker 360*38e8c45fSAndroid Build Coastguard Worker // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated. 361*38e8c45fSAndroid Build Coastguard Worker void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId, 362*38e8c45fSAndroid Build Coastguard Worker std::optional<ui::Size> physicalSize) override; 363*38e8c45fSAndroid Build Coastguard Worker 364*38e8c45fSAndroid Build Coastguard Worker // Attempts to create a new layer on this display 365*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<HWC2::Layer> createLayer(HalDisplayId) override; 366*38e8c45fSAndroid Build Coastguard Worker 367*38e8c45fSAndroid Build Coastguard Worker status_t getDeviceCompositionChanges( 368*38e8c45fSAndroid Build Coastguard Worker HalDisplayId, bool frameUsesClientComposition, 369*38e8c45fSAndroid Build Coastguard Worker std::optional<std::chrono::steady_clock::time_point> earliestPresentTime, 370*38e8c45fSAndroid Build Coastguard Worker nsecs_t expectedPresentTime, Fps frameInterval, 371*38e8c45fSAndroid Build Coastguard Worker std::optional<DeviceRequestedChanges>* outChanges) override; 372*38e8c45fSAndroid Build Coastguard Worker 373*38e8c45fSAndroid Build Coastguard Worker status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence, 374*38e8c45fSAndroid Build Coastguard Worker const sp<GraphicBuffer>& target, ui::Dataspace, 375*38e8c45fSAndroid Build Coastguard Worker float hdrSdrRatio) override; 376*38e8c45fSAndroid Build Coastguard Worker 377*38e8c45fSAndroid Build Coastguard Worker // Present layers to the display and read releaseFences. 378*38e8c45fSAndroid Build Coastguard Worker status_t presentAndGetReleaseFences( 379*38e8c45fSAndroid Build Coastguard Worker HalDisplayId, 380*38e8c45fSAndroid Build Coastguard Worker std::optional<std::chrono::steady_clock::time_point> earliestPresentTime) override; 381*38e8c45fSAndroid Build Coastguard Worker 382*38e8c45fSAndroid Build Coastguard Worker status_t executeCommands(HalDisplayId) override; 383*38e8c45fSAndroid Build Coastguard Worker 384*38e8c45fSAndroid Build Coastguard Worker // set power mode 385*38e8c45fSAndroid Build Coastguard Worker status_t setPowerMode(PhysicalDisplayId, hal::PowerMode mode) override; 386*38e8c45fSAndroid Build Coastguard Worker 387*38e8c45fSAndroid Build Coastguard Worker // Sets a color transform to be applied to the result of composition 388*38e8c45fSAndroid Build Coastguard Worker status_t setColorTransform(HalDisplayId, const mat4& transform) override; 389*38e8c45fSAndroid Build Coastguard Worker 390*38e8c45fSAndroid Build Coastguard Worker // reset state when a display is disconnected 391*38e8c45fSAndroid Build Coastguard Worker void disconnectDisplay(HalDisplayId) override; 392*38e8c45fSAndroid Build Coastguard Worker 393*38e8c45fSAndroid Build Coastguard Worker // Get the present fence/timestamp received from the last call to present. 394*38e8c45fSAndroid Build Coastguard Worker sp<Fence> getPresentFence(HalDisplayId) const override; 395*38e8c45fSAndroid Build Coastguard Worker nsecs_t getPresentTimestamp(PhysicalDisplayId) const override; 396*38e8c45fSAndroid Build Coastguard Worker 397*38e8c45fSAndroid Build Coastguard Worker // Get last release fence for the given layer 398*38e8c45fSAndroid Build Coastguard Worker sp<Fence> getLayerReleaseFence(HalDisplayId, HWC2::Layer*) const override; 399*38e8c45fSAndroid Build Coastguard Worker 400*38e8c45fSAndroid Build Coastguard Worker // Set the output buffer and acquire fence for a virtual display. 401*38e8c45fSAndroid Build Coastguard Worker status_t setOutputBuffer(HalVirtualDisplayId, const sp<Fence>& acquireFence, 402*38e8c45fSAndroid Build Coastguard Worker const sp<GraphicBuffer>& buffer) override; 403*38e8c45fSAndroid Build Coastguard Worker 404*38e8c45fSAndroid Build Coastguard Worker // After SurfaceFlinger has retrieved the release fences for all the frames, 405*38e8c45fSAndroid Build Coastguard Worker // it can call this to clear the shared pointers in the release fence map 406*38e8c45fSAndroid Build Coastguard Worker void clearReleaseFences(HalDisplayId) override; 407*38e8c45fSAndroid Build Coastguard Worker 408*38e8c45fSAndroid Build Coastguard Worker // Fetches the HDR capabilities of the given display 409*38e8c45fSAndroid Build Coastguard Worker status_t getHdrCapabilities(HalDisplayId, HdrCapabilities* outCapabilities) override; 410*38e8c45fSAndroid Build Coastguard Worker 411*38e8c45fSAndroid Build Coastguard Worker const aidl::android::hardware::graphics::composer3::OverlayProperties& getOverlaySupport() 412*38e8c45fSAndroid Build Coastguard Worker const override; 413*38e8c45fSAndroid Build Coastguard Worker 414*38e8c45fSAndroid Build Coastguard Worker int32_t getSupportedPerFrameMetadata(HalDisplayId) const override; 415*38e8c45fSAndroid Build Coastguard Worker 416*38e8c45fSAndroid Build Coastguard Worker // Returns the available RenderIntent of the given display. 417*38e8c45fSAndroid Build Coastguard Worker std::vector<ui::RenderIntent> getRenderIntents(HalDisplayId, ui::ColorMode) const override; 418*38e8c45fSAndroid Build Coastguard Worker 419*38e8c45fSAndroid Build Coastguard Worker mat4 getDataspaceSaturationMatrix(HalDisplayId, ui::Dataspace) override; 420*38e8c45fSAndroid Build Coastguard Worker 421*38e8c45fSAndroid Build Coastguard Worker // Returns the attributes of the color sampling engine. 422*38e8c45fSAndroid Build Coastguard Worker status_t getDisplayedContentSamplingAttributes(HalDisplayId, ui::PixelFormat* outFormat, 423*38e8c45fSAndroid Build Coastguard Worker ui::Dataspace* outDataspace, 424*38e8c45fSAndroid Build Coastguard Worker uint8_t* outComponentMask) override; 425*38e8c45fSAndroid Build Coastguard Worker status_t setDisplayContentSamplingEnabled(HalDisplayId, bool enabled, uint8_t componentMask, 426*38e8c45fSAndroid Build Coastguard Worker uint64_t maxFrames) override; 427*38e8c45fSAndroid Build Coastguard Worker status_t getDisplayedContentSample(HalDisplayId, uint64_t maxFrames, uint64_t timestamp, 428*38e8c45fSAndroid Build Coastguard Worker DisplayedFrameStats* outStats) override; 429*38e8c45fSAndroid Build Coastguard Worker ftl::Future<status_t> setDisplayBrightness( 430*38e8c45fSAndroid Build Coastguard Worker PhysicalDisplayId, float brightness, float brightnessNits, 431*38e8c45fSAndroid Build Coastguard Worker const Hwc2::Composer::DisplayBrightnessOptions&) override; 432*38e8c45fSAndroid Build Coastguard Worker 433*38e8c45fSAndroid Build Coastguard Worker // Events handling --------------------------------------------------------- 434*38e8c45fSAndroid Build Coastguard Worker 435*38e8c45fSAndroid Build Coastguard Worker // Returns PhysicalDisplayId (and display name on connection of new or previously disconnected 436*38e8c45fSAndroid Build Coastguard Worker // display), or std::nullopt if hotplug event was ignored. 437*38e8c45fSAndroid Build Coastguard Worker std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId, hal::Connection) override; 438*38e8c45fSAndroid Build Coastguard Worker 439*38e8c45fSAndroid Build Coastguard Worker bool updatesDeviceProductInfoOnHotplugReconnect() const override; 440*38e8c45fSAndroid Build Coastguard Worker 441*38e8c45fSAndroid Build Coastguard Worker std::optional<PhysicalDisplayId> onVsync(hal::HWDisplayId, nsecs_t timestamp) override; 442*38e8c45fSAndroid Build Coastguard Worker void setVsyncEnabled(PhysicalDisplayId, hal::Vsync enabled) override; 443*38e8c45fSAndroid Build Coastguard Worker 444*38e8c45fSAndroid Build Coastguard Worker bool isConnected(PhysicalDisplayId) const override; 445*38e8c45fSAndroid Build Coastguard Worker 446*38e8c45fSAndroid Build Coastguard Worker std::vector<HWCDisplayMode> getModes(PhysicalDisplayId, 447*38e8c45fSAndroid Build Coastguard Worker int32_t maxFrameIntervalNs) const override; 448*38e8c45fSAndroid Build Coastguard Worker 449*38e8c45fSAndroid Build Coastguard Worker ftl::Expected<hal::HWConfigId, status_t> getActiveMode(PhysicalDisplayId) const override; 450*38e8c45fSAndroid Build Coastguard Worker 451*38e8c45fSAndroid Build Coastguard Worker std::vector<ui::ColorMode> getColorModes(PhysicalDisplayId) const override; 452*38e8c45fSAndroid Build Coastguard Worker 453*38e8c45fSAndroid Build Coastguard Worker status_t setActiveColorMode(PhysicalDisplayId, ui::ColorMode, ui::RenderIntent) override; 454*38e8c45fSAndroid Build Coastguard Worker 455*38e8c45fSAndroid Build Coastguard Worker bool getValidateSkipped(HalDisplayId displayId) const override; 456*38e8c45fSAndroid Build Coastguard Worker 457*38e8c45fSAndroid Build Coastguard Worker // Composer 2.4 458*38e8c45fSAndroid Build Coastguard Worker ui::DisplayConnectionType getDisplayConnectionType(PhysicalDisplayId) const override; 459*38e8c45fSAndroid Build Coastguard Worker bool isVsyncPeriodSwitchSupported(PhysicalDisplayId) const override; 460*38e8c45fSAndroid Build Coastguard Worker ftl::Expected<nsecs_t, status_t> getDisplayVsyncPeriod(PhysicalDisplayId) const override; 461*38e8c45fSAndroid Build Coastguard Worker status_t setActiveModeWithConstraints(PhysicalDisplayId, hal::HWConfigId, 462*38e8c45fSAndroid Build Coastguard Worker const hal::VsyncPeriodChangeConstraints&, 463*38e8c45fSAndroid Build Coastguard Worker hal::VsyncPeriodChangeTimeline* outTimeline) override; 464*38e8c45fSAndroid Build Coastguard Worker status_t setAutoLowLatencyMode(PhysicalDisplayId, bool) override; 465*38e8c45fSAndroid Build Coastguard Worker status_t getSupportedContentTypes(PhysicalDisplayId, 466*38e8c45fSAndroid Build Coastguard Worker std::vector<hal::ContentType>*) const override; 467*38e8c45fSAndroid Build Coastguard Worker status_t setContentType(PhysicalDisplayId, hal::ContentType) override; 468*38e8c45fSAndroid Build Coastguard Worker 469*38e8c45fSAndroid Build Coastguard Worker const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override; 470*38e8c45fSAndroid Build Coastguard Worker 471*38e8c45fSAndroid Build Coastguard Worker // Composer 3.0 472*38e8c45fSAndroid Build Coastguard Worker status_t setBootDisplayMode(PhysicalDisplayId, hal::HWConfigId) override; 473*38e8c45fSAndroid Build Coastguard Worker status_t clearBootDisplayMode(PhysicalDisplayId) override; 474*38e8c45fSAndroid Build Coastguard Worker std::optional<hal::HWConfigId> getPreferredBootDisplayMode(PhysicalDisplayId) override; 475*38e8c45fSAndroid Build Coastguard Worker status_t getDisplayDecorationSupport( 476*38e8c45fSAndroid Build Coastguard Worker PhysicalDisplayId, 477*38e8c45fSAndroid Build Coastguard Worker std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* 478*38e8c45fSAndroid Build Coastguard Worker support) override; 479*38e8c45fSAndroid Build Coastguard Worker status_t setIdleTimerEnabled(PhysicalDisplayId, std::chrono::milliseconds timeout) override; 480*38e8c45fSAndroid Build Coastguard Worker bool hasDisplayIdleTimerCapability(PhysicalDisplayId) const override; 481*38e8c45fSAndroid Build Coastguard Worker Hwc2::AidlTransform getPhysicalDisplayOrientation(PhysicalDisplayId) const override; 482*38e8c45fSAndroid Build Coastguard Worker std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability> 483*38e8c45fSAndroid Build Coastguard Worker getHdrConversionCapabilities() const override; 484*38e8c45fSAndroid Build Coastguard Worker status_t setHdrConversionStrategy( 485*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::common::HdrConversionStrategy, 486*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::common::Hdr*) override; 487*38e8c45fSAndroid Build Coastguard Worker status_t setRefreshRateChangedCallbackDebugEnabled(PhysicalDisplayId, bool enabled) override; 488*38e8c45fSAndroid Build Coastguard Worker status_t notifyExpectedPresent(PhysicalDisplayId, TimePoint expectedPresentTime, 489*38e8c45fSAndroid Build Coastguard Worker Fps frameInterval) override; 490*38e8c45fSAndroid Build Coastguard Worker HWC2::Display::LutFileDescriptorMapper& getLutFileDescriptorMapper() override; 491*38e8c45fSAndroid Build Coastguard Worker int32_t getMaxLayerPictureProfiles(PhysicalDisplayId) override; 492*38e8c45fSAndroid Build Coastguard Worker status_t setDisplayPictureProfileHandle(PhysicalDisplayId, 493*38e8c45fSAndroid Build Coastguard Worker const android::PictureProfileHandle& profile) override; 494*38e8c45fSAndroid Build Coastguard Worker 495*38e8c45fSAndroid Build Coastguard Worker // for debugging ---------------------------------------------------------- 496*38e8c45fSAndroid Build Coastguard Worker void dump(std::string& out) const override; 497*38e8c45fSAndroid Build Coastguard Worker void dumpOverlayProperties(std::string& out) const override; 498*38e8c45fSAndroid Build Coastguard Worker getComposer()499*38e8c45fSAndroid Build Coastguard Worker Hwc2::Composer* getComposer() const override { return mComposer.get(); } 500*38e8c45fSAndroid Build Coastguard Worker getPrimaryHwcDisplayId()501*38e8c45fSAndroid Build Coastguard Worker hal::HWDisplayId getPrimaryHwcDisplayId() const override { 502*38e8c45fSAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(!mPrimaryHwcDisplayId, "Missing HWC primary display"); 503*38e8c45fSAndroid Build Coastguard Worker return *mPrimaryHwcDisplayId; 504*38e8c45fSAndroid Build Coastguard Worker } 505*38e8c45fSAndroid Build Coastguard Worker getPrimaryDisplayId()506*38e8c45fSAndroid Build Coastguard Worker PhysicalDisplayId getPrimaryDisplayId() const override { 507*38e8c45fSAndroid Build Coastguard Worker const auto id = toPhysicalDisplayId(getPrimaryHwcDisplayId()); 508*38e8c45fSAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(!id, "Missing primary display"); 509*38e8c45fSAndroid Build Coastguard Worker return *id; 510*38e8c45fSAndroid Build Coastguard Worker } 511*38e8c45fSAndroid Build Coastguard Worker isHeadless()512*38e8c45fSAndroid Build Coastguard Worker virtual bool isHeadless() const override { return !mPrimaryHwcDisplayId; } 513*38e8c45fSAndroid Build Coastguard Worker 514*38e8c45fSAndroid Build Coastguard Worker std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const override; 515*38e8c45fSAndroid Build Coastguard Worker std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const override; 516*38e8c45fSAndroid Build Coastguard Worker 517*38e8c45fSAndroid Build Coastguard Worker private: 518*38e8c45fSAndroid Build Coastguard Worker // For unit tests 519*38e8c45fSAndroid Build Coastguard Worker friend TestableSurfaceFlinger; 520*38e8c45fSAndroid Build Coastguard Worker friend HWComposerTest; 521*38e8c45fSAndroid Build Coastguard Worker 522*38e8c45fSAndroid Build Coastguard Worker struct DisplayData { 523*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<HWC2::Display> hwcDisplay; 524*38e8c45fSAndroid Build Coastguard Worker 525*38e8c45fSAndroid Build Coastguard Worker sp<Fence> lastPresentFence = Fence::NO_FENCE; // signals when the last set op retires 526*38e8c45fSAndroid Build Coastguard Worker nsecs_t lastPresentTimestamp = 0; 527*38e8c45fSAndroid Build Coastguard Worker 528*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences; 529*38e8c45fSAndroid Build Coastguard Worker 530*38e8c45fSAndroid Build Coastguard Worker bool validateWasSkipped; 531*38e8c45fSAndroid Build Coastguard Worker hal::Error presentError; 532*38e8c45fSAndroid Build Coastguard Worker 533*38e8c45fSAndroid Build Coastguard Worker bool vsyncTraceToggle = false; 534*38e8c45fSAndroid Build Coastguard Worker 535*38e8c45fSAndroid Build Coastguard Worker std::mutex vsyncEnabledLock; 536*38e8c45fSAndroid Build Coastguard Worker hal::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = hal::Vsync::DISABLE; 537*38e8c45fSAndroid Build Coastguard Worker }; 538*38e8c45fSAndroid Build Coastguard Worker 539*38e8c45fSAndroid Build Coastguard Worker std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId); 540*38e8c45fSAndroid Build Coastguard Worker std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId); 541*38e8c45fSAndroid Build Coastguard Worker bool shouldIgnoreHotplugConnect(hal::HWDisplayId, bool hasDisplayIdentificationData) const; 542*38e8c45fSAndroid Build Coastguard Worker 543*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::DisplayConfiguration::Dpi 544*38e8c45fSAndroid Build Coastguard Worker getEstimatedDotsPerInchFromSize(uint64_t hwcDisplayId, const HWCDisplayMode& hwcMode) const; 545*38e8c45fSAndroid Build Coastguard Worker 546*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::DisplayConfiguration::Dpi correctedDpiIfneeded( 547*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::DisplayConfiguration::Dpi dpi, 548*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::DisplayConfiguration::Dpi estimatedDpi) 549*38e8c45fSAndroid Build Coastguard Worker const; 550*38e8c45fSAndroid Build Coastguard Worker std::vector<HWCDisplayMode> getModesFromDisplayConfigurations(uint64_t hwcDisplayId, 551*38e8c45fSAndroid Build Coastguard Worker int32_t maxFrameIntervalNs) const; 552*38e8c45fSAndroid Build Coastguard Worker std::vector<HWCDisplayMode> getModesFromLegacyDisplayConfigs(uint64_t hwcDisplayId) const; 553*38e8c45fSAndroid Build Coastguard Worker 554*38e8c45fSAndroid Build Coastguard Worker int32_t getAttribute(hal::HWDisplayId hwcDisplayId, hal::HWConfigId configId, 555*38e8c45fSAndroid Build Coastguard Worker hal::Attribute attribute) const; 556*38e8c45fSAndroid Build Coastguard Worker 557*38e8c45fSAndroid Build Coastguard Worker void loadCapabilities(); 558*38e8c45fSAndroid Build Coastguard Worker void loadLayerMetadataSupport(); 559*38e8c45fSAndroid Build Coastguard Worker void loadOverlayProperties(); 560*38e8c45fSAndroid Build Coastguard Worker void loadHdrConversionCapabilities(); 561*38e8c45fSAndroid Build Coastguard Worker 562*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<HalDisplayId, DisplayData> mDisplayData; 563*38e8c45fSAndroid Build Coastguard Worker 564*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<android::Hwc2::Composer> mComposer; 565*38e8c45fSAndroid Build Coastguard Worker std::unordered_set<aidl::android::hardware::graphics::composer3::Capability> mCapabilities; 566*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::OverlayProperties mOverlayProperties; 567*38e8c45fSAndroid Build Coastguard Worker std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability> 568*38e8c45fSAndroid Build Coastguard Worker mHdrConversionCapabilities = {}; 569*38e8c45fSAndroid Build Coastguard Worker 570*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata; 571*38e8c45fSAndroid Build Coastguard Worker bool mRegisteredCallback = false; 572*38e8c45fSAndroid Build Coastguard Worker 573*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<hal::HWDisplayId, PhysicalDisplayId> mPhysicalDisplayIdMap; 574*38e8c45fSAndroid Build Coastguard Worker std::optional<hal::HWDisplayId> mPrimaryHwcDisplayId; 575*38e8c45fSAndroid Build Coastguard Worker bool mHasMultiDisplaySupport = false; 576*38e8c45fSAndroid Build Coastguard Worker 577*38e8c45fSAndroid Build Coastguard Worker const size_t mMaxVirtualDisplayDimension; 578*38e8c45fSAndroid Build Coastguard Worker const bool mUpdateDeviceProductInfoOnHotplugReconnect; 579*38e8c45fSAndroid Build Coastguard Worker bool mEnableVrrTimeout; 580*38e8c45fSAndroid Build Coastguard Worker 581*38e8c45fSAndroid Build Coastguard Worker HWC2::Display::LutFileDescriptorMapper mLutFileDescriptorMapper; 582*38e8c45fSAndroid Build Coastguard Worker }; 583*38e8c45fSAndroid Build Coastguard Worker 584*38e8c45fSAndroid Build Coastguard Worker } // namespace impl 585*38e8c45fSAndroid Build Coastguard Worker } // namespace android 586