blob: 8e2aeaf2347d0df7aca4bbc9229f5b2365c9d1a5 [file] [log] [blame]
Dan Stoza651bf312015-10-23 17:03:17 -07001/*
2 * Copyright 2015 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 Laskowski8b01cc02020-07-14 19:02:41 -070017#pragma once
Dan Stoza651bf312015-10-23 17:03:17 -070018
Lloyd Piquea516c002021-05-07 14:36:58 -070019#include <android-base/expected.h>
Ady Abraham27fbcc72021-09-20 14:54:57 -070020#include <android-base/thread_annotations.h>
Dominik Laskowski969cdcb2024-02-08 16:35:29 -050021#include <ftl/expected.h>
Dominik Laskowskib17c6212022-05-09 09:36:19 -070022#include <ftl/future.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070023#include <gui/HdrMetadata.h>
Mathias Agopian1d77b712017-02-17 15:46:13 -080024#include <math/mat4.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070025#include <ui/HdrCapabilities.h>
Yichi Chen8366f562019-03-25 19:44:06 +080026#include <ui/Region.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010027#include <ui/StaticDisplayInfo.h>
Dan Stoza651bf312015-10-23 17:03:17 -070028#include <utils/Log.h>
29#include <utils/StrongPointer.h>
30#include <utils/Timers.h>
31
32#include <functional>
33#include <string>
34#include <unordered_map>
Dan Stoza9f26a9c2016-06-22 14:51:09 -070035#include <unordered_set>
Dan Stoza651bf312015-10-23 17:03:17 -070036#include <vector>
37
Alec Mouricdf16792021-12-10 13:16:06 -080038#include "ComposerHal.h"
Peiyong Line9d809e2020-04-14 13:10:48 -070039#include "Hal.h"
40
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -050041#include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h>
Huihong Luo791bef92023-09-19 21:18:45 -070042#include <aidl/android/hardware/graphics/common/DisplayHotplugEvent.h>
Ady Abrahamde549d42022-01-26 19:19:17 -080043#include <aidl/android/hardware/graphics/composer3/Capability.h>
Alec Mouri30835f22022-03-18 00:58:26 +000044#include <aidl/android/hardware/graphics/composer3/ClientTargetPropertyWithBrightness.h>
Ady Abraham6e60b142022-01-06 18:10:35 -080045#include <aidl/android/hardware/graphics/composer3/Color.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050046#include <aidl/android/hardware/graphics/composer3/Composition.h>
Leon Scroggins III5967aec2021-12-29 11:14:22 -050047#include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
Sally Qi492cec32024-06-28 14:34:47 -070048#include <aidl/android/hardware/graphics/composer3/Lut.h>
Sally Qi0cbd08b2022-08-17 12:12:28 -070049#include <aidl/android/hardware/graphics/composer3/OverlayProperties.h>
ramindani12bfe6b2023-02-03 13:29:19 -080050#include <aidl/android/hardware/graphics/composer3/RefreshRateChangedDebugData.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050051
Dan Stoza651bf312015-10-23 17:03:17 -070052namespace android {
Lloyd Piquebc792092018-01-17 11:52:30 -080053
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070054class Fence;
55class FloatRect;
56class GraphicBuffer;
57class TestableSurfaceFlinger;
58struct DisplayedFrameStats;
59
60namespace Hwc2 {
61class Composer;
62} // namespace Hwc2
Dan Stoza651bf312015-10-23 17:03:17 -070063
64namespace HWC2 {
65
Dan Stoza651bf312015-10-23 17:03:17 -070066class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070067
68namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070069
Huihong Luo817ebb82023-12-13 12:54:24 -080070using aidl::android::hardware::drm::HdcpLevels;
Huihong Luo791bef92023-09-19 21:18:45 -070071using aidl::android::hardware::graphics::common::DisplayHotplugEvent;
ramindani12bfe6b2023-02-03 13:29:19 -080072using aidl::android::hardware::graphics::composer3::RefreshRateChangedDebugData;
73
Steven Thomas94e35b92017-07-26 18:48:28 -070074// Implement this interface to receive hardware composer events.
75//
76// These callback functions will generally be called on a hwbinder thread, but
Huihong Luo791bef92023-09-19 21:18:45 -070077// when first registering the callback the onComposerHalHotplugEvent() function
78// will immediately be called on the thread calling registerCallback().
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070079struct ComposerCallback {
Huihong Luo791bef92023-09-19 21:18:45 -070080 virtual void onComposerHalHotplugEvent(hal::HWDisplayId, DisplayHotplugEvent) = 0;
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070081 virtual void onComposerHalRefresh(hal::HWDisplayId) = 0;
Dominik Laskowskidc2bb802022-09-28 16:02:59 -040082 virtual void onComposerHalVsync(hal::HWDisplayId, nsecs_t timestamp,
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070083 std::optional<hal::VsyncPeriodNanos>) = 0;
84 virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId,
85 const hal::VsyncPeriodChangeTimeline&) = 0;
86 virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0;
Yichi Chen3401b562022-01-17 15:42:35 +080087 virtual void onComposerHalVsyncIdle(hal::HWDisplayId) = 0;
ramindani12bfe6b2023-02-03 13:29:19 -080088 virtual void onRefreshRateChangedDebug(const RefreshRateChangedDebugData&) = 0;
Huihong Luo817ebb82023-12-13 12:54:24 -080089 virtual void onComposerHalHdcpLevelsChanged(hal::HWDisplayId, const HdcpLevels& levels) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070090
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070091protected:
92 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070093};
Dan Stoza651bf312015-10-23 17:03:17 -070094
Peiyong Line9d809e2020-04-14 13:10:48 -070095// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080096class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070097public:
Ana Krulec4593b692019-01-11 22:07:25 -080098 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070099
Peiyong Line9d809e2020-04-14 13:10:48 -0700100 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800101 virtual bool isConnected() const = 0;
Florian Mayercffc3792022-03-01 23:50:09 +0000102 virtual void setConnected(bool connected) = 0; // For use by HWComposer only
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500103 virtual bool hasCapability(
104 aidl::android::hardware::graphics::composer3::DisplayCapability) const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -0700105 virtual bool isVsyncPeriodSwitchSupported() const = 0;
ramindani32cf0602022-03-02 02:30:29 +0000106 virtual bool hasDisplayIdleTimerCapability() const = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -0700107 virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0;
Lucas Berthou8d0a0c42024-08-27 14:32:31 +0000108 virtual std::optional<ui::Size> getPhysicalSizeInMm() const = 0;
Dan Stoza651bf312015-10-23 17:03:17 -0700109
ramindani86d3d982022-03-16 20:57:42 +0000110 [[nodiscard]] virtual hal::Error acceptChanges() = 0;
111 [[nodiscard]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error>
Lloyd Piquea516c002021-05-07 14:36:58 -0700112 createLayer() = 0;
ramindani86d3d982022-03-16 20:57:42 +0000113 [[nodiscard]] virtual hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500114 std::unordered_map<Layer*, aidl::android::hardware::graphics::composer3::Composition>*
115 outTypes) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000116 [[nodiscard]] virtual hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +0800117 // Returns a bitmask which contains HdrMetadata::Type::*.
ramindani86d3d982022-03-16 20:57:42 +0000118 [[nodiscard]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
119 [[nodiscard]] virtual hal::Error getRenderIntents(
Peiyong Line9d809e2020-04-14 13:10:48 -0700120 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000121 [[nodiscard]] virtual hal::Error getDataspaceSaturationMatrix(hal::Dataspace dataspace,
122 android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800123
ramindani86d3d982022-03-16 20:57:42 +0000124 [[nodiscard]] virtual hal::Error getName(std::string* outName) const = 0;
125 [[nodiscard]] virtual hal::Error getRequests(
Peiyong Line9d809e2020-04-14 13:10:48 -0700126 hal::DisplayRequest* outDisplayRequests,
127 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
Dominik Laskowski969cdcb2024-02-08 16:35:29 -0500128 [[nodiscard]] virtual ftl::Expected<ui::DisplayConnectionType, hal::Error> getConnectionType()
129 const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000130 [[nodiscard]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
131 [[nodiscard]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800132 android::HdrCapabilities* outCapabilities) const = 0;
Sally Qi0cbd08b2022-08-17 12:12:28 -0700133 [[nodiscard]] virtual hal::Error getOverlaySupport(
134 aidl::android::hardware::graphics::composer3::OverlayProperties* outProperties)
135 const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000136 [[nodiscard]] virtual hal::Error getDisplayedContentSamplingAttributes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700137 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800138 uint8_t* outComponentMask) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000139 [[nodiscard]] virtual hal::Error setDisplayContentSamplingEnabled(bool enabled,
140 uint8_t componentMask,
141 uint64_t maxFrames) const = 0;
142 [[nodiscard]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800143 uint64_t maxFrames, uint64_t timestamp,
144 android::DisplayedFrameStats* outStats) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000145 [[nodiscard]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800146 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000147 [[nodiscard]] virtual hal::Error present(android::sp<android::Fence>* outPresentFence) = 0;
148 [[nodiscard]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800149 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Alec Mourif97df4d2023-09-06 02:10:05 +0000150 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace,
151 float hdrSdrRatio) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000152 [[nodiscard]] virtual hal::Error setColorMode(hal::ColorMode mode,
153 hal::RenderIntent renderIntent) = 0;
154 [[nodiscard]] virtual hal::Error setColorTransform(const android::mat4& matrix) = 0;
155 [[nodiscard]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800156 const android::sp<android::GraphicBuffer>& buffer,
157 const android::sp<android::Fence>& releaseFence) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000158 [[nodiscard]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
159 [[nodiscard]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
ramindani09acbb82023-11-03 09:02:38 -0700160 [[nodiscard]] virtual hal::Error validate(nsecs_t expectedPresentTime, int32_t frameIntervalNs,
161 uint32_t* outNumTypes, uint32_t* outNumRequests) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000162 [[nodiscard]] virtual hal::Error presentOrValidate(nsecs_t expectedPresentTime,
ramindani4aac32c2023-10-30 14:13:30 -0700163 int32_t frameIntervalNs,
ramindani86d3d982022-03-16 20:57:42 +0000164 uint32_t* outNumTypes,
165 uint32_t* outNumRequests,
166 android::sp<android::Fence>* outPresentFence,
167 uint32_t* state) = 0;
Dominik Laskowskib17c6212022-05-09 09:36:19 -0700168 [[nodiscard]] virtual ftl::Future<hal::Error> setDisplayBrightness(
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000169 float brightness, float brightnessNits,
170 const Hwc2::Composer::DisplayBrightnessOptions& options) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000171 [[nodiscard]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100172 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700173 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000174 [[nodiscard]] virtual hal::Error setBootDisplayConfig(hal::HWConfigId configId) = 0;
175 [[nodiscard]] virtual hal::Error clearBootDisplayConfig() = 0;
176 [[nodiscard]] virtual hal::Error getPreferredBootDisplayConfig(
Kriti Dang7defaf32021-11-15 11:55:43 +0100177 hal::HWConfigId* configId) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000178 [[nodiscard]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
179 [[nodiscard]] virtual hal::Error getSupportedContentTypes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700180 std::vector<hal::ContentType>*) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000181 [[nodiscard]] virtual hal::Error setContentType(hal::ContentType) = 0;
182 [[nodiscard]] virtual hal::Error getClientTargetProperty(
Alec Mouri30835f22022-03-18 00:58:26 +0000183 aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness*
184 outClientTargetProperty) = 0;
Sally Qi11dcd582024-08-16 18:11:27 -0700185 [[nodiscard]] virtual hal::Error getRequestedLuts(
186 std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>*
187 outLuts) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000188 [[nodiscard]] virtual hal::Error getDisplayDecorationSupport(
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500189 std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
190 support) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000191 [[nodiscard]] virtual hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) = 0;
192 [[nodiscard]] virtual hal::Error getPhysicalDisplayOrientation(
ramindani06e518e2022-03-14 18:47:53 +0000193 Hwc2::AidlTransform* outTransform) const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800194};
195
196namespace impl {
197
Lloyd Piquea516c002021-05-07 14:36:58 -0700198class Layer;
199
Ana Krulec4593b692019-01-11 22:07:25 -0800200class Display : public HWC2::Display {
201public:
Ady Abrahamde549d42022-01-26 19:19:17 -0800202 Display(android::Hwc2::Composer&,
203 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&,
204 hal::HWDisplayId, hal::DisplayType);
Ana Krulec4593b692019-01-11 22:07:25 -0800205 ~Display() override;
206
207 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700208 hal::Error acceptChanges() override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700209 base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700210 hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500211 std::unordered_map<HWC2::Layer*,
212 aidl::android::hardware::graphics::composer3::Composition>* outTypes)
213 override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700214 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800215 // Returns a bitmask which contains HdrMetadata::Type::*.
216 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700217 hal::Error getRenderIntents(hal::ColorMode colorMode,
218 std::vector<hal::RenderIntent>* outRenderIntents) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200219 hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700220
Peiyong Line9d809e2020-04-14 13:10:48 -0700221 hal::Error getName(std::string* outName) const override;
222 hal::Error getRequests(
223 hal::DisplayRequest* outDisplayRequests,
Lloyd Piquea516c002021-05-07 14:36:58 -0700224 std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override;
Dominik Laskowski969cdcb2024-02-08 16:35:29 -0500225 ftl::Expected<ui::DisplayConnectionType, hal::Error> getConnectionType() const override;
Ady Abraham27fbcc72021-09-20 14:54:57 -0700226 hal::Error supportsDoze(bool* outSupport) const override EXCLUDES(mDisplayCapabilitiesMutex);
Peiyong Line9d809e2020-04-14 13:10:48 -0700227 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
Sally Qi0cbd08b2022-08-17 12:12:28 -0700228 hal::Error getOverlaySupport(aidl::android::hardware::graphics::composer3::OverlayProperties*
229 outProperties) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700230 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
231 hal::Dataspace* outDataspace,
232 uint8_t* outComponentMask) const override;
233 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
234 uint64_t maxFrames) const override;
235 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
236 android::DisplayedFrameStats* outStats) const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700237 hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>*
238 outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700239 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700240 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
241 const android::sp<android::Fence>& acquireFence,
Alec Mourif97df4d2023-09-06 02:10:05 +0000242 hal::Dataspace dataspace, float hdrSdrRatio) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200243 hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
Ady Abrahamdc011a92021-12-21 14:06:44 -0800244 hal::Error setColorTransform(const android::mat4& matrix) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200245 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700246 const android::sp<android::Fence>& releaseFence) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200247 hal::Error setPowerMode(hal::PowerMode) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700248 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
ramindani09acbb82023-11-03 09:02:38 -0700249 hal::Error validate(nsecs_t expectedPresentTime, int32_t frameIntervalNs, uint32_t* outNumTypes,
Ady Abraham43065bd2021-12-10 17:22:15 -0800250 uint32_t* outNumRequests) override;
ramindani4aac32c2023-10-30 14:13:30 -0700251 hal::Error presentOrValidate(nsecs_t expectedPresentTime, int32_t frameIntervalNs,
252 uint32_t* outNumTypes, uint32_t* outNumRequests,
Peiyong Line9d809e2020-04-14 13:10:48 -0700253 android::sp<android::Fence>* outPresentFence,
254 uint32_t* state) override;
Dominik Laskowskib17c6212022-05-09 09:36:19 -0700255 ftl::Future<hal::Error> setDisplayBrightness(
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000256 float brightness, float brightnessNits,
257 const Hwc2::Composer::DisplayBrightnessOptions& options) override;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100258 hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId,
259 const hal::VsyncPeriodChangeConstraints& constraints,
260 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Kriti Dang7defaf32021-11-15 11:55:43 +0100261 hal::Error setBootDisplayConfig(hal::HWConfigId configId) override;
262 hal::Error clearBootDisplayConfig() override;
263 hal::Error getPreferredBootDisplayConfig(hal::HWConfigId* configId) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700264 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700265 hal::Error getSupportedContentTypes(
266 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700267 hal::Error setContentType(hal::ContentType) override;
Alec Mouri30835f22022-03-18 00:58:26 +0000268 hal::Error getClientTargetProperty(
269 aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness*
270 outClientTargetProperty) override;
Sally Qi11dcd582024-08-16 18:11:27 -0700271 hal::Error getRequestedLuts(
272 std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>*
273 outLuts) override;
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500274 hal::Error getDisplayDecorationSupport(
275 std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
276 support) override;
ramindani32cf0602022-03-02 02:30:29 +0000277 hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700278
Dan Stoza651bf312015-10-23 17:03:17 -0700279 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700280 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800281 bool isConnected() const override { return mIsConnected; }
Florian Mayercffc3792022-03-01 23:50:09 +0000282 void setConnected(bool connected) override;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500283 bool hasCapability(aidl::android::hardware::graphics::composer3::DisplayCapability)
284 const override EXCLUDES(mDisplayCapabilitiesMutex);
Lloyd Piquea516c002021-05-07 14:36:58 -0700285 bool isVsyncPeriodSwitchSupported() const override;
ramindani32cf0602022-03-02 02:30:29 +0000286 bool hasDisplayIdleTimerCapability() const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700287 void onLayerDestroyed(hal::HWLayerId layerId) override;
ramindani06e518e2022-03-14 18:47:53 +0000288 hal::Error getPhysicalDisplayOrientation(Hwc2::AidlTransform* outTransform) const override;
Lucas Berthou8d0a0c42024-08-27 14:32:31 +0000289 void setPhysicalSizeInMm(std::optional<ui::Size> size);
290 std::optional<ui::Size> getPhysicalSizeInMm() const override { return mPhysicalSize; }
Dan Stoza651bf312015-10-23 17:03:17 -0700291
292private:
HyunKyounga264a352024-04-24 18:51:33 +0900293 void loadDisplayCapabilities();
Dan Stoza651bf312015-10-23 17:03:17 -0700294
Dan Stoza651bf312015-10-23 17:03:17 -0700295 // This may fail (and return a null pointer) if no layer with this ID exists
296 // on this display
Lloyd Piquea516c002021-05-07 14:36:58 -0700297 std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700298
Lloyd Piquebc792092018-01-17 11:52:30 -0800299 friend android::TestableSurfaceFlinger;
300
Dan Stoza651bf312015-10-23 17:03:17 -0700301 // Member variables
302
Florian Mayercffc3792022-03-01 23:50:09 +0000303 // These are references to data owned by HWComposer, which will outlive
Steven Thomas94e35b92017-07-26 18:48:28 -0700304 // this HWC2::Display, so these references are guaranteed to be valid for
305 // the lifetime of this object.
306 android::Hwc2::Composer& mComposer;
Ady Abrahamde549d42022-01-26 19:19:17 -0800307 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
308 mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700309
Peiyong Line9d809e2020-04-14 13:10:48 -0700310 const hal::HWDisplayId mId;
311 hal::DisplayType mType;
Dominik Laskowski969cdcb2024-02-08 16:35:29 -0500312 // Cached on first call to getConnectionType.
313 mutable std::optional<ftl::Expected<ui::DisplayConnectionType, hal::Error>> mConnectionType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800314 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700315
Lloyd Piquea516c002021-05-07 14:36:58 -0700316 using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>;
317 Layers mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700318
Ady Abraham27fbcc72021-09-20 14:54:57 -0700319 mutable std::mutex mDisplayCapabilitiesMutex;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700320 std::once_flag mDisplayCapabilityQueryFlag;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500321 std::optional<
322 std::unordered_set<aidl::android::hardware::graphics::composer3::DisplayCapability>>
323 mDisplayCapabilities GUARDED_BY(mDisplayCapabilitiesMutex);
Lucas Berthou8d0a0c42024-08-27 14:32:31 +0000324 // Physical size in mm.
325 std::optional<ui::Size> mPhysicalSize;
Dan Stoza651bf312015-10-23 17:03:17 -0700326};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800327
Ana Krulec4593b692019-01-11 22:07:25 -0800328} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700329
Lloyd Pique35d58242018-12-18 16:33:25 -0800330class Layer {
331public:
332 virtual ~Layer();
333
Peiyong Line9d809e2020-04-14 13:10:48 -0700334 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800335
ramindani86d3d982022-03-16 20:57:42 +0000336 [[nodiscard]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
337 [[nodiscard]] virtual hal::Error setBuffer(uint32_t slot,
338 const android::sp<android::GraphicBuffer>& buffer,
339 const android::sp<android::Fence>& acquireFence) = 0;
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700340 [[nodiscard]] virtual hal::Error setBufferSlotsToClear(
341 const std::vector<uint32_t>& slotsToClear, uint32_t activeBufferSlot) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000342 [[nodiscard]] virtual hal::Error setSurfaceDamage(const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800343
ramindani86d3d982022-03-16 20:57:42 +0000344 [[nodiscard]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
345 [[nodiscard]] virtual hal::Error setColor(
Ady Abraham6e60b142022-01-06 18:10:35 -0800346 aidl::android::hardware::graphics::composer3::Color color) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000347 [[nodiscard]] virtual hal::Error setCompositionType(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500348 aidl::android::hardware::graphics::composer3::Composition type) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000349 [[nodiscard]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
350 [[nodiscard]] virtual hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
351 const android::HdrMetadata& metadata) = 0;
352 [[nodiscard]] virtual hal::Error setDisplayFrame(const android::Rect& frame) = 0;
353 [[nodiscard]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
354 [[nodiscard]] virtual hal::Error setSidebandStream(const native_handle_t* stream) = 0;
355 [[nodiscard]] virtual hal::Error setSourceCrop(const android::FloatRect& crop) = 0;
356 [[nodiscard]] virtual hal::Error setTransform(hal::Transform transform) = 0;
357 [[nodiscard]] virtual hal::Error setVisibleRegion(const android::Region& region) = 0;
358 [[nodiscard]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800359
360 // Composer HAL 2.3
ramindani86d3d982022-03-16 20:57:42 +0000361 [[nodiscard]] virtual hal::Error setColorTransform(const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800362
363 // Composer HAL 2.4
ramindani86d3d982022-03-16 20:57:42 +0000364 [[nodiscard]] virtual hal::Error setLayerGenericMetadata(const std::string& name,
365 bool mandatory,
366 const std::vector<uint8_t>& value) = 0;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700367
368 // AIDL HAL
ramindani86d3d982022-03-16 20:57:42 +0000369 [[nodiscard]] virtual hal::Error setBrightness(float brightness) = 0;
370 [[nodiscard]] virtual hal::Error setBlockingRegion(const android::Region& region) = 0;
Sally Qi11dcd582024-08-16 18:11:27 -0700371 [[nodiscard]] virtual hal::Error setLuts(
372 std::vector<aidl::android::hardware::graphics::composer3::Lut>& luts) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800373};
374
375namespace impl {
376
Peiyong Line9d809e2020-04-14 13:10:48 -0700377// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800378
379class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700380public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700381 Layer(android::Hwc2::Composer& composer,
Ady Abrahamde549d42022-01-26 19:19:17 -0800382 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
383 capabilities,
384 HWC2::Display& display, hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800385 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700386
Lloyd Piquea516c002021-05-07 14:36:58 -0700387 void onOwningDisplayDestroyed();
388
Peiyong Line9d809e2020-04-14 13:10:48 -0700389 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700390
Peiyong Line9d809e2020-04-14 13:10:48 -0700391 hal::Error setCursorPosition(int32_t x, int32_t y) override;
392 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
393 const android::sp<android::Fence>& acquireFence) override;
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700394 hal::Error setBufferSlotsToClear(const std::vector<uint32_t>& slotsToClear,
395 uint32_t activeBufferSlot) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700396 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700397
Peiyong Line9d809e2020-04-14 13:10:48 -0700398 hal::Error setBlendMode(hal::BlendMode mode) override;
Ady Abraham6e60b142022-01-06 18:10:35 -0800399 hal::Error setColor(aidl::android::hardware::graphics::composer3::Color color) override;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500400 hal::Error setCompositionType(
401 aidl::android::hardware::graphics::composer3::Composition type) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700402 hal::Error setDataspace(hal::Dataspace dataspace) override;
403 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
404 const android::HdrMetadata& metadata) override;
405 hal::Error setDisplayFrame(const android::Rect& frame) override;
406 hal::Error setPlaneAlpha(float alpha) override;
407 hal::Error setSidebandStream(const native_handle_t* stream) override;
408 hal::Error setSourceCrop(const android::FloatRect& crop) override;
409 hal::Error setTransform(hal::Transform transform) override;
410 hal::Error setVisibleRegion(const android::Region& region) override;
411 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700412
Peiyong Lin698147a2018-09-14 13:27:18 -0700413 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700414 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700415
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800416 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700417 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
418 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800419
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700420 // AIDL HAL
Alec Mouri6da0e272022-02-07 12:45:57 -0800421 hal::Error setBrightness(float brightness) override;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500422 hal::Error setBlockingRegion(const android::Region& region) override;
Sally Qi11dcd582024-08-16 18:11:27 -0700423 hal::Error setLuts(
424 std::vector<aidl::android::hardware::graphics::composer3::Lut>& luts) override;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700425
Dan Stoza651bf312015-10-23 17:03:17 -0700426private:
Florian Mayercffc3792022-03-01 23:50:09 +0000427 // These are references to data owned by HWComposer, which will outlive
Steven Thomas94e35b92017-07-26 18:48:28 -0700428 // this HWC2::Layer, so these references are guaranteed to be valid for
429 // the lifetime of this object.
430 android::Hwc2::Composer& mComposer;
Ady Abrahamde549d42022-01-26 19:19:17 -0800431 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
432 mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700433
Lloyd Piquea516c002021-05-07 14:36:58 -0700434 HWC2::Display* mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700435 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800436
437 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
438 // multiple times.
439 android::Region mVisibleRegion = android::Region::INVALID_REGION;
440 android::Region mDamageRegion = android::Region::INVALID_REGION;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500441 android::Region mBlockingRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700442 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700443 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700444 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800445 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700446};
447
Lloyd Pique35d58242018-12-18 16:33:25 -0800448} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700449} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700450} // namespace android