blob: c355ebd4a62f32e7508f4c45e40f5a43f0aa1539 [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>
Dominik Laskowski5690bde2020-04-23 19:04:22 -070021#include <future>
Dan Stoza9e56aa02015-11-02 13:00:03 -080022#include <memory>
Dominik Laskowski1af47932018-11-12 10:20:46 -080023#include <mutex>
Steven Thomas6e8f7062017-11-22 14:15:29 -080024#include <optional>
Dominik Laskowski075d3172018-05-24 15:50:06 -070025#include <unordered_map>
26#include <unordered_set>
Dan Stoza9e56aa02015-11-02 13:00:03 -080027#include <vector>
28
Dominik Laskowski1af47932018-11-12 10:20:46 -080029#include <android-base/thread_annotations.h>
30#include <ui/Fence.h>
Ady Abraham8a82ba62020-01-17 12:43:17 -080031
32// TODO(b/129481165): remove the #pragma below and fix conversion issues
33#pragma clang diagnostic push
34#pragma clang diagnostic ignored "-Wconversion"
Dominik Laskowski1af47932018-11-12 10:20:46 -080035#include <ui/GraphicTypes.h>
Ady Abraham8a82ba62020-01-17 12:43:17 -080036#pragma clang diagnostic pop
37
Dominik Laskowski1af47932018-11-12 10:20:46 -080038#include <utils/StrongPointer.h>
39#include <utils/Timers.h>
40
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -070041#include "DisplayIdentification.h"
Dominik Laskowski1af47932018-11-12 10:20:46 -080042#include "HWC2.h"
Peiyong Line9d809e2020-04-14 13:10:48 -070043#include "Hal.h"
Dan Stoza9e56aa02015-11-02 13:00:03 -080044
Mathias Agopiana350ff92010-08-10 17:14:02 -070045namespace android {
Mathias Agopiana350ff92010-08-10 17:14:02 -070046
Peiyong Line9d809e2020-04-14 13:10:48 -070047namespace hal = hardware::graphics::composer::hal;
48
Kevin DuBois1d4249a2018-08-29 10:45:14 -070049struct DisplayedFrameStats;
Jesse Hall399184a2014-03-03 15:42:54 -080050class GraphicBuffer;
Lloyd Piquee39cad22017-12-20 17:01:29 -080051class TestableSurfaceFlinger;
David Sodmanfb95bcc2017-12-22 15:45:30 -080052struct CompositionInfo;
Mathias Agopian83727852010-09-23 18:13:21 -070053
Lloyd Piquea822d522017-12-20 16:42:57 -080054namespace Hwc2 {
55class Composer;
56} // namespace Hwc2
57
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080058namespace compositionengine {
59class Output;
60} // namespace compositionengine
61
Lloyd Pique4603f3c2020-02-11 12:06:56 -080062struct KnownHWCGenericLayerMetadata {
63 const char* name;
64 const uint32_t id;
65};
66
Lloyd Pique441d5042018-10-18 16:49:51 -070067class HWComposer {
68public:
Peiyong Lindfc3f7c2020-05-07 20:15:50 -070069 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 Pique441d5042018-10-18 16:49:51 -070081 virtual ~HWComposer();
82
Lloyd Pique4603f3c2020-02-11 12:06:56 -080083 virtual void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -070084
Peiyong Line9d809e2020-04-14 13:10:48 -070085 virtual bool getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -070086 DisplayIdentificationData* outData) const = 0;
87
Peiyong Line9d809e2020-04-14 13:10:48 -070088 virtual bool hasCapability(hal::Capability capability) const = 0;
Dominik Laskowski1162e472020-04-02 19:02:47 -070089 virtual bool hasDisplayCapability(DisplayId displayId,
Peiyong Line9d809e2020-04-14 13:10:48 -070090 hal::DisplayCapability capability) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -070091
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 Line9d809e2020-04-14 13:10:48 -070096 virtual void allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) = 0;
Marin Shalamanovbdd59152020-02-14 15:30:06 +010097
Lloyd Pique441d5042018-10-18 16:49:51 -070098 // 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 Pique66d68602019-02-13 14:23:31 -0800103 // 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 Pique441d5042018-10-18 16:49:51 -0700113
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 Lin65248e02020-04-18 21:15:07 -0700122 virtual status_t setPowerMode(DisplayId displayId, hal::PowerMode mode) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700123
Lloyd Pique441d5042018-10-18 16:49:51 -0700124 // 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 Pique441d5042018-10-18 16:49:51 -0700130 // 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 Gittik57e63c52019-01-18 16:37:54 +0000168 // Sets the brightness of a display.
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700169 virtual std::future<status_t> setDisplayBrightness(DisplayId displayId, float brightness) = 0;
Dan Gittik57e63c52019-01-18 16:37:54 +0000170
Lloyd Pique441d5042018-10-18 16:49:51 -0700171 // 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 Shalamanovbdd59152020-02-14 15:30:06 +0100175 // This function is called from SurfaceFlinger.
Peiyong Line9d809e2020-04-14 13:10:48 -0700176 virtual std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId hwcDisplayId,
177 hal::Connection connection) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700178
Peiyong Line9d809e2020-04-14 13:10:48 -0700179 virtual bool onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) = 0;
180 virtual void setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700181
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 Abraham3a77a7b2019-12-02 18:46:59 -0800200 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800201 virtual DisplayConnectionType getDisplayConnectionType(DisplayId) const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800202 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 Line9d809e2020-04-14 13:10:48 -0700206 const hal::VsyncPeriodChangeConstraints& constraints,
207 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100208 virtual status_t setAutoLowLatencyMode(DisplayId displayId, bool on) = 0;
209 virtual status_t getSupportedContentTypes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700210 DisplayId displayId, std::vector<hal::ContentType>* outSupportedContentTypes) = 0;
211 virtual status_t setContentType(DisplayId displayId, hal::ContentType contentType) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800212 virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata()
213 const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800214
Lloyd Pique441d5042018-10-18 16:49:51 -0700215 // 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 Line9d809e2020-04-14 13:10:48 -0700221 virtual std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const = 0;
222 virtual std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700223
Peiyong Line9d809e2020-04-14 13:10:48 -0700224 virtual std::optional<DisplayId> toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const = 0;
225 virtual std::optional<hal::HWDisplayId> fromPhysicalDisplayId(DisplayId displayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700226};
227
228namespace impl {
229
230class HWComposer final : public android::HWComposer {
Mathias Agopiana350ff92010-08-10 17:14:02 -0700231public:
Dominik Laskowski1af47932018-11-12 10:20:46 -0800232 explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800233 explicit HWComposer(const std::string& composerServiceName);
Mathias Agopian8b736f12012-08-13 17:54:26 -0700234
Lloyd Pique441d5042018-10-18 16:49:51 -0700235 ~HWComposer() override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700236
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800237 void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700238
Peiyong Line9d809e2020-04-14 13:10:48 -0700239 bool getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700240 DisplayIdentificationData* outData) const override;
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700241
Peiyong Line9d809e2020-04-14 13:10:48 -0700242 bool hasCapability(hal::Capability capability) const override;
Dominik Laskowski1162e472020-04-02 19:02:47 -0700243 bool hasDisplayCapability(DisplayId displayId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700244 hal::DisplayCapability capability) const override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700245
Dominik Laskowski075d3172018-05-24 15:50:06 -0700246 // 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 Pique441d5042018-10-18 16:49:51 -0700248 ui::PixelFormat* format) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700249
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100250 // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated.
Peiyong Line9d809e2020-04-14 13:10:48 -0700251 void allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) override;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100252
Dan Stoza9e56aa02015-11-02 13:00:03 -0800253 // Attempts to create a new layer on this display
Lloyd Pique441d5042018-10-18 16:49:51 -0700254 HWC2::Layer* createLayer(DisplayId displayId) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700255 // Destroy a previously created layer
Lloyd Pique441d5042018-10-18 16:49:51 -0700256 void destroyLayer(DisplayId displayId, HWC2::Layer* layer) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700257
Lloyd Pique66d68602019-02-13 14:23:31 -0800258 status_t getDeviceCompositionChanges(
259 DisplayId, bool frameUsesClientComposition,
260 std::optional<DeviceRequestedChanges>* outChanges) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700261
Dominik Laskowski075d3172018-05-24 15:50:06 -0700262 status_t setClientTarget(DisplayId displayId, uint32_t slot, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700263 const sp<GraphicBuffer>& target, ui::Dataspace dataspace) override;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800264
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800265 // Present layers to the display and read releaseFences.
Lloyd Pique441d5042018-10-18 16:49:51 -0700266 status_t presentAndGetReleaseFences(DisplayId displayId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700267
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700268 // set power mode
Peiyong Lin65248e02020-04-18 21:15:07 -0700269 status_t setPowerMode(DisplayId displayId, hal::PowerMode mode) override;
Colin Cross10fbdb62012-07-12 17:56:34 -0700270
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700271 // Sets a color transform to be applied to the result of composition
Lloyd Pique441d5042018-10-18 16:49:51 -0700272 status_t setColorTransform(DisplayId displayId, const mat4& transform) override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700273
Andy McFadden27ec5732012-10-02 19:04:45 -0700274 // reset state when an external, non-virtual display is disconnected
Lloyd Pique441d5042018-10-18 16:49:51 -0700275 void disconnectDisplay(DisplayId displayId) override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700276
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800277 // get the present fence received from the last call to present.
Lloyd Pique441d5042018-10-18 16:49:51 -0700278 sp<Fence> getPresentFence(DisplayId displayId) const override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700279
Dan Stoza9e56aa02015-11-02 13:00:03 -0800280 // Get last release fence for the given layer
Lloyd Pique441d5042018-10-18 16:49:51 -0700281 sp<Fence> getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const override;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700282
Jesse Hall851cfe82013-03-20 13:44:00 -0700283 // Set the output buffer and acquire fence for a virtual display.
Dan Stoza9e56aa02015-11-02 13:00:03 -0800284 // Returns INVALID_OPERATION if displayId is not a virtual display.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700285 status_t setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700286 const sp<GraphicBuffer>& buffer) override;
Jesse Hall851cfe82013-03-20 13:44:00 -0700287
Dan Stoza9e56aa02015-11-02 13:00:03 -0800288 // 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 Pique441d5042018-10-18 16:49:51 -0700290 void clearReleaseFences(DisplayId displayId) override;
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700291
Peiyong Lin62665892018-04-16 11:07:44 -0700292 // Fetches the HDR capabilities of the given display
Lloyd Pique441d5042018-10-18 16:49:51 -0700293 status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) override;
Dan Stozac4f471e2016-03-24 09:31:08 -0700294
Lloyd Pique441d5042018-10-18 16:49:51 -0700295 int32_t getSupportedPerFrameMetadata(DisplayId displayId) const override;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700296
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700297 // Returns the available RenderIntent of the given display.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700298 std::vector<ui::RenderIntent> getRenderIntents(DisplayId displayId,
Lloyd Pique441d5042018-10-18 16:49:51 -0700299 ui::ColorMode colorMode) const override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700300
Lloyd Pique441d5042018-10-18 16:49:51 -0700301 mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700302
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700303 // Returns the attributes of the color sampling engine.
304 status_t getDisplayedContentSamplingAttributes(DisplayId displayId, ui::PixelFormat* outFormat,
305 ui::Dataspace* outDataspace,
Lloyd Pique441d5042018-10-18 16:49:51 -0700306 uint8_t* outComponentMask) override;
Kevin DuBois74e53772018-11-19 10:52:38 -0800307 status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled,
Lloyd Pique441d5042018-10-18 16:49:51 -0700308 uint8_t componentMask, uint64_t maxFrames) override;
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700309 status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700310 DisplayedFrameStats* outStats) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700311 std::future<status_t> setDisplayBrightness(DisplayId displayId, float brightness) override;
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700312
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700313 // Events handling ---------------------------------------------------------
314
Dominik Laskowski075d3172018-05-24 15:50:06 -0700315 // 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 Line9d809e2020-04-14 13:10:48 -0700317 std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId hwcDisplayId,
318 hal::Connection connection) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700319
Peiyong Line9d809e2020-04-14 13:10:48 -0700320 bool onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) override;
321 void setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700322
Lloyd Pique441d5042018-10-18 16:49:51 -0700323 nsecs_t getRefreshTimestamp(DisplayId displayId) const override;
324 bool isConnected(DisplayId displayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700325
Dan Stoza9e56aa02015-11-02 13:00:03 -0800326 // Non-const because it can update configMap inside of mDisplayData
Lloyd Pique441d5042018-10-18 16:49:51 -0700327 std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs(
328 DisplayId displayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700329
Lloyd Pique441d5042018-10-18 16:49:51 -0700330 std::shared_ptr<const HWC2::Display::Config> getActiveConfig(
331 DisplayId displayId) const override;
332 int getActiveConfigIndex(DisplayId displayId) const override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700333
Lloyd Pique441d5042018-10-18 16:49:51 -0700334 std::vector<ui::ColorMode> getColorModes(DisplayId displayId) const override;
Michael Wright28f24d02016-07-12 13:30:53 -0700335
Dominik Laskowski075d3172018-05-24 15:50:06 -0700336 status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode,
Lloyd Pique441d5042018-10-18 16:49:51 -0700337 ui::RenderIntent renderIntent) override;
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600338
Lloyd Pique441d5042018-10-18 16:49:51 -0700339 bool isUsingVrComposer() const override;
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800340
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800341 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800342 DisplayConnectionType getDisplayConnectionType(DisplayId) const override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800343 bool isVsyncPeriodSwitchSupported(DisplayId displayId) const override;
344 nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const override;
345 status_t setActiveConfigWithConstraints(DisplayId displayId, size_t configId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700346 const hal::VsyncPeriodChangeConstraints& constraints,
347 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100348 status_t setAutoLowLatencyMode(DisplayId displayId, bool) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700349 status_t getSupportedContentTypes(DisplayId displayId, std::vector<hal::ContentType>*) override;
350 status_t setContentType(DisplayId displayId, hal::ContentType) override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800351
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800352 const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override;
353
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700354 // for debugging ----------------------------------------------------------
Lloyd Pique441d5042018-10-18 16:49:51 -0700355 void dump(std::string& out) const override;
Mathias Agopian83727852010-09-23 18:13:21 -0700356
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800357 Hwc2::Composer* getComposer() const override { return mComposer.get(); }
Steven Thomas6e8f7062017-11-22 14:15:29 -0800358
Dominik Laskowski075d3172018-05-24 15:50:06 -0700359 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700360 std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700361 return mInternalHwcDisplayId;
362 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700363 std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700364 return mExternalHwcDisplayId;
365 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700366
Peiyong Line9d809e2020-04-14 13:10:48 -0700367 std::optional<DisplayId> toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const override;
368 std::optional<hal::HWDisplayId> fromPhysicalDisplayId(DisplayId displayId) const override;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700369
Mathias Agopiana350ff92010-08-10 17:14:02 -0700370private:
Lloyd Piquee39cad22017-12-20 17:01:29 -0800371 // For unit tests
372 friend TestableSurfaceFlinger;
373
Peiyong Line9d809e2020-04-14 13:10:48 -0700374 std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId hwcDisplayId);
375 std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId hwcDisplayId);
376 bool shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId,
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100377 bool hasDisplayIdentificationData) const;
378
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800379 void loadCapabilities();
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800380 void loadLayerMetadataSupport();
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800381 uint32_t getMaxVirtualDisplayCount() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700382
Mathias Agopiane60b0682012-08-21 23:34:09 -0700383 struct DisplayData {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700384 bool isVirtual = false;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800385 std::unique_ptr<HWC2::Display> hwcDisplay;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700386 sp<Fence> lastPresentFence = Fence::NO_FENCE; // signals when the last set op retires
Steven Thomas94e35b92017-07-26 18:48:28 -0700387 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700388 buffer_handle_t outbufHandle = nullptr;
389 sp<Fence> outbufAcquireFence = Fence::NO_FENCE;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800390 mutable std::unordered_map<int32_t,
391 std::shared_ptr<const HWC2::Display::Config>> configMap;
Jamie Gennis2ec3e072012-11-11 16:24:33 -0800392
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700393 bool validateWasSkipped;
Peiyong Line9d809e2020-04-14 13:10:48 -0700394 hal::Error presentError;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800395
396 bool vsyncTraceToggle = false;
397
398 std::mutex vsyncEnabledLock;
Peiyong Line9d809e2020-04-14 13:10:48 -0700399 hal::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = hal::Vsync::DISABLE;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800400
401 mutable std::mutex lastHwVsyncLock;
402 nsecs_t lastHwVsync GUARDED_BY(lastHwVsyncLock) = 0;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700403 };
404
Dominik Laskowski075d3172018-05-24 15:50:06 -0700405 std::unordered_map<DisplayId, DisplayData> mDisplayData;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800406
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800407 std::unique_ptr<android::Hwc2::Composer> mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700408 std::unordered_set<hal::Capability> mCapabilities;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800409 std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800410 bool mRegisteredCallback = false;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800411
Peiyong Line9d809e2020-04-14 13:10:48 -0700412 std::unordered_map<hal::HWDisplayId, DisplayId> mPhysicalDisplayIdMap;
413 std::optional<hal::HWDisplayId> mInternalHwcDisplayId;
414 std::optional<hal::HWDisplayId> mExternalHwcDisplayId;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700415 bool mHasMultiDisplaySupport = false;
416
Dominik Laskowski34157762018-10-31 13:07:19 -0700417 std::unordered_set<DisplayId> mFreeVirtualDisplayIds;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700418 uint32_t mNextVirtualDisplayId = 0;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800419 uint32_t mRemainingHwcVirtualDisplays{getMaxVirtualDisplayCount()};
Mathias Agopiana350ff92010-08-10 17:14:02 -0700420};
421
Lloyd Pique441d5042018-10-18 16:49:51 -0700422} // namespace impl
Dominik Laskowski1af47932018-11-12 10:20:46 -0800423} // namespace android
Mathias Agopiana350ff92010-08-10 17:14:02 -0700424
425#endif // ANDROID_SF_HWCOMPOSER_H