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> |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 21 | #include <ui/DisplayInfo.h> |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 22 | #include <ui/HdrCapabilities.h> |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 23 | #include <ui/Region.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 | |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 82 | class Config { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 83 | public: |
| 84 | class Builder |
| 85 | { |
| 86 | public: |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 87 | Builder(Display& display, hal::HWConfigId id); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 88 | |
| 89 | std::shared_ptr<const Config> build() { |
| 90 | return std::const_pointer_cast<const Config>( |
| 91 | std::move(mConfig)); |
| 92 | } |
| 93 | |
| 94 | Builder& setWidth(int32_t width) { |
| 95 | mConfig->mWidth = width; |
| 96 | return *this; |
| 97 | } |
| 98 | Builder& setHeight(int32_t height) { |
| 99 | mConfig->mHeight = height; |
| 100 | return *this; |
| 101 | } |
| 102 | Builder& setVsyncPeriod(int32_t vsyncPeriod) { |
| 103 | mConfig->mVsyncPeriod = vsyncPeriod; |
| 104 | return *this; |
| 105 | } |
| 106 | Builder& setDpiX(int32_t dpiX) { |
| 107 | if (dpiX == -1) { |
| 108 | mConfig->mDpiX = getDefaultDensity(); |
| 109 | } else { |
| 110 | mConfig->mDpiX = dpiX / 1000.0f; |
| 111 | } |
| 112 | return *this; |
| 113 | } |
| 114 | Builder& setDpiY(int32_t dpiY) { |
| 115 | if (dpiY == -1) { |
| 116 | mConfig->mDpiY = getDefaultDensity(); |
| 117 | } else { |
| 118 | mConfig->mDpiY = dpiY / 1000.0f; |
| 119 | } |
| 120 | return *this; |
| 121 | } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 122 | Builder& setConfigGroup(int32_t configGroup) { |
| 123 | mConfig->mConfigGroup = configGroup; |
| 124 | return *this; |
| 125 | } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 126 | |
| 127 | private: |
| 128 | float getDefaultDensity(); |
| 129 | std::shared_ptr<Config> mConfig; |
| 130 | }; |
| 131 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 132 | hal::HWDisplayId getDisplayId() const { return mDisplay.getId(); } |
| 133 | hal::HWConfigId getId() const { return mId; } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 134 | |
| 135 | int32_t getWidth() const { return mWidth; } |
| 136 | int32_t getHeight() const { return mHeight; } |
David Sodman | 1afa8b0 | 2018-10-15 11:20:48 -0700 | [diff] [blame] | 137 | nsecs_t getVsyncPeriod() const { return mVsyncPeriod; } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 138 | float getDpiX() const { return mDpiX; } |
| 139 | float getDpiY() const { return mDpiY; } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 140 | int32_t getConfigGroup() const { return mConfigGroup; } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 141 | |
| 142 | private: |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 143 | Config(Display& display, hal::HWConfigId id); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 144 | |
| 145 | Display& mDisplay; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 146 | hal::HWConfigId mId; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 147 | |
| 148 | int32_t mWidth; |
| 149 | int32_t mHeight; |
| 150 | nsecs_t mVsyncPeriod; |
| 151 | float mDpiX; |
| 152 | float mDpiY; |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 153 | int32_t mConfigGroup; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 156 | virtual hal::HWDisplayId getId() const = 0; |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 157 | virtual bool isConnected() const = 0; |
| 158 | virtual void setConnected(bool connected) = 0; // For use by Device only |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 159 | virtual const std::unordered_set<hal::DisplayCapability>& getCapabilities() const = 0; |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 160 | virtual bool isVsyncPeriodSwitchSupported() const = 0; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 161 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 162 | [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0; |
| 163 | [[clang::warn_unused_result]] virtual hal::Error createLayer(Layer** outLayer) = 0; |
| 164 | [[clang::warn_unused_result]] virtual hal::Error destroyLayer(Layer* layer) = 0; |
| 165 | [[clang::warn_unused_result]] virtual hal::Error getActiveConfig( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 166 | std::shared_ptr<const Config>* outConfig) const = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 167 | [[clang::warn_unused_result]] virtual hal::Error getActiveConfigIndex(int* outIndex) const = 0; |
| 168 | [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes( |
| 169 | std::unordered_map<Layer*, hal::Composition>* outTypes) = 0; |
| 170 | [[clang::warn_unused_result]] virtual hal::Error getColorModes( |
| 171 | std::vector<hal::ColorMode>* outModes) const = 0; |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 172 | // Returns a bitmask which contains HdrMetadata::Type::*. |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 173 | [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 174 | [[clang::warn_unused_result]] virtual hal::Error getRenderIntents( |
| 175 | hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0; |
| 176 | [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix( |
| 177 | hal::Dataspace dataspace, android::mat4* outMatrix) = 0; |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 178 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 179 | // Doesn't call into the HWC2 device, so no errors are possible |
| 180 | [[clang::warn_unused_result]] virtual std::vector<std::shared_ptr<const Config>> getConfigs() |
| 181 | const = 0; |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 182 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 183 | [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0; |
| 184 | [[clang::warn_unused_result]] virtual hal::Error getRequests( |
| 185 | hal::DisplayRequest* outDisplayRequests, |
| 186 | std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0; |
| 187 | [[clang::warn_unused_result]] virtual hal::Error getConnectionType( |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 188 | android::DisplayConnectionType*) const = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 189 | [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0; |
| 190 | [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 191 | android::HdrCapabilities* outCapabilities) const = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 192 | [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes( |
| 193 | hal::PixelFormat* outFormat, hal::Dataspace* outDataspace, |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 194 | uint8_t* outComponentMask) const = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 195 | [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 196 | bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 197 | [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 198 | uint64_t maxFrames, uint64_t timestamp, |
| 199 | android::DisplayedFrameStats* outStats) const = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 200 | [[clang::warn_unused_result]] virtual hal::Error getReleaseFences( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 201 | std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 202 | [[clang::warn_unused_result]] virtual hal::Error present( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 203 | android::sp<android::Fence>* outPresentFence) = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 204 | [[clang::warn_unused_result]] virtual hal::Error setActiveConfig( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 205 | const std::shared_ptr<const Config>& config) = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 206 | [[clang::warn_unused_result]] virtual hal::Error setClientTarget( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 207 | uint32_t slot, const android::sp<android::GraphicBuffer>& target, |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 208 | const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0; |
| 209 | [[clang::warn_unused_result]] virtual hal::Error setColorMode( |
| 210 | hal::ColorMode mode, hal::RenderIntent renderIntent) = 0; |
| 211 | [[clang::warn_unused_result]] virtual hal::Error setColorTransform( |
| 212 | const android::mat4& matrix, hal::ColorTransform hint) = 0; |
| 213 | [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 214 | const android::sp<android::GraphicBuffer>& buffer, |
| 215 | const android::sp<android::Fence>& releaseFence) = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 216 | [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0; |
| 217 | [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0; |
| 218 | [[clang::warn_unused_result]] virtual hal::Error validate(uint32_t* outNumTypes, |
| 219 | uint32_t* outNumRequests) = 0; |
| 220 | [[clang::warn_unused_result]] virtual hal::Error presentOrValidate( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 221 | uint32_t* outNumTypes, uint32_t* outNumRequests, |
| 222 | android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0; |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 223 | [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness( |
| 224 | float brightness) = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 225 | [[clang::warn_unused_result]] virtual hal::Error getDisplayVsyncPeriod( |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 226 | nsecs_t* outVsyncPeriod) const = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 227 | [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints( |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 228 | const std::shared_ptr<const HWC2::Display::Config>& config, |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 229 | const hal::VsyncPeriodChangeConstraints& constraints, |
| 230 | hal::VsyncPeriodChangeTimeline* outTimeline) = 0; |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 231 | [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 232 | [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes( |
| 233 | std::vector<hal::ContentType>*) const = 0; |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 234 | [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0; |
Peiyong Lin | dfc3f7c | 2020-05-07 20:15:50 -0700 | [diff] [blame] | 235 | [[clang::warn_unused_result]] virtual hal::Error getClientTargetProperty( |
| 236 | hal::ClientTargetProperty* outClientTargetProperty) = 0; |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 237 | }; |
| 238 | |
| 239 | namespace impl { |
| 240 | |
| 241 | class Display : public HWC2::Display { |
| 242 | public: |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame^] | 243 | Display(android::Hwc2::Composer&, const std::unordered_set<hal::Capability>&, hal::HWDisplayId, |
| 244 | hal::DisplayType); |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 245 | ~Display() override; |
| 246 | |
| 247 | // Required by HWC2 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 248 | hal::Error acceptChanges() override; |
| 249 | hal::Error createLayer(Layer** outLayer) override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame^] | 250 | hal::Error destroyLayer(Layer*) override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 251 | hal::Error getActiveConfig(std::shared_ptr<const Config>* outConfig) const override; |
| 252 | hal::Error getActiveConfigIndex(int* outIndex) const override; |
| 253 | hal::Error getChangedCompositionTypes( |
| 254 | std::unordered_map<Layer*, hal::Composition>* outTypes) override; |
| 255 | hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override; |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 256 | // Returns a bitmask which contains HdrMetadata::Type::*. |
| 257 | int32_t getSupportedPerFrameMetadata() const override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 258 | hal::Error getRenderIntents(hal::ColorMode colorMode, |
| 259 | std::vector<hal::RenderIntent>* outRenderIntents) const override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame^] | 260 | hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 261 | |
| 262 | // Doesn't call into the HWC2 device, so no errors are possible |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 263 | std::vector<std::shared_ptr<const Config>> getConfigs() const override; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 264 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 265 | hal::Error getName(std::string* outName) const override; |
| 266 | hal::Error getRequests( |
| 267 | hal::DisplayRequest* outDisplayRequests, |
| 268 | std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) override; |
| 269 | hal::Error getConnectionType(android::DisplayConnectionType*) const override; |
| 270 | hal::Error supportsDoze(bool* outSupport) const override; |
| 271 | hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override; |
| 272 | hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat, |
| 273 | hal::Dataspace* outDataspace, |
| 274 | uint8_t* outComponentMask) const override; |
| 275 | hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask, |
| 276 | uint64_t maxFrames) const override; |
| 277 | hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp, |
| 278 | android::DisplayedFrameStats* outStats) const override; |
| 279 | hal::Error getReleaseFences( |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 280 | std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 281 | hal::Error present(android::sp<android::Fence>* outPresentFence) override; |
| 282 | hal::Error setActiveConfig(const std::shared_ptr<const HWC2::Display::Config>& config) override; |
| 283 | hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target, |
| 284 | const android::sp<android::Fence>& acquireFence, |
| 285 | hal::Dataspace dataspace) override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame^] | 286 | hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 287 | hal::Error setColorTransform(const android::mat4& matrix, hal::ColorTransform hint) override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame^] | 288 | hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&, |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 289 | const android::sp<android::Fence>& releaseFence) override; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame^] | 290 | hal::Error setPowerMode(hal::PowerMode) override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 291 | hal::Error setVsyncEnabled(hal::Vsync enabled) override; |
| 292 | hal::Error validate(uint32_t* outNumTypes, uint32_t* outNumRequests) override; |
| 293 | hal::Error presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests, |
| 294 | android::sp<android::Fence>* outPresentFence, |
| 295 | uint32_t* state) override; |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 296 | std::future<hal::Error> setDisplayBrightness(float brightness) override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 297 | hal::Error getDisplayVsyncPeriod(nsecs_t* outVsyncPeriod) const override; |
| 298 | hal::Error setActiveConfigWithConstraints( |
| 299 | const std::shared_ptr<const HWC2::Display::Config>& config, |
| 300 | const hal::VsyncPeriodChangeConstraints& constraints, |
| 301 | hal::VsyncPeriodChangeTimeline* outTimeline) override; |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 302 | hal::Error setAutoLowLatencyMode(bool on) override; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 303 | hal::Error getSupportedContentTypes( |
| 304 | std::vector<hal::ContentType>* outSupportedContentTypes) const override; |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 305 | hal::Error setContentType(hal::ContentType) override; |
Peiyong Lin | dfc3f7c | 2020-05-07 20:15:50 -0700 | [diff] [blame] | 306 | hal::Error getClientTargetProperty(hal::ClientTargetProperty* outClientTargetProperty) override; |
| 307 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 308 | // Other Display methods |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 309 | hal::HWDisplayId getId() const override { return mId; } |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 310 | bool isConnected() const override { return mIsConnected; } |
| 311 | void setConnected(bool connected) override; // For use by Device only |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 312 | const std::unordered_set<hal::DisplayCapability>& getCapabilities() const override { |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 313 | return mDisplayCapabilities; |
| 314 | }; |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 315 | virtual bool isVsyncPeriodSwitchSupported() const override; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 316 | |
| 317 | private: |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame^] | 318 | int32_t getAttribute(hal::HWConfigId, hal::Attribute); |
| 319 | void loadConfig(hal::HWConfigId); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 320 | void loadConfigs(); |
| 321 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 322 | // This may fail (and return a null pointer) if no layer with this ID exists |
| 323 | // on this display |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame^] | 324 | Layer* getLayerById(hal::HWLayerId) const; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 325 | |
Lloyd Pique | bc79209 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 326 | friend android::TestableSurfaceFlinger; |
| 327 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 328 | // Member variables |
| 329 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 330 | // These are references to data owned by HWC2::Device, which will outlive |
| 331 | // this HWC2::Display, so these references are guaranteed to be valid for |
| 332 | // the lifetime of this object. |
| 333 | android::Hwc2::Composer& mComposer; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 334 | const std::unordered_set<hal::Capability>& mCapabilities; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 335 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 336 | const hal::HWDisplayId mId; |
| 337 | hal::DisplayType mType; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 338 | bool mIsConnected = false; |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 339 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 340 | std::unordered_map<hal::HWLayerId, std::unique_ptr<Layer>> mLayers; |
| 341 | std::unordered_map<hal::HWConfigId, std::shared_ptr<const Config>> mConfigs; |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 342 | |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 343 | std::once_flag mDisplayCapabilityQueryFlag; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 344 | std::unordered_set<hal::DisplayCapability> mDisplayCapabilities; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 345 | }; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 346 | |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 347 | } // namespace impl |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 348 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 349 | class Layer { |
| 350 | public: |
| 351 | virtual ~Layer(); |
| 352 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 353 | virtual hal::HWLayerId getId() const = 0; |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 354 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 355 | [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0; |
| 356 | [[clang::warn_unused_result]] virtual hal::Error setBuffer( |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 357 | uint32_t slot, const android::sp<android::GraphicBuffer>& buffer, |
| 358 | const android::sp<android::Fence>& acquireFence) = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 359 | [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage( |
| 360 | const android::Region& damage) = 0; |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 361 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 362 | [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0; |
| 363 | [[clang::warn_unused_result]] virtual hal::Error setColor(hal::Color color) = 0; |
| 364 | [[clang::warn_unused_result]] virtual hal::Error setCompositionType(hal::Composition type) = 0; |
| 365 | [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0; |
| 366 | [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata( |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 367 | const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 368 | [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame( |
| 369 | const android::Rect& frame) = 0; |
| 370 | [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0; |
| 371 | [[clang::warn_unused_result]] virtual hal::Error setSidebandStream( |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 372 | const native_handle_t* stream) = 0; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 373 | [[clang::warn_unused_result]] virtual hal::Error setSourceCrop( |
| 374 | const android::FloatRect& crop) = 0; |
| 375 | [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0; |
| 376 | [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion( |
| 377 | const android::Region& region) = 0; |
| 378 | [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0; |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 379 | |
| 380 | // Composer HAL 2.3 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 381 | [[clang::warn_unused_result]] virtual hal::Error setColorTransform( |
| 382 | const android::mat4& matrix) = 0; |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 383 | |
| 384 | // Composer HAL 2.4 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 385 | [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata( |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 386 | 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] | 387 | }; |
| 388 | |
| 389 | namespace impl { |
| 390 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 391 | // Convenience C++ class to access per layer functions directly. |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 392 | |
| 393 | class Layer : public HWC2::Layer { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 394 | public: |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 395 | Layer(android::Hwc2::Composer& composer, |
| 396 | const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId displayId, |
| 397 | hal::HWLayerId layerId); |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 398 | ~Layer() override; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 399 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 400 | hal::HWLayerId getId() const override { return mId; } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 401 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 402 | hal::Error setCursorPosition(int32_t x, int32_t y) override; |
| 403 | hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer, |
| 404 | const android::sp<android::Fence>& acquireFence) override; |
| 405 | hal::Error setSurfaceDamage(const android::Region& damage) override; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 406 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 407 | hal::Error setBlendMode(hal::BlendMode mode) override; |
| 408 | hal::Error setColor(hal::Color color) override; |
| 409 | hal::Error setCompositionType(hal::Composition type) override; |
| 410 | hal::Error setDataspace(hal::Dataspace dataspace) override; |
| 411 | hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata, |
| 412 | const android::HdrMetadata& metadata) override; |
| 413 | hal::Error setDisplayFrame(const android::Rect& frame) override; |
| 414 | hal::Error setPlaneAlpha(float alpha) override; |
| 415 | hal::Error setSidebandStream(const native_handle_t* stream) override; |
| 416 | hal::Error setSourceCrop(const android::FloatRect& crop) override; |
| 417 | hal::Error setTransform(hal::Transform transform) override; |
| 418 | hal::Error setVisibleRegion(const android::Region& region) override; |
| 419 | hal::Error setZOrder(uint32_t z) override; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 420 | |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 421 | // Composer HAL 2.3 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 422 | hal::Error setColorTransform(const android::mat4& matrix) override; |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 423 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 424 | // Composer HAL 2.4 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 425 | hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory, |
| 426 | const std::vector<uint8_t>& value) override; |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 427 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 428 | private: |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 429 | // These are references to data owned by HWC2::Device, which will outlive |
| 430 | // this HWC2::Layer, so these references are guaranteed to be valid for |
| 431 | // the lifetime of this object. |
| 432 | android::Hwc2::Composer& mComposer; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 433 | const std::unordered_set<hal::Capability>& mCapabilities; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 434 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 435 | hal::HWDisplayId mDisplayId; |
| 436 | hal::HWLayerId mId; |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 437 | |
| 438 | // Cached HWC2 data, to ensure the same commands aren't sent to the HWC |
| 439 | // multiple times. |
| 440 | android::Region mVisibleRegion = android::Region::INVALID_REGION; |
| 441 | android::Region mDamageRegion = android::Region::INVALID_REGION; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 442 | hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN; |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 443 | android::HdrMetadata mHdrMetadata; |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 444 | android::mat4 mColorMatrix; |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 445 | uint32_t mBufferSlot; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 446 | }; |
| 447 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 448 | } // namespace impl |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 449 | } // namespace HWC2 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 450 | } // namespace android |