| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2010 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_HWCOMPOSER_H | 
|  | 18 | #define ANDROID_SF_HWCOMPOSER_H | 
|  | 19 |  | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 20 | #include <cstdint> | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 21 | #include <memory> | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 22 | #include <mutex> | 
| Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 23 | #include <optional> | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 24 | #include <unordered_map> | 
|  | 25 | #include <unordered_set> | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 26 | #include <vector> | 
|  | 27 |  | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 28 | #include <android-base/thread_annotations.h> | 
|  | 29 | #include <ui/Fence.h> | 
|  | 30 | #include <ui/GraphicTypes.h> | 
|  | 31 | #include <utils/StrongPointer.h> | 
|  | 32 | #include <utils/Timers.h> | 
|  | 33 |  | 
| Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 34 | #include "DisplayIdentification.h" | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 35 | #include "HWC2.h" | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 36 |  | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 37 | namespace android { | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 38 |  | 
| Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 39 | struct DisplayedFrameStats; | 
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 40 | class GraphicBuffer; | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 41 | class TestableSurfaceFlinger; | 
| David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 42 | struct CompositionInfo; | 
| Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 43 |  | 
| Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 44 | namespace Hwc2 { | 
|  | 45 | class Composer; | 
|  | 46 | } // namespace Hwc2 | 
|  | 47 |  | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 48 | namespace compositionengine { | 
|  | 49 | class Output; | 
|  | 50 | } // namespace compositionengine | 
|  | 51 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 52 | class HWComposer { | 
|  | 53 | public: | 
|  | 54 | virtual ~HWComposer(); | 
|  | 55 |  | 
|  | 56 | virtual void registerCallback(HWC2::ComposerCallback* callback, int32_t sequenceId) = 0; | 
|  | 57 |  | 
|  | 58 | virtual bool getDisplayIdentificationData(hwc2_display_t hwcDisplayId, uint8_t* outPort, | 
|  | 59 | DisplayIdentificationData* outData) const = 0; | 
|  | 60 |  | 
|  | 61 | virtual bool hasCapability(HWC2::Capability capability) const = 0; | 
|  | 62 | virtual bool hasDisplayCapability(const std::optional<DisplayId>& displayId, | 
|  | 63 | HWC2::DisplayCapability capability) const = 0; | 
|  | 64 |  | 
|  | 65 | // Attempts to allocate a virtual display and returns its ID if created on the HWC device. | 
|  | 66 | virtual std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height, | 
|  | 67 | ui::PixelFormat* format) = 0; | 
|  | 68 |  | 
|  | 69 | // Attempts to create a new layer on this display | 
|  | 70 | virtual HWC2::Layer* createLayer(DisplayId displayId) = 0; | 
|  | 71 | // Destroy a previously created layer | 
|  | 72 | virtual void destroyLayer(DisplayId displayId, HWC2::Layer* layer) = 0; | 
|  | 73 |  | 
|  | 74 | // Asks the HAL what it can do | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 75 | virtual status_t prepare(DisplayId displayId, const compositionengine::Output&) = 0; | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 76 |  | 
|  | 77 | virtual status_t setClientTarget(DisplayId displayId, uint32_t slot, | 
|  | 78 | const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target, | 
|  | 79 | ui::Dataspace dataspace) = 0; | 
|  | 80 |  | 
|  | 81 | // Present layers to the display and read releaseFences. | 
|  | 82 | virtual status_t presentAndGetReleaseFences(DisplayId displayId) = 0; | 
|  | 83 |  | 
|  | 84 | // set power mode | 
|  | 85 | virtual status_t setPowerMode(DisplayId displayId, int mode) = 0; | 
|  | 86 |  | 
|  | 87 | // set active config | 
|  | 88 | virtual status_t setActiveConfig(DisplayId displayId, size_t configId) = 0; | 
|  | 89 |  | 
|  | 90 | // Sets a color transform to be applied to the result of composition | 
|  | 91 | virtual status_t setColorTransform(DisplayId displayId, const mat4& transform) = 0; | 
|  | 92 |  | 
|  | 93 | // reset state when an external, non-virtual display is disconnected | 
|  | 94 | virtual void disconnectDisplay(DisplayId displayId) = 0; | 
|  | 95 |  | 
|  | 96 | // does this display have layers handled by HWC | 
|  | 97 | virtual bool hasDeviceComposition(const std::optional<DisplayId>& displayId) const = 0; | 
|  | 98 |  | 
|  | 99 | // does this display have pending request to flip client target | 
|  | 100 | virtual bool hasFlipClientTargetRequest(const std::optional<DisplayId>& displayId) const = 0; | 
|  | 101 |  | 
|  | 102 | // does this display have layers handled by GLES | 
|  | 103 | virtual bool hasClientComposition(const std::optional<DisplayId>& displayId) const = 0; | 
|  | 104 |  | 
|  | 105 | // get the present fence received from the last call to present. | 
|  | 106 | virtual sp<Fence> getPresentFence(DisplayId displayId) const = 0; | 
|  | 107 |  | 
|  | 108 | // Get last release fence for the given layer | 
|  | 109 | virtual sp<Fence> getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const = 0; | 
|  | 110 |  | 
|  | 111 | // Set the output buffer and acquire fence for a virtual display. | 
|  | 112 | // Returns INVALID_OPERATION if displayId is not a virtual display. | 
|  | 113 | virtual status_t setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence, | 
|  | 114 | const sp<GraphicBuffer>& buffer) = 0; | 
|  | 115 |  | 
|  | 116 | // After SurfaceFlinger has retrieved the release fences for all the frames, | 
|  | 117 | // it can call this to clear the shared pointers in the release fence map | 
|  | 118 | virtual void clearReleaseFences(DisplayId displayId) = 0; | 
|  | 119 |  | 
|  | 120 | // Fetches the HDR capabilities of the given display | 
|  | 121 | virtual status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) = 0; | 
|  | 122 |  | 
|  | 123 | virtual int32_t getSupportedPerFrameMetadata(DisplayId displayId) const = 0; | 
|  | 124 |  | 
|  | 125 | // Returns the available RenderIntent of the given display. | 
|  | 126 | virtual std::vector<ui::RenderIntent> getRenderIntents(DisplayId displayId, | 
|  | 127 | ui::ColorMode colorMode) const = 0; | 
|  | 128 |  | 
|  | 129 | virtual mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) = 0; | 
|  | 130 |  | 
|  | 131 | // Returns the attributes of the color sampling engine. | 
|  | 132 | virtual status_t getDisplayedContentSamplingAttributes(DisplayId displayId, | 
|  | 133 | ui::PixelFormat* outFormat, | 
|  | 134 | ui::Dataspace* outDataspace, | 
|  | 135 | uint8_t* outComponentMask) = 0; | 
|  | 136 | virtual status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled, | 
|  | 137 | uint8_t componentMask, | 
|  | 138 | uint64_t maxFrames) = 0; | 
|  | 139 | virtual status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, | 
|  | 140 | uint64_t timestamp, | 
|  | 141 | DisplayedFrameStats* outStats) = 0; | 
|  | 142 |  | 
| Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 143 | // Sets the brightness of a display. | 
|  | 144 | virtual status_t setDisplayBrightness(DisplayId displayId, float brightness) = 0; | 
|  | 145 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 146 | // Events handling --------------------------------------------------------- | 
|  | 147 |  | 
|  | 148 | // Returns stable display ID (and display name on connection of new or previously disconnected | 
|  | 149 | // display), or std::nullopt if hotplug event was ignored. | 
|  | 150 | virtual std::optional<DisplayIdentificationInfo> onHotplug(hwc2_display_t hwcDisplayId, | 
|  | 151 | HWC2::Connection connection) = 0; | 
|  | 152 |  | 
|  | 153 | virtual bool onVsync(hwc2_display_t hwcDisplayId, int64_t timestamp) = 0; | 
|  | 154 | virtual void setVsyncEnabled(DisplayId displayId, HWC2::Vsync enabled) = 0; | 
|  | 155 |  | 
|  | 156 | virtual nsecs_t getRefreshTimestamp(DisplayId displayId) const = 0; | 
|  | 157 | virtual bool isConnected(DisplayId displayId) const = 0; | 
|  | 158 |  | 
|  | 159 | // Non-const because it can update configMap inside of mDisplayData | 
|  | 160 | virtual std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs( | 
|  | 161 | DisplayId displayId) const = 0; | 
|  | 162 |  | 
|  | 163 | virtual std::shared_ptr<const HWC2::Display::Config> getActiveConfig( | 
|  | 164 | DisplayId displayId) const = 0; | 
|  | 165 | virtual int getActiveConfigIndex(DisplayId displayId) const = 0; | 
|  | 166 |  | 
|  | 167 | virtual std::vector<ui::ColorMode> getColorModes(DisplayId displayId) const = 0; | 
|  | 168 |  | 
|  | 169 | virtual status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode, | 
|  | 170 | ui::RenderIntent renderIntent) = 0; | 
|  | 171 |  | 
|  | 172 | virtual bool isUsingVrComposer() const = 0; | 
|  | 173 |  | 
|  | 174 | // for debugging ---------------------------------------------------------- | 
|  | 175 | virtual void dump(std::string& out) const = 0; | 
|  | 176 |  | 
|  | 177 | virtual Hwc2::Composer* getComposer() const = 0; | 
|  | 178 |  | 
|  | 179 | // TODO(b/74619554): Remove special cases for internal/external display. | 
|  | 180 | virtual std::optional<hwc2_display_t> getInternalHwcDisplayId() const = 0; | 
|  | 181 | virtual std::optional<hwc2_display_t> getExternalHwcDisplayId() const = 0; | 
|  | 182 |  | 
|  | 183 | virtual std::optional<DisplayId> toPhysicalDisplayId(hwc2_display_t hwcDisplayId) const = 0; | 
|  | 184 | virtual std::optional<hwc2_display_t> fromPhysicalDisplayId(DisplayId displayId) const = 0; | 
|  | 185 | }; | 
|  | 186 |  | 
|  | 187 | namespace impl { | 
|  | 188 |  | 
|  | 189 | class HWComposer final : public android::HWComposer { | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 190 | public: | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 191 | explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer); | 
| Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 192 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 193 | ~HWComposer() override; | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 194 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 195 | void registerCallback(HWC2::ComposerCallback* callback, int32_t sequenceId) override; | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 196 |  | 
| Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 197 | bool getDisplayIdentificationData(hwc2_display_t hwcDisplayId, uint8_t* outPort, | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 198 | DisplayIdentificationData* outData) const override; | 
| Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 199 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 200 | bool hasCapability(HWC2::Capability capability) const override; | 
| Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 201 | bool hasDisplayCapability(const std::optional<DisplayId>& displayId, | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 202 | HWC2::DisplayCapability capability) const override; | 
| Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 203 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 204 | // Attempts to allocate a virtual display and returns its ID if created on the HWC device. | 
|  | 205 | std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height, | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 206 | ui::PixelFormat* format) override; | 
| Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 207 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 208 | // Attempts to create a new layer on this display | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 209 | HWC2::Layer* createLayer(DisplayId displayId) override; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 210 | // Destroy a previously created layer | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 211 | void destroyLayer(DisplayId displayId, HWC2::Layer* layer) override; | 
| Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 212 |  | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 213 | // Asks the HAL what it can do | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 214 | status_t prepare(DisplayId displayId, const compositionengine::Output&) override; | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 215 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 216 | status_t setClientTarget(DisplayId displayId, uint32_t slot, const sp<Fence>& acquireFence, | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 217 | const sp<GraphicBuffer>& target, ui::Dataspace dataspace) override; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 218 |  | 
| Fabien Sanglard | a87aa7b | 2016-11-30 16:27:22 -0800 | [diff] [blame] | 219 | // Present layers to the display and read releaseFences. | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 220 | status_t presentAndGetReleaseFences(DisplayId displayId) override; | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 221 |  | 
| Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 222 | // set power mode | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 223 | status_t setPowerMode(DisplayId displayId, int mode) override; | 
| Colin Cross | 10fbdb6 | 2012-07-12 17:56:34 -0700 | [diff] [blame] | 224 |  | 
| Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 225 | // set active config | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 226 | status_t setActiveConfig(DisplayId displayId, size_t configId) override; | 
| Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 227 |  | 
| Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 228 | // Sets a color transform to be applied to the result of composition | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 229 | status_t setColorTransform(DisplayId displayId, const mat4& transform) override; | 
| Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 230 |  | 
| Andy McFadden | 27ec573 | 2012-10-02 19:04:45 -0700 | [diff] [blame] | 231 | // reset state when an external, non-virtual display is disconnected | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 232 | void disconnectDisplay(DisplayId displayId) override; | 
| Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 233 |  | 
| Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 234 | // does this display have layers handled by HWC | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 235 | bool hasDeviceComposition(const std::optional<DisplayId>& displayId) const override; | 
| Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 236 |  | 
| Madhuri Athota | 88a905b | 2017-05-04 16:58:15 +0530 | [diff] [blame] | 237 | // does this display have pending request to flip client target | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 238 | bool hasFlipClientTargetRequest(const std::optional<DisplayId>& displayId) const override; | 
| Madhuri Athota | 88a905b | 2017-05-04 16:58:15 +0530 | [diff] [blame] | 239 |  | 
| Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 240 | // does this display have layers handled by GLES | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 241 | bool hasClientComposition(const std::optional<DisplayId>& displayId) const override; | 
| Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 242 |  | 
| Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 243 | // get the present fence received from the last call to present. | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 244 | sp<Fence> getPresentFence(DisplayId displayId) const override; | 
| Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 245 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 246 | // Get last release fence for the given layer | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 247 | sp<Fence> getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const override; | 
| Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 248 |  | 
| Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 249 | // Set the output buffer and acquire fence for a virtual display. | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 250 | // Returns INVALID_OPERATION if displayId is not a virtual display. | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 251 | status_t setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence, | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 252 | const sp<GraphicBuffer>& buffer) override; | 
| Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 253 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 254 | // After SurfaceFlinger has retrieved the release fences for all the frames, | 
|  | 255 | // it can call this to clear the shared pointers in the release fence map | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 256 | void clearReleaseFences(DisplayId displayId) override; | 
| Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 257 |  | 
| Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 258 | // Fetches the HDR capabilities of the given display | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 259 | status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) override; | 
| Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 260 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 261 | int32_t getSupportedPerFrameMetadata(DisplayId displayId) const override; | 
| Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 262 |  | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 263 | // Returns the available RenderIntent of the given display. | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 264 | std::vector<ui::RenderIntent> getRenderIntents(DisplayId displayId, | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 265 | ui::ColorMode colorMode) const override; | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 266 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 267 | mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) override; | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 268 |  | 
| Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 269 | // Returns the attributes of the color sampling engine. | 
|  | 270 | status_t getDisplayedContentSamplingAttributes(DisplayId displayId, ui::PixelFormat* outFormat, | 
|  | 271 | ui::Dataspace* outDataspace, | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 272 | uint8_t* outComponentMask) override; | 
| Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 273 | status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled, | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 274 | uint8_t componentMask, uint64_t maxFrames) override; | 
| Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 275 | status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, uint64_t timestamp, | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 276 | DisplayedFrameStats* outStats) override; | 
| Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 277 | status_t setDisplayBrightness(DisplayId displayId, float brightness) override; | 
| Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 278 |  | 
| Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 279 | // Events handling --------------------------------------------------------- | 
|  | 280 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 281 | // Returns stable display ID (and display name on connection of new or previously disconnected | 
|  | 282 | // display), or std::nullopt if hotplug event was ignored. | 
|  | 283 | std::optional<DisplayIdentificationInfo> onHotplug(hwc2_display_t hwcDisplayId, | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 284 | HWC2::Connection connection) override; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 285 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 286 | bool onVsync(hwc2_display_t hwcDisplayId, int64_t timestamp) override; | 
|  | 287 | void setVsyncEnabled(DisplayId displayId, HWC2::Vsync enabled) override; | 
| Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 288 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 289 | nsecs_t getRefreshTimestamp(DisplayId displayId) const override; | 
|  | 290 | bool isConnected(DisplayId displayId) const override; | 
| Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 291 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 292 | // Non-const because it can update configMap inside of mDisplayData | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 293 | std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs( | 
|  | 294 | DisplayId displayId) const override; | 
| Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 295 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 296 | std::shared_ptr<const HWC2::Display::Config> getActiveConfig( | 
|  | 297 | DisplayId displayId) const override; | 
|  | 298 | int getActiveConfigIndex(DisplayId displayId) const override; | 
| Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 299 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 300 | std::vector<ui::ColorMode> getColorModes(DisplayId displayId) const override; | 
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 301 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 302 | status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode, | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 303 | ui::RenderIntent renderIntent) override; | 
| Courtney Goeltzenleuchter | fad9d8c | 2016-06-23 11:49:50 -0600 | [diff] [blame] | 304 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 305 | bool isUsingVrComposer() const override; | 
| Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 306 |  | 
| Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 307 | // for debugging ---------------------------------------------------------- | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 308 | void dump(std::string& out) const override; | 
| Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 309 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 310 | Hwc2::Composer* getComposer() const override { return mHwcDevice->getComposer(); } | 
| Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 311 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 312 | // TODO(b/74619554): Remove special cases for internal/external display. | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 313 | std::optional<hwc2_display_t> getInternalHwcDisplayId() const override { | 
|  | 314 | return mInternalHwcDisplayId; | 
|  | 315 | } | 
|  | 316 | std::optional<hwc2_display_t> getExternalHwcDisplayId() const override { | 
|  | 317 | return mExternalHwcDisplayId; | 
|  | 318 | } | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 319 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 320 | std::optional<DisplayId> toPhysicalDisplayId(hwc2_display_t hwcDisplayId) const override; | 
|  | 321 | std::optional<hwc2_display_t> fromPhysicalDisplayId(DisplayId displayId) const override; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 322 |  | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 323 | private: | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 324 | // For unit tests | 
|  | 325 | friend TestableSurfaceFlinger; | 
|  | 326 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 327 | std::optional<DisplayIdentificationInfo> onHotplugConnect(hwc2_display_t hwcDisplayId); | 
|  | 328 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 329 | static void validateChange(HWC2::Composition from, HWC2::Composition to); | 
| Mathias Agopian | 31d2843 | 2012-04-03 16:31:39 -0700 | [diff] [blame] | 330 |  | 
| Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 331 | struct DisplayData { | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 332 | bool isVirtual = false; | 
| Dominik Laskowski | f9750f2 | 2018-06-06 12:24:53 -0700 | [diff] [blame] | 333 | bool hasClientComposition = false; | 
|  | 334 | bool hasDeviceComposition = false; | 
|  | 335 | HWC2::Display* hwcDisplay = nullptr; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 336 | HWC2::DisplayRequest displayRequests; | 
| Dominik Laskowski | f9750f2 | 2018-06-06 12:24:53 -0700 | [diff] [blame] | 337 | sp<Fence> lastPresentFence = Fence::NO_FENCE; // signals when the last set op retires | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 338 | std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences; | 
| Dominik Laskowski | f9750f2 | 2018-06-06 12:24:53 -0700 | [diff] [blame] | 339 | buffer_handle_t outbufHandle = nullptr; | 
|  | 340 | sp<Fence> outbufAcquireFence = Fence::NO_FENCE; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 341 | mutable std::unordered_map<int32_t, | 
|  | 342 | std::shared_ptr<const HWC2::Display::Config>> configMap; | 
| Jamie Gennis | 2ec3e07 | 2012-11-11 16:24:33 -0800 | [diff] [blame] | 343 |  | 
| Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 344 | bool validateWasSkipped; | 
|  | 345 | HWC2::Error presentError; | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 346 |  | 
|  | 347 | bool vsyncTraceToggle = false; | 
|  | 348 |  | 
|  | 349 | std::mutex vsyncEnabledLock; | 
|  | 350 | HWC2::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = HWC2::Vsync::Disable; | 
|  | 351 |  | 
|  | 352 | mutable std::mutex lastHwVsyncLock; | 
|  | 353 | nsecs_t lastHwVsync GUARDED_BY(lastHwVsyncLock) = 0; | 
| Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 354 | }; | 
|  | 355 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 356 | std::unordered_map<DisplayId, DisplayData> mDisplayData; | 
| Dominik Laskowski | b04f98a | 2018-11-07 21:07:16 -0800 | [diff] [blame] | 357 |  | 
|  | 358 | // This must be destroyed before mDisplayData, because destructor may call back into HWComposer | 
|  | 359 | // and look up DisplayData. | 
|  | 360 | std::unique_ptr<HWC2::Device> mHwcDevice; | 
|  | 361 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 362 | std::unordered_map<hwc2_display_t, DisplayId> mPhysicalDisplayIdMap; | 
|  | 363 | std::optional<hwc2_display_t> mInternalHwcDisplayId; | 
|  | 364 | std::optional<hwc2_display_t> mExternalHwcDisplayId; | 
|  | 365 | bool mHasMultiDisplaySupport = false; | 
|  | 366 |  | 
| Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 367 | std::unordered_set<DisplayId> mFreeVirtualDisplayIds; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 368 | uint32_t mNextVirtualDisplayId = 0; | 
| Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 369 | uint32_t mRemainingHwcVirtualDisplays{mHwcDevice->getMaxVirtualDisplayCount()}; | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 370 | }; | 
|  | 371 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 372 | } // namespace impl | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 373 | } // namespace android | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 374 |  | 
|  | 375 | #endif // ANDROID_SF_HWCOMPOSER_H |