blob: 06fa89a84327a80ac27f36fdfa8a38b6cbe4192d [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>
Ady Abrahamde549d42022-01-26 19:19:17 -080041#include <aidl/android/hardware/graphics/composer3/Capability.h>
Alec Mouri30835f22022-03-18 00:58:26 +000042#include <aidl/android/hardware/graphics/composer3/ClientTargetPropertyWithBrightness.h>
Ady Abraham6e60b142022-01-06 18:10:35 -080043#include <aidl/android/hardware/graphics/composer3/Color.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050044#include <aidl/android/hardware/graphics/composer3/Composition.h>
Leon Scroggins III5967aec2021-12-29 11:14:22 -050045#include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
Sally Qi0cbd08b2022-08-17 12:12:28 -070046#include <aidl/android/hardware/graphics/composer3/OverlayProperties.h>
ramindani12bfe6b2023-02-03 13:29:19 -080047#include <aidl/android/hardware/graphics/composer3/RefreshRateChangedDebugData.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050048
Dan Stoza651bf312015-10-23 17:03:17 -070049namespace android {
Lloyd Piquebc792092018-01-17 11:52:30 -080050
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070051class Fence;
52class FloatRect;
53class GraphicBuffer;
54class TestableSurfaceFlinger;
55struct DisplayedFrameStats;
56
57namespace Hwc2 {
58class Composer;
59} // namespace Hwc2
Dan Stoza651bf312015-10-23 17:03:17 -070060
61namespace HWC2 {
62
Dan Stoza651bf312015-10-23 17:03:17 -070063class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070064
65namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070066
ramindani12bfe6b2023-02-03 13:29:19 -080067using aidl::android::hardware::graphics::composer3::RefreshRateChangedDebugData;
68
Steven Thomas94e35b92017-07-26 18:48:28 -070069// Implement this interface to receive hardware composer events.
70//
71// These callback functions will generally be called on a hwbinder thread, but
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070072// when first registering the callback the onComposerHalHotplug() function will
Steven Thomas94e35b92017-07-26 18:48:28 -070073// immediately be called on the thread calling registerCallback().
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070074struct ComposerCallback {
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070075 virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0;
76 virtual void onComposerHalRefresh(hal::HWDisplayId) = 0;
Dominik Laskowskidc2bb802022-09-28 16:02:59 -040077 virtual void onComposerHalVsync(hal::HWDisplayId, nsecs_t timestamp,
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070078 std::optional<hal::VsyncPeriodNanos>) = 0;
79 virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId,
80 const hal::VsyncPeriodChangeTimeline&) = 0;
81 virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0;
Yichi Chen3401b562022-01-17 15:42:35 +080082 virtual void onComposerHalVsyncIdle(hal::HWDisplayId) = 0;
ramindani12bfe6b2023-02-03 13:29:19 -080083 virtual void onRefreshRateChangedDebug(const RefreshRateChangedDebugData&) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070084
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070085protected:
86 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070087};
Dan Stoza651bf312015-10-23 17:03:17 -070088
Peiyong Line9d809e2020-04-14 13:10:48 -070089// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080090class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070091public:
Ana Krulec4593b692019-01-11 22:07:25 -080092 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070093
Peiyong Line9d809e2020-04-14 13:10:48 -070094 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080095 virtual bool isConnected() const = 0;
Florian Mayercffc3792022-03-01 23:50:09 +000096 virtual void setConnected(bool connected) = 0; // For use by HWComposer only
Leon Scroggins III5967aec2021-12-29 11:14:22 -050097 virtual bool hasCapability(
98 aidl::android::hardware::graphics::composer3::DisplayCapability) const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070099 virtual bool isVsyncPeriodSwitchSupported() const = 0;
ramindani32cf0602022-03-02 02:30:29 +0000100 virtual bool hasDisplayIdleTimerCapability() const = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -0700101 virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0;
Dan Stoza651bf312015-10-23 17:03:17 -0700102
ramindani86d3d982022-03-16 20:57:42 +0000103 [[nodiscard]] virtual hal::Error acceptChanges() = 0;
104 [[nodiscard]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error>
Lloyd Piquea516c002021-05-07 14:36:58 -0700105 createLayer() = 0;
ramindani86d3d982022-03-16 20:57:42 +0000106 [[nodiscard]] virtual hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500107 std::unordered_map<Layer*, aidl::android::hardware::graphics::composer3::Composition>*
108 outTypes) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000109 [[nodiscard]] virtual hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +0800110 // Returns a bitmask which contains HdrMetadata::Type::*.
ramindani86d3d982022-03-16 20:57:42 +0000111 [[nodiscard]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
112 [[nodiscard]] virtual hal::Error getRenderIntents(
Peiyong Line9d809e2020-04-14 13:10:48 -0700113 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000114 [[nodiscard]] virtual hal::Error getDataspaceSaturationMatrix(hal::Dataspace dataspace,
115 android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800116
ramindani86d3d982022-03-16 20:57:42 +0000117 [[nodiscard]] virtual hal::Error getName(std::string* outName) const = 0;
118 [[nodiscard]] virtual hal::Error getRequests(
Peiyong Line9d809e2020-04-14 13:10:48 -0700119 hal::DisplayRequest* outDisplayRequests,
120 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000121 [[nodiscard]] virtual hal::Error getConnectionType(ui::DisplayConnectionType*) const = 0;
122 [[nodiscard]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
123 [[nodiscard]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800124 android::HdrCapabilities* outCapabilities) const = 0;
Sally Qi0cbd08b2022-08-17 12:12:28 -0700125 [[nodiscard]] virtual hal::Error getOverlaySupport(
126 aidl::android::hardware::graphics::composer3::OverlayProperties* outProperties)
127 const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000128 [[nodiscard]] virtual hal::Error getDisplayedContentSamplingAttributes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700129 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800130 uint8_t* outComponentMask) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000131 [[nodiscard]] virtual hal::Error setDisplayContentSamplingEnabled(bool enabled,
132 uint8_t componentMask,
133 uint64_t maxFrames) const = 0;
134 [[nodiscard]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800135 uint64_t maxFrames, uint64_t timestamp,
136 android::DisplayedFrameStats* outStats) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000137 [[nodiscard]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800138 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000139 [[nodiscard]] virtual hal::Error present(android::sp<android::Fence>* outPresentFence) = 0;
140 [[nodiscard]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800141 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700142 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000143 [[nodiscard]] virtual hal::Error setColorMode(hal::ColorMode mode,
144 hal::RenderIntent renderIntent) = 0;
145 [[nodiscard]] virtual hal::Error setColorTransform(const android::mat4& matrix) = 0;
146 [[nodiscard]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800147 const android::sp<android::GraphicBuffer>& buffer,
148 const android::sp<android::Fence>& releaseFence) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000149 [[nodiscard]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
150 [[nodiscard]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
151 [[nodiscard]] virtual hal::Error validate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
152 uint32_t* outNumRequests) = 0;
153 [[nodiscard]] virtual hal::Error presentOrValidate(nsecs_t expectedPresentTime,
ramindani4aac32c2023-10-30 14:13:30 -0700154 int32_t frameIntervalNs,
ramindani86d3d982022-03-16 20:57:42 +0000155 uint32_t* outNumTypes,
156 uint32_t* outNumRequests,
157 android::sp<android::Fence>* outPresentFence,
158 uint32_t* state) = 0;
Dominik Laskowskib17c6212022-05-09 09:36:19 -0700159 [[nodiscard]] virtual ftl::Future<hal::Error> setDisplayBrightness(
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000160 float brightness, float brightnessNits,
161 const Hwc2::Composer::DisplayBrightnessOptions& options) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000162 [[nodiscard]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100163 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700164 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000165 [[nodiscard]] virtual hal::Error setBootDisplayConfig(hal::HWConfigId configId) = 0;
166 [[nodiscard]] virtual hal::Error clearBootDisplayConfig() = 0;
167 [[nodiscard]] virtual hal::Error getPreferredBootDisplayConfig(
Kriti Dang7defaf32021-11-15 11:55:43 +0100168 hal::HWConfigId* configId) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000169 [[nodiscard]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
170 [[nodiscard]] virtual hal::Error getSupportedContentTypes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700171 std::vector<hal::ContentType>*) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000172 [[nodiscard]] virtual hal::Error setContentType(hal::ContentType) = 0;
173 [[nodiscard]] virtual hal::Error getClientTargetProperty(
Alec Mouri30835f22022-03-18 00:58:26 +0000174 aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness*
175 outClientTargetProperty) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000176 [[nodiscard]] virtual hal::Error getDisplayDecorationSupport(
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500177 std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
178 support) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000179 [[nodiscard]] virtual hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) = 0;
180 [[nodiscard]] virtual hal::Error getPhysicalDisplayOrientation(
ramindani06e518e2022-03-14 18:47:53 +0000181 Hwc2::AidlTransform* outTransform) const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800182};
183
184namespace impl {
185
Lloyd Piquea516c002021-05-07 14:36:58 -0700186class Layer;
187
Ana Krulec4593b692019-01-11 22:07:25 -0800188class Display : public HWC2::Display {
189public:
Ady Abrahamde549d42022-01-26 19:19:17 -0800190 Display(android::Hwc2::Composer&,
191 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&,
192 hal::HWDisplayId, hal::DisplayType);
Ana Krulec4593b692019-01-11 22:07:25 -0800193 ~Display() override;
194
195 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700196 hal::Error acceptChanges() override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700197 base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700198 hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500199 std::unordered_map<HWC2::Layer*,
200 aidl::android::hardware::graphics::composer3::Composition>* outTypes)
201 override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700202 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800203 // Returns a bitmask which contains HdrMetadata::Type::*.
204 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700205 hal::Error getRenderIntents(hal::ColorMode colorMode,
206 std::vector<hal::RenderIntent>* outRenderIntents) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200207 hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700208
Peiyong Line9d809e2020-04-14 13:10:48 -0700209 hal::Error getName(std::string* outName) const override;
210 hal::Error getRequests(
211 hal::DisplayRequest* outDisplayRequests,
Lloyd Piquea516c002021-05-07 14:36:58 -0700212 std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override;
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100213 hal::Error getConnectionType(ui::DisplayConnectionType*) const override;
Ady Abraham27fbcc72021-09-20 14:54:57 -0700214 hal::Error supportsDoze(bool* outSupport) const override EXCLUDES(mDisplayCapabilitiesMutex);
Peiyong Line9d809e2020-04-14 13:10:48 -0700215 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
Sally Qi0cbd08b2022-08-17 12:12:28 -0700216 hal::Error getOverlaySupport(aidl::android::hardware::graphics::composer3::OverlayProperties*
217 outProperties) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700218 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
219 hal::Dataspace* outDataspace,
220 uint8_t* outComponentMask) const override;
221 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
222 uint64_t maxFrames) const override;
223 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
224 android::DisplayedFrameStats* outStats) const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700225 hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>*
226 outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700227 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700228 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
229 const android::sp<android::Fence>& acquireFence,
230 hal::Dataspace dataspace) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200231 hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
Ady Abrahamdc011a92021-12-21 14:06:44 -0800232 hal::Error setColorTransform(const android::mat4& matrix) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200233 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700234 const android::sp<android::Fence>& releaseFence) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200235 hal::Error setPowerMode(hal::PowerMode) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700236 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
Ady Abraham43065bd2021-12-10 17:22:15 -0800237 hal::Error validate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
238 uint32_t* outNumRequests) override;
ramindani4aac32c2023-10-30 14:13:30 -0700239 hal::Error presentOrValidate(nsecs_t expectedPresentTime, int32_t frameIntervalNs,
240 uint32_t* outNumTypes, uint32_t* outNumRequests,
Peiyong Line9d809e2020-04-14 13:10:48 -0700241 android::sp<android::Fence>* outPresentFence,
242 uint32_t* state) override;
Dominik Laskowskib17c6212022-05-09 09:36:19 -0700243 ftl::Future<hal::Error> setDisplayBrightness(
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000244 float brightness, float brightnessNits,
245 const Hwc2::Composer::DisplayBrightnessOptions& options) override;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100246 hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId,
247 const hal::VsyncPeriodChangeConstraints& constraints,
248 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Kriti Dang7defaf32021-11-15 11:55:43 +0100249 hal::Error setBootDisplayConfig(hal::HWConfigId configId) override;
250 hal::Error clearBootDisplayConfig() override;
251 hal::Error getPreferredBootDisplayConfig(hal::HWConfigId* configId) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700252 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700253 hal::Error getSupportedContentTypes(
254 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700255 hal::Error setContentType(hal::ContentType) override;
Alec Mouri30835f22022-03-18 00:58:26 +0000256 hal::Error getClientTargetProperty(
257 aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness*
258 outClientTargetProperty) override;
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500259 hal::Error getDisplayDecorationSupport(
260 std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
261 support) override;
ramindani32cf0602022-03-02 02:30:29 +0000262 hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700263
Dan Stoza651bf312015-10-23 17:03:17 -0700264 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700265 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800266 bool isConnected() const override { return mIsConnected; }
Florian Mayercffc3792022-03-01 23:50:09 +0000267 void setConnected(bool connected) override;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500268 bool hasCapability(aidl::android::hardware::graphics::composer3::DisplayCapability)
269 const override EXCLUDES(mDisplayCapabilitiesMutex);
Lloyd Piquea516c002021-05-07 14:36:58 -0700270 bool isVsyncPeriodSwitchSupported() const override;
ramindani32cf0602022-03-02 02:30:29 +0000271 bool hasDisplayIdleTimerCapability() const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700272 void onLayerDestroyed(hal::HWLayerId layerId) override;
ramindani06e518e2022-03-14 18:47:53 +0000273 hal::Error getPhysicalDisplayOrientation(Hwc2::AidlTransform* outTransform) const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700274
275private:
Dan Stoza651bf312015-10-23 17:03:17 -0700276
Dan Stoza651bf312015-10-23 17:03:17 -0700277 // This may fail (and return a null pointer) if no layer with this ID exists
278 // on this display
Lloyd Piquea516c002021-05-07 14:36:58 -0700279 std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700280
Lloyd Piquebc792092018-01-17 11:52:30 -0800281 friend android::TestableSurfaceFlinger;
282
Dan Stoza651bf312015-10-23 17:03:17 -0700283 // Member variables
284
Florian Mayercffc3792022-03-01 23:50:09 +0000285 // These are references to data owned by HWComposer, which will outlive
Steven Thomas94e35b92017-07-26 18:48:28 -0700286 // this HWC2::Display, so these references are guaranteed to be valid for
287 // the lifetime of this object.
288 android::Hwc2::Composer& mComposer;
Ady Abrahamde549d42022-01-26 19:19:17 -0800289 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
290 mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700291
Peiyong Line9d809e2020-04-14 13:10:48 -0700292 const hal::HWDisplayId mId;
293 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800294 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700295
Lloyd Piquea516c002021-05-07 14:36:58 -0700296 using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>;
297 Layers mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700298
Ady Abraham27fbcc72021-09-20 14:54:57 -0700299 mutable std::mutex mDisplayCapabilitiesMutex;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700300 std::once_flag mDisplayCapabilityQueryFlag;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500301 std::optional<
302 std::unordered_set<aidl::android::hardware::graphics::composer3::DisplayCapability>>
303 mDisplayCapabilities GUARDED_BY(mDisplayCapabilitiesMutex);
Dan Stoza651bf312015-10-23 17:03:17 -0700304};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800305
Ana Krulec4593b692019-01-11 22:07:25 -0800306} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700307
Lloyd Pique35d58242018-12-18 16:33:25 -0800308class Layer {
309public:
310 virtual ~Layer();
311
Peiyong Line9d809e2020-04-14 13:10:48 -0700312 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800313
ramindani86d3d982022-03-16 20:57:42 +0000314 [[nodiscard]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
315 [[nodiscard]] virtual hal::Error setBuffer(uint32_t slot,
316 const android::sp<android::GraphicBuffer>& buffer,
317 const android::sp<android::Fence>& acquireFence) = 0;
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700318 [[nodiscard]] virtual hal::Error setBufferSlotsToClear(
319 const std::vector<uint32_t>& slotsToClear, uint32_t activeBufferSlot) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000320 [[nodiscard]] virtual hal::Error setSurfaceDamage(const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800321
ramindani86d3d982022-03-16 20:57:42 +0000322 [[nodiscard]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
323 [[nodiscard]] virtual hal::Error setColor(
Ady Abraham6e60b142022-01-06 18:10:35 -0800324 aidl::android::hardware::graphics::composer3::Color color) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000325 [[nodiscard]] virtual hal::Error setCompositionType(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500326 aidl::android::hardware::graphics::composer3::Composition type) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000327 [[nodiscard]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
328 [[nodiscard]] virtual hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
329 const android::HdrMetadata& metadata) = 0;
330 [[nodiscard]] virtual hal::Error setDisplayFrame(const android::Rect& frame) = 0;
331 [[nodiscard]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
332 [[nodiscard]] virtual hal::Error setSidebandStream(const native_handle_t* stream) = 0;
333 [[nodiscard]] virtual hal::Error setSourceCrop(const android::FloatRect& crop) = 0;
334 [[nodiscard]] virtual hal::Error setTransform(hal::Transform transform) = 0;
335 [[nodiscard]] virtual hal::Error setVisibleRegion(const android::Region& region) = 0;
336 [[nodiscard]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800337
338 // Composer HAL 2.3
ramindani86d3d982022-03-16 20:57:42 +0000339 [[nodiscard]] virtual hal::Error setColorTransform(const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800340
341 // Composer HAL 2.4
ramindani86d3d982022-03-16 20:57:42 +0000342 [[nodiscard]] virtual hal::Error setLayerGenericMetadata(const std::string& name,
343 bool mandatory,
344 const std::vector<uint8_t>& value) = 0;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700345
346 // AIDL HAL
ramindani86d3d982022-03-16 20:57:42 +0000347 [[nodiscard]] virtual hal::Error setBrightness(float brightness) = 0;
348 [[nodiscard]] virtual hal::Error setBlockingRegion(const android::Region& region) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800349};
350
351namespace impl {
352
Peiyong Line9d809e2020-04-14 13:10:48 -0700353// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800354
355class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700356public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700357 Layer(android::Hwc2::Composer& composer,
Ady Abrahamde549d42022-01-26 19:19:17 -0800358 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
359 capabilities,
360 HWC2::Display& display, hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800361 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700362
Lloyd Piquea516c002021-05-07 14:36:58 -0700363 void onOwningDisplayDestroyed();
364
Peiyong Line9d809e2020-04-14 13:10:48 -0700365 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700366
Peiyong Line9d809e2020-04-14 13:10:48 -0700367 hal::Error setCursorPosition(int32_t x, int32_t y) override;
368 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
369 const android::sp<android::Fence>& acquireFence) override;
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700370 hal::Error setBufferSlotsToClear(const std::vector<uint32_t>& slotsToClear,
371 uint32_t activeBufferSlot) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700372 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700373
Peiyong Line9d809e2020-04-14 13:10:48 -0700374 hal::Error setBlendMode(hal::BlendMode mode) override;
Ady Abraham6e60b142022-01-06 18:10:35 -0800375 hal::Error setColor(aidl::android::hardware::graphics::composer3::Color color) override;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500376 hal::Error setCompositionType(
377 aidl::android::hardware::graphics::composer3::Composition type) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700378 hal::Error setDataspace(hal::Dataspace dataspace) override;
379 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
380 const android::HdrMetadata& metadata) override;
381 hal::Error setDisplayFrame(const android::Rect& frame) override;
382 hal::Error setPlaneAlpha(float alpha) override;
383 hal::Error setSidebandStream(const native_handle_t* stream) override;
384 hal::Error setSourceCrop(const android::FloatRect& crop) override;
385 hal::Error setTransform(hal::Transform transform) override;
386 hal::Error setVisibleRegion(const android::Region& region) override;
387 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700388
Peiyong Lin698147a2018-09-14 13:27:18 -0700389 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700390 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700391
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800392 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700393 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
394 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800395
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700396 // AIDL HAL
Alec Mouri6da0e272022-02-07 12:45:57 -0800397 hal::Error setBrightness(float brightness) override;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500398 hal::Error setBlockingRegion(const android::Region& region) override;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700399
Dan Stoza651bf312015-10-23 17:03:17 -0700400private:
Florian Mayercffc3792022-03-01 23:50:09 +0000401 // These are references to data owned by HWComposer, which will outlive
Steven Thomas94e35b92017-07-26 18:48:28 -0700402 // this HWC2::Layer, so these references are guaranteed to be valid for
403 // the lifetime of this object.
404 android::Hwc2::Composer& mComposer;
Ady Abrahamde549d42022-01-26 19:19:17 -0800405 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
406 mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700407
Lloyd Piquea516c002021-05-07 14:36:58 -0700408 HWC2::Display* mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700409 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800410
411 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
412 // multiple times.
413 android::Region mVisibleRegion = android::Region::INVALID_REGION;
414 android::Region mDamageRegion = android::Region::INVALID_REGION;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500415 android::Region mBlockingRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700416 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700417 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700418 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800419 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700420};
421
Lloyd Pique35d58242018-12-18 16:33:25 -0800422} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700423} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700424} // namespace android