blob: 698e3afa4637b15acdfc7ba141e2a04b7b48d952 [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
Marin Shalamanova524a092020-07-27 21:39:55 +020087 virtual bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -070088 DisplayIdentificationData* outData) const = 0;
89
Marin Shalamanova524a092020-07-27 21:39:55 +020090 virtual bool hasCapability(hal::Capability) const = 0;
91 virtual bool hasDisplayCapability(DisplayId, hal::DisplayCapability) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -070092
93 // Attempts to allocate a virtual display and returns its ID if created on the HWC device.
94 virtual std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height,
Marin Shalamanova524a092020-07-27 21:39:55 +020095 ui::PixelFormat*) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -070096
Marin Shalamanova524a092020-07-27 21:39:55 +020097 virtual void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) = 0;
Marin Shalamanovbdd59152020-02-14 15:30:06 +010098
Lloyd Pique441d5042018-10-18 16:49:51 -070099 // Attempts to create a new layer on this display
Marin Shalamanova524a092020-07-27 21:39:55 +0200100 virtual HWC2::Layer* createLayer(DisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700101 // Destroy a previously created layer
Marin Shalamanova524a092020-07-27 21:39:55 +0200102 virtual void destroyLayer(DisplayId, HWC2::Layer*) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700103
Lloyd Pique66d68602019-02-13 14:23:31 -0800104 // Gets any required composition change requests from the HWC device.
105 //
106 // Note that frameUsesClientComposition must be set correctly based on
107 // whether the current frame appears to use client composition. If it is
108 // false some internal optimizations are allowed to present the display
109 // with fewer handshakes, but this does not work if client composition is
110 // expected.
111 virtual status_t getDeviceCompositionChanges(
112 DisplayId, bool frameUsesClientComposition,
113 std::optional<DeviceRequestedChanges>* outChanges) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700114
Marin Shalamanova524a092020-07-27 21:39:55 +0200115 virtual status_t setClientTarget(DisplayId, uint32_t slot, const sp<Fence>& acquireFence,
116 const sp<GraphicBuffer>& target, ui::Dataspace) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700117
118 // Present layers to the display and read releaseFences.
Marin Shalamanova524a092020-07-27 21:39:55 +0200119 virtual status_t presentAndGetReleaseFences(DisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700120
121 // set power mode
Marin Shalamanova524a092020-07-27 21:39:55 +0200122 virtual status_t setPowerMode(DisplayId, hal::PowerMode) = 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
Marin Shalamanova524a092020-07-27 21:39:55 +0200125 virtual status_t setColorTransform(DisplayId, const mat4& transform) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700126
127 // reset state when an external, non-virtual display is disconnected
Marin Shalamanova524a092020-07-27 21:39:55 +0200128 virtual void disconnectDisplay(DisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700129
Lloyd Pique441d5042018-10-18 16:49:51 -0700130 // get the present fence received from the last call to present.
Marin Shalamanova524a092020-07-27 21:39:55 +0200131 virtual sp<Fence> getPresentFence(DisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700132
133 // Get last release fence for the given layer
Marin Shalamanova524a092020-07-27 21:39:55 +0200134 virtual sp<Fence> getLayerReleaseFence(DisplayId, HWC2::Layer*) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700135
136 // Set the output buffer and acquire fence for a virtual display.
137 // Returns INVALID_OPERATION if displayId is not a virtual display.
Marin Shalamanova524a092020-07-27 21:39:55 +0200138 virtual status_t setOutputBuffer(DisplayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700139 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
Marin Shalamanova524a092020-07-27 21:39:55 +0200143 virtual void clearReleaseFences(DisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700144
145 // Fetches the HDR capabilities of the given display
Marin Shalamanova524a092020-07-27 21:39:55 +0200146 virtual status_t getHdrCapabilities(DisplayId, HdrCapabilities* outCapabilities) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700147
Marin Shalamanova524a092020-07-27 21:39:55 +0200148 virtual int32_t getSupportedPerFrameMetadata(DisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700149
150 // Returns the available RenderIntent of the given display.
Marin Shalamanova524a092020-07-27 21:39:55 +0200151 virtual std::vector<ui::RenderIntent> getRenderIntents(DisplayId, ui::ColorMode) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700152
Marin Shalamanova524a092020-07-27 21:39:55 +0200153 virtual mat4 getDataspaceSaturationMatrix(DisplayId, ui::Dataspace) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700154
155 // Returns the attributes of the color sampling engine.
Marin Shalamanova524a092020-07-27 21:39:55 +0200156 virtual status_t getDisplayedContentSamplingAttributes(DisplayId, ui::PixelFormat* outFormat,
Lloyd Pique441d5042018-10-18 16:49:51 -0700157 ui::Dataspace* outDataspace,
158 uint8_t* outComponentMask) = 0;
Marin Shalamanova524a092020-07-27 21:39:55 +0200159 virtual status_t setDisplayContentSamplingEnabled(DisplayId, bool enabled,
Lloyd Pique441d5042018-10-18 16:49:51 -0700160 uint8_t componentMask,
161 uint64_t maxFrames) = 0;
Marin Shalamanova524a092020-07-27 21:39:55 +0200162 virtual status_t getDisplayedContentSample(DisplayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700163 DisplayedFrameStats* outStats) = 0;
164
Dan Gittik57e63c52019-01-18 16:37:54 +0000165 // Sets the brightness of a display.
Marin Shalamanova524a092020-07-27 21:39:55 +0200166 virtual std::future<status_t> setDisplayBrightness(DisplayId, float brightness) = 0;
Dan Gittik57e63c52019-01-18 16:37:54 +0000167
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.
Marin Shalamanova524a092020-07-27 21:39:55 +0200173 virtual std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId,
174 hal::Connection) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700175
Marin Shalamanova524a092020-07-27 21:39:55 +0200176 virtual bool onVsync(hal::HWDisplayId, int64_t timestamp) = 0;
177 virtual void setVsyncEnabled(DisplayId, hal::Vsync enabled) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700178
Marin Shalamanova524a092020-07-27 21:39:55 +0200179 virtual nsecs_t getRefreshTimestamp(DisplayId) const = 0;
180 virtual bool isConnected(DisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700181
182 // Non-const because it can update configMap inside of mDisplayData
183 virtual std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs(
Marin Shalamanova524a092020-07-27 21:39:55 +0200184 DisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700185
Marin Shalamanova524a092020-07-27 21:39:55 +0200186 virtual std::shared_ptr<const HWC2::Display::Config> getActiveConfig(DisplayId) const = 0;
187 virtual int getActiveConfigIndex(DisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700188
Marin Shalamanova524a092020-07-27 21:39:55 +0200189 virtual std::vector<ui::ColorMode> getColorModes(DisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700190
Marin Shalamanova524a092020-07-27 21:39:55 +0200191 virtual status_t setActiveColorMode(DisplayId, ui::ColorMode mode, ui::RenderIntent) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700192
193 virtual bool isUsingVrComposer() const = 0;
194
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800195 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800196 virtual DisplayConnectionType getDisplayConnectionType(DisplayId) const = 0;
Marin Shalamanova524a092020-07-27 21:39:55 +0200197 virtual bool isVsyncPeriodSwitchSupported(DisplayId) const = 0;
198 virtual nsecs_t getDisplayVsyncPeriod(DisplayId) const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800199 virtual status_t setActiveConfigWithConstraints(
Marin Shalamanova524a092020-07-27 21:39:55 +0200200 DisplayId, size_t configId, const hal::VsyncPeriodChangeConstraints&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700201 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Marin Shalamanova524a092020-07-27 21:39:55 +0200202 virtual status_t setAutoLowLatencyMode(DisplayId, bool on) = 0;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100203 virtual status_t getSupportedContentTypes(
Marin Shalamanova524a092020-07-27 21:39:55 +0200204 DisplayId, std::vector<hal::ContentType>* outSupportedContentTypes) = 0;
205 virtual status_t setContentType(DisplayId, hal::ContentType) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800206 virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata()
207 const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800208
Lloyd Pique441d5042018-10-18 16:49:51 -0700209 // for debugging ----------------------------------------------------------
210 virtual void dump(std::string& out) const = 0;
211
212 virtual Hwc2::Composer* getComposer() const = 0;
213
214 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700215 virtual std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const = 0;
216 virtual std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700217
Marin Shalamanova524a092020-07-27 21:39:55 +0200218 virtual std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const = 0;
219 virtual std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700220};
221
222namespace impl {
223
224class HWComposer final : public android::HWComposer {
Mathias Agopiana350ff92010-08-10 17:14:02 -0700225public:
Dominik Laskowski1af47932018-11-12 10:20:46 -0800226 explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800227 explicit HWComposer(const std::string& composerServiceName);
Mathias Agopian8b736f12012-08-13 17:54:26 -0700228
Lloyd Pique441d5042018-10-18 16:49:51 -0700229 ~HWComposer() override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700230
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800231 void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700232
Marin Shalamanova524a092020-07-27 21:39:55 +0200233 bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700234 DisplayIdentificationData* outData) const override;
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700235
Marin Shalamanova524a092020-07-27 21:39:55 +0200236 bool hasCapability(hal::Capability) const override;
237 bool hasDisplayCapability(DisplayId, hal::DisplayCapability) const override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700238
Dominik Laskowski075d3172018-05-24 15:50:06 -0700239 // Attempts to allocate a virtual display and returns its ID if created on the HWC device.
240 std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height,
Marin Shalamanova524a092020-07-27 21:39:55 +0200241 ui::PixelFormat*) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700242
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100243 // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated.
Marin Shalamanova524a092020-07-27 21:39:55 +0200244 void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) override;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100245
Dan Stoza9e56aa02015-11-02 13:00:03 -0800246 // Attempts to create a new layer on this display
Marin Shalamanova524a092020-07-27 21:39:55 +0200247 HWC2::Layer* createLayer(DisplayId) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700248 // Destroy a previously created layer
Marin Shalamanova524a092020-07-27 21:39:55 +0200249 void destroyLayer(DisplayId, HWC2::Layer*) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700250
Lloyd Pique66d68602019-02-13 14:23:31 -0800251 status_t getDeviceCompositionChanges(
252 DisplayId, bool frameUsesClientComposition,
253 std::optional<DeviceRequestedChanges>* outChanges) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700254
Marin Shalamanova524a092020-07-27 21:39:55 +0200255 status_t setClientTarget(DisplayId, uint32_t slot, const sp<Fence>& acquireFence,
256 const sp<GraphicBuffer>& target, ui::Dataspace) override;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800257
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800258 // Present layers to the display and read releaseFences.
Marin Shalamanova524a092020-07-27 21:39:55 +0200259 status_t presentAndGetReleaseFences(DisplayId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700260
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700261 // set power mode
Marin Shalamanova524a092020-07-27 21:39:55 +0200262 status_t setPowerMode(DisplayId, hal::PowerMode mode) override;
Colin Cross10fbdb62012-07-12 17:56:34 -0700263
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700264 // Sets a color transform to be applied to the result of composition
Marin Shalamanova524a092020-07-27 21:39:55 +0200265 status_t setColorTransform(DisplayId, const mat4& transform) override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700266
Andy McFadden27ec5732012-10-02 19:04:45 -0700267 // reset state when an external, non-virtual display is disconnected
Marin Shalamanova524a092020-07-27 21:39:55 +0200268 void disconnectDisplay(DisplayId) override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700269
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800270 // get the present fence received from the last call to present.
Marin Shalamanova524a092020-07-27 21:39:55 +0200271 sp<Fence> getPresentFence(DisplayId) const override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700272
Dan Stoza9e56aa02015-11-02 13:00:03 -0800273 // Get last release fence for the given layer
Marin Shalamanova524a092020-07-27 21:39:55 +0200274 sp<Fence> getLayerReleaseFence(DisplayId, HWC2::Layer*) const override;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700275
Jesse Hall851cfe82013-03-20 13:44:00 -0700276 // Set the output buffer and acquire fence for a virtual display.
Dan Stoza9e56aa02015-11-02 13:00:03 -0800277 // Returns INVALID_OPERATION if displayId is not a virtual display.
Marin Shalamanova524a092020-07-27 21:39:55 +0200278 status_t setOutputBuffer(DisplayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700279 const sp<GraphicBuffer>& buffer) override;
Jesse Hall851cfe82013-03-20 13:44:00 -0700280
Dan Stoza9e56aa02015-11-02 13:00:03 -0800281 // After SurfaceFlinger has retrieved the release fences for all the frames,
282 // it can call this to clear the shared pointers in the release fence map
Marin Shalamanova524a092020-07-27 21:39:55 +0200283 void clearReleaseFences(DisplayId) override;
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700284
Peiyong Lin62665892018-04-16 11:07:44 -0700285 // Fetches the HDR capabilities of the given display
Marin Shalamanova524a092020-07-27 21:39:55 +0200286 status_t getHdrCapabilities(DisplayId, HdrCapabilities* outCapabilities) override;
Dan Stozac4f471e2016-03-24 09:31:08 -0700287
Marin Shalamanova524a092020-07-27 21:39:55 +0200288 int32_t getSupportedPerFrameMetadata(DisplayId) const override;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700289
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700290 // Returns the available RenderIntent of the given display.
Marin Shalamanova524a092020-07-27 21:39:55 +0200291 std::vector<ui::RenderIntent> getRenderIntents(DisplayId, ui::ColorMode) const override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700292
Marin Shalamanova524a092020-07-27 21:39:55 +0200293 mat4 getDataspaceSaturationMatrix(DisplayId, ui::Dataspace) override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700294
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700295 // Returns the attributes of the color sampling engine.
Marin Shalamanova524a092020-07-27 21:39:55 +0200296 status_t getDisplayedContentSamplingAttributes(DisplayId, ui::PixelFormat* outFormat,
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700297 ui::Dataspace* outDataspace,
Lloyd Pique441d5042018-10-18 16:49:51 -0700298 uint8_t* outComponentMask) override;
Marin Shalamanova524a092020-07-27 21:39:55 +0200299 status_t setDisplayContentSamplingEnabled(DisplayId, bool enabled, uint8_t componentMask,
300 uint64_t maxFrames) override;
301 status_t getDisplayedContentSample(DisplayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700302 DisplayedFrameStats* outStats) override;
Marin Shalamanova524a092020-07-27 21:39:55 +0200303 std::future<status_t> setDisplayBrightness(DisplayId, float brightness) override;
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700304
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700305 // Events handling ---------------------------------------------------------
306
Dominik Laskowski075d3172018-05-24 15:50:06 -0700307 // Returns stable display ID (and display name on connection of new or previously disconnected
308 // display), or std::nullopt if hotplug event was ignored.
Marin Shalamanova524a092020-07-27 21:39:55 +0200309 std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId, hal::Connection) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700310
Marin Shalamanova524a092020-07-27 21:39:55 +0200311 bool onVsync(hal::HWDisplayId, int64_t timestamp) override;
312 void setVsyncEnabled(DisplayId, hal::Vsync enabled) override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700313
Marin Shalamanova524a092020-07-27 21:39:55 +0200314 nsecs_t getRefreshTimestamp(DisplayId) const override;
315 bool isConnected(DisplayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700316
Dan Stoza9e56aa02015-11-02 13:00:03 -0800317 // Non-const because it can update configMap inside of mDisplayData
Marin Shalamanova524a092020-07-27 21:39:55 +0200318 std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs(DisplayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700319
Marin Shalamanova524a092020-07-27 21:39:55 +0200320 std::shared_ptr<const HWC2::Display::Config> getActiveConfig(DisplayId) const override;
321 int getActiveConfigIndex(DisplayId) const override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700322
Marin Shalamanova524a092020-07-27 21:39:55 +0200323 std::vector<ui::ColorMode> getColorModes(DisplayId) const override;
Michael Wright28f24d02016-07-12 13:30:53 -0700324
Marin Shalamanova524a092020-07-27 21:39:55 +0200325 status_t setActiveColorMode(DisplayId, ui::ColorMode, ui::RenderIntent) override;
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600326
Lloyd Pique441d5042018-10-18 16:49:51 -0700327 bool isUsingVrComposer() const override;
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800328
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800329 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800330 DisplayConnectionType getDisplayConnectionType(DisplayId) const override;
Marin Shalamanova524a092020-07-27 21:39:55 +0200331 bool isVsyncPeriodSwitchSupported(DisplayId) const override;
332 nsecs_t getDisplayVsyncPeriod(DisplayId) const override;
333 status_t setActiveConfigWithConstraints(DisplayId, size_t configId,
334 const hal::VsyncPeriodChangeConstraints&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700335 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Marin Shalamanova524a092020-07-27 21:39:55 +0200336 status_t setAutoLowLatencyMode(DisplayId, bool) override;
337 status_t getSupportedContentTypes(DisplayId, std::vector<hal::ContentType>*) override;
338 status_t setContentType(DisplayId, hal::ContentType) override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800339
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800340 const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override;
341
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700342 // for debugging ----------------------------------------------------------
Lloyd Pique441d5042018-10-18 16:49:51 -0700343 void dump(std::string& out) const override;
Mathias Agopian83727852010-09-23 18:13:21 -0700344
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800345 Hwc2::Composer* getComposer() const override { return mComposer.get(); }
Steven Thomas6e8f7062017-11-22 14:15:29 -0800346
Dominik Laskowski075d3172018-05-24 15:50:06 -0700347 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700348 std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700349 return mInternalHwcDisplayId;
350 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700351 std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700352 return mExternalHwcDisplayId;
353 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700354
Marin Shalamanova524a092020-07-27 21:39:55 +0200355 std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const override;
356 std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const override;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700357
Mathias Agopiana350ff92010-08-10 17:14:02 -0700358private:
Lloyd Piquee39cad22017-12-20 17:01:29 -0800359 // For unit tests
360 friend TestableSurfaceFlinger;
361
Marin Shalamanova524a092020-07-27 21:39:55 +0200362 std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId);
363 std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId);
364 bool shouldIgnoreHotplugConnect(hal::HWDisplayId, bool hasDisplayIdentificationData) const;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100365
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800366 void loadCapabilities();
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800367 void loadLayerMetadataSupport();
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800368 uint32_t getMaxVirtualDisplayCount() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700369
Mathias Agopiane60b0682012-08-21 23:34:09 -0700370 struct DisplayData {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700371 bool isVirtual = false;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800372 std::unique_ptr<HWC2::Display> hwcDisplay;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700373 sp<Fence> lastPresentFence = Fence::NO_FENCE; // signals when the last set op retires
Steven Thomas94e35b92017-07-26 18:48:28 -0700374 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700375 buffer_handle_t outbufHandle = nullptr;
376 sp<Fence> outbufAcquireFence = Fence::NO_FENCE;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800377 mutable std::unordered_map<int32_t,
378 std::shared_ptr<const HWC2::Display::Config>> configMap;
Jamie Gennis2ec3e072012-11-11 16:24:33 -0800379
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700380 bool validateWasSkipped;
Peiyong Line9d809e2020-04-14 13:10:48 -0700381 hal::Error presentError;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800382
383 bool vsyncTraceToggle = false;
384
385 std::mutex vsyncEnabledLock;
Peiyong Line9d809e2020-04-14 13:10:48 -0700386 hal::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = hal::Vsync::DISABLE;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800387
388 mutable std::mutex lastHwVsyncLock;
389 nsecs_t lastHwVsync GUARDED_BY(lastHwVsyncLock) = 0;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700390 };
391
Dominik Laskowski075d3172018-05-24 15:50:06 -0700392 std::unordered_map<DisplayId, DisplayData> mDisplayData;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800393
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800394 std::unique_ptr<android::Hwc2::Composer> mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700395 std::unordered_set<hal::Capability> mCapabilities;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800396 std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800397 bool mRegisteredCallback = false;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800398
Marin Shalamanova524a092020-07-27 21:39:55 +0200399 std::unordered_map<hal::HWDisplayId, PhysicalDisplayId> mPhysicalDisplayIdMap;
Peiyong Line9d809e2020-04-14 13:10:48 -0700400 std::optional<hal::HWDisplayId> mInternalHwcDisplayId;
401 std::optional<hal::HWDisplayId> mExternalHwcDisplayId;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700402 bool mHasMultiDisplaySupport = false;
403
Dominik Laskowski34157762018-10-31 13:07:19 -0700404 std::unordered_set<DisplayId> mFreeVirtualDisplayIds;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700405 uint32_t mNextVirtualDisplayId = 0;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800406 uint32_t mRemainingHwcVirtualDisplays{getMaxVirtualDisplayCount()};
Mathias Agopiana350ff92010-08-10 17:14:02 -0700407};
408
Lloyd Pique441d5042018-10-18 16:49:51 -0700409} // namespace impl
Dominik Laskowski1af47932018-11-12 10:20:46 -0800410} // namespace android
Mathias Agopiana350ff92010-08-10 17:14:02 -0700411
412#endif // ANDROID_SF_HWCOMPOSER_H