| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright 2015 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 | #ifndef ANDROID_SF_HWC2_H | 
 | 18 | #define ANDROID_SF_HWC2_H | 
 | 19 |  | 
 | 20 | #define HWC2_INCLUDE_STRINGIFICATION | 
 | 21 | #define HWC2_USE_CPP11 | 
 | 22 | #include <hardware/hwcomposer2.h> | 
 | 23 | #undef HWC2_INCLUDE_STRINGIFICATION | 
 | 24 | #undef HWC2_USE_CPP11 | 
 | 25 |  | 
| Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 26 | #include <gui/HdrMetadata.h> | 
| Mathias Agopian | 1d77b71 | 2017-02-17 15:46:13 -0800 | [diff] [blame] | 27 | #include <math/mat4.h> | 
| Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 28 | #include <ui/GraphicTypes.h> | 
| Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 29 | #include <ui/HdrCapabilities.h> | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 30 | #include <utils/Log.h> | 
 | 31 | #include <utils/StrongPointer.h> | 
 | 32 | #include <utils/Timers.h> | 
 | 33 |  | 
 | 34 | #include <functional> | 
 | 35 | #include <string> | 
 | 36 | #include <unordered_map> | 
| Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 37 | #include <unordered_set> | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 38 | #include <vector> | 
 | 39 |  | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 40 | #include "PowerAdvisor.h" | 
 | 41 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 42 | namespace android { | 
 | 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; | 
 | 46 |     class Rect; | 
 | 47 |     class Region; | 
| 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; | 
 | 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; | 
 | 75 |     virtual void onVsyncReceived(int32_t sequenceId, hwc2_display_t display, | 
 | 76 |                                  int64_t timestamp) = 0; | 
 | 77 |     virtual ~ComposerCallback() = default; | 
 | 78 | }; | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 79 |  | 
| Fabien Sanglard | 3396070 | 2016-11-29 17:58:21 -0800 | [diff] [blame] | 80 | // C++ Wrapper around hwc2_device_t. Load all functions pointers | 
 | 81 | // and handle callback registration. | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 82 | class Device | 
 | 83 | { | 
 | 84 | public: | 
| Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 85 |     explicit Device(std::unique_ptr<android::Hwc2::Composer> composer); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 86 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 87 |     void registerCallback(ComposerCallback* callback, int32_t sequenceId); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 88 |  | 
 | 89 |     // Required by HWC2 | 
 | 90 |  | 
 | 91 |     std::string dump() const; | 
 | 92 |  | 
| Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 93 |     const std::unordered_set<Capability>& getCapabilities() const { | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 94 |         return mCapabilities; | 
 | 95 |     }; | 
 | 96 |  | 
 | 97 |     uint32_t getMaxVirtualDisplayCount() const; | 
| Dominik Laskowski | 0954b1d | 2018-06-13 14:58:49 -0700 | [diff] [blame] | 98 |     Error getDisplayIdentificationData(hwc2_display_t hwcDisplayId, uint8_t* outPort, | 
 | 99 |                                        std::vector<uint8_t>* outData) const; | 
 | 100 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 101 |     Error createVirtualDisplay(uint32_t width, uint32_t height, | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 102 |             android::ui::PixelFormat* format, Display** outDisplay); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 103 |     void destroyDisplay(hwc2_display_t displayId); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 104 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 105 |     void onHotplug(hwc2_display_t displayId, Connection connection); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 106 |  | 
 | 107 |     // Other Device methods | 
 | 108 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 109 |     Display* getDisplayById(hwc2_display_t id); | 
| Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 110 |  | 
| Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 111 |     android::Hwc2::Composer* getComposer() { return mComposer.get(); } | 
| Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 112 |  | 
| Chia-I Wu | ae5a6b8 | 2017-10-10 09:09:22 -0700 | [diff] [blame] | 113 |     // We buffer most state changes and flush them implicitly with | 
 | 114 |     // Display::validate, Display::present, and Display::presentOrValidate. | 
 | 115 |     // This method provides an explicit way to flush state changes to HWC. | 
 | 116 |     Error flushCommands(); | 
 | 117 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 118 | private: | 
 | 119 |     // Initialization methods | 
 | 120 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 121 |     void loadCapabilities(); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 122 |  | 
 | 123 |     // Member variables | 
| Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 124 |     std::unique_ptr<android::Hwc2::Composer> mComposer; | 
| Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 125 |     std::unordered_set<Capability> mCapabilities; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 126 |     std::unordered_map<hwc2_display_t, std::unique_ptr<Display>> mDisplays; | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 127 |     android::Hwc2::impl::PowerAdvisor mPowerAdvisor; | 
| Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 128 |     bool mRegisteredCallback = false; | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 129 | }; | 
 | 130 |  | 
