blob: b8000386acc03dcc7045c659d3f5d88e02c162e8 [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
Marin Shalamanov1c434292020-06-12 01:47:29 +020067// See the comment for SurfaceFlinger::getHwComposer for the thread safety rules for accessing
68// this class.
Lloyd Pique441d5042018-10-18 16:49:51 -070069class HWComposer {
70public:
Peiyong Lindfc3f7c2020-05-07 20:15:50 -070071 struct DeviceRequestedChanges {
72 using ChangedTypes = std::unordered_map<HWC2::Layer*, hal::Composition>;
73 using ClientTargetProperty = hal::ClientTargetProperty;
74 using DisplayRequests = hal::DisplayRequest;
75 using LayerRequests = std::unordered_map<HWC2::Layer*, hal::LayerRequest>;
76
77 ChangedTypes changedTypes;
78 DisplayRequests displayRequests;
79 LayerRequests layerRequests;
80 ClientTargetProperty clientTargetProperty;
81 };
82
Lloyd Pique441d5042018-10-18 16:49:51 -070083 virtual ~HWComposer();
84
Lloyd Pique4603f3c2020-02-11 12:06:56 -080085 virtual void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -070086
Peiyong Line9d809e2020-04-14 13:10:48 -070087 virtual bool getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -070088 DisplayIdentificationData* outData) const = 0;
89
Peiyong Line9d809e2020-04-14 13:10:48 -070090 virtual bool hasCapability(hal::Capability capability) const = 0;
Dominik Laskowski1162e472020-04-02 19:02:47 -070091 virtual bool hasDisplayCapability(DisplayId displayId,
Peiyong Line9d809e2020-04-14 13:10:48 -070092 hal::DisplayCapability capability) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -070093
94 // Attempts to allocate a virtual display and returns its ID if created on the HWC device.
95 virtual std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height,
96 ui::PixelFormat* format) = 0;
97
Peiyong Line9d809e2020-04-14 13:10:48 -070098 virtual void allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) = 0;
Marin Shalamanovbdd59152020-02-14 15:30:06 +010099
Lloyd Pique441d5042018-10-18 16:49:51 -0700100 // Attempts to create a new layer on this display
101 virtual HWC2::Layer* createLayer(DisplayId displayId) = 0;
102 // Destroy a previously created layer
103 virtual void destroyLayer(DisplayId displayId, HWC2::Layer* layer) = 0;
104
Lloyd Pique66d68602019-02-13 14:23:31 -0800105 // Gets any required composition change requests from the HWC device.
106 //
107 // Note that frameUsesClientComposition must be set correctly based on
108 // whether the current frame appears to use client composition. If it is
109 // false some internal optimizations are allowed to present the display
110 // with fewer handshakes, but this does not work if client composition is
111 // expected.
112 virtual status_t getDeviceCompositionChanges(
113 DisplayId, bool frameUsesClientComposition,
114 std::optional<DeviceRequestedChanges>* outChanges) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700115
116 virtual status_t setClientTarget(DisplayId displayId, uint32_t slot,
117 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target,
118 ui::Dataspace dataspace) = 0;
119
120 // Present layers to the display and read releaseFences.
121 virtual status_t presentAndGetReleaseFences(DisplayId displayId) = 0;
122
123 // set power mode
Peiyong Lin65248e02020-04-18 21:15:07 -0700124 virtual status_t setPowerMode(DisplayId displayId, hal::PowerMode mode) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700125
Lloyd Pique441d5042018-10-18 16:49:51 -0700126 // Sets a color transform to be applied to the result of composition
127 virtual status_t setColorTransform(DisplayId displayId, const mat4& transform) = 0;
128
129 // reset state when an external, non-virtual display is disconnected
130 virtual void disconnectDisplay(DisplayId displayId) = 0;
131
Lloyd Pique441d5042018-10-18 16:49:51 -0700132 // get the present fence received from the last call to present.
133 virtual sp<Fence> getPresentFence(DisplayId displayId) const = 0;
134
135 // Get last release fence for the given layer
136 virtual sp<Fence> getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const = 0;
137
138 // Set the output buffer and acquire fence for a virtual display.
139 // Returns INVALID_OPERATION if displayId is not a virtual display.
140 virtual status_t setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence,
141 const sp<GraphicBuffer>& buffer) = 0;
142
143 // After SurfaceFlinger has retrieved the release fences for all the frames,
144 // it can call this to clear the shared pointers in the release fence map
145 virtual void clearReleaseFences(DisplayId displayId) = 0;
146
147 // Fetches the HDR capabilities of the given display
148 virtual status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) = 0;
149
150 virtual int32_t getSupportedPerFrameMetadata(DisplayId displayId) const = 0;
151
152 // Returns the available RenderIntent of the given display.
153 virtual std::vector<ui::RenderIntent> getRenderIntents(DisplayId displayId,
154 ui::ColorMode colorMode) const = 0;
155
156 virtual mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) = 0;
157
158 // Returns the attributes of the color sampling engine.
159 virtual status_t getDisplayedContentSamplingAttributes(DisplayId displayId,
160 ui::PixelFormat* outFormat,
161 ui::Dataspace* outDataspace,
162 uint8_t* outComponentMask) = 0;
163 virtual status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled,
164 uint8_t componentMask,
165 uint64_t maxFrames) = 0;
166 virtual status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames,
167 uint64_t timestamp,
168 DisplayedFrameStats* outStats) = 0;
169
Dan Gittik57e63c52019-01-18 16:37:54 +0000170 // Sets the brightness of a display.
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700171 virtual std::future<status_t> setDisplayBrightness(DisplayId displayId, float brightness) = 0;
Dan Gittik57e63c52019-01-18 16:37:54 +0000172
Lloyd Pique441d5042018-10-18 16:49:51 -0700173 // Events handling ---------------------------------------------------------
174
175 // Returns stable display ID (and display name on connection of new or previously disconnected
176 // display), or std::nullopt if hotplug event was ignored.
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100177 // This function is called from SurfaceFlinger.
Peiyong Line9d809e2020-04-14 13:10:48 -0700178 virtual std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId hwcDisplayId,
179 hal::Connection connection) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700180
Peiyong Line9d809e2020-04-14 13:10:48 -0700181 virtual bool onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) = 0;
182 virtual void setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700183
184 virtual nsecs_t getRefreshTimestamp(DisplayId displayId) const = 0;
185 virtual bool isConnected(DisplayId displayId) const = 0;
186
187 // Non-const because it can update configMap inside of mDisplayData
188 virtual std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs(
189 DisplayId displayId) const = 0;
190
191 virtual std::shared_ptr<const HWC2::Display::Config> getActiveConfig(
192 DisplayId displayId) const = 0;
193 virtual int getActiveConfigIndex(DisplayId displayId) const = 0;
194
195 virtual std::vector<ui::ColorMode> getColorModes(DisplayId displayId) const = 0;
196
197 virtual status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode,
198 ui::RenderIntent renderIntent) = 0;
199
200 virtual bool isUsingVrComposer() const = 0;
201
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800202 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800203 virtual DisplayConnectionType getDisplayConnectionType(DisplayId) const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800204 virtual bool isVsyncPeriodSwitchSupported(DisplayId displayId) const = 0;
205 virtual nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const = 0;
206 virtual status_t setActiveConfigWithConstraints(
207 DisplayId displayId, size_t configId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700208 const hal::VsyncPeriodChangeConstraints& constraints,
209 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100210 virtual status_t setAutoLowLatencyMode(DisplayId displayId, bool on) = 0;
211 virtual status_t getSupportedContentTypes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700212 DisplayId displayId, std::vector<hal::ContentType>* outSupportedContentTypes) = 0;
213 virtual status_t setContentType(DisplayId displayId, hal::ContentType contentType) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800214 virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata()
215 const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800216
Lloyd Pique441d5042018-10-18 16:49:51 -0700217 // for debugging ----------------------------------------------------------
218 virtual void dump(std::string& out) const = 0;
219
220 virtual Hwc2::Composer* getComposer() const = 0;
221
222 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700223 virtual std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const = 0;
224 virtual std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700225
Peiyong Line9d809e2020-04-14 13:10:48 -0700226 virtual std::optional<DisplayId> toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const = 0;
227 virtual std::optional<hal::HWDisplayId> fromPhysicalDisplayId(DisplayId displayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700228};
229
230namespace impl {
231
232class HWComposer final : public android::HWComposer {
Mathias Agopiana350ff92010-08-10 17:14:02 -0700233public:
Dominik Laskowski1af47932018-11-12 10:20:46 -0800234 explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800235 explicit HWComposer(const std::string& composerServiceName);
Mathias Agopian8b736f12012-08-13 17:54:26 -0700236
Lloyd Pique441d5042018-10-18 16:49:51 -0700237 ~HWComposer() override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700238
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800239 void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700240
Peiyong Line9d809e2020-04-14 13:10:48 -0700241 bool getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700242 DisplayIdentificationData* outData) const override;
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700243
Peiyong Line9d809e2020-04-14 13:10:48 -0700244 bool hasCapability(hal::Capability capability) const override;
Dominik Laskowski1162e472020-04-02 19:02:47 -0700245 bool hasDisplayCapability(DisplayId displayId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700246 hal::DisplayCapability capability) const override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700247
Dominik Laskowski075d3172018-05-24 15:50:06 -0700248 // Attempts to allocate a virtual display and returns its ID if created on the HWC device.
249 std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height,
Lloyd Pique441d5042018-10-18 16:49:51 -0700250 ui::PixelFormat* format) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700251
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100252 // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated.
Peiyong Line9d809e2020-04-14 13:10:48 -0700253 void allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) override;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100254
Dan Stoza9e56aa02015-11-02 13:00:03 -0800255 // Attempts to create a new layer on this display
Lloyd Pique441d5042018-10-18 16:49:51 -0700256 HWC2::Layer* createLayer(DisplayId displayId) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700257 // Destroy a previously created layer
Lloyd Pique441d5042018-10-18 16:49:51 -0700258 void destroyLayer(DisplayId displayId, HWC2::Layer* layer) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700259
Lloyd Pique66d68602019-02-13 14:23:31 -0800260 status_t getDeviceCompositionChanges(
261 DisplayId, bool frameUsesClientComposition,
262 std::optional<DeviceRequestedChanges>* outChanges) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700263
Dominik Laskowski075d3172018-05-24 15:50:06 -0700264 status_t setClientTarget(DisplayId displayId, uint32_t slot, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700265 const sp<GraphicBuffer>& target, ui::Dataspace dataspace) override;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800266
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800267 // Present layers to the display and read releaseFences.
Lloyd Pique441d5042018-10-18 16:49:51 -0700268 status_t presentAndGetReleaseFences(DisplayId displayId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700269
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700270 // set power mode
Peiyong Lin65248e02020-04-18 21:15:07 -0700271 status_t setPowerMode(DisplayId displayId, hal::PowerMode mode) override;
Colin Cross10fbdb62012-07-12 17:56:34 -0700272
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700273 // Sets a color transform to be applied to the result of composition
Lloyd Pique441d5042018-10-18 16:49:51 -0700274 status_t setColorTransform(DisplayId displayId, const mat4& transform) override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700275
Andy McFadden27ec5732012-10-02 19:04:45 -0700276 // reset state when an external, non-virtual display is disconnected
Lloyd Pique441d5042018-10-18 16:49:51 -0700277 void disconnectDisplay(DisplayId displayId) override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700278
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800279 // get the present fence received from the last call to present.
Lloyd Pique441d5042018-10-18 16:49:51 -0700280 sp<Fence> getPresentFence(DisplayId displayId) const override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700281
Dan Stoza9e56aa02015-11-02 13:00:03 -0800282 // Get last release fence for the given layer
Lloyd Pique441d5042018-10-18 16:49:51 -0700283 sp<Fence> getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const override;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700284
Jesse Hall851cfe82013-03-20 13:44:00 -0700285 // Set the output buffer and acquire fence for a virtual display.
Dan Stoza9e56aa02015-11-02 13:00:03 -0800286 // Returns INVALID_OPERATION if displayId is not a virtual display.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700287 status_t setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700288 const sp<GraphicBuffer>& buffer) override;
Jesse Hall851cfe82013-03-20 13:44:00 -0700289
Dan Stoza9e56aa02015-11-02 13:00:03 -0800290 // After SurfaceFlinger has retrieved the release fences for all the frames,
291 // it can call this to clear the shared pointers in the release fence map
Lloyd Pique441d5042018-10-18 16:49:51 -0700292 void clearReleaseFences(DisplayId displayId) override;
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700293
Peiyong Lin62665892018-04-16 11:07:44 -0700294 // Fetches the HDR capabilities of the given display
Lloyd Pique441d5042018-10-18 16:49:51 -0700295 status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) override;
Dan Stozac4f471e2016-03-24 09:31:08 -0700296
Lloyd Pique441d5042018-10-18 16:49:51 -0700297 int32_t getSupportedPerFrameMetadata(DisplayId displayId) const override;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700298
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700299 // Returns the available RenderIntent of the given display.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700300 std::vector<ui::RenderIntent> getRenderIntents(DisplayId displayId,
Lloyd Pique441d5042018-10-18 16:49:51 -0700301 ui::ColorMode colorMode) const override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700302
Lloyd Pique441d5042018-10-18 16:49:51 -0700303 mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700304
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700305 // Returns the attributes of the color sampling engine.
306 status_t getDisplayedContentSamplingAttributes(DisplayId displayId, ui::PixelFormat* outFormat,
307 ui::Dataspace* outDataspace,
Lloyd Pique441d5042018-10-18 16:49:51 -0700308 uint8_t* outComponentMask) override;
Kevin DuBois74e53772018-11-19 10:52:38 -0800309 status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled,
Lloyd Pique441d5042018-10-18 16:49:51 -0700310 uint8_t componentMask, uint64_t maxFrames) override;
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700311 status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700312 DisplayedFrameStats* outStats) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700313 std::future<status_t> setDisplayBrightness(DisplayId displayId, float brightness) override;
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700314
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700315 // Events handling ---------------------------------------------------------
316
Dominik Laskowski075d3172018-05-24 15:50:06 -0700317 // Returns stable display ID (and display name on connection of new or previously disconnected
318 // display), or std::nullopt if hotplug event was ignored.
Peiyong Line9d809e2020-04-14 13:10:48 -0700319 std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId hwcDisplayId,
320 hal::Connection connection) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700321
Peiyong Line9d809e2020-04-14 13:10:48 -0700322 bool onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) override;
323 void setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700324
Lloyd Pique441d5042018-10-18 16:49:51 -0700325 nsecs_t getRefreshTimestamp(DisplayId displayId) const override;
326 bool isConnected(DisplayId displayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700327
Dan Stoza9e56aa02015-11-02 13:00:03 -0800328 // Non-const because it can update configMap inside of mDisplayData
Lloyd Pique441d5042018-10-18 16:49:51 -0700329 std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs(
330 DisplayId displayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700331
Lloyd Pique441d5042018-10-18 16:49:51 -0700332 std::shared_ptr<const HWC2::Display::Config> getActiveConfig(
333 DisplayId displayId) const override;
334 int getActiveConfigIndex(DisplayId displayId) const override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700335
Lloyd Pique441d5042018-10-18 16:49:51 -0700336 std::vector<ui::ColorMode> getColorModes(DisplayId displayId) const override;
Michael Wright28f24d02016-07-12 13:30:53 -0700337
Dominik Laskowski075d3172018-05-24 15:50:06 -0700338 status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode,
Lloyd Pique441d5042018-10-18 16:49:51 -0700339 ui::RenderIntent renderIntent) override;
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600340
Lloyd Pique441d5042018-10-18 16:49:51 -0700341 bool isUsingVrComposer() const override;
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800342
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800343 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800344 DisplayConnectionType getDisplayConnectionType(DisplayId) const override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800345 bool isVsyncPeriodSwitchSupported(DisplayId displayId) const override;
346 nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const override;
347 status_t setActiveConfigWithConstraints(DisplayId displayId, size_t configId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700348 const hal::VsyncPeriodChangeConstraints& constraints,
349 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100350 status_t setAutoLowLatencyMode(DisplayId displayId, bool) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700351 status_t getSupportedContentTypes(DisplayId displayId, std::vector<hal::ContentType>*) override;
352 status_t setContentType(DisplayId displayId, hal::ContentType) override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800353
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800354 const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override;
355
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700356 // for debugging ----------------------------------------------------------
Lloyd Pique441d5042018-10-18 16:49:51 -0700357 void dump(std::string& out) const override;
Mathias Agopian83727852010-09-23 18:13:21 -0700358
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800359 Hwc2::Composer* getComposer() const override { return mComposer.get(); }
Steven Thomas6e8f7062017-11-22 14:15:29 -0800360
Dominik Laskowski075d3172018-05-24 15:50:06 -0700361 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700362 std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700363 return mInternalHwcDisplayId;
364 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700365 std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700366 return mExternalHwcDisplayId;
367 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700368
Peiyong Line9d809e2020-04-14 13:10:48 -0700369 std::optional<DisplayId> toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const override;
370 std::optional<hal::HWDisplayId> fromPhysicalDisplayId(DisplayId displayId) const override;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700371
Mathias Agopiana350ff92010-08-10 17:14:02 -0700372private:
Lloyd Piquee39cad22017-12-20 17:01:29 -0800373 // For unit tests
374 friend TestableSurfaceFlinger;
375
Peiyong Line9d809e2020-04-14 13:10:48 -0700376 std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId hwcDisplayId);
377 std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId hwcDisplayId);
378 bool shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId,
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100379 bool hasDisplayIdentificationData) const;
380
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800381 void loadCapabilities();
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800382 void loadLayerMetadataSupport();
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800383 uint32_t getMaxVirtualDisplayCount() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700384
Mathias Agopiane60b0682012-08-21 23:34:09 -0700385 struct DisplayData {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700386 bool isVirtual = false;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800387 std::unique_ptr<HWC2::Display> hwcDisplay;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700388 sp<Fence> lastPresentFence = Fence::NO_FENCE; // signals when the last set op retires
Steven Thomas94e35b92017-07-26 18:48:28 -0700389 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700390 buffer_handle_t outbufHandle = nullptr;
391 sp<Fence> outbufAcquireFence = Fence::NO_FENCE;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800392 mutable std::unordered_map<int32_t,
393 std::shared_ptr<const HWC2::Display::Config>> configMap;
Jamie Gennis2ec3e072012-11-11 16:24:33 -0800394
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700395 bool validateWasSkipped;
Peiyong Line9d809e2020-04-14 13:10:48 -0700396 hal::Error presentError;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800397
398 bool vsyncTraceToggle = false;
399
400 std::mutex vsyncEnabledLock;
Peiyong Line9d809e2020-04-14 13:10:48 -0700401 hal::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = hal::Vsync::DISABLE;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800402
403 mutable std::mutex lastHwVsyncLock;
404 nsecs_t lastHwVsync GUARDED_BY(lastHwVsyncLock) = 0;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700405 };
406
Dominik Laskowski075d3172018-05-24 15:50:06 -0700407 std::unordered_map<DisplayId, DisplayData> mDisplayData;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800408
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800409 std::unique_ptr<android::Hwc2::Composer> mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700410 std::unordered_set<hal::Capability> mCapabilities;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800411 std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800412 bool mRegisteredCallback = false;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800413
Peiyong Line9d809e2020-04-14 13:10:48 -0700414 std::unordered_map<hal::HWDisplayId, DisplayId> mPhysicalDisplayIdMap;
415 std::optional<hal::HWDisplayId> mInternalHwcDisplayId;
416 std::optional<hal::HWDisplayId> mExternalHwcDisplayId;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700417 bool mHasMultiDisplaySupport = false;
418
Dominik Laskowski34157762018-10-31 13:07:19 -0700419 std::unordered_set<DisplayId> mFreeVirtualDisplayIds;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700420 uint32_t mNextVirtualDisplayId = 0;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800421 uint32_t mRemainingHwcVirtualDisplays{getMaxVirtualDisplayCount()};
Mathias Agopiana350ff92010-08-10 17:14:02 -0700422};
423
Lloyd Pique441d5042018-10-18 16:49:51 -0700424} // namespace impl
Dominik Laskowski1af47932018-11-12 10:20:46 -0800425} // namespace android
Mathias Agopiana350ff92010-08-10 17:14:02 -0700426
427#endif // ANDROID_SF_HWCOMPOSER_H