blob: 5bad52973ac97aeffdea63447db3d95e14dbfaa5 [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"
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010035#pragma clang diagnostic ignored "-Wextra"
Dominik Laskowski1af47932018-11-12 10:20:46 -080036#include <ui/GraphicTypes.h>
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010037#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
Ady Abraham8a82ba62020-01-17 12:43:17 -080038
Dominik Laskowski1af47932018-11-12 10:20:46 -080039#include <utils/StrongPointer.h>
40#include <utils/Timers.h>
41
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020042#include "DisplayIdGenerator.h"
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -070043#include "DisplayIdentification.h"
Marin Shalamanov3ea1d602020-12-16 19:59:39 +010044#include "DisplayMode.h"
Dominik Laskowski1af47932018-11-12 10:20:46 -080045#include "HWC2.h"
Peiyong Line9d809e2020-04-14 13:10:48 -070046#include "Hal.h"
Dan Stoza9e56aa02015-11-02 13:00:03 -080047
Mathias Agopiana350ff92010-08-10 17:14:02 -070048namespace android {
Mathias Agopiana350ff92010-08-10 17:14:02 -070049
Peiyong Line9d809e2020-04-14 13:10:48 -070050namespace hal = hardware::graphics::composer::hal;
51
Kevin DuBois1d4249a2018-08-29 10:45:14 -070052struct DisplayedFrameStats;
Jesse Hall399184a2014-03-03 15:42:54 -080053class GraphicBuffer;
Lloyd Piquee39cad22017-12-20 17:01:29 -080054class TestableSurfaceFlinger;
David Sodmanfb95bcc2017-12-22 15:45:30 -080055struct CompositionInfo;
Mathias Agopian83727852010-09-23 18:13:21 -070056
Lloyd Piquea822d522017-12-20 16:42:57 -080057namespace Hwc2 {
58class Composer;
59} // namespace Hwc2
60
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080061namespace compositionengine {
62class Output;
63} // namespace compositionengine
64
Lloyd Pique4603f3c2020-02-11 12:06:56 -080065struct KnownHWCGenericLayerMetadata {
66 const char* name;
67 const uint32_t id;
68};
69
Marin Shalamanov1c434292020-06-12 01:47:29 +020070// See the comment for SurfaceFlinger::getHwComposer for the thread safety rules for accessing
71// this class.
Lloyd Pique441d5042018-10-18 16:49:51 -070072class HWComposer {
73public:
Peiyong Lindfc3f7c2020-05-07 20:15:50 -070074 struct DeviceRequestedChanges {
75 using ChangedTypes = std::unordered_map<HWC2::Layer*, hal::Composition>;
76 using ClientTargetProperty = hal::ClientTargetProperty;
77 using DisplayRequests = hal::DisplayRequest;
78 using LayerRequests = std::unordered_map<HWC2::Layer*, hal::LayerRequest>;
79
80 ChangedTypes changedTypes;
81 DisplayRequests displayRequests;
82 LayerRequests layerRequests;
83 ClientTargetProperty clientTargetProperty;
84 };
85
Marin Shalamanov045b7002021-01-07 16:56:24 +010086 struct HWCDisplayMode {
87 hal::HWConfigId hwcId;
88 int32_t width = -1;
89 int32_t height = -1;
90 nsecs_t vsyncPeriod = -1;
91 int32_t dpiX = -1;
92 int32_t dpiY = -1;
93 int32_t configGroup = -1;
Marin Shalamanovd3b5c5d2021-02-11 18:26:14 +010094
95 friend std::ostream& operator<<(std::ostream& os, const HWCDisplayMode& mode) {
96 return os << "id=" << mode.hwcId << " res=" << mode.width << "x" << mode.height
97 << " vsyncPeriod=" << mode.vsyncPeriod << " dpi=" << mode.dpiX << "x"
98 << mode.dpiY << " group=" << mode.configGroup;
99 }
Marin Shalamanov045b7002021-01-07 16:56:24 +0100100 };
101
Lloyd Pique441d5042018-10-18 16:49:51 -0700102 virtual ~HWComposer();
103
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800104 virtual void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700105
Marin Shalamanova524a092020-07-27 21:39:55 +0200106 virtual bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700107 DisplayIdentificationData* outData) const = 0;
108
Marin Shalamanova524a092020-07-27 21:39:55 +0200109 virtual bool hasCapability(hal::Capability) const = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200110 virtual bool hasDisplayCapability(HalDisplayId, hal::DisplayCapability) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700111
112 // Attempts to allocate a virtual display and returns its ID if created on the HWC device.
113 virtual std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height,
Marin Shalamanova524a092020-07-27 21:39:55 +0200114 ui::PixelFormat*) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700115
Marin Shalamanova524a092020-07-27 21:39:55 +0200116 virtual void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) = 0;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100117
Lloyd Pique441d5042018-10-18 16:49:51 -0700118 // Attempts to create a new layer on this display
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200119 virtual HWC2::Layer* createLayer(HalDisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700120 // Destroy a previously created layer
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200121 virtual void destroyLayer(HalDisplayId, HWC2::Layer*) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700122
Lloyd Pique66d68602019-02-13 14:23:31 -0800123 // Gets any required composition change requests from the HWC device.
124 //
125 // Note that frameUsesClientComposition must be set correctly based on
126 // whether the current frame appears to use client composition. If it is
127 // false some internal optimizations are allowed to present the display
128 // with fewer handshakes, but this does not work if client composition is
129 // expected.
130 virtual status_t getDeviceCompositionChanges(
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200131 HalDisplayId, bool frameUsesClientComposition,
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700132 std::chrono::steady_clock::time_point earliestPresentTime,
Lloyd Pique66d68602019-02-13 14:23:31 -0800133 std::optional<DeviceRequestedChanges>* outChanges) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700134
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200135 virtual status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence,
Marin Shalamanova524a092020-07-27 21:39:55 +0200136 const sp<GraphicBuffer>& target, ui::Dataspace) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700137
138 // Present layers to the display and read releaseFences.
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700139 virtual status_t presentAndGetReleaseFences(
140 HalDisplayId, std::chrono::steady_clock::time_point earliestPresentTime) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700141
142 // set power mode
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200143 virtual status_t setPowerMode(PhysicalDisplayId, hal::PowerMode) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700144
Lloyd Pique441d5042018-10-18 16:49:51 -0700145 // Sets a color transform to be applied to the result of composition
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200146 virtual status_t setColorTransform(HalDisplayId, const mat4& transform) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700147
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200148 // reset state when a display is disconnected
149 virtual void disconnectDisplay(HalDisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700150
Lloyd Pique441d5042018-10-18 16:49:51 -0700151 // get the present fence received from the last call to present.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200152 virtual sp<Fence> getPresentFence(HalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700153
154 // Get last release fence for the given layer
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200155 virtual sp<Fence> getLayerReleaseFence(HalDisplayId, HWC2::Layer*) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700156
157 // Set the output buffer and acquire fence for a virtual display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200158 virtual status_t setOutputBuffer(HalVirtualDisplayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700159 const sp<GraphicBuffer>& buffer) = 0;
160
161 // After SurfaceFlinger has retrieved the release fences for all the frames,
162 // it can call this to clear the shared pointers in the release fence map
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200163 virtual void clearReleaseFences(HalDisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700164
165 // Fetches the HDR capabilities of the given display
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200166 virtual status_t getHdrCapabilities(HalDisplayId, HdrCapabilities* outCapabilities) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700167
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200168 virtual int32_t getSupportedPerFrameMetadata(HalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700169
170 // Returns the available RenderIntent of the given display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200171 virtual std::vector<ui::RenderIntent> getRenderIntents(HalDisplayId, ui::ColorMode) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700172
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200173 virtual mat4 getDataspaceSaturationMatrix(HalDisplayId, ui::Dataspace) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700174
175 // Returns the attributes of the color sampling engine.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200176 virtual status_t getDisplayedContentSamplingAttributes(HalDisplayId, ui::PixelFormat* outFormat,
Lloyd Pique441d5042018-10-18 16:49:51 -0700177 ui::Dataspace* outDataspace,
178 uint8_t* outComponentMask) = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200179 virtual status_t setDisplayContentSamplingEnabled(HalDisplayId, bool enabled,
Lloyd Pique441d5042018-10-18 16:49:51 -0700180 uint8_t componentMask,
181 uint64_t maxFrames) = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200182 virtual status_t getDisplayedContentSample(HalDisplayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700183 DisplayedFrameStats* outStats) = 0;
184
Dan Gittik57e63c52019-01-18 16:37:54 +0000185 // Sets the brightness of a display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200186 virtual std::future<status_t> setDisplayBrightness(PhysicalDisplayId, float brightness) = 0;
Dan Gittik57e63c52019-01-18 16:37:54 +0000187
Lloyd Pique441d5042018-10-18 16:49:51 -0700188 // Events handling ---------------------------------------------------------
189
190 // Returns stable display ID (and display name on connection of new or previously disconnected
191 // display), or std::nullopt if hotplug event was ignored.
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100192 // This function is called from SurfaceFlinger.
Marin Shalamanova524a092020-07-27 21:39:55 +0200193 virtual std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId,
194 hal::Connection) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700195
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200196 // If true we'll update the DeviceProductInfo on subsequent hotplug connected events.
197 // TODO(b/157555476): Remove when the framework has proper support for headless mode
198 virtual bool updatesDeviceProductInfoOnHotplugReconnect() const = 0;
199
Marin Shalamanova524a092020-07-27 21:39:55 +0200200 virtual bool onVsync(hal::HWDisplayId, int64_t timestamp) = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200201 virtual void setVsyncEnabled(PhysicalDisplayId, hal::Vsync enabled) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700202
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200203 virtual bool isConnected(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700204
Marin Shalamanov045b7002021-01-07 16:56:24 +0100205 virtual std::vector<HWCDisplayMode> getModes(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700206
Marin Shalamanov045b7002021-01-07 16:56:24 +0100207 virtual std::optional<hal::HWConfigId> getActiveMode(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700208
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200209 virtual std::vector<ui::ColorMode> getColorModes(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700210
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200211 virtual status_t setActiveColorMode(PhysicalDisplayId, ui::ColorMode mode,
212 ui::RenderIntent) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700213
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800214 // Composer 2.4
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100215 virtual ui::DisplayConnectionType getDisplayConnectionType(PhysicalDisplayId) const = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200216 virtual bool isVsyncPeriodSwitchSupported(PhysicalDisplayId) const = 0;
Marin Shalamanov045b7002021-01-07 16:56:24 +0100217 virtual status_t getDisplayVsyncPeriod(PhysicalDisplayId displayId,
218 nsecs_t* outVsyncPeriod) const = 0;
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100219 virtual status_t setActiveModeWithConstraints(PhysicalDisplayId, hal::HWConfigId,
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100220 const hal::VsyncPeriodChangeConstraints&,
221 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200222 virtual status_t setAutoLowLatencyMode(PhysicalDisplayId, bool on) = 0;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100223 virtual status_t getSupportedContentTypes(
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200224 PhysicalDisplayId, std::vector<hal::ContentType>* outSupportedContentTypes) = 0;
225 virtual status_t setContentType(PhysicalDisplayId, hal::ContentType) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800226 virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata()
227 const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800228
Lloyd Pique441d5042018-10-18 16:49:51 -0700229 // for debugging ----------------------------------------------------------
230 virtual void dump(std::string& out) const = 0;
231
232 virtual Hwc2::Composer* getComposer() const = 0;
233
234 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700235 virtual std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const = 0;
236 virtual std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700237
Marin Shalamanova524a092020-07-27 21:39:55 +0200238 virtual std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const = 0;
239 virtual std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700240};
241
242namespace impl {
243
244class HWComposer final : public android::HWComposer {
Mathias Agopiana350ff92010-08-10 17:14:02 -0700245public:
Dominik Laskowski1af47932018-11-12 10:20:46 -0800246 explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800247 explicit HWComposer(const std::string& composerServiceName);
Mathias Agopian8b736f12012-08-13 17:54:26 -0700248
Lloyd Pique441d5042018-10-18 16:49:51 -0700249 ~HWComposer() override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700250
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800251 void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700252
Marin Shalamanova524a092020-07-27 21:39:55 +0200253 bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700254 DisplayIdentificationData* outData) const override;
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700255
Marin Shalamanova524a092020-07-27 21:39:55 +0200256 bool hasCapability(hal::Capability) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200257 bool hasDisplayCapability(HalDisplayId, hal::DisplayCapability) const override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700258
Dominik Laskowski075d3172018-05-24 15:50:06 -0700259 // Attempts to allocate a virtual display and returns its ID if created on the HWC device.
260 std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height,
Marin Shalamanova524a092020-07-27 21:39:55 +0200261 ui::PixelFormat*) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700262
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100263 // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated.
Marin Shalamanova524a092020-07-27 21:39:55 +0200264 void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) override;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100265
Dan Stoza9e56aa02015-11-02 13:00:03 -0800266 // Attempts to create a new layer on this display
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200267 HWC2::Layer* createLayer(HalDisplayId) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700268 // Destroy a previously created layer
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200269 void destroyLayer(HalDisplayId, HWC2::Layer*) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700270
Lloyd Pique66d68602019-02-13 14:23:31 -0800271 status_t getDeviceCompositionChanges(
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200272 HalDisplayId, bool frameUsesClientComposition,
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700273 std::chrono::steady_clock::time_point earliestPresentTime,
Lloyd Pique66d68602019-02-13 14:23:31 -0800274 std::optional<DeviceRequestedChanges>* outChanges) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700275
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200276 status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence,
Marin Shalamanova524a092020-07-27 21:39:55 +0200277 const sp<GraphicBuffer>& target, ui::Dataspace) override;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800278
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800279 // Present layers to the display and read releaseFences.
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700280 status_t presentAndGetReleaseFences(
281 HalDisplayId, std::chrono::steady_clock::time_point earliestPresentTime) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700282
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700283 // set power mode
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200284 status_t setPowerMode(PhysicalDisplayId, hal::PowerMode mode) override;
Colin Cross10fbdb62012-07-12 17:56:34 -0700285
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700286 // Sets a color transform to be applied to the result of composition
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200287 status_t setColorTransform(HalDisplayId, const mat4& transform) override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700288
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200289 // reset state when a display is disconnected
290 void disconnectDisplay(HalDisplayId) override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700291
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800292 // get the present fence received from the last call to present.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200293 sp<Fence> getPresentFence(HalDisplayId) const override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700294
Dan Stoza9e56aa02015-11-02 13:00:03 -0800295 // Get last release fence for the given layer
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200296 sp<Fence> getLayerReleaseFence(HalDisplayId, HWC2::Layer*) const override;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700297
Jesse Hall851cfe82013-03-20 13:44:00 -0700298 // Set the output buffer and acquire fence for a virtual display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200299 status_t setOutputBuffer(HalVirtualDisplayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700300 const sp<GraphicBuffer>& buffer) override;
Jesse Hall851cfe82013-03-20 13:44:00 -0700301
Dan Stoza9e56aa02015-11-02 13:00:03 -0800302 // After SurfaceFlinger has retrieved the release fences for all the frames,
303 // it can call this to clear the shared pointers in the release fence map
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200304 void clearReleaseFences(HalDisplayId) override;
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700305
Peiyong Lin62665892018-04-16 11:07:44 -0700306 // Fetches the HDR capabilities of the given display
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200307 status_t getHdrCapabilities(HalDisplayId, HdrCapabilities* outCapabilities) override;
Dan Stozac4f471e2016-03-24 09:31:08 -0700308
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200309 int32_t getSupportedPerFrameMetadata(HalDisplayId) const override;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700310
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700311 // Returns the available RenderIntent of the given display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200312 std::vector<ui::RenderIntent> getRenderIntents(HalDisplayId, ui::ColorMode) const override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700313
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200314 mat4 getDataspaceSaturationMatrix(HalDisplayId, ui::Dataspace) override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700315
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700316 // Returns the attributes of the color sampling engine.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200317 status_t getDisplayedContentSamplingAttributes(HalDisplayId, ui::PixelFormat* outFormat,
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700318 ui::Dataspace* outDataspace,
Lloyd Pique441d5042018-10-18 16:49:51 -0700319 uint8_t* outComponentMask) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200320 status_t setDisplayContentSamplingEnabled(HalDisplayId, bool enabled, uint8_t componentMask,
Marin Shalamanova524a092020-07-27 21:39:55 +0200321 uint64_t maxFrames) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200322 status_t getDisplayedContentSample(HalDisplayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700323 DisplayedFrameStats* outStats) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200324 std::future<status_t> setDisplayBrightness(PhysicalDisplayId, float brightness) override;
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700325
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700326 // Events handling ---------------------------------------------------------
327
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200328 // Returns PhysicalDisplayId (and display name on connection of new or previously disconnected
Dominik Laskowski075d3172018-05-24 15:50:06 -0700329 // display), or std::nullopt if hotplug event was ignored.
Marin Shalamanova524a092020-07-27 21:39:55 +0200330 std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId, hal::Connection) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700331
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200332 bool updatesDeviceProductInfoOnHotplugReconnect() const override;
333
Marin Shalamanova524a092020-07-27 21:39:55 +0200334 bool onVsync(hal::HWDisplayId, int64_t timestamp) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200335 void setVsyncEnabled(PhysicalDisplayId, hal::Vsync enabled) override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700336
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200337 bool isConnected(PhysicalDisplayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700338
Marin Shalamanov045b7002021-01-07 16:56:24 +0100339 std::vector<HWCDisplayMode> getModes(PhysicalDisplayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700340
Marin Shalamanov045b7002021-01-07 16:56:24 +0100341 std::optional<hal::HWConfigId> getActiveMode(PhysicalDisplayId) const override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700342
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200343 std::vector<ui::ColorMode> getColorModes(PhysicalDisplayId) const override;
Michael Wright28f24d02016-07-12 13:30:53 -0700344
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200345 status_t setActiveColorMode(PhysicalDisplayId, ui::ColorMode, ui::RenderIntent) override;
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600346
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800347 // Composer 2.4
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100348 ui::DisplayConnectionType getDisplayConnectionType(PhysicalDisplayId) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200349 bool isVsyncPeriodSwitchSupported(PhysicalDisplayId) const override;
Marin Shalamanov045b7002021-01-07 16:56:24 +0100350 status_t getDisplayVsyncPeriod(PhysicalDisplayId displayId,
351 nsecs_t* outVsyncPeriod) const override;
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100352 status_t setActiveModeWithConstraints(PhysicalDisplayId, hal::HWConfigId,
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100353 const hal::VsyncPeriodChangeConstraints&,
354 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200355 status_t setAutoLowLatencyMode(PhysicalDisplayId, bool) override;
356 status_t getSupportedContentTypes(PhysicalDisplayId, std::vector<hal::ContentType>*) override;
357 status_t setContentType(PhysicalDisplayId, hal::ContentType) override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800358
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800359 const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override;
360
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700361 // for debugging ----------------------------------------------------------
Lloyd Pique441d5042018-10-18 16:49:51 -0700362 void dump(std::string& out) const override;
Mathias Agopian83727852010-09-23 18:13:21 -0700363
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800364 Hwc2::Composer* getComposer() const override { return mComposer.get(); }
Steven Thomas6e8f7062017-11-22 14:15:29 -0800365
Dominik Laskowski075d3172018-05-24 15:50:06 -0700366 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700367 std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700368 return mInternalHwcDisplayId;
369 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700370 std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700371 return mExternalHwcDisplayId;
372 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700373
Marin Shalamanova524a092020-07-27 21:39:55 +0200374 std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const override;
375 std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const override;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700376
Mathias Agopiana350ff92010-08-10 17:14:02 -0700377private:
Lloyd Piquee39cad22017-12-20 17:01:29 -0800378 // For unit tests
379 friend TestableSurfaceFlinger;
380
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;
Jamie Gennis2ec3e072012-11-11 16:24:33 -0800388
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700389 bool validateWasSkipped;
Peiyong Line9d809e2020-04-14 13:10:48 -0700390 hal::Error presentError;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800391
392 bool vsyncTraceToggle = false;
393
394 std::mutex vsyncEnabledLock;
Peiyong Line9d809e2020-04-14 13:10:48 -0700395 hal::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = hal::Vsync::DISABLE;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800396
Marin Shalamanov045b7002021-01-07 16:56:24 +0100397 nsecs_t lastHwVsync = 0;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700398 };
399
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100400 std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId);
401 std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId);
402 bool shouldIgnoreHotplugConnect(hal::HWDisplayId, bool hasDisplayIdentificationData) const;
403
404 int32_t getAttribute(hal::HWDisplayId hwcDisplayId, hal::HWConfigId configId,
Marin Shalamanov045b7002021-01-07 16:56:24 +0100405 hal::Attribute attribute) const;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100406
407 void loadCapabilities();
408 void loadLayerMetadataSupport();
409 uint32_t getMaxVirtualDisplayCount() const;
410
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200411 std::unordered_map<HalDisplayId, DisplayData> mDisplayData;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800412
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800413 std::unique_ptr<android::Hwc2::Composer> mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700414 std::unordered_set<hal::Capability> mCapabilities;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800415 std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800416 bool mRegisteredCallback = false;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800417
Marin Shalamanova524a092020-07-27 21:39:55 +0200418 std::unordered_map<hal::HWDisplayId, PhysicalDisplayId> mPhysicalDisplayIdMap;
Peiyong Line9d809e2020-04-14 13:10:48 -0700419 std::optional<hal::HWDisplayId> mInternalHwcDisplayId;
420 std::optional<hal::HWDisplayId> mExternalHwcDisplayId;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700421 bool mHasMultiDisplaySupport = false;
422
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200423 RandomDisplayIdGenerator<HalVirtualDisplayId> mVirtualIdGenerator{getMaxVirtualDisplayCount()};
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200424
425 const bool mUpdateDeviceProductInfoOnHotplugReconnect;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700426};
427
Lloyd Pique441d5042018-10-18 16:49:51 -0700428} // namespace impl
Dominik Laskowski1af47932018-11-12 10:20:46 -0800429} // namespace android
Mathias Agopiana350ff92010-08-10 17:14:02 -0700430
431#endif // ANDROID_SF_HWCOMPOSER_H