blob: 0a605a85155762d343fb9f165041bc294b2b9790 [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
Ady Abraham6e60b142022-01-06 18:10:35 -080040#include <aidl/android/hardware/graphics/composer3/Color.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050041#include <aidl/android/hardware/graphics/composer3/Composition.h>
Leon Scroggins III5967aec2021-12-29 11:14:22 -050042#include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050043
Dan Stoza651bf312015-10-23 17:03:17 -070044namespace android {
Lloyd Piquebc792092018-01-17 11:52:30 -080045
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070046class Fence;
47class FloatRect;
48class GraphicBuffer;
49class TestableSurfaceFlinger;
50struct DisplayedFrameStats;
51
52namespace Hwc2 {
53class Composer;
54} // namespace Hwc2
Dan Stoza651bf312015-10-23 17:03:17 -070055
56namespace HWC2 {
57
Dan Stoza651bf312015-10-23 17:03:17 -070058class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070059
60namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070061
Steven Thomas94e35b92017-07-26 18:48:28 -070062// Implement this interface to receive hardware composer events.
63//
64// These callback functions will generally be called on a hwbinder thread, but
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070065// when first registering the callback the onComposerHalHotplug() function will
Steven Thomas94e35b92017-07-26 18:48:28 -070066// immediately be called on the thread calling registerCallback().
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070067struct ComposerCallback {
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070068 virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0;
69 virtual void onComposerHalRefresh(hal::HWDisplayId) = 0;
70 virtual void onComposerHalVsync(hal::HWDisplayId, int64_t timestamp,
71 std::optional<hal::VsyncPeriodNanos>) = 0;
72 virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId,
73 const hal::VsyncPeriodChangeTimeline&) = 0;
74 virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0;
Yichi Chen3401b562022-01-17 15:42:35 +080075 virtual void onComposerHalVsyncIdle(hal::HWDisplayId) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070076
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070077protected:
78 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070079};
Dan Stoza651bf312015-10-23 17:03:17 -070080
Peiyong Line9d809e2020-04-14 13:10:48 -070081// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080082class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070083public:
Ana Krulec4593b692019-01-11 22:07:25 -080084 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070085
Peiyong Line9d809e2020-04-14 13:10:48 -070086 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080087 virtual bool isConnected() const = 0;
88 virtual void setConnected(bool connected) = 0; // For use by Device only
Leon Scroggins III5967aec2021-12-29 11:14:22 -050089 virtual bool hasCapability(
90 aidl::android::hardware::graphics::composer3::DisplayCapability) const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070091 virtual bool isVsyncPeriodSwitchSupported() const = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070092 virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0;
Dan Stoza651bf312015-10-23 17:03:17 -070093
Peiyong Line9d809e2020-04-14 13:10:48 -070094 [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070095 [[clang::warn_unused_result]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error>
96 createLayer() = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070097 [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050098 std::unordered_map<Layer*, aidl::android::hardware::graphics::composer3::Composition>*
99 outTypes) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700100 [[clang::warn_unused_result]] virtual hal::Error getColorModes(
101 std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +0800102 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -0800103 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700104 [[clang::warn_unused_result]] virtual hal::Error getRenderIntents(
105 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
106 [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix(
107 hal::Dataspace dataspace, android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800108
Peiyong Line9d809e2020-04-14 13:10:48 -0700109 [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0;
110 [[clang::warn_unused_result]] virtual hal::Error getRequests(
111 hal::DisplayRequest* outDisplayRequests,
112 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
113 [[clang::warn_unused_result]] virtual hal::Error getConnectionType(
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100114 ui::DisplayConnectionType*) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700115 [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
116 [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800117 android::HdrCapabilities* outCapabilities) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700118 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes(
119 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800120 uint8_t* outComponentMask) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700121 [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled(
Ana Krulec4593b692019-01-11 22:07:25 -0800122 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700123 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800124 uint64_t maxFrames, uint64_t timestamp,
125 android::DisplayedFrameStats* outStats) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700126 [[clang::warn_unused_result]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800127 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700128 [[clang::warn_unused_result]] virtual hal::Error present(
Ana Krulec4593b692019-01-11 22:07:25 -0800129 android::sp<android::Fence>* outPresentFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700130 [[clang::warn_unused_result]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800131 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700132 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
133 [[clang::warn_unused_result]] virtual hal::Error setColorMode(
134 hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
135 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
Ady Abrahamdc011a92021-12-21 14:06:44 -0800136 const android::mat4& matrix) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700137 [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800138 const android::sp<android::GraphicBuffer>& buffer,
139 const android::sp<android::Fence>& releaseFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700140 [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
141 [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
Ady Abraham43065bd2021-12-10 17:22:15 -0800142 [[clang::warn_unused_result]] virtual hal::Error validate(nsecs_t expectedPresentTime,
143 uint32_t* outNumTypes,
Peiyong Line9d809e2020-04-14 13:10:48 -0700144 uint32_t* outNumRequests) = 0;
145 [[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
Ady Abraham43065bd2021-12-10 17:22:15 -0800146 nsecs_t expectedPresentTime, uint32_t* outNumTypes, uint32_t* outNumRequests,
Ana Krulec4593b692019-01-11 22:07:25 -0800147 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700148 [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
Alec Mouricdf16792021-12-10 13:16:06 -0800149 float brightness, const Hwc2::Composer::DisplayBrightnessOptions& options) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700150 [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100151 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700152 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Kriti Dang7defaf32021-11-15 11:55:43 +0100153 [[clang::warn_unused_result]] virtual hal::Error setBootDisplayConfig(
154 hal::HWConfigId configId) = 0;
155 [[clang::warn_unused_result]] virtual hal::Error clearBootDisplayConfig() = 0;
156 [[clang::warn_unused_result]] virtual hal::Error getPreferredBootDisplayConfig(
157 hal::HWConfigId* configId) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700158 [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700159 [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
160 std::vector<hal::ContentType>*) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700161 [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700162 [[clang::warn_unused_result]] virtual hal::Error getClientTargetProperty(
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700163 hal::ClientTargetProperty* outClientTargetProperty, float* outWhitePointNits) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800164};
165
166namespace impl {
167
Lloyd Piquea516c002021-05-07 14:36:58 -0700168class Layer;
169
Ana Krulec4593b692019-01-11 22:07:25 -0800170class Display : public HWC2::Display {
171public:
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200172 Display(android::Hwc2::Composer&, const std::unordered_set<hal::Capability>&, hal::HWDisplayId,
173 hal::DisplayType);
Ana Krulec4593b692019-01-11 22:07:25 -0800174 ~Display() override;
175
176 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700177 hal::Error acceptChanges() override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700178 base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700179 hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500180 std::unordered_map<HWC2::Layer*,
181 aidl::android::hardware::graphics::composer3::Composition>* outTypes)
182 override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700183 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800184 // Returns a bitmask which contains HdrMetadata::Type::*.
185 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700186 hal::Error getRenderIntents(hal::ColorMode colorMode,
187 std::vector<hal::RenderIntent>* outRenderIntents) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200188 hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700189
Peiyong Line9d809e2020-04-14 13:10:48 -0700190 hal::Error getName(std::string* outName) const override;
191 hal::Error getRequests(
192 hal::DisplayRequest* outDisplayRequests,
Lloyd Piquea516c002021-05-07 14:36:58 -0700193 std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override;
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100194 hal::Error getConnectionType(ui::DisplayConnectionType*) const override;
Ady Abraham27fbcc72021-09-20 14:54:57 -0700195 hal::Error supportsDoze(bool* outSupport) const override EXCLUDES(mDisplayCapabilitiesMutex);
Peiyong Line9d809e2020-04-14 13:10:48 -0700196 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
197 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
198 hal::Dataspace* outDataspace,
199 uint8_t* outComponentMask) const override;
200 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
201 uint64_t maxFrames) const override;
202 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
203 android::DisplayedFrameStats* outStats) const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700204 hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>*
205 outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700206 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700207 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
208 const android::sp<android::Fence>& acquireFence,
209 hal::Dataspace dataspace) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200210 hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
Ady Abrahamdc011a92021-12-21 14:06:44 -0800211 hal::Error setColorTransform(const android::mat4& matrix) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200212 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700213 const android::sp<android::Fence>& releaseFence) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200214 hal::Error setPowerMode(hal::PowerMode) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700215 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
Ady Abraham43065bd2021-12-10 17:22:15 -0800216 hal::Error validate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
217 uint32_t* outNumRequests) override;
218 hal::Error presentOrValidate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
219 uint32_t* outNumRequests,
Peiyong Line9d809e2020-04-14 13:10:48 -0700220 android::sp<android::Fence>* outPresentFence,
221 uint32_t* state) override;
Alec Mouricdf16792021-12-10 13:16:06 -0800222 std::future<hal::Error> setDisplayBrightness(
223 float brightness, const Hwc2::Composer::DisplayBrightnessOptions& options) override;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100224 hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId,
225 const hal::VsyncPeriodChangeConstraints& constraints,
226 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Kriti Dang7defaf32021-11-15 11:55:43 +0100227 hal::Error setBootDisplayConfig(hal::HWConfigId configId) override;
228 hal::Error clearBootDisplayConfig() override;
229 hal::Error getPreferredBootDisplayConfig(hal::HWConfigId* configId) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700230 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700231 hal::Error getSupportedContentTypes(
232 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700233 hal::Error setContentType(hal::ContentType) override;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700234 hal::Error getClientTargetProperty(hal::ClientTargetProperty* outClientTargetProperty,
235 float* outWhitePointNits) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700236
Dan Stoza651bf312015-10-23 17:03:17 -0700237 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700238 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800239 bool isConnected() const override { return mIsConnected; }
240 void setConnected(bool connected) override; // For use by Device only
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500241 bool hasCapability(aidl::android::hardware::graphics::composer3::DisplayCapability)
242 const override EXCLUDES(mDisplayCapabilitiesMutex);
Lloyd Piquea516c002021-05-07 14:36:58 -0700243 bool isVsyncPeriodSwitchSupported() const override;
244 void onLayerDestroyed(hal::HWLayerId layerId) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700245
246private:
Dan Stoza651bf312015-10-23 17:03:17 -0700247
Dan Stoza651bf312015-10-23 17:03:17 -0700248 // This may fail (and return a null pointer) if no layer with this ID exists
249 // on this display
Lloyd Piquea516c002021-05-07 14:36:58 -0700250 std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700251
Lloyd Piquebc792092018-01-17 11:52:30 -0800252 friend android::TestableSurfaceFlinger;
253
Dan Stoza651bf312015-10-23 17:03:17 -0700254 // Member variables
255
Steven Thomas94e35b92017-07-26 18:48:28 -0700256 // These are references to data owned by HWC2::Device, which will outlive
257 // this HWC2::Display, so these references are guaranteed to be valid for
258 // the lifetime of this object.
259 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700260 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700261
Peiyong Line9d809e2020-04-14 13:10:48 -0700262 const hal::HWDisplayId mId;
263 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800264 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700265
Lloyd Piquea516c002021-05-07 14:36:58 -0700266 using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>;
267 Layers mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700268
Ady Abraham27fbcc72021-09-20 14:54:57 -0700269 mutable std::mutex mDisplayCapabilitiesMutex;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700270 std::once_flag mDisplayCapabilityQueryFlag;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500271 std::optional<
272 std::unordered_set<aidl::android::hardware::graphics::composer3::DisplayCapability>>
273 mDisplayCapabilities GUARDED_BY(mDisplayCapabilitiesMutex);
Dan Stoza651bf312015-10-23 17:03:17 -0700274};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800275
Ana Krulec4593b692019-01-11 22:07:25 -0800276} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700277
Lloyd Pique35d58242018-12-18 16:33:25 -0800278class Layer {
279public:
280 virtual ~Layer();
281
Peiyong Line9d809e2020-04-14 13:10:48 -0700282 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800283
Peiyong Line9d809e2020-04-14 13:10:48 -0700284 [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
285 [[clang::warn_unused_result]] virtual hal::Error setBuffer(
Lloyd Pique35d58242018-12-18 16:33:25 -0800286 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
287 const android::sp<android::Fence>& acquireFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700288 [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage(
289 const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800290
Peiyong Line9d809e2020-04-14 13:10:48 -0700291 [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
Ady Abraham6e60b142022-01-06 18:10:35 -0800292 [[clang::warn_unused_result]] virtual hal::Error setColor(
293 aidl::android::hardware::graphics::composer3::Color color) = 0;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500294 [[clang::warn_unused_result]] virtual hal::Error setCompositionType(
295 aidl::android::hardware::graphics::composer3::Composition type) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700296 [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
297 [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata(
Lloyd Pique35d58242018-12-18 16:33:25 -0800298 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700299 [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame(
300 const android::Rect& frame) = 0;
301 [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
302 [[clang::warn_unused_result]] virtual hal::Error setSidebandStream(
Lloyd Pique35d58242018-12-18 16:33:25 -0800303 const native_handle_t* stream) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700304 [[clang::warn_unused_result]] virtual hal::Error setSourceCrop(
305 const android::FloatRect& crop) = 0;
306 [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0;
307 [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion(
308 const android::Region& region) = 0;
309 [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800310
311 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700312 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
313 const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800314
315 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700316 [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata(
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800317 const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700318
319 // AIDL HAL
320 [[clang::warn_unused_result]] virtual hal::Error setWhitePointNits(float whitePointNits) = 0;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500321 [[clang::warn_unused_result]] virtual hal::Error setBlockingRegion(
322 const android::Region& region) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800323};
324
325namespace impl {
326
Peiyong Line9d809e2020-04-14 13:10:48 -0700327// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800328
329class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700330public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700331 Layer(android::Hwc2::Composer& composer,
Lloyd Piquea516c002021-05-07 14:36:58 -0700332 const std::unordered_set<hal::Capability>& capabilities, HWC2::Display& display,
Peiyong Line9d809e2020-04-14 13:10:48 -0700333 hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800334 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700335
Lloyd Piquea516c002021-05-07 14:36:58 -0700336 void onOwningDisplayDestroyed();
337
Peiyong Line9d809e2020-04-14 13:10:48 -0700338 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700339
Peiyong Line9d809e2020-04-14 13:10:48 -0700340 hal::Error setCursorPosition(int32_t x, int32_t y) override;
341 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
342 const android::sp<android::Fence>& acquireFence) override;
343 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700344
Peiyong Line9d809e2020-04-14 13:10:48 -0700345 hal::Error setBlendMode(hal::BlendMode mode) override;
Ady Abraham6e60b142022-01-06 18:10:35 -0800346 hal::Error setColor(aidl::android::hardware::graphics::composer3::Color color) override;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500347 hal::Error setCompositionType(
348 aidl::android::hardware::graphics::composer3::Composition type) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700349 hal::Error setDataspace(hal::Dataspace dataspace) override;
350 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
351 const android::HdrMetadata& metadata) override;
352 hal::Error setDisplayFrame(const android::Rect& frame) override;
353 hal::Error setPlaneAlpha(float alpha) override;
354 hal::Error setSidebandStream(const native_handle_t* stream) override;
355 hal::Error setSourceCrop(const android::FloatRect& crop) override;
356 hal::Error setTransform(hal::Transform transform) override;
357 hal::Error setVisibleRegion(const android::Region& region) override;
358 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700359
Peiyong Lin698147a2018-09-14 13:27:18 -0700360 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700361 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700362
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800363 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700364 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
365 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800366
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700367 // AIDL HAL
368 hal::Error setWhitePointNits(float whitePointNits) override;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500369 hal::Error setBlockingRegion(const android::Region& region) override;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700370
Dan Stoza651bf312015-10-23 17:03:17 -0700371private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700372 // These are references to data owned by HWC2::Device, which will outlive
373 // this HWC2::Layer, so these references are guaranteed to be valid for
374 // the lifetime of this object.
375 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700376 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700377
Lloyd Piquea516c002021-05-07 14:36:58 -0700378 HWC2::Display* mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700379 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800380
381 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
382 // multiple times.
383 android::Region mVisibleRegion = android::Region::INVALID_REGION;
384 android::Region mDamageRegion = android::Region::INVALID_REGION;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500385 android::Region mBlockingRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700386 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700387 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700388 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800389 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700390};
391
Lloyd Pique35d58242018-12-18 16:33:25 -0800392} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700393} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700394} // namespace android