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