blob: 488cdc510519ae69a8434456508450df81c9e27d [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
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800193 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800194 virtual DisplayConnectionType getDisplayConnectionType(DisplayId) const = 0;
Marin Shalamanova524a092020-07-27 21:39:55 +0200195 virtual bool isVsyncPeriodSwitchSupported(DisplayId) const = 0;
196 virtual nsecs_t getDisplayVsyncPeriod(DisplayId) const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800197 virtual status_t setActiveConfigWithConstraints(
Marin Shalamanova524a092020-07-27 21:39:55 +0200198 DisplayId, size_t configId, const hal::VsyncPeriodChangeConstraints&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700199 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Marin Shalamanova524a092020-07-27 21:39:55 +0200200 virtual status_t setAutoLowLatencyMode(DisplayId, bool on) = 0;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100201 virtual status_t getSupportedContentTypes(
Marin Shalamanova524a092020-07-27 21:39:55 +0200202 DisplayId, std::vector<hal::ContentType>* outSupportedContentTypes) = 0;
203 virtual status_t setContentType(DisplayId, hal::ContentType) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800204 virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata()
205 const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800206
Lloyd Pique441d5042018-10-18 16:49:51 -0700207 // for debugging ----------------------------------------------------------
208 virtual void dump(std::string& out) const = 0;
209
210 virtual Hwc2::Composer* getComposer() const = 0;
211
212 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700213 virtual std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const = 0;
214 virtual std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700215
Marin Shalamanova524a092020-07-27 21:39:55 +0200216 virtual std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const = 0;
217 virtual std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700218};
219
220namespace impl {
221
222class HWComposer final : public android::HWComposer {
Mathias Agopiana350ff92010-08-10 17:14:02 -0700223public:
Dominik Laskowski1af47932018-11-12 10:20:46 -0800224 explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800225 explicit HWComposer(const std::string& composerServiceName);
Mathias Agopian8b736f12012-08-13 17:54:26 -0700226
Lloyd Pique441d5042018-10-18 16:49:51 -0700227 ~HWComposer() override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700228
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800229 void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700230
Marin Shalamanova524a092020-07-27 21:39:55 +0200231 bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700232 DisplayIdentificationData* outData) const override;
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700233
Marin Shalamanova524a092020-07-27 21:39:55 +0200234 bool hasCapability(hal::Capability) const override;
235 bool hasDisplayCapability(DisplayId, hal::DisplayCapability) const override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700236
Dominik Laskowski075d3172018-05-24 15:50:06 -0700237 // Attempts to allocate a virtual display and returns its ID if created on the HWC device.
238 std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height,
Marin Shalamanova524a092020-07-27 21:39:55 +0200239 ui::PixelFormat*) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700240
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100241 // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated.
Marin Shalamanova524a092020-07-27 21:39:55 +0200242 void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) override;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100243
Dan Stoza9e56aa02015-11-02 13:00:03 -0800244 // Attempts to create a new layer on this display
Marin Shalamanova524a092020-07-27 21:39:55 +0200245 HWC2::Layer* createLayer(DisplayId) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700246 // Destroy a previously created layer
Marin Shalamanova524a092020-07-27 21:39:55 +0200247 void destroyLayer(DisplayId, HWC2::Layer*) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700248
Lloyd Pique66d68602019-02-13 14:23:31 -0800249 status_t getDeviceCompositionChanges(
250 DisplayId, bool frameUsesClientComposition,
251 std::optional<DeviceRequestedChanges>* outChanges) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700252
Marin Shalamanova524a092020-07-27 21:39:55 +0200253 status_t setClientTarget(DisplayId, uint32_t slot, const sp<Fence>& acquireFence,
254 const sp<GraphicBuffer>& target, ui::Dataspace) override;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800255
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800256 // Present layers to the display and read releaseFences.
Marin Shalamanova524a092020-07-27 21:39:55 +0200257 status_t presentAndGetReleaseFences(DisplayId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700258
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700259 // set power mode
Marin Shalamanova524a092020-07-27 21:39:55 +0200260 status_t setPowerMode(DisplayId, hal::PowerMode mode) override;
Colin Cross10fbdb62012-07-12 17:56:34 -0700261
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700262 // Sets a color transform to be applied to the result of composition
Marin Shalamanova524a092020-07-27 21:39:55 +0200263 status_t setColorTransform(DisplayId, const mat4& transform) override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700264
Andy McFadden27ec5732012-10-02 19:04:45 -0700265 // reset state when an external, non-virtual display is disconnected
Marin Shalamanova524a092020-07-27 21:39:55 +0200266 void disconnectDisplay(DisplayId) override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700267
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800268 // get the present fence received from the last call to present.
Marin Shalamanova524a092020-07-27 21:39:55 +0200269 sp<Fence> getPresentFence(DisplayId) const override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700270
Dan Stoza9e56aa02015-11-02 13:00:03 -0800271 // Get last release fence for the given layer
Marin Shalamanova524a092020-07-27 21:39:55 +0200272 sp<Fence> getLayerReleaseFence(DisplayId, HWC2::Layer*) const override;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700273
Jesse Hall851cfe82013-03-20 13:44:00 -0700274 // Set the output buffer and acquire fence for a virtual display.
Dan Stoza9e56aa02015-11-02 13:00:03 -0800275 // Returns INVALID_OPERATION if displayId is not a virtual display.
Marin Shalamanova524a092020-07-27 21:39:55 +0200276 status_t setOutputBuffer(DisplayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700277 const sp<GraphicBuffer>& buffer) override;
Jesse Hall851cfe82013-03-20 13:44:00 -0700278
Dan Stoza9e56aa02015-11-02 13:00:03 -0800279 // After SurfaceFlinger has retrieved the release fences for all the frames,
280 // it can call this to clear the shared pointers in the release fence map
Marin Shalamanova524a092020-07-27 21:39:55 +0200281 void clearReleaseFences(DisplayId) override;
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700282
Peiyong Lin62665892018-04-16 11:07:44 -0700283 // Fetches the HDR capabilities of the given display
Marin Shalamanova524a092020-07-27 21:39:55 +0200284 status_t getHdrCapabilities(DisplayId, HdrCapabilities* outCapabilities) override;
Dan Stozac4f471e2016-03-24 09:31:08 -0700285
Marin Shalamanova524a092020-07-27 21:39:55 +0200286 int32_t getSupportedPerFrameMetadata(DisplayId) const override;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700287
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700288 // Returns the available RenderIntent of the given display.
Marin Shalamanova524a092020-07-27 21:39:55 +0200289 std::vector<ui::RenderIntent> getRenderIntents(DisplayId, ui::ColorMode) const override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700290
Marin Shalamanova524a092020-07-27 21:39:55 +0200291 mat4 getDataspaceSaturationMatrix(DisplayId, ui::Dataspace) override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700292
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700293 // Returns the attributes of the color sampling engine.
Marin Shalamanova524a092020-07-27 21:39:55 +0200294 status_t getDisplayedContentSamplingAttributes(DisplayId, ui::PixelFormat* outFormat,
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700295 ui::Dataspace* outDataspace,
Lloyd Pique441d5042018-10-18 16:49:51 -0700296 uint8_t* outComponentMask) override;
Marin Shalamanova524a092020-07-27 21:39:55 +0200297 status_t setDisplayContentSamplingEnabled(DisplayId, bool enabled, uint8_t componentMask,
298 uint64_t maxFrames) override;
299 status_t getDisplayedContentSample(DisplayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700300 DisplayedFrameStats* outStats) override;
Marin Shalamanova524a092020-07-27 21:39:55 +0200301 std::future<status_t> setDisplayBrightness(DisplayId, float brightness) override;
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700302
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700303 // Events handling ---------------------------------------------------------
304
Dominik Laskowski075d3172018-05-24 15:50:06 -0700305 // Returns stable display ID (and display name on connection of new or previously disconnected
306 // display), or std::nullopt if hotplug event was ignored.
Marin Shalamanova524a092020-07-27 21:39:55 +0200307 std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId, hal::Connection) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700308
Marin Shalamanova524a092020-07-27 21:39:55 +0200309 bool onVsync(hal::HWDisplayId, int64_t timestamp) override;
310 void setVsyncEnabled(DisplayId, hal::Vsync enabled) override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700311
Marin Shalamanova524a092020-07-27 21:39:55 +0200312 nsecs_t getRefreshTimestamp(DisplayId) const override;
313 bool isConnected(DisplayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700314
Dan Stoza9e56aa02015-11-02 13:00:03 -0800315 // Non-const because it can update configMap inside of mDisplayData
Marin Shalamanova524a092020-07-27 21:39:55 +0200316 std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs(DisplayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700317
Marin Shalamanova524a092020-07-27 21:39:55 +0200318 std::shared_ptr<const HWC2::Display::Config> getActiveConfig(DisplayId) const override;
319 int getActiveConfigIndex(DisplayId) const override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700320
Marin Shalamanova524a092020-07-27 21:39:55 +0200321 std::vector<ui::ColorMode> getColorModes(DisplayId) const override;
Michael Wright28f24d02016-07-12 13:30:53 -0700322
Marin Shalamanova524a092020-07-27 21:39:55 +0200323 status_t setActiveColorMode(DisplayId, ui::ColorMode, ui::RenderIntent) override;
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600324
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800325 // Composer 2.4
Dominik Laskowski55c85402020-01-21 16:25:47 -0800326 DisplayConnectionType getDisplayConnectionType(DisplayId) const override;
Marin Shalamanova524a092020-07-27 21:39:55 +0200327 bool isVsyncPeriodSwitchSupported(DisplayId) const override;
328 nsecs_t getDisplayVsyncPeriod(DisplayId) const override;
329 status_t setActiveConfigWithConstraints(DisplayId, size_t configId,
330 const hal::VsyncPeriodChangeConstraints&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700331 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Marin Shalamanova524a092020-07-27 21:39:55 +0200332 status_t setAutoLowLatencyMode(DisplayId, bool) override;
333 status_t getSupportedContentTypes(DisplayId, std::vector<hal::ContentType>*) override;
334 status_t setContentType(DisplayId, hal::ContentType) override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800335
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800336 const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override;
337
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700338 // for debugging ----------------------------------------------------------
Lloyd Pique441d5042018-10-18 16:49:51 -0700339 void dump(std::string& out) const override;
Mathias Agopian83727852010-09-23 18:13:21 -0700340
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800341 Hwc2::Composer* getComposer() const override { return mComposer.get(); }
Steven Thomas6e8f7062017-11-22 14:15:29 -0800342
Dominik Laskowski075d3172018-05-24 15:50:06 -0700343 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700344 std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700345 return mInternalHwcDisplayId;
346 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700347 std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700348 return mExternalHwcDisplayId;
349 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700350
Marin Shalamanova524a092020-07-27 21:39:55 +0200351 std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const override;
352 std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const override;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700353
Mathias Agopiana350ff92010-08-10 17:14:02 -0700354private:
Lloyd Piquee39cad22017-12-20 17:01:29 -0800355 // For unit tests
356 friend TestableSurfaceFlinger;
357
Marin Shalamanova524a092020-07-27 21:39:55 +0200358 std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId);
359 std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId);
360 bool shouldIgnoreHotplugConnect(hal::HWDisplayId, bool hasDisplayIdentificationData) const;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100361
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800362 void loadCapabilities();
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800363 void loadLayerMetadataSupport();
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800364 uint32_t getMaxVirtualDisplayCount() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700365
Mathias Agopiane60b0682012-08-21 23:34:09 -0700366 struct DisplayData {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700367 bool isVirtual = false;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800368 std::unique_ptr<HWC2::Display> hwcDisplay;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700369 sp<Fence> lastPresentFence = Fence::NO_FENCE; // signals when the last set op retires
Steven Thomas94e35b92017-07-26 18:48:28 -0700370 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700371 buffer_handle_t outbufHandle = nullptr;
372 sp<Fence> outbufAcquireFence = Fence::NO_FENCE;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800373 mutable std::unordered_map<int32_t,
374 std::shared_ptr<const HWC2::Display::Config>> configMap;
Jamie Gennis2ec3e072012-11-11 16:24:33 -0800375
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700376 bool validateWasSkipped;
Peiyong Line9d809e2020-04-14 13:10:48 -0700377 hal::Error presentError;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800378
379 bool vsyncTraceToggle = false;
380
381 std::mutex vsyncEnabledLock;
Peiyong Line9d809e2020-04-14 13:10:48 -0700382 hal::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = hal::Vsync::DISABLE;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800383
384 mutable std::mutex lastHwVsyncLock;
385 nsecs_t lastHwVsync GUARDED_BY(lastHwVsyncLock) = 0;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700386 };
387
Dominik Laskowski075d3172018-05-24 15:50:06 -0700388 std::unordered_map<DisplayId, DisplayData> mDisplayData;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800389
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800390 std::unique_ptr<android::Hwc2::Composer> mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700391 std::unordered_set<hal::Capability> mCapabilities;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800392 std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800393 bool mRegisteredCallback = false;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800394
Marin Shalamanova524a092020-07-27 21:39:55 +0200395 std::unordered_map<hal::HWDisplayId, PhysicalDisplayId> mPhysicalDisplayIdMap;
Peiyong Line9d809e2020-04-14 13:10:48 -0700396 std::optional<hal::HWDisplayId> mInternalHwcDisplayId;
397 std::optional<hal::HWDisplayId> mExternalHwcDisplayId;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700398 bool mHasMultiDisplaySupport = false;
399
Dominik Laskowski34157762018-10-31 13:07:19 -0700400 std::unordered_set<DisplayId> mFreeVirtualDisplayIds;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700401 uint32_t mNextVirtualDisplayId = 0;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800402 uint32_t mRemainingHwcVirtualDisplays{getMaxVirtualDisplayCount()};
Mathias Agopiana350ff92010-08-10 17:14:02 -0700403};
404
Lloyd Pique441d5042018-10-18 16:49:51 -0700405} // namespace impl
Dominik Laskowski1af47932018-11-12 10:20:46 -0800406} // namespace android
Mathias Agopiana350ff92010-08-10 17:14:02 -0700407
408#endif // ANDROID_SF_HWCOMPOSER_H