blob: df4e4b8d0be357d44971cc4dc00f96313fc62032 [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
Alec Mouricdf16792021-12-10 13:16:06 -080037#include "ComposerHal.h"
Peiyong Line9d809e2020-04-14 13:10:48 -070038#include "Hal.h"
39
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050040#include <aidl/android/hardware/graphics/composer3/Composition.h>
Leon Scroggins III5967aec2021-12-29 11:14:22 -050041#include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050042
Dan Stoza651bf312015-10-23 17:03:17 -070043namespace android {
Lloyd Piquebc792092018-01-17 11:52:30 -080044
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070045class Fence;
46class FloatRect;
47class GraphicBuffer;
48class TestableSurfaceFlinger;
49struct DisplayedFrameStats;
50
51namespace Hwc2 {
52class Composer;
53} // namespace Hwc2
Dan Stoza651bf312015-10-23 17:03:17 -070054
55namespace HWC2 {
56
Dan Stoza651bf312015-10-23 17:03:17 -070057class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070058
59namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070060
Steven Thomas94e35b92017-07-26 18:48:28 -070061// Implement this interface to receive hardware composer events.
62//
63// These callback functions will generally be called on a hwbinder thread, but
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070064// when first registering the callback the onComposerHalHotplug() function will
Steven Thomas94e35b92017-07-26 18:48:28 -070065// immediately be called on the thread calling registerCallback().
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070066struct ComposerCallback {
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070067 virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0;
68 virtual void onComposerHalRefresh(hal::HWDisplayId) = 0;
69 virtual void onComposerHalVsync(hal::HWDisplayId, int64_t timestamp,
70 std::optional<hal::VsyncPeriodNanos>) = 0;
71 virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId,
72 const hal::VsyncPeriodChangeTimeline&) = 0;
73 virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070074
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070075protected:
76 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070077};
Dan Stoza651bf312015-10-23 17:03:17 -070078
Peiyong Line9d809e2020-04-14 13:10:48 -070079// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080080class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070081public:
Ana Krulec4593b692019-01-11 22:07:25 -080082 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070083
Peiyong Line9d809e2020-04-14 13:10:48 -070084 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -080085 virtual bool isConnected() const = 0;
86 virtual void setConnected(bool connected) = 0; // For use by Device only
Leon Scroggins III5967aec2021-12-29 11:14:22 -050087 virtual bool hasCapability(
88 aidl::android::hardware::graphics::composer3::DisplayCapability) const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070089 virtual bool isVsyncPeriodSwitchSupported() const = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070090 virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0;
Dan Stoza651bf312015-10-23 17:03:17 -070091
Peiyong Line9d809e2020-04-14 13:10:48 -070092 [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0;
Lloyd Piquea516c002021-05-07 14:36:58 -070093 [[clang::warn_unused_result]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error>
94 createLayer() = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070095 [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050096 std::unordered_map<Layer*, aidl::android::hardware::graphics::composer3::Composition>*
97 outTypes) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -070098 [[clang::warn_unused_result]] virtual hal::Error getColorModes(
99 std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +0800100 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -0800101 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700102 [[clang::warn_unused_result]] virtual hal::Error getRenderIntents(
103 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
104 [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix(
105 hal::Dataspace dataspace, android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800106
Peiyong Line9d809e2020-04-14 13:10:48 -0700107 [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0;
108 [[clang::warn_unused_result]] virtual hal::Error getRequests(
109 hal::DisplayRequest* outDisplayRequests,
110 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
111 [[clang::warn_unused_result]] virtual hal::Error getConnectionType(
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100112 ui::DisplayConnectionType*) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700113 [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
114 [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800115 android::HdrCapabilities* outCapabilities) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700116 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes(
117 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800118 uint8_t* outComponentMask) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700119 [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled(
Ana Krulec4593b692019-01-11 22:07:25 -0800120 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700121 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800122 uint64_t maxFrames, uint64_t timestamp,
123 android::DisplayedFrameStats* outStats) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700124 [[clang::warn_unused_result]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800125 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700126 [[clang::warn_unused_result]] virtual hal::Error present(
Ana Krulec4593b692019-01-11 22:07:25 -0800127 android::sp<android::Fence>* outPresentFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700128 [[clang::warn_unused_result]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800129 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700130 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
131 [[clang::warn_unused_result]] virtual hal::Error setColorMode(
132 hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
133 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
Ady Abrahamdc011a92021-12-21 14:06:44 -0800134 const android::mat4& matrix) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700135 [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800136 const android::sp<android::GraphicBuffer>& buffer,
137 const android::sp<android::Fence>& releaseFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700138 [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
139 [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
Ady Abraham43065bd2021-12-10 17:22:15 -0800140 [[clang::warn_unused_result]] virtual hal::Error validate(nsecs_t expectedPresentTime,
141 uint32_t* outNumTypes,
Peiyong Line9d809e2020-04-14 13:10:48 -0700142 uint32_t* outNumRequests) = 0;
143 [[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
Ady Abraham43065bd2021-12-10 17:22:15 -0800144 nsecs_t expectedPresentTime, uint32_t* outNumTypes, uint32_t* outNumRequests,
Ana Krulec4593b692019-01-11 22:07:25 -0800145 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700146 [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
Alec Mouricdf16792021-12-10 13:16:06 -0800147 float brightness, const Hwc2::Composer::DisplayBrightnessOptions& options) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700148 [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100149 hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700150 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700151 [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700152 [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
153 std::vector<hal::ContentType>*) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700154 [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700155 [[clang::warn_unused_result]] virtual hal::Error getClientTargetProperty(
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700156 hal::ClientTargetProperty* outClientTargetProperty, float* outWhitePointNits) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800157};
158
159namespace impl {
160
Lloyd Piquea516c002021-05-07 14:36:58 -0700161class Layer;
162
Ana Krulec4593b692019-01-11 22:07:25 -0800163class Display : public HWC2::Display {
164public:
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200165 Display(android::Hwc2::Composer&, const std::unordered_set<hal::Capability>&, hal::HWDisplayId,
166 hal::DisplayType);
Ana Krulec4593b692019-01-11 22:07:25 -0800167 ~Display() override;
168
169 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700170 hal::Error acceptChanges() override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700171 base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700172 hal::Error getChangedCompositionTypes(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500173 std::unordered_map<HWC2::Layer*,
174 aidl::android::hardware::graphics::composer3::Composition>* outTypes)
175 override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700176 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800177 // Returns a bitmask which contains HdrMetadata::Type::*.
178 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700179 hal::Error getRenderIntents(hal::ColorMode colorMode,
180 std::vector<hal::RenderIntent>* outRenderIntents) const override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200181 hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700182
Peiyong Line9d809e2020-04-14 13:10:48 -0700183 hal::Error getName(std::string* outName) const override;
184 hal::Error getRequests(
185 hal::DisplayRequest* outDisplayRequests,
Lloyd Piquea516c002021-05-07 14:36:58 -0700186 std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override;
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100187 hal::Error getConnectionType(ui::DisplayConnectionType*) const override;
Ady Abraham27fbcc72021-09-20 14:54:57 -0700188 hal::Error supportsDoze(bool* outSupport) const override EXCLUDES(mDisplayCapabilitiesMutex);
Peiyong Line9d809e2020-04-14 13:10:48 -0700189 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
190 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
191 hal::Dataspace* outDataspace,
192 uint8_t* outComponentMask) const override;
193 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
194 uint64_t maxFrames) const override;
195 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
196 android::DisplayedFrameStats* outStats) const override;
Lloyd Piquea516c002021-05-07 14:36:58 -0700197 hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>*
198 outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700199 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700200 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
201 const android::sp<android::Fence>& acquireFence,
202 hal::Dataspace dataspace) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200203 hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
Ady Abrahamdc011a92021-12-21 14:06:44 -0800204 hal::Error setColorTransform(const android::mat4& matrix) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200205 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
Peiyong Line9d809e2020-04-14 13:10:48 -0700206 const android::sp<android::Fence>& releaseFence) override;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200207 hal::Error setPowerMode(hal::PowerMode) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700208 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
Ady Abraham43065bd2021-12-10 17:22:15 -0800209 hal::Error validate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
210 uint32_t* outNumRequests) override;
211 hal::Error presentOrValidate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
212 uint32_t* outNumRequests,
Peiyong Line9d809e2020-04-14 13:10:48 -0700213 android::sp<android::Fence>* outPresentFence,
214 uint32_t* state) override;
Alec Mouricdf16792021-12-10 13:16:06 -0800215 std::future<hal::Error> setDisplayBrightness(
216 float brightness, const Hwc2::Composer::DisplayBrightnessOptions& options) override;
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100217 hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId,
218 const hal::VsyncPeriodChangeConstraints& constraints,
219 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700220 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700221 hal::Error getSupportedContentTypes(
222 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700223 hal::Error setContentType(hal::ContentType) override;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700224 hal::Error getClientTargetProperty(hal::ClientTargetProperty* outClientTargetProperty,
225 float* outWhitePointNits) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700226
Dan Stoza651bf312015-10-23 17:03:17 -0700227 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700228 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800229 bool isConnected() const override { return mIsConnected; }
230 void setConnected(bool connected) override; // For use by Device only
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500231 bool hasCapability(aidl::android::hardware::graphics::composer3::DisplayCapability)
232 const override EXCLUDES(mDisplayCapabilitiesMutex);
Lloyd Piquea516c002021-05-07 14:36:58 -0700233 bool isVsyncPeriodSwitchSupported() const override;
234 void onLayerDestroyed(hal::HWLayerId layerId) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700235
236private:
Dan Stoza651bf312015-10-23 17:03:17 -0700237
Dan Stoza651bf312015-10-23 17:03:17 -0700238 // This may fail (and return a null pointer) if no layer with this ID exists
239 // on this display
Lloyd Piquea516c002021-05-07 14:36:58 -0700240 std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700241
Lloyd Piquebc792092018-01-17 11:52:30 -0800242 friend android::TestableSurfaceFlinger;
243
Dan Stoza651bf312015-10-23 17:03:17 -0700244 // Member variables
245
Steven Thomas94e35b92017-07-26 18:48:28 -0700246 // These are references to data owned by HWC2::Device, which will outlive
247 // this HWC2::Display, so these references are guaranteed to be valid for
248 // the lifetime of this object.
249 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700250 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700251
Peiyong Line9d809e2020-04-14 13:10:48 -0700252 const hal::HWDisplayId mId;
253 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800254 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700255
Lloyd Piquea516c002021-05-07 14:36:58 -0700256 using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>;
257 Layers mLayers;
Ady Abraham7159f572019-10-11 11:10:18 -0700258
Ady Abraham27fbcc72021-09-20 14:54:57 -0700259 mutable std::mutex mDisplayCapabilitiesMutex;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700260 std::once_flag mDisplayCapabilityQueryFlag;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500261 std::optional<
262 std::unordered_set<aidl::android::hardware::graphics::composer3::DisplayCapability>>
263 mDisplayCapabilities GUARDED_BY(mDisplayCapabilitiesMutex);
Dan Stoza651bf312015-10-23 17:03:17 -0700264};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800265
Ana Krulec4593b692019-01-11 22:07:25 -0800266} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700267
Lloyd Pique35d58242018-12-18 16:33:25 -0800268class Layer {
269public:
270 virtual ~Layer();
271
Peiyong Line9d809e2020-04-14 13:10:48 -0700272 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800273
Peiyong Line9d809e2020-04-14 13:10:48 -0700274 [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
275 [[clang::warn_unused_result]] virtual hal::Error setBuffer(
Lloyd Pique35d58242018-12-18 16:33:25 -0800276 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
277 const android::sp<android::Fence>& acquireFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700278 [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage(
279 const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800280
Peiyong Line9d809e2020-04-14 13:10:48 -0700281 [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
282 [[clang::warn_unused_result]] virtual hal::Error setColor(hal::Color color) = 0;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500283 [[clang::warn_unused_result]] virtual hal::Error setCompositionType(
284 aidl::android::hardware::graphics::composer3::Composition type) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700285 [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
286 [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata(
Lloyd Pique35d58242018-12-18 16:33:25 -0800287 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700288 [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame(
289 const android::Rect& frame) = 0;
290 [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
291 [[clang::warn_unused_result]] virtual hal::Error setSidebandStream(
Lloyd Pique35d58242018-12-18 16:33:25 -0800292 const native_handle_t* stream) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700293 [[clang::warn_unused_result]] virtual hal::Error setSourceCrop(
294 const android::FloatRect& crop) = 0;
295 [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0;
296 [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion(
297 const android::Region& region) = 0;
298 [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800299
300 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700301 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
302 const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800303
304 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700305 [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata(
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800306 const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700307
308 // AIDL HAL
309 [[clang::warn_unused_result]] virtual hal::Error setWhitePointNits(float whitePointNits) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800310};
311
312namespace impl {
313
Peiyong Line9d809e2020-04-14 13:10:48 -0700314// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800315
316class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700317public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700318 Layer(android::Hwc2::Composer& composer,
Lloyd Piquea516c002021-05-07 14:36:58 -0700319 const std::unordered_set<hal::Capability>& capabilities, HWC2::Display& display,
Peiyong Line9d809e2020-04-14 13:10:48 -0700320 hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800321 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700322
Lloyd Piquea516c002021-05-07 14:36:58 -0700323 void onOwningDisplayDestroyed();
324
Peiyong Line9d809e2020-04-14 13:10:48 -0700325 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700326
Peiyong Line9d809e2020-04-14 13:10:48 -0700327 hal::Error setCursorPosition(int32_t x, int32_t y) override;
328 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
329 const android::sp<android::Fence>& acquireFence) override;
330 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700331
Peiyong Line9d809e2020-04-14 13:10:48 -0700332 hal::Error setBlendMode(hal::BlendMode mode) override;
333 hal::Error setColor(hal::Color color) override;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500334 hal::Error setCompositionType(
335 aidl::android::hardware::graphics::composer3::Composition type) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700336 hal::Error setDataspace(hal::Dataspace dataspace) override;
337 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
338 const android::HdrMetadata& metadata) override;
339 hal::Error setDisplayFrame(const android::Rect& frame) override;
340 hal::Error setPlaneAlpha(float alpha) override;
341 hal::Error setSidebandStream(const native_handle_t* stream) override;
342 hal::Error setSourceCrop(const android::FloatRect& crop) override;
343 hal::Error setTransform(hal::Transform transform) override;
344 hal::Error setVisibleRegion(const android::Region& region) override;
345 hal::Error setZOrder(uint32_t z) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700346
Peiyong Lin698147a2018-09-14 13:27:18 -0700347 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700348 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700349
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800350 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700351 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
352 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800353
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700354 // AIDL HAL
355 hal::Error setWhitePointNits(float whitePointNits) override;
356
Dan Stoza651bf312015-10-23 17:03:17 -0700357private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700358 // These are references to data owned by HWC2::Device, which will outlive
359 // this HWC2::Layer, so these references are guaranteed to be valid for
360 // the lifetime of this object.
361 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700362 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700363
Lloyd Piquea516c002021-05-07 14:36:58 -0700364 HWC2::Display* mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700365 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800366
367 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
368 // multiple times.
369 android::Region mVisibleRegion = android::Region::INVALID_REGION;
370 android::Region mDamageRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700371 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700372 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700373 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800374 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700375};
376
Lloyd Pique35d58242018-12-18 16:33:25 -0800377} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700378} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700379} // namespace android