blob: 6819ff43d22902ce296714eb2d6062882bb7b6c8 [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>
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 {
Kevin DuBois1d4249a2018-08-29 10:45:14 -070039 struct DisplayedFrameStats;
Dan Stoza651bf312015-10-23 17:03:17 -070040 class Fence;
Dan Stoza5a423ea2017-02-16 14:10:39 -080041 class FloatRect;
Dan Stoza651bf312015-10-23 17:03:17 -070042 class GraphicBuffer;
Chia-I Wuaab99f52016-10-05 12:59:58 +080043 namespace Hwc2 {
44 class Composer;
Dan Stoza71bded52016-10-19 11:10:33 -070045 }
Lloyd Piquebc792092018-01-17 11:52:30 -080046
47 class TestableSurfaceFlinger;
Dan Stoza651bf312015-10-23 17:03:17 -070048
49namespace HWC2 {
50
Dan Stoza651bf312015-10-23 17:03:17 -070051class Layer;
Peiyong Line9d809e2020-04-14 13:10:48 -070052
53namespace hal = android::hardware::graphics::composer::hal;
Dan Stoza651bf312015-10-23 17:03:17 -070054
Steven Thomas94e35b92017-07-26 18:48:28 -070055// Implement this interface to receive hardware composer events.
56//
57// These callback functions will generally be called on a hwbinder thread, but
58// when first registering the callback the onHotplugReceived() function will
59// immediately be called on the thread calling registerCallback().
60//
61// All calls receive a sequenceId, which will be the value that was supplied to
62// HWC2::Device::registerCallback(). It's used to help differentiate callbacks
63// from different hardware composer instances.
64class ComposerCallback {
65 public:
Peiyong Line9d809e2020-04-14 13:10:48 -070066 virtual void onHotplugReceived(int32_t sequenceId, hal::HWDisplayId display,
67 hal::Connection connection) = 0;
68 virtual void onRefreshReceived(int32_t sequenceId, hal::HWDisplayId display) = 0;
69 virtual void onVsyncReceived(int32_t sequenceId, hal::HWDisplayId display, int64_t timestamp,
70 std::optional<hal::VsyncPeriodNanos> vsyncPeriod) = 0;
71 virtual void onVsyncPeriodTimingChangedReceived(
72 int32_t sequenceId, hal::HWDisplayId display,
73 const hal::VsyncPeriodChangeTimeline& updatedTimeline) = 0;
74 virtual void onSeamlessPossible(int32_t sequenceId, hal::HWDisplayId display) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070075
Peiyong Line9d809e2020-04-14 13:10:48 -070076 virtual ~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
Ana Krulec4593b692019-01-11 22:07:25 -080084 class Config {
Dan Stoza651bf312015-10-23 17:03:17 -070085 public:
86 class Builder
87 {
88 public:
Peiyong Line9d809e2020-04-14 13:10:48 -070089 Builder(Display& display, hal::HWConfigId id);
Dan Stoza651bf312015-10-23 17:03:17 -070090
91 std::shared_ptr<const Config> build() {
92 return std::const_pointer_cast<const Config>(
93 std::move(mConfig));
94 }
95
96 Builder& setWidth(int32_t width) {
97 mConfig->mWidth = width;
98 return *this;
99 }
100 Builder& setHeight(int32_t height) {
101 mConfig->mHeight = height;
102 return *this;
103 }
104 Builder& setVsyncPeriod(int32_t vsyncPeriod) {
105 mConfig->mVsyncPeriod = vsyncPeriod;
106 return *this;
107 }
108 Builder& setDpiX(int32_t dpiX) {
109 if (dpiX == -1) {
110 mConfig->mDpiX = getDefaultDensity();
111 } else {
112 mConfig->mDpiX = dpiX / 1000.0f;
113 }
114 return *this;
115 }
116 Builder& setDpiY(int32_t dpiY) {
117 if (dpiY == -1) {
118 mConfig->mDpiY = getDefaultDensity();
119 } else {
120 mConfig->mDpiY = dpiY / 1000.0f;
121 }
122 return *this;
123 }
Ady Abraham7159f572019-10-11 11:10:18 -0700124 Builder& setConfigGroup(int32_t configGroup) {
125 mConfig->mConfigGroup = configGroup;
126 return *this;
127 }
Dan Stoza651bf312015-10-23 17:03:17 -0700128
129 private:
130 float getDefaultDensity();
131 std::shared_ptr<Config> mConfig;
132 };
133
Peiyong Line9d809e2020-04-14 13:10:48 -0700134 hal::HWDisplayId getDisplayId() const { return mDisplay.getId(); }
135 hal::HWConfigId getId() const { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700136
137 int32_t getWidth() const { return mWidth; }
138 int32_t getHeight() const { return mHeight; }
David Sodman1afa8b02018-10-15 11:20:48 -0700139 nsecs_t getVsyncPeriod() const { return mVsyncPeriod; }
Dan Stoza651bf312015-10-23 17:03:17 -0700140 float getDpiX() const { return mDpiX; }
141 float getDpiY() const { return mDpiY; }
Ady Abraham7159f572019-10-11 11:10:18 -0700142 int32_t getConfigGroup() const { return mConfigGroup; }
Dan Stoza651bf312015-10-23 17:03:17 -0700143
144 private:
Peiyong Line9d809e2020-04-14 13:10:48 -0700145 Config(Display& display, hal::HWConfigId id);
Dan Stoza651bf312015-10-23 17:03:17 -0700146
147 Display& mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700148 hal::HWConfigId mId;
Dan Stoza651bf312015-10-23 17:03:17 -0700149
150 int32_t mWidth;
151 int32_t mHeight;
152 nsecs_t mVsyncPeriod;
153 float mDpiX;
154 float mDpiY;
Ady Abraham7159f572019-10-11 11:10:18 -0700155 int32_t mConfigGroup;
Dan Stoza651bf312015-10-23 17:03:17 -0700156 };
157
Peiyong Line9d809e2020-04-14 13:10:48 -0700158 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800159 virtual bool isConnected() const = 0;
160 virtual void setConnected(bool connected) = 0; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -0700161 virtual const std::unordered_set<hal::DisplayCapability>& getCapabilities() const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -0700162 virtual bool isVsyncPeriodSwitchSupported() const = 0;
Dan Stoza651bf312015-10-23 17:03:17 -0700163
Peiyong Line9d809e2020-04-14 13:10:48 -0700164 [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0;
165 [[clang::warn_unused_result]] virtual hal::Error createLayer(Layer** outLayer) = 0;
166 [[clang::warn_unused_result]] virtual hal::Error destroyLayer(Layer* layer) = 0;
167 [[clang::warn_unused_result]] virtual hal::Error getActiveConfig(
Ana Krulec4593b692019-01-11 22:07:25 -0800168 std::shared_ptr<const Config>* outConfig) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700169 [[clang::warn_unused_result]] virtual hal::Error getActiveConfigIndex(int* outIndex) const = 0;
170 [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes(
171 std::unordered_map<Layer*, hal::Composition>* outTypes) = 0;
172 [[clang::warn_unused_result]] virtual hal::Error getColorModes(
173 std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +0800174 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -0800175 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700176 [[clang::warn_unused_result]] virtual hal::Error getRenderIntents(
177 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
178 [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix(
179 hal::Dataspace dataspace, android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800180
Peiyong Line9d809e2020-04-14 13:10:48 -0700181 // Doesn't call into the HWC2 device, so no errors are possible
182 [[clang::warn_unused_result]] virtual std::vector<std::shared_ptr<const Config>> getConfigs()
183 const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800184
Peiyong Line9d809e2020-04-14 13:10:48 -0700185 [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0;
186 [[clang::warn_unused_result]] virtual hal::Error getRequests(
187 hal::DisplayRequest* outDisplayRequests,
188 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
189 [[clang::warn_unused_result]] virtual hal::Error getConnectionType(
Dominik Laskowski55c85402020-01-21 16:25:47 -0800190 android::DisplayConnectionType*) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700191 [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
192 [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800193 android::HdrCapabilities* outCapabilities) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700194 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes(
195 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800196 uint8_t* outComponentMask) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700197 [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled(
Ana Krulec4593b692019-01-11 22:07:25 -0800198 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700199 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800200 uint64_t maxFrames, uint64_t timestamp,
201 android::DisplayedFrameStats* outStats) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700202 [[clang::warn_unused_result]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800203 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700204 [[clang::warn_unused_result]] virtual hal::Error present(
Ana Krulec4593b692019-01-11 22:07:25 -0800205 android::sp<android::Fence>* outPresentFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700206 [[clang::warn_unused_result]] virtual hal::Error setActiveConfig(
Ana Krulec4593b692019-01-11 22:07:25 -0800207 const std::shared_ptr<const Config>& config) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700208 [[clang::warn_unused_result]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800209 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700210 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
211 [[clang::warn_unused_result]] virtual hal::Error setColorMode(
212 hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
213 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
214 const android::mat4& matrix, hal::ColorTransform hint) = 0;
215 [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800216 const android::sp<android::GraphicBuffer>& buffer,
217 const android::sp<android::Fence>& releaseFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700218 [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
219 [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
220 [[clang::warn_unused_result]] virtual hal::Error validate(uint32_t* outNumTypes,
221 uint32_t* outNumRequests) = 0;
222 [[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
Ana Krulec4593b692019-01-11 22:07:25 -0800223 uint32_t* outNumTypes, uint32_t* outNumRequests,
224 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700225 [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
226 float brightness) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700227 [[clang::warn_unused_result]] virtual hal::Error getDisplayVsyncPeriod(
Ady Abraham7159f572019-10-11 11:10:18 -0700228 nsecs_t* outVsyncPeriod) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700229 [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
Ady Abraham7159f572019-10-11 11:10:18 -0700230 const std::shared_ptr<const HWC2::Display::Config>& config,
Peiyong Line9d809e2020-04-14 13:10:48 -0700231 const hal::VsyncPeriodChangeConstraints& constraints,
232 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700233 [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700234 [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
235 std::vector<hal::ContentType>*) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700236 [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700237 [[clang::warn_unused_result]] virtual hal::Error getClientTargetProperty(
238 hal::ClientTargetProperty* outClientTargetProperty) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800239};
240
241namespace impl {
242
243class Display : public HWC2::Display {
244public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700245 Display(android::Hwc2::Composer& composer,
246 const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId id,
247 hal::DisplayType type);
Ana Krulec4593b692019-01-11 22:07:25 -0800248 ~Display() override;
249
250 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700251 hal::Error acceptChanges() override;
252 hal::Error createLayer(Layer** outLayer) override;
253 hal::Error destroyLayer(Layer* layer) override;
254 hal::Error getActiveConfig(std::shared_ptr<const Config>* outConfig) const override;
255 hal::Error getActiveConfigIndex(int* outIndex) const override;
256 hal::Error getChangedCompositionTypes(
257 std::unordered_map<Layer*, hal::Composition>* outTypes) override;
258 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800259 // Returns a bitmask which contains HdrMetadata::Type::*.
260 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700261 hal::Error getRenderIntents(hal::ColorMode colorMode,
262 std::vector<hal::RenderIntent>* outRenderIntents) const override;
263 hal::Error getDataspaceSaturationMatrix(hal::Dataspace dataspace,
264 android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700265
266 // Doesn't call into the HWC2 device, so no errors are possible
Ana Krulec4593b692019-01-11 22:07:25 -0800267 std::vector<std::shared_ptr<const Config>> getConfigs() const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700268
Peiyong Line9d809e2020-04-14 13:10:48 -0700269 hal::Error getName(std::string* outName) const override;
270 hal::Error getRequests(
271 hal::DisplayRequest* outDisplayRequests,
272 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) override;
273 hal::Error getConnectionType(android::DisplayConnectionType*) const override;
274 hal::Error supportsDoze(bool* outSupport) const override;
275 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
276 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
277 hal::Dataspace* outDataspace,
278 uint8_t* outComponentMask) const override;
279 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
280 uint64_t maxFrames) const override;
281 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
282 android::DisplayedFrameStats* outStats) const override;
283 hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800284 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700285 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
286 hal::Error setActiveConfig(const std::shared_ptr<const HWC2::Display::Config>& config) override;
287 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
288 const android::sp<android::Fence>& acquireFence,
289 hal::Dataspace dataspace) override;
290 hal::Error setColorMode(hal::ColorMode mode, hal::RenderIntent renderIntent) override;
291 hal::Error setColorTransform(const android::mat4& matrix, hal::ColorTransform hint) override;
292 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>& buffer,
293 const android::sp<android::Fence>& releaseFence) override;
294 hal::Error setPowerMode(hal::PowerMode mode) override;
295 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
296 hal::Error validate(uint32_t* outNumTypes, uint32_t* outNumRequests) override;
297 hal::Error presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests,
298 android::sp<android::Fence>* outPresentFence,
299 uint32_t* state) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700300 std::future<hal::Error> setDisplayBrightness(float brightness) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700301 hal::Error getDisplayVsyncPeriod(nsecs_t* outVsyncPeriod) const override;
302 hal::Error setActiveConfigWithConstraints(
303 const std::shared_ptr<const HWC2::Display::Config>& config,
304 const hal::VsyncPeriodChangeConstraints& constraints,
305 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700306 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700307 hal::Error getSupportedContentTypes(
308 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700309 hal::Error setContentType(hal::ContentType) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700310 hal::Error getClientTargetProperty(hal::ClientTargetProperty* outClientTargetProperty) override;
311
Dan Stoza651bf312015-10-23 17:03:17 -0700312 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700313 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800314 bool isConnected() const override { return mIsConnected; }
315 void setConnected(bool connected) override; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -0700316 const std::unordered_set<hal::DisplayCapability>& getCapabilities() const override {
Peiyong Lined531a32018-10-26 18:27:56 -0700317 return mDisplayCapabilities;
318 };
Ady Abraham7159f572019-10-11 11:10:18 -0700319 virtual bool isVsyncPeriodSwitchSupported() const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700320
321private:
Peiyong Line9d809e2020-04-14 13:10:48 -0700322 int32_t getAttribute(hal::HWConfigId configId, hal::Attribute attribute);
323 void loadConfig(hal::HWConfigId configId);
Dan Stoza651bf312015-10-23 17:03:17 -0700324 void loadConfigs();
325
Dan Stoza651bf312015-10-23 17:03:17 -0700326 // This may fail (and return a null pointer) if no layer with this ID exists
327 // on this display
Peiyong Line9d809e2020-04-14 13:10:48 -0700328 Layer* getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700329
Lloyd Piquebc792092018-01-17 11:52:30 -0800330 friend android::TestableSurfaceFlinger;
331
Dan Stoza651bf312015-10-23 17:03:17 -0700332 // Member variables
333
Steven Thomas94e35b92017-07-26 18:48:28 -0700334 // These are references to data owned by HWC2::Device, which will outlive
335 // this HWC2::Display, 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
Peiyong Line9d809e2020-04-14 13:10:48 -0700340 const hal::HWDisplayId mId;
341 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800342 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700343
Peiyong Line9d809e2020-04-14 13:10:48 -0700344 std::unordered_map<hal::HWLayerId, std::unique_ptr<Layer>> mLayers;
345 std::unordered_map<hal::HWConfigId, std::shared_ptr<const Config>> mConfigs;
Ady Abraham7159f572019-10-11 11:10:18 -0700346
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700347 std::once_flag mDisplayCapabilityQueryFlag;
Peiyong Line9d809e2020-04-14 13:10:48 -0700348 std::unordered_set<hal::DisplayCapability> mDisplayCapabilities;
Dan Stoza651bf312015-10-23 17:03:17 -0700349};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800350
Ana Krulec4593b692019-01-11 22:07:25 -0800351} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700352
Lloyd Pique35d58242018-12-18 16:33:25 -0800353class Layer {
354public:
355 virtual ~Layer();
356
Peiyong Line9d809e2020-04-14 13:10:48 -0700357 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800358
Peiyong Line9d809e2020-04-14 13:10:48 -0700359 [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
360 [[clang::warn_unused_result]] virtual hal::Error setBuffer(
Lloyd Pique35d58242018-12-18 16:33:25 -0800361 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
362 const android::sp<android::Fence>& acquireFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700363 [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage(
364 const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800365
Peiyong Line9d809e2020-04-14 13:10:48 -0700366 [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
367 [[clang::warn_unused_result]] virtual hal::Error setColor(hal::Color color) = 0;
368 [[clang::warn_unused_result]] virtual hal::Error setCompositionType(hal::Composition type) = 0;
369 [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
370 [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata(
Lloyd Pique35d58242018-12-18 16:33:25 -0800371 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700372 [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame(
373 const android::Rect& frame) = 0;
374 [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
375 [[clang::warn_unused_result]] virtual hal::Error setSidebandStream(
Lloyd Pique35d58242018-12-18 16:33:25 -0800376 const native_handle_t* stream) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700377 [[clang::warn_unused_result]] virtual hal::Error setSourceCrop(
378 const android::FloatRect& crop) = 0;
379 [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0;
380 [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion(
381 const android::Region& region) = 0;
382 [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0;
383 [[clang::warn_unused_result]] virtual hal::Error setInfo(uint32_t type, uint32_t appId) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800384
385 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700386 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
387 const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800388
389 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700390 [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata(
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800391 const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800392};
393
394namespace impl {
395
Peiyong Line9d809e2020-04-14 13:10:48 -0700396// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800397
398class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700399public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700400 Layer(android::Hwc2::Composer& composer,
401 const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId displayId,
402 hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800403 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700404
Peiyong Line9d809e2020-04-14 13:10:48 -0700405 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700406
Peiyong Line9d809e2020-04-14 13:10:48 -0700407 hal::Error setCursorPosition(int32_t x, int32_t y) override;
408 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
409 const android::sp<android::Fence>& acquireFence) override;
410 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700411
Peiyong Line9d809e2020-04-14 13:10:48 -0700412 hal::Error setBlendMode(hal::BlendMode mode) override;
413 hal::Error setColor(hal::Color color) override;
414 hal::Error setCompositionType(hal::Composition type) override;
415 hal::Error setDataspace(hal::Dataspace dataspace) override;
416 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
417 const android::HdrMetadata& metadata) override;
418 hal::Error setDisplayFrame(const android::Rect& frame) override;
419 hal::Error setPlaneAlpha(float alpha) override;
420 hal::Error setSidebandStream(const native_handle_t* stream) override;
421 hal::Error setSourceCrop(const android::FloatRect& crop) override;
422 hal::Error setTransform(hal::Transform transform) override;
423 hal::Error setVisibleRegion(const android::Region& region) override;
424 hal::Error setZOrder(uint32_t z) override;
425 hal::Error setInfo(uint32_t type, uint32_t appId) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700426
Peiyong Lin698147a2018-09-14 13:27:18 -0700427 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700428 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700429
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800430 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700431 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
432 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800433
Dan Stoza651bf312015-10-23 17:03:17 -0700434private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700435 // These are references to data owned by HWC2::Device, which will outlive
436 // this HWC2::Layer, so these references are guaranteed to be valid for
437 // the lifetime of this object.
438 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700439 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700440
Peiyong Line9d809e2020-04-14 13:10:48 -0700441 hal::HWDisplayId mDisplayId;
442 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800443
444 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
445 // multiple times.
446 android::Region mVisibleRegion = android::Region::INVALID_REGION;
447 android::Region mDamageRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700448 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700449 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700450 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800451 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700452};
453
Lloyd Pique35d58242018-12-18 16:33:25 -0800454} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700455} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700456} // namespace android
Dan Stoza651bf312015-10-23 17:03:17 -0700457
458#endif // ANDROID_SF_HWC2_H