blob: 871465d7172468da8a1120fe893b73309804f971 [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>
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
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070059// when first registering the callback the onComposerHalHotplug() function will
Steven Thomas94e35b92017-07-26 18:48:28 -070060// immediately be called on the thread calling registerCallback().
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070061struct ComposerCallback {
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070062 virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0;
63 virtual void onComposerHalRefresh(hal::HWDisplayId) = 0;
64 virtual void onComposerHalVsync(hal::HWDisplayId, int64_t timestamp,
65 std::optional<hal::VsyncPeriodNanos>) = 0;
66 virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId,
67 const hal::VsyncPeriodChangeTimeline&) = 0;
68 virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070069
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070070protected:
71 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070072};
Dan Stoza651bf312015-10-23 17:03:17 -070073
Peiyong Line9d809e2020-04-14 13:10:48 -070074// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080075class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070076public:
Ana Krulec4593b692019-01-11 22:07:25 -080077 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070078
Peiyong Line9d809e2020-04-14 13:10:48 -070079 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080080 virtual bool isConnected() const = 0;
81 virtual void setConnected(bool connected) = 0; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -070082 virtual const std::unordered_set<hal::DisplayCapability>& getCapabilities() const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070083 virtual bool isVsyncPeriodSwitchSupported() const = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070084 virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0;
Dan Stoza651bf312015-10-23 17:03:17 -070085
Peiyong Line9d809e2020-04-14 13:10:48 -070086 [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070087 [[clang::warn_unused_result]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error>
88 createLayer() = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070089 [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes(
90 std::unordered_map<Layer*, hal::Composition>* outTypes) = 0;
91 [[clang::warn_unused_result]] virtual hal::Error getColorModes(
92 std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +080093 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -080094 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070095 [[clang::warn_unused_result]] virtual hal::Error getRenderIntents(
96 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
97 [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix(
98 hal::Dataspace dataspace, android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080099
Peiyong Line9d809e2020-04-14 13:10:48 -0700100 [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0;
101 [[clang::warn_unused_result]] virtual hal::Error getRequests(
102 hal::DisplayRequest* outDisplayRequests,
103 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
104 [[clang::warn_unused_result]] virtual hal::Error getConnectionType(
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100105 ui::DisplayConnectionType*) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700106 [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
107 [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800108 android::HdrCapabilities* outCapabilities) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700109 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes(
110 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800111 uint8_t* outComponentMask) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700112 [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled(
Ana Krulec4593b692019-01-11 22:07:25 -0800113 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700114 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800115 uint64_t maxFrames, uint64_t timestamp,
116 android::DisplayedFrameStats* outStats) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700117 [[clang::warn_unused_result]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800118 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700119 [[clang::warn_unused_result]] virtual hal::Error present(
Ana Krulec4593b692019-01-11 22:07:25 -0800120 android::sp<android::Fence>* outPresentFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700121 [[clang::warn_unused_result]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800122 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700123 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
124 [[clang::warn_unused_result]] virtual hal::Error setColorMode(
125 hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
126 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
127 const android::mat4& matrix, hal::ColorTransform hint) = 0;
128 [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800129 const android::sp<android::GraphicBuffer>& buffer,
130 const android::sp<android::Fence>& releaseFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700131 [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
132 [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
133 [[clang::warn_unused_result]] virtual hal::Error validate(uint32_t* outNumTypes,
134 uint32_t* outNumRequests) = 0;
135 [[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
Ana Krulec4593b692019-01-11 22:07:25 -0800136 uint32_t* outNumTypes, uint32_t* outNumRequests,
137 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700138 [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
139 float brightness) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700140 [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100141 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700142 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700143 [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700144 [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
145 std::vector<hal::ContentType>*) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700146 [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700147 [[clang::warn_unused_result]] virtual hal::Error getClientTargetProperty(
148 hal::ClientTargetProperty* outClientTargetProperty) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800149};
150
151namespace impl {
152
Lloyd Piquea516c002021-05-07 14:36:58 -0700153class Layer;
154
Ana Krulec4593b692019-01-11 22:07:25 -0800155class 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;
Lloyd Piquea516c002021-05-07 14:36:58 -0700163 base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700164 hal::Error getChangedCompositionTypes(
Lloyd Piquea516c002021-05-07 14:36:58 -0700165 std::unordered_map<HWC2::Layer*, hal::Composition>* outTypes) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700166 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800167 // Returns a bitmask which contains HdrMetadata::Type::*.
168 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700169 hal::Error getRenderIntents(hal::ColorMode colorMode,
170 std::vector<hal::RenderIntent>* outRenderIntents) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200171 hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700172
Peiyong Line9d809e2020-04-14 13:10:48 -0700173 hal::Error getName(std::string* outName) const override;
174 hal::Error getRequests(
175 hal::DisplayRequest* outDisplayRequests,
Lloyd Piquea516c002021-05-07 14:36:58 -0700176 std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override;
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100177 hal::Error getConnectionType(ui::DisplayConnectionType*) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700178 hal::Error supportsDoze(bool* outSupport) const override;
179 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
180 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
181 hal::Dataspace* outDataspace,
182 uint8_t* outComponentMask) const override;
183 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
184 uint64_t maxFrames) const override;
185 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
186 android::DisplayedFrameStats* outStats) const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700187 hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>*
188 outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700189 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700190 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
191 const android::sp<android::Fence>& acquireFence,
192 hal::Dataspace dataspace) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200193 hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700194 hal::Error setColorTransform(const android::mat4& matrix, hal::ColorTransform hint) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200195 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700196 const android::sp<android::Fence>& releaseFence) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200197 hal::Error setPowerMode(hal::PowerMode) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700198 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
199 hal::Error validate(uint32_t* outNumTypes, uint32_t* outNumRequests) override;
200 hal::Error presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests,
201 android::sp<android::Fence>* outPresentFence,
202 uint32_t* state) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700203 std::future<hal::Error> setDisplayBrightness(float brightness) override;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100204 hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId,
205 const hal::VsyncPeriodChangeConstraints& constraints,
206 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700207 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700208 hal::Error getSupportedContentTypes(
209 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700210 hal::Error setContentType(hal::ContentType) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700211 hal::Error getClientTargetProperty(hal::ClientTargetProperty* outClientTargetProperty) override;
212
Dan Stoza651bf312015-10-23 17:03:17 -0700213 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700214 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800215 bool isConnected() const override { return mIsConnected; }
216 void setConnected(bool connected) override; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -0700217 const std::unordered_set<hal::DisplayCapability>& getCapabilities() const override {
Peiyong Lined531a32018-10-26 18:27:56 -0700218 return mDisplayCapabilities;
219 };
Lloyd Piquea516c002021-05-07 14:36:58 -0700220 bool isVsyncPeriodSwitchSupported() const override;
221 void onLayerDestroyed(hal::HWLayerId layerId) 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
Lloyd Piquea516c002021-05-07 14:36:58 -0700227 std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) 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
Lloyd Piquea516c002021-05-07 14:36:58 -0700243 using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>;
244 Layers mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700245
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700246 std::once_flag mDisplayCapabilityQueryFlag;
Peiyong Line9d809e2020-04-14 13:10:48 -0700247 std::unordered_set<hal::DisplayCapability> mDisplayCapabilities;
Dan Stoza651bf312015-10-23 17:03:17 -0700248};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800249
Ana Krulec4593b692019-01-11 22:07:25 -0800250} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700251
Lloyd Pique35d58242018-12-18 16:33:25 -0800252class Layer {
253public:
254 virtual ~Layer();
255
Peiyong Line9d809e2020-04-14 13:10:48 -0700256 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800257
Peiyong Line9d809e2020-04-14 13:10:48 -0700258 [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
259 [[clang::warn_unused_result]] virtual hal::Error setBuffer(
Lloyd Pique35d58242018-12-18 16:33:25 -0800260 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
261 const android::sp<android::Fence>& acquireFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700262 [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage(
263 const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800264
Peiyong Line9d809e2020-04-14 13:10:48 -0700265 [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
266 [[clang::warn_unused_result]] virtual hal::Error setColor(hal::Color color) = 0;
267 [[clang::warn_unused_result]] virtual hal::Error setCompositionType(hal::Composition type) = 0;
268 [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
269 [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata(
Lloyd Pique35d58242018-12-18 16:33:25 -0800270 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700271 [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame(
272 const android::Rect& frame) = 0;
273 [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
274 [[clang::warn_unused_result]] virtual hal::Error setSidebandStream(
Lloyd Pique35d58242018-12-18 16:33:25 -0800275 const native_handle_t* stream) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700276 [[clang::warn_unused_result]] virtual hal::Error setSourceCrop(
277 const android::FloatRect& crop) = 0;
278 [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0;
279 [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion(
280 const android::Region& region) = 0;
281 [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800282
283 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700284 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
285 const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800286
287 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700288 [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata(
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800289 const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800290};
291
292namespace impl {
293
Peiyong Line9d809e2020-04-14 13:10:48 -0700294// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800295
296class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700297public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700298 Layer(android::Hwc2::Composer& composer,
Lloyd Piquea516c002021-05-07 14:36:58 -0700299 const std::unordered_set<hal::Capability>& capabilities, HWC2::Display& display,
Peiyong Line9d809e2020-04-14 13:10:48 -0700300 hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800301 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700302
Lloyd Piquea516c002021-05-07 14:36:58 -0700303 void onOwningDisplayDestroyed();
304
Peiyong Line9d809e2020-04-14 13:10:48 -0700305 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700306
Peiyong Line9d809e2020-04-14 13:10:48 -0700307 hal::Error setCursorPosition(int32_t x, int32_t y) override;
308 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
309 const android::sp<android::Fence>& acquireFence) override;
310 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700311
Peiyong Line9d809e2020-04-14 13:10:48 -0700312 hal::Error setBlendMode(hal::BlendMode mode) override;
313 hal::Error setColor(hal::Color color) override;
314 hal::Error setCompositionType(hal::Composition type) override;
315 hal::Error setDataspace(hal::Dataspace dataspace) override;
316 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
317 const android::HdrMetadata& metadata) override;
318 hal::Error setDisplayFrame(const android::Rect& frame) override;
319 hal::Error setPlaneAlpha(float alpha) override;
320 hal::Error setSidebandStream(const native_handle_t* stream) override;
321 hal::Error setSourceCrop(const android::FloatRect& crop) override;
322 hal::Error setTransform(hal::Transform transform) override;
323 hal::Error setVisibleRegion(const android::Region& region) override;
324 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700325
Peiyong Lin698147a2018-09-14 13:27:18 -0700326 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700327 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700328
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800329 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700330 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
331 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800332
Dan Stoza651bf312015-10-23 17:03:17 -0700333private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700334 // These are references to data owned by HWC2::Device, which will outlive
335 // this HWC2::Layer, so these references are guaranteed to be valid for
336 // the lifetime of this object.
337 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700338 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700339
Lloyd Piquea516c002021-05-07 14:36:58 -0700340 HWC2::Display* mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700341 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800342
343 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
344 // multiple times.
345 android::Region mVisibleRegion = android::Region::INVALID_REGION;
346 android::Region mDamageRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700347 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700348 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700349 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800350 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700351};
352
Lloyd Pique35d58242018-12-18 16:33:25 -0800353} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700354} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700355} // namespace android