blob: c03cede124f97ce646c890ee1d8ddb1458ec22bc [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>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070021#include <gui/HdrMetadata.h>
Mathias Agopian1d77b712017-02-17 15:46:13 -080022#include <math/mat4.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070023#include <ui/HdrCapabilities.h>
Yichi Chen8366f562019-03-25 19:44:06 +080024#include <ui/Region.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010025#include <ui/StaticDisplayInfo.h>
Dan Stoza651bf312015-10-23 17:03:17 -070026#include <utils/Log.h>
27#include <utils/StrongPointer.h>
28#include <utils/Timers.h>
29
30#include <functional>
Dominik Laskowski5690bde2020-04-23 19:04:22 -070031#include <future>
Dan Stoza651bf312015-10-23 17:03:17 -070032#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>
Ady Abraham6e60b142022-01-06 18:10:35 -080042#include <aidl/android/hardware/graphics/composer3/Color.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050043#include <aidl/android/hardware/graphics/composer3/Composition.h>
Leon Scroggins III5967aec2021-12-29 11:14:22 -050044#include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050045
Dan Stoza651bf312015-10-23 17:03:17 -070046namespace android {
Lloyd Piquebc792092018-01-17 11:52:30 -080047
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070048class Fence;
49class FloatRect;
50class GraphicBuffer;
51class TestableSurfaceFlinger;
52struct DisplayedFrameStats;
53
54namespace Hwc2 {
55class Composer;
56} // namespace Hwc2
Dan Stoza651bf312015-10-23 17:03:17 -070057
58namespace HWC2 {
59
Dan Stoza651bf312015-10-23 17:03:17 -070060class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070061
62namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070063
Steven Thomas94e35b92017-07-26 18:48:28 -070064// Implement this interface to receive hardware composer events.
65//
66// These callback functions will generally be called on a hwbinder thread, but
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070067// when first registering the callback the onComposerHalHotplug() function will
Steven Thomas94e35b92017-07-26 18:48:28 -070068// immediately be called on the thread calling registerCallback().
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070069struct ComposerCallback {
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070070 virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0;
71 virtual void onComposerHalRefresh(hal::HWDisplayId) = 0;
72 virtual void onComposerHalVsync(hal::HWDisplayId, int64_t timestamp,
73 std::optional<hal::VsyncPeriodNanos>) = 0;
74 virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId,
75 const hal::VsyncPeriodChangeTimeline&) = 0;
76 virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0;
Yichi Chen3401b562022-01-17 15:42:35 +080077 virtual void onComposerHalVsyncIdle(hal::HWDisplayId) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070078
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070079protected:
80 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070081};
Dan Stoza651bf312015-10-23 17:03:17 -070082
Peiyong Line9d809e2020-04-14 13:10:48 -070083// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080084class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070085public:
Ana Krulec4593b692019-01-11 22:07:25 -080086 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070087
Peiyong Line9d809e2020-04-14 13:10:48 -070088 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080089 virtual bool isConnected() const = 0;
90 virtual void setConnected(bool connected) = 0; // For use by Device only
Leon Scroggins III5967aec2021-12-29 11:14:22 -050091 virtual bool hasCapability(
92 aidl::android::hardware::graphics::composer3::DisplayCapability) const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070093 virtual bool isVsyncPeriodSwitchSupported() const = 0;
ramindani32cf0602022-03-02 02:30:29 +000094 virtual bool hasDisplayIdleTimerCapability() const = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070095 virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0;
Dan Stoza651bf312015-10-23 17:03:17 -070096
Peiyong Line9d809e2020-04-14 13:10:48 -070097 [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070098 [[clang::warn_unused_result]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error>
99 createLayer() = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700100 [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500101 std::unordered_map<Layer*, aidl::android::hardware::graphics::composer3::Composition>*
102 outTypes) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700103 [[clang::warn_unused_result]] virtual hal::Error getColorModes(
104 std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +0800105 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -0800106 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700107 [[clang::warn_unused_result]] virtual hal::Error getRenderIntents(
108 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
109 [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix(
110 hal::Dataspace dataspace, android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800111
Peiyong Line9d809e2020-04-14 13:10:48 -0700112 [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0;
113 [[clang::warn_unused_result]] virtual hal::Error getRequests(
114 hal::DisplayRequest* outDisplayRequests,
115 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
116 [[clang::warn_unused_result]] virtual hal::Error getConnectionType(
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100117 ui::DisplayConnectionType*) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700118 [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
119 [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800120 android::HdrCapabilities* outCapabilities) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700121 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes(
122 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800123 uint8_t* outComponentMask) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700124 [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled(
Ana Krulec4593b692019-01-11 22:07:25 -0800125 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700126 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800127 uint64_t maxFrames, uint64_t timestamp,
128 android::DisplayedFrameStats* outStats) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700129 [[clang::warn_unused_result]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800130 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700131 [[clang::warn_unused_result]] virtual hal::Error present(
Ana Krulec4593b692019-01-11 22:07:25 -0800132 android::sp<android::Fence>* outPresentFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700133 [[clang::warn_unused_result]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800134 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700135 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
136 [[clang::warn_unused_result]] virtual hal::Error setColorMode(
137 hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
138 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
Ady Abrahamdc011a92021-12-21 14:06:44 -0800139 const android::mat4& matrix) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700140 [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800141 const android::sp<android::GraphicBuffer>& buffer,
142 const android::sp<android::Fence>& releaseFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700143 [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
144 [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
Ady Abraham43065bd2021-12-10 17:22:15 -0800145 [[clang::warn_unused_result]] virtual hal::Error validate(nsecs_t expectedPresentTime,
146 uint32_t* outNumTypes,
Peiyong Line9d809e2020-04-14 13:10:48 -0700147 uint32_t* outNumRequests) = 0;
148 [[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
Ady Abraham43065bd2021-12-10 17:22:15 -0800149 nsecs_t expectedPresentTime, uint32_t* outNumTypes, uint32_t* outNumRequests,
Ana Krulec4593b692019-01-11 22:07:25 -0800150 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700151 [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
Alec Mouricdf16792021-12-10 13:16:06 -0800152 float brightness, const Hwc2::Composer::DisplayBrightnessOptions& options) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700153 [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100154 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700155 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Kriti Dang7defaf32021-11-15 11:55:43 +0100156 [[clang::warn_unused_result]] virtual hal::Error setBootDisplayConfig(
157 hal::HWConfigId configId) = 0;
158 [[clang::warn_unused_result]] virtual hal::Error clearBootDisplayConfig() = 0;
159 [[clang::warn_unused_result]] virtual hal::Error getPreferredBootDisplayConfig(
160 hal::HWConfigId* configId) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700161 [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700162 [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
163 std::vector<hal::ContentType>*) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700164 [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700165 [[clang::warn_unused_result]] virtual hal::Error getClientTargetProperty(
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700166 hal::ClientTargetProperty* outClientTargetProperty, float* outWhitePointNits) = 0;
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500167 [[clang::warn_unused_result]] virtual hal::Error getDisplayDecorationSupport(
168 std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
169 support) = 0;
ramindani32cf0602022-03-02 02:30:29 +0000170 [[clang::warn_unused_result]] virtual hal::Error setIdleTimerEnabled(
171 std::chrono::milliseconds timeout) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800172};
173
174namespace impl {
175
Lloyd Piquea516c002021-05-07 14:36:58 -0700176class Layer;
177
Ana Krulec4593b692019-01-11 22:07:25 -0800178class Display : public HWC2::Display {
179public:
Ady Abrahamde549d42022-01-26 19:19:17 -0800180 Display(android::Hwc2::Composer&,
181 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&,
182 hal::HWDisplayId, hal::DisplayType);
Ana Krulec4593b692019-01-11 22:07:25 -0800183 ~Display() override;
184
185 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700186 hal::Error acceptChanges() override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700187 base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700188 hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500189 std::unordered_map<HWC2::Layer*,
190 aidl::android::hardware::graphics::composer3::Composition>* outTypes)
191 override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700192 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800193 // Returns a bitmask which contains HdrMetadata::Type::*.
194 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700195 hal::Error getRenderIntents(hal::ColorMode colorMode,
196 std::vector<hal::RenderIntent>* outRenderIntents) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200197 hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700198
Peiyong Line9d809e2020-04-14 13:10:48 -0700199 hal::Error getName(std::string* outName) const override;
200 hal::Error getRequests(
201 hal::DisplayRequest* outDisplayRequests,
Lloyd Piquea516c002021-05-07 14:36:58 -0700202 std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override;
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100203 hal::Error getConnectionType(ui::DisplayConnectionType*) const override;
Ady Abraham27fbcc72021-09-20 14:54:57 -0700204 hal::Error supportsDoze(bool* outSupport) const override EXCLUDES(mDisplayCapabilitiesMutex);
Peiyong Line9d809e2020-04-14 13:10:48 -0700205 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
206 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
207 hal::Dataspace* outDataspace,
208 uint8_t* outComponentMask) const override;
209 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
210 uint64_t maxFrames) const override;
211 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
212 android::DisplayedFrameStats* outStats) const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700213 hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>*
214 outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700215 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700216 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
217 const android::sp<android::Fence>& acquireFence,
218 hal::Dataspace dataspace) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200219 hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
Ady Abrahamdc011a92021-12-21 14:06:44 -0800220 hal::Error setColorTransform(const android::mat4& matrix) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200221 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700222 const android::sp<android::Fence>& releaseFence) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200223 hal::Error setPowerMode(hal::PowerMode) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700224 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
Ady Abraham43065bd2021-12-10 17:22:15 -0800225 hal::Error validate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
226 uint32_t* outNumRequests) override;
227 hal::Error presentOrValidate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
228 uint32_t* outNumRequests,
Peiyong Line9d809e2020-04-14 13:10:48 -0700229 android::sp<android::Fence>* outPresentFence,
230 uint32_t* state) override;
Alec Mouricdf16792021-12-10 13:16:06 -0800231 std::future<hal::Error> setDisplayBrightness(
232 float brightness, const Hwc2::Composer::DisplayBrightnessOptions& options) override;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100233 hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId,
234 const hal::VsyncPeriodChangeConstraints& constraints,
235 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Kriti Dang7defaf32021-11-15 11:55:43 +0100236 hal::Error setBootDisplayConfig(hal::HWConfigId configId) override;
237 hal::Error clearBootDisplayConfig() override;
238 hal::Error getPreferredBootDisplayConfig(hal::HWConfigId* configId) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700239 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700240 hal::Error getSupportedContentTypes(
241 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700242 hal::Error setContentType(hal::ContentType) override;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700243 hal::Error getClientTargetProperty(hal::ClientTargetProperty* outClientTargetProperty,
244 float* outWhitePointNits) override;
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500245 hal::Error getDisplayDecorationSupport(
246 std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
247 support) override;
ramindani32cf0602022-03-02 02:30:29 +0000248 hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700249
Dan Stoza651bf312015-10-23 17:03:17 -0700250 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700251 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800252 bool isConnected() const override { return mIsConnected; }
253 void setConnected(bool connected) override; // For use by Device only
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500254 bool hasCapability(aidl::android::hardware::graphics::composer3::DisplayCapability)
255 const override EXCLUDES(mDisplayCapabilitiesMutex);
Lloyd Piquea516c002021-05-07 14:36:58 -0700256 bool isVsyncPeriodSwitchSupported() const override;
ramindani32cf0602022-03-02 02:30:29 +0000257 bool hasDisplayIdleTimerCapability() const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700258 void onLayerDestroyed(hal::HWLayerId layerId) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700259
260private:
Dan Stoza651bf312015-10-23 17:03:17 -0700261
Dan Stoza651bf312015-10-23 17:03:17 -0700262 // This may fail (and return a null pointer) if no layer with this ID exists
263 // on this display
Lloyd Piquea516c002021-05-07 14:36:58 -0700264 std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700265
Lloyd Piquebc792092018-01-17 11:52:30 -0800266 friend android::TestableSurfaceFlinger;
267
Dan Stoza651bf312015-10-23 17:03:17 -0700268 // Member variables
269
Steven Thomas94e35b92017-07-26 18:48:28 -0700270 // These are references to data owned by HWC2::Device, which will outlive
271 // this HWC2::Display, so these references are guaranteed to be valid for
272 // the lifetime of this object.
273 android::Hwc2::Composer& mComposer;
Ady Abrahamde549d42022-01-26 19:19:17 -0800274 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
275 mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700276
Peiyong Line9d809e2020-04-14 13:10:48 -0700277 const hal::HWDisplayId mId;
278 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800279 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700280
Lloyd Piquea516c002021-05-07 14:36:58 -0700281 using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>;
282 Layers mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700283
Ady Abraham27fbcc72021-09-20 14:54:57 -0700284 mutable std::mutex mDisplayCapabilitiesMutex;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700285 std::once_flag mDisplayCapabilityQueryFlag;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500286 std::optional<
287 std::unordered_set<aidl::android::hardware::graphics::composer3::DisplayCapability>>
288 mDisplayCapabilities GUARDED_BY(mDisplayCapabilitiesMutex);
Dan Stoza651bf312015-10-23 17:03:17 -0700289};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800290
Ana Krulec4593b692019-01-11 22:07:25 -0800291} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700292
Lloyd Pique35d58242018-12-18 16:33:25 -0800293class Layer {
294public:
295 virtual ~Layer();
296
Peiyong Line9d809e2020-04-14 13:10:48 -0700297 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800298
Peiyong Line9d809e2020-04-14 13:10:48 -0700299 [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
300 [[clang::warn_unused_result]] virtual hal::Error setBuffer(
Lloyd Pique35d58242018-12-18 16:33:25 -0800301 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
302 const android::sp<android::Fence>& acquireFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700303 [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage(
304 const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800305
Peiyong Line9d809e2020-04-14 13:10:48 -0700306 [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
Ady Abraham6e60b142022-01-06 18:10:35 -0800307 [[clang::warn_unused_result]] virtual hal::Error setColor(
308 aidl::android::hardware::graphics::composer3::Color color) = 0;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500309 [[clang::warn_unused_result]] virtual hal::Error setCompositionType(
310 aidl::android::hardware::graphics::composer3::Composition type) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700311 [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
312 [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata(
Lloyd Pique35d58242018-12-18 16:33:25 -0800313 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700314 [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame(
315 const android::Rect& frame) = 0;
316 [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
317 [[clang::warn_unused_result]] virtual hal::Error setSidebandStream(
Lloyd Pique35d58242018-12-18 16:33:25 -0800318 const native_handle_t* stream) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700319 [[clang::warn_unused_result]] virtual hal::Error setSourceCrop(
320 const android::FloatRect& crop) = 0;
321 [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0;
322 [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion(
323 const android::Region& region) = 0;
324 [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800325
326 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700327 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
328 const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800329
330 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700331 [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata(
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800332 const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700333
334 // AIDL HAL
Alec Mouri6da0e272022-02-07 12:45:57 -0800335 [[clang::warn_unused_result]] virtual hal::Error setBrightness(float brightness) = 0;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500336 [[clang::warn_unused_result]] virtual hal::Error setBlockingRegion(
337 const android::Region& region) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800338};
339
340namespace impl {
341
Peiyong Line9d809e2020-04-14 13:10:48 -0700342// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800343
344class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700345public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700346 Layer(android::Hwc2::Composer& composer,
Ady Abrahamde549d42022-01-26 19:19:17 -0800347 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
348 capabilities,
349 HWC2::Display& display, hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800350 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700351
Lloyd Piquea516c002021-05-07 14:36:58 -0700352 void onOwningDisplayDestroyed();
353
Peiyong Line9d809e2020-04-14 13:10:48 -0700354 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700355
Peiyong Line9d809e2020-04-14 13:10:48 -0700356 hal::Error setCursorPosition(int32_t x, int32_t y) override;
357 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
358 const android::sp<android::Fence>& acquireFence) override;
359 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700360
Peiyong Line9d809e2020-04-14 13:10:48 -0700361 hal::Error setBlendMode(hal::BlendMode mode) override;
Ady Abraham6e60b142022-01-06 18:10:35 -0800362 hal::Error setColor(aidl::android::hardware::graphics::composer3::Color color) override;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500363 hal::Error setCompositionType(
364 aidl::android::hardware::graphics::composer3::Composition type) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700365 hal::Error setDataspace(hal::Dataspace dataspace) override;
366 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
367 const android::HdrMetadata& metadata) override;
368 hal::Error setDisplayFrame(const android::Rect& frame) override;
369 hal::Error setPlaneAlpha(float alpha) override;
370 hal::Error setSidebandStream(const native_handle_t* stream) override;
371 hal::Error setSourceCrop(const android::FloatRect& crop) override;
372 hal::Error setTransform(hal::Transform transform) override;
373 hal::Error setVisibleRegion(const android::Region& region) override;
374 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700375
Peiyong Lin698147a2018-09-14 13:27:18 -0700376 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700377 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700378
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800379 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700380 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
381 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800382
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700383 // AIDL HAL
Alec Mouri6da0e272022-02-07 12:45:57 -0800384 hal::Error setBrightness(float brightness) override;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500385 hal::Error setBlockingRegion(const android::Region& region) override;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700386
Dan Stoza651bf312015-10-23 17:03:17 -0700387private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700388 // These are references to data owned by HWC2::Device, which will outlive
389 // this HWC2::Layer, so these references are guaranteed to be valid for
390 // the lifetime of this object.
391 android::Hwc2::Composer& mComposer;
Ady Abrahamde549d42022-01-26 19:19:17 -0800392 const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>&
393 mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700394
Lloyd Piquea516c002021-05-07 14:36:58 -0700395 HWC2::Display* mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700396 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800397
398 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
399 // multiple times.
400 android::Region mVisibleRegion = android::Region::INVALID_REGION;
401 android::Region mDamageRegion = android::Region::INVALID_REGION;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500402 android::Region mBlockingRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700403 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700404 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700405 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800406 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700407};
408
Lloyd Pique35d58242018-12-18 16:33:25 -0800409} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700410} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700411} // namespace android