blob: 52662cffbb5db73cbe9aa2c1d024ebc637344c42 [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
Dominik Laskowskif8db0f02021-04-19 11:05:25 -070017#pragma once
Mathias Agopiana350ff92010-08-10 17:14:02 -070018
Dominik Laskowski1af47932018-11-12 10:20:46 -080019#include <cstdint>
Dan Stoza9e56aa02015-11-02 13:00:03 -080020#include <memory>
Dominik Laskowski1af47932018-11-12 10:20:46 -080021#include <mutex>
Steven Thomas6e8f7062017-11-22 14:15:29 -080022#include <optional>
Dominik Laskowski075d3172018-05-24 15:50:06 -070023#include <unordered_map>
24#include <unordered_set>
Dan Stoza9e56aa02015-11-02 13:00:03 -080025#include <vector>
26
Dominik Laskowski1af47932018-11-12 10:20:46 -080027#include <android-base/thread_annotations.h>
Dominik Laskowskid940a012024-01-28 13:25:44 -050028#include <ftl/expected.h>
Dominik Laskowskib17c6212022-05-09 09:36:19 -070029#include <ftl/future.h>
Alec Mouriff793872022-01-13 17:45:06 -080030#include <ui/DisplayIdentification.h>
Ady Abrahamec7aa8a2021-06-28 12:37:09 -070031#include <ui/FenceTime.h>
Brian Lindahl7a4cb7e2024-10-30 10:42:21 -060032#include <ui/PictureProfileHandle.h>
Ady Abraham8a82ba62020-01-17 12:43:17 -080033
34// TODO(b/129481165): remove the #pragma below and fix conversion issues
35#pragma clang diagnostic push
36#pragma clang diagnostic ignored "-Wconversion"
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010037#pragma clang diagnostic ignored "-Wextra"
Dominik Laskowski1af47932018-11-12 10:20:46 -080038#include <ui/GraphicTypes.h>
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010039#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
Ady Abraham8a82ba62020-01-17 12:43:17 -080040
Dominik Laskowski1af47932018-11-12 10:20:46 -080041#include <utils/StrongPointer.h>
42#include <utils/Timers.h>
43
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
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -050048#include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h>
Kriti Dangd432bb52023-02-09 18:21:04 +010049#include <aidl/android/hardware/graphics/common/Hdr.h>
Kriti Dang674b9372022-11-18 10:58:44 +010050#include <aidl/android/hardware/graphics/common/HdrConversionCapability.h>
51#include <aidl/android/hardware/graphics/common/HdrConversionStrategy.h>
Ady Abrahamde549d42022-01-26 19:19:17 -080052#include <aidl/android/hardware/graphics/composer3/Capability.h>
Alec Mouri85065692022-03-18 00:58:26 +000053#include <aidl/android/hardware/graphics/composer3/ClientTargetPropertyWithBrightness.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050054#include <aidl/android/hardware/graphics/composer3/Composition.h>
Leon Scroggins III5967aec2021-12-29 11:14:22 -050055#include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
Sally Qi11dcd582024-08-16 18:11:27 -070056#include <aidl/android/hardware/graphics/composer3/DisplayLuts.h>
Sally Qi95f669a2024-08-27 11:31:42 -070057#include <aidl/android/hardware/graphics/composer3/LutProperties.h>
Sasha McIntoshf08ed642024-10-24 15:43:07 -040058#include <aidl/android/hardware/graphics/composer3/OutputType.h>
Sally Qi0cbd08b2022-08-17 12:12:28 -070059#include <aidl/android/hardware/graphics/composer3/OverlayProperties.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050060
Mathias Agopiana350ff92010-08-10 17:14:02 -070061namespace android {
Mathias Agopiana350ff92010-08-10 17:14:02 -070062
Peiyong Line9d809e2020-04-14 13:10:48 -070063namespace hal = hardware::graphics::composer::hal;
64
Kevin DuBois1d4249a2018-08-29 10:45:14 -070065struct DisplayedFrameStats;
Jesse Hall399184a2014-03-03 15:42:54 -080066class GraphicBuffer;
Lloyd Piquee39cad22017-12-20 17:01:29 -080067class TestableSurfaceFlinger;
ramindanib90711b2023-10-02 15:13:19 -070068struct HWComposerTest;
David Sodmanfb95bcc2017-12-22 15:45:30 -080069struct CompositionInfo;
Brian Lindahl7a4cb7e2024-10-30 10:42:21 -060070class PictureProfileHandle;
Mathias Agopian83727852010-09-23 18:13:21 -070071
Lloyd Piquea822d522017-12-20 16:42:57 -080072namespace Hwc2 {
73class Composer;
74} // namespace Hwc2
75
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080076namespace compositionengine {
77class Output;
78} // namespace compositionengine
79
Lloyd Pique4603f3c2020-02-11 12:06:56 -080080struct KnownHWCGenericLayerMetadata {
81 const char* name;
82 const uint32_t id;
83};
84
Marin Shalamanov1c434292020-06-12 01:47:29 +020085// See the comment for SurfaceFlinger::getHwComposer for the thread safety rules for accessing
86// this class.
Lloyd Pique441d5042018-10-18 16:49:51 -070087class HWComposer {
88public:
Peiyong Lindfc3f7c2020-05-07 20:15:50 -070089 struct DeviceRequestedChanges {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050090 using ChangedTypes =
91 std::unordered_map<HWC2::Layer*,
92 aidl::android::hardware::graphics::composer3::Composition>;
Alec Mouri85065692022-03-18 00:58:26 +000093 using ClientTargetProperty =
94 aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -070095 using DisplayRequests = hal::DisplayRequest;
96 using LayerRequests = std::unordered_map<HWC2::Layer*, hal::LayerRequest>;
Sally Qi95f669a2024-08-27 11:31:42 -070097 using LutProperties = aidl::android::hardware::graphics::composer3::LutProperties;
98 using LayerLuts = HWC2::Display::LayerLuts;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -070099
100 ChangedTypes changedTypes;
101 DisplayRequests displayRequests;
102 LayerRequests layerRequests;
103 ClientTargetProperty clientTargetProperty;
Sally Qi95f669a2024-08-27 11:31:42 -0700104 LayerLuts layerLuts;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700105 };
106
Marin Shalamanov045b7002021-01-07 16:56:24 +0100107 struct HWCDisplayMode {
108 hal::HWConfigId hwcId;
109 int32_t width = -1;
110 int32_t height = -1;
111 nsecs_t vsyncPeriod = -1;
ramindani0cd1d8d2023-06-13 13:43:23 -0700112 float dpiX = -1.f;
113 float dpiY = -1.f;
Marin Shalamanov045b7002021-01-07 16:56:24 +0100114 int32_t configGroup = -1;
ramindania04b8a52023-08-07 18:49:47 -0700115 std::optional<hal::VrrConfig> vrrConfig;
Sasha McIntoshf08ed642024-10-24 15:43:07 -0400116 OutputType hdrOutputType;
Marin Shalamanovd3b5c5d2021-02-11 18:26:14 +0100117
118 friend std::ostream& operator<<(std::ostream& os, const HWCDisplayMode& mode) {
119 return os << "id=" << mode.hwcId << " res=" << mode.width << "x" << mode.height
120 << " vsyncPeriod=" << mode.vsyncPeriod << " dpi=" << mode.dpiX << "x"
ramindania04b8a52023-08-07 18:49:47 -0700121 << mode.dpiY << " group=" << mode.configGroup
Sasha McIntoshf08ed642024-10-24 15:43:07 -0400122 << " vrrConfig=" << to_string(mode.vrrConfig).c_str()
123 << " hdrOutputType=" << toString(mode.hdrOutputType);
Marin Shalamanovd3b5c5d2021-02-11 18:26:14 +0100124 }
Marin Shalamanov045b7002021-01-07 16:56:24 +0100125 };
126
Lloyd Pique441d5042018-10-18 16:49:51 -0700127 virtual ~HWComposer();
128
Yichi Chen3401b562022-01-17 15:42:35 +0800129 virtual void setCallback(HWC2::ComposerCallback&) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700130
Marin Shalamanova524a092020-07-27 21:39:55 +0200131 virtual bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700132 DisplayIdentificationData* outData) const = 0;
133
Ady Abrahamde549d42022-01-26 19:19:17 -0800134 virtual bool hasCapability(aidl::android::hardware::graphics::composer3::Capability) const = 0;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500135 virtual bool hasDisplayCapability(
136 HalDisplayId,
137 aidl::android::hardware::graphics::composer3::DisplayCapability) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700138
Dominik Laskowski13948602021-03-08 20:48:28 -0800139 virtual size_t getMaxVirtualDisplayCount() const = 0;
140 virtual size_t getMaxVirtualDisplayDimension() const = 0;
141
142 // Attempts to allocate a virtual display on the HWC. The maximum number of virtual displays
143 // supported by the HWC can be queried in advance, but allocation may fail for other reasons.
Dominik Laskowski263eec42021-07-21 23:13:24 -0700144 virtual bool allocateVirtualDisplay(HalVirtualDisplayId, ui::Size, ui::PixelFormat*) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700145
Lucas Berthou8d0a0c42024-08-27 14:32:31 +0000146 virtual void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId,
147 std::optional<ui::Size> physicalSize) = 0;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100148
Lloyd Pique441d5042018-10-18 16:49:51 -0700149 // Attempts to create a new layer on this display
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700150 virtual std::shared_ptr<HWC2::Layer> createLayer(HalDisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700151
Lloyd Pique66d68602019-02-13 14:23:31 -0800152 // Gets any required composition change requests from the HWC device.
153 //
154 // Note that frameUsesClientComposition must be set correctly based on
155 // whether the current frame appears to use client composition. If it is
156 // false some internal optimizations are allowed to present the display
157 // with fewer handshakes, but this does not work if client composition is
158 // expected.
159 virtual status_t getDeviceCompositionChanges(
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200160 HalDisplayId, bool frameUsesClientComposition,
Ady Abrahamf1db8032023-03-24 17:52:34 -0700161 std::optional<std::chrono::steady_clock::time_point> earliestPresentTime,
ramindani4aac32c2023-10-30 14:13:30 -0700162 nsecs_t expectedPresentTime, Fps frameInterval,
163 std::optional<DeviceRequestedChanges>* outChanges) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700164
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200165 virtual status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence,
Alec Mourif97df4d2023-09-06 02:10:05 +0000166 const sp<GraphicBuffer>& target, ui::Dataspace,
167 float hdrSdrRatio) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700168
169 // Present layers to the display and read releaseFences.
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700170 virtual status_t presentAndGetReleaseFences(
Ady Abrahamf1db8032023-03-24 17:52:34 -0700171 HalDisplayId,
172 std::optional<std::chrono::steady_clock::time_point> earliestPresentTime) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700173
Leon Scroggins IIIa3ba7fa2024-05-22 16:34:52 -0400174 virtual status_t executeCommands(HalDisplayId) = 0;
175
Lloyd Pique441d5042018-10-18 16:49:51 -0700176 // set power mode
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200177 virtual status_t setPowerMode(PhysicalDisplayId, hal::PowerMode) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700178
Lloyd Pique441d5042018-10-18 16:49:51 -0700179 // Sets a color transform to be applied to the result of composition
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200180 virtual status_t setColorTransform(HalDisplayId, const mat4& transform) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700181
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200182 // reset state when a display is disconnected
183 virtual void disconnectDisplay(HalDisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700184
Dominik Laskowskidc2bb802022-09-28 16:02:59 -0400185 // Get the present fence/timestamp received from the last call to present.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200186 virtual sp<Fence> getPresentFence(HalDisplayId) const = 0;
Dominik Laskowskidc2bb802022-09-28 16:02:59 -0400187 virtual nsecs_t getPresentTimestamp(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700188
189 // Get last release fence for the given layer
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200190 virtual sp<Fence> getLayerReleaseFence(HalDisplayId, HWC2::Layer*) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700191
192 // Set the output buffer and acquire fence for a virtual display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200193 virtual status_t setOutputBuffer(HalVirtualDisplayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700194 const sp<GraphicBuffer>& buffer) = 0;
195
196 // After SurfaceFlinger has retrieved the release fences for all the frames,
197 // it can call this to clear the shared pointers in the release fence map
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200198 virtual void clearReleaseFences(HalDisplayId) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700199
200 // Fetches the HDR capabilities of the given display
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200201 virtual status_t getHdrCapabilities(HalDisplayId, HdrCapabilities* outCapabilities) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700202
Sally Qibb866c12022-10-17 11:31:20 -0700203 virtual const aidl::android::hardware::graphics::composer3::OverlayProperties&
204 getOverlaySupport() const = 0;
Sally Qi0cbd08b2022-08-17 12:12:28 -0700205
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200206 virtual int32_t getSupportedPerFrameMetadata(HalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700207
208 // Returns the available RenderIntent of the given display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200209 virtual std::vector<ui::RenderIntent> getRenderIntents(HalDisplayId, ui::ColorMode) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700210
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200211 virtual mat4 getDataspaceSaturationMatrix(HalDisplayId, ui::Dataspace) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700212
213 // Returns the attributes of the color sampling engine.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200214 virtual status_t getDisplayedContentSamplingAttributes(HalDisplayId, ui::PixelFormat* outFormat,
Lloyd Pique441d5042018-10-18 16:49:51 -0700215 ui::Dataspace* outDataspace,
216 uint8_t* outComponentMask) = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200217 virtual status_t setDisplayContentSamplingEnabled(HalDisplayId, bool enabled,
Lloyd Pique441d5042018-10-18 16:49:51 -0700218 uint8_t componentMask,
219 uint64_t maxFrames) = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200220 virtual status_t getDisplayedContentSample(HalDisplayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700221 DisplayedFrameStats* outStats) = 0;
222
Dan Gittik57e63c52019-01-18 16:37:54 +0000223 // Sets the brightness of a display.
Dominik Laskowskib17c6212022-05-09 09:36:19 -0700224 virtual ftl::Future<status_t> setDisplayBrightness(
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000225 PhysicalDisplayId, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -0800226 const Hwc2::Composer::DisplayBrightnessOptions&) = 0;
Dan Gittik57e63c52019-01-18 16:37:54 +0000227
Matt Buckley50c44062022-01-17 20:48:10 +0000228 // Get whether the display skipped validation on the latest present
229 virtual bool getValidateSkipped(HalDisplayId displayId) const = 0;
230
Lloyd Pique441d5042018-10-18 16:49:51 -0700231 // Events handling ---------------------------------------------------------
232
233 // Returns stable display ID (and display name on connection of new or previously disconnected
234 // display), or std::nullopt if hotplug event was ignored.
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100235 // This function is called from SurfaceFlinger.
Marin Shalamanova524a092020-07-27 21:39:55 +0200236 virtual std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId,
237 hal::Connection) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700238
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200239 // If true we'll update the DeviceProductInfo on subsequent hotplug connected events.
240 // TODO(b/157555476): Remove when the framework has proper support for headless mode
241 virtual bool updatesDeviceProductInfoOnHotplugReconnect() const = 0;
242
Leon Scroggins III959a7ff2023-02-07 11:24:25 -0500243 // Called when a vsync happens. If the vsync is valid, returns the
244 // corresponding PhysicalDisplayId. Otherwise returns nullopt.
245 virtual std::optional<PhysicalDisplayId> onVsync(hal::HWDisplayId, nsecs_t timestamp) = 0;
246
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200247 virtual void setVsyncEnabled(PhysicalDisplayId, hal::Vsync enabled) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700248
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200249 virtual bool isConnected(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700250
ramindani263a3f12023-07-18 20:44:49 -0700251 virtual std::vector<HWCDisplayMode> getModes(PhysicalDisplayId,
252 int32_t maxFrameIntervalNs) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700253
Dominik Laskowskid940a012024-01-28 13:25:44 -0500254 virtual ftl::Expected<hal::HWConfigId, status_t> getActiveMode(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700255
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200256 virtual std::vector<ui::ColorMode> getColorModes(PhysicalDisplayId) const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700257
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200258 virtual status_t setActiveColorMode(PhysicalDisplayId, ui::ColorMode mode,
259 ui::RenderIntent) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700260
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800261 // Composer 2.4
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100262 virtual ui::DisplayConnectionType getDisplayConnectionType(PhysicalDisplayId) const = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200263 virtual bool isVsyncPeriodSwitchSupported(PhysicalDisplayId) const = 0;
Dominik Laskowskia109bb22024-01-28 13:33:51 -0500264 virtual ftl::Expected<nsecs_t, status_t> getDisplayVsyncPeriod(PhysicalDisplayId) const = 0;
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100265 virtual status_t setActiveModeWithConstraints(PhysicalDisplayId, hal::HWConfigId,
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100266 const hal::VsyncPeriodChangeConstraints&,
267 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200268 virtual status_t setAutoLowLatencyMode(PhysicalDisplayId, bool on) = 0;
Galia Peycheva5492cb52019-10-30 14:13:16 +0100269 virtual status_t getSupportedContentTypes(
Dominik Laskowski6c7b36e2022-03-03 08:27:58 -0800270 PhysicalDisplayId, std::vector<hal::ContentType>* outSupportedContentTypes) const = 0;
271
272 bool supportsContentType(PhysicalDisplayId displayId, hal::ContentType type) const {
273 std::vector<hal::ContentType> types;
274 return getSupportedContentTypes(displayId, &types) == NO_ERROR &&
275 std::find(types.begin(), types.end(), type) != types.end();
276 }
277
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200278 virtual status_t setContentType(PhysicalDisplayId, hal::ContentType) = 0;
Dominik Laskowski6c7b36e2022-03-03 08:27:58 -0800279
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800280 virtual const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata()
281 const = 0;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800282
Lloyd Pique441d5042018-10-18 16:49:51 -0700283 virtual void dump(std::string& out) const = 0;
284
Sally Qi254ef492024-04-08 15:01:28 -0700285 virtual void dumpOverlayProperties(std::string& out) const = 0;
286
Lloyd Pique441d5042018-10-18 16:49:51 -0700287 virtual Hwc2::Composer* getComposer() const = 0;
288
Marin Shalamanov8b196592021-08-09 16:24:42 +0200289 // Returns the first display connected at boot. Its connection via HWComposer::onHotplug,
290 // which in practice is immediately after HWComposer construction, must occur before any
291 // call to this function.
292 // The primary display can be temporarily disconnected from the perspective
293 // of this class. Callers must not call getPrimaryHwcDisplayId() or getPrimaryDisplayId()
294 // if isHeadless().
Dominik Laskowskif8db0f02021-04-19 11:05:25 -0700295 //
296 // TODO(b/182939859): Remove special cases for primary display.
297 virtual hal::HWDisplayId getPrimaryHwcDisplayId() const = 0;
298 virtual PhysicalDisplayId getPrimaryDisplayId() const = 0;
299 virtual bool isHeadless() const = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700300
Marin Shalamanova524a092020-07-27 21:39:55 +0200301 virtual std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const = 0;
302 virtual std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const = 0;
Kriti Dang7defaf32021-11-15 11:55:43 +0100303
Brian Lindahl7a4cb7e2024-10-30 10:42:21 -0600304 // AIDL Composer
Kriti Dang7defaf32021-11-15 11:55:43 +0100305 virtual status_t setBootDisplayMode(PhysicalDisplayId, hal::HWConfigId) = 0;
306 virtual status_t clearBootDisplayMode(PhysicalDisplayId) = 0;
Kriti Dang16ca2972022-02-01 20:07:03 +0100307 virtual std::optional<hal::HWConfigId> getPreferredBootDisplayMode(PhysicalDisplayId) = 0;
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500308 virtual status_t getDisplayDecorationSupport(
309 PhysicalDisplayId,
310 std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
311 support) = 0;
ramindani32cf0602022-03-02 02:30:29 +0000312 virtual status_t setIdleTimerEnabled(PhysicalDisplayId, std::chrono::milliseconds timeout) = 0;
ramindani06e518e2022-03-14 18:47:53 +0000313 virtual bool hasDisplayIdleTimerCapability(PhysicalDisplayId) const = 0;
314 virtual Hwc2::AidlTransform getPhysicalDisplayOrientation(PhysicalDisplayId) const = 0;
Kriti Dang674b9372022-11-18 10:58:44 +0100315 virtual std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability>
316 getHdrConversionCapabilities() const = 0;
317 virtual status_t setHdrConversionStrategy(
Kriti Dangd432bb52023-02-09 18:21:04 +0100318 aidl::android::hardware::graphics::common::HdrConversionStrategy,
319 aidl::android::hardware::graphics::common::Hdr*) = 0;
ramindanib2158ee2023-02-13 20:29:59 -0800320 virtual status_t setRefreshRateChangedCallbackDebugEnabled(PhysicalDisplayId, bool enabled) = 0;
ramindanic67d22c2023-11-28 14:58:47 -0800321 virtual status_t notifyExpectedPresent(PhysicalDisplayId, TimePoint expectedPresentTime,
322 Fps frameInterval) = 0;
Sally Qi95f669a2024-08-27 11:31:42 -0700323 virtual HWC2::Display::LutFileDescriptorMapper& getLutFileDescriptorMapper() = 0;
Brian Lindahl7a4cb7e2024-10-30 10:42:21 -0600324 virtual int32_t getMaxLayerPictureProfiles(PhysicalDisplayId) = 0;
325 virtual status_t setDisplayPictureProfileHandle(PhysicalDisplayId,
326 const PictureProfileHandle& handle) = 0;
Lloyd Pique441d5042018-10-18 16:49:51 -0700327};
328
Vishnu Naira3140382022-02-24 14:07:11 -0800329static inline bool operator==(const android::HWComposer::DeviceRequestedChanges& lhs,
330 const android::HWComposer::DeviceRequestedChanges& rhs) {
331 return lhs.changedTypes == rhs.changedTypes && lhs.displayRequests == rhs.displayRequests &&
332 lhs.layerRequests == rhs.layerRequests &&
Sally Qi95f669a2024-08-27 11:31:42 -0700333 lhs.clientTargetProperty == rhs.clientTargetProperty && lhs.layerLuts == rhs.layerLuts;
Vishnu Naira3140382022-02-24 14:07:11 -0800334}
335
Lloyd Pique441d5042018-10-18 16:49:51 -0700336namespace impl {
337
338class HWComposer final : public android::HWComposer {
Mathias Agopiana350ff92010-08-10 17:14:02 -0700339public:
Dominik Laskowski1af47932018-11-12 10:20:46 -0800340 explicit HWComposer(std::unique_ptr<Hwc2::Composer> composer);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800341 explicit HWComposer(const std::string& composerServiceName);
Mathias Agopian8b736f12012-08-13 17:54:26 -0700342
Lloyd Pique441d5042018-10-18 16:49:51 -0700343 ~HWComposer() override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700344
Yichi Chen3401b562022-01-17 15:42:35 +0800345 void setCallback(HWC2::ComposerCallback&) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700346
Marin Shalamanova524a092020-07-27 21:39:55 +0200347 bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
Lloyd Pique441d5042018-10-18 16:49:51 -0700348 DisplayIdentificationData* outData) const override;
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700349
Ady Abrahamde549d42022-01-26 19:19:17 -0800350 bool hasCapability(aidl::android::hardware::graphics::composer3::Capability) const override;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500351 bool hasDisplayCapability(
352 HalDisplayId,
353 aidl::android::hardware::graphics::composer3::DisplayCapability) const override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700354
Dominik Laskowski13948602021-03-08 20:48:28 -0800355 size_t getMaxVirtualDisplayCount() const override;
356 size_t getMaxVirtualDisplayDimension() const override;
357
Dominik Laskowski263eec42021-07-21 23:13:24 -0700358 bool allocateVirtualDisplay(HalVirtualDisplayId, ui::Size, ui::PixelFormat*) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700359
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100360 // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated.
Lucas Berthou8d0a0c42024-08-27 14:32:31 +0000361 void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId,
362 std::optional<ui::Size> physicalSize) override;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100363
Dan Stoza9e56aa02015-11-02 13:00:03 -0800364 // Attempts to create a new layer on this display
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700365 std::shared_ptr<HWC2::Layer> createLayer(HalDisplayId) override;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700366
Lloyd Pique66d68602019-02-13 14:23:31 -0800367 status_t getDeviceCompositionChanges(
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200368 HalDisplayId, bool frameUsesClientComposition,
Ady Abrahamf1db8032023-03-24 17:52:34 -0700369 std::optional<std::chrono::steady_clock::time_point> earliestPresentTime,
ramindani4aac32c2023-10-30 14:13:30 -0700370 nsecs_t expectedPresentTime, Fps frameInterval,
Lloyd Pique66d68602019-02-13 14:23:31 -0800371 std::optional<DeviceRequestedChanges>* outChanges) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700372
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200373 status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence,
Alec Mourif97df4d2023-09-06 02:10:05 +0000374 const sp<GraphicBuffer>& target, ui::Dataspace,
375 float hdrSdrRatio) override;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800376
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800377 // Present layers to the display and read releaseFences.
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700378 status_t presentAndGetReleaseFences(
Ady Abrahamf1db8032023-03-24 17:52:34 -0700379 HalDisplayId,
380 std::optional<std::chrono::steady_clock::time_point> earliestPresentTime) override;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700381
Leon Scroggins IIIa3ba7fa2024-05-22 16:34:52 -0400382 status_t executeCommands(HalDisplayId) override;
383
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700384 // set power mode
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200385 status_t setPowerMode(PhysicalDisplayId, hal::PowerMode mode) override;
Colin Cross10fbdb62012-07-12 17:56:34 -0700386
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700387 // Sets a color transform to be applied to the result of composition
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200388 status_t setColorTransform(HalDisplayId, const mat4& transform) override;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700389
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200390 // reset state when a display is disconnected
391 void disconnectDisplay(HalDisplayId) override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700392
Dominik Laskowskidc2bb802022-09-28 16:02:59 -0400393 // Get the present fence/timestamp received from the last call to present.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200394 sp<Fence> getPresentFence(HalDisplayId) const override;
Dominik Laskowskidc2bb802022-09-28 16:02:59 -0400395 nsecs_t getPresentTimestamp(PhysicalDisplayId) const override;
Mathias Agopianda27af92012-09-13 18:17:13 -0700396
Dan Stoza9e56aa02015-11-02 13:00:03 -0800397 // Get last release fence for the given layer
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200398 sp<Fence> getLayerReleaseFence(HalDisplayId, HWC2::Layer*) const override;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700399
Jesse Hall851cfe82013-03-20 13:44:00 -0700400 // Set the output buffer and acquire fence for a virtual display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200401 status_t setOutputBuffer(HalVirtualDisplayId, const sp<Fence>& acquireFence,
Lloyd Pique441d5042018-10-18 16:49:51 -0700402 const sp<GraphicBuffer>& buffer) override;
Jesse Hall851cfe82013-03-20 13:44:00 -0700403
Dan Stoza9e56aa02015-11-02 13:00:03 -0800404 // After SurfaceFlinger has retrieved the release fences for all the frames,
405 // it can call this to clear the shared pointers in the release fence map
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200406 void clearReleaseFences(HalDisplayId) override;
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700407
Peiyong Lin62665892018-04-16 11:07:44 -0700408 // Fetches the HDR capabilities of the given display
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200409 status_t getHdrCapabilities(HalDisplayId, HdrCapabilities* outCapabilities) override;
Dan Stozac4f471e2016-03-24 09:31:08 -0700410
Sally Qibb866c12022-10-17 11:31:20 -0700411 const aidl::android::hardware::graphics::composer3::OverlayProperties& getOverlaySupport()
412 const override;
Sally Qi0cbd08b2022-08-17 12:12:28 -0700413
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200414 int32_t getSupportedPerFrameMetadata(HalDisplayId) const override;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700415
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700416 // Returns the available RenderIntent of the given display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200417 std::vector<ui::RenderIntent> getRenderIntents(HalDisplayId, ui::ColorMode) const override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700418
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200419 mat4 getDataspaceSaturationMatrix(HalDisplayId, ui::Dataspace) override;
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700420
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700421 // Returns the attributes of the color sampling engine.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200422 status_t getDisplayedContentSamplingAttributes(HalDisplayId, ui::PixelFormat* outFormat,
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700423 ui::Dataspace* outDataspace,
Lloyd Pique441d5042018-10-18 16:49:51 -0700424 uint8_t* outComponentMask) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200425 status_t setDisplayContentSamplingEnabled(HalDisplayId, bool enabled, uint8_t componentMask,
Marin Shalamanova524a092020-07-27 21:39:55 +0200426 uint64_t maxFrames) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200427 status_t getDisplayedContentSample(HalDisplayId, uint64_t maxFrames, uint64_t timestamp,
Lloyd Pique441d5042018-10-18 16:49:51 -0700428 DisplayedFrameStats* outStats) override;
Dominik Laskowskib17c6212022-05-09 09:36:19 -0700429 ftl::Future<status_t> setDisplayBrightness(
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000430 PhysicalDisplayId, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -0800431 const Hwc2::Composer::DisplayBrightnessOptions&) override;
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700432
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700433 // Events handling ---------------------------------------------------------
434
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200435 // Returns PhysicalDisplayId (and display name on connection of new or previously disconnected
Dominik Laskowski075d3172018-05-24 15:50:06 -0700436 // display), or std::nullopt if hotplug event was ignored.
Marin Shalamanova524a092020-07-27 21:39:55 +0200437 std::optional<DisplayIdentificationInfo> onHotplug(hal::HWDisplayId, hal::Connection) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700438
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200439 bool updatesDeviceProductInfoOnHotplugReconnect() const override;
440
Leon Scroggins III959a7ff2023-02-07 11:24:25 -0500441 std::optional<PhysicalDisplayId> onVsync(hal::HWDisplayId, nsecs_t timestamp) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200442 void setVsyncEnabled(PhysicalDisplayId, hal::Vsync enabled) override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700443
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200444 bool isConnected(PhysicalDisplayId) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700445
ramindani263a3f12023-07-18 20:44:49 -0700446 std::vector<HWCDisplayMode> getModes(PhysicalDisplayId,
447 int32_t maxFrameIntervalNs) const override;
Dan Stoza7f7da322014-05-02 15:26:25 -0700448
Dominik Laskowskid940a012024-01-28 13:25:44 -0500449 ftl::Expected<hal::HWConfigId, status_t> getActiveMode(PhysicalDisplayId) const override;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700450
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200451 std::vector<ui::ColorMode> getColorModes(PhysicalDisplayId) const override;
Michael Wright28f24d02016-07-12 13:30:53 -0700452
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200453 status_t setActiveColorMode(PhysicalDisplayId, ui::ColorMode, ui::RenderIntent) override;
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600454
Matt Buckley50c44062022-01-17 20:48:10 +0000455 bool getValidateSkipped(HalDisplayId displayId) const override;
456
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800457 // Composer 2.4
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100458 ui::DisplayConnectionType getDisplayConnectionType(PhysicalDisplayId) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200459 bool isVsyncPeriodSwitchSupported(PhysicalDisplayId) const override;
Dominik Laskowskia109bb22024-01-28 13:33:51 -0500460 ftl::Expected<nsecs_t, status_t> getDisplayVsyncPeriod(PhysicalDisplayId) const override;
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100461 status_t setActiveModeWithConstraints(PhysicalDisplayId, hal::HWConfigId,
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100462 const hal::VsyncPeriodChangeConstraints&,
463 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200464 status_t setAutoLowLatencyMode(PhysicalDisplayId, bool) override;
Dominik Laskowski6c7b36e2022-03-03 08:27:58 -0800465 status_t getSupportedContentTypes(PhysicalDisplayId,
466 std::vector<hal::ContentType>*) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200467 status_t setContentType(PhysicalDisplayId, hal::ContentType) override;
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800468
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800469 const std::unordered_map<std::string, bool>& getSupportedLayerGenericMetadata() const override;
470
Kriti Dang7defaf32021-11-15 11:55:43 +0100471 // Composer 3.0
Kriti Dang7defaf32021-11-15 11:55:43 +0100472 status_t setBootDisplayMode(PhysicalDisplayId, hal::HWConfigId) override;
473 status_t clearBootDisplayMode(PhysicalDisplayId) override;
Kriti Dang16ca2972022-02-01 20:07:03 +0100474 std::optional<hal::HWConfigId> getPreferredBootDisplayMode(PhysicalDisplayId) override;
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500475 status_t getDisplayDecorationSupport(
476 PhysicalDisplayId,
477 std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
478 support) override;
ramindani32cf0602022-03-02 02:30:29 +0000479 status_t setIdleTimerEnabled(PhysicalDisplayId, std::chrono::milliseconds timeout) override;
ramindani06e518e2022-03-14 18:47:53 +0000480 bool hasDisplayIdleTimerCapability(PhysicalDisplayId) const override;
481 Hwc2::AidlTransform getPhysicalDisplayOrientation(PhysicalDisplayId) const override;
Kriti Dang674b9372022-11-18 10:58:44 +0100482 std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability>
483 getHdrConversionCapabilities() const override;
484 status_t setHdrConversionStrategy(
Kriti Dangd432bb52023-02-09 18:21:04 +0100485 aidl::android::hardware::graphics::common::HdrConversionStrategy,
486 aidl::android::hardware::graphics::common::Hdr*) override;
ramindanib2158ee2023-02-13 20:29:59 -0800487 status_t setRefreshRateChangedCallbackDebugEnabled(PhysicalDisplayId, bool enabled) override;
ramindanic67d22c2023-11-28 14:58:47 -0800488 status_t notifyExpectedPresent(PhysicalDisplayId, TimePoint expectedPresentTime,
489 Fps frameInterval) override;
Sally Qi95f669a2024-08-27 11:31:42 -0700490 HWC2::Display::LutFileDescriptorMapper& getLutFileDescriptorMapper() override;
Brian Lindahl7a4cb7e2024-10-30 10:42:21 -0600491 int32_t getMaxLayerPictureProfiles(PhysicalDisplayId) override;
492 status_t setDisplayPictureProfileHandle(PhysicalDisplayId,
493 const android::PictureProfileHandle& profile) override;
Sally Qi11dcd582024-08-16 18:11:27 -0700494
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700495 // for debugging ----------------------------------------------------------
Lloyd Pique441d5042018-10-18 16:49:51 -0700496 void dump(std::string& out) const override;
Sally Qi254ef492024-04-08 15:01:28 -0700497 void dumpOverlayProperties(std::string& out) const override;
Mathias Agopian83727852010-09-23 18:13:21 -0700498
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800499 Hwc2::Composer* getComposer() const override { return mComposer.get(); }
Steven Thomas6e8f7062017-11-22 14:15:29 -0800500
Dominik Laskowskif8db0f02021-04-19 11:05:25 -0700501 hal::HWDisplayId getPrimaryHwcDisplayId() const override {
502 LOG_ALWAYS_FATAL_IF(!mPrimaryHwcDisplayId, "Missing HWC primary display");
503 return *mPrimaryHwcDisplayId;
Lloyd Pique441d5042018-10-18 16:49:51 -0700504 }
Dominik Laskowskif8db0f02021-04-19 11:05:25 -0700505
506 PhysicalDisplayId getPrimaryDisplayId() const override {
507 const auto id = toPhysicalDisplayId(getPrimaryHwcDisplayId());
508 LOG_ALWAYS_FATAL_IF(!id, "Missing primary display");
509 return *id;
Lloyd Pique441d5042018-10-18 16:49:51 -0700510 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700511
Dominik Laskowskif8db0f02021-04-19 11:05:25 -0700512 virtual bool isHeadless() const override { return !mPrimaryHwcDisplayId; }
513
Marin Shalamanova524a092020-07-27 21:39:55 +0200514 std::optional<PhysicalDisplayId> toPhysicalDisplayId(hal::HWDisplayId) const override;
515 std::optional<hal::HWDisplayId> fromPhysicalDisplayId(PhysicalDisplayId) const override;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700516
Mathias Agopiana350ff92010-08-10 17:14:02 -0700517private:
Lloyd Piquee39cad22017-12-20 17:01:29 -0800518 // For unit tests
519 friend TestableSurfaceFlinger;
ramindani355fca82023-12-18 12:07:34 -0800520 friend HWComposerTest;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800521
Mathias Agopiane60b0682012-08-21 23:34:09 -0700522 struct DisplayData {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800523 std::unique_ptr<HWC2::Display> hwcDisplay;
Dominik Laskowskidc2bb802022-09-28 16:02:59 -0400524
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700525 sp<Fence> lastPresentFence = Fence::NO_FENCE; // signals when the last set op retires
Dominik Laskowskidc2bb802022-09-28 16:02:59 -0400526 nsecs_t lastPresentTimestamp = 0;
527
Steven Thomas94e35b92017-07-26 18:48:28 -0700528 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Jamie Gennis2ec3e072012-11-11 16:24:33 -0800529
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700530 bool validateWasSkipped;
Peiyong Line9d809e2020-04-14 13:10:48 -0700531 hal::Error presentError;
Dominik Laskowski1af47932018-11-12 10:20:46 -0800532
533 bool vsyncTraceToggle = false;
534
535 std::mutex vsyncEnabledLock;
Peiyong Line9d809e2020-04-14 13:10:48 -0700536 hal::Vsync vsyncEnabled GUARDED_BY(vsyncEnabledLock) = hal::Vsync::DISABLE;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700537 };
538
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100539 std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId);
540 std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId);
541 bool shouldIgnoreHotplugConnect(hal::HWDisplayId, bool hasDisplayIdentificationData) const;
542
Lucas Berthou8d0a0c42024-08-27 14:32:31 +0000543 aidl::android::hardware::graphics::composer3::DisplayConfiguration::Dpi
544 getEstimatedDotsPerInchFromSize(uint64_t hwcDisplayId, const HWCDisplayMode& hwcMode) const;
545
546 aidl::android::hardware::graphics::composer3::DisplayConfiguration::Dpi correctedDpiIfneeded(
547 aidl::android::hardware::graphics::composer3::DisplayConfiguration::Dpi dpi,
548 aidl::android::hardware::graphics::composer3::DisplayConfiguration::Dpi estimatedDpi)
549 const;
ramindani263a3f12023-07-18 20:44:49 -0700550 std::vector<HWCDisplayMode> getModesFromDisplayConfigurations(uint64_t hwcDisplayId,
551 int32_t maxFrameIntervalNs) const;
ramindani0cd1d8d2023-06-13 13:43:23 -0700552 std::vector<HWCDisplayMode> getModesFromLegacyDisplayConfigs(uint64_t hwcDisplayId) const;
553
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100554 int32_t getAttribute(hal::HWDisplayId hwcDisplayId, hal::HWConfigId configId,
Marin Shalamanov045b7002021-01-07 16:56:24 +0100555 hal::Attribute attribute) const;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100556
557 void loadCapabilities();
558 void loadLayerMetadataSupport();
Sally Qibb866c12022-10-17 11:31:20 -0700559 void loadOverlayProperties();
Kriti Dang674b9372022-11-18 10:58:44 +0100560 void loadHdrConversionCapabilities();
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100561
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200562 std::unordered_map<HalDisplayId, DisplayData> mDisplayData;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800563
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800564 std::unique_ptr<android::Hwc2::Composer> mComposer;
Ady Abrahamde549d42022-01-26 19:19:17 -0800565 std::unordered_set<aidl::android::hardware::graphics::composer3::Capability> mCapabilities;
Sally Qibb866c12022-10-17 11:31:20 -0700566 aidl::android::hardware::graphics::composer3::OverlayProperties mOverlayProperties;
Kriti Dang674b9372022-11-18 10:58:44 +0100567 std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability>
568 mHdrConversionCapabilities = {};
569
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800570 std::unordered_map<std::string, bool> mSupportedLayerGenericMetadata;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800571 bool mRegisteredCallback = false;
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800572
Marin Shalamanova524a092020-07-27 21:39:55 +0200573 std::unordered_map<hal::HWDisplayId, PhysicalDisplayId> mPhysicalDisplayIdMap;
Dominik Laskowskif8db0f02021-04-19 11:05:25 -0700574 std::optional<hal::HWDisplayId> mPrimaryHwcDisplayId;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700575 bool mHasMultiDisplaySupport = false;
576
Dominik Laskowski13948602021-03-08 20:48:28 -0800577 const size_t mMaxVirtualDisplayDimension;
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200578 const bool mUpdateDeviceProductInfoOnHotplugReconnect;
ramindani355fca82023-12-18 12:07:34 -0800579 bool mEnableVrrTimeout;
Sally Qi95f669a2024-08-27 11:31:42 -0700580
581 HWC2::Display::LutFileDescriptorMapper mLutFileDescriptorMapper;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700582};
583
Lloyd Pique441d5042018-10-18 16:49:51 -0700584} // namespace impl
Dominik Laskowski1af47932018-11-12 10:20:46 -0800585} // namespace android