| Fabien Sanglard | 3396070 | 2016-11-29 17:58:21 -0800 | [diff] [blame] | 131 | // Convenience C++ class to access hwc2_device_t Display functions directly. | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 132 | class Display | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 133 | { | 
 | 134 | public: | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 135 |     Display(android::Hwc2::Composer& composer, android::Hwc2::PowerAdvisor& advisor, | 
 | 136 |             const std::unordered_set<Capability>& capabilities, | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 137 |             hwc2_display_t id, DisplayType type); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 138 |     ~Display(); | 
 | 139 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 140 |     class Config | 
 | 141 |     { | 
 | 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 |             } | 
 | 181 |  | 
 | 182 |         private: | 
 | 183 |             float getDefaultDensity(); | 
 | 184 |             std::shared_ptr<Config> mConfig; | 
 | 185 |         }; | 
 | 186 |  | 
 | 187 |         hwc2_display_t getDisplayId() const { return mDisplay.getId(); } | 
 | 188 |         hwc2_config_t getId() const { return mId; } | 
 | 189 |  | 
 | 190 |         int32_t getWidth() const { return mWidth; } | 
 | 191 |         int32_t getHeight() const { return mHeight; } | 
 | 192 |         nsecs_t getVsyncPeriod() const { return mVsyncPeriod; } | 
 | 193 |         float getDpiX() const { return mDpiX; } | 
 | 194 |         float getDpiY() const { return mDpiY; } | 
 | 195 |  | 
 | 196 |     private: | 
 | 197 |         Config(Display& display, hwc2_config_t id); | 
 | 198 |  | 
 | 199 |         Display& mDisplay; | 
 | 200 |         hwc2_config_t mId; | 
 | 201 |  | 
 | 202 |         int32_t mWidth; | 
 | 203 |         int32_t mHeight; | 
 | 204 |         nsecs_t mVsyncPeriod; | 
 | 205 |         float mDpiX; | 
 | 206 |         float mDpiY; | 
 | 207 |     }; | 
 | 208 |  | 
 | 209 |     // Required by HWC2 | 
 | 210 |  | 
 | 211 |     [[clang::warn_unused_result]] Error acceptChanges(); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 212 |     [[clang::warn_unused_result]] Error createLayer(Layer** outLayer); | 
 | 213 |     [[clang::warn_unused_result]] Error destroyLayer(Layer* layer); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 214 |     [[clang::warn_unused_result]] Error getActiveConfig( | 
 | 215 |             std::shared_ptr<const Config>* outConfig) const; | 
| Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 216 |     [[clang::warn_unused_result]] Error getActiveConfigIndex(int* outIndex) const; | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 217 |     [[clang::warn_unused_result]] Error getChangedCompositionTypes( | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 218 |             std::unordered_map<Layer*, Composition>* outTypes); | 
| Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 219 |     [[clang::warn_unused_result]] Error getColorModes( | 
| Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 220 |             std::vector<android::ui::ColorMode>* outModes) const; | 
| Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 221 |     // Returns a bitmask which contains HdrMetadata::Type::*. | 
 | 222 |     [[clang::warn_unused_result]] int32_t getSupportedPerFrameMetadata() const; | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 223 |     [[clang::warn_unused_result]] Error getRenderIntents( | 
 | 224 |             android::ui::ColorMode colorMode, | 
 | 225 |             std::vector<android::ui::RenderIntent>* outRenderIntents) const; | 
 | 226 |     [[clang::warn_unused_result]] Error getDataspaceSaturationMatrix( | 
 | 227 |             android::ui::Dataspace dataspace, android::mat4* outMatrix); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 228 |  | 
 | 229 |     // Doesn't call into the HWC2 device, so no errors are possible | 
 | 230 |     std::vector<std::shared_ptr<const Config>> getConfigs() const; | 
 | 231 |  | 
 | 232 |     [[clang::warn_unused_result]] Error getName(std::string* outName) const; | 
 | 233 |     [[clang::warn_unused_result]] Error getRequests( | 
 | 234 |             DisplayRequest* outDisplayRequests, | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 235 |             std::unordered_map<Layer*, LayerRequest>* outLayerRequests); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 236 |     [[clang::warn_unused_result]] Error getType(DisplayType* outType) const; | 
 | 237 |     [[clang::warn_unused_result]] Error supportsDoze(bool* outSupport) const; | 
| Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 238 |     [[clang::warn_unused_result]] Error getHdrCapabilities( | 
| Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 239 |             android::HdrCapabilities* outCapabilities) const; | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 240 |     [[clang::warn_unused_result]] Error getReleaseFences( | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 241 |             std::unordered_map<Layer*, | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 242 |                     android::sp<android::Fence>>* outFences) const; | 
 | 243 |     [[clang::warn_unused_result]] Error present( | 
| Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 244 |             android::sp<android::Fence>* outPresentFence); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 245 |     [[clang::warn_unused_result]] Error setActiveConfig( | 
 | 246 |             const std::shared_ptr<const Config>& config); | 
 | 247 |     [[clang::warn_unused_result]] Error setClientTarget( | 
| Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 248 |             uint32_t slot, const android::sp<android::GraphicBuffer>& target, | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 249 |             const android::sp<android::Fence>& acquireFence, | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 250 |             android::ui::Dataspace dataspace); | 
| Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 251 |     [[clang::warn_unused_result]] Error setColorMode( | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 252 |             android::ui::ColorMode mode, | 
 | 253 |             android::ui::RenderIntent renderIntent); | 
| Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 254 |     [[clang::warn_unused_result]] Error setColorTransform( | 
 | 255 |             const android::mat4& matrix, android_color_transform_t hint); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 256 |     [[clang::warn_unused_result]] Error setOutputBuffer( | 
 | 257 |             const android::sp<android::GraphicBuffer>& buffer, | 
 | 258 |             const android::sp<android::Fence>& releaseFence); | 
 | 259 |     [[clang::warn_unused_result]] Error setPowerMode(PowerMode mode); | 
 | 260 |     [[clang::warn_unused_result]] Error setVsyncEnabled(Vsync enabled); | 
 | 261 |     [[clang::warn_unused_result]] Error validate(uint32_t* outNumTypes, | 
 | 262 |             uint32_t* outNumRequests); | 
| Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 263 |     [[clang::warn_unused_result]] Error presentOrValidate(uint32_t* outNumTypes, | 
| Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 264 |             uint32_t* outNumRequests, | 
 | 265 |             android::sp<android::Fence>* outPresentFence, uint32_t* state); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 266 |  | 
 | 267 |     // Other Display methods | 
 | 268 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 269 |     hwc2_display_t getId() const { return mId; } | 
 | 270 |     bool isConnected() const { return mIsConnected; } | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 271 |     void setConnected(bool connected);  // For use by Device only | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 272 |  | 
 | 273 | private: | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 274 |     int32_t getAttribute(hwc2_config_t configId, Attribute attribute); | 
 | 275 |     void loadConfig(hwc2_config_t configId); | 
 | 276 |     void loadConfigs(); | 
 | 277 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 278 |     // This may fail (and return a null pointer) if no layer with this ID exists | 
 | 279 |     // on this display | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 280 |     Layer* getLayerById(hwc2_layer_t id) const; | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 281 |  | 
| Lloyd Pique | bc79209 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 282 |     friend android::TestableSurfaceFlinger; | 
 | 283 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 284 |     // Member variables | 
 | 285 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 286 |     // These are references to data owned by HWC2::Device, which will outlive | 
 | 287 |     // this HWC2::Display, so these references are guaranteed to be valid for | 
 | 288 |     // the lifetime of this object. | 
 | 289 |     android::Hwc2::Composer& mComposer; | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 290 |     android::Hwc2::PowerAdvisor& mPowerAdvisor; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 291 |     const std::unordered_set<Capability>& mCapabilities; | 
 | 292 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 293 |     hwc2_display_t mId; | 
 | 294 |     bool mIsConnected; | 
| Chris Forbes | 016d73c | 2017-04-11 10:04:31 -0700 | [diff] [blame] | 295 |     DisplayType mType; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 296 |     std::unordered_map<hwc2_layer_t, std::unique_ptr<Layer>> mLayers; | 
| Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 297 |     std::unordered_map<hwc2_config_t, std::shared_ptr<const Config>> mConfigs; | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 298 | }; | 
 | 299 |  | 
