blob: 5685c9a8892020cd769b7002bec5462e244cb031 [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
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070019#include <gui/HdrMetadata.h>
Mathias Agopian1d77b712017-02-17 15:46:13 -080020#include <math/mat4.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070021#include <ui/HdrCapabilities.h>
Yichi Chen8366f562019-03-25 19:44:06 +080022#include <ui/Region.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010023#include <ui/StaticDisplayInfo.h>
Dan Stoza651bf312015-10-23 17:03:17 -070024#include <utils/Log.h>
25#include <utils/StrongPointer.h>
26#include <utils/Timers.h>
27
28#include <functional>
Dominik Laskowski5690bde2020-04-23 19:04:22 -070029#include <future>
Dan Stoza651bf312015-10-23 17:03:17 -070030#include <string>
31#include <unordered_map>
Dan Stoza9f26a9c2016-06-22 14:51:09 -070032#include <unordered_set>
Dan Stoza651bf312015-10-23 17:03:17 -070033#include <vector>
34
Peiyong Line9d809e2020-04-14 13:10:48 -070035#include "Hal.h"
36
Dan Stoza651bf312015-10-23 17:03:17 -070037namespace android {
Lloyd Piquebc792092018-01-17 11:52:30 -080038
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070039class Fence;
40class FloatRect;
41class GraphicBuffer;
42class TestableSurfaceFlinger;
43struct DisplayedFrameStats;
44
45namespace Hwc2 {
46class Composer;
47} // namespace Hwc2
Dan Stoza651bf312015-10-23 17:03:17 -070048
49namespace HWC2 {
50
Dan Stoza651bf312015-10-23 17:03:17 -070051class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070052
53namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070054
Steven Thomas94e35b92017-07-26 18:48:28 -070055// Implement this interface to receive hardware composer events.
56//
57// These callback functions will generally be called on a hwbinder thread, but
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070058// when first registering the callback the onComposerHalHotplug() function will
Steven Thomas94e35b92017-07-26 18:48:28 -070059// immediately be called on the thread calling registerCallback().
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070060struct ComposerCallback {
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070061 virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0;
62 virtual void onComposerHalRefresh(hal::HWDisplayId) = 0;
63 virtual void onComposerHalVsync(hal::HWDisplayId, int64_t timestamp,
64 std::optional<hal::VsyncPeriodNanos>) = 0;
65 virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId,
66 const hal::VsyncPeriodChangeTimeline&) = 0;
67 virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070068
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070069protected:
70 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070071};
Dan Stoza651bf312015-10-23 17:03:17 -070072
Peiyong Line9d809e2020-04-14 13:10:48 -070073// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080074class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070075public:
Ana Krulec4593b692019-01-11 22:07:25 -080076 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070077
Peiyong Line9d809e2020-04-14 13:10:48 -070078 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080079 virtual bool isConnected() const = 0;
80 virtual void setConnected(bool connected) = 0; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -070081 virtual const std::unordered_set<hal::DisplayCapability>& getCapabilities() const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070082 virtual bool isVsyncPeriodSwitchSupported() const = 0;
Dan Stoza651bf312015-10-23 17:03:17 -070083
Peiyong Line9d809e2020-04-14 13:10:48 -070084 [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0;
85 [[clang::warn_unused_result]] virtual hal::Error createLayer(Layer** outLayer) = 0;
86 [[clang::warn_unused_result]] virtual hal::Error destroyLayer(Layer* layer) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070087 [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes(
88 std::unordered_map<Layer*, hal::Composition>* outTypes) = 0;
89 [[clang::warn_unused_result]] virtual hal::Error getColorModes(
90 std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +080091 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -080092 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070093 [[clang::warn_unused_result]] virtual hal::Error getRenderIntents(
94 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
95 [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix(
96 hal::Dataspace dataspace, android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080097
Peiyong Line9d809e2020-04-14 13:10:48 -070098 [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0;
99 [[clang::warn_unused_result]] virtual hal::Error getRequests(
100 hal::DisplayRequest* outDisplayRequests,
101 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
102 [[clang::warn_unused_result]] virtual hal::Error getConnectionType(
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100103 ui::DisplayConnectionType*) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700104 [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
105 [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800106 android::HdrCapabilities* outCapabilities) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700107 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes(
108 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800109 uint8_t* outComponentMask) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700110 [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled(
Ana Krulec4593b692019-01-11 22:07:25 -0800111 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700112 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800113 uint64_t maxFrames, uint64_t timestamp,
114 android::DisplayedFrameStats* outStats) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700115 [[clang::warn_unused_result]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800116 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700117 [[clang::warn_unused_result]] virtual hal::Error present(
Ana Krulec4593b692019-01-11 22:07:25 -0800118 android::sp<android::Fence>* outPresentFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700119 [[clang::warn_unused_result]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800120 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700121 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
122 [[clang::warn_unused_result]] virtual hal::Error setColorMode(
123 hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
124 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
125 const android::mat4& matrix, hal::ColorTransform hint) = 0;
126 [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800127 const android::sp<android::GraphicBuffer>& buffer,
128 const android::sp<android::Fence>& releaseFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700129 [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
130 [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
131 [[clang::warn_unused_result]] virtual hal::Error validate(uint32_t* outNumTypes,
132 uint32_t* outNumRequests) = 0;
133 [[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
Ana Krulec4593b692019-01-11 22:07:25 -0800134 uint32_t* outNumTypes, uint32_t* outNumRequests,
135 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700136 [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
137 float brightness) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700138 [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100139 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700140 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700141 [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700142 [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
143 std::vector<hal::ContentType>*) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700144 [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700145 [[clang::warn_unused_result]] virtual hal::Error getClientTargetProperty(
146 hal::ClientTargetProperty* outClientTargetProperty) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800147};
148
149namespace impl {
150
151class Display : public HWC2::Display {
152public:
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200153 Display(android::Hwc2::Composer&, const std::unordered_set<hal::Capability>&, hal::HWDisplayId,
154 hal::DisplayType);
Ana Krulec4593b692019-01-11 22:07:25 -0800155 ~Display() override;
156
157 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700158 hal::Error acceptChanges() override;
159 hal::Error createLayer(Layer** outLayer) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200160 hal::Error destroyLayer(Layer*) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700161 hal::Error getChangedCompositionTypes(
162 std::unordered_map<Layer*, hal::Composition>* outTypes) override;
163 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800164 // Returns a bitmask which contains HdrMetadata::Type::*.
165 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700166 hal::Error getRenderIntents(hal::ColorMode colorMode,
167 std::vector<hal::RenderIntent>* outRenderIntents) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200168 hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700169
Peiyong Line9d809e2020-04-14 13:10:48 -0700170 hal::Error getName(std::string* outName) const override;
171 hal::Error getRequests(
172 hal::DisplayRequest* outDisplayRequests,
173 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) override;
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100174 hal::Error getConnectionType(ui::DisplayConnectionType*) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700175 hal::Error supportsDoze(bool* outSupport) const override;
176 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
177 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
178 hal::Dataspace* outDataspace,
179 uint8_t* outComponentMask) const override;
180 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
181 uint64_t maxFrames) const override;
182 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
183 android::DisplayedFrameStats* outStats) const override;
184 hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800185 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700186 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700187 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
188 const android::sp<android::Fence>& acquireFence,
189 hal::Dataspace dataspace) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200190 hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700191 hal::Error setColorTransform(const android::mat4& matrix, hal::ColorTransform hint) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200192 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700193 const android::sp<android::Fence>& releaseFence) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200194 hal::Error setPowerMode(hal::PowerMode) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700195 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
196 hal::Error validate(uint32_t* outNumTypes, uint32_t* outNumRequests) override;
197 hal::Error presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests,
198 android::sp<android::Fence>* outPresentFence,
199 uint32_t* state) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700200 std::future<hal::Error> setDisplayBrightness(float brightness) override;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100201 hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId,
202 const hal::VsyncPeriodChangeConstraints& constraints,
203 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700204 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700205 hal::Error getSupportedContentTypes(
206 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700207 hal::Error setContentType(hal::ContentType) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700208 hal::Error getClientTargetProperty(hal::ClientTargetProperty* outClientTargetProperty) override;
209
Dan Stoza651bf312015-10-23 17:03:17 -0700210 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700211 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800212 bool isConnected() const override { return mIsConnected; }
213 void setConnected(bool connected) override; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -0700214 const std::unordered_set<hal::DisplayCapability>& getCapabilities() const override {
Peiyong Lined531a32018-10-26 18:27:56 -0700215 return mDisplayCapabilities;
216 };
Ady Abraham7159f572019-10-11 11:10:18 -0700217 virtual bool isVsyncPeriodSwitchSupported() const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700218
219private:
Dan Stoza651bf312015-10-23 17:03:17 -0700220
Dan Stoza651bf312015-10-23 17:03:17 -0700221 // This may fail (and return a null pointer) if no layer with this ID exists
222 // on this display
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200223 Layer* getLayerById(hal::HWLayerId) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700224
Lloyd Piquebc792092018-01-17 11:52:30 -0800225 friend android::TestableSurfaceFlinger;
226
Dan Stoza651bf312015-10-23 17:03:17 -0700227 // Member variables
228
Steven Thomas94e35b92017-07-26 18:48:28 -0700229 // These are references to data owned by HWC2::Device, which will outlive
230 // this HWC2::Display, so these references are guaranteed to be valid for
231 // the lifetime of this object.
232 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700233 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700234
Peiyong Line9d809e2020-04-14 13:10:48 -0700235 const hal::HWDisplayId mId;
236 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800237 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700238
Peiyong Line9d809e2020-04-14 13:10:48 -0700239 std::unordered_map<hal::HWLayerId, std::unique_ptr<Layer>> mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700240
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700241 std::once_flag mDisplayCapabilityQueryFlag;
Peiyong Line9d809e2020-04-14 13:10:48 -0700242 std::unordered_set<hal::DisplayCapability> mDisplayCapabilities;
Dan Stoza651bf312015-10-23 17:03:17 -0700243};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800244
Ana Krulec4593b692019-01-11 22:07:25 -0800245} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700246
Lloyd Pique35d58242018-12-18 16:33:25 -0800247class Layer {
248public:
249 virtual ~Layer();
250
Peiyong Line9d809e2020-04-14 13:10:48 -0700251 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800252
Peiyong Line9d809e2020-04-14 13:10:48 -0700253 [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
254 [[clang::warn_unused_result]] virtual hal::Error setBuffer(
Lloyd Pique35d58242018-12-18 16:33:25 -0800255 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
256 const android::sp<android::Fence>& acquireFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700257 [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage(
258 const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800259
Peiyong Line9d809e2020-04-14 13:10:48 -0700260 [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
261 [[clang::warn_unused_result]] virtual hal::Error setColor(hal::Color color) = 0;
262 [[clang::warn_unused_result]] virtual hal::Error setCompositionType(hal::Composition type) = 0;
263 [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
264 [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata(
Lloyd Pique35d58242018-12-18 16:33:25 -0800265 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700266 [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame(
267 const android::Rect& frame) = 0;
268 [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
269 [[clang::warn_unused_result]] virtual hal::Error setSidebandStream(
Lloyd Pique35d58242018-12-18 16:33:25 -0800270 const native_handle_t* stream) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700271 [[clang::warn_unused_result]] virtual hal::Error setSourceCrop(
272 const android::FloatRect& crop) = 0;
273 [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0;
274 [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion(
275 const android::Region& region) = 0;
276 [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800277
278 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700279 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
280 const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800281
282 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700283 [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata(
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800284 const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800285};
286
287namespace impl {
288
Peiyong Line9d809e2020-04-14 13:10:48 -0700289// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800290
291class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700292public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700293 Layer(android::Hwc2::Composer& composer,
294 const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId displayId,
295 hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800296 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700297
Peiyong Line9d809e2020-04-14 13:10:48 -0700298 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700299
Peiyong Line9d809e2020-04-14 13:10:48 -0700300 hal::Error setCursorPosition(int32_t x, int32_t y) override;
301 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
302 const android::sp<android::Fence>& acquireFence) override;
303 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700304
Peiyong Line9d809e2020-04-14 13:10:48 -0700305 hal::Error setBlendMode(hal::BlendMode mode) override;
306 hal::Error setColor(hal::Color color) override;
307 hal::Error setCompositionType(hal::Composition type) override;
308 hal::Error setDataspace(hal::Dataspace dataspace) override;
309 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
310 const android::HdrMetadata& metadata) override;
311 hal::Error setDisplayFrame(const android::Rect& frame) override;
312 hal::Error setPlaneAlpha(float alpha) override;
313 hal::Error setSidebandStream(const native_handle_t* stream) override;
314 hal::Error setSourceCrop(const android::FloatRect& crop) override;
315 hal::Error setTransform(hal::Transform transform) override;
316 hal::Error setVisibleRegion(const android::Region& region) override;
317 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700318
Peiyong Lin698147a2018-09-14 13:27:18 -0700319 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700320 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700321
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800322 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700323 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
324 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800325
Dan Stoza651bf312015-10-23 17:03:17 -0700326private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700327 // These are references to data owned by HWC2::Device, which will outlive
328 // this HWC2::Layer, so these references are guaranteed to be valid for
329 // the lifetime of this object.
330 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700331 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700332
Peiyong Line9d809e2020-04-14 13:10:48 -0700333 hal::HWDisplayId mDisplayId;
334 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800335
336 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
337 // multiple times.
338 android::Region mVisibleRegion = android::Region::INVALID_REGION;
339 android::Region mDamageRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700340 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700341 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700342 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800343 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700344};
345
Lloyd Pique35d58242018-12-18 16:33:25 -0800346} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700347} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700348} // namespace android