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