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