blob: fae95e79c3f07ed956f03b4ca12c246eca533a47 [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 Pique1b33fc32021-05-07 14:36:58 -070019#include <android-base/expected.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070020#include <gui/HdrMetadata.h>
Mathias Agopian1d77b712017-02-17 15:46:13 -080021#include <math/mat4.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070022#include <ui/HdrCapabilities.h>
Yichi Chen8366f562019-03-25 19:44:06 +080023#include <ui/Region.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010024#include <ui/StaticDisplayInfo.h>
Dan Stoza651bf312015-10-23 17:03:17 -070025#include <utils/Log.h>
26#include <utils/StrongPointer.h>
27#include <utils/Timers.h>
28
29#include <functional>
Dominik Laskowski5690bde2020-04-23 19:04:22 -070030#include <future>
Dan Stoza651bf312015-10-23 17:03:17 -070031#include <string>
32#include <unordered_map>
Dan Stoza9f26a9c2016-06-22 14:51:09 -070033#include <unordered_set>
Dan Stoza651bf312015-10-23 17:03:17 -070034#include <vector>
35
Peiyong Line9d809e2020-04-14 13:10:48 -070036#include "Hal.h"
37
Dan Stoza651bf312015-10-23 17:03:17 -070038namespace android {
Lloyd Piquebc792092018-01-17 11:52:30 -080039
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070040class Fence;
41class FloatRect;
42class GraphicBuffer;
43class TestableSurfaceFlinger;
44struct DisplayedFrameStats;
45
46namespace Hwc2 {
47class Composer;
48} // namespace Hwc2
Dan Stoza651bf312015-10-23 17:03:17 -070049
50namespace HWC2 {
51
Dan Stoza651bf312015-10-23 17:03:17 -070052class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070053
54namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070055
Steven Thomas94e35b92017-07-26 18:48:28 -070056// Implement this interface to receive hardware composer events.
57//
58// These callback functions will generally be called on a hwbinder thread, but
59// when first registering the callback the onHotplugReceived() function will
60// immediately be called on the thread calling registerCallback().
61//
62// All calls receive a sequenceId, which will be the value that was supplied to
63// HWC2::Device::registerCallback(). It's used to help differentiate callbacks
64// from different hardware composer instances.
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070065struct ComposerCallback {
66 virtual void onHotplugReceived(int32_t sequenceId, hal::HWDisplayId, hal::Connection) = 0;
67 virtual void onRefreshReceived(int32_t sequenceId, hal::HWDisplayId) = 0;
68 virtual void onVsyncReceived(int32_t sequenceId, hal::HWDisplayId, int64_t timestamp,
69 std::optional<hal::VsyncPeriodNanos>) = 0;
70 virtual void onVsyncPeriodTimingChangedReceived(int32_t sequenceId, hal::HWDisplayId,
71 const hal::VsyncPeriodChangeTimeline&) = 0;
72 virtual void onSeamlessPossible(int32_t sequenceId, 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
Peiyong Line9d809e2020-04-14 13:10:48 -070086 virtual const std::unordered_set<hal::DisplayCapability>& getCapabilities() const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070087 virtual bool isVsyncPeriodSwitchSupported() const = 0;
Lloyd Pique1b33fc32021-05-07 14:36:58 -070088 virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0;
Dan Stoza651bf312015-10-23 17:03:17 -070089
Peiyong Line9d809e2020-04-14 13:10:48 -070090 [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0;
Lloyd Pique1b33fc32021-05-07 14:36:58 -070091 [[clang::warn_unused_result]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error>
92 createLayer() = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070093 [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes(
94 std::unordered_map<Layer*, hal::Composition>* outTypes) = 0;
95 [[clang::warn_unused_result]] virtual hal::Error getColorModes(
96 std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +080097 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -080098 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070099 [[clang::warn_unused_result]] virtual hal::Error getRenderIntents(
100 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
101 [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix(
102 hal::Dataspace dataspace, android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800103
Peiyong Line9d809e2020-04-14 13:10:48 -0700104 [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0;
105 [[clang::warn_unused_result]] virtual hal::Error getRequests(
106 hal::DisplayRequest* outDisplayRequests,
107 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
108 [[clang::warn_unused_result]] virtual hal::Error getConnectionType(
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100109 ui::DisplayConnectionType*) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700110 [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
111 [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800112 android::HdrCapabilities* outCapabilities) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700113 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes(
114 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800115 uint8_t* outComponentMask) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700116 [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled(
Ana Krulec4593b692019-01-11 22:07:25 -0800117 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700118 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800119 uint64_t maxFrames, uint64_t timestamp,
120 android::DisplayedFrameStats* outStats) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700121 [[clang::warn_unused_result]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800122 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700123 [[clang::warn_unused_result]] virtual hal::Error present(
Ana Krulec4593b692019-01-11 22:07:25 -0800124 android::sp<android::Fence>* outPresentFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700125 [[clang::warn_unused_result]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800126 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700127 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
128 [[clang::warn_unused_result]] virtual hal::Error setColorMode(
129 hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
130 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
131 const android::mat4& matrix, hal::ColorTransform hint) = 0;
132 [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800133 const android::sp<android::GraphicBuffer>& buffer,
134 const android::sp<android::Fence>& releaseFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700135 [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
136 [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
137 [[clang::warn_unused_result]] virtual hal::Error validate(uint32_t* outNumTypes,
138 uint32_t* outNumRequests) = 0;
139 [[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
Ana Krulec4593b692019-01-11 22:07:25 -0800140 uint32_t* outNumTypes, uint32_t* outNumRequests,
141 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700142 [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
143 float brightness) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700144 [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100145 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700146 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700147 [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700148 [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
149 std::vector<hal::ContentType>*) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700150 [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700151 [[clang::warn_unused_result]] virtual hal::Error getClientTargetProperty(
152 hal::ClientTargetProperty* outClientTargetProperty) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800153};
154
155namespace impl {
156
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700157class Layer;
158
Ana Krulec4593b692019-01-11 22:07:25 -0800159class Display : public HWC2::Display {
160public:
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200161 Display(android::Hwc2::Composer&, const std::unordered_set<hal::Capability>&, hal::HWDisplayId,
162 hal::DisplayType);
Ana Krulec4593b692019-01-11 22:07:25 -0800163 ~Display() override;
164
165 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700166 hal::Error acceptChanges() override;
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700167 base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700168 hal::Error getChangedCompositionTypes(
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700169 std::unordered_map<HWC2::Layer*, hal::Composition>* outTypes) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700170 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800171 // Returns a bitmask which contains HdrMetadata::Type::*.
172 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700173 hal::Error getRenderIntents(hal::ColorMode colorMode,
174 std::vector<hal::RenderIntent>* outRenderIntents) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200175 hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700176
Peiyong Line9d809e2020-04-14 13:10:48 -0700177 hal::Error getName(std::string* outName) const override;
178 hal::Error getRequests(
179 hal::DisplayRequest* outDisplayRequests,
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700180 std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override;
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100181 hal::Error getConnectionType(ui::DisplayConnectionType*) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700182 hal::Error supportsDoze(bool* outSupport) const override;
183 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
184 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
185 hal::Dataspace* outDataspace,
186 uint8_t* outComponentMask) const override;
187 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
188 uint64_t maxFrames) const override;
189 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
190 android::DisplayedFrameStats* outStats) const override;
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700191 hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>*
192 outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700193 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700194 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
195 const android::sp<android::Fence>& acquireFence,
196 hal::Dataspace dataspace) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200197 hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700198 hal::Error setColorTransform(const android::mat4& matrix, hal::ColorTransform hint) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200199 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700200 const android::sp<android::Fence>& releaseFence) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200201 hal::Error setPowerMode(hal::PowerMode) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700202 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
203 hal::Error validate(uint32_t* outNumTypes, uint32_t* outNumRequests) override;
204 hal::Error presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests,
205 android::sp<android::Fence>* outPresentFence,
206 uint32_t* state) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700207 std::future<hal::Error> setDisplayBrightness(float brightness) override;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100208 hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId,
209 const hal::VsyncPeriodChangeConstraints& constraints,
210 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700211 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700212 hal::Error getSupportedContentTypes(
213 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700214 hal::Error setContentType(hal::ContentType) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700215 hal::Error getClientTargetProperty(hal::ClientTargetProperty* outClientTargetProperty) override;
216
Dan Stoza651bf312015-10-23 17:03:17 -0700217 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700218 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800219 bool isConnected() const override { return mIsConnected; }
220 void setConnected(bool connected) override; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -0700221 const std::unordered_set<hal::DisplayCapability>& getCapabilities() const override {
Peiyong Lined531a32018-10-26 18:27:56 -0700222 return mDisplayCapabilities;
223 };
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700224 bool isVsyncPeriodSwitchSupported() const override;
225 void onLayerDestroyed(hal::HWLayerId layerId) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700226
227private:
Dan Stoza651bf312015-10-23 17:03:17 -0700228
Dan Stoza651bf312015-10-23 17:03:17 -0700229 // This may fail (and return a null pointer) if no layer with this ID exists
230 // on this display
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700231 std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700232
Lloyd Piquebc792092018-01-17 11:52:30 -0800233 friend android::TestableSurfaceFlinger;
234
Dan Stoza651bf312015-10-23 17:03:17 -0700235 // Member variables
236
Steven Thomas94e35b92017-07-26 18:48:28 -0700237 // These are references to data owned by HWC2::Device, which will outlive
238 // this HWC2::Display, so these references are guaranteed to be valid for
239 // the lifetime of this object.
240 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700241 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700242
Peiyong Line9d809e2020-04-14 13:10:48 -0700243 const hal::HWDisplayId mId;
244 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800245 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700246
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700247 using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>;
248 Layers mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700249
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700250 std::once_flag mDisplayCapabilityQueryFlag;
Peiyong Line9d809e2020-04-14 13:10:48 -0700251 std::unordered_set<hal::DisplayCapability> mDisplayCapabilities;
Dan Stoza651bf312015-10-23 17:03:17 -0700252};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800253
Ana Krulec4593b692019-01-11 22:07:25 -0800254} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700255
Lloyd Pique35d58242018-12-18 16:33:25 -0800256class Layer {
257public:
258 virtual ~Layer();
259
Peiyong Line9d809e2020-04-14 13:10:48 -0700260 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800261
Peiyong Line9d809e2020-04-14 13:10:48 -0700262 [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
263 [[clang::warn_unused_result]] virtual hal::Error setBuffer(
Lloyd Pique35d58242018-12-18 16:33:25 -0800264 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
265 const android::sp<android::Fence>& acquireFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700266 [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage(
267 const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800268
Peiyong Line9d809e2020-04-14 13:10:48 -0700269 [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
270 [[clang::warn_unused_result]] virtual hal::Error setColor(hal::Color color) = 0;
271 [[clang::warn_unused_result]] virtual hal::Error setCompositionType(hal::Composition type) = 0;
272 [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
273 [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata(
Lloyd Pique35d58242018-12-18 16:33:25 -0800274 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700275 [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame(
276 const android::Rect& frame) = 0;
277 [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
278 [[clang::warn_unused_result]] virtual hal::Error setSidebandStream(
Lloyd Pique35d58242018-12-18 16:33:25 -0800279 const native_handle_t* stream) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700280 [[clang::warn_unused_result]] virtual hal::Error setSourceCrop(
281 const android::FloatRect& crop) = 0;
282 [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0;
283 [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion(
284 const android::Region& region) = 0;
285 [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800286
287 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700288 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
289 const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800290
291 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700292 [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata(
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800293 const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800294};
295
296namespace impl {
297
Peiyong Line9d809e2020-04-14 13:10:48 -0700298// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800299
300class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700301public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700302 Layer(android::Hwc2::Composer& composer,
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700303 const std::unordered_set<hal::Capability>& capabilities, HWC2::Display& display,
Peiyong Line9d809e2020-04-14 13:10:48 -0700304 hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800305 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700306
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700307 void onOwningDisplayDestroyed();
308
Peiyong Line9d809e2020-04-14 13:10:48 -0700309 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700310
Peiyong Line9d809e2020-04-14 13:10:48 -0700311 hal::Error setCursorPosition(int32_t x, int32_t y) override;
312 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
313 const android::sp<android::Fence>& acquireFence) override;
314 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700315
Peiyong Line9d809e2020-04-14 13:10:48 -0700316 hal::Error setBlendMode(hal::BlendMode mode) override;
317 hal::Error setColor(hal::Color color) override;
318 hal::Error setCompositionType(hal::Composition type) override;
319 hal::Error setDataspace(hal::Dataspace dataspace) override;
320 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
321 const android::HdrMetadata& metadata) override;
322 hal::Error setDisplayFrame(const android::Rect& frame) override;
323 hal::Error setPlaneAlpha(float alpha) override;
324 hal::Error setSidebandStream(const native_handle_t* stream) override;
325 hal::Error setSourceCrop(const android::FloatRect& crop) override;
326 hal::Error setTransform(hal::Transform transform) override;
327 hal::Error setVisibleRegion(const android::Region& region) override;
328 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700329
Peiyong Lin698147a2018-09-14 13:27:18 -0700330 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700331 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700332
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800333 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700334 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
335 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800336
Dan Stoza651bf312015-10-23 17:03:17 -0700337private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700338 // These are references to data owned by HWC2::Device, which will outlive
339 // this HWC2::Layer, so these references are guaranteed to be valid for
340 // the lifetime of this object.
341 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700342 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700343
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700344 HWC2::Display* mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700345 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800346
347 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
348 // multiple times.
349 android::Region mVisibleRegion = android::Region::INVALID_REGION;
350 android::Region mDamageRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700351 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700352 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700353 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800354 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700355};
356
Lloyd Pique35d58242018-12-18 16:33:25 -0800357} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700358} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700359} // namespace android