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