Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 17 | #pragma once |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 18 | |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 19 | #include <cstdint> |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 20 | #include <memory> |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 21 | #include <mutex> |
Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 22 | #include <optional> |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 23 | #include <unordered_map> |
| 24 | #include <unordered_set> |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 25 | #include <vector> |
| 26 | |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 27 | #include <android-base/thread_annotations.h> |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 28 | #include <ftl/expected.h> |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 29 | #include <ftl/future.h> |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 30 | #include <ui/DisplayIdentification.h> |
Ady Abraham | ec7aa8a | 2021-06-28 12:37:09 -0700 | [diff] [blame] | 31 | #include <ui/FenceTime.h> |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 32 | |
| 33 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 34 | #pragma clang diagnostic push |
| 35 | #pragma clang diagnostic ignored "-Wconversion" |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 36 | #pragma clang diagnostic ignored "-Wextra" |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 37 | #include <ui/GraphicTypes.h> |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 38 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 39 | |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 40 | #include <utils/StrongPointer.h> |
| 41 | #include <utils/Timers.h> |
| 42 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 43 | #include "DisplayMode.h" |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 44 | #include "HWC2.h" |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 45 | #include "Hal.h" |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 46 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 47 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 48 | #include <aidl/android/hardware/graphics/common/Hdr.h> |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 49 | #include <aidl/android/hardware/graphics/common/HdrConversionCapability.h> |
| 50 | #include <aidl/android/hardware/graphics/common/HdrConversionStrategy.h> |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 51 | #include <aidl/android/hardware/graphics/composer3/Capability.h> |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 52 | #include <aidl/android/hardware/graphics/composer3/ClientTargetPropertyWithBrightness.h> |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 53 | #include <aidl/android/hardware/graphics/composer3/Composition.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 54 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 55 | #include <aidl/android/hardware/graphics/composer3/OverlayProperties.h> |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 56 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 57 | namespace android { |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 58 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 59 | namespace hal = hardware::graphics::composer::hal; |
| 60 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 61 | struct DisplayedFrameStats; |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 62 | class GraphicBuffer; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 63 | class TestableSurfaceFlinger; |
ramindani | b90711b | 2023-10-02 15:13:19 -0700 | [diff] [blame] | 64 | struct HWComposerTest; |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 65 | struct CompositionInfo; |
Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 66 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 67 | namespace Hwc2 { |
| 68 | class Composer; |
| 69 | } // namespace Hwc2 |
| 70 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 71 | namespace compositionengine { |
| 72 | class Output; |
| 73 | } // namespace compositionengine |
| 74 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 75 | struct KnownHWCGenericLayerMetadata { |
| 76 | const char* name; |
| 77 | const uint32_t id; |
| 78 | }; |
| 79 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 80 | // See the comment for SurfaceFlinger::getHwComposer for the thread safety rules for accessing |
| 81 | // this class. |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 82 | class HWComposer { |
| 83 | public: |
Peiyong Lin | dfc3f7c | 2020-05-07 20:15:50 -0700 | [diff] [blame] | 84 | struct DeviceRequestedChanges { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 85 | using ChangedTypes = |
| 86 | std::unordered_map<HWC2::Layer*, |
| 87 | aidl::android::hardware::graphics::composer3::Composition>; |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 88 | using ClientTargetProperty = |
| 89 | aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness; |
Peiyong Lin | dfc3f7c | 2020-05-07 20:15:50 -0700 | [diff] [blame] | 90 | using DisplayRequests = hal::DisplayRequest; |
| 91 | using LayerRequests = std::unordered_map<HWC2::Layer*, hal::LayerRequest>; |
| 92 | |
| 93 | ChangedTypes changedTypes; |
| 94 | DisplayRequests displayRequests; |
| 95 | LayerRequests layerRequests; |
| 96 | ClientTargetProperty clientTargetProperty; |
| 97 | }; |
| 98 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 99 | struct HWCDisplayMode { |
| 100 | hal::HWConfigId hwcId; |
| 101 | int32_t width = -1; |
| 102 | int32_t height = -1; |
| 103 | nsecs_t vsyncPeriod = -1; |
ramindani | 0cd1d8d | 2023-06-13 13:43:23 -0700 | [diff] [blame] | 104 | float dpiX = -1.f; |
| 105 | float dpiY = -1.f; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 106 | int32_t configGroup = -1; |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 107 | std::optional<hal::VrrConfig> vrrConfig; |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 108 | |
| 109 | friend std::ostream& operator<<(std::ostream& os, const HWCDisplayMode& mode) { |
| 110 | return os << "id=" << mode.hwcId << " res=" << mode.width << "x" << mode.height |
| 111 | << " vsyncPeriod=" << mode.vsyncPeriod << " dpi=" << mode.dpiX << "x" |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 112 | << mode.dpiY << " group=" << mode.configGroup |
| 113 | << " vrrConfig=" << to_string(mode.vrrConfig).c_str(); |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 114 | } |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 115 | }; |
| 116 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 117 | virtual ~HWComposer(); |
| 118 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 119 | virtual void setCallback(HWC2::ComposerCallback&) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 120 | |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 121 | virtual bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 122 | DisplayIdentificationData* outData) const = 0; |
| 123 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 124 | virtual bool hasCapability(aidl::android::hardware::graphics::composer3::Capability) const = 0; |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 125 | virtual bool hasDisplayCapability( |
| 126 | HalDisplayId, |
| 127 | aidl::android::hardware::graphics::composer3::DisplayCapability) const = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 128 | |
Dominik Laskowski | 1394860 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 129 | virtual size_t getMaxVirtualDisplayCount() const = 0; |
| 130 | virtual size_t getMaxVirtualDisplayDimension() const = 0; |
| 131 | |
| 132 | // Attempts to allocate a virtual display on the HWC. The maximum number of virtual displays |
| 133 | // supported by the HWC can be queried in advance, but allocation may fail for other reasons. |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 134 | virtual bool allocateVirtualDisplay(HalVirtualDisplayId, ui::Size, ui::PixelFormat*) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 135 | |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 136 | virtual void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) = 0; |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 137 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 138 | // Attempts to create a new layer on this display |
Lloyd Pique | 1b33fc3 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 139 | virtual std::shared_ptr<HWC2::Layer> createLayer(HalDisplayId) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 140 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 141 | // Gets any required composition change requests from the HWC device. |
| 142 | // |
| 143 | // Note that frameUsesClientComposition must be set correctly based on |
| 144 | // whether the current frame appears to use client composition. If it is |
| 145 | // false some internal optimizations are allowed to present the display |
| 146 | // with fewer handshakes, but this does not work if client composition is |
| 147 | // expected. |
| 148 | virtual status_t getDeviceCompositionChanges( |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 149 | HalDisplayId, bool frameUsesClientComposition, |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 150 | std::optional<std::chrono::steady_clock::time_point> earliestPresentTime, |
ramindani | 4aac32c | 2023-10-30 14:13:30 -0700 | [diff] [blame] | 151 | nsecs_t expectedPresentTime, Fps frameInterval, |
| 152 | std::optional<DeviceRequestedChanges>* outChanges) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 153 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 154 | virtual status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence, |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 155 | const sp<GraphicBuffer>& target, ui::Dataspace, |
| 156 | float hdrSdrRatio) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 157 | |
| 158 | // Present layers to the display and read releaseFences. |
Ady Abraham | b42cdc1 | 2021-05-11 14:31:26 -0700 | [diff] [blame] | 159 | virtual status_t presentAndGetReleaseFences( |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 160 | HalDisplayId, |
| 161 | std::optional<std::chrono::steady_clock::time_point> earliestPresentTime) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 162 | |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame^] | 163 | virtual status_t executeCommands(HalDisplayId) = 0; |
| 164 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 165 | // set power mode |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 166 | virtual status_t setPowerMode(PhysicalDisplayId, hal::PowerMode) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 167 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 168 | // Sets a color transform to be applied to the result of composition |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 169 | virtual status_t setColorTransform(HalDisplayId, const mat4& transform) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 170 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 171 | // reset state when a display is disconnected |
| 172 | virtual void disconnectDisplay(HalDisplayId) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 173 | |
Dominik Laskowski | dc2bb80 | 2022-09-28 16:02:59 -0400 | [diff] [blame] | 174 | // Get the present fence/timestamp received from the last call to present. |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 175 | virtual sp<Fence> getPresentFence(HalDisplayId) const = 0; |
Dominik Laskowski | dc2bb80 | 2022-09-28 16:02:59 -0400 | [diff] [blame] | 176 | virtual nsecs_t getPresentTimestamp(PhysicalDisplayId) const = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 177 | |
| 178 | // Get last release fence for the given layer |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 179 | virtual sp<Fence> getLayerReleaseFence(HalDisplayId, HWC2::Layer*) const = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 180 | |
| 181 | // Set the output buffer and acquire fence for a virtual display. |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 182 | virtual status_t setOutputBuffer(HalVirtualDisplayId, const sp<Fence>& acquireFence, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 183 | const sp<GraphicBuffer>& buffer) = 0; |
| 184 | |
| 185 | // After SurfaceFlinger has retrieved the release fences for all the frames, |
| 186 | // it can call this to clear the shared pointers in the release fence map |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 187 | virtual void clearReleaseFences(HalDisplayId) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 188 | |
| 189 | // Fetches the HDR capabilities of the given display |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 190 | virtual status_t getHdrCapabilities(HalDisplayId, HdrCapabilities* outCapabilities) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 191 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 192 | virtual const aidl::android::hardware::graphics::composer3::OverlayProperties& |
| 193 | getOverlaySupport() const = 0; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 194 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 195 | virtual int32_t getSupportedPerFrameMetadata(HalDisplayId) const = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 196 | |
| 197 | // Returns the available RenderIntent of the given display. |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 198 | virtual std::vector<ui::RenderIntent> getRenderIntents(HalDisplayId, ui::ColorMode) const = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 199 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 200 | virtual mat4 getDataspaceSaturationMatrix(HalDisplayId, ui::Dataspace) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 201 | |
| 202 | // Returns the attributes of the color sampling engine. |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 203 | virtual status_t getDisplayedContentSamplingAttributes(HalDisplayId, ui::PixelFormat* outFormat, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 204 | ui::Dataspace* outDataspace, |
| 205 | uint8_t* outComponentMask) = 0; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 206 | virtual status_t setDisplayContentSamplingEnabled(HalDisplayId, bool enabled, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 207 | uint8_t componentMask, |
| 208 | uint64_t maxFrames) = 0; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 209 | virtual status_t getDisplayedContentSample(HalDisplayId, uint64_t maxFrames, uint64_t timestamp, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 210 | DisplayedFrameStats* outStats) = 0; |
| 211 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 212 | // Sets the brightness of a display. |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 213 | virtual ftl::Future<status_t> setDisplayBrightness( |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 214 | PhysicalDisplayId, float brightness, float brightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 215 | const Hwc2::Composer::DisplayBrightnessOptions&) = 0; |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 216 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 217 | // Get whether the display skipped validation on the latest present |
| 218 | virtual bool getValidateSkipped(HalDisplayId displayId) const = 0; |
| 219 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 220 | // Events handling --------------------------------------------------------- |
| 221 | |
| 222 | // Returns stable display ID (and display name on connection of new or previously disconnected |
| 223 | // display), or std::nullopt if hotplug event was ignored. |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 224 | // This function is called from SurfaceFlinger. |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 225 | virtual std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId, |
| 226 | hal::Connection) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 227 | |
Marin Shalamanov | f8c6372 | 2020-10-06 13:11:21 +0200 | [diff] [blame] | 228 | // If true we'll update the DeviceProductInfo on subsequent hotplug connected events. |
| 229 | // TODO(b/157555476): Remove when the framework has proper support for headless mode |
| 230 | virtual bool updatesDeviceProductInfoOnHotplugReconnect() const = 0; |
| 231 | |
Leon Scroggins III | 959a7ff | 2023-02-07 11:24:25 -0500 | [diff] [blame] | 232 | // Called when a vsync happens. If the vsync is valid, returns the |
| 233 | // corresponding PhysicalDisplayId. Otherwise returns nullopt. |
| 234 | virtual std::optional<PhysicalDisplayId> onVsync(hal::HWDisplayId, nsecs_t timestamp) = 0; |
| 235 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 236 | virtual void setVsyncEnabled(PhysicalDisplayId, hal::Vsync enabled) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 237 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 238 | virtual bool isConnected(PhysicalDisplayId) const = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 239 | |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 240 | virtual std::vector<HWCDisplayMode> getModes(PhysicalDisplayId, |
| 241 | int32_t maxFrameIntervalNs) const = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 242 | |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 243 | virtual ftl::Expected<hal::HWConfigId, status_t> getActiveMode(PhysicalDisplayId) const = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 244 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 245 | virtual std::vector<ui::ColorMode> getColorModes(PhysicalDisplayId) const = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 246 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 247 | virtual status_t setActiveColorMode(PhysicalDisplayId, ui::ColorMode mode, |
| 248 | ui::RenderIntent) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 249 | |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 250 | // Composer 2.4 |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 251 | virtual ui::DisplayConnectionType getDisplayConnectionType(PhysicalDisplayId) const = 0; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 252 | virtual bool isVsyncPeriodSwitchSupported(PhysicalDisplayId) const = 0; |
Dominik Laskowski | a109bb2 | 2024-01-28 13:33:51 -0500 | [diff] [blame] | 253 | virtual ftl::Expected<nsecs_t, status_t> getDisplayVsyncPeriod(PhysicalDisplayId) const = 0; |
Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 254 | virtual status_t setActiveModeWithConstraints(PhysicalDisplayId, hal::HWConfigId, |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 255 | const hal::VsyncPeriodChangeConstraints&, |
| 256 | hal::VsyncPeriodChangeTimeline* outTimeline) = 0; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 257 | virtual status_t setAutoLowLatencyMode(PhysicalDisplayId, bool on) = 0; |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 258 | virtual status_t getSupportedContentTypes( |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 259 | PhysicalDisplayId, std::vector<hal::ContentType>* outSupportedContentTypes) const = 0; |
| 260 | |
| 261 | bool supportsContentType(PhysicalDisplayId displayId, hal::ContentType type) const { |
| 262 | std::vector<hal::ContentType> types; |
| 263 | return getSupportedContentTypes(displayId, &types) == NO_ERROR && |
| 264 | std::find(types.begin(), types.end(), type) != types.end(); |
| 265 | } |
| 266 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 267 | virtual status_t setContentType(PhysicalDisplayId, hal::ContentType) = 0; |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 268 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 269 | virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() |
| 270 | const = 0; |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 271 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 272 | virtual void dump(std::string& out) const = 0; |
| 273 | |
Sally Qi | 254ef49 | 2024-04-08 15:01:28 -0700 | [diff] [blame] | 274 | virtual void dumpOverlayProperties(std::string& out) const = 0; |
| 275 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 276 | virtual Hwc2::Composer* getComposer() const = 0; |
| 277 | |
Marin Shalamanov | 8b19659 | 2021-08-09 16:24:42 +0200 | [diff] [blame] | 278 | // Returns the first display connected at boot. Its connection via HWComposer::onHotplug, |
| 279 | // which in practice is immediately after HWComposer construction, must occur before any |
| 280 | // call to this function. |
| 281 | // The primary display can be temporarily disconnected from the perspective |
| 282 | // of this class. Callers must not call getPrimaryHwcDisplayId() or getPrimaryDisplayId() |
| 283 | // if isHeadless(). |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 284 | // |
| 285 | // TODO(b/182939859): Remove special cases for primary display. |
| 286 | virtual hal::HWDisplayId getPrimaryHwcDisplayId() const = 0; |
| 287 | virtual PhysicalDisplayId getPrimaryDisplayId() const = 0; |
| 288 | virtual bool isHeadless() const = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 289 | |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 290 | virtual std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const = 0; |
| 291 | virtual std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const = 0; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 292 | |
| 293 | // Composer 3.0 |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 294 | virtual status_t setBootDisplayMode(PhysicalDisplayId, hal::HWConfigId) = 0; |
| 295 | virtual status_t clearBootDisplayMode(PhysicalDisplayId) = 0; |
Kriti Dang | 16ca297 | 2022-02-01 20:07:03 +0100 | [diff] [blame] | 296 | virtual std::optional<hal::HWConfigId> getPreferredBootDisplayMode(PhysicalDisplayId) = 0; |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 297 | virtual status_t getDisplayDecorationSupport( |
| 298 | PhysicalDisplayId, |
| 299 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* |
| 300 | support) = 0; |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 301 | virtual status_t setIdleTimerEnabled(PhysicalDisplayId, std::chrono::milliseconds timeout) = 0; |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 302 | virtual bool hasDisplayIdleTimerCapability(PhysicalDisplayId) const = 0; |
| 303 | virtual Hwc2::AidlTransform getPhysicalDisplayOrientation(PhysicalDisplayId) const = 0; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 304 | virtual std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability> |
| 305 | getHdrConversionCapabilities() const = 0; |
| 306 | virtual status_t setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 307 | aidl::android::hardware::graphics::common::HdrConversionStrategy, |
| 308 | aidl::android::hardware::graphics::common::Hdr*) = 0; |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 309 | virtual status_t setRefreshRateChangedCallbackDebugEnabled(PhysicalDisplayId, bool enabled) = 0; |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 310 | virtual status_t notifyExpectedPresent(PhysicalDisplayId, TimePoint expectedPresentTime, |
| 311 | Fps frameInterval) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 312 | }; |
| 313 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 314 | static inline bool operator==(const android::HWComposer::DeviceRequestedChanges& lhs, |
| 315 | const android::HWComposer::DeviceRequestedChanges& rhs) { |
| 316 | return lhs.changedTypes == rhs.changedTypes && lhs.displayRequests == rhs.displayRequests && |
| 317 | lhs.layerRequests == rhs.layerRequests && |
| 318 | lhs.clientTargetProperty == rhs.clientTargetProperty; |
| 319 | } |
| 320 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 321 | namespace impl { |
| 322 | |
| 323 | class HWComposer final : public android::HWComposer { |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 324 | public: |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 325 | explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer); |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 326 | explicit HWComposer(const std::string& composerServiceName); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 327 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 328 | ~HWComposer() override; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 329 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 330 | void setCallback(HWC2::ComposerCallback&) override; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 331 | |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 332 | bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 333 | DisplayIdentificationData* outData) const override; |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 334 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 335 | bool hasCapability(aidl::android::hardware::graphics::composer3::Capability) const override; |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 336 | bool hasDisplayCapability( |
| 337 | HalDisplayId, |
| 338 | aidl::android::hardware::graphics::composer3::DisplayCapability) const override; |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 339 | |
Dominik Laskowski | 1394860 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 340 | size_t getMaxVirtualDisplayCount() const override; |
| 341 | size_t getMaxVirtualDisplayDimension() const override; |
| 342 | |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 343 | bool allocateVirtualDisplay(HalVirtualDisplayId, ui::Size, ui::PixelFormat*) override; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 344 | |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 345 | // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated. |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 346 | void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) override; |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 347 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 348 | // Attempts to create a new layer on this display |
Lloyd Pique | 1b33fc3 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 349 | std::shared_ptr<HWC2::Layer> createLayer(HalDisplayId) override; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 350 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 351 | status_t getDeviceCompositionChanges( |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 352 | HalDisplayId, bool frameUsesClientComposition, |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 353 | std::optional<std::chrono::steady_clock::time_point> earliestPresentTime, |
ramindani | 4aac32c | 2023-10-30 14:13:30 -0700 | [diff] [blame] | 354 | nsecs_t expectedPresentTime, Fps frameInterval, |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 355 | std::optional<DeviceRequestedChanges>* outChanges) override; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 356 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 357 | status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence, |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 358 | const sp<GraphicBuffer>& target, ui::Dataspace, |
| 359 | float hdrSdrRatio) override; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 360 | |
Fabien Sanglard | a87aa7b | 2016-11-30 16:27:22 -0800 | [diff] [blame] | 361 | // Present layers to the display and read releaseFences. |
Ady Abraham | b42cdc1 | 2021-05-11 14:31:26 -0700 | [diff] [blame] | 362 | status_t presentAndGetReleaseFences( |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 363 | HalDisplayId, |
| 364 | std::optional<std::chrono::steady_clock::time_point> earliestPresentTime) override; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 365 | |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame^] | 366 | status_t executeCommands(HalDisplayId) override; |
| 367 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 368 | // set power mode |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 369 | status_t setPowerMode(PhysicalDisplayId, hal::PowerMode mode) override; |
Colin Cross | 10fbdb6 | 2012-07-12 17:56:34 -0700 | [diff] [blame] | 370 | |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 371 | // Sets a color transform to be applied to the result of composition |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 372 | status_t setColorTransform(HalDisplayId, const mat4& transform) override; |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 373 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 374 | // reset state when a display is disconnected |
| 375 | void disconnectDisplay(HalDisplayId) override; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 376 | |
Dominik Laskowski | dc2bb80 | 2022-09-28 16:02:59 -0400 | [diff] [blame] | 377 | // Get the present fence/timestamp received from the last call to present. |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 378 | sp<Fence> getPresentFence(HalDisplayId) const override; |
Dominik Laskowski | dc2bb80 | 2022-09-28 16:02:59 -0400 | [diff] [blame] | 379 | nsecs_t getPresentTimestamp(PhysicalDisplayId) const override; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 380 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 381 | // Get last release fence for the given layer |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 382 | sp<Fence> getLayerReleaseFence(HalDisplayId, HWC2::Layer*) const override; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 383 | |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 384 | // Set the output buffer and acquire fence for a virtual display. |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 385 | status_t setOutputBuffer(HalVirtualDisplayId, const sp<Fence>& acquireFence, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 386 | const sp<GraphicBuffer>& buffer) override; |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 387 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 388 | // After SurfaceFlinger has retrieved the release fences for all the frames, |
| 389 | // it can call this to clear the shared pointers in the release fence map |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 390 | void clearReleaseFences(HalDisplayId) override; |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 391 | |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 392 | // Fetches the HDR capabilities of the given display |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 393 | status_t getHdrCapabilities(HalDisplayId, HdrCapabilities* outCapabilities) override; |
Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 394 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 395 | const aidl::android::hardware::graphics::composer3::OverlayProperties& getOverlaySupport() |
| 396 | const override; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 397 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 398 | int32_t getSupportedPerFrameMetadata(HalDisplayId) const override; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 399 | |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 400 | // Returns the available RenderIntent of the given display. |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 401 | std::vector<ui::RenderIntent> getRenderIntents(HalDisplayId, ui::ColorMode) const override; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 402 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 403 | mat4 getDataspaceSaturationMatrix(HalDisplayId, ui::Dataspace) override; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 404 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 405 | // Returns the attributes of the color sampling engine. |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 406 | status_t getDisplayedContentSamplingAttributes(HalDisplayId, ui::PixelFormat* outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 407 | ui::Dataspace* outDataspace, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 408 | uint8_t* outComponentMask) override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 409 | status_t setDisplayContentSamplingEnabled(HalDisplayId, bool enabled, uint8_t componentMask, |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 410 | uint64_t maxFrames) override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 411 | status_t getDisplayedContentSample(HalDisplayId, uint64_t maxFrames, uint64_t timestamp, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 412 | DisplayedFrameStats* outStats) override; |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 413 | ftl::Future<status_t> setDisplayBrightness( |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 414 | PhysicalDisplayId, float brightness, float brightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 415 | const Hwc2::Composer::DisplayBrightnessOptions&) override; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 416 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 417 | // Events handling --------------------------------------------------------- |
| 418 | |
Marin Shalamanov | f8c6372 | 2020-10-06 13:11:21 +0200 | [diff] [blame] | 419 | // Returns PhysicalDisplayId (and display name on connection of new or previously disconnected |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 420 | // display), or std::nullopt if hotplug event was ignored. |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 421 | std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId, hal::Connection) override; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 422 | |
Marin Shalamanov | f8c6372 | 2020-10-06 13:11:21 +0200 | [diff] [blame] | 423 | bool updatesDeviceProductInfoOnHotplugReconnect() const override; |
| 424 | |
Leon Scroggins III | 959a7ff | 2023-02-07 11:24:25 -0500 | [diff] [blame] | 425 | std::optional<PhysicalDisplayId> onVsync(hal::HWDisplayId, nsecs_t timestamp) override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 426 | void setVsyncEnabled(PhysicalDisplayId, hal::Vsync enabled) override; |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 427 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 428 | bool isConnected(PhysicalDisplayId) const override; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 429 | |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 430 | std::vector<HWCDisplayMode> getModes(PhysicalDisplayId, |
| 431 | int32_t maxFrameIntervalNs) const override; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 432 | |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 433 | ftl::Expected<hal::HWConfigId, status_t> getActiveMode(PhysicalDisplayId) const override; |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 434 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 435 | std::vector<ui::ColorMode> getColorModes(PhysicalDisplayId) const override; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 436 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 437 | status_t setActiveColorMode(PhysicalDisplayId, ui::ColorMode, ui::RenderIntent) override; |
Courtney Goeltzenleuchter | fad9d8c | 2016-06-23 11:49:50 -0600 | [diff] [blame] | 438 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 439 | bool getValidateSkipped(HalDisplayId displayId) const override; |
| 440 | |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 441 | // Composer 2.4 |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 442 | ui::DisplayConnectionType getDisplayConnectionType(PhysicalDisplayId) const override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 443 | bool isVsyncPeriodSwitchSupported(PhysicalDisplayId) const override; |
Dominik Laskowski | a109bb2 | 2024-01-28 13:33:51 -0500 | [diff] [blame] | 444 | ftl::Expected<nsecs_t, status_t> getDisplayVsyncPeriod(PhysicalDisplayId) const override; |
Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 445 | status_t setActiveModeWithConstraints(PhysicalDisplayId, hal::HWConfigId, |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 446 | const hal::VsyncPeriodChangeConstraints&, |
| 447 | hal::VsyncPeriodChangeTimeline* outTimeline) override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 448 | status_t setAutoLowLatencyMode(PhysicalDisplayId, bool) override; |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 449 | status_t getSupportedContentTypes(PhysicalDisplayId, |
| 450 | std::vector<hal::ContentType>*) const override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 451 | status_t setContentType(PhysicalDisplayId, hal::ContentType) override; |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 452 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 453 | const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override; |
| 454 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 455 | // Composer 3.0 |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 456 | status_t setBootDisplayMode(PhysicalDisplayId, hal::HWConfigId) override; |
| 457 | status_t clearBootDisplayMode(PhysicalDisplayId) override; |
Kriti Dang | 16ca297 | 2022-02-01 20:07:03 +0100 | [diff] [blame] | 458 | std::optional<hal::HWConfigId> getPreferredBootDisplayMode(PhysicalDisplayId) override; |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 459 | status_t getDisplayDecorationSupport( |
| 460 | PhysicalDisplayId, |
| 461 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* |
| 462 | support) override; |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 463 | status_t setIdleTimerEnabled(PhysicalDisplayId, std::chrono::milliseconds timeout) override; |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 464 | bool hasDisplayIdleTimerCapability(PhysicalDisplayId) const override; |
| 465 | Hwc2::AidlTransform getPhysicalDisplayOrientation(PhysicalDisplayId) const override; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 466 | std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability> |
| 467 | getHdrConversionCapabilities() const override; |
| 468 | status_t setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 469 | aidl::android::hardware::graphics::common::HdrConversionStrategy, |
| 470 | aidl::android::hardware::graphics::common::Hdr*) override; |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 471 | status_t setRefreshRateChangedCallbackDebugEnabled(PhysicalDisplayId, bool enabled) override; |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 472 | status_t notifyExpectedPresent(PhysicalDisplayId, TimePoint expectedPresentTime, |
| 473 | Fps frameInterval) override; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 474 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 475 | // for debugging ---------------------------------------------------------- |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 476 | void dump(std::string& out) const override; |
Sally Qi | 254ef49 | 2024-04-08 15:01:28 -0700 | [diff] [blame] | 477 | void dumpOverlayProperties(std::string& out) const override; |
Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 478 | |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 479 | Hwc2::Composer* getComposer() const override { return mComposer.get(); } |
Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 480 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 481 | hal::HWDisplayId getPrimaryHwcDisplayId() const override { |
| 482 | LOG_ALWAYS_FATAL_IF(!mPrimaryHwcDisplayId, "Missing HWC primary display"); |
| 483 | return *mPrimaryHwcDisplayId; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 484 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 485 | |
| 486 | PhysicalDisplayId getPrimaryDisplayId() const override { |
| 487 | const auto id = toPhysicalDisplayId(getPrimaryHwcDisplayId()); |
| 488 | LOG_ALWAYS_FATAL_IF(!id, "Missing primary display"); |
| 489 | return *id; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 490 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 491 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 492 | virtual bool isHeadless() const override { return !mPrimaryHwcDisplayId; } |
| 493 | |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 494 | std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const override; |
| 495 | std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const override; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 496 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 497 | private: |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 498 | // For unit tests |
| 499 | friend TestableSurfaceFlinger; |
ramindani | 355fca8 | 2023-12-18 12:07:34 -0800 | [diff] [blame] | 500 | friend HWComposerTest; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 501 | |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 502 | struct DisplayData { |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 503 | std::unique_ptr<HWC2::Display> hwcDisplay; |
Dominik Laskowski | dc2bb80 | 2022-09-28 16:02:59 -0400 | [diff] [blame] | 504 | |
Dominik Laskowski | f9750f2 | 2018-06-06 12:24:53 -0700 | [diff] [blame] | 505 | sp<Fence> lastPresentFence = Fence::NO_FENCE; // signals when the last set op retires |
Dominik Laskowski | dc2bb80 | 2022-09-28 16:02:59 -0400 | [diff] [blame] | 506 | nsecs_t lastPresentTimestamp = 0; |
| 507 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 508 | std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences; |
Jamie Gennis | 2ec3e07 | 2012-11-11 16:24:33 -0800 | [diff] [blame] | 509 | |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 510 | bool validateWasSkipped; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 511 | hal::Error presentError; |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 512 | |
| 513 | bool vsyncTraceToggle = false; |
| 514 | |
| 515 | std::mutex vsyncEnabledLock; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 516 | hal::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = hal::Vsync::DISABLE; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 517 | }; |
| 518 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 519 | std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId); |
| 520 | std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId); |
| 521 | bool shouldIgnoreHotplugConnect(hal::HWDisplayId, bool hasDisplayIdentificationData) const; |
| 522 | |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 523 | std::vector<HWCDisplayMode> getModesFromDisplayConfigurations(uint64_t hwcDisplayId, |
| 524 | int32_t maxFrameIntervalNs) const; |
ramindani | 0cd1d8d | 2023-06-13 13:43:23 -0700 | [diff] [blame] | 525 | std::vector<HWCDisplayMode> getModesFromLegacyDisplayConfigs(uint64_t hwcDisplayId) const; |
| 526 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 527 | int32_t getAttribute(hal::HWDisplayId hwcDisplayId, hal::HWConfigId configId, |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 528 | hal::Attribute attribute) const; |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 529 | |
| 530 | void loadCapabilities(); |
| 531 | void loadLayerMetadataSupport(); |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 532 | void loadOverlayProperties(); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 533 | void loadHdrConversionCapabilities(); |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 534 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 535 | std::unordered_map<HalDisplayId, DisplayData> mDisplayData; |
Dominik Laskowski | b04f98a | 2018-11-07 21:07:16 -0800 | [diff] [blame] | 536 | |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 537 | std::unique_ptr<android::Hwc2::Composer> mComposer; |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 538 | std::unordered_set<aidl::android::hardware::graphics::composer3::Capability> mCapabilities; |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 539 | aidl::android::hardware::graphics::composer3::OverlayProperties mOverlayProperties; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 540 | std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability> |
| 541 | mHdrConversionCapabilities = {}; |
| 542 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 543 | std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata; |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 544 | bool mRegisteredCallback = false; |
Dominik Laskowski | b04f98a | 2018-11-07 21:07:16 -0800 | [diff] [blame] | 545 | |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 546 | std::unordered_map<hal::HWDisplayId, PhysicalDisplayId> mPhysicalDisplayIdMap; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 547 | std::optional<hal::HWDisplayId> mPrimaryHwcDisplayId; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 548 | bool mHasMultiDisplaySupport = false; |
| 549 | |
Dominik Laskowski | 1394860 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 550 | const size_t mMaxVirtualDisplayDimension; |
Marin Shalamanov | f8c6372 | 2020-10-06 13:11:21 +0200 | [diff] [blame] | 551 | const bool mUpdateDeviceProductInfoOnHotplugReconnect; |
ramindani | 355fca8 | 2023-12-18 12:07:34 -0800 | [diff] [blame] | 552 | bool mEnableVrrTimeout; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 553 | }; |
| 554 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 555 | } // namespace impl |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 556 | } // namespace android |