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