blob: 3ddcdd8bab63b7105480f62571113d71472e1967 [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
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -070042#include "DisplayIdentification.h"
Marin Shalamanov3ea1d602020-12-16 19:59:39 +010043#include "DisplayMode.h"
Dominik Laskowski1af47932018-11-12 10:20:46 -080044#include "HWC2.h"
Peiyong Line9d809e2020-04-14 13:10:48 -070045#include "Hal.h"
Dan Stoza9e56aa02015-11-02 13:00:03 -080046
Mathias Agopiana350ff92010-08-10 17:14:02 -070047namespace android {
Mathias Agopiana350ff92010-08-10 17:14:02 -070048
Peiyong Line9d809e2020-04-14 13:10:48 -070049namespace hal = hardware::graphics::composer::hal;
50
Kevin DuBois1d4249a2018-08-29 10:45:14 -070051struct DisplayedFrameStats;
Jesse Hall399184a2014-03-03 15:42:54 -080052class GraphicBuffer;
Lloyd Piquee39cad22017-12-20 17:01:29 -080053class TestableSurfaceFlinger;
David Sodmanfb95bcc2017-12-22 15:45:30 -080054struct CompositionInfo;
Mathias Agopian83727852010-09-23 18:13:21 -070055
Lloyd Piquea822d522017-12-20 16:42:57 -080056namespace Hwc2 {
57class Composer;
58} // namespace Hwc2
59
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080060namespace compositionengine {
61class Output;
62} // namespace compositionengine
63
Lloyd Pique4603f3c2020-02-11 12:06:56 -080064struct KnownHWCGenericLayerMetadata {
65 const char* name;
66 const uint32_t id;
67};
68
Marin Shalamanov1c434292020-06-12 01:47:29 +020069// See the comment for SurfaceFlinger::getHwComposer for the thread safety rules for accessing
70// this class.
Lloyd Pique441d5042018-10-18 16:49:51 -070071class HWComposer {
72public:
Peiyong Lindfc3f7c2020-05-07 20:15:50 -070073 struct DeviceRequestedChanges {
74 using ChangedTypes = std::unordered_map<HWC2::Layer*, hal::Composition>;
75 using ClientTargetProperty = hal::ClientTargetProperty;
76 using DisplayRequests = hal::DisplayRequest;
77 using LayerRequests = std::unordered_map<HWC2::Layer*, hal::LayerRequest>;
78
79 ChangedTypes changedTypes;
80 DisplayRequests displayRequests;
81 LayerRequests layerRequests;
82 ClientTargetProperty clientTargetProperty;
83 };
84
Marin Shalamanov045b7002021-01-07 16:56:24 +010085 struct HWCDisplayMode {
86 hal::HWConfigId hwcId;
87 int32_t width = -1;
88 int32_t height = -1;
89 nsecs_t vsyncPeriod = -1;
90 int32_t dpiX = -1;
91 int32_t dpiY = -1;
92 int32_t configGroup = -1;
Marin Shalamanovd3b5c5d2021-02-11 18:26:14 +010093
94 friend std::ostream& operator<<(std::ostream& os, const HWCDisplayMode& mode) {
95 return os << "id=" << mode.hwcId << " res=" << mode.width << "x" << mode.height
96 << " vsyncPeriod=" << mode.vsyncPeriod << " dpi=" << mode.dpiX << "x"
97 << mode.dpiY << " group=" << mode.configGroup;
98 }
Marin Shalamanov045b7002021-01-07 16:56:24 +010099 };
100
Lloyd Pique441d5042018-10-18 16:49:51 -0700101 virtual ~HWComposer();
102
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800103 virtual void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700104
Marin Shalamanova524a092020-07-27 21:39:55 +0200105 virtual bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700106 DisplayIdentificationData* outData) const = 0;
107
Marin Shalamanova524a092020-07-27 21:39:55 +0200108 virtual bool hasCapability(hal::Capability) const = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200109 virtual bool hasDisplayCapability(HalDisplayId, hal::DisplayCapability) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700110
Dominik Laskowski13948602021-03-08 20:48:28 -0800111 virtual size_t getMaxVirtualDisplayCount() const = 0;
112 virtual size_t getMaxVirtualDisplayDimension() const = 0;
113
114 // Attempts to allocate a virtual display on the HWC. The maximum number of virtual displays
115 // supported by the HWC can be queried in advance, but allocation may fail for other reasons.
116 // For virtualized compositors, the PhysicalDisplayId is a hint that this virtual display is
117 // a mirror of a physical display, and that the screen should be captured by the host rather
118 // than guest compositor.
119 virtual bool allocateVirtualDisplay(HalVirtualDisplayId, ui::Size, ui::PixelFormat*,
120 std::optional<PhysicalDisplayId> mirror) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700121
Marin Shalamanova524a092020-07-27 21:39:55 +0200122 virtual void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) = 0;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100123
Lloyd Pique441d5042018-10-18 16:49:51 -0700124 // Attempts to create a new layer on this display
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700125 virtual std::shared_ptr<HWC2::Layer> createLayer(HalDisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700126
Lloyd Pique66d68602019-02-13 14:23:31 -0800127 // Gets any required composition change requests from the HWC device.
128 //
129 // Note that frameUsesClientComposition must be set correctly based on
130 // whether the current frame appears to use client composition. If it is
131 // false some internal optimizations are allowed to present the display
132 // with fewer handshakes, but this does not work if client composition is
133 // expected.
134 virtual status_t getDeviceCompositionChanges(
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200135 HalDisplayId, bool frameUsesClientComposition,
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700136 std::chrono::steady_clock::time_point earliestPresentTime,
Lloyd Pique66d68602019-02-13 14:23:31 -0800137 std::optional<DeviceRequestedChanges>* outChanges) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700138
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200139 virtual status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence,
Marin Shalamanova524a092020-07-27 21:39:55 +0200140 const sp<GraphicBuffer>& target, ui::Dataspace) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700141
142 // Present layers to the display and read releaseFences.
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700143 virtual status_t presentAndGetReleaseFences(
144 HalDisplayId, std::chrono::steady_clock::time_point earliestPresentTime) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700145
146 // set power mode
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200147 virtual status_t setPowerMode(PhysicalDisplayId, hal::PowerMode) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700148
Lloyd Pique441d5042018-10-18 16:49:51 -0700149 // Sets a color transform to be applied to the result of composition
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200150 virtual status_t setColorTransform(HalDisplayId, const mat4& transform) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700151
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200152 // reset state when a display is disconnected
153 virtual void disconnectDisplay(HalDisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700154
Lloyd Pique441d5042018-10-18 16:49:51 -0700155 // get the present fence received from the last call to present.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200156 virtual sp<Fence> getPresentFence(HalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700157
158 // Get last release fence for the given layer
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200159 virtual sp<Fence> getLayerReleaseFence(HalDisplayId, HWC2::Layer*) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700160
161 // Set the output buffer and acquire fence for a virtual display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200162 virtual status_t setOutputBuffer(HalVirtualDisplayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700163 const sp<GraphicBuffer>& buffer) = 0;
164
165 // After SurfaceFlinger has retrieved the release fences for all the frames,
166 // it can call this to clear the shared pointers in the release fence map
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200167 virtual void clearReleaseFences(HalDisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700168
169 // Fetches the HDR capabilities of the given display
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200170 virtual status_t getHdrCapabilities(HalDisplayId, HdrCapabilities* outCapabilities) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700171
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200172 virtual int32_t getSupportedPerFrameMetadata(HalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700173
174 // Returns the available RenderIntent of the given display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200175 virtual std::vector<ui::RenderIntent> getRenderIntents(HalDisplayId, ui::ColorMode) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700176
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200177 virtual mat4 getDataspaceSaturationMatrix(HalDisplayId, ui::Dataspace) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700178
179 // Returns the attributes of the color sampling engine.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200180 virtual status_t getDisplayedContentSamplingAttributes(HalDisplayId, ui::PixelFormat* outFormat,
Lloyd Pique441d5042018-10-18 16:49:51 -0700181 ui::Dataspace* outDataspace,
182 uint8_t* outComponentMask) = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200183 virtual status_t setDisplayContentSamplingEnabled(HalDisplayId, bool enabled,
Lloyd Pique441d5042018-10-18 16:49:51 -0700184 uint8_t componentMask,
185 uint64_t maxFrames) = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200186 virtual status_t getDisplayedContentSample(HalDisplayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700187 DisplayedFrameStats* outStats) = 0;
188
Dan Gittik57e63c52019-01-18 16:37:54 +0000189 // Sets the brightness of a display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200190 virtual std::future<status_t> setDisplayBrightness(PhysicalDisplayId, float brightness) = 0;
Dan Gittik57e63c52019-01-18 16:37:54 +0000191
Lloyd Pique441d5042018-10-18 16:49:51 -0700192 // Events handling ---------------------------------------------------------
193
194 // Returns stable display ID (and display name on connection of new or previously disconnected
195 // display), or std::nullopt if hotplug event was ignored.
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100196 // This function is called from SurfaceFlinger.
Marin Shalamanova524a092020-07-27 21:39:55 +0200197 virtual std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId,
198 hal::Connection) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700199
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200200 // If true we'll update the DeviceProductInfo on subsequent hotplug connected events.
201 // TODO(b/157555476): Remove when the framework has proper support for headless mode
202 virtual bool updatesDeviceProductInfoOnHotplugReconnect() const = 0;
203
Marin Shalamanova524a092020-07-27 21:39:55 +0200204 virtual bool onVsync(hal::HWDisplayId, int64_t timestamp) = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200205 virtual void setVsyncEnabled(PhysicalDisplayId, hal::Vsync enabled) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700206
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200207 virtual bool isConnected(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700208
Marin Shalamanov045b7002021-01-07 16:56:24 +0100209 virtual std::vector<HWCDisplayMode> getModes(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700210
Marin Shalamanov045b7002021-01-07 16:56:24 +0100211 virtual std::optional<hal::HWConfigId> getActiveMode(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700212
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200213 virtual std::vector<ui::ColorMode> getColorModes(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700214
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200215 virtual status_t setActiveColorMode(PhysicalDisplayId, ui::ColorMode mode,
216 ui::RenderIntent) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700217
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800218 // Composer 2.4
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100219 virtual ui::DisplayConnectionType getDisplayConnectionType(PhysicalDisplayId) const = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200220 virtual bool isVsyncPeriodSwitchSupported(PhysicalDisplayId) const = 0;
Marin Shalamanov045b7002021-01-07 16:56:24 +0100221 virtual status_t getDisplayVsyncPeriod(PhysicalDisplayId displayId,
222 nsecs_t* outVsyncPeriod) const = 0;
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100223 virtual status_t setActiveModeWithConstraints(PhysicalDisplayId, hal::HWConfigId,
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100224 const hal::VsyncPeriodChangeConstraints&,
225 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200226 virtual status_t setAutoLowLatencyMode(PhysicalDisplayId, bool on) = 0;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100227 virtual status_t getSupportedContentTypes(
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200228 PhysicalDisplayId, std::vector<hal::ContentType>* outSupportedContentTypes) = 0;
229 virtual status_t setContentType(PhysicalDisplayId, hal::ContentType) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800230 virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata()
231 const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800232
Lloyd Pique441d5042018-10-18 16:49:51 -0700233 // for debugging ----------------------------------------------------------
234 virtual void dump(std::string& out) const = 0;
235
236 virtual Hwc2::Composer* getComposer() const = 0;
237
238 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700239 virtual std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const = 0;
240 virtual std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700241
Marin Shalamanova524a092020-07-27 21:39:55 +0200242 virtual std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const = 0;
243 virtual std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700244};
245
246namespace impl {
247
248class HWComposer final : public android::HWComposer {
Mathias Agopiana350ff92010-08-10 17:14:02 -0700249public:
Dominik Laskowski1af47932018-11-12 10:20:46 -0800250 explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800251 explicit HWComposer(const std::string& composerServiceName);
Mathias Agopian8b736f12012-08-13 17:54:26 -0700252
Lloyd Pique441d5042018-10-18 16:49:51 -0700253 ~HWComposer() override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700254
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800255 void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700256
Marin Shalamanova524a092020-07-27 21:39:55 +0200257 bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700258 DisplayIdentificationData* outData) const override;
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700259
Marin Shalamanova524a092020-07-27 21:39:55 +0200260 bool hasCapability(hal::Capability) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200261 bool hasDisplayCapability(HalDisplayId, hal::DisplayCapability) const override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700262
Dominik Laskowski13948602021-03-08 20:48:28 -0800263 size_t getMaxVirtualDisplayCount() const override;
264 size_t getMaxVirtualDisplayDimension() const override;
265
266 bool allocateVirtualDisplay(HalVirtualDisplayId, ui::Size, ui::PixelFormat*,
267 std::optional<PhysicalDisplayId>) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700268
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100269 // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated.
Marin Shalamanova524a092020-07-27 21:39:55 +0200270 void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) override;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100271
Dan Stoza9e56aa02015-11-02 13:00:03 -0800272 // Attempts to create a new layer on this display
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700273 std::shared_ptr<HWC2::Layer> createLayer(HalDisplayId) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700274
Lloyd Pique66d68602019-02-13 14:23:31 -0800275 status_t getDeviceCompositionChanges(
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200276 HalDisplayId, bool frameUsesClientComposition,
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700277 std::chrono::steady_clock::time_point earliestPresentTime,
Lloyd Pique66d68602019-02-13 14:23:31 -0800278 std::optional<DeviceRequestedChanges>* outChanges) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700279
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200280 status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence,
Marin Shalamanova524a092020-07-27 21:39:55 +0200281 const sp<GraphicBuffer>& target, ui::Dataspace) override;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800282
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800283 // Present layers to the display and read releaseFences.
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700284 status_t presentAndGetReleaseFences(
285 HalDisplayId, std::chrono::steady_clock::time_point earliestPresentTime) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700286
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700287 // set power mode
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200288 status_t setPowerMode(PhysicalDisplayId, hal::PowerMode mode) override;
Colin Cross10fbdb62012-07-12 17:56:34 -0700289
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700290 // Sets a color transform to be applied to the result of composition
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200291 status_t setColorTransform(HalDisplayId, const mat4& transform) override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700292
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200293 // reset state when a display is disconnected
294 void disconnectDisplay(HalDisplayId) override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700295
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800296 // get the present fence received from the last call to present.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200297 sp<Fence> getPresentFence(HalDisplayId) const override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700298
Dan Stoza9e56aa02015-11-02 13:00:03 -0800299 // Get last release fence for the given layer
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200300 sp<Fence> getLayerReleaseFence(HalDisplayId, HWC2::Layer*) const override;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700301
Jesse Hall851cfe82013-03-20 13:44:00 -0700302 // Set the output buffer and acquire fence for a virtual display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200303 status_t setOutputBuffer(HalVirtualDisplayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700304 const sp<GraphicBuffer>& buffer) override;
Jesse Hall851cfe82013-03-20 13:44:00 -0700305
Dan Stoza9e56aa02015-11-02 13:00:03 -0800306 // After SurfaceFlinger has retrieved the release fences for all the frames,
307 // it can call this to clear the shared pointers in the release fence map
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200308 void clearReleaseFences(HalDisplayId) override;
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700309
Peiyong Lin62665892018-04-16 11:07:44 -0700310 // Fetches the HDR capabilities of the given display
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200311 status_t getHdrCapabilities(HalDisplayId, HdrCapabilities* outCapabilities) override;
Dan Stozac4f471e2016-03-24 09:31:08 -0700312
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200313 int32_t getSupportedPerFrameMetadata(HalDisplayId) const override;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700314
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700315 // Returns the available RenderIntent of the given display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200316 std::vector<ui::RenderIntent> getRenderIntents(HalDisplayId, ui::ColorMode) const override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700317
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200318 mat4 getDataspaceSaturationMatrix(HalDisplayId, ui::Dataspace) override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700319
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700320 // Returns the attributes of the color sampling engine.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200321 status_t getDisplayedContentSamplingAttributes(HalDisplayId, ui::PixelFormat* outFormat,
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700322 ui::Dataspace* outDataspace,
Lloyd Pique441d5042018-10-18 16:49:51 -0700323 uint8_t* outComponentMask) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200324 status_t setDisplayContentSamplingEnabled(HalDisplayId, bool enabled, uint8_t componentMask,
Marin Shalamanova524a092020-07-27 21:39:55 +0200325 uint64_t maxFrames) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200326 status_t getDisplayedContentSample(HalDisplayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700327 DisplayedFrameStats* outStats) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200328 std::future<status_t> setDisplayBrightness(PhysicalDisplayId, float brightness) override;
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700329
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700330 // Events handling ---------------------------------------------------------
331
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200332 // Returns PhysicalDisplayId (and display name on connection of new or previously disconnected
Dominik Laskowski075d3172018-05-24 15:50:06 -0700333 // display), or std::nullopt if hotplug event was ignored.
Marin Shalamanova524a092020-07-27 21:39:55 +0200334 std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId, hal::Connection) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700335
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200336 bool updatesDeviceProductInfoOnHotplugReconnect() const override;
337
Marin Shalamanova524a092020-07-27 21:39:55 +0200338 bool onVsync(hal::HWDisplayId, int64_t timestamp) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200339 void setVsyncEnabled(PhysicalDisplayId, hal::Vsync enabled) override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700340
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200341 bool isConnected(PhysicalDisplayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700342
Marin Shalamanov045b7002021-01-07 16:56:24 +0100343 std::vector<HWCDisplayMode> getModes(PhysicalDisplayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700344
Marin Shalamanov045b7002021-01-07 16:56:24 +0100345 std::optional<hal::HWConfigId> getActiveMode(PhysicalDisplayId) const override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700346
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200347 std::vector<ui::ColorMode> getColorModes(PhysicalDisplayId) const override;
Michael Wright28f24d02016-07-12 13:30:53 -0700348
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200349 status_t setActiveColorMode(PhysicalDisplayId, ui::ColorMode, ui::RenderIntent) override;
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600350
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800351 // Composer 2.4
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100352 ui::DisplayConnectionType getDisplayConnectionType(PhysicalDisplayId) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200353 bool isVsyncPeriodSwitchSupported(PhysicalDisplayId) const override;
Marin Shalamanov045b7002021-01-07 16:56:24 +0100354 status_t getDisplayVsyncPeriod(PhysicalDisplayId displayId,
355 nsecs_t* outVsyncPeriod) const override;
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100356 status_t setActiveModeWithConstraints(PhysicalDisplayId, hal::HWConfigId,
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100357 const hal::VsyncPeriodChangeConstraints&,
358 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200359 status_t setAutoLowLatencyMode(PhysicalDisplayId, bool) override;
360 status_t getSupportedContentTypes(PhysicalDisplayId, std::vector<hal::ContentType>*) override;
361 status_t setContentType(PhysicalDisplayId, hal::ContentType) override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800362
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800363 const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override;
364
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700365 // for debugging ----------------------------------------------------------
Lloyd Pique441d5042018-10-18 16:49:51 -0700366 void dump(std::string& out) const override;
Mathias Agopian83727852010-09-23 18:13:21 -0700367
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800368 Hwc2::Composer* getComposer() const override { return mComposer.get(); }
Steven Thomas6e8f7062017-11-22 14:15:29 -0800369
Dominik Laskowski075d3172018-05-24 15:50:06 -0700370 // TODO(b/74619554): Remove special cases for internal/external display.
Peiyong Line9d809e2020-04-14 13:10:48 -0700371 std::optional<hal::HWDisplayId> getInternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700372 return mInternalHwcDisplayId;
373 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700374 std::optional<hal::HWDisplayId> getExternalHwcDisplayId() const override {
Lloyd Pique441d5042018-10-18 16:49:51 -0700375 return mExternalHwcDisplayId;
376 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700377
Marin Shalamanova524a092020-07-27 21:39:55 +0200378 std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const override;
379 std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const override;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700380
Mathias Agopiana350ff92010-08-10 17:14:02 -0700381private:
Lloyd Piquee39cad22017-12-20 17:01:29 -0800382 // For unit tests
383 friend TestableSurfaceFlinger;
384
Mathias Agopiane60b0682012-08-21 23:34:09 -0700385 struct DisplayData {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700386 bool isVirtual = false;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800387 std::unique_ptr<HWC2::Display> hwcDisplay;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700388 sp<Fence> lastPresentFence = Fence::NO_FENCE; // signals when the last set op retires
Steven Thomas94e35b92017-07-26 18:48:28 -0700389 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700390 buffer_handle_t outbufHandle = nullptr;
391 sp<Fence> outbufAcquireFence = Fence::NO_FENCE;
Jamie Gennis2ec3e072012-11-11 16:24:33 -0800392
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700393 bool validateWasSkipped;
Peiyong Line9d809e2020-04-14 13:10:48 -0700394 hal::Error presentError;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800395
396 bool vsyncTraceToggle = false;
397
398 std::mutex vsyncEnabledLock;
Peiyong Line9d809e2020-04-14 13:10:48 -0700399 hal::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = hal::Vsync::DISABLE;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800400
Marin Shalamanov045b7002021-01-07 16:56:24 +0100401 nsecs_t lastHwVsync = 0;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700402 };
403
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100404 std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId);
405 std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId);
406 bool shouldIgnoreHotplugConnect(hal::HWDisplayId, bool hasDisplayIdentificationData) const;
407
408 int32_t getAttribute(hal::HWDisplayId hwcDisplayId, hal::HWConfigId configId,
Marin Shalamanov045b7002021-01-07 16:56:24 +0100409 hal::Attribute attribute) const;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100410
411 void loadCapabilities();
412 void loadLayerMetadataSupport();
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100413
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200414 std::unordered_map<HalDisplayId, DisplayData> mDisplayData;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800415
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800416 std::unique_ptr<android::Hwc2::Composer> mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700417 std::unordered_set<hal::Capability> mCapabilities;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800418 std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800419 bool mRegisteredCallback = false;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800420
Marin Shalamanova524a092020-07-27 21:39:55 +0200421 std::unordered_map<hal::HWDisplayId, PhysicalDisplayId> mPhysicalDisplayIdMap;
Peiyong Line9d809e2020-04-14 13:10:48 -0700422 std::optional<hal::HWDisplayId> mInternalHwcDisplayId;
423 std::optional<hal::HWDisplayId> mExternalHwcDisplayId;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700424 bool mHasMultiDisplaySupport = false;
425
Dominik Laskowski13948602021-03-08 20:48:28 -0800426 const size_t mMaxVirtualDisplayDimension;
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200427 const bool mUpdateDeviceProductInfoOnHotplugReconnect;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700428};
429
Lloyd Pique441d5042018-10-18 16:49:51 -0700430} // namespace impl
Dominik Laskowski1af47932018-11-12 10:20:46 -0800431} // namespace android
Mathias Agopiana350ff92010-08-10 17:14:02 -0700432
433#endif // ANDROID_SF_HWCOMPOSER_H