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