blob: f833393125a5a12952fee1d38337d605a2320154 [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
Peiyong Line9d809e2020-04-14 13:10:48 -070037#include "Hal.h"
38
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050039#include <aidl/android/hardware/graphics/composer3/Composition.h>
Leon Scroggins III5967aec2021-12-29 11:14:22 -050040#include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050041
Dan Stoza651bf312015-10-23 17:03:17 -070042namespace android {
Lloyd Piquebc792092018-01-17 11:52:30 -080043
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070044class Fence;
45class FloatRect;
46class GraphicBuffer;
47class TestableSurfaceFlinger;
48struct DisplayedFrameStats;
49
50namespace Hwc2 {
51class Composer;
52} // namespace Hwc2
Dan Stoza651bf312015-10-23 17:03:17 -070053
54namespace HWC2 {
55
Dan Stoza651bf312015-10-23 17:03:17 -070056class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070057
58namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070059
Steven Thomas94e35b92017-07-26 18:48:28 -070060// Implement this interface to receive hardware composer events.
61//
62// These callback functions will generally be called on a hwbinder thread, but
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070063// when first registering the callback the onComposerHalHotplug() function will
Steven Thomas94e35b92017-07-26 18:48:28 -070064// immediately be called on the thread calling registerCallback().
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070065struct ComposerCallback {
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070066 virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0;
67 virtual void onComposerHalRefresh(hal::HWDisplayId) = 0;
68 virtual void onComposerHalVsync(hal::HWDisplayId, int64_t timestamp,
69 std::optional<hal::VsyncPeriodNanos>) = 0;
70 virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId,
71 const hal::VsyncPeriodChangeTimeline&) = 0;
72 virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070073
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070074protected:
75 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070076};
Dan Stoza651bf312015-10-23 17:03:17 -070077
Peiyong Line9d809e2020-04-14 13:10:48 -070078// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080079class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070080public:
Ana Krulec4593b692019-01-11 22:07:25 -080081 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070082
Peiyong Line9d809e2020-04-14 13:10:48 -070083 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080084 virtual bool isConnected() const = 0;
85 virtual void setConnected(bool connected) = 0; // For use by Device only
Leon Scroggins III5967aec2021-12-29 11:14:22 -050086 virtual bool hasCapability(
87 aidl::android::hardware::graphics::composer3::DisplayCapability) const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070088 virtual bool isVsyncPeriodSwitchSupported() const = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070089 virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0;
Dan Stoza651bf312015-10-23 17:03:17 -070090
Peiyong Line9d809e2020-04-14 13:10:48 -070091 [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070092 [[clang::warn_unused_result]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error>
93 createLayer() = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070094 [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050095 std::unordered_map<Layer*, aidl::android::hardware::graphics::composer3::Composition>*
96 outTypes) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070097 [[clang::warn_unused_result]] virtual hal::Error getColorModes(
98 std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +080099 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -0800100 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700101 [[clang::warn_unused_result]] virtual hal::Error getRenderIntents(
102 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
103 [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix(
104 hal::Dataspace dataspace, android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800105
Peiyong Line9d809e2020-04-14 13:10:48 -0700106 [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0;
107 [[clang::warn_unused_result]] virtual hal::Error getRequests(
108 hal::DisplayRequest* outDisplayRequests,
109 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
110 [[clang::warn_unused_result]] virtual hal::Error getConnectionType(
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100111 ui::DisplayConnectionType*) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700112 [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
113 [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800114 android::HdrCapabilities* outCapabilities) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700115 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes(
116 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800117 uint8_t* outComponentMask) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700118 [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled(
Ana Krulec4593b692019-01-11 22:07:25 -0800119 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700120 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800121 uint64_t maxFrames, uint64_t timestamp,
122 android::DisplayedFrameStats* outStats) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700123 [[clang::warn_unused_result]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800124 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700125 [[clang::warn_unused_result]] virtual hal::Error present(
Ana Krulec4593b692019-01-11 22:07:25 -0800126 android::sp<android::Fence>* outPresentFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700127 [[clang::warn_unused_result]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800128 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700129 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
130 [[clang::warn_unused_result]] virtual hal::Error setColorMode(
131 hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
132 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
Ady Abrahamdc011a92021-12-21 14:06:44 -0800133 const android::mat4& matrix) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700134 [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800135 const android::sp<android::GraphicBuffer>& buffer,
136 const android::sp<android::Fence>& releaseFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700137 [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
138 [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
Ady Abraham43065bd2021-12-10 17:22:15 -0800139 [[clang::warn_unused_result]] virtual hal::Error validate(nsecs_t expectedPresentTime,
140 uint32_t* outNumTypes,
Peiyong Line9d809e2020-04-14 13:10:48 -0700141 uint32_t* outNumRequests) = 0;
142 [[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
Ady Abraham43065bd2021-12-10 17:22:15 -0800143 nsecs_t expectedPresentTime, uint32_t* outNumTypes, uint32_t* outNumRequests,
Ana Krulec4593b692019-01-11 22:07:25 -0800144 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700145 [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
146 float brightness) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700147 [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100148 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700149 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700150 [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700151 [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
152 std::vector<hal::ContentType>*) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700153 [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700154 [[clang::warn_unused_result]] virtual hal::Error getClientTargetProperty(
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700155 hal::ClientTargetProperty* outClientTargetProperty, float* outWhitePointNits) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800156};
157
158namespace impl {
159
Lloyd Piquea516c002021-05-07 14:36:58 -0700160class Layer;
161
Ana Krulec4593b692019-01-11 22:07:25 -0800162class Display : public HWC2::Display {
163public:
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200164 Display(android::Hwc2::Composer&, const std::unordered_set<hal::Capability>&, hal::HWDisplayId,
165 hal::DisplayType);
Ana Krulec4593b692019-01-11 22:07:25 -0800166 ~Display() override;
167
168 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700169 hal::Error acceptChanges() override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700170 base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700171 hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500172 std::unordered_map<HWC2::Layer*,
173 aidl::android::hardware::graphics::composer3::Composition>* outTypes)
174 override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700175 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800176 // Returns a bitmask which contains HdrMetadata::Type::*.
177 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700178 hal::Error getRenderIntents(hal::ColorMode colorMode,
179 std::vector<hal::RenderIntent>* outRenderIntents) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200180 hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700181
Peiyong Line9d809e2020-04-14 13:10:48 -0700182 hal::Error getName(std::string* outName) const override;
183 hal::Error getRequests(
184 hal::DisplayRequest* outDisplayRequests,
Lloyd Piquea516c002021-05-07 14:36:58 -0700185 std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override;
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100186 hal::Error getConnectionType(ui::DisplayConnectionType*) const override;
Ady Abraham27fbcc72021-09-20 14:54:57 -0700187 hal::Error supportsDoze(bool* outSupport) const override EXCLUDES(mDisplayCapabilitiesMutex);
Peiyong Line9d809e2020-04-14 13:10:48 -0700188 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
189 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
190 hal::Dataspace* outDataspace,
191 uint8_t* outComponentMask) const override;
192 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
193 uint64_t maxFrames) const override;
194 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
195 android::DisplayedFrameStats* outStats) const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700196 hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>*
197 outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700198 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700199 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
200 const android::sp<android::Fence>& acquireFence,
201 hal::Dataspace dataspace) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200202 hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
Ady Abrahamdc011a92021-12-21 14:06:44 -0800203 hal::Error setColorTransform(const android::mat4& matrix) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200204 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700205 const android::sp<android::Fence>& releaseFence) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200206 hal::Error setPowerMode(hal::PowerMode) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700207 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
Ady Abraham43065bd2021-12-10 17:22:15 -0800208 hal::Error validate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
209 uint32_t* outNumRequests) override;
210 hal::Error presentOrValidate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
211 uint32_t* outNumRequests,
Peiyong Line9d809e2020-04-14 13:10:48 -0700212 android::sp<android::Fence>* outPresentFence,
213 uint32_t* state) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700214 std::future<hal::Error> setDisplayBrightness(float brightness) override;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100215 hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId,
216 const hal::VsyncPeriodChangeConstraints& constraints,
217 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700218 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700219 hal::Error getSupportedContentTypes(
220 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700221 hal::Error setContentType(hal::ContentType) override;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700222 hal::Error getClientTargetProperty(hal::ClientTargetProperty* outClientTargetProperty,
223 float* outWhitePointNits) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700224
Dan Stoza651bf312015-10-23 17:03:17 -0700225 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700226 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800227 bool isConnected() const override { return mIsConnected; }
228 void setConnected(bool connected) override; // For use by Device only
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500229 bool hasCapability(aidl::android::hardware::graphics::composer3::DisplayCapability)
230 const override EXCLUDES(mDisplayCapabilitiesMutex);
Lloyd Piquea516c002021-05-07 14:36:58 -0700231 bool isVsyncPeriodSwitchSupported() const override;
232 void onLayerDestroyed(hal::HWLayerId layerId) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700233
234private:
Dan Stoza651bf312015-10-23 17:03:17 -0700235
Dan Stoza651bf312015-10-23 17:03:17 -0700236 // This may fail (and return a null pointer) if no layer with this ID exists
237 // on this display
Lloyd Piquea516c002021-05-07 14:36:58 -0700238 std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700239
Lloyd Piquebc792092018-01-17 11:52:30 -0800240 friend android::TestableSurfaceFlinger;
241
Dan Stoza651bf312015-10-23 17:03:17 -0700242 // Member variables
243
Steven Thomas94e35b92017-07-26 18:48:28 -0700244 // These are references to data owned by HWC2::Device, which will outlive
245 // this HWC2::Display, so these references are guaranteed to be valid for
246 // the lifetime of this object.
247 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700248 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700249
Peiyong Line9d809e2020-04-14 13:10:48 -0700250 const hal::HWDisplayId mId;
251 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800252 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700253
Lloyd Piquea516c002021-05-07 14:36:58 -0700254 using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>;
255 Layers mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700256
Ady Abraham27fbcc72021-09-20 14:54:57 -0700257 mutable std::mutex mDisplayCapabilitiesMutex;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700258 std::once_flag mDisplayCapabilityQueryFlag;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500259 std::optional<
260 std::unordered_set<aidl::android::hardware::graphics::composer3::DisplayCapability>>
261 mDisplayCapabilities GUARDED_BY(mDisplayCapabilitiesMutex);
Dan Stoza651bf312015-10-23 17:03:17 -0700262};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800263
Ana Krulec4593b692019-01-11 22:07:25 -0800264} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700265
Lloyd Pique35d58242018-12-18 16:33:25 -0800266class Layer {
267public:
268 virtual ~Layer();
269
Peiyong Line9d809e2020-04-14 13:10:48 -0700270 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800271
Peiyong Line9d809e2020-04-14 13:10:48 -0700272 [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
273 [[clang::warn_unused_result]] virtual hal::Error setBuffer(
Lloyd Pique35d58242018-12-18 16:33:25 -0800274 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
275 const android::sp<android::Fence>& acquireFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700276 [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage(
277 const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800278
Peiyong Line9d809e2020-04-14 13:10:48 -0700279 [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
280 [[clang::warn_unused_result]] virtual hal::Error setColor(hal::Color color) = 0;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500281 [[clang::warn_unused_result]] virtual hal::Error setCompositionType(
282 aidl::android::hardware::graphics::composer3::Composition type) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700283 [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
284 [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata(
Lloyd Pique35d58242018-12-18 16:33:25 -0800285 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700286 [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame(
287 const android::Rect& frame) = 0;
288 [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
289 [[clang::warn_unused_result]] virtual hal::Error setSidebandStream(
Lloyd Pique35d58242018-12-18 16:33:25 -0800290 const native_handle_t* stream) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700291 [[clang::warn_unused_result]] virtual hal::Error setSourceCrop(
292 const android::FloatRect& crop) = 0;
293 [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0;
294 [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion(
295 const android::Region& region) = 0;
296 [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800297
298 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700299 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
300 const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800301
302 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700303 [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata(
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800304 const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700305
306 // AIDL HAL
307 [[clang::warn_unused_result]] virtual hal::Error setWhitePointNits(float whitePointNits) = 0;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500308 [[clang::warn_unused_result]] virtual hal::Error setBlockingRegion(
309 const android::Region& region) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800310};
311
312namespace impl {
313
Peiyong Line9d809e2020-04-14 13:10:48 -0700314// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800315
316class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700317public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700318 Layer(android::Hwc2::Composer& composer,
Lloyd Piquea516c002021-05-07 14:36:58 -0700319 const std::unordered_set<hal::Capability>& capabilities, HWC2::Display& display,
Peiyong Line9d809e2020-04-14 13:10:48 -0700320 hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800321 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700322
Lloyd Piquea516c002021-05-07 14:36:58 -0700323 void onOwningDisplayDestroyed();
324
Peiyong Line9d809e2020-04-14 13:10:48 -0700325 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700326
Peiyong Line9d809e2020-04-14 13:10:48 -0700327 hal::Error setCursorPosition(int32_t x, int32_t y) override;
328 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
329 const android::sp<android::Fence>& acquireFence) override;
330 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700331
Peiyong Line9d809e2020-04-14 13:10:48 -0700332 hal::Error setBlendMode(hal::BlendMode mode) override;
333 hal::Error setColor(hal::Color color) override;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500334 hal::Error setCompositionType(
335 aidl::android::hardware::graphics::composer3::Composition type) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700336 hal::Error setDataspace(hal::Dataspace dataspace) override;
337 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
338 const android::HdrMetadata& metadata) override;
339 hal::Error setDisplayFrame(const android::Rect& frame) override;
340 hal::Error setPlaneAlpha(float alpha) override;
341 hal::Error setSidebandStream(const native_handle_t* stream) override;
342 hal::Error setSourceCrop(const android::FloatRect& crop) override;
343 hal::Error setTransform(hal::Transform transform) override;
344 hal::Error setVisibleRegion(const android::Region& region) override;
345 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700346
Peiyong Lin698147a2018-09-14 13:27:18 -0700347 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700348 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700349
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800350 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700351 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
352 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800353
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700354 // AIDL HAL
355 hal::Error setWhitePointNits(float whitePointNits) override;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500356 hal::Error setBlockingRegion(const android::Region& region) override;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700357
Dan Stoza651bf312015-10-23 17:03:17 -0700358private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700359 // These are references to data owned by HWC2::Device, which will outlive
360 // this HWC2::Layer, so these references are guaranteed to be valid for
361 // the lifetime of this object.
362 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700363 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700364
Lloyd Piquea516c002021-05-07 14:36:58 -0700365 HWC2::Display* mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700366 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800367
368 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
369 // multiple times.
370 android::Region mVisibleRegion = android::Region::INVALID_REGION;
371 android::Region mDamageRegion = android::Region::INVALID_REGION;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -0500372 android::Region mBlockingRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700373 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700374 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700375 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800376 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700377};
378
Lloyd Pique35d58242018-12-18 16:33:25 -0800379} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700380} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700381} // namespace android