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> |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 30 | |
| 31 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 32 | #pragma clang diagnostic push |
| 33 | #pragma clang diagnostic ignored "-Wconversion" |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 34 | #include <ui/GraphicTypes.h> |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 35 | #pragma clang diagnostic pop |
| 36 | |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 37 | #include <utils/StrongPointer.h> |
| 38 | #include <utils/Timers.h> |
| 39 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 40 | #include "DisplayIdentification.h" |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 41 | #include "HWC2.h" |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 42 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 43 | namespace android { |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 44 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 45 | struct DisplayedFrameStats; |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 46 | class GraphicBuffer; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 47 | class TestableSurfaceFlinger; |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 48 | struct CompositionInfo; |
Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 49 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 50 | namespace Hwc2 { |
| 51 | class Composer; |
| 52 | } // namespace Hwc2 |
| 53 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 54 | namespace compositionengine { |
| 55 | class Output; |
| 56 | } // namespace compositionengine |
| 57 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 58 | struct KnownHWCGenericLayerMetadata { |
| 59 | const char* name; |
| 60 | const uint32_t id; |
| 61 | }; |
| 62 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 63 | class HWComposer { |
| 64 | public: |
| 65 | virtual ~HWComposer(); |
| 66 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 67 | virtual void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 68 | |
| 69 | virtual bool getDisplayIdentificationData(hwc2_display_t hwcDisplayId, uint8_t* outPort, |
| 70 | DisplayIdentificationData* outData) const = 0; |
| 71 | |
| 72 | virtual bool hasCapability(HWC2::Capability capability) const = 0; |
Dominik Laskowski | 1162e47 | 2020-04-02 19:02:47 -0700 | [diff] [blame] | 73 | virtual bool hasDisplayCapability(DisplayId displayId, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 74 | HWC2::DisplayCapability capability) const = 0; |
| 75 | |
| 76 | // Attempts to allocate a virtual display and returns its ID if created on the HWC device. |
| 77 | virtual std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height, |
| 78 | ui::PixelFormat* format) = 0; |
| 79 | |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 80 | virtual void allocatePhysicalDisplay(hwc2_display_t hwcDisplayId, DisplayId displayId) = 0; |
| 81 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 82 | // Attempts to create a new layer on this display |
| 83 | virtual HWC2::Layer* createLayer(DisplayId displayId) = 0; |
| 84 | // Destroy a previously created layer |
| 85 | virtual void destroyLayer(DisplayId displayId, HWC2::Layer* layer) = 0; |
| 86 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 87 | struct DeviceRequestedChanges { |
| 88 | using ChangedTypes = std::unordered_map<HWC2::Layer*, HWC2::Composition>; |
| 89 | using DisplayRequests = HWC2::DisplayRequest; |
| 90 | using LayerRequests = std::unordered_map<HWC2::Layer*, HWC2::LayerRequest>; |
| 91 | |
| 92 | ChangedTypes changedTypes; |
| 93 | DisplayRequests displayRequests; |
| 94 | LayerRequests layerRequests; |
| 95 | }; |
| 96 | |
| 97 | // Gets any required composition change requests from the HWC device. |
| 98 | // |
| 99 | // Note that frameUsesClientComposition must be set correctly based on |
| 100 | // whether the current frame appears to use client composition. If it is |
| 101 | // false some internal optimizations are allowed to present the display |
| 102 | // with fewer handshakes, but this does not work if client composition is |
| 103 | // expected. |
| 104 | virtual status_t getDeviceCompositionChanges( |
| 105 | DisplayId, bool frameUsesClientComposition, |
| 106 | std::optional<DeviceRequestedChanges>* outChanges) = 0; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 107 | |
| 108 | virtual status_t setClientTarget(DisplayId displayId, uint32_t slot, |
| 109 | const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target, |
| 110 | ui::Dataspace dataspace) = 0; |
| 111 | |
| 112 | // Present layers to the display and read releaseFences. |
| 113 | virtual status_t presentAndGetReleaseFences(DisplayId displayId) = 0; |
| 114 | |
| 115 | // set power mode |
| 116 | virtual status_t setPowerMode(DisplayId displayId, int mode) = 0; |
| 117 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 118 | // Sets a color transform to be applied to the result of composition |
| 119 | virtual status_t setColorTransform(DisplayId displayId, const mat4& transform) = 0; |
| 120 | |
| 121 | // reset state when an external, non-virtual display is disconnected |
| 122 | virtual void disconnectDisplay(DisplayId displayId) = 0; |
| 123 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 124 | // get the present fence received from the last call to present. |
| 125 | virtual sp<Fence> getPresentFence(DisplayId displayId) const = 0; |
| 126 | |
| 127 | // Get last release fence for the given layer |
| 128 | virtual sp<Fence> getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const = 0; |
| 129 | |
| 130 | // Set the output buffer and acquire fence for a virtual display. |
| 131 | // Returns INVALID_OPERATION if displayId is not a virtual display. |
| 132 | virtual status_t setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence, |
| 133 | const sp<GraphicBuffer>& buffer) = 0; |
| 134 | |
| 135 | // After SurfaceFlinger has retrieved the release fences for all the frames, |
| 136 | // it can call this to clear the shared pointers in the release fence map |
| 137 | virtual void clearReleaseFences(DisplayId displayId) = 0; |
| 138 | |
| 139 | // Fetches the HDR capabilities of the given display |
| 140 | virtual status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) = 0; |
| 141 | |
| 142 | virtual int32_t getSupportedPerFrameMetadata(DisplayId displayId) const = 0; |
| 143 | |
| 144 | // Returns the available RenderIntent of the given display. |
| 145 | virtual std::vector<ui::RenderIntent> getRenderIntents(DisplayId displayId, |
| 146 | ui::ColorMode colorMode) const = 0; |
| 147 | |
| 148 | virtual mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) = 0; |
| 149 | |
| 150 | // Returns the attributes of the color sampling engine. |
| 151 | virtual status_t getDisplayedContentSamplingAttributes(DisplayId displayId, |
| 152 | ui::PixelFormat* outFormat, |
| 153 | ui::Dataspace* outDataspace, |
| 154 | uint8_t* outComponentMask) = 0; |
| 155 | virtual status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled, |
| 156 | uint8_t componentMask, |
| 157 | uint64_t maxFrames) = 0; |
| 158 | virtual status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, |
| 159 | uint64_t timestamp, |
| 160 | DisplayedFrameStats* outStats) = 0; |
| 161 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 162 | // Sets the brightness of a display. |
| 163 | virtual status_t setDisplayBrightness(DisplayId displayId, float brightness) = 0; |
| 164 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 165 | // Events handling --------------------------------------------------------- |
| 166 | |
| 167 | // Returns stable display ID (and display name on connection of new or previously disconnected |
| 168 | // display), or std::nullopt if hotplug event was ignored. |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 169 | // This function is called from SurfaceFlinger. |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 170 | virtual std::optional<DisplayIdentificationInfo> onHotplug(hwc2_display_t hwcDisplayId, |
| 171 | HWC2::Connection connection) = 0; |
| 172 | |
| 173 | virtual bool onVsync(hwc2_display_t hwcDisplayId, int64_t timestamp) = 0; |
| 174 | virtual void setVsyncEnabled(DisplayId displayId, HWC2::Vsync enabled) = 0; |
| 175 | |
| 176 | virtual nsecs_t getRefreshTimestamp(DisplayId displayId) const = 0; |
| 177 | virtual bool isConnected(DisplayId displayId) const = 0; |
| 178 | |
| 179 | // Non-const because it can update configMap inside of mDisplayData |
| 180 | virtual std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs( |
| 181 | DisplayId displayId) const = 0; |
| 182 | |
| 183 | virtual std::shared_ptr<const HWC2::Display::Config> getActiveConfig( |
| 184 | DisplayId displayId) const = 0; |
| 185 | virtual int getActiveConfigIndex(DisplayId displayId) const = 0; |
| 186 | |
| 187 | virtual std::vector<ui::ColorMode> getColorModes(DisplayId displayId) const = 0; |
| 188 | |
| 189 | virtual status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode, |
| 190 | ui::RenderIntent renderIntent) = 0; |
| 191 | |
| 192 | virtual bool isUsingVrComposer() const = 0; |
| 193 | |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 194 | // Composer 2.4 |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 195 | virtual DisplayConnectionType getDisplayConnectionType(DisplayId) const = 0; |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 196 | virtual bool isVsyncPeriodSwitchSupported(DisplayId displayId) const = 0; |
| 197 | virtual nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const = 0; |
| 198 | virtual status_t setActiveConfigWithConstraints( |
| 199 | DisplayId displayId, size_t configId, |
| 200 | const HWC2::VsyncPeriodChangeConstraints& constraints, |
| 201 | HWC2::VsyncPeriodChangeTimeline* outTimeline) = 0; |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 202 | virtual status_t setAutoLowLatencyMode(DisplayId displayId, bool on) = 0; |
| 203 | virtual status_t getSupportedContentTypes( |
| 204 | DisplayId displayId, std::vector<HWC2::ContentType>* outSupportedContentTypes) = 0; |
| 205 | virtual status_t setContentType(DisplayId displayId, HWC2::ContentType contentType) = 0; |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 206 | virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() |
| 207 | const = 0; |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 208 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 209 | // for debugging ---------------------------------------------------------- |
| 210 | virtual void dump(std::string& out) const = 0; |
| 211 | |
| 212 | virtual Hwc2::Composer* getComposer() const = 0; |
| 213 | |
| 214 | // TODO(b/74619554): Remove special cases for internal/external display. |
| 215 | virtual std::optional<hwc2_display_t> getInternalHwcDisplayId() const = 0; |
| 216 | virtual std::optional<hwc2_display_t> getExternalHwcDisplayId() const = 0; |
| 217 | |
| 218 | virtual std::optional<DisplayId> toPhysicalDisplayId(hwc2_display_t hwcDisplayId) const = 0; |
| 219 | virtual std::optional<hwc2_display_t> fromPhysicalDisplayId(DisplayId displayId) const = 0; |
| 220 | }; |
| 221 | |
| 222 | namespace impl { |
| 223 | |
| 224 | class HWComposer final : public android::HWComposer { |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 225 | public: |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 226 | explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer); |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 227 | explicit HWComposer(const std::string& composerServiceName); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 228 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 229 | ~HWComposer() override; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 230 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 231 | void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 232 | |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 233 | bool getDisplayIdentificationData(hwc2_display_t hwcDisplayId, uint8_t* outPort, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 234 | DisplayIdentificationData* outData) const override; |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 235 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 236 | bool hasCapability(HWC2::Capability capability) const override; |
Dominik Laskowski | 1162e47 | 2020-04-02 19:02:47 -0700 | [diff] [blame] | 237 | bool hasDisplayCapability(DisplayId displayId, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 238 | HWC2::DisplayCapability capability) const override; |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 239 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 240 | // Attempts to allocate a virtual display and returns its ID if created on the HWC device. |
| 241 | std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 242 | ui::PixelFormat* format) override; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 243 | |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 244 | // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated. |
| 245 | void allocatePhysicalDisplay(hwc2_display_t hwcDisplayId, DisplayId displayId) override; |
| 246 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 247 | // Attempts to create a new layer on this display |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 248 | HWC2::Layer* createLayer(DisplayId displayId) override; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 249 | // Destroy a previously created layer |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 250 | void destroyLayer(DisplayId displayId, HWC2::Layer* layer) override; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 251 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 252 | status_t getDeviceCompositionChanges( |
| 253 | DisplayId, bool frameUsesClientComposition, |
| 254 | std::optional<DeviceRequestedChanges>* outChanges) override; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 255 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 256 | status_t setClientTarget(DisplayId displayId, uint32_t slot, const sp<Fence>& acquireFence, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 257 | const sp<GraphicBuffer>& target, ui::Dataspace dataspace) override; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 258 | |
Fabien Sanglard | a87aa7b | 2016-11-30 16:27:22 -0800 | [diff] [blame] | 259 | // Present layers to the display and read releaseFences. |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 260 | status_t presentAndGetReleaseFences(DisplayId displayId) override; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 261 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 262 | // set power mode |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 263 | status_t setPowerMode(DisplayId displayId, int mode) override; |
Colin Cross | 10fbdb6 | 2012-07-12 17:56:34 -0700 | [diff] [blame] | 264 | |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 265 | // Sets a color transform to be applied to the result of composition |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 266 | status_t setColorTransform(DisplayId displayId, const mat4& transform) override; |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 267 | |
Andy McFadden | 27ec573 | 2012-10-02 19:04:45 -0700 | [diff] [blame] | 268 | // reset state when an external, non-virtual display is disconnected |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 269 | void disconnectDisplay(DisplayId displayId) override; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 270 | |
Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 271 | // get the present fence received from the last call to present. |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 272 | sp<Fence> getPresentFence(DisplayId displayId) const override; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 273 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 274 | // Get last release fence for the given layer |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 275 | sp<Fence> getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const override; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 276 | |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 277 | // Set the output buffer and acquire fence for a virtual display. |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 278 | // Returns INVALID_OPERATION if displayId is not a virtual display. |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 279 | status_t setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 280 | const sp<GraphicBuffer>& buffer) override; |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 281 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 282 | // After SurfaceFlinger has retrieved the release fences for all the frames, |
| 283 | // 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] | 284 | void clearReleaseFences(DisplayId displayId) override; |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 285 | |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 286 | // Fetches the HDR capabilities of the given display |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 287 | status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) override; |
Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 288 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 289 | int32_t getSupportedPerFrameMetadata(DisplayId displayId) const override; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 290 | |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 291 | // Returns the available RenderIntent of the given display. |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 292 | std::vector<ui::RenderIntent> getRenderIntents(DisplayId displayId, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 293 | ui::ColorMode colorMode) const override; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 294 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 295 | mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) override; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 296 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 297 | // Returns the attributes of the color sampling engine. |
| 298 | status_t getDisplayedContentSamplingAttributes(DisplayId displayId, ui::PixelFormat* outFormat, |
| 299 | ui::Dataspace* outDataspace, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 300 | uint8_t* outComponentMask) override; |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 301 | status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 302 | uint8_t componentMask, uint64_t maxFrames) override; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 303 | status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, uint64_t timestamp, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 304 | DisplayedFrameStats* outStats) override; |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 305 | status_t setDisplayBrightness(DisplayId displayId, float brightness) override; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 306 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 307 | // Events handling --------------------------------------------------------- |
| 308 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 309 | // Returns stable display ID (and display name on connection of new or previously disconnected |
| 310 | // display), or std::nullopt if hotplug event was ignored. |
| 311 | std::optional<DisplayIdentificationInfo> onHotplug(hwc2_display_t hwcDisplayId, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 312 | HWC2::Connection connection) override; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 313 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 314 | bool onVsync(hwc2_display_t hwcDisplayId, int64_t timestamp) override; |
| 315 | void setVsyncEnabled(DisplayId displayId, HWC2::Vsync enabled) override; |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 316 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 317 | nsecs_t getRefreshTimestamp(DisplayId displayId) const override; |
| 318 | bool isConnected(DisplayId displayId) const override; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 319 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 320 | // Non-const because it can update configMap inside of mDisplayData |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 321 | std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs( |
| 322 | DisplayId displayId) const override; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 323 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 324 | std::shared_ptr<const HWC2::Display::Config> getActiveConfig( |
| 325 | DisplayId displayId) const override; |
| 326 | int getActiveConfigIndex(DisplayId displayId) const override; |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 327 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 328 | std::vector<ui::ColorMode> getColorModes(DisplayId displayId) const override; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 329 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 330 | status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode, |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 331 | ui::RenderIntent renderIntent) override; |
Courtney Goeltzenleuchter | fad9d8c | 2016-06-23 11:49:50 -0600 | [diff] [blame] | 332 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 333 | bool isUsingVrComposer() const override; |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 334 | |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 335 | // Composer 2.4 |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 336 | DisplayConnectionType getDisplayConnectionType(DisplayId) const override; |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 337 | bool isVsyncPeriodSwitchSupported(DisplayId displayId) const override; |
| 338 | nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const override; |
| 339 | status_t setActiveConfigWithConstraints(DisplayId displayId, size_t configId, |
| 340 | const HWC2::VsyncPeriodChangeConstraints& constraints, |
| 341 | HWC2::VsyncPeriodChangeTimeline* outTimeline) override; |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 342 | status_t setAutoLowLatencyMode(DisplayId displayId, bool) override; |
| 343 | status_t getSupportedContentTypes(DisplayId displayId, |
| 344 | std::vector<HWC2::ContentType>*) override; |
| 345 | status_t setContentType(DisplayId displayId, HWC2::ContentType) override; |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 346 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 347 | const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override; |
| 348 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 349 | // for debugging ---------------------------------------------------------- |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 350 | void dump(std::string& out) const override; |
Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 351 | |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 352 | Hwc2::Composer* getComposer() const override { return mComposer.get(); } |
Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 353 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 354 | // TODO(b/74619554): Remove special cases for internal/external display. |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 355 | std::optional<hwc2_display_t> getInternalHwcDisplayId() const override { |
| 356 | return mInternalHwcDisplayId; |
| 357 | } |
| 358 | std::optional<hwc2_display_t> getExternalHwcDisplayId() const override { |
| 359 | return mExternalHwcDisplayId; |
| 360 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 361 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 362 | std::optional<DisplayId> toPhysicalDisplayId(hwc2_display_t hwcDisplayId) const override; |
| 363 | std::optional<hwc2_display_t> fromPhysicalDisplayId(DisplayId displayId) const override; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 364 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 365 | private: |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 366 | // For unit tests |
| 367 | friend TestableSurfaceFlinger; |
| 368 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 369 | std::optional<DisplayIdentificationInfo> onHotplugConnect(hwc2_display_t hwcDisplayId); |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 370 | std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hwc2_display_t hwcDisplayId); |
| 371 | bool shouldIgnoreHotplugConnect(hwc2_display_t hwcDisplayId, |
| 372 | bool hasDisplayIdentificationData) const; |
| 373 | |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 374 | void loadCapabilities(); |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 375 | void loadLayerMetadataSupport(); |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 376 | uint32_t getMaxVirtualDisplayCount() const; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 377 | |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 378 | struct DisplayData { |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 379 | bool isVirtual = false; |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 380 | std::unique_ptr<HWC2::Display> hwcDisplay; |
Dominik Laskowski | f9750f2 | 2018-06-06 12:24:53 -0700 | [diff] [blame] | 381 | 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] | 382 | std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences; |
Dominik Laskowski | f9750f2 | 2018-06-06 12:24:53 -0700 | [diff] [blame] | 383 | buffer_handle_t outbufHandle = nullptr; |
| 384 | sp<Fence> outbufAcquireFence = Fence::NO_FENCE; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 385 | mutable std::unordered_map<int32_t, |
| 386 | std::shared_ptr<const HWC2::Display::Config>> configMap; |
Jamie Gennis | 2ec3e07 | 2012-11-11 16:24:33 -0800 | [diff] [blame] | 387 | |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 388 | bool validateWasSkipped; |
| 389 | HWC2::Error presentError; |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 390 | |
| 391 | bool vsyncTraceToggle = false; |
| 392 | |
| 393 | std::mutex vsyncEnabledLock; |
| 394 | HWC2::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = HWC2::Vsync::Disable; |
| 395 | |
| 396 | mutable std::mutex lastHwVsyncLock; |
| 397 | nsecs_t lastHwVsync GUARDED_BY(lastHwVsyncLock) = 0; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 398 | }; |
| 399 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 400 | std::unordered_map<DisplayId, DisplayData> mDisplayData; |
Dominik Laskowski | b04f98a | 2018-11-07 21:07:16 -0800 | [diff] [blame] | 401 | |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 402 | std::unique_ptr<android::Hwc2::Composer> mComposer; |
| 403 | std::unordered_set<HWC2::Capability> mCapabilities; |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 404 | std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata; |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 405 | bool mRegisteredCallback = false; |
Dominik Laskowski | b04f98a | 2018-11-07 21:07:16 -0800 | [diff] [blame] | 406 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 407 | std::unordered_map<hwc2_display_t, DisplayId> mPhysicalDisplayIdMap; |
| 408 | std::optional<hwc2_display_t> mInternalHwcDisplayId; |
| 409 | std::optional<hwc2_display_t> mExternalHwcDisplayId; |
| 410 | bool mHasMultiDisplaySupport = false; |
| 411 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 412 | std::unordered_set<DisplayId> mFreeVirtualDisplayIds; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 413 | uint32_t mNextVirtualDisplayId = 0; |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 414 | uint32_t mRemainingHwcVirtualDisplays{getMaxVirtualDisplayCount()}; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 415 | }; |
| 416 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 417 | } // namespace impl |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 418 | } // namespace android |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 419 | |
| 420 | #endif // ANDROID_SF_HWCOMPOSER_H |