blob: b7e9f3a693057e8d01238e818d905c51204ca9cd [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:
69 virtual ~HWComposer();
70
Lloyd Pique4603f3c2020-02-11 12:06:56 -080071 virtual void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -070072
Peiyong Line9d809e2020-04-14 13:10:48 -070073 virtual bool getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -070074 DisplayIdentificationData* outData) const = 0;
75
Peiyong Line9d809e2020-04-14 13:10:48 -070076 virtual bool hasCapability(hal::Capability capability) const = 0;
Dominik Laskowski1162e472020-04-02 19:02:47 -070077 virtual bool hasDisplayCapability(DisplayId displayId,
Peiyong Line9d809e2020-04-14 13:10:48 -070078 hal::DisplayCapability capability) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -070079
80 // Attempts to allocate a virtual display and returns its ID if created on the HWC device.
81 virtual std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height,
82 ui::PixelFormat* format) = 0;
83
Peiyong Line9d809e2020-04-14 13:10:48 -070084 virtual void allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) = 0;
Marin Shalamanovbdd59152020-02-14 15:30:06 +010085
Lloyd Pique441d5042018-10-18 16:49:51 -070086 // Attempts to create a new layer on this display
87 virtual HWC2::Layer* createLayer(DisplayId displayId) = 0;
88 // Destroy a previously created layer
89 virtual void destroyLayer(DisplayId displayId, HWC2::Layer* layer) = 0;
90
Lloyd Pique66d68602019-02-13 14:23:31 -080091 struct DeviceRequestedChanges {
Peiyong Line9d809e2020-04-14 13:10:48 -070092 using ChangedTypes = std::unordered_map<HWC2::Layer*, hal::Composition>;
93 using DisplayRequests = hal::DisplayRequest;
94 using LayerRequests = std::unordered_map<HWC2::Layer*, hal::LayerRequest>;
Lloyd Pique66d68602019-02-13 14:23:31 -080095
96 ChangedTypes changedTypes;
97 DisplayRequests displayRequests;
98 LayerRequests layerRequests;
99 };
100
101 // Gets any required composition change requests from the HWC device.
102 //
103 // Note that frameUsesClientComposition must be set correctly based on
104 // whether the current frame appears to use client composition. If it is
105 // false some internal optimizations are allowed to present the display
106 // with fewer handshakes, but this does not work if client composition is
107 // expected.
108 virtual status_t getDeviceCompositionChanges(
109 DisplayId, bool frameUsesClientComposition,
110 std::optional<DeviceRequestedChanges>* outChanges) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700111
112 virtual status_t setClientTarget(DisplayId displayId, uint32_t slot,
113 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target,
114 ui::Dataspace dataspace) = 0;
115
116 // Present layers to the display and read releaseFences.
117 virtual status_t presentAndGetReleaseFences(DisplayId displayId) = 0;
118
119 // set power mode
Peiyong Lin65248e02020-04-18 21:15:07 -0700120 virtual status_t setPowerMode(DisplayId displayId, hal::PowerMode mode) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700121
Lloyd Pique441d5042018-10-18 16:49:51 -0700122 // Sets a color transform to be applied to the result of composition
123 virtual status_t setColorTransform(DisplayId displayId, const mat4& transform) = 0;
124
125 // reset state when an external, non-virtual display is disconnected
126 virtual void disconnectDisplay(DisplayId displayId) = 0;
127
Lloyd Pique441d5042018-10-18 16:49:51 -0700128 // get the present fence received from the last call to present.
129 virtual sp<Fence> getPresentFence(DisplayId displayId) const = 0;
130
131 // Get last release fence for the given layer
132 virtual sp<Fence> getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const = 0;
133
134 // Set the output buffer and acquire fence for a virtual display.
135 // Returns INVALID_OPERATION if displayId is not a virtual display.
136 virtual status_t setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence,
137 const sp<GraphicBuffer>& buffer) = 0;
138
139 // After SurfaceFlinger has retrieved the release fences for all the frames,
140 // it can call this to clear the shared pointers in the release fence map
141 virtual void clearReleaseFences(DisplayId displayId) = 0;
142
143 // Fetches the HDR capabilities of the given display
144 virtual status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) = 0;
145
146 virtual int32_t getSupportedPerFrameMetadata(DisplayId displayId) const = 0;
147
148 // Returns the available RenderIntent of the given display.
149 virtual std::vector<ui::RenderIntent> getRenderIntents(DisplayId displayId,
150 ui::ColorMode colorMode) const = 0;
151
152 virtual mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) = 0;
153
154 // Returns the attributes of the color sampling engine.
155 virtual status_t getDisplayedContentSamplingAttributes(DisplayId displayId,
156 ui::PixelFormat* outFormat,
157 ui::Dataspace* outDataspace,
158 uint8_t* outComponentMask) = 0;
159 virtual status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled,
160 uint8_t componentMask,
161 uint64_t maxFrames) = 0;
162 virtual status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames,
163 uint64_t timestamp,
164 DisplayedFrameStats* outStats) = 0;
165
Dan Gittik57e63c52019-01-18 16:37:54 +0000166 // Sets the brightness of a display.
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700167 virtual std::future<status_t> setDisplayBrightness(DisplayId displayId, float brightness) = 0;
Dan Gittik57e63c52019-01-18 16:37:54 +0000168
Lloyd Pique441d5042018-10-18 16:49:51 -0700169 // Events handling ---------------------------------------------------------
170
171 // Returns stable display ID (and display name on connection of new or previously disconnected
172 // display), or std::nullopt if hotplug event was ignored.
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100173 // This function is called from SurfaceFlinger.
Peiyong Line9d809e2020-04-14 13:10:48 -0700174 virtual std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId hwcDisplayId,
175 hal::Connection connection) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700176
Peiyong Line9d809e2020-04-14 13:10:48 -0700177 virtual bool onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) = 0;
178 virtual void setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700179
180 virtual nsecs_t getRefreshTimestamp(DisplayId displayId) const = 0;
181 virtual bool isConnected(DisplayId displayId) const = 0;
182
183 // Non-const because it can update configMap inside of mDisplayData
184 virtual std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs(
185 DisplayId displayId) const = 0;
186
187 virtual std::shared_ptr<const HWC2::Display::Config> getActiveConfig(
188 DisplayId displayId) const = 0;
189 virtual int getActiveConfigIndex(DisplayId displayId) const = 0;
190
191 virtual std::vector<ui::ColorMode> getColorModes(DisplayId displayId) const = 0;
192
193 virtual status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode,
194 ui::RenderIntent renderIntent) = 0;
195
196 virtual bool isUsingVrComposer() const = 0;
197
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800198 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800199 virtual DisplayConnectionType getDisplayConnectionType(DisplayId) const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800200 virtual bool isVsyncPeriodSwitchSupported(DisplayId displayId) const = 0;
201 virtual nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const = 0;
202 virtual status_t setActiveConfigWithConstraints(
203 DisplayId displayId, size_t configId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700204 const hal::VsyncPeriodChangeConstraints& constraints,
205 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100206 virtual status_t setAutoLowLatencyMode(DisplayId displayId, bool on) = 0;
207 virtual status_t getSupportedContentTypes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700208 DisplayId displayId, std::vector<hal::ContentType>* outSupportedContentTypes) = 0;
209 virtual status_t setContentType(DisplayId displayId, hal::ContentType contentType) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800210 virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata()
211 const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800212
Lloyd Pique441d5042018-10-18 16:49:51 -0700213 // for debugging ----------------------------------------------------------
214 virtual void dump(std::string& out) const = 0;
215
216 virtual Hwc2::Composer* getComposer() const = 0;
217
218 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700219 virtual std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const = 0;
220 virtual std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700221
Peiyong Line9d809e2020-04-14 13:10:48 -0700222 virtual std::optional<DisplayId> toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const = 0;
223 virtual std::optional<hal::HWDisplayId> fromPhysicalDisplayId(DisplayId displayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700224};
225
226namespace impl {
227
228class HWComposer final : public android::HWComposer {
Mathias Agopiana350ff92010-08-10 17:14:02 -0700229public:
Dominik Laskowski1af47932018-11-12 10:20:46 -0800230 explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800231 explicit HWComposer(const std::string& composerServiceName);
Mathias Agopian8b736f12012-08-13 17:54:26 -0700232
Lloyd Pique441d5042018-10-18 16:49:51 -0700233 ~HWComposer() override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700234
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800235 void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700236
Peiyong Line9d809e2020-04-14 13:10:48 -0700237 bool getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700238 DisplayIdentificationData* outData) const override;
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700239
Peiyong Line9d809e2020-04-14 13:10:48 -0700240 bool hasCapability(hal::Capability capability) const override;
Dominik Laskowski1162e472020-04-02 19:02:47 -0700241 bool hasDisplayCapability(DisplayId displayId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700242 hal::DisplayCapability capability) const override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700243
Dominik Laskowski075d3172018-05-24 15:50:06 -0700244 // Attempts to allocate a virtual display and returns its ID if created on the HWC device.
245 std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height,
Lloyd Pique441d5042018-10-18 16:49:51 -0700246 ui::PixelFormat* format) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700247
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100248 // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated.
Peiyong Line9d809e2020-04-14 13:10:48 -0700249 void allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) override;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100250
Dan Stoza9e56aa02015-11-02 13:00:03 -0800251 // Attempts to create a new layer on this display
Lloyd Pique441d5042018-10-18 16:49:51 -0700252 HWC2::Layer* createLayer(DisplayId displayId) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700253 // Destroy a previously created layer
Lloyd Pique441d5042018-10-18 16:49:51 -0700254 void destroyLayer(DisplayId displayId, HWC2::Layer* layer) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700255
Lloyd Pique66d68602019-02-13 14:23:31 -0800256 status_t getDeviceCompositionChanges(
257 DisplayId, bool frameUsesClientComposition,
258 std::optional<DeviceRequestedChanges>* outChanges) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700259
Dominik Laskowski075d3172018-05-24 15:50:06 -0700260 status_t setClientTarget(DisplayId displayId, uint32_t slot, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700261 const sp<GraphicBuffer>& target, ui::Dataspace dataspace) override;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800262
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800263 // Present layers to the display and read releaseFences.
Lloyd Pique441d5042018-10-18 16:49:51 -0700264 status_t presentAndGetReleaseFences(DisplayId displayId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700265
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700266 // set power mode
Peiyong Lin65248e02020-04-18 21:15:07 -0700267 status_t setPowerMode(DisplayId displayId, hal::PowerMode mode) override;
Colin Cross10fbdb62012-07-12 17:56:34 -0700268
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700269 // Sets a color transform to be applied to the result of composition
Lloyd Pique441d5042018-10-18 16:49:51 -0700270 status_t setColorTransform(DisplayId displayId, const mat4& transform) override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700271
Andy McFadden27ec5732012-10-02 19:04:45 -0700272 // reset state when an external, non-virtual display is disconnected
Lloyd Pique441d5042018-10-18 16:49:51 -0700273 void disconnectDisplay(DisplayId displayId) override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700274
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800275 // get the present fence received from the last call to present.
Lloyd Pique441d5042018-10-18 16:49:51 -0700276 sp<Fence> getPresentFence(DisplayId displayId) const override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700277
Dan Stoza9e56aa02015-11-02 13:00:03 -0800278 // Get last release fence for the given layer
Lloyd Pique441d5042018-10-18 16:49:51 -0700279 sp<Fence> getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const override;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700280
Jesse Hall851cfe82013-03-20 13:44:00 -0700281 // Set the output buffer and acquire fence for a virtual display.
Dan Stoza9e56aa02015-11-02 13:00:03 -0800282 // Returns INVALID_OPERATION if displayId is not a virtual display.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700283 status_t setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700284 const sp<GraphicBuffer>& buffer) override;
Jesse Hall851cfe82013-03-20 13:44:00 -0700285
Dan Stoza9e56aa02015-11-02 13:00:03 -0800286 // After SurfaceFlinger has retrieved the release fences for all the frames,
287 // it can call this to clear the shared pointers in the release fence map
Lloyd Pique441d5042018-10-18 16:49:51 -0700288 void clearReleaseFences(DisplayId displayId) override;
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700289
Peiyong Lin62665892018-04-16 11:07:44 -0700290 // Fetches the HDR capabilities of the given display
Lloyd Pique441d5042018-10-18 16:49:51 -0700291 status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) override;
Dan Stozac4f471e2016-03-24 09:31:08 -0700292
Lloyd Pique441d5042018-10-18 16:49:51 -0700293 int32_t getSupportedPerFrameMetadata(DisplayId displayId) const override;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700294
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700295 // Returns the available RenderIntent of the given display.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700296 std::vector<ui::RenderIntent> getRenderIntents(DisplayId displayId,
Lloyd Pique441d5042018-10-18 16:49:51 -0700297 ui::ColorMode colorMode) const override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700298
Lloyd Pique441d5042018-10-18 16:49:51 -0700299 mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700300
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700301 // Returns the attributes of the color sampling engine.
302 status_t getDisplayedContentSamplingAttributes(DisplayId displayId, ui::PixelFormat* outFormat,
303 ui::Dataspace* outDataspace,
Lloyd Pique441d5042018-10-18 16:49:51 -0700304 uint8_t* outComponentMask) override;
Kevin DuBois74e53772018-11-19 10:52:38 -0800305 status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled,
Lloyd Pique441d5042018-10-18 16:49:51 -0700306 uint8_t componentMask, uint64_t maxFrames) override;
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700307 status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700308 DisplayedFrameStats* outStats) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700309 std::future<status_t> setDisplayBrightness(DisplayId displayId, float brightness) override;
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700310
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700311 // Events handling ---------------------------------------------------------
312
Dominik Laskowski075d3172018-05-24 15:50:06 -0700313 // Returns stable display ID (and display name on connection of new or previously disconnected
314 // display), or std::nullopt if hotplug event was ignored.
Peiyong Line9d809e2020-04-14 13:10:48 -0700315 std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId hwcDisplayId,
316 hal::Connection connection) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700317
Peiyong Line9d809e2020-04-14 13:10:48 -0700318 bool onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) override;
319 void setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700320
Lloyd Pique441d5042018-10-18 16:49:51 -0700321 nsecs_t getRefreshTimestamp(DisplayId displayId) const override;
322 bool isConnected(DisplayId displayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700323
Dan Stoza9e56aa02015-11-02 13:00:03 -0800324 // Non-const because it can update configMap inside of mDisplayData
Lloyd Pique441d5042018-10-18 16:49:51 -0700325 std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs(
326 DisplayId displayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700327
Lloyd Pique441d5042018-10-18 16:49:51 -0700328 std::shared_ptr<const HWC2::Display::Config> getActiveConfig(
329 DisplayId displayId) const override;
330 int getActiveConfigIndex(DisplayId displayId) const override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700331
Lloyd Pique441d5042018-10-18 16:49:51 -0700332 std::vector<ui::ColorMode> getColorModes(DisplayId displayId) const override;
Michael Wright28f24d02016-07-12 13:30:53 -0700333
Dominik Laskowski075d3172018-05-24 15:50:06 -0700334 status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode,
Lloyd Pique441d5042018-10-18 16:49:51 -0700335 ui::RenderIntent renderIntent) override;
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600336
Lloyd Pique441d5042018-10-18 16:49:51 -0700337 bool isUsingVrComposer() const override;
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800338
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800339 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800340 DisplayConnectionType getDisplayConnectionType(DisplayId) const override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800341 bool isVsyncPeriodSwitchSupported(DisplayId displayId) const override;
342 nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const override;
343 status_t setActiveConfigWithConstraints(DisplayId displayId, size_t configId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700344 const hal::VsyncPeriodChangeConstraints& constraints,
345 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100346 status_t setAutoLowLatencyMode(DisplayId displayId, bool) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700347 status_t getSupportedContentTypes(DisplayId displayId, std::vector<hal::ContentType>*) override;
348 status_t setContentType(DisplayId displayId, hal::ContentType) override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800349
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800350 const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override;
351
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700352 // for debugging ----------------------------------------------------------
Lloyd Pique441d5042018-10-18 16:49:51 -0700353 void dump(std::string& out) const override;
Mathias Agopian83727852010-09-23 18:13:21 -0700354
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800355 Hwc2::Composer* getComposer() const override { return mComposer.get(); }
Steven Thomas6e8f7062017-11-22 14:15:29 -0800356
Dominik Laskowski075d3172018-05-24 15:50:06 -0700357 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700358 std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700359 return mInternalHwcDisplayId;
360 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700361 std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700362 return mExternalHwcDisplayId;
363 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700364
Peiyong Line9d809e2020-04-14 13:10:48 -0700365 std::optional<DisplayId> toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const override;
366 std::optional<hal::HWDisplayId> fromPhysicalDisplayId(DisplayId displayId) const override;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700367
Mathias Agopiana350ff92010-08-10 17:14:02 -0700368private:
Lloyd Piquee39cad22017-12-20 17:01:29 -0800369 // For unit tests
370 friend TestableSurfaceFlinger;
371
Peiyong Line9d809e2020-04-14 13:10:48 -0700372 std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId hwcDisplayId);
373 std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId hwcDisplayId);
374 bool shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId,
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100375 bool hasDisplayIdentificationData) const;
376
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800377 void loadCapabilities();
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800378 void loadLayerMetadataSupport();
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800379 uint32_t getMaxVirtualDisplayCount() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700380
Mathias Agopiane60b0682012-08-21 23:34:09 -0700381 struct DisplayData {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700382 bool isVirtual = false;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800383 std::unique_ptr<HWC2::Display> hwcDisplay;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700384 sp<Fence> lastPresentFence = Fence::NO_FENCE; // signals when the last set op retires
Steven Thomas94e35b92017-07-26 18:48:28 -0700385 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700386 buffer_handle_t outbufHandle = nullptr;
387 sp<Fence> outbufAcquireFence = Fence::NO_FENCE;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800388 mutable std::unordered_map<int32_t,
389 std::shared_ptr<const HWC2::Display::Config>> configMap;
Jamie Gennis2ec3e072012-11-11 16:24:33 -0800390
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700391 bool validateWasSkipped;
Peiyong Line9d809e2020-04-14 13:10:48 -0700392 hal::Error presentError;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800393
394 bool vsyncTraceToggle = false;
395
396 std::mutex vsyncEnabledLock;
Peiyong Line9d809e2020-04-14 13:10:48 -0700397 hal::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = hal::Vsync::DISABLE;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800398
399 mutable std::mutex lastHwVsyncLock;
400 nsecs_t lastHwVsync GUARDED_BY(lastHwVsyncLock) = 0;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700401 };
402
Dominik Laskowski075d3172018-05-24 15:50:06 -0700403 std::unordered_map<DisplayId, DisplayData> mDisplayData;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800404
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800405 std::unique_ptr<android::Hwc2::Composer> mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700406 std::unordered_set<hal::Capability> mCapabilities;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800407 std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800408 bool mRegisteredCallback = false;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800409
Peiyong Line9d809e2020-04-14 13:10:48 -0700410 std::unordered_map<hal::HWDisplayId, DisplayId> mPhysicalDisplayIdMap;
411 std::optional<hal::HWDisplayId> mInternalHwcDisplayId;
412 std::optional<hal::HWDisplayId> mExternalHwcDisplayId;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700413 bool mHasMultiDisplaySupport = false;
414
Dominik Laskowski34157762018-10-31 13:07:19 -0700415 std::unordered_set<DisplayId> mFreeVirtualDisplayIds;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700416 uint32_t mNextVirtualDisplayId = 0;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800417 uint32_t mRemainingHwcVirtualDisplays{getMaxVirtualDisplayCount()};
Mathias Agopiana350ff92010-08-10 17:14:02 -0700418};
419
Lloyd Pique441d5042018-10-18 16:49:51 -0700420} // namespace impl
Dominik Laskowski1af47932018-11-12 10:20:46 -0800421} // namespace android
Mathias Agopiana350ff92010-08-10 17:14:02 -0700422
423#endif // ANDROID_SF_HWCOMPOSER_H