blob: 91ded86bbe5e5ef0e013f882eb3678c59b07e18f [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>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050047
Dan Stoza651bf312015-10-23 17:03:17 -070048namespace android {
Lloyd Piquebc792092018-01-17 11:52:30 -080049
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070050class Fence;
51class FloatRect;
52class GraphicBuffer;
53class TestableSurfaceFlinger;
54struct DisplayedFrameStats;
55
56namespace Hwc2 {
57class Composer;
58} // namespace Hwc2
Dan Stoza651bf312015-10-23 17:03:17 -070059
60namespace HWC2 {
61
Dan Stoza651bf312015-10-23 17:03:17 -070062class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070063
64namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070065
Steven Thomas94e35b92017-07-26 18:48:28 -070066// Implement this interface to receive hardware composer events.
67//
68// These callback functions will generally be called on a hwbinder thread, but
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070069// when first registering the callback the onComposerHalHotplug() function will
Steven Thomas94e35b92017-07-26 18:48:28 -070070// immediately be called on the thread calling registerCallback().
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070071struct ComposerCallback {
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070072 virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0;
73 virtual void onComposerHalRefresh(hal::HWDisplayId) = 0;
74 virtual void onComposerHalVsync(hal::HWDisplayId, int64_t timestamp,
75 std::optional<hal::VsyncPeriodNanos>) = 0;
76 virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId,
77 const hal::VsyncPeriodChangeTimeline&) = 0;
78 virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0;
Yichi Chen3401b562022-01-17 15:42:35 +080079 virtual void onComposerHalVsyncIdle(hal::HWDisplayId) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070080
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070081protected:
82 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070083};
Dan Stoza651bf312015-10-23 17:03:17 -070084
Peiyong Line9d809e2020-04-14 13:10:48 -070085// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080086class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070087public:
Ana Krulec4593b692019-01-11 22:07:25 -080088 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070089
Peiyong Line9d809e2020-04-14 13:10:48 -070090 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080091 virtual bool isConnected() const = 0;
Florian Mayercffc3792022-03-01 23:50:09 +000092 virtual void setConnected(bool connected) = 0; // For use by HWComposer only
Leon Scroggins III5967aec2021-12-29 11:14:22 -050093 virtual bool hasCapability(
94 aidl::android::hardware::graphics::composer3::DisplayCapability) const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070095 virtual bool isVsyncPeriodSwitchSupported() const = 0;
ramindani32cf0602022-03-02 02:30:29 +000096 virtual bool hasDisplayIdleTimerCapability() const = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070097 virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0;
Dan Stoza651bf312015-10-23 17:03:17 -070098
ramindani86d3d982022-03-16 20:57:42 +000099 [[nodiscard]] virtual hal::Error acceptChanges() = 0;
100 [[nodiscard]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error>
Lloyd Piquea516c002021-05-07 14:36:58 -0700101 createLayer() = 0;
ramindani86d3d982022-03-16 20:57:42 +0000102 [[nodiscard]] virtual hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500103 std::unordered_map<Layer*, aidl::android::hardware::graphics::composer3::Composition>*
104 outTypes) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000105 [[nodiscard]] virtual hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +0800106 // Returns a bitmask which contains HdrMetadata::Type::*.
ramindani86d3d982022-03-16 20:57:42 +0000107 [[nodiscard]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
108 [[nodiscard]] virtual hal::Error getRenderIntents(
Peiyong Line9d809e2020-04-14 13:10:48 -0700109 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000110 [[nodiscard]] virtual hal::Error getDataspaceSaturationMatrix(hal::Dataspace dataspace,
111 android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800112
ramindani86d3d982022-03-16 20:57:42 +0000113 [[nodiscard]] virtual hal::Error getName(std::string* outName) const = 0;
114 [[nodiscard]] virtual hal::Error getRequests(
Peiyong Line9d809e2020-04-14 13:10:48 -0700115 hal::DisplayRequest* outDisplayRequests,
116 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000117 [[nodiscard]] virtual hal::Error getConnectionType(ui::DisplayConnectionType*) const = 0;
118 [[nodiscard]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
119 [[nodiscard]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800120 android::HdrCapabilities* outCapabilities) const = 0;
Sally Qi0cbd08b2022-08-17 12:12:28 -0700121 [[nodiscard]] virtual hal::Error getOverlaySupport(
122 aidl::android::hardware::graphics::composer3::OverlayProperties* outProperties)
123 const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000124 [[nodiscard]] virtual hal::Error getDisplayedContentSamplingAttributes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700125 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800126 uint8_t* outComponentMask) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000127 [[nodiscard]] virtual hal::Error setDisplayContentSamplingEnabled(bool enabled,
128 uint8_t componentMask,
129 uint64_t maxFrames) const = 0;
130 [[nodiscard]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800131 uint64_t maxFrames, uint64_t timestamp,
132 android::DisplayedFrameStats* outStats) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000133 [[nodiscard]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800134 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000135 [[nodiscard]] virtual hal::Error present(android::sp<android::Fence>* outPresentFence) = 0;
136 [[nodiscard]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800137 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700138 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000139 [[nodiscard]] virtual hal::Error setColorMode(hal::ColorMode mode,
140 hal::RenderIntent renderIntent) = 0;
141 [[nodiscard]] virtual hal::Error setColorTransform(const android::mat4& matrix) = 0;
142 [[nodiscard]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800143 const android::sp<android::GraphicBuffer>& buffer,
144 const android::sp<android::Fence>& releaseFence) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000145 [[nodiscard]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
146 [[nodiscard]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
147 [[nodiscard]] virtual hal::Error validate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
148 uint32_t* outNumRequests) = 0;
149 [[nodiscard]] virtual hal::Error presentOrValidate(nsecs_t expectedPresentTime,
150 uint32_t* outNumTypes,
151 uint32_t* outNumRequests,
152 android::sp<android::Fence>* outPresentFence,
153 uint32_t* state) = 0;
Dominik Laskowskib17c6212022-05-09 09:36:19 -0700154 [[nodiscard]] virtual ftl::Future<hal::Error> setDisplayBrightness(
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000155 float brightness, float brightnessNits,
156 const Hwc2::Composer::DisplayBrightnessOptions& options) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000157 [[nodiscard]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100158 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700159 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000160 [[nodiscard]] virtual hal::Error setBootDisplayConfig(hal::HWConfigId configId) = 0;
161 [[nodiscard]] virtual hal::Error clearBootDisplayConfig() = 0;
162 [[nodiscard]] virtual hal::Error getPreferredBootDisplayConfig(
Kriti Dang7defaf32021-11-15 11:55:43 +0100163 hal::HWConfigId* configId) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000164 [[nodiscard]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
165 [[nodiscard]] virtual hal::Error getSupportedContentTypes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700166 std::vector<hal::ContentType>*) const = 0;
ramindani86d3d982022-03-16 20:57:42 +0000167 [[nodiscard]] virtual hal::Error setContentType(hal::ContentType) = 0;
168 [[nodiscard]] virtual hal::Error getClientTargetProperty(
Alec Mouri30835f22022-03-18 00:58:26 +0000169 aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness*
170 outClientTargetProperty) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000171 [[nodiscard]] virtual hal::Error getDisplayDecorationSupport(
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500172 std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
173 support) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000174 [[nodiscard]] virtual hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) = 0;
175 [[nodiscard]] virtual hal::Error getPhysicalDisplayOrientation(
ramindani06e518e2022-03-14 18:47:53 +0000176 Hwc2::AidlTransform* outTransform) const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800177};
178
179namespace impl {
180
Lloyd Piquea516c002021-05-07 14:36:58 -0700181class Layer;
182
Ana Krulec4593b692019-01-11 22:07:25 -0800183class Display : public HWC2::Display {
184public:
Ady Abrahamde549d42022-01-26 19:19:17 -0800185 Display(android::Hwc2::Composer&,
186 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&,
187 hal::HWDisplayId, hal::DisplayType);
Ana Krulec4593b692019-01-11 22:07:25 -0800188 ~Display() override;
189
190 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700191 hal::Error acceptChanges() override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700192 base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700193 hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500194 std::unordered_map<HWC2::Layer*,
195 aidl::android::hardware::graphics::composer3::Composition>* outTypes)
196 override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700197 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800198 // Returns a bitmask which contains HdrMetadata::Type::*.
199 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700200 hal::Error getRenderIntents(hal::ColorMode colorMode,
201 std::vector<hal::RenderIntent>* outRenderIntents) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200202 hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700203
Peiyong Line9d809e2020-04-14 13:10:48 -0700204 hal::Error getName(std::string* outName) const override;
205 hal::Error getRequests(
206 hal::DisplayRequest* outDisplayRequests,
Lloyd Piquea516c002021-05-07 14:36:58 -0700207 std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override;
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100208 hal::Error getConnectionType(ui::DisplayConnectionType*) const override;
Ady Abraham27fbcc72021-09-20 14:54:57 -0700209 hal::Error supportsDoze(bool* outSupport) const override EXCLUDES(mDisplayCapabilitiesMutex);
Peiyong Line9d809e2020-04-14 13:10:48 -0700210 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
Sally Qi0cbd08b2022-08-17 12:12:28 -0700211 hal::Error getOverlaySupport(aidl::android::hardware::graphics::composer3::OverlayProperties*
212 outProperties) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700213 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
214 hal::Dataspace* outDataspace,
215 uint8_t* outComponentMask) const override;
216 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
217 uint64_t maxFrames) const override;
218 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
219 android::DisplayedFrameStats* outStats) const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700220 hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>*
221 outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700222 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700223 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
224 const android::sp<android::Fence>& acquireFence,
225 hal::Dataspace dataspace) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200226 hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
Ady Abrahamdc011a92021-12-21 14:06:44 -0800227 hal::Error setColorTransform(const android::mat4& matrix) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200228 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700229 const android::sp<android::Fence>& releaseFence) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200230 hal::Error setPowerMode(hal::PowerMode) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700231 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
Ady Abraham43065bd2021-12-10 17:22:15 -0800232 hal::Error validate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
233 uint32_t* outNumRequests) override;
234 hal::Error presentOrValidate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
235 uint32_t* outNumRequests,
Peiyong Line9d809e2020-04-14 13:10:48 -0700236 android::sp<android::Fence>* outPresentFence,
237 uint32_t* state) override;
Dominik Laskowskib17c6212022-05-09 09:36:19 -0700238 ftl::Future<hal::Error> setDisplayBrightness(
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000239 float brightness, float brightnessNits,
240 const Hwc2::Composer::DisplayBrightnessOptions& options) override;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100241 hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId,
242 const hal::VsyncPeriodChangeConstraints& constraints,
243 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Kriti Dang7defaf32021-11-15 11:55:43 +0100244 hal::Error setBootDisplayConfig(hal::HWConfigId configId) override;
245 hal::Error clearBootDisplayConfig() override;
246 hal::Error getPreferredBootDisplayConfig(hal::HWConfigId* configId) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700247 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700248 hal::Error getSupportedContentTypes(
249 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700250 hal::Error setContentType(hal::ContentType) override;
Alec Mouri30835f22022-03-18 00:58:26 +0000251 hal::Error getClientTargetProperty(
252 aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness*
253 outClientTargetProperty) override;
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500254 hal::Error getDisplayDecorationSupport(
255 std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
256 support) override;
ramindani32cf0602022-03-02 02:30:29 +0000257 hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700258
Dan Stoza651bf312015-10-23 17:03:17 -0700259 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700260 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800261 bool isConnected() const override { return mIsConnected; }
Florian Mayercffc3792022-03-01 23:50:09 +0000262 void setConnected(bool connected) override;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500263 bool hasCapability(aidl::android::hardware::graphics::composer3::DisplayCapability)
264 const override EXCLUDES(mDisplayCapabilitiesMutex);
Lloyd Piquea516c002021-05-07 14:36:58 -0700265 bool isVsyncPeriodSwitchSupported() const override;
ramindani32cf0602022-03-02 02:30:29 +0000266 bool hasDisplayIdleTimerCapability() const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700267 void onLayerDestroyed(hal::HWLayerId layerId) override;
ramindani06e518e2022-03-14 18:47:53 +0000268 hal::Error getPhysicalDisplayOrientation(Hwc2::AidlTransform* outTransform) const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700269
270private:
Dan Stoza651bf312015-10-23 17:03:17 -0700271
Dan Stoza651bf312015-10-23 17:03:17 -0700272 // This may fail (and return a null pointer) if no layer with this ID exists
273 // on this display
Lloyd Piquea516c002021-05-07 14:36:58 -0700274 std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700275
Lloyd Piquebc792092018-01-17 11:52:30 -0800276 friend android::TestableSurfaceFlinger;
277
Dan Stoza651bf312015-10-23 17:03:17 -0700278 // Member variables
279
Florian Mayercffc3792022-03-01 23:50:09 +0000280 // These are references to data owned by HWComposer, which will outlive
Steven Thomas94e35b92017-07-26 18:48:28 -0700281 // this HWC2::Display, so these references are guaranteed to be valid for
282 // the lifetime of this object.
283 android::Hwc2::Composer& mComposer;
Ady Abrahamde549d42022-01-26 19:19:17 -0800284 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
285 mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700286
Peiyong Line9d809e2020-04-14 13:10:48 -0700287 const hal::HWDisplayId mId;
288 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800289 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700290
Lloyd Piquea516c002021-05-07 14:36:58 -0700291 using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>;
292 Layers mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700293
Ady Abraham27fbcc72021-09-20 14:54:57 -0700294 mutable std::mutex mDisplayCapabilitiesMutex;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700295 std::once_flag mDisplayCapabilityQueryFlag;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500296 std::optional<
297 std::unordered_set<aidl::android::hardware::graphics::composer3::DisplayCapability>>
298 mDisplayCapabilities GUARDED_BY(mDisplayCapabilitiesMutex);
Dan Stoza651bf312015-10-23 17:03:17 -0700299};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800300
Ana Krulec4593b692019-01-11 22:07:25 -0800301} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700302
Lloyd Pique35d58242018-12-18 16:33:25 -0800303class Layer {
304public:
305 virtual ~Layer();
306
Peiyong Line9d809e2020-04-14 13:10:48 -0700307 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800308
ramindani86d3d982022-03-16 20:57:42 +0000309 [[nodiscard]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
310 [[nodiscard]] virtual hal::Error setBuffer(uint32_t slot,
311 const android::sp<android::GraphicBuffer>& buffer,
312 const android::sp<android::Fence>& acquireFence) = 0;
313 [[nodiscard]] virtual hal::Error setSurfaceDamage(const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800314
ramindani86d3d982022-03-16 20:57:42 +0000315 [[nodiscard]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
316 [[nodiscard]] virtual hal::Error setColor(
Ady Abraham6e60b142022-01-06 18:10:35 -0800317 aidl::android::hardware::graphics::composer3::Color color) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000318 [[nodiscard]] virtual hal::Error setCompositionType(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500319 aidl::android::hardware::graphics::composer3::Composition type) = 0;
ramindani86d3d982022-03-16 20:57:42 +0000320 [[nodiscard]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
321 [[nodiscard]] virtual hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
322 const android::HdrMetadata& metadata) = 0;
323 [[nodiscard]] virtual hal::Error setDisplayFrame(const android::Rect& frame) = 0;
324 [[nodiscard]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
325 [[nodiscard]] virtual hal::Error setSidebandStream(const native_handle_t* stream) = 0;
326 [[nodiscard]] virtual hal::Error setSourceCrop(const android::FloatRect& crop) = 0;
327 [[nodiscard]] virtual hal::Error setTransform(hal::Transform transform) = 0;
328 [[nodiscard]] virtual hal::Error setVisibleRegion(const android::Region& region) = 0;
329 [[nodiscard]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800330
331 // Composer HAL 2.3
ramindani86d3d982022-03-16 20:57:42 +0000332 [[nodiscard]] virtual hal::Error setColorTransform(const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800333
334 // Composer HAL 2.4
ramindani86d3d982022-03-16 20:57:42 +0000335 [[nodiscard]] virtual hal::Error setLayerGenericMetadata(const std::string& name,
336 bool mandatory,
337 const std::vector<uint8_t>& value) = 0;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700338
339 // AIDL HAL
ramindani86d3d982022-03-16 20:57:42 +0000340 [[nodiscard]] virtual hal::Error setBrightness(float brightness) = 0;
341 [[nodiscard]] virtual hal::Error setBlockingRegion(const android::Region& region) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800342};
343
344namespace impl {
345
Peiyong Line9d809e2020-04-14 13:10:48 -0700346// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800347
348class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700349public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700350 Layer(android::Hwc2::Composer& composer,
Ady Abrahamde549d42022-01-26 19:19:17 -0800351 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
352 capabilities,
353 HWC2::Display& display, hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800354 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700355
Lloyd Piquea516c002021-05-07 14:36:58 -0700356 void onOwningDisplayDestroyed();
357
Peiyong Line9d809e2020-04-14 13:10:48 -0700358 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700359
Peiyong Line9d809e2020-04-14 13:10:48 -0700360 hal::Error setCursorPosition(int32_t x, int32_t y) override;
361 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
362 const android::sp<android::Fence>& acquireFence) override;
363 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700364
Peiyong Line9d809e2020-04-14 13:10:48 -0700365 hal::Error setBlendMode(hal::BlendMode mode) override;
Ady Abraham6e60b142022-01-06 18:10:35 -0800366 hal::Error setColor(aidl::android::hardware::graphics::composer3::Color color) override;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500367 hal::Error setCompositionType(
368 aidl::android::hardware::graphics::composer3::Composition type) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700369 hal::Error setDataspace(hal::Dataspace dataspace) override;
370 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
371 const android::HdrMetadata& metadata) override;
372 hal::Error setDisplayFrame(const android::Rect& frame) override;
373 hal::Error setPlaneAlpha(float alpha) override;
374 hal::Error setSidebandStream(const native_handle_t* stream) override;
375 hal::Error setSourceCrop(const android::FloatRect& crop) override;
376 hal::Error setTransform(hal::Transform transform) override;
377 hal::Error setVisibleRegion(const android::Region& region) override;
378 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700379
Peiyong Lin698147a2018-09-14 13:27:18 -0700380 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700381 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700382
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800383 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700384 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
385 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800386
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700387 // AIDL HAL
Alec Mouri6da0e272022-02-07 12:45:57 -0800388 hal::Error setBrightness(float brightness) override;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500389 hal::Error setBlockingRegion(const android::Region& region) override;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700390
Dan Stoza651bf312015-10-23 17:03:17 -0700391private:
Florian Mayercffc3792022-03-01 23:50:09 +0000392 // These are references to data owned by HWComposer, which will outlive
Steven Thomas94e35b92017-07-26 18:48:28 -0700393 // this HWC2::Layer, so these references are guaranteed to be valid for
394 // the lifetime of this object.
395 android::Hwc2::Composer& mComposer;
Ady Abrahamde549d42022-01-26 19:19:17 -0800396 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
397 mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700398
Lloyd Piquea516c002021-05-07 14:36:58 -0700399 HWC2::Display* mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700400 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800401
402 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
403 // multiple times.
404 android::Region mVisibleRegion = android::Region::INVALID_REGION;
405 android::Region mDamageRegion = android::Region::INVALID_REGION;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500406 android::Region mBlockingRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700407 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700408 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700409 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800410 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700411};
412
Lloyd Pique35d58242018-12-18 16:33:25 -0800413} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700414} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700415} // namespace android