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