blob: cfa21932e9a30102d9f8bded530ef7fbc574a652 [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"
Peiyong Line9d809e2020-04-14 13:10:48 -070042#include "Hal.h"
Dan Stoza9e56aa02015-11-02 13:00:03 -080043
Mathias Agopiana350ff92010-08-10 17:14:02 -070044namespace android {
Mathias Agopiana350ff92010-08-10 17:14:02 -070045
Peiyong Line9d809e2020-04-14 13:10:48 -070046namespace hal = hardware::graphics::composer::hal;
47
Kevin DuBois1d4249a2018-08-29 10:45:14 -070048struct DisplayedFrameStats;
Jesse Hall399184a2014-03-03 15:42:54 -080049class GraphicBuffer;
Lloyd Piquee39cad22017-12-20 17:01:29 -080050class TestableSurfaceFlinger;
David Sodmanfb95bcc2017-12-22 15:45:30 -080051struct CompositionInfo;
Mathias Agopian83727852010-09-23 18:13:21 -070052
Lloyd Piquea822d522017-12-20 16:42:57 -080053namespace Hwc2 {
54class Composer;
55} // namespace Hwc2
56
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080057namespace compositionengine {
58class Output;
59} // namespace compositionengine
60
Lloyd Pique4603f3c2020-02-11 12:06:56 -080061struct KnownHWCGenericLayerMetadata {
62 const char* name;
63 const uint32_t id;
64};
65
Lloyd Pique441d5042018-10-18 16:49:51 -070066class HWComposer {
67public:
68 virtual ~HWComposer();
69
Lloyd Pique4603f3c2020-02-11 12:06:56 -080070 virtual void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -070071
Peiyong Line9d809e2020-04-14 13:10:48 -070072 virtual bool getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -070073 DisplayIdentificationData* outData) const = 0;
74
Peiyong Line9d809e2020-04-14 13:10:48 -070075 virtual bool hasCapability(hal::Capability capability) const = 0;
Dominik Laskowski1162e472020-04-02 19:02:47 -070076 virtual bool hasDisplayCapability(DisplayId displayId,
Peiyong Line9d809e2020-04-14 13:10:48 -070077 hal::DisplayCapability capability) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -070078
79 // Attempts to allocate a virtual display and returns its ID if created on the HWC device.
80 virtual std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height,
81 ui::PixelFormat* format) = 0;
82
Peiyong Line9d809e2020-04-14 13:10:48 -070083 virtual void allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) = 0;
Marin Shalamanovbdd59152020-02-14 15:30:06 +010084
Lloyd Pique441d5042018-10-18 16:49:51 -070085 // Attempts to create a new layer on this display
86 virtual HWC2::Layer* createLayer(DisplayId displayId) = 0;
87 // Destroy a previously created layer
88 virtual void destroyLayer(DisplayId displayId, HWC2::Layer* layer) = 0;
89
Lloyd Pique66d68602019-02-13 14:23:31 -080090 struct DeviceRequestedChanges {
Peiyong Line9d809e2020-04-14 13:10:48 -070091 using ChangedTypes = std::unordered_map<HWC2::Layer*, hal::Composition>;
92 using DisplayRequests = hal::DisplayRequest;
93 using LayerRequests = std::unordered_map<HWC2::Layer*, hal::LayerRequest>;
Lloyd Pique66d68602019-02-13 14:23:31 -080094
95 ChangedTypes changedTypes;
96 DisplayRequests displayRequests;
97 LayerRequests layerRequests;
98 };
99
100 // Gets any required composition change requests from the HWC device.
101 //
102 // Note that frameUsesClientComposition must be set correctly based on
103 // whether the current frame appears to use client composition. If it is
104 // false some internal optimizations are allowed to present the display
105 // with fewer handshakes, but this does not work if client composition is
106 // expected.
107 virtual status_t getDeviceCompositionChanges(
108 DisplayId, bool frameUsesClientComposition,
109 std::optional<DeviceRequestedChanges>* outChanges) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700110
111 virtual status_t setClientTarget(DisplayId displayId, uint32_t slot,
112 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target,
113 ui::Dataspace dataspace) = 0;
114
115 // Present layers to the display and read releaseFences.
116 virtual status_t presentAndGetReleaseFences(DisplayId displayId) = 0;
117
118 // set power mode
Peiyong Lin65248e02020-04-18 21:15:07 -0700119 virtual status_t setPowerMode(DisplayId displayId, hal::PowerMode mode) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700120
Lloyd Pique441d5042018-10-18 16:49:51 -0700121 // Sets a color transform to be applied to the result of composition
122 virtual status_t setColorTransform(DisplayId displayId, const mat4& transform) = 0;
123
124 // reset state when an external, non-virtual display is disconnected
125 virtual void disconnectDisplay(DisplayId displayId) = 0;
126
Lloyd Pique441d5042018-10-18 16:49:51 -0700127 // get the present fence received from the last call to present.
128 virtual sp<Fence> getPresentFence(DisplayId displayId) const = 0;
129
130 // Get last release fence for the given layer
131 virtual sp<Fence> getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const = 0;
132
133 // Set the output buffer and acquire fence for a virtual display.
134 // Returns INVALID_OPERATION if displayId is not a virtual display.
135 virtual status_t setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence,
136 const sp<GraphicBuffer>& buffer) = 0;
137
138 // After SurfaceFlinger has retrieved the release fences for all the frames,
139 // it can call this to clear the shared pointers in the release fence map
140 virtual void clearReleaseFences(DisplayId displayId) = 0;
141
142 // Fetches the HDR capabilities of the given display
143 virtual status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) = 0;
144
145 virtual int32_t getSupportedPerFrameMetadata(DisplayId displayId) const = 0;
146
147 // Returns the available RenderIntent of the given display.
148 virtual std::vector<ui::RenderIntent> getRenderIntents(DisplayId displayId,
149 ui::ColorMode colorMode) const = 0;
150
151 virtual mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) = 0;
152
153 // Returns the attributes of the color sampling engine.
154 virtual status_t getDisplayedContentSamplingAttributes(DisplayId displayId,
155 ui::PixelFormat* outFormat,
156 ui::Dataspace* outDataspace,
157 uint8_t* outComponentMask) = 0;
158 virtual status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled,
159 uint8_t componentMask,
160 uint64_t maxFrames) = 0;
161 virtual status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames,
162 uint64_t timestamp,
163 DisplayedFrameStats* outStats) = 0;
164
Dan Gittik57e63c52019-01-18 16:37:54 +0000165 // Sets the brightness of a display.
166 virtual status_t setDisplayBrightness(DisplayId displayId, float brightness) = 0;
167
Lloyd Pique441d5042018-10-18 16:49:51 -0700168 // Events handling ---------------------------------------------------------
169
170 // Returns stable display ID (and display name on connection of new or previously disconnected
171 // display), or std::nullopt if hotplug event was ignored.
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100172 // This function is called from SurfaceFlinger.
Peiyong Line9d809e2020-04-14 13:10:48 -0700173 virtual std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId hwcDisplayId,
174 hal::Connection connection) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700175
Peiyong Line9d809e2020-04-14 13:10:48 -0700176 virtual bool onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) = 0;
177 virtual void setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700178
179 virtual nsecs_t getRefreshTimestamp(DisplayId displayId) const = 0;
180 virtual bool isConnected(DisplayId displayId) const = 0;
181
182 // Non-const because it can update configMap inside of mDisplayData
183 virtual std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs(
184 DisplayId displayId) const = 0;
185
186 virtual std::shared_ptr<const HWC2::Display::Config> getActiveConfig(
187 DisplayId displayId) const = 0;
188 virtual int getActiveConfigIndex(DisplayId displayId) const = 0;
189
190 virtual std::vector<ui::ColorMode> getColorModes(DisplayId displayId) const = 0;
191
192 virtual status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode,
193 ui::RenderIntent renderIntent) = 0;
194
195 virtual bool isUsingVrComposer() const = 0;
196
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800197 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800198 virtual DisplayConnectionType getDisplayConnectionType(DisplayId) const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800199 virtual bool isVsyncPeriodSwitchSupported(DisplayId displayId) const = 0;
200 virtual nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const = 0;
201 virtual status_t setActiveConfigWithConstraints(
202 DisplayId displayId, size_t configId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700203 const hal::VsyncPeriodChangeConstraints& constraints,
204 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100205 virtual status_t setAutoLowLatencyMode(DisplayId displayId, bool on) = 0;
206 virtual status_t getSupportedContentTypes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700207 DisplayId displayId, std::vector<hal::ContentType>* outSupportedContentTypes) = 0;
208 virtual status_t setContentType(DisplayId displayId, hal::ContentType contentType) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800209 virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata()
210 const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800211
Lloyd Pique441d5042018-10-18 16:49:51 -0700212 // for debugging ----------------------------------------------------------
213 virtual void dump(std::string& out) const = 0;
214
215 virtual Hwc2::Composer* getComposer() const = 0;
216
217 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700218 virtual std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const = 0;
219 virtual std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700220
Peiyong Line9d809e2020-04-14 13:10:48 -0700221 virtual std::optional<DisplayId> toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const = 0;
222 virtual std::optional<hal::HWDisplayId> fromPhysicalDisplayId(DisplayId displayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700223};
224
225namespace impl {
226
227class HWComposer final : public android::HWComposer {
Mathias Agopiana350ff92010-08-10 17:14:02 -0700228public:
Dominik Laskowski1af47932018-11-12 10:20:46 -0800229 explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800230 explicit HWComposer(const std::string& composerServiceName);
Mathias Agopian8b736f12012-08-13 17:54:26 -0700231
Lloyd Pique441d5042018-10-18 16:49:51 -0700232 ~HWComposer() override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700233
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800234 void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700235
Peiyong Line9d809e2020-04-14 13:10:48 -0700236 bool getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700237 DisplayIdentificationData* outData) const override;
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700238
Peiyong Line9d809e2020-04-14 13:10:48 -0700239 bool hasCapability(hal::Capability capability) const override;
Dominik Laskowski1162e472020-04-02 19:02:47 -0700240 bool hasDisplayCapability(DisplayId displayId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700241 hal::DisplayCapability capability) const override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700242
Dominik Laskowski075d3172018-05-24 15:50:06 -0700243 // Attempts to allocate a virtual display and returns its ID if created on the HWC device.
244 std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height,
Lloyd Pique441d5042018-10-18 16:49:51 -0700245 ui::PixelFormat* format) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700246
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100247 // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated.
Peiyong Line9d809e2020-04-14 13:10:48 -0700248 void allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) override;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100249
Dan Stoza9e56aa02015-11-02 13:00:03 -0800250 // Attempts to create a new layer on this display
Lloyd Pique441d5042018-10-18 16:49:51 -0700251 HWC2::Layer* createLayer(DisplayId displayId) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700252 // Destroy a previously created layer
Lloyd Pique441d5042018-10-18 16:49:51 -0700253 void destroyLayer(DisplayId displayId, HWC2::Layer* layer) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700254
Lloyd Pique66d68602019-02-13 14:23:31 -0800255 status_t getDeviceCompositionChanges(
256 DisplayId, bool frameUsesClientComposition,
257 std::optional<DeviceRequestedChanges>* outChanges) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700258
Dominik Laskowski075d3172018-05-24 15:50:06 -0700259 status_t setClientTarget(DisplayId displayId, uint32_t slot, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700260 const sp<GraphicBuffer>& target, ui::Dataspace dataspace) override;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800261
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800262 // Present layers to the display and read releaseFences.
Lloyd Pique441d5042018-10-18 16:49:51 -0700263 status_t presentAndGetReleaseFences(DisplayId displayId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700264
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700265 // set power mode
Peiyong Lin65248e02020-04-18 21:15:07 -0700266 status_t setPowerMode(DisplayId displayId, hal::PowerMode mode) override;
Colin Cross10fbdb62012-07-12 17:56:34 -0700267
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700268 // Sets a color transform to be applied to the result of composition
Lloyd Pique441d5042018-10-18 16:49:51 -0700269 status_t setColorTransform(DisplayId displayId, const mat4& transform) override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700270
Andy McFadden27ec5732012-10-02 19:04:45 -0700271 // reset state when an external, non-virtual display is disconnected
Lloyd Pique441d5042018-10-18 16:49:51 -0700272 void disconnectDisplay(DisplayId displayId) override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700273
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800274 // get the present fence received from the last call to present.
Lloyd Pique441d5042018-10-18 16:49:51 -0700275 sp<Fence> getPresentFence(DisplayId displayId) const override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700276
Dan Stoza9e56aa02015-11-02 13:00:03 -0800277 // Get last release fence for the given layer
Lloyd Pique441d5042018-10-18 16:49:51 -0700278 sp<Fence> getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const override;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700279
Jesse Hall851cfe82013-03-20 13:44:00 -0700280 // Set the output buffer and acquire fence for a virtual display.
Dan Stoza9e56aa02015-11-02 13:00:03 -0800281 // Returns INVALID_OPERATION if displayId is not a virtual display.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700282 status_t setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700283 const sp<GraphicBuffer>& buffer) override;
Jesse Hall851cfe82013-03-20 13:44:00 -0700284
Dan Stoza9e56aa02015-11-02 13:00:03 -0800285 // After SurfaceFlinger has retrieved the release fences for all the frames,
286 // it can call this to clear the shared pointers in the release fence map
Lloyd Pique441d5042018-10-18 16:49:51 -0700287 void clearReleaseFences(DisplayId displayId) override;
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700288
Peiyong Lin62665892018-04-16 11:07:44 -0700289 // Fetches the HDR capabilities of the given display
Lloyd Pique441d5042018-10-18 16:49:51 -0700290 status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) override;
Dan Stozac4f471e2016-03-24 09:31:08 -0700291
Lloyd Pique441d5042018-10-18 16:49:51 -0700292 int32_t getSupportedPerFrameMetadata(DisplayId displayId) const override;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700293
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700294 // Returns the available RenderIntent of the given display.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700295 std::vector<ui::RenderIntent> getRenderIntents(DisplayId displayId,
Lloyd Pique441d5042018-10-18 16:49:51 -0700296 ui::ColorMode colorMode) const override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700297
Lloyd Pique441d5042018-10-18 16:49:51 -0700298 mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700299
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700300 // Returns the attributes of the color sampling engine.
301 status_t getDisplayedContentSamplingAttributes(DisplayId displayId, ui::PixelFormat* outFormat,
302 ui::Dataspace* outDataspace,
Lloyd Pique441d5042018-10-18 16:49:51 -0700303 uint8_t* outComponentMask) override;
Kevin DuBois74e53772018-11-19 10:52:38 -0800304 status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled,
Lloyd Pique441d5042018-10-18 16:49:51 -0700305 uint8_t componentMask, uint64_t maxFrames) override;
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700306 status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700307 DisplayedFrameStats* outStats) override;
Dan Gittik57e63c52019-01-18 16:37:54 +0000308 status_t setDisplayBrightness(DisplayId displayId, float brightness) override;
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700309
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700310 // Events handling ---------------------------------------------------------
311
Dominik Laskowski075d3172018-05-24 15:50:06 -0700312 // Returns stable display ID (and display name on connection of new or previously disconnected
313 // display), or std::nullopt if hotplug event was ignored.
Peiyong Line9d809e2020-04-14 13:10:48 -0700314 std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId hwcDisplayId,
315 hal::Connection connection) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700316
Peiyong Line9d809e2020-04-14 13:10:48 -0700317 bool onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) override;
318 void setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700319
Lloyd Pique441d5042018-10-18 16:49:51 -0700320 nsecs_t getRefreshTimestamp(DisplayId displayId) const override;
321 bool isConnected(DisplayId displayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700322
Dan Stoza9e56aa02015-11-02 13:00:03 -0800323 // Non-const because it can update configMap inside of mDisplayData
Lloyd Pique441d5042018-10-18 16:49:51 -0700324 std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs(
325 DisplayId displayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700326
Lloyd Pique441d5042018-10-18 16:49:51 -0700327 std::shared_ptr<const HWC2::Display::Config> getActiveConfig(
328 DisplayId displayId) const override;
329 int getActiveConfigIndex(DisplayId displayId) const override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700330
Lloyd Pique441d5042018-10-18 16:49:51 -0700331 std::vector<ui::ColorMode> getColorModes(DisplayId displayId) const override;
Michael Wright28f24d02016-07-12 13:30:53 -0700332
Dominik Laskowski075d3172018-05-24 15:50:06 -0700333 status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode,
Lloyd Pique441d5042018-10-18 16:49:51 -0700334 ui::RenderIntent renderIntent) override;
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600335
Lloyd Pique441d5042018-10-18 16:49:51 -0700336 bool isUsingVrComposer() const override;
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800337
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800338 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800339 DisplayConnectionType getDisplayConnectionType(DisplayId) const override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800340 bool isVsyncPeriodSwitchSupported(DisplayId displayId) const override;
341 nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const override;
342 status_t setActiveConfigWithConstraints(DisplayId displayId, size_t configId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700343 const hal::VsyncPeriodChangeConstraints& constraints,
344 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100345 status_t setAutoLowLatencyMode(DisplayId displayId, bool) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700346 status_t getSupportedContentTypes(DisplayId displayId, std::vector<hal::ContentType>*) override;
347 status_t setContentType(DisplayId displayId, hal::ContentType) override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800348
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800349 const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override;
350
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700351 // for debugging ----------------------------------------------------------
Lloyd Pique441d5042018-10-18 16:49:51 -0700352 void dump(std::string& out) const override;
Mathias Agopian83727852010-09-23 18:13:21 -0700353
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800354 Hwc2::Composer* getComposer() const override { return mComposer.get(); }
Steven Thomas6e8f7062017-11-22 14:15:29 -0800355
Dominik Laskowski075d3172018-05-24 15:50:06 -0700356 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700357 std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700358 return mInternalHwcDisplayId;
359 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700360 std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700361 return mExternalHwcDisplayId;
362 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700363
Peiyong Line9d809e2020-04-14 13:10:48 -0700364 std::optional<DisplayId> toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const override;
365 std::optional<hal::HWDisplayId> fromPhysicalDisplayId(DisplayId displayId) const override;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700366
Mathias Agopiana350ff92010-08-10 17:14:02 -0700367private:
Lloyd Piquee39cad22017-12-20 17:01:29 -0800368 // For unit tests
369 friend TestableSurfaceFlinger;
370
Peiyong Line9d809e2020-04-14 13:10:48 -0700371 std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId hwcDisplayId);
372 std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId hwcDisplayId);
373 bool shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId,
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100374 bool hasDisplayIdentificationData) const;
375
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800376 void loadCapabilities();
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800377 void loadLayerMetadataSupport();
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800378 uint32_t getMaxVirtualDisplayCount() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700379
Mathias Agopiane60b0682012-08-21 23:34:09 -0700380 struct DisplayData {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700381 bool isVirtual = false;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800382 std::unique_ptr<HWC2::Display> hwcDisplay;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700383 sp<Fence> lastPresentFence = Fence::NO_FENCE; // signals when the last set op retires
Steven Thomas94e35b92017-07-26 18:48:28 -0700384 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700385 buffer_handle_t outbufHandle = nullptr;
386 sp<Fence> outbufAcquireFence = Fence::NO_FENCE;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800387 mutable std::unordered_map<int32_t,
388 std::shared_ptr<const HWC2::Display::Config>> configMap;
Jamie Gennis2ec3e072012-11-11 16:24:33 -0800389
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700390 bool validateWasSkipped;
Peiyong Line9d809e2020-04-14 13:10:48 -0700391 hal::Error presentError;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800392
393 bool vsyncTraceToggle = false;
394
395 std::mutex vsyncEnabledLock;
Peiyong Line9d809e2020-04-14 13:10:48 -0700396 hal::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = hal::Vsync::DISABLE;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800397
398 mutable std::mutex lastHwVsyncLock;
399 nsecs_t lastHwVsync GUARDED_BY(lastHwVsyncLock) = 0;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700400 };
401
Dominik Laskowski075d3172018-05-24 15:50:06 -0700402 std::unordered_map<DisplayId, DisplayData> mDisplayData;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800403
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800404 std::unique_ptr<android::Hwc2::Composer> mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700405 std::unordered_set<hal::Capability> mCapabilities;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800406 std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800407 bool mRegisteredCallback = false;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800408
Peiyong Line9d809e2020-04-14 13:10:48 -0700409 std::unordered_map<hal::HWDisplayId, DisplayId> mPhysicalDisplayIdMap;
410 std::optional<hal::HWDisplayId> mInternalHwcDisplayId;
411 std::optional<hal::HWDisplayId> mExternalHwcDisplayId;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700412 bool mHasMultiDisplaySupport = false;
413
Dominik Laskowski34157762018-10-31 13:07:19 -0700414 std::unordered_set<DisplayId> mFreeVirtualDisplayIds;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700415 uint32_t mNextVirtualDisplayId = 0;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800416 uint32_t mRemainingHwcVirtualDisplays{getMaxVirtualDisplayCount()};
Mathias Agopiana350ff92010-08-10 17:14:02 -0700417};
418
Lloyd Pique441d5042018-10-18 16:49:51 -0700419} // namespace impl
Dominik Laskowski1af47932018-11-12 10:20:46 -0800420} // namespace android
Mathias Agopiana350ff92010-08-10 17:14:02 -0700421
422#endif // ANDROID_SF_HWCOMPOSER_H