blob: e7bf286d0814a7c2469bf47d7d7f118e47d6c74d [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
58// when first registering the callback the onHotplugReceived() function will
59// immediately be called on the thread calling registerCallback().
60//
61// All calls receive a sequenceId, which will be the value that was supplied to
62// HWC2::Device::registerCallback(). It's used to help differentiate callbacks
63// from different hardware composer instances.
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070064struct ComposerCallback {
65 virtual void onHotplugReceived(int32_t sequenceId, hal::HWDisplayId, hal::Connection) = 0;
66 virtual void onRefreshReceived(int32_t sequenceId, hal::HWDisplayId) = 0;
67 virtual void onVsyncReceived(int32_t sequenceId, hal::HWDisplayId, int64_t timestamp,
68 std::optional<hal::VsyncPeriodNanos>) = 0;
69 virtual void onVsyncPeriodTimingChangedReceived(int32_t sequenceId, hal::HWDisplayId,
70 const hal::VsyncPeriodChangeTimeline&) = 0;
71 virtual void onSeamlessPossible(int32_t sequenceId, hal::HWDisplayId) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070072
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070073protected:
74 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070075};
Dan Stoza651bf312015-10-23 17:03:17 -070076
Peiyong Line9d809e2020-04-14 13:10:48 -070077// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080078class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070079public:
Ana Krulec4593b692019-01-11 22:07:25 -080080 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070081
Peiyong Line9d809e2020-04-14 13:10:48 -070082 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080083 virtual bool isConnected() const = 0;
84 virtual void setConnected(bool connected) = 0; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -070085 virtual const std::unordered_set<hal::DisplayCapability>& getCapabilities() const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070086 virtual bool isVsyncPeriodSwitchSupported() const = 0;
Dan Stoza651bf312015-10-23 17:03:17 -070087
Peiyong Line9d809e2020-04-14 13:10:48 -070088 [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0;
89 [[clang::warn_unused_result]] virtual hal::Error createLayer(Layer** outLayer) = 0;
90 [[clang::warn_unused_result]] virtual hal::Error destroyLayer(Layer* layer) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070091 [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes(
92 std::unordered_map<Layer*, hal::Composition>* outTypes) = 0;
93 [[clang::warn_unused_result]] virtual hal::Error getColorModes(
94 std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +080095 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -080096 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070097 [[clang::warn_unused_result]] virtual hal::Error getRenderIntents(
98 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
99 [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix(
100 hal::Dataspace dataspace, android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800101
Peiyong Line9d809e2020-04-14 13:10:48 -0700102 [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0;
103 [[clang::warn_unused_result]] virtual hal::Error getRequests(
104 hal::DisplayRequest* outDisplayRequests,
105 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
106 [[clang::warn_unused_result]] virtual hal::Error getConnectionType(
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100107 ui::DisplayConnectionType*) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700108 [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
109 [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800110 android::HdrCapabilities* outCapabilities) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700111 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes(
112 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800113 uint8_t* outComponentMask) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700114 [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled(
Ana Krulec4593b692019-01-11 22:07:25 -0800115 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700116 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800117 uint64_t maxFrames, uint64_t timestamp,
118 android::DisplayedFrameStats* outStats) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700119 [[clang::warn_unused_result]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800120 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700121 [[clang::warn_unused_result]] virtual hal::Error present(
Ana Krulec4593b692019-01-11 22:07:25 -0800122 android::sp<android::Fence>* outPresentFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700123 [[clang::warn_unused_result]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800124 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700125 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
126 [[clang::warn_unused_result]] virtual hal::Error setColorMode(
127 hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
128 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
129 const android::mat4& matrix, hal::ColorTransform hint) = 0;
130 [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800131 const android::sp<android::GraphicBuffer>& buffer,
132 const android::sp<android::Fence>& releaseFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700133 [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
134 [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
135 [[clang::warn_unused_result]] virtual hal::Error validate(uint32_t* outNumTypes,
136 uint32_t* outNumRequests) = 0;
137 [[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
Ana Krulec4593b692019-01-11 22:07:25 -0800138 uint32_t* outNumTypes, uint32_t* outNumRequests,
139 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700140 [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
141 float brightness) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700142 [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100143 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700144 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700145 [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700146 [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
147 std::vector<hal::ContentType>*) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700148 [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700149 [[clang::warn_unused_result]] virtual hal::Error getClientTargetProperty(
150 hal::ClientTargetProperty* outClientTargetProperty) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800151};
152
153namespace impl {
154
155class Display : public HWC2::Display {
156public:
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200157 Display(android::Hwc2::Composer&, const std::unordered_set<hal::Capability>&, hal::HWDisplayId,
158 hal::DisplayType);
Ana Krulec4593b692019-01-11 22:07:25 -0800159 ~Display() override;
160
161 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700162 hal::Error acceptChanges() override;
163 hal::Error createLayer(Layer** outLayer) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200164 hal::Error destroyLayer(Layer*) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700165 hal::Error getChangedCompositionTypes(
166 std::unordered_map<Layer*, hal::Composition>* outTypes) override;
167 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800168 // Returns a bitmask which contains HdrMetadata::Type::*.
169 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700170 hal::Error getRenderIntents(hal::ColorMode colorMode,
171 std::vector<hal::RenderIntent>* outRenderIntents) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200172 hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700173
Peiyong Line9d809e2020-04-14 13:10:48 -0700174 hal::Error getName(std::string* outName) const override;
175 hal::Error getRequests(
176 hal::DisplayRequest* outDisplayRequests,
177 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) override;
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100178 hal::Error getConnectionType(ui::DisplayConnectionType*) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700179 hal::Error supportsDoze(bool* outSupport) const override;
180 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
181 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
182 hal::Dataspace* outDataspace,
183 uint8_t* outComponentMask) const override;
184 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
185 uint64_t maxFrames) const override;
186 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
187 android::DisplayedFrameStats* outStats) const override;
188 hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800189 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700190 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700191 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
192 const android::sp<android::Fence>& acquireFence,
193 hal::Dataspace dataspace) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200194 hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700195 hal::Error setColorTransform(const android::mat4& matrix, hal::ColorTransform hint) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200196 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700197 const android::sp<android::Fence>& releaseFence) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200198 hal::Error setPowerMode(hal::PowerMode) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700199 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
200 hal::Error validate(uint32_t* outNumTypes, uint32_t* outNumRequests) override;
201 hal::Error presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests,
202 android::sp<android::Fence>* outPresentFence,
203 uint32_t* state) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700204 std::future<hal::Error> setDisplayBrightness(float brightness) override;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100205 hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId,
206 const hal::VsyncPeriodChangeConstraints& constraints,
207 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700208 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700209 hal::Error getSupportedContentTypes(
210 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700211 hal::Error setContentType(hal::ContentType) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700212 hal::Error getClientTargetProperty(hal::ClientTargetProperty* outClientTargetProperty) override;
213
Dan Stoza651bf312015-10-23 17:03:17 -0700214 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700215 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800216 bool isConnected() const override { return mIsConnected; }
217 void setConnected(bool connected) override; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -0700218 const std::unordered_set<hal::DisplayCapability>& getCapabilities() const override {
Peiyong Lined531a32018-10-26 18:27:56 -0700219 return mDisplayCapabilities;
220 };
Ady Abraham7159f572019-10-11 11:10:18 -0700221 virtual bool isVsyncPeriodSwitchSupported() const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700222
223private:
Dan Stoza651bf312015-10-23 17:03:17 -0700224
Dan Stoza651bf312015-10-23 17:03:17 -0700225 // This may fail (and return a null pointer) if no layer with this ID exists
226 // on this display
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200227 Layer* getLayerById(hal::HWLayerId) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700228
Lloyd Piquebc792092018-01-17 11:52:30 -0800229 friend android::TestableSurfaceFlinger;
230
Dan Stoza651bf312015-10-23 17:03:17 -0700231 // Member variables
232
Steven Thomas94e35b92017-07-26 18:48:28 -0700233 // These are references to data owned by HWC2::Device, which will outlive
234 // this HWC2::Display, so these references are guaranteed to be valid for
235 // the lifetime of this object.
236 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700237 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700238
Peiyong Line9d809e2020-04-14 13:10:48 -0700239 const hal::HWDisplayId mId;
240 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800241 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700242
Peiyong Line9d809e2020-04-14 13:10:48 -0700243 std::unordered_map<hal::HWLayerId, std::unique_ptr<Layer>> mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700244
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700245 std::once_flag mDisplayCapabilityQueryFlag;
Peiyong Line9d809e2020-04-14 13:10:48 -0700246 std::unordered_set<hal::DisplayCapability> mDisplayCapabilities;
Dan Stoza651bf312015-10-23 17:03:17 -0700247};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800248
Ana Krulec4593b692019-01-11 22:07:25 -0800249} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700250
Lloyd Pique35d58242018-12-18 16:33:25 -0800251class Layer {
252public:
253 virtual ~Layer();
254
Peiyong Line9d809e2020-04-14 13:10:48 -0700255 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800256
Peiyong Line9d809e2020-04-14 13:10:48 -0700257 [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
258 [[clang::warn_unused_result]] virtual hal::Error setBuffer(
Lloyd Pique35d58242018-12-18 16:33:25 -0800259 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
260 const android::sp<android::Fence>& acquireFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700261 [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage(
262 const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800263
Peiyong Line9d809e2020-04-14 13:10:48 -0700264 [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
265 [[clang::warn_unused_result]] virtual hal::Error setColor(hal::Color color) = 0;
266 [[clang::warn_unused_result]] virtual hal::Error setCompositionType(hal::Composition type) = 0;
267 [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
268 [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata(
Lloyd Pique35d58242018-12-18 16:33:25 -0800269 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700270 [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame(
271 const android::Rect& frame) = 0;
272 [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
273 [[clang::warn_unused_result]] virtual hal::Error setSidebandStream(
Lloyd Pique35d58242018-12-18 16:33:25 -0800274 const native_handle_t* stream) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700275 [[clang::warn_unused_result]] virtual hal::Error setSourceCrop(
276 const android::FloatRect& crop) = 0;
277 [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0;
278 [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion(
279 const android::Region& region) = 0;
280 [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800281
282 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700283 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
284 const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800285
286 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700287 [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata(
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800288 const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800289};
290
291namespace impl {
292
Peiyong Line9d809e2020-04-14 13:10:48 -0700293// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800294
295class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700296public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700297 Layer(android::Hwc2::Composer& composer,
298 const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId displayId,
299 hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800300 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700301
Peiyong Line9d809e2020-04-14 13:10:48 -0700302 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700303
Peiyong Line9d809e2020-04-14 13:10:48 -0700304 hal::Error setCursorPosition(int32_t x, int32_t y) override;
305 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
306 const android::sp<android::Fence>& acquireFence) override;
307 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700308
Peiyong Line9d809e2020-04-14 13:10:48 -0700309 hal::Error setBlendMode(hal::BlendMode mode) override;
310 hal::Error setColor(hal::Color color) override;
311 hal::Error setCompositionType(hal::Composition type) override;
312 hal::Error setDataspace(hal::Dataspace dataspace) override;
313 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
314 const android::HdrMetadata& metadata) override;
315 hal::Error setDisplayFrame(const android::Rect& frame) override;
316 hal::Error setPlaneAlpha(float alpha) override;
317 hal::Error setSidebandStream(const native_handle_t* stream) override;
318 hal::Error setSourceCrop(const android::FloatRect& crop) override;
319 hal::Error setTransform(hal::Transform transform) override;
320 hal::Error setVisibleRegion(const android::Region& region) override;
321 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700322
Peiyong Lin698147a2018-09-14 13:27:18 -0700323 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700324 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700325
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800326 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700327 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
328 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800329
Dan Stoza651bf312015-10-23 17:03:17 -0700330private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700331 // These are references to data owned by HWC2::Device, which will outlive
332 // this HWC2::Layer, so these references are guaranteed to be valid for
333 // the lifetime of this object.
334 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700335 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700336
Peiyong Line9d809e2020-04-14 13:10:48 -0700337 hal::HWDisplayId mDisplayId;
338 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800339
340 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
341 // multiple times.
342 android::Region mVisibleRegion = android::Region::INVALID_REGION;
343 android::Region mDamageRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700344 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700345 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700346 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800347 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700348};
349
Lloyd Pique35d58242018-12-18 16:33:25 -0800350} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700351} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700352} // namespace android