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