blob: a65efb2931df52f48726f83ac470e7c0e979ff1c [file] [log] [blame]
Dan Stoza651bf312015-10-23 17:03:17 -07001/*
2 * Copyright 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070017#pragma once
Dan Stoza651bf312015-10-23 17:03:17 -070018
Lloyd Piquea516c002021-05-07 14:36:58 -070019#include <android-base/expected.h>
Ady Abraham27fbcc72021-09-20 14:54:57 -070020#include <android-base/thread_annotations.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070021#include <gui/HdrMetadata.h>
Mathias Agopian1d77b712017-02-17 15:46:13 -080022#include <math/mat4.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070023#include <ui/HdrCapabilities.h>
Yichi Chen8366f562019-03-25 19:44:06 +080024#include <ui/Region.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010025#include <ui/StaticDisplayInfo.h>
Dan Stoza651bf312015-10-23 17:03:17 -070026#include <utils/Log.h>
27#include <utils/StrongPointer.h>
28#include <utils/Timers.h>
29
30#include <functional>
Dominik Laskowski5690bde2020-04-23 19:04:22 -070031#include <future>
Dan Stoza651bf312015-10-23 17:03:17 -070032#include <string>
33#include <unordered_map>
Dan Stoza9f26a9c2016-06-22 14:51:09 -070034#include <unordered_set>
Dan Stoza651bf312015-10-23 17:03:17 -070035#include <vector>
36
Peiyong Line9d809e2020-04-14 13:10:48 -070037#include "Hal.h"
38
Dan Stoza651bf312015-10-23 17:03:17 -070039namespace android {
Lloyd Piquebc792092018-01-17 11:52:30 -080040
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070041class Fence;
42class FloatRect;
43class GraphicBuffer;
44class TestableSurfaceFlinger;
45struct DisplayedFrameStats;
46
47namespace Hwc2 {
48class Composer;
49} // namespace Hwc2
Dan Stoza651bf312015-10-23 17:03:17 -070050
51namespace HWC2 {
52
Dan Stoza651bf312015-10-23 17:03:17 -070053class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070054
55namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070056
Steven Thomas94e35b92017-07-26 18:48:28 -070057// Implement this interface to receive hardware composer events.
58//
59// These callback functions will generally be called on a hwbinder thread, but
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070060// when first registering the callback the onComposerHalHotplug() function will
Steven Thomas94e35b92017-07-26 18:48:28 -070061// immediately be called on the thread calling registerCallback().
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070062struct ComposerCallback {
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070063 virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0;
64 virtual void onComposerHalRefresh(hal::HWDisplayId) = 0;
65 virtual void onComposerHalVsync(hal::HWDisplayId, int64_t timestamp,
66 std::optional<hal::VsyncPeriodNanos>) = 0;
67 virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId,
68 const hal::VsyncPeriodChangeTimeline&) = 0;
69 virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070070
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070071protected:
72 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070073};
Dan Stoza651bf312015-10-23 17:03:17 -070074
Peiyong Line9d809e2020-04-14 13:10:48 -070075// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080076class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070077public:
Ana Krulec4593b692019-01-11 22:07:25 -080078 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070079
Peiyong Line9d809e2020-04-14 13:10:48 -070080 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080081 virtual bool isConnected() const = 0;
82 virtual void setConnected(bool connected) = 0; // For use by Device only
Ady Abraham27fbcc72021-09-20 14:54:57 -070083 virtual bool hasCapability(hal::DisplayCapability) const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070084 virtual bool isVsyncPeriodSwitchSupported() const = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070085 virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0;
Dan Stoza651bf312015-10-23 17:03:17 -070086
Peiyong Line9d809e2020-04-14 13:10:48 -070087 [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070088 [[clang::warn_unused_result]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error>
89 createLayer() = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070090 [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes(
91 std::unordered_map<Layer*, hal::Composition>* outTypes) = 0;
92 [[clang::warn_unused_result]] virtual hal::Error getColorModes(
93 std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +080094 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -080095 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070096 [[clang::warn_unused_result]] virtual hal::Error getRenderIntents(
97 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
98 [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix(
99 hal::Dataspace dataspace, android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800100
Peiyong Line9d809e2020-04-14 13:10:48 -0700101 [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0;
102 [[clang::warn_unused_result]] virtual hal::Error getRequests(
103 hal::DisplayRequest* outDisplayRequests,
104 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
105 [[clang::warn_unused_result]] virtual hal::Error getConnectionType(
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100106 ui::DisplayConnectionType*) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700107 [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
108 [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800109 android::HdrCapabilities* outCapabilities) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700110 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes(
111 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800112 uint8_t* outComponentMask) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700113 [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled(
Ana Krulec4593b692019-01-11 22:07:25 -0800114 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700115 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800116 uint64_t maxFrames, uint64_t timestamp,
117 android::DisplayedFrameStats* outStats) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700118 [[clang::warn_unused_result]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800119 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700120 [[clang::warn_unused_result]] virtual hal::Error present(
Ana Krulec4593b692019-01-11 22:07:25 -0800121 android::sp<android::Fence>* outPresentFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700122 [[clang::warn_unused_result]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800123 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700124 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
125 [[clang::warn_unused_result]] virtual hal::Error setColorMode(
126 hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
127 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
128 const android::mat4& matrix, hal::ColorTransform hint) = 0;
129 [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800130 const android::sp<android::GraphicBuffer>& buffer,
131 const android::sp<android::Fence>& releaseFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700132 [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
133 [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
134 [[clang::warn_unused_result]] virtual hal::Error validate(uint32_t* outNumTypes,
135 uint32_t* outNumRequests) = 0;
136 [[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
Ana Krulec4593b692019-01-11 22:07:25 -0800137 uint32_t* outNumTypes, uint32_t* outNumRequests,
138 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700139 [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
140 float brightness) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700141 [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100142 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700143 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700144 [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700145 [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
146 std::vector<hal::ContentType>*) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700147 [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700148 [[clang::warn_unused_result]] virtual hal::Error getClientTargetProperty(
149 hal::ClientTargetProperty* outClientTargetProperty) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800150};
151
152namespace impl {
153
Lloyd Piquea516c002021-05-07 14:36:58 -0700154class Layer;
155
Ana Krulec4593b692019-01-11 22:07:25 -0800156class Display : public HWC2::Display {
157public:
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200158 Display(android::Hwc2::Composer&, const std::unordered_set<hal::Capability>&, hal::HWDisplayId,
159 hal::DisplayType);
Ana Krulec4593b692019-01-11 22:07:25 -0800160 ~Display() override;
161
162 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700163 hal::Error acceptChanges() override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700164 base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700165 hal::Error getChangedCompositionTypes(
Lloyd Piquea516c002021-05-07 14:36:58 -0700166 std::unordered_map<HWC2::Layer*, hal::Composition>* outTypes) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700167 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,
Lloyd Piquea516c002021-05-07 14:36:58 -0700177 std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override;
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100178 hal::Error getConnectionType(ui::DisplayConnectionType*) const override;
Ady Abraham27fbcc72021-09-20 14:54:57 -0700179 hal::Error supportsDoze(bool* outSupport) const override EXCLUDES(mDisplayCapabilitiesMutex);
Peiyong Line9d809e2020-04-14 13:10:48 -0700180 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;
Lloyd Piquea516c002021-05-07 14:36:58 -0700188 hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>*
189 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
Ady Abraham27fbcc72021-09-20 14:54:57 -0700218 bool hasCapability(hal::DisplayCapability) const override EXCLUDES(mDisplayCapabilitiesMutex);
Lloyd Piquea516c002021-05-07 14:36:58 -0700219 bool isVsyncPeriodSwitchSupported() const override;
220 void onLayerDestroyed(hal::HWLayerId layerId) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700221
222private:
Dan Stoza651bf312015-10-23 17:03:17 -0700223
Dan Stoza651bf312015-10-23 17:03:17 -0700224 // This may fail (and return a null pointer) if no layer with this ID exists
225 // on this display
Lloyd Piquea516c002021-05-07 14:36:58 -0700226 std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700227
Lloyd Piquebc792092018-01-17 11:52:30 -0800228 friend android::TestableSurfaceFlinger;
229
Dan Stoza651bf312015-10-23 17:03:17 -0700230 // Member variables
231
Steven Thomas94e35b92017-07-26 18:48:28 -0700232 // These are references to data owned by HWC2::Device, which will outlive
233 // this HWC2::Display, so these references are guaranteed to be valid for
234 // the lifetime of this object.
235 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700236 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700237
Peiyong Line9d809e2020-04-14 13:10:48 -0700238 const hal::HWDisplayId mId;
239 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800240 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700241
Lloyd Piquea516c002021-05-07 14:36:58 -0700242 using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>;
243 Layers mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700244
Ady Abraham27fbcc72021-09-20 14:54:57 -0700245 mutable std::mutex mDisplayCapabilitiesMutex;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700246 std::once_flag mDisplayCapabilityQueryFlag;
Ady Abraham27fbcc72021-09-20 14:54:57 -0700247 std::optional<std::unordered_set<hal::DisplayCapability>> mDisplayCapabilities
248 GUARDED_BY(mDisplayCapabilitiesMutex);
Dan Stoza651bf312015-10-23 17:03:17 -0700249};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800250
Ana Krulec4593b692019-01-11 22:07:25 -0800251} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700252
Lloyd Pique35d58242018-12-18 16:33:25 -0800253class Layer {
254public:
255 virtual ~Layer();
256
Peiyong Line9d809e2020-04-14 13:10:48 -0700257 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800258
Peiyong Line9d809e2020-04-14 13:10:48 -0700259 [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
260 [[clang::warn_unused_result]] virtual hal::Error setBuffer(
Lloyd Pique35d58242018-12-18 16:33:25 -0800261 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
262 const android::sp<android::Fence>& acquireFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700263 [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage(
264 const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800265
Peiyong Line9d809e2020-04-14 13:10:48 -0700266 [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
267 [[clang::warn_unused_result]] virtual hal::Error setColor(hal::Color color) = 0;
268 [[clang::warn_unused_result]] virtual hal::Error setCompositionType(hal::Composition type) = 0;
269 [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
270 [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata(
Lloyd Pique35d58242018-12-18 16:33:25 -0800271 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700272 [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame(
273 const android::Rect& frame) = 0;
274 [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
275 [[clang::warn_unused_result]] virtual hal::Error setSidebandStream(
Lloyd Pique35d58242018-12-18 16:33:25 -0800276 const native_handle_t* stream) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700277 [[clang::warn_unused_result]] virtual hal::Error setSourceCrop(
278 const android::FloatRect& crop) = 0;
279 [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0;
280 [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion(
281 const android::Region& region) = 0;
282 [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800283
284 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700285 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
286 const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800287
288 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700289 [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata(
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800290 const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800291};
292
293namespace impl {
294
Peiyong Line9d809e2020-04-14 13:10:48 -0700295// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800296
297class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700298public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700299 Layer(android::Hwc2::Composer& composer,
Lloyd Piquea516c002021-05-07 14:36:58 -0700300 const std::unordered_set<hal::Capability>& capabilities, HWC2::Display& display,
Peiyong Line9d809e2020-04-14 13:10:48 -0700301 hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800302 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700303
Lloyd Piquea516c002021-05-07 14:36:58 -0700304 void onOwningDisplayDestroyed();
305
Peiyong Line9d809e2020-04-14 13:10:48 -0700306 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700307
Peiyong Line9d809e2020-04-14 13:10:48 -0700308 hal::Error setCursorPosition(int32_t x, int32_t y) override;
309 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
310 const android::sp<android::Fence>& acquireFence) override;
311 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700312
Peiyong Line9d809e2020-04-14 13:10:48 -0700313 hal::Error setBlendMode(hal::BlendMode mode) override;
314 hal::Error setColor(hal::Color color) override;
315 hal::Error setCompositionType(hal::Composition type) override;
316 hal::Error setDataspace(hal::Dataspace dataspace) override;
317 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
318 const android::HdrMetadata& metadata) override;
319 hal::Error setDisplayFrame(const android::Rect& frame) override;
320 hal::Error setPlaneAlpha(float alpha) override;
321 hal::Error setSidebandStream(const native_handle_t* stream) override;
322 hal::Error setSourceCrop(const android::FloatRect& crop) override;
323 hal::Error setTransform(hal::Transform transform) override;
324 hal::Error setVisibleRegion(const android::Region& region) override;
325 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700326
Peiyong Lin698147a2018-09-14 13:27:18 -0700327 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700328 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700329
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800330 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700331 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
332 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800333
Dan Stoza651bf312015-10-23 17:03:17 -0700334private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700335 // These are references to data owned by HWC2::Device, which will outlive
336 // this HWC2::Layer, so these references are guaranteed to be valid for
337 // the lifetime of this object.
338 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700339 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700340
Lloyd Piquea516c002021-05-07 14:36:58 -0700341 HWC2::Display* mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700342 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800343
344 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
345 // multiple times.
346 android::Region mVisibleRegion = android::Region::INVALID_REGION;
347 android::Region mDamageRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700348 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700349 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700350 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800351 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700352};
353
Lloyd Pique35d58242018-12-18 16:33:25 -0800354} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700355} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700356} // namespace android