Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 17 | #pragma once |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 18 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 19 | #include <android-base/expected.h> |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 20 | #include <android-base/thread_annotations.h> |
Dominik Laskowski | 969cdcb | 2024-02-08 16:35:29 -0500 | [diff] [blame] | 21 | #include <ftl/expected.h> |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 22 | #include <ftl/future.h> |
Sally Qi | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame] | 23 | #include <ftl/small_map.h> |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 24 | #include <gui/HdrMetadata.h> |
Mathias Agopian | 1d77b71 | 2017-02-17 15:46:13 -0800 | [diff] [blame] | 25 | #include <math/mat4.h> |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 26 | #include <ui/HdrCapabilities.h> |
Brian Lindahl | 7a4cb7e | 2024-10-30 10:42:21 -0600 | [diff] [blame] | 27 | #include <ui/PictureProfileHandle.h> |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 28 | #include <ui/Region.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 29 | #include <ui/StaticDisplayInfo.h> |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 30 | #include <utils/Log.h> |
| 31 | #include <utils/StrongPointer.h> |
| 32 | #include <utils/Timers.h> |
| 33 | |
| 34 | #include <functional> |
| 35 | #include <string> |
| 36 | #include <unordered_map> |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 37 | #include <unordered_set> |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 38 | #include <vector> |
| 39 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 40 | #include "ComposerHal.h" |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 41 | #include "Hal.h" |
| 42 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 43 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 44 | #include <aidl/android/hardware/graphics/common/DisplayHotplugEvent.h> |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 45 | #include <aidl/android/hardware/graphics/composer3/Capability.h> |
Alec Mouri | 30835f2 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 46 | #include <aidl/android/hardware/graphics/composer3/ClientTargetPropertyWithBrightness.h> |
Ady Abraham | 6e60b14 | 2022-01-06 18:10:35 -0800 | [diff] [blame] | 47 | #include <aidl/android/hardware/graphics/composer3/Color.h> |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 48 | #include <aidl/android/hardware/graphics/composer3/Composition.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 49 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 50 | #include <aidl/android/hardware/graphics/composer3/Luts.h> |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 51 | #include <aidl/android/hardware/graphics/composer3/OverlayProperties.h> |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 52 | #include <aidl/android/hardware/graphics/composer3/RefreshRateChangedDebugData.h> |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 53 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 54 | namespace android { |
Lloyd Pique | bc79209 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 55 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 56 | class Fence; |
| 57 | class FloatRect; |
| 58 | class GraphicBuffer; |
| 59 | class TestableSurfaceFlinger; |
| 60 | struct DisplayedFrameStats; |
| 61 | |
| 62 | namespace Hwc2 { |
| 63 | class Composer; |
| 64 | } // namespace Hwc2 |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 65 | |
| 66 | namespace HWC2 { |
| 67 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 68 | class Layer; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 69 | |
| 70 | namespace hal = android::hardware::graphics::composer::hal; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 71 | |
Huihong Luo | 817ebb8 | 2023-12-13 12:54:24 -0800 | [diff] [blame] | 72 | using aidl::android::hardware::drm::HdcpLevels; |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 73 | using aidl::android::hardware::graphics::common::DisplayHotplugEvent; |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 74 | using aidl::android::hardware::graphics::composer3::RefreshRateChangedDebugData; |
| 75 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 76 | // Implement this interface to receive hardware composer events. |
| 77 | // |
| 78 | // These callback functions will generally be called on a hwbinder thread, but |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 79 | // when first registering the callback the onComposerHalHotplugEvent() function |
| 80 | // will immediately be called on the thread calling registerCallback(). |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 81 | struct ComposerCallback { |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 82 | virtual void onComposerHalHotplugEvent(hal::HWDisplayId, DisplayHotplugEvent) = 0; |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 83 | virtual void onComposerHalRefresh(hal::HWDisplayId) = 0; |
Dominik Laskowski | dc2bb80 | 2022-09-28 16:02:59 -0400 | [diff] [blame] | 84 | virtual void onComposerHalVsync(hal::HWDisplayId, nsecs_t timestamp, |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 85 | std::optional<hal::VsyncPeriodNanos>) = 0; |
| 86 | virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId, |
| 87 | const hal::VsyncPeriodChangeTimeline&) = 0; |
| 88 | virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0; |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 89 | virtual void onComposerHalVsyncIdle(hal::HWDisplayId) = 0; |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 90 | virtual void onRefreshRateChangedDebug(const RefreshRateChangedDebugData&) = 0; |
Huihong Luo | 817ebb8 | 2023-12-13 12:54:24 -0800 | [diff] [blame] | 91 | virtual void onComposerHalHdcpLevelsChanged(hal::HWDisplayId, const HdcpLevels& levels) = 0; |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 92 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 93 | protected: |
| 94 | ~ComposerCallback() = default; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 95 | }; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 96 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 97 | // Convenience C++ class to access per display functions directly. |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 98 | class Display { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 99 | public: |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 100 | virtual ~Display(); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 101 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 102 | virtual hal::HWDisplayId getId() const = 0; |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 103 | virtual bool isConnected() const = 0; |
Florian Mayer | cffc379 | 2022-03-01 23:50:09 +0000 | [diff] [blame] | 104 | virtual void setConnected(bool connected) = 0; // For use by HWComposer only |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 105 | virtual bool hasCapability( |
| 106 | aidl::android::hardware::graphics::composer3::DisplayCapability) const = 0; |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 107 | virtual bool isVsyncPeriodSwitchSupported() const = 0; |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 108 | virtual bool hasDisplayIdleTimerCapability() const = 0; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 109 | virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0; |
Lucas Berthou | 8d0a0c4 | 2024-08-27 14:32:31 +0000 | [diff] [blame] | 110 | virtual std::optional<ui::Size> getPhysicalSizeInMm() const = 0; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 111 | |
Sally Qi | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame] | 112 | static const int kLutFileDescriptorMapperSize = 20; |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 113 | using LutOffsetAndProperties = std::vector< |
| 114 | std::pair<int32_t, aidl::android::hardware::graphics::composer3::LutProperties>>; |
Sally Qi | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame] | 115 | using LayerLuts = |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 116 | ftl::SmallMap<HWC2::Layer*, LutOffsetAndProperties, kLutFileDescriptorMapperSize>; |
Sally Qi | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame] | 117 | using LutFileDescriptorMapper = |
| 118 | ftl::SmallMap<HWC2::Layer*, ndk::ScopedFileDescriptor, kLutFileDescriptorMapperSize>; |
| 119 | |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 120 | [[nodiscard]] virtual hal::Error acceptChanges() = 0; |
| 121 | [[nodiscard]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 122 | createLayer() = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 123 | [[nodiscard]] virtual hal::Error getChangedCompositionTypes( |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 124 | std::unordered_map<Layer*, aidl::android::hardware::graphics::composer3::Composition>* |
| 125 | outTypes) = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 126 | [[nodiscard]] virtual hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const = 0; |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 127 | // Returns a bitmask which contains HdrMetadata::Type::*. |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 128 | [[nodiscard]] virtual int32_t getSupportedPerFrameMetadata() const = 0; |
| 129 | [[nodiscard]] virtual hal::Error getRenderIntents( |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 130 | hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 131 | [[nodiscard]] virtual hal::Error getDataspaceSaturationMatrix(hal::Dataspace dataspace, |
| 132 | android::mat4* outMatrix) = 0; |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 133 | |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 134 | [[nodiscard]] virtual hal::Error getName(std::string* outName) const = 0; |
| 135 | [[nodiscard]] virtual hal::Error getRequests( |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 136 | hal::DisplayRequest* outDisplayRequests, |
| 137 | std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0; |
Dominik Laskowski | 969cdcb | 2024-02-08 16:35:29 -0500 | [diff] [blame] | 138 | [[nodiscard]] virtual ftl::Expected<ui::DisplayConnectionType, hal::Error> getConnectionType() |
| 139 | const = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 140 | [[nodiscard]] virtual hal::Error supportsDoze(bool* outSupport) const = 0; |
| 141 | [[nodiscard]] virtual hal::Error getHdrCapabilities( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 142 | android::HdrCapabilities* outCapabilities) const = 0; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 143 | [[nodiscard]] virtual hal::Error getOverlaySupport( |
| 144 | aidl::android::hardware::graphics::composer3::OverlayProperties* outProperties) |
| 145 | const = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 146 | [[nodiscard]] virtual hal::Error getDisplayedContentSamplingAttributes( |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 147 | hal::PixelFormat* outFormat, hal::Dataspace* outDataspace, |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 148 | uint8_t* outComponentMask) const = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 149 | [[nodiscard]] virtual hal::Error setDisplayContentSamplingEnabled(bool enabled, |
| 150 | uint8_t componentMask, |
| 151 | uint64_t maxFrames) const = 0; |
| 152 | [[nodiscard]] virtual hal::Error getDisplayedContentSample( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 153 | uint64_t maxFrames, uint64_t timestamp, |
| 154 | android::DisplayedFrameStats* outStats) const = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 155 | [[nodiscard]] virtual hal::Error getReleaseFences( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 156 | std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 157 | [[nodiscard]] virtual hal::Error present(android::sp<android::Fence>* outPresentFence) = 0; |
| 158 | [[nodiscard]] virtual hal::Error setClientTarget( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 159 | uint32_t slot, const android::sp<android::GraphicBuffer>& target, |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 160 | const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace, |
| 161 | float hdrSdrRatio) = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 162 | [[nodiscard]] virtual hal::Error setColorMode(hal::ColorMode mode, |
| 163 | hal::RenderIntent renderIntent) = 0; |
| 164 | [[nodiscard]] virtual hal::Error setColorTransform(const android::mat4& matrix) = 0; |
| 165 | [[nodiscard]] virtual hal::Error setOutputBuffer( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 166 | const android::sp<android::GraphicBuffer>& buffer, |
| 167 | const android::sp<android::Fence>& releaseFence) = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 168 | [[nodiscard]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0; |
| 169 | [[nodiscard]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0; |
ramindani | 09acbb8 | 2023-11-03 09:02:38 -0700 | [diff] [blame] | 170 | [[nodiscard]] virtual hal::Error validate(nsecs_t expectedPresentTime, int32_t frameIntervalNs, |
| 171 | uint32_t* outNumTypes, uint32_t* outNumRequests) = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 172 | [[nodiscard]] virtual hal::Error presentOrValidate(nsecs_t expectedPresentTime, |
ramindani | 4aac32c | 2023-10-30 14:13:30 -0700 | [diff] [blame] | 173 | int32_t frameIntervalNs, |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 174 | uint32_t* outNumTypes, |
| 175 | uint32_t* outNumRequests, |
| 176 | android::sp<android::Fence>* outPresentFence, |
| 177 | uint32_t* state) = 0; |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 178 | [[nodiscard]] virtual ftl::Future<hal::Error> setDisplayBrightness( |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 179 | float brightness, float brightnessNits, |
| 180 | const Hwc2::Composer::DisplayBrightnessOptions& options) = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 181 | [[nodiscard]] virtual hal::Error setActiveConfigWithConstraints( |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 182 | hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints, |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 183 | hal::VsyncPeriodChangeTimeline* outTimeline) = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 184 | [[nodiscard]] virtual hal::Error setBootDisplayConfig(hal::HWConfigId configId) = 0; |
| 185 | [[nodiscard]] virtual hal::Error clearBootDisplayConfig() = 0; |
| 186 | [[nodiscard]] virtual hal::Error getPreferredBootDisplayConfig( |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 187 | hal::HWConfigId* configId) const = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 188 | [[nodiscard]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0; |
| 189 | [[nodiscard]] virtual hal::Error getSupportedContentTypes( |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 190 | std::vector<hal::ContentType>*) const = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 191 | [[nodiscard]] virtual hal::Error setContentType(hal::ContentType) = 0; |
| 192 | [[nodiscard]] virtual hal::Error getClientTargetProperty( |
Alec Mouri | 30835f2 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 193 | aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness* |
| 194 | outClientTargetProperty) = 0; |
Sally Qi | 11dcd58 | 2024-08-16 18:11:27 -0700 | [diff] [blame] | 195 | [[nodiscard]] virtual hal::Error getRequestedLuts( |
Sally Qi | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame] | 196 | LayerLuts* outLuts, LutFileDescriptorMapper& lutFileDescriptorMapper) = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 197 | [[nodiscard]] virtual hal::Error getDisplayDecorationSupport( |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 198 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* |
| 199 | support) = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 200 | [[nodiscard]] virtual hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) = 0; |
| 201 | [[nodiscard]] virtual hal::Error getPhysicalDisplayOrientation( |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 202 | Hwc2::AidlTransform* outTransform) const = 0; |
Brian Lindahl | 7a4cb7e | 2024-10-30 10:42:21 -0600 | [diff] [blame] | 203 | [[nodiscard]] virtual hal::Error getMaxLayerPictureProfiles(int32_t* maxProfiles) = 0; |
| 204 | [[nodiscard]] virtual hal::Error setPictureProfileHandle( |
| 205 | const PictureProfileHandle& handle) = 0; |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | namespace impl { |
| 209 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 210 | class Layer; |
| 211 | |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 212 | class Display : public HWC2::Display { |
| 213 | public: |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 214 | Display(android::Hwc2::Composer&, |
| 215 | const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&, |
| 216 | hal::HWDisplayId, hal::DisplayType); |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 217 | ~Display() override; |
| 218 | |
| 219 | // Required by HWC2 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 220 | hal::Error acceptChanges() override; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 221 | base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 222 | hal::Error getChangedCompositionTypes( |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 223 | std::unordered_map<HWC2::Layer*, |
| 224 | aidl::android::hardware::graphics::composer3::Composition>* outTypes) |
| 225 | override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 226 | hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override; |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 227 | // Returns a bitmask which contains HdrMetadata::Type::*. |
| 228 | int32_t getSupportedPerFrameMetadata() const override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 229 | hal::Error getRenderIntents(hal::ColorMode colorMode, |
| 230 | std::vector<hal::RenderIntent>* outRenderIntents) const override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 231 | hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 232 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 233 | hal::Error getName(std::string* outName) const override; |
| 234 | hal::Error getRequests( |
| 235 | hal::DisplayRequest* outDisplayRequests, |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 236 | std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override; |
Dominik Laskowski | 969cdcb | 2024-02-08 16:35:29 -0500 | [diff] [blame] | 237 | ftl::Expected<ui::DisplayConnectionType, hal::Error> getConnectionType() const override; |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 238 | hal::Error supportsDoze(bool* outSupport) const override EXCLUDES(mDisplayCapabilitiesMutex); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 239 | hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 240 | hal::Error getOverlaySupport(aidl::android::hardware::graphics::composer3::OverlayProperties* |
| 241 | outProperties) const override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 242 | hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat, |
| 243 | hal::Dataspace* outDataspace, |
| 244 | uint8_t* outComponentMask) const override; |
| 245 | hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask, |
| 246 | uint64_t maxFrames) const override; |
| 247 | hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp, |
| 248 | android::DisplayedFrameStats* outStats) const override; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 249 | hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>* |
| 250 | outFences) const override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 251 | hal::Error present(android::sp<android::Fence>* outPresentFence) override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 252 | hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target, |
| 253 | const android::sp<android::Fence>& acquireFence, |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 254 | hal::Dataspace dataspace, float hdrSdrRatio) override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 255 | hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override; |
Ady Abraham | dc011a9 | 2021-12-21 14:06:44 -0800 | [diff] [blame] | 256 | hal::Error setColorTransform(const android::mat4& matrix) override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 257 | hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&, |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 258 | const android::sp<android::Fence>& releaseFence) override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 259 | hal::Error setPowerMode(hal::PowerMode) override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 260 | hal::Error setVsyncEnabled(hal::Vsync enabled) override; |
ramindani | 09acbb8 | 2023-11-03 09:02:38 -0700 | [diff] [blame] | 261 | hal::Error validate(nsecs_t expectedPresentTime, int32_t frameIntervalNs, uint32_t* outNumTypes, |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 262 | uint32_t* outNumRequests) override; |
ramindani | 4aac32c | 2023-10-30 14:13:30 -0700 | [diff] [blame] | 263 | hal::Error presentOrValidate(nsecs_t expectedPresentTime, int32_t frameIntervalNs, |
| 264 | uint32_t* outNumTypes, uint32_t* outNumRequests, |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 265 | android::sp<android::Fence>* outPresentFence, |
| 266 | uint32_t* state) override; |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 267 | ftl::Future<hal::Error> setDisplayBrightness( |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 268 | float brightness, float brightnessNits, |
| 269 | const Hwc2::Composer::DisplayBrightnessOptions& options) override; |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 270 | hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId, |
| 271 | const hal::VsyncPeriodChangeConstraints& constraints, |
| 272 | hal::VsyncPeriodChangeTimeline* outTimeline) override; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 273 | hal::Error setBootDisplayConfig(hal::HWConfigId configId) override; |
| 274 | hal::Error clearBootDisplayConfig() override; |
| 275 | hal::Error getPreferredBootDisplayConfig(hal::HWConfigId* configId) const override; |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 276 | hal::Error setAutoLowLatencyMode(bool on) override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 277 | hal::Error getSupportedContentTypes( |
| 278 | std::vector<hal::ContentType>* outSupportedContentTypes) const override; |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 279 | hal::Error setContentType(hal::ContentType) override; |
Alec Mouri | 30835f2 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 280 | hal::Error getClientTargetProperty( |
| 281 | aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness* |
| 282 | outClientTargetProperty) override; |
Sally Qi | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame] | 283 | hal::Error getRequestedLuts(LayerLuts* outLuts, |
| 284 | LutFileDescriptorMapper& lutFileDescriptorMapper) override; |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 285 | hal::Error getDisplayDecorationSupport( |
| 286 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* |
| 287 | support) override; |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 288 | hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) override; |
Brian Lindahl | 7a4cb7e | 2024-10-30 10:42:21 -0600 | [diff] [blame] | 289 | hal::Error getMaxLayerPictureProfiles(int32_t* maxProfiles) override; |
| 290 | hal::Error setPictureProfileHandle(const android::PictureProfileHandle& handle) override; |
Peiyong Lin | dfc3f7c | 2020-05-07 20:15:50 -0700 | [diff] [blame] | 291 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 292 | // Other Display methods |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 293 | hal::HWDisplayId getId() const override { return mId; } |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 294 | bool isConnected() const override { return mIsConnected; } |
Florian Mayer | cffc379 | 2022-03-01 23:50:09 +0000 | [diff] [blame] | 295 | void setConnected(bool connected) override; |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 296 | bool hasCapability(aidl::android::hardware::graphics::composer3::DisplayCapability) |
| 297 | const override EXCLUDES(mDisplayCapabilitiesMutex); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 298 | bool isVsyncPeriodSwitchSupported() const override; |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 299 | bool hasDisplayIdleTimerCapability() const override; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 300 | void onLayerDestroyed(hal::HWLayerId layerId) override; |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 301 | hal::Error getPhysicalDisplayOrientation(Hwc2::AidlTransform* outTransform) const override; |
Lucas Berthou | 8d0a0c4 | 2024-08-27 14:32:31 +0000 | [diff] [blame] | 302 | void setPhysicalSizeInMm(std::optional<ui::Size> size); |
| 303 | std::optional<ui::Size> getPhysicalSizeInMm() const override { return mPhysicalSize; } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 304 | |
| 305 | private: |
HyunKyoung | a264a35 | 2024-04-24 18:51:33 +0900 | [diff] [blame] | 306 | void loadDisplayCapabilities(); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 307 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 308 | // This may fail (and return a null pointer) if no layer with this ID exists |
| 309 | // on this display |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 310 | std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) const; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 311 | |
Lloyd Pique | bc79209 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 312 | friend android::TestableSurfaceFlinger; |
| 313 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 314 | // Member variables |
| 315 | |
Florian Mayer | cffc379 | 2022-03-01 23:50:09 +0000 | [diff] [blame] | 316 | // These are references to data owned by HWComposer, which will outlive |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 317 | // this HWC2::Display, so these references are guaranteed to be valid for |
| 318 | // the lifetime of this object. |
| 319 | android::Hwc2::Composer& mComposer; |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 320 | const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>& |
| 321 | mCapabilities; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 322 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 323 | const hal::HWDisplayId mId; |
| 324 | hal::DisplayType mType; |
Dominik Laskowski | 969cdcb | 2024-02-08 16:35:29 -0500 | [diff] [blame] | 325 | // Cached on first call to getConnectionType. |
| 326 | mutable std::optional<ftl::Expected<ui::DisplayConnectionType, hal::Error>> mConnectionType; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 327 | bool mIsConnected = false; |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 328 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 329 | using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>; |
| 330 | Layers mLayers; |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 331 | |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 332 | mutable std::mutex mDisplayCapabilitiesMutex; |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 333 | std::once_flag mDisplayCapabilityQueryFlag; |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 334 | std::optional< |
| 335 | std::unordered_set<aidl::android::hardware::graphics::composer3::DisplayCapability>> |
| 336 | mDisplayCapabilities GUARDED_BY(mDisplayCapabilitiesMutex); |
Lucas Berthou | 8d0a0c4 | 2024-08-27 14:32:31 +0000 | [diff] [blame] | 337 | // Physical size in mm. |
| 338 | std::optional<ui::Size> mPhysicalSize; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 339 | }; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 340 | |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 341 | } // namespace impl |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 342 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 343 | class Layer { |
| 344 | public: |
| 345 | virtual ~Layer(); |
| 346 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 347 | virtual hal::HWLayerId getId() const = 0; |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 348 | |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 349 | [[nodiscard]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0; |
| 350 | [[nodiscard]] virtual hal::Error setBuffer(uint32_t slot, |
| 351 | const android::sp<android::GraphicBuffer>& buffer, |
| 352 | const android::sp<android::Fence>& acquireFence) = 0; |
Brian Lindahl | b158a5c | 2022-12-15 15:21:13 -0700 | [diff] [blame] | 353 | [[nodiscard]] virtual hal::Error setBufferSlotsToClear( |
| 354 | const std::vector<uint32_t>& slotsToClear, uint32_t activeBufferSlot) = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 355 | [[nodiscard]] virtual hal::Error setSurfaceDamage(const android::Region& damage) = 0; |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 356 | |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 357 | [[nodiscard]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0; |
| 358 | [[nodiscard]] virtual hal::Error setColor( |
Ady Abraham | 6e60b14 | 2022-01-06 18:10:35 -0800 | [diff] [blame] | 359 | aidl::android::hardware::graphics::composer3::Color color) = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 360 | [[nodiscard]] virtual hal::Error setCompositionType( |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 361 | aidl::android::hardware::graphics::composer3::Composition type) = 0; |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 362 | [[nodiscard]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0; |
| 363 | [[nodiscard]] virtual hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata, |
| 364 | const android::HdrMetadata& metadata) = 0; |
| 365 | [[nodiscard]] virtual hal::Error setDisplayFrame(const android::Rect& frame) = 0; |
| 366 | [[nodiscard]] virtual hal::Error setPlaneAlpha(float alpha) = 0; |
| 367 | [[nodiscard]] virtual hal::Error setSidebandStream(const native_handle_t* stream) = 0; |
| 368 | [[nodiscard]] virtual hal::Error setSourceCrop(const android::FloatRect& crop) = 0; |
| 369 | [[nodiscard]] virtual hal::Error setTransform(hal::Transform transform) = 0; |
| 370 | [[nodiscard]] virtual hal::Error setVisibleRegion(const android::Region& region) = 0; |
| 371 | [[nodiscard]] virtual hal::Error setZOrder(uint32_t z) = 0; |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 372 | |
| 373 | // Composer HAL 2.3 |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 374 | [[nodiscard]] virtual hal::Error setColorTransform(const android::mat4& matrix) = 0; |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 375 | |
| 376 | // Composer HAL 2.4 |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 377 | [[nodiscard]] virtual hal::Error setLayerGenericMetadata(const std::string& name, |
| 378 | bool mandatory, |
| 379 | const std::vector<uint8_t>& value) = 0; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 380 | |
| 381 | // AIDL HAL |
ramindani | 86d3d98 | 2022-03-16 20:57:42 +0000 | [diff] [blame] | 382 | [[nodiscard]] virtual hal::Error setBrightness(float brightness) = 0; |
| 383 | [[nodiscard]] virtual hal::Error setBlockingRegion(const android::Region& region) = 0; |
Sally Qi | 11dcd58 | 2024-08-16 18:11:27 -0700 | [diff] [blame] | 384 | [[nodiscard]] virtual hal::Error setLuts( |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 385 | aidl::android::hardware::graphics::composer3::Luts& luts) = 0; |
Brian Lindahl | 7a4cb7e | 2024-10-30 10:42:21 -0600 | [diff] [blame] | 386 | [[nodiscard]] virtual hal::Error setPictureProfileHandle( |
| 387 | const PictureProfileHandle& handle) = 0; |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 388 | }; |
| 389 | |
| 390 | namespace impl { |
| 391 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 392 | // Convenience C++ class to access per layer functions directly. |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 393 | |
| 394 | class Layer : public HWC2::Layer { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 395 | public: |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 396 | Layer(android::Hwc2::Composer& composer, |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 397 | const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>& |
| 398 | capabilities, |
| 399 | HWC2::Display& display, hal::HWLayerId layerId); |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 400 | ~Layer() override; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 401 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 402 | void onOwningDisplayDestroyed(); |
| 403 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 404 | hal::HWLayerId getId() const override { return mId; } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 405 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 406 | hal::Error setCursorPosition(int32_t x, int32_t y) override; |
| 407 | hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer, |
| 408 | const android::sp<android::Fence>& acquireFence) override; |
Brian Lindahl | b158a5c | 2022-12-15 15:21:13 -0700 | [diff] [blame] | 409 | hal::Error setBufferSlotsToClear(const std::vector<uint32_t>& slotsToClear, |
| 410 | uint32_t activeBufferSlot) override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 411 | hal::Error setSurfaceDamage(const android::Region& damage) override; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 412 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 413 | hal::Error setBlendMode(hal::BlendMode mode) override; |
Ady Abraham | 6e60b14 | 2022-01-06 18:10:35 -0800 | [diff] [blame] | 414 | hal::Error setColor(aidl::android::hardware::graphics::composer3::Color color) override; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 415 | hal::Error setCompositionType( |
| 416 | aidl::android::hardware::graphics::composer3::Composition type) override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 417 | hal::Error setDataspace(hal::Dataspace dataspace) override; |
| 418 | hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata, |
| 419 | const android::HdrMetadata& metadata) override; |
| 420 | hal::Error setDisplayFrame(const android::Rect& frame) override; |
| 421 | hal::Error setPlaneAlpha(float alpha) override; |
| 422 | hal::Error setSidebandStream(const native_handle_t* stream) override; |
| 423 | hal::Error setSourceCrop(const android::FloatRect& crop) override; |
| 424 | hal::Error setTransform(hal::Transform transform) override; |
| 425 | hal::Error setVisibleRegion(const android::Region& region) override; |
| 426 | hal::Error setZOrder(uint32_t z) override; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 427 | |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 428 | // Composer HAL 2.3 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 429 | hal::Error setColorTransform(const android::mat4& matrix) override; |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 430 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 431 | // Composer HAL 2.4 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 432 | hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory, |
| 433 | const std::vector<uint8_t>& value) override; |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 434 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 435 | // AIDL HAL |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 436 | hal::Error setBrightness(float brightness) override; |
Leon Scroggins III | d77d316 | 2022-01-05 10:42:28 -0500 | [diff] [blame] | 437 | hal::Error setBlockingRegion(const android::Region& region) override; |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 438 | hal::Error setLuts(aidl::android::hardware::graphics::composer3::Luts&) override; |
Brian Lindahl | 7a4cb7e | 2024-10-30 10:42:21 -0600 | [diff] [blame] | 439 | hal::Error setPictureProfileHandle(const PictureProfileHandle& handle) override; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 440 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 441 | private: |
Florian Mayer | cffc379 | 2022-03-01 23:50:09 +0000 | [diff] [blame] | 442 | // These are references to data owned by HWComposer, which will outlive |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 443 | // this HWC2::Layer, so these references are guaranteed to be valid for |
| 444 | // the lifetime of this object. |
| 445 | android::Hwc2::Composer& mComposer; |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 446 | const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>& |
| 447 | mCapabilities; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 448 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 449 | HWC2::Display* mDisplay; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 450 | hal::HWLayerId mId; |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 451 | |
| 452 | // Cached HWC2 data, to ensure the same commands aren't sent to the HWC |
| 453 | // multiple times. |
| 454 | android::Region mVisibleRegion = android::Region::INVALID_REGION; |
| 455 | android::Region mDamageRegion = android::Region::INVALID_REGION; |
Leon Scroggins III | d77d316 | 2022-01-05 10:42:28 -0500 | [diff] [blame] | 456 | android::Region mBlockingRegion = android::Region::INVALID_REGION; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 457 | hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN; |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 458 | android::HdrMetadata mHdrMetadata; |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 459 | android::mat4 mColorMatrix; |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 460 | uint32_t mBufferSlot; |
Brian Lindahl | 7a4cb7e | 2024-10-30 10:42:21 -0600 | [diff] [blame] | 461 | android::PictureProfileHandle profile; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 462 | }; |
| 463 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 464 | } // namespace impl |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 465 | } // namespace HWC2 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 466 | } // namespace android |