blob: e18419a8e492da4cef071df6b572c701818d2d15 [file] [log] [blame]
Mathias Agopiana350ff92010-08-10 17:14:02 -07001/*
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 Laskowski1af47932018-11-12 10:20:46 -080020#include <cstdint>
Dan Stoza9e56aa02015-11-02 13:00:03 -080021#include <memory>
Dominik Laskowski1af47932018-11-12 10:20:46 -080022#include <mutex>
Steven Thomas6e8f7062017-11-22 14:15:29 -080023#include <optional>
Dominik Laskowski075d3172018-05-24 15:50:06 -070024#include <unordered_map>
25#include <unordered_set>
Dan Stoza9e56aa02015-11-02 13:00:03 -080026#include <vector>
27
Dominik Laskowski1af47932018-11-12 10:20:46 -080028#include <android-base/thread_annotations.h>
29#include <ui/Fence.h>
Ady Abraham8a82ba62020-01-17 12:43:17 -080030
31// TODO(b/129481165): remove the #pragma below and fix conversion issues
32#pragma clang diagnostic push
33#pragma clang diagnostic ignored "-Wconversion"
Dominik Laskowski1af47932018-11-12 10:20:46 -080034#include <ui/GraphicTypes.h>
Ady Abraham8a82ba62020-01-17 12:43:17 -080035#pragma clang diagnostic pop
36
Dominik Laskowski1af47932018-11-12 10:20:46 -080037#include <utils/StrongPointer.h>
38#include <utils/Timers.h>
39
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -070040#include "DisplayIdentification.h"
Dominik Laskowski1af47932018-11-12 10:20:46 -080041#include "HWC2.h"
Dan Stoza9e56aa02015-11-02 13:00:03 -080042
Mathias Agopiana350ff92010-08-10 17:14:02 -070043namespace android {
Mathias Agopiana350ff92010-08-10 17:14:02 -070044
Kevin DuBois1d4249a2018-08-29 10:45:14 -070045struct DisplayedFrameStats;
Jesse Hall399184a2014-03-03 15:42:54 -080046class GraphicBuffer;
Lloyd Piquee39cad22017-12-20 17:01:29 -080047class TestableSurfaceFlinger;
David Sodmanfb95bcc2017-12-22 15:45:30 -080048struct CompositionInfo;
Mathias Agopian83727852010-09-23 18:13:21 -070049
Lloyd Piquea822d522017-12-20 16:42:57 -080050namespace Hwc2 {
51class Composer;
52} // namespace Hwc2
53
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080054namespace compositionengine {
55class Output;
56} // namespace compositionengine
57
Lloyd Pique4603f3c2020-02-11 12:06:56 -080058struct KnownHWCGenericLayerMetadata {
59 const char* name;
60 const uint32_t id;
61};
62
Lloyd Pique441d5042018-10-18 16:49:51 -070063class HWComposer {
64public:
65 virtual ~HWComposer();
66
Lloyd Pique4603f3c2020-02-11 12:06:56 -080067 virtual void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -070068
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 Laskowski1162e472020-04-02 19:02:47 -070073 virtual bool hasDisplayCapability(DisplayId displayId,
Lloyd Pique441d5042018-10-18 16:49:51 -070074 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 Shalamanovbdd59152020-02-14 15:30:06 +010080 virtual void allocatePhysicalDisplay(hwc2_display_t hwcDisplayId, DisplayId displayId) = 0;
81
Lloyd Pique441d5042018-10-18 16:49:51 -070082 // 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 Pique66d68602019-02-13 14:23:31 -080087 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 Pique441d5042018-10-18 16:49:51 -0700107
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 Pique441d5042018-10-18 16:49:51 -0700118 // 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 Pique441d5042018-10-18 16:49:51 -0700124 // 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 Gittik57e63c52019-01-18 16:37:54 +0000162 // Sets the brightness of a display.
163 virtual status_t setDisplayBrightness(DisplayId displayId, float brightness) = 0;
164
Lloyd Pique441d5042018-10-18 16:49:51 -0700165 // 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 Shalamanovbdd59152020-02-14 15:30:06 +0100169 // This function is called from SurfaceFlinger.
Lloyd Pique441d5042018-10-18 16:49:51 -0700170 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 Abraham3a77a7b2019-12-02 18:46:59 -0800194 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800195 virtual DisplayConnectionType getDisplayConnectionType(DisplayId) const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800196 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 Peycheva5492cb52019-10-30 14:13:16 +0100202 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 Pique4603f3c2020-02-11 12:06:56 -0800206 virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata()
207 const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800208
Lloyd Pique441d5042018-10-18 16:49:51 -0700209 // 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
222namespace impl {
223
224class HWComposer final : public android::HWComposer {
Mathias Agopiana350ff92010-08-10 17:14:02 -0700225public:
Dominik Laskowski1af47932018-11-12 10:20:46 -0800226 explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800227 explicit HWComposer(const std::string& composerServiceName);
Mathias Agopian8b736f12012-08-13 17:54:26 -0700228
Lloyd Pique441d5042018-10-18 16:49:51 -0700229 ~HWComposer() override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700230
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800231 void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700232
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700233 bool getDisplayIdentificationData(hwc2_display_t hwcDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700234 DisplayIdentificationData* outData) const override;
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700235
Lloyd Pique441d5042018-10-18 16:49:51 -0700236 bool hasCapability(HWC2::Capability capability) const override;
Dominik Laskowski1162e472020-04-02 19:02:47 -0700237 bool hasDisplayCapability(DisplayId displayId,
Lloyd Pique441d5042018-10-18 16:49:51 -0700238 HWC2::DisplayCapability capability) const override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700239
Dominik Laskowski075d3172018-05-24 15:50:06 -0700240 // 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 Pique441d5042018-10-18 16:49:51 -0700242 ui::PixelFormat* format) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700243
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100244 // 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 Stoza9e56aa02015-11-02 13:00:03 -0800247 // Attempts to create a new layer on this display
Lloyd Pique441d5042018-10-18 16:49:51 -0700248 HWC2::Layer* createLayer(DisplayId displayId) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700249 // Destroy a previously created layer
Lloyd Pique441d5042018-10-18 16:49:51 -0700250 void destroyLayer(DisplayId displayId, HWC2::Layer* layer) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700251
Lloyd Pique66d68602019-02-13 14:23:31 -0800252 status_t getDeviceCompositionChanges(
253 DisplayId, bool frameUsesClientComposition,
254 std::optional<DeviceRequestedChanges>* outChanges) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700255
Dominik Laskowski075d3172018-05-24 15:50:06 -0700256 status_t setClientTarget(DisplayId displayId, uint32_t slot, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700257 const sp<GraphicBuffer>& target, ui::Dataspace dataspace) override;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800258
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800259 // Present layers to the display and read releaseFences.
Lloyd Pique441d5042018-10-18 16:49:51 -0700260 status_t presentAndGetReleaseFences(DisplayId displayId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700261
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700262 // set power mode
Lloyd Pique441d5042018-10-18 16:49:51 -0700263 status_t setPowerMode(DisplayId displayId, int mode) override;
Colin Cross10fbdb62012-07-12 17:56:34 -0700264
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700265 // Sets a color transform to be applied to the result of composition
Lloyd Pique441d5042018-10-18 16:49:51 -0700266 status_t setColorTransform(DisplayId displayId, const mat4& transform) override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700267
Andy McFadden27ec5732012-10-02 19:04:45 -0700268 // reset state when an external, non-virtual display is disconnected
Lloyd Pique441d5042018-10-18 16:49:51 -0700269 void disconnectDisplay(DisplayId displayId) override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700270
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800271 // get the present fence received from the last call to present.
Lloyd Pique441d5042018-10-18 16:49:51 -0700272 sp<Fence> getPresentFence(DisplayId displayId) const override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700273
Dan Stoza9e56aa02015-11-02 13:00:03 -0800274 // Get last release fence for the given layer
Lloyd Pique441d5042018-10-18 16:49:51 -0700275 sp<Fence> getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const override;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700276
Jesse Hall851cfe82013-03-20 13:44:00 -0700277 // Set the output buffer and acquire fence for a virtual display.
Dan Stoza9e56aa02015-11-02 13:00:03 -0800278 // Returns INVALID_OPERATION if displayId is not a virtual display.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700279 status_t setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700280 const sp<GraphicBuffer>& buffer) override;
Jesse Hall851cfe82013-03-20 13:44:00 -0700281
Dan Stoza9e56aa02015-11-02 13:00:03 -0800282 // 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 Pique441d5042018-10-18 16:49:51 -0700284 void clearReleaseFences(DisplayId displayId) override;
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700285
Peiyong Lin62665892018-04-16 11:07:44 -0700286 // Fetches the HDR capabilities of the given display
Lloyd Pique441d5042018-10-18 16:49:51 -0700287 status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) override;
Dan Stozac4f471e2016-03-24 09:31:08 -0700288
Lloyd Pique441d5042018-10-18 16:49:51 -0700289 int32_t getSupportedPerFrameMetadata(DisplayId displayId) const override;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700290
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700291 // Returns the available RenderIntent of the given display.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700292 std::vector<ui::RenderIntent> getRenderIntents(DisplayId displayId,
Lloyd Pique441d5042018-10-18 16:49:51 -0700293 ui::ColorMode colorMode) const override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700294
Lloyd Pique441d5042018-10-18 16:49:51 -0700295 mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700296
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700297 // Returns the attributes of the color sampling engine.
298 status_t getDisplayedContentSamplingAttributes(DisplayId displayId, ui::PixelFormat* outFormat,
299 ui::Dataspace* outDataspace,
Lloyd Pique441d5042018-10-18 16:49:51 -0700300 uint8_t* outComponentMask) override;
Kevin DuBois74e53772018-11-19 10:52:38 -0800301 status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled,
Lloyd Pique441d5042018-10-18 16:49:51 -0700302 uint8_t componentMask, uint64_t maxFrames) override;
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700303 status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700304 DisplayedFrameStats* outStats) override;
Dan Gittik57e63c52019-01-18 16:37:54 +0000305 status_t setDisplayBrightness(DisplayId displayId, float brightness) override;
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700306
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700307 // Events handling ---------------------------------------------------------
308
Dominik Laskowski075d3172018-05-24 15:50:06 -0700309 // 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 Pique441d5042018-10-18 16:49:51 -0700312 HWC2::Connection connection) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700313
Lloyd Pique441d5042018-10-18 16:49:51 -0700314 bool onVsync(hwc2_display_t hwcDisplayId, int64_t timestamp) override;
315 void setVsyncEnabled(DisplayId displayId, HWC2::Vsync enabled) override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700316
Lloyd Pique441d5042018-10-18 16:49:51 -0700317 nsecs_t getRefreshTimestamp(DisplayId displayId) const override;
318 bool isConnected(DisplayId displayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700319
Dan Stoza9e56aa02015-11-02 13:00:03 -0800320 // Non-const because it can update configMap inside of mDisplayData
Lloyd Pique441d5042018-10-18 16:49:51 -0700321 std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs(
322 DisplayId displayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700323
Lloyd Pique441d5042018-10-18 16:49:51 -0700324 std::shared_ptr<const HWC2::Display::Config> getActiveConfig(
325 DisplayId displayId) const override;
326 int getActiveConfigIndex(DisplayId displayId) const override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700327
Lloyd Pique441d5042018-10-18 16:49:51 -0700328 std::vector<ui::ColorMode> getColorModes(DisplayId displayId) const override;
Michael Wright28f24d02016-07-12 13:30:53 -0700329
Dominik Laskowski075d3172018-05-24 15:50:06 -0700330 status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode,
Lloyd Pique441d5042018-10-18 16:49:51 -0700331 ui::RenderIntent renderIntent) override;
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600332
Lloyd Pique441d5042018-10-18 16:49:51 -0700333 bool isUsingVrComposer() const override;
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800334
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800335 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800336 DisplayConnectionType getDisplayConnectionType(DisplayId) const override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800337 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 Peycheva5492cb52019-10-30 14:13:16 +0100342 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 Abraham3a77a7b2019-12-02 18:46:59 -0800346
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800347 const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override;
348
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700349 // for debugging ----------------------------------------------------------
Lloyd Pique441d5042018-10-18 16:49:51 -0700350 void dump(std::string& out) const override;
Mathias Agopian83727852010-09-23 18:13:21 -0700351
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800352 Hwc2::Composer* getComposer() const override { return mComposer.get(); }
Steven Thomas6e8f7062017-11-22 14:15:29 -0800353
Dominik Laskowski075d3172018-05-24 15:50:06 -0700354 // TODO(b/74619554): Remove special cases for internal/external display.
Lloyd Pique441d5042018-10-18 16:49:51 -0700355 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 Laskowski075d3172018-05-24 15:50:06 -0700361
Lloyd Pique441d5042018-10-18 16:49:51 -0700362 std::optional<DisplayId> toPhysicalDisplayId(hwc2_display_t hwcDisplayId) const override;
363 std::optional<hwc2_display_t> fromPhysicalDisplayId(DisplayId displayId) const override;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700364
Mathias Agopiana350ff92010-08-10 17:14:02 -0700365private:
Lloyd Piquee39cad22017-12-20 17:01:29 -0800366 // For unit tests
367 friend TestableSurfaceFlinger;
368
Dominik Laskowski075d3172018-05-24 15:50:06 -0700369 std::optional<DisplayIdentificationInfo> onHotplugConnect(hwc2_display_t hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100370 std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hwc2_display_t hwcDisplayId);
371 bool shouldIgnoreHotplugConnect(hwc2_display_t hwcDisplayId,
372 bool hasDisplayIdentificationData) const;
373
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800374 void loadCapabilities();
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800375 void loadLayerMetadataSupport();
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800376 uint32_t getMaxVirtualDisplayCount() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700377
Mathias Agopiane60b0682012-08-21 23:34:09 -0700378 struct DisplayData {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700379 bool isVirtual = false;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800380 std::unique_ptr<HWC2::Display> hwcDisplay;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700381 sp<Fence> lastPresentFence = Fence::NO_FENCE; // signals when the last set op retires
Steven Thomas94e35b92017-07-26 18:48:28 -0700382 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700383 buffer_handle_t outbufHandle = nullptr;
384 sp<Fence> outbufAcquireFence = Fence::NO_FENCE;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800385 mutable std::unordered_map<int32_t,
386 std::shared_ptr<const HWC2::Display::Config>> configMap;
Jamie Gennis2ec3e072012-11-11 16:24:33 -0800387
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700388 bool validateWasSkipped;
389 HWC2::Error presentError;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800390
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 Agopiane60b0682012-08-21 23:34:09 -0700398 };
399
Dominik Laskowski075d3172018-05-24 15:50:06 -0700400 std::unordered_map<DisplayId, DisplayData> mDisplayData;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800401
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800402 std::unique_ptr<android::Hwc2::Composer> mComposer;
403 std::unordered_set<HWC2::Capability> mCapabilities;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800404 std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800405 bool mRegisteredCallback = false;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800406
Dominik Laskowski075d3172018-05-24 15:50:06 -0700407 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 Laskowski34157762018-10-31 13:07:19 -0700412 std::unordered_set<DisplayId> mFreeVirtualDisplayIds;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700413 uint32_t mNextVirtualDisplayId = 0;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800414 uint32_t mRemainingHwcVirtualDisplays{getMaxVirtualDisplayCount()};
Mathias Agopiana350ff92010-08-10 17:14:02 -0700415};
416
Lloyd Pique441d5042018-10-18 16:49:51 -0700417} // namespace impl
Dominik Laskowski1af47932018-11-12 10:20:46 -0800418} // namespace android
Mathias Agopiana350ff92010-08-10 17:14:02 -0700419
420#endif // ANDROID_SF_HWCOMPOSER_H