blob: af31df8216e026bddbb81860bb17ab8039b3a466 [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
17#ifndef ANDROID_SF_HWC2_H
18#define ANDROID_SF_HWC2_H
19
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070020#include <gui/HdrMetadata.h>
Mathias Agopian1d77b712017-02-17 15:46:13 -080021#include <math/mat4.h>
Dominik Laskowski55c85402020-01-21 16:25:47 -080022#include <ui/DisplayInfo.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>
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>
30#include <string>
31#include <unordered_map>
Dan Stoza9f26a9c2016-06-22 14:51:09 -070032#include <unordered_set>
Dan Stoza651bf312015-10-23 17:03:17 -070033#include <vector>
34
Peiyong Line9d809e2020-04-14 13:10:48 -070035#include "Hal.h"
36
Dan Stoza651bf312015-10-23 17:03:17 -070037namespace android {
Kevin DuBois1d4249a2018-08-29 10:45:14 -070038 struct DisplayedFrameStats;
Dan Stoza651bf312015-10-23 17:03:17 -070039 class Fence;
Dan Stoza5a423ea2017-02-16 14:10:39 -080040 class FloatRect;
Dan Stoza651bf312015-10-23 17:03:17 -070041 class GraphicBuffer;
Chia-I Wuaab99f52016-10-05 12:59:58 +080042 namespace Hwc2 {
43 class Composer;
Dan Stoza71bded52016-10-19 11:10:33 -070044 }
Lloyd Piquebc792092018-01-17 11:52:30 -080045
46 class TestableSurfaceFlinger;
Dan Stoza651bf312015-10-23 17:03:17 -070047
48namespace HWC2 {
49
Dan Stoza651bf312015-10-23 17:03:17 -070050class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070051
52namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070053
Steven Thomas94e35b92017-07-26 18:48:28 -070054// Implement this interface to receive hardware composer events.
55//
56// These callback functions will generally be called on a hwbinder thread, but
57// when first registering the callback the onHotplugReceived() function will
58// immediately be called on the thread calling registerCallback().
59//
60// All calls receive a sequenceId, which will be the value that was supplied to
61// HWC2::Device::registerCallback(). It's used to help differentiate callbacks
62// from different hardware composer instances.
63class ComposerCallback {
64 public:
Peiyong Line9d809e2020-04-14 13:10:48 -070065 virtual void onHotplugReceived(int32_t sequenceId, hal::HWDisplayId display,
66 hal::Connection connection) = 0;
67 virtual void onRefreshReceived(int32_t sequenceId, hal::HWDisplayId display) = 0;
68 virtual void onVsyncReceived(int32_t sequenceId, hal::HWDisplayId display, int64_t timestamp,
69 std::optional<hal::VsyncPeriodNanos> vsyncPeriod) = 0;
70 virtual void onVsyncPeriodTimingChangedReceived(
71 int32_t sequenceId, hal::HWDisplayId display,
72 const hal::VsyncPeriodChangeTimeline& updatedTimeline) = 0;
73 virtual void onSeamlessPossible(int32_t sequenceId, hal::HWDisplayId display) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070074
Peiyong Line9d809e2020-04-14 13:10:48 -070075 virtual ~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
Ana Krulec4593b692019-01-11 22:07:25 -080083 class Config {
Dan Stoza651bf312015-10-23 17:03:17 -070084 public:
85 class Builder
86 {
87 public:
Peiyong Line9d809e2020-04-14 13:10:48 -070088 Builder(Display& display, hal::HWConfigId id);
Dan Stoza651bf312015-10-23 17:03:17 -070089
90 std::shared_ptr<const Config> build() {
91 return std::const_pointer_cast<const Config>(
92 std::move(mConfig));
93 }
94
95 Builder& setWidth(int32_t width) {
96 mConfig->mWidth = width;
97 return *this;
98 }
99 Builder& setHeight(int32_t height) {
100 mConfig->mHeight = height;
101 return *this;
102 }
103 Builder& setVsyncPeriod(int32_t vsyncPeriod) {
104 mConfig->mVsyncPeriod = vsyncPeriod;
105 return *this;
106 }
107 Builder& setDpiX(int32_t dpiX) {
108 if (dpiX == -1) {
109 mConfig->mDpiX = getDefaultDensity();
110 } else {
111 mConfig->mDpiX = dpiX / 1000.0f;
112 }
113 return *this;
114 }
115 Builder& setDpiY(int32_t dpiY) {
116 if (dpiY == -1) {
117 mConfig->mDpiY = getDefaultDensity();
118 } else {
119 mConfig->mDpiY = dpiY / 1000.0f;
120 }
121 return *this;
122 }
Ady Abraham7159f572019-10-11 11:10:18 -0700123 Builder& setConfigGroup(int32_t configGroup) {
124 mConfig->mConfigGroup = configGroup;
125 return *this;
126 }
Dan Stoza651bf312015-10-23 17:03:17 -0700127
128 private:
129 float getDefaultDensity();
130 std::shared_ptr<Config> mConfig;
131 };
132
Peiyong Line9d809e2020-04-14 13:10:48 -0700133 hal::HWDisplayId getDisplayId() const { return mDisplay.getId(); }
134 hal::HWConfigId getId() const { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700135
136 int32_t getWidth() const { return mWidth; }
137 int32_t getHeight() const { return mHeight; }
David Sodman1afa8b02018-10-15 11:20:48 -0700138 nsecs_t getVsyncPeriod() const { return mVsyncPeriod; }
Dan Stoza651bf312015-10-23 17:03:17 -0700139 float getDpiX() const { return mDpiX; }
140 float getDpiY() const { return mDpiY; }
Ady Abraham7159f572019-10-11 11:10:18 -0700141 int32_t getConfigGroup() const { return mConfigGroup; }
Dan Stoza651bf312015-10-23 17:03:17 -0700142
143 private:
Peiyong Line9d809e2020-04-14 13:10:48 -0700144 Config(Display& display, hal::HWConfigId id);
Dan Stoza651bf312015-10-23 17:03:17 -0700145
146 Display& mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700147 hal::HWConfigId mId;
Dan Stoza651bf312015-10-23 17:03:17 -0700148
149 int32_t mWidth;
150 int32_t mHeight;
151 nsecs_t mVsyncPeriod;
152 float mDpiX;
153 float mDpiY;
Ady Abraham7159f572019-10-11 11:10:18 -0700154 int32_t mConfigGroup;
Dan Stoza651bf312015-10-23 17:03:17 -0700155 };
156
Peiyong Line9d809e2020-04-14 13:10:48 -0700157 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800158 virtual bool isConnected() const = 0;
159 virtual void setConnected(bool connected) = 0; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -0700160 virtual const std::unordered_set<hal::DisplayCapability>& getCapabilities() const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -0700161 virtual bool isVsyncPeriodSwitchSupported() const = 0;
Dan Stoza651bf312015-10-23 17:03:17 -0700162
Peiyong Line9d809e2020-04-14 13:10:48 -0700163 [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0;
164 [[clang::warn_unused_result]] virtual hal::Error createLayer(Layer** outLayer) = 0;
165 [[clang::warn_unused_result]] virtual hal::Error destroyLayer(Layer* layer) = 0;
166 [[clang::warn_unused_result]] virtual hal::Error getActiveConfig(
Ana Krulec4593b692019-01-11 22:07:25 -0800167 std::shared_ptr<const Config>* outConfig) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700168 [[clang::warn_unused_result]] virtual hal::Error getActiveConfigIndex(int* outIndex) const = 0;
169 [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes(
170 std::unordered_map<Layer*, hal::Composition>* outTypes) = 0;
171 [[clang::warn_unused_result]] virtual hal::Error getColorModes(
172 std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +0800173 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -0800174 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700175 [[clang::warn_unused_result]] virtual hal::Error getRenderIntents(
176 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
177 [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix(
178 hal::Dataspace dataspace, android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800179
Peiyong Line9d809e2020-04-14 13:10:48 -0700180 // Doesn't call into the HWC2 device, so no errors are possible
181 [[clang::warn_unused_result]] virtual std::vector<std::shared_ptr<const Config>> getConfigs()
182 const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800183
Peiyong Line9d809e2020-04-14 13:10:48 -0700184 [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0;
185 [[clang::warn_unused_result]] virtual hal::Error getRequests(
186 hal::DisplayRequest* outDisplayRequests,
187 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
188 [[clang::warn_unused_result]] virtual hal::Error getConnectionType(
Dominik Laskowski55c85402020-01-21 16:25:47 -0800189 android::DisplayConnectionType*) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700190 [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
191 [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800192 android::HdrCapabilities* outCapabilities) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700193 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes(
194 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800195 uint8_t* outComponentMask) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700196 [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled(
Ana Krulec4593b692019-01-11 22:07:25 -0800197 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700198 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800199 uint64_t maxFrames, uint64_t timestamp,
200 android::DisplayedFrameStats* outStats) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700201 [[clang::warn_unused_result]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800202 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700203 [[clang::warn_unused_result]] virtual hal::Error present(
Ana Krulec4593b692019-01-11 22:07:25 -0800204 android::sp<android::Fence>* outPresentFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700205 [[clang::warn_unused_result]] virtual hal::Error setActiveConfig(
Ana Krulec4593b692019-01-11 22:07:25 -0800206 const std::shared_ptr<const Config>& config) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700207 [[clang::warn_unused_result]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800208 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700209 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
210 [[clang::warn_unused_result]] virtual hal::Error setColorMode(
211 hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
212 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
213 const android::mat4& matrix, hal::ColorTransform hint) = 0;
214 [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800215 const android::sp<android::GraphicBuffer>& buffer,
216 const android::sp<android::Fence>& releaseFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700217 [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
218 [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
219 [[clang::warn_unused_result]] virtual hal::Error validate(uint32_t* outNumTypes,
220 uint32_t* outNumRequests) = 0;
221 [[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
Ana Krulec4593b692019-01-11 22:07:25 -0800222 uint32_t* outNumTypes, uint32_t* outNumRequests,
223 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700224 [[clang::warn_unused_result]] virtual hal::Error setDisplayBrightness(
225 float brightness) const = 0;
226 [[clang::warn_unused_result]] virtual hal::Error getDisplayVsyncPeriod(
Ady Abraham7159f572019-10-11 11:10:18 -0700227 nsecs_t* outVsyncPeriod) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700228 [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
Ady Abraham7159f572019-10-11 11:10:18 -0700229 const std::shared_ptr<const HWC2::Display::Config>& config,
Peiyong Line9d809e2020-04-14 13:10:48 -0700230 const hal::VsyncPeriodChangeConstraints& constraints,
231 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
232 [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) const = 0;
233 [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
234 std::vector<hal::ContentType>*) const = 0;
235 [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800236};
237
238namespace impl {
239
240class Display : public HWC2::Display {
241public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700242 Display(android::Hwc2::Composer& composer,
243 const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId id,
244 hal::DisplayType type);
Ana Krulec4593b692019-01-11 22:07:25 -0800245 ~Display() override;
246
247 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700248 hal::Error acceptChanges() override;
249 hal::Error createLayer(Layer** outLayer) override;
250 hal::Error destroyLayer(Layer* layer) override;
251 hal::Error getActiveConfig(std::shared_ptr<const Config>* outConfig) const override;
252 hal::Error getActiveConfigIndex(int* outIndex) const override;
253 hal::Error getChangedCompositionTypes(
254 std::unordered_map<Layer*, hal::Composition>* outTypes) override;
255 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800256 // Returns a bitmask which contains HdrMetadata::Type::*.
257 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700258 hal::Error getRenderIntents(hal::ColorMode colorMode,
259 std::vector<hal::RenderIntent>* outRenderIntents) const override;
260 hal::Error getDataspaceSaturationMatrix(hal::Dataspace dataspace,
261 android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700262
263 // Doesn't call into the HWC2 device, so no errors are possible
Ana Krulec4593b692019-01-11 22:07:25 -0800264 std::vector<std::shared_ptr<const Config>> getConfigs() const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700265
Peiyong Line9d809e2020-04-14 13:10:48 -0700266 hal::Error getName(std::string* outName) const override;
267 hal::Error getRequests(
268 hal::DisplayRequest* outDisplayRequests,
269 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) override;
270 hal::Error getConnectionType(android::DisplayConnectionType*) const override;
271 hal::Error supportsDoze(bool* outSupport) const override;
272 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
273 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
274 hal::Dataspace* outDataspace,
275 uint8_t* outComponentMask) const override;
276 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
277 uint64_t maxFrames) const override;
278 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
279 android::DisplayedFrameStats* outStats) const override;
280 hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800281 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700282 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
283 hal::Error setActiveConfig(const std::shared_ptr<const HWC2::Display::Config>& config) override;
284 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
285 const android::sp<android::Fence>& acquireFence,
286 hal::Dataspace dataspace) override;
287 hal::Error setColorMode(hal::ColorMode mode, hal::RenderIntent renderIntent) override;
288 hal::Error setColorTransform(const android::mat4& matrix, hal::ColorTransform hint) override;
289 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>& buffer,
290 const android::sp<android::Fence>& releaseFence) override;
291 hal::Error setPowerMode(hal::PowerMode mode) override;
292 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
293 hal::Error validate(uint32_t* outNumTypes, uint32_t* outNumRequests) override;
294 hal::Error presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests,
295 android::sp<android::Fence>* outPresentFence,
296 uint32_t* state) override;
297 hal::Error setDisplayBrightness(float brightness) const override;
298 hal::Error getDisplayVsyncPeriod(nsecs_t* outVsyncPeriod) const override;
299 hal::Error setActiveConfigWithConstraints(
300 const std::shared_ptr<const HWC2::Display::Config>& config,
301 const hal::VsyncPeriodChangeConstraints& constraints,
302 hal::VsyncPeriodChangeTimeline* outTimeline) override;
303 hal::Error setAutoLowLatencyMode(bool on) const override;
304 hal::Error getSupportedContentTypes(
305 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
306 hal::Error setContentType(hal::ContentType contentType) const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700307 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700308 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800309 bool isConnected() const override { return mIsConnected; }
310 void setConnected(bool connected) override; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -0700311 const std::unordered_set<hal::DisplayCapability>& getCapabilities() const override {
Peiyong Lined531a32018-10-26 18:27:56 -0700312 return mDisplayCapabilities;
313 };
Ady Abraham7159f572019-10-11 11:10:18 -0700314 virtual bool isVsyncPeriodSwitchSupported() const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700315
316private:
Peiyong Line9d809e2020-04-14 13:10:48 -0700317 int32_t getAttribute(hal::HWConfigId configId, hal::Attribute attribute);
318 void loadConfig(hal::HWConfigId configId);
Dan Stoza651bf312015-10-23 17:03:17 -0700319 void loadConfigs();
320
Dan Stoza651bf312015-10-23 17:03:17 -0700321 // This may fail (and return a null pointer) if no layer with this ID exists
322 // on this display
Peiyong Line9d809e2020-04-14 13:10:48 -0700323 Layer* getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700324
Lloyd Piquebc792092018-01-17 11:52:30 -0800325 friend android::TestableSurfaceFlinger;
326
Dan Stoza651bf312015-10-23 17:03:17 -0700327 // Member variables
328
Steven Thomas94e35b92017-07-26 18:48:28 -0700329 // These are references to data owned by HWC2::Device, which will outlive
330 // this HWC2::Display, so these references are guaranteed to be valid for
331 // the lifetime of this object.
332 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700333 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700334
Peiyong Line9d809e2020-04-14 13:10:48 -0700335 const hal::HWDisplayId mId;
336 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800337 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700338
Peiyong Line9d809e2020-04-14 13:10:48 -0700339 std::unordered_map<hal::HWLayerId, std::unique_ptr<Layer>> mLayers;
340 std::unordered_map<hal::HWConfigId, std::shared_ptr<const Config>> mConfigs;
Ady Abraham7159f572019-10-11 11:10:18 -0700341
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700342 std::once_flag mDisplayCapabilityQueryFlag;
Peiyong Line9d809e2020-04-14 13:10:48 -0700343 std::unordered_set<hal::DisplayCapability> mDisplayCapabilities;
Dan Stoza651bf312015-10-23 17:03:17 -0700344};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800345
Ana Krulec4593b692019-01-11 22:07:25 -0800346} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700347
Lloyd Pique35d58242018-12-18 16:33:25 -0800348class Layer {
349public:
350 virtual ~Layer();
351
Peiyong Line9d809e2020-04-14 13:10:48 -0700352 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800353
Peiyong Line9d809e2020-04-14 13:10:48 -0700354 [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
355 [[clang::warn_unused_result]] virtual hal::Error setBuffer(
Lloyd Pique35d58242018-12-18 16:33:25 -0800356 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
357 const android::sp<android::Fence>& acquireFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700358 [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage(
359 const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800360
Peiyong Line9d809e2020-04-14 13:10:48 -0700361 [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
362 [[clang::warn_unused_result]] virtual hal::Error setColor(hal::Color color) = 0;
363 [[clang::warn_unused_result]] virtual hal::Error setCompositionType(hal::Composition type) = 0;
364 [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
365 [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata(
Lloyd Pique35d58242018-12-18 16:33:25 -0800366 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700367 [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame(
368 const android::Rect& frame) = 0;
369 [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
370 [[clang::warn_unused_result]] virtual hal::Error setSidebandStream(
Lloyd Pique35d58242018-12-18 16:33:25 -0800371 const native_handle_t* stream) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700372 [[clang::warn_unused_result]] virtual hal::Error setSourceCrop(
373 const android::FloatRect& crop) = 0;
374 [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0;
375 [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion(
376 const android::Region& region) = 0;
377 [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0;
378 [[clang::warn_unused_result]] virtual hal::Error setInfo(uint32_t type, uint32_t appId) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800379
380 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700381 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
382 const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800383
384 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700385 [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata(
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800386 const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800387};
388
389namespace impl {
390
Peiyong Line9d809e2020-04-14 13:10:48 -0700391// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800392
393class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700394public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700395 Layer(android::Hwc2::Composer& composer,
396 const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId displayId,
397 hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800398 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700399
Peiyong Line9d809e2020-04-14 13:10:48 -0700400 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700401
Peiyong Line9d809e2020-04-14 13:10:48 -0700402 hal::Error setCursorPosition(int32_t x, int32_t y) override;
403 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
404 const android::sp<android::Fence>& acquireFence) override;
405 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700406
Peiyong Line9d809e2020-04-14 13:10:48 -0700407 hal::Error setBlendMode(hal::BlendMode mode) override;
408 hal::Error setColor(hal::Color color) override;
409 hal::Error setCompositionType(hal::Composition type) override;
410 hal::Error setDataspace(hal::Dataspace dataspace) override;
411 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
412 const android::HdrMetadata& metadata) override;
413 hal::Error setDisplayFrame(const android::Rect& frame) override;
414 hal::Error setPlaneAlpha(float alpha) override;
415 hal::Error setSidebandStream(const native_handle_t* stream) override;
416 hal::Error setSourceCrop(const android::FloatRect& crop) override;
417 hal::Error setTransform(hal::Transform transform) override;
418 hal::Error setVisibleRegion(const android::Region& region) override;
419 hal::Error setZOrder(uint32_t z) override;
420 hal::Error setInfo(uint32_t type, uint32_t appId) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700421
Peiyong Lin698147a2018-09-14 13:27:18 -0700422 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700423 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700424
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800425 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700426 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
427 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800428
Dan Stoza651bf312015-10-23 17:03:17 -0700429private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700430 // These are references to data owned by HWC2::Device, which will outlive
431 // this HWC2::Layer, so these references are guaranteed to be valid for
432 // the lifetime of this object.
433 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700434 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700435
Peiyong Line9d809e2020-04-14 13:10:48 -0700436 hal::HWDisplayId mDisplayId;
437 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800438
439 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
440 // multiple times.
441 android::Region mVisibleRegion = android::Region::INVALID_REGION;
442 android::Region mDamageRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700443 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700444 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700445 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800446 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700447};
448
Lloyd Pique35d58242018-12-18 16:33:25 -0800449} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700450} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700451} // namespace android
Dan Stoza651bf312015-10-23 17:03:17 -0700452
453#endif // ANDROID_SF_HWC2_H