| Fabien Sanglard | 3396070 | 2016-11-29 17:58:21 -0800 | [diff] [blame] | 300 | // Convenience C++ class to access hwc2_device_t Layer functions directly. | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 301 | class Layer | 
 | 302 | { | 
 | 303 | public: | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 304 |     Layer(android::Hwc2::Composer& composer, | 
 | 305 |           const std::unordered_set<Capability>& capabilities, | 
 | 306 |           hwc2_display_t displayId, hwc2_layer_t layerId); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 307 |     ~Layer(); | 
 | 308 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 309 |     hwc2_layer_t getId() const { return mId; } | 
 | 310 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 311 |     // Register a listener to be notified when the layer is destroyed. When the | 
 | 312 |     // listener function is called, the Layer will be in the process of being | 
 | 313 |     // destroyed, so it's not safe to call methods on it. | 
 | 314 |     void setLayerDestroyedListener(std::function<void(Layer*)> listener); | 
 | 315 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 316 |     [[clang::warn_unused_result]] Error setCursorPosition(int32_t x, int32_t y); | 
| Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 317 |     [[clang::warn_unused_result]] Error setBuffer(uint32_t slot, | 
| Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 318 |             const android::sp<android::GraphicBuffer>& buffer, | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 319 |             const android::sp<android::Fence>& acquireFence); | 
 | 320 |     [[clang::warn_unused_result]] Error setSurfaceDamage( | 
 | 321 |             const android::Region& damage); | 
 | 322 |  | 
 | 323 |     [[clang::warn_unused_result]] Error setBlendMode(BlendMode mode); | 
 | 324 |     [[clang::warn_unused_result]] Error setColor(hwc_color_t color); | 
 | 325 |     [[clang::warn_unused_result]] Error setCompositionType(Composition type); | 
| Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 326 |     [[clang::warn_unused_result]] Error setDataspace( | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 327 |             android::ui::Dataspace dataspace); | 
| Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 328 |     [[clang::warn_unused_result]] Error setPerFrameMetadata( | 
 | 329 |             const int32_t supportedPerFrameMetadata, | 
 | 330 |             const android::HdrMetadata& metadata); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 331 |     [[clang::warn_unused_result]] Error setDisplayFrame( | 
 | 332 |             const android::Rect& frame); | 
 | 333 |     [[clang::warn_unused_result]] Error setPlaneAlpha(float alpha); | 
 | 334 |     [[clang::warn_unused_result]] Error setSidebandStream( | 
 | 335 |             const native_handle_t* stream); | 
 | 336 |     [[clang::warn_unused_result]] Error setSourceCrop( | 
| Dan Stoza | 5a423ea | 2017-02-16 14:10:39 -0800 | [diff] [blame] | 337 |             const android::FloatRect& crop); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 338 |     [[clang::warn_unused_result]] Error setTransform(Transform transform); | 
 | 339 |     [[clang::warn_unused_result]] Error setVisibleRegion( | 
 | 340 |             const android::Region& region); | 
 | 341 |     [[clang::warn_unused_result]] Error setZOrder(uint32_t z); | 
| Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 342 |     [[clang::warn_unused_result]] Error setInfo(uint32_t type, uint32_t appId); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 343 |  | 
 | 344 | private: | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 345 |     // These are references to data owned by HWC2::Device, which will outlive | 
 | 346 |     // this HWC2::Layer, so these references are guaranteed to be valid for | 
 | 347 |     // the lifetime of this object. | 
 | 348 |     android::Hwc2::Composer& mComposer; | 
 | 349 |     const std::unordered_set<Capability>& mCapabilities; | 
 | 350 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 351 |     hwc2_display_t mDisplayId; | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 352 |     hwc2_layer_t mId; | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 353 |     android::ui::Dataspace mDataSpace = android::ui::Dataspace::UNKNOWN; | 
| Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 354 |     android::HdrMetadata mHdrMetadata; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 355 |     std::function<void(Layer*)> mLayerDestroyedListener; | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 356 | }; | 
 | 357 |  | 
 | 358 | } // namespace HWC2 | 
 | 359 |  | 
 | 360 | #endif // ANDROID_SF_HWC2_H |