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