blob: 29fe38008db86f9dfad9697114dec2a66773fa24 [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 Laskowskib17c6212022-05-09 09:36:19 -070021#include <ftl/future.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070022#include <gui/HdrMetadata.h>
Mathias Agopian1d77b712017-02-17 15:46:13 -080023#include <math/mat4.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070024#include <ui/HdrCapabilities.h>
Yichi Chen8366f562019-03-25 19:44:06 +080025#include <ui/Region.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010026#include <ui/StaticDisplayInfo.h>
Dan Stoza651bf312015-10-23 17:03:17 -070027#include <utils/Log.h>
28#include <utils/StrongPointer.h>
29#include <utils/Timers.h>
30
31#include <functional>
32#include <string>
33#include <unordered_map>
Dan Stoza9f26a9c2016-06-22 14:51:09 -070034#include <unordered_set>
Dan Stoza651bf312015-10-23 17:03:17 -070035#include <vector>
36
Alec Mouricdf16792021-12-10 13:16:06 -080037#include "ComposerHal.h"
Peiyong Line9d809e2020-04-14 13:10:48 -070038#include "Hal.h"
39
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -050040#include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h>
Huihong Luo791bef92023-09-19 21:18:45 -070041#include <aidl/android/hardware/graphics/common/DisplayHotplugEvent.h>
Ady Abrahamde549d42022-01-26 19:19:17 -080042#include <aidl/android/hardware/graphics/composer3/Capability.h>
Alec Mouri30835f22022-03-18 00:58:26 +000043#include <aidl/android/hardware/graphics/composer3/ClientTargetPropertyWithBrightness.h>
Ady Abraham6e60b142022-01-06 18:10:35 -080044#include <aidl/android/hardware/graphics/composer3/Color.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050045#include <aidl/android/hardware/graphics/composer3/Composition.h>
Leon Scroggins III5967aec2021-12-29 11:14:22 -050046#include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
Sally Qi0cbd08b2022-08-17 12:12:28 -070047#include <aidl/android/hardware/graphics/composer3/OverlayProperties.h>
ramindani12bfe6b2023-02-03 13:29:19 -080048#include <aidl/android/hardware/graphics/composer3/RefreshRateChangedDebugData.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050049
Dan Stoza651bf312015-10-23 17:03:17 -070050namespace android {
Lloyd Piquebc792092018-01-17 11:52:30 -080051
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070052class Fence;
53class FloatRect;
54class GraphicBuffer;
55class TestableSurfaceFlinger;
56struct DisplayedFrameStats;
57
58namespace Hwc2 {
59class Composer;
60} // namespace Hwc2
Dan Stoza651bf312015-10-23 17:03:17 -070061
62namespace HWC2 {
63
Dan Stoza651bf312015-10-23 17:03:17 -070064class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070065
66namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070067
Huihong Luo791bef92023-09-19 21:18:45 -070068using aidl::android::hardware::graphics::common::DisplayHotplugEvent;
ramindani12bfe6b2023-02-03 13:29:19 -080069using aidl::android::hardware::graphics::composer3::RefreshRateChangedDebugData;
70
Steven Thomas94e35b92017-07-26 18:48:28 -070071// Implement this interface to receive hardware composer events.
72//
73// These callback functions will generally be called on a hwbinder thread, but
Huihong Luo791bef92023-09-19 21:18:45 -070074// when first registering the callback the onComposerHalHotplugEvent() function
75// will immediately be called on the thread calling registerCallback().
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070076struct ComposerCallback {
Huihong Luo791bef92023-09-19 21:18:45 -070077 virtual void onComposerHalHotplugEvent(hal::HWDisplayId, DisplayHotplugEvent) = 0;
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070078 virtual void onComposerHalRefresh(hal::HWDisplayId) = 0;
Dominik Laskowskidc2bb802022-09-28 16:02:59 -040079 virtual void onComposerHalVsync(hal::HWDisplayId, nsecs_t timestamp,
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070080 std::optional<hal::VsyncPeriodNanos>) = 0;
81 virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId,
82 const hal::VsyncPeriodChangeTimeline&) = 0;
83 virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0;
Yichi Chen3401b562022-01-17 15:42:35 +080084 virtual void onComposerHalVsyncIdle(hal::HWDisplayId) = 0;
ramindani12bfe6b2023-02-03 13:29:19 -080085 virtual void onRefreshRateChangedDebug(const RefreshRateChangedDebugData&) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070086
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070087protected:
88 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070089};
Dan Stoza651bf312015-10-23 17:03:17 -070090
Peiyong Line9d809e2020-04-14 13:10:48 -070091// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080092class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070093public:
Ana Krulec4593b692019-01-11 22:07:25 -080094 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070095
Peiyong Line9d809e2020-04-14 13:10:48 -070096 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080097 virtual bool isConnected() const = 0;
Florian Mayercffc3792022-03-01 23:50:09 +000098 virtual void setConnected(bool connected) = 0; // For use by HWComposer only
Leon Scroggins III5967aec2021-12-29 11:14:22 -050099 virtual bool hasCapability(
100 aidl::android::hardware::graphics::composer3::DisplayCapability) const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -0700101 virtual bool isVsyncPeriodSwitchSupported() const = 0;
ramindani32cf0602022-03-02 02:30:29 +0000102 virtual bool hasDisplayIdleTimerCapability() const = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -0700103 virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0;
Dan Stoza651bf312015-10-23 17:03:17 -0700104
ramindani86d3d982022-03-16 20:57:42 +0000105 [[nodiscard]] virtual hal::Error acceptChanges() = 0;
106 [[nodiscard]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error>
Lloyd Piquea516c002021-05-07 14:36:58 -0700107 createLayer() = 0;
ramindani86d3d982022-03-16 20:57:42 +0000108 [[nodiscard]] virtual hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500109 std::unordered_map<Layer*, aidl::android::hardware::graphics::composer3::Composition>*
110 outTypes) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000111 [[nodiscard]] virtual hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +0800112 // Returns a bitmask which contains HdrMetadata::Type::*.
ramindani86d3d982022-03-16 20:57:42 +0000113 [[nodiscard]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
114 [[nodiscard]] virtual hal::Error getRenderIntents(
Peiyong Line9d809e2020-04-14 13:10:48 -0700115 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000116 [[nodiscard]] virtual hal::Error getDataspaceSaturationMatrix(hal::Dataspace dataspace,
117 android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800118
ramindani86d3d982022-03-16 20:57:42 +0000119 [[nodiscard]] virtual hal::Error getName(std::string* outName) const = 0;
120 [[nodiscard]] virtual hal::Error getRequests(
Peiyong Line9d809e2020-04-14 13:10:48 -0700121 hal::DisplayRequest* outDisplayRequests,
122 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000123 [[nodiscard]] virtual hal::Error getConnectionType(ui::DisplayConnectionType*) const = 0;
124 [[nodiscard]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
125 [[nodiscard]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800126 android::HdrCapabilities* outCapabilities) const = 0;
Sally Qi0cbd08b2022-08-17 12:12:28 -0700127 [[nodiscard]] virtual hal::Error getOverlaySupport(
128 aidl::android::hardware::graphics::composer3::OverlayProperties* outProperties)
129 const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000130 [[nodiscard]] virtual hal::Error getDisplayedContentSamplingAttributes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700131 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800132 uint8_t* outComponentMask) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000133 [[nodiscard]] virtual hal::Error setDisplayContentSamplingEnabled(bool enabled,
134 uint8_t componentMask,
135 uint64_t maxFrames) const = 0;
136 [[nodiscard]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800137 uint64_t maxFrames, uint64_t timestamp,
138 android::DisplayedFrameStats* outStats) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000139 [[nodiscard]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800140 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000141 [[nodiscard]] virtual hal::Error present(android::sp<android::Fence>* outPresentFence) = 0;
142 [[nodiscard]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800143 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700144 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000145 [[nodiscard]] virtual hal::Error setColorMode(hal::ColorMode mode,
146 hal::RenderIntent renderIntent) = 0;
147 [[nodiscard]] virtual hal::Error setColorTransform(const android::mat4& matrix) = 0;
148 [[nodiscard]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800149 const android::sp<android::GraphicBuffer>& buffer,
150 const android::sp<android::Fence>& releaseFence) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000151 [[nodiscard]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
152 [[nodiscard]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
ramindani09acbb82023-11-03 09:02:38 -0700153 [[nodiscard]] virtual hal::Error validate(nsecs_t expectedPresentTime, int32_t frameIntervalNs,
154 uint32_t* outNumTypes, uint32_t* outNumRequests) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000155 [[nodiscard]] virtual hal::Error presentOrValidate(nsecs_t expectedPresentTime,
ramindani4aac32c2023-10-30 14:13:30 -0700156 int32_t frameIntervalNs,
ramindani86d3d982022-03-16 20:57:42 +0000157 uint32_t* outNumTypes,
158 uint32_t* outNumRequests,
159 android::sp<android::Fence>* outPresentFence,
160 uint32_t* state) = 0;
Dominik Laskowskib17c6212022-05-09 09:36:19 -0700161 [[nodiscard]] virtual ftl::Future<hal::Error> setDisplayBrightness(
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000162 float brightness, float brightnessNits,
163 const Hwc2::Composer::DisplayBrightnessOptions& options) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000164 [[nodiscard]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100165 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700166 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000167 [[nodiscard]] virtual hal::Error setBootDisplayConfig(hal::HWConfigId configId) = 0;
168 [[nodiscard]] virtual hal::Error clearBootDisplayConfig() = 0;
169 [[nodiscard]] virtual hal::Error getPreferredBootDisplayConfig(
Kriti Dang7defaf32021-11-15 11:55:43 +0100170 hal::HWConfigId* configId) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000171 [[nodiscard]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
172 [[nodiscard]] virtual hal::Error getSupportedContentTypes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700173 std::vector<hal::ContentType>*) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000174 [[nodiscard]] virtual hal::Error setContentType(hal::ContentType) = 0;
175 [[nodiscard]] virtual hal::Error getClientTargetProperty(
Alec Mouri30835f22022-03-18 00:58:26 +0000176 aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness*
177 outClientTargetProperty) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000178 [[nodiscard]] virtual hal::Error getDisplayDecorationSupport(
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500179 std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
180 support) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000181 [[nodiscard]] virtual hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) = 0;
182 [[nodiscard]] virtual hal::Error getPhysicalDisplayOrientation(
ramindani06e518e2022-03-14 18:47:53 +0000183 Hwc2::AidlTransform* outTransform) const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800184};
185
186namespace impl {
187
Lloyd Piquea516c002021-05-07 14:36:58 -0700188class Layer;
189
Ana Krulec4593b692019-01-11 22:07:25 -0800190class Display : public HWC2::Display {
191public:
Ady Abrahamde549d42022-01-26 19:19:17 -0800192 Display(android::Hwc2::Composer&,
193 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&,
194 hal::HWDisplayId, hal::DisplayType);
Ana Krulec4593b692019-01-11 22:07:25 -0800195 ~Display() override;
196
197 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700198 hal::Error acceptChanges() override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700199 base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700200 hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500201 std::unordered_map<HWC2::Layer*,
202 aidl::android::hardware::graphics::composer3::Composition>* outTypes)
203 override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700204 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800205 // Returns a bitmask which contains HdrMetadata::Type::*.
206 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700207 hal::Error getRenderIntents(hal::ColorMode colorMode,
208 std::vector<hal::RenderIntent>* outRenderIntents) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200209 hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700210
Peiyong Line9d809e2020-04-14 13:10:48 -0700211 hal::Error getName(std::string* outName) const override;
212 hal::Error getRequests(
213 hal::DisplayRequest* outDisplayRequests,
Lloyd Piquea516c002021-05-07 14:36:58 -0700214 std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override;
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100215 hal::Error getConnectionType(ui::DisplayConnectionType*) const override;
Ady Abraham27fbcc72021-09-20 14:54:57 -0700216 hal::Error supportsDoze(bool* outSupport) const override EXCLUDES(mDisplayCapabilitiesMutex);
Peiyong Line9d809e2020-04-14 13:10:48 -0700217 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
Sally Qi0cbd08b2022-08-17 12:12:28 -0700218 hal::Error getOverlaySupport(aidl::android::hardware::graphics::composer3::OverlayProperties*
219 outProperties) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700220 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
221 hal::Dataspace* outDataspace,
222 uint8_t* outComponentMask) const override;
223 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
224 uint64_t maxFrames) const override;
225 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
226 android::DisplayedFrameStats* outStats) const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700227 hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>*
228 outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700229 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700230 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
231 const android::sp<android::Fence>& acquireFence,
232 hal::Dataspace dataspace) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200233 hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
Ady Abrahamdc011a92021-12-21 14:06:44 -0800234 hal::Error setColorTransform(const android::mat4& matrix) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200235 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700236 const android::sp<android::Fence>& releaseFence) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200237 hal::Error setPowerMode(hal::PowerMode) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700238 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
ramindani09acbb82023-11-03 09:02:38 -0700239 hal::Error validate(nsecs_t expectedPresentTime, int32_t frameIntervalNs, uint32_t* outNumTypes,
Ady Abraham43065bd2021-12-10 17:22:15 -0800240 uint32_t* outNumRequests) override;
ramindani4aac32c2023-10-30 14:13:30 -0700241 hal::Error presentOrValidate(nsecs_t expectedPresentTime, int32_t frameIntervalNs,
242 uint32_t* outNumTypes, uint32_t* outNumRequests,
Peiyong Line9d809e2020-04-14 13:10:48 -0700243 android::sp<android::Fence>* outPresentFence,
244 uint32_t* state) override;
Dominik Laskowskib17c6212022-05-09 09:36:19 -0700245 ftl::Future<hal::Error> setDisplayBrightness(
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000246 float brightness, float brightnessNits,
247 const Hwc2::Composer::DisplayBrightnessOptions& options) override;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100248 hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId,
249 const hal::VsyncPeriodChangeConstraints& constraints,
250 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Kriti Dang7defaf32021-11-15 11:55:43 +0100251 hal::Error setBootDisplayConfig(hal::HWConfigId configId) override;
252 hal::Error clearBootDisplayConfig() override;
253 hal::Error getPreferredBootDisplayConfig(hal::HWConfigId* configId) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700254 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700255 hal::Error getSupportedContentTypes(
256 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700257 hal::Error setContentType(hal::ContentType) override;
Alec Mouri30835f22022-03-18 00:58:26 +0000258 hal::Error getClientTargetProperty(
259 aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness*
260 outClientTargetProperty) override;
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500261 hal::Error getDisplayDecorationSupport(
262 std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
263 support) override;
ramindani32cf0602022-03-02 02:30:29 +0000264 hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700265
Dan Stoza651bf312015-10-23 17:03:17 -0700266 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700267 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800268 bool isConnected() const override { return mIsConnected; }
Florian Mayercffc3792022-03-01 23:50:09 +0000269 void setConnected(bool connected) override;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500270 bool hasCapability(aidl::android::hardware::graphics::composer3::DisplayCapability)
271 const override EXCLUDES(mDisplayCapabilitiesMutex);
Lloyd Piquea516c002021-05-07 14:36:58 -0700272 bool isVsyncPeriodSwitchSupported() const override;
ramindani32cf0602022-03-02 02:30:29 +0000273 bool hasDisplayIdleTimerCapability() const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700274 void onLayerDestroyed(hal::HWLayerId layerId) override;
ramindani06e518e2022-03-14 18:47:53 +0000275 hal::Error getPhysicalDisplayOrientation(Hwc2::AidlTransform* outTransform) const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700276
277private:
Dan Stoza651bf312015-10-23 17:03:17 -0700278
Dan Stoza651bf312015-10-23 17:03:17 -0700279 // This may fail (and return a null pointer) if no layer with this ID exists
280 // on this display
Lloyd Piquea516c002021-05-07 14:36:58 -0700281 std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700282
Lloyd Piquebc792092018-01-17 11:52:30 -0800283 friend android::TestableSurfaceFlinger;
284
Dan Stoza651bf312015-10-23 17:03:17 -0700285 // Member variables
286
Florian Mayercffc3792022-03-01 23:50:09 +0000287 // These are references to data owned by HWComposer, which will outlive
Steven Thomas94e35b92017-07-26 18:48:28 -0700288 // this HWC2::Display, so these references are guaranteed to be valid for
289 // the lifetime of this object.
290 android::Hwc2::Composer& mComposer;
Ady Abrahamde549d42022-01-26 19:19:17 -0800291 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
292 mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700293
Peiyong Line9d809e2020-04-14 13:10:48 -0700294 const hal::HWDisplayId mId;
295 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800296 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700297
Lloyd Piquea516c002021-05-07 14:36:58 -0700298 using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>;
299 Layers mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700300
Ady Abraham27fbcc72021-09-20 14:54:57 -0700301 mutable std::mutex mDisplayCapabilitiesMutex;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700302 std::once_flag mDisplayCapabilityQueryFlag;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500303 std::optional<
304 std::unordered_set<aidl::android::hardware::graphics::composer3::DisplayCapability>>
305 mDisplayCapabilities GUARDED_BY(mDisplayCapabilitiesMutex);
Dan Stoza651bf312015-10-23 17:03:17 -0700306};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800307
Ana Krulec4593b692019-01-11 22:07:25 -0800308} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700309
Lloyd Pique35d58242018-12-18 16:33:25 -0800310class Layer {
311public:
312 virtual ~Layer();
313
Peiyong Line9d809e2020-04-14 13:10:48 -0700314 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800315
ramindani86d3d982022-03-16 20:57:42 +0000316 [[nodiscard]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
317 [[nodiscard]] virtual hal::Error setBuffer(uint32_t slot,
318 const android::sp<android::GraphicBuffer>& buffer,
319 const android::sp<android::Fence>& acquireFence) = 0;
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700320 [[nodiscard]] virtual hal::Error setBufferSlotsToClear(
321 const std::vector<uint32_t>& slotsToClear, uint32_t activeBufferSlot) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000322 [[nodiscard]] virtual hal::Error setSurfaceDamage(const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800323
ramindani86d3d982022-03-16 20:57:42 +0000324 [[nodiscard]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
325 [[nodiscard]] virtual hal::Error setColor(
Ady Abraham6e60b142022-01-06 18:10:35 -0800326 aidl::android::hardware::graphics::composer3::Color color) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000327 [[nodiscard]] virtual hal::Error setCompositionType(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500328 aidl::android::hardware::graphics::composer3::Composition type) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000329 [[nodiscard]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
330 [[nodiscard]] virtual hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
331 const android::HdrMetadata& metadata) = 0;
332 [[nodiscard]] virtual hal::Error setDisplayFrame(const android::Rect& frame) = 0;
333 [[nodiscard]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
334 [[nodiscard]] virtual hal::Error setSidebandStream(const native_handle_t* stream) = 0;
335 [[nodiscard]] virtual hal::Error setSourceCrop(const android::FloatRect& crop) = 0;
336 [[nodiscard]] virtual hal::Error setTransform(hal::Transform transform) = 0;
337 [[nodiscard]] virtual hal::Error setVisibleRegion(const android::Region& region) = 0;
338 [[nodiscard]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800339
340 // Composer HAL 2.3
ramindani86d3d982022-03-16 20:57:42 +0000341 [[nodiscard]] virtual hal::Error setColorTransform(const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800342
343 // Composer HAL 2.4
ramindani86d3d982022-03-16 20:57:42 +0000344 [[nodiscard]] virtual hal::Error setLayerGenericMetadata(const std::string& name,
345 bool mandatory,
346 const std::vector<uint8_t>& value) = 0;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700347
348 // AIDL HAL
ramindani86d3d982022-03-16 20:57:42 +0000349 [[nodiscard]] virtual hal::Error setBrightness(float brightness) = 0;
350 [[nodiscard]] virtual hal::Error setBlockingRegion(const android::Region& region) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800351};
352
353namespace impl {
354
Peiyong Line9d809e2020-04-14 13:10:48 -0700355// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800356
357class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700358public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700359 Layer(android::Hwc2::Composer& composer,
Ady Abrahamde549d42022-01-26 19:19:17 -0800360 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
361 capabilities,
362 HWC2::Display& display, hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800363 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700364
Lloyd Piquea516c002021-05-07 14:36:58 -0700365 void onOwningDisplayDestroyed();
366
Peiyong Line9d809e2020-04-14 13:10:48 -0700367 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700368
Peiyong Line9d809e2020-04-14 13:10:48 -0700369 hal::Error setCursorPosition(int32_t x, int32_t y) override;
370 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
371 const android::sp<android::Fence>& acquireFence) override;
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700372 hal::Error setBufferSlotsToClear(const std::vector<uint32_t>& slotsToClear,
373 uint32_t activeBufferSlot) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700374 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700375
Peiyong Line9d809e2020-04-14 13:10:48 -0700376 hal::Error setBlendMode(hal::BlendMode mode) override;
Ady Abraham6e60b142022-01-06 18:10:35 -0800377 hal::Error setColor(aidl::android::hardware::graphics::composer3::Color color) override;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500378 hal::Error setCompositionType(
379 aidl::android::hardware::graphics::composer3::Composition type) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700380 hal::Error setDataspace(hal::Dataspace dataspace) override;
381 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
382 const android::HdrMetadata& metadata) override;
383 hal::Error setDisplayFrame(const android::Rect& frame) override;
384 hal::Error setPlaneAlpha(float alpha) override;
385 hal::Error setSidebandStream(const native_handle_t* stream) override;
386 hal::Error setSourceCrop(const android::FloatRect& crop) override;
387 hal::Error setTransform(hal::Transform transform) override;
388 hal::Error setVisibleRegion(const android::Region& region) override;
389 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700390
Peiyong Lin698147a2018-09-14 13:27:18 -0700391 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700392 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700393
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800394 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700395 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
396 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800397
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700398 // AIDL HAL
Alec Mouri6da0e272022-02-07 12:45:57 -0800399 hal::Error setBrightness(float brightness) override;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500400 hal::Error setBlockingRegion(const android::Region& region) override;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700401
Dan Stoza651bf312015-10-23 17:03:17 -0700402private:
Florian Mayercffc3792022-03-01 23:50:09 +0000403 // These are references to data owned by HWComposer, which will outlive
Steven Thomas94e35b92017-07-26 18:48:28 -0700404 // this HWC2::Layer, so these references are guaranteed to be valid for
405 // the lifetime of this object.
406 android::Hwc2::Composer& mComposer;
Ady Abrahamde549d42022-01-26 19:19:17 -0800407 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
408 mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700409
Lloyd Piquea516c002021-05-07 14:36:58 -0700410 HWC2::Display* mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700411 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800412
413 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
414 // multiple times.
415 android::Region mVisibleRegion = android::Region::INVALID_REGION;
416 android::Region mDamageRegion = android::Region::INVALID_REGION;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500417 android::Region mBlockingRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700418 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700419 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700420 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800421 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700422};
423
Lloyd Pique35d58242018-12-18 16:33:25 -0800424} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700425} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700426} // namespace android