blob: e0a5ef14ddbc7ff77fb5aae368f6e66f491045a6 [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
20#define HWC2_INCLUDE_STRINGIFICATION
21#define HWC2_USE_CPP11
22#include <hardware/hwcomposer2.h>
23#undef HWC2_INCLUDE_STRINGIFICATION
24#undef HWC2_USE_CPP11
25
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070026#include <gui/HdrMetadata.h>
Mathias Agopian1d77b712017-02-17 15:46:13 -080027#include <math/mat4.h>
Peiyong Linfd997e02018-03-28 15:29:00 -070028#include <ui/GraphicTypes.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070029#include <ui/HdrCapabilities.h>
Yichi Chen8366f562019-03-25 19:44:06 +080030#include <ui/Region.h>
Dan Stoza651bf312015-10-23 17:03:17 -070031#include <utils/Log.h>
32#include <utils/StrongPointer.h>
33#include <utils/Timers.h>
34
35#include <functional>
36#include <string>
37#include <unordered_map>
Dan Stoza9f26a9c2016-06-22 14:51:09 -070038#include <unordered_set>
Dan Stoza651bf312015-10-23 17:03:17 -070039#include <vector>
40
41namespace android {
Kevin DuBois1d4249a2018-08-29 10:45:14 -070042 struct DisplayedFrameStats;
Dan Stoza651bf312015-10-23 17:03:17 -070043 class Fence;
Dan Stoza5a423ea2017-02-16 14:10:39 -080044 class FloatRect;
Dan Stoza651bf312015-10-23 17:03:17 -070045 class GraphicBuffer;
Chia-I Wuaab99f52016-10-05 12:59:58 +080046 namespace Hwc2 {
47 class Composer;
Dan Stoza71bded52016-10-19 11:10:33 -070048 }
Lloyd Piquebc792092018-01-17 11:52:30 -080049
50 class TestableSurfaceFlinger;
Dan Stoza651bf312015-10-23 17:03:17 -070051}
52
53namespace HWC2 {
54
55class Display;
56class Layer;
57
Steven Thomas94e35b92017-07-26 18:48:28 -070058// Implement this interface to receive hardware composer events.
59//
60// These callback functions will generally be called on a hwbinder thread, but
61// when first registering the callback the onHotplugReceived() function will
62// immediately be called on the thread calling registerCallback().
63//
64// All calls receive a sequenceId, which will be the value that was supplied to
65// HWC2::Device::registerCallback(). It's used to help differentiate callbacks
66// from different hardware composer instances.
67class ComposerCallback {
68 public:
69 virtual void onHotplugReceived(int32_t sequenceId, hwc2_display_t display,
Lloyd Pique715a2c12017-12-14 17:18:08 -080070 Connection connection) = 0;
Steven Thomas94e35b92017-07-26 18:48:28 -070071 virtual void onRefreshReceived(int32_t sequenceId,
72 hwc2_display_t display) = 0;
73 virtual void onVsyncReceived(int32_t sequenceId, hwc2_display_t display,
74 int64_t timestamp) = 0;
75 virtual ~ComposerCallback() = default;
76};
Dan Stoza651bf312015-10-23 17:03:17 -070077
Fabien Sanglard33960702016-11-29 17:58:21 -080078// C++ Wrapper around hwc2_device_t. Load all functions pointers
79// and handle callback registration.
Dan Stoza651bf312015-10-23 17:03:17 -070080class Device
81{
82public:
Lloyd Piquea822d522017-12-20 16:42:57 -080083 explicit Device(std::unique_ptr<android::Hwc2::Composer> composer);
Dan Stoza651bf312015-10-23 17:03:17 -070084
Steven Thomas94e35b92017-07-26 18:48:28 -070085 void registerCallback(ComposerCallback* callback, int32_t sequenceId);
Dan Stoza651bf312015-10-23 17:03:17 -070086
87 // Required by HWC2
88
89 std::string dump() const;
90
Dan Stoza9f26a9c2016-06-22 14:51:09 -070091 const std::unordered_set<Capability>& getCapabilities() const {
Dan Stoza651bf312015-10-23 17:03:17 -070092 return mCapabilities;
93 };
94
95 uint32_t getMaxVirtualDisplayCount() const;
Dominik Laskowski0954b1d2018-06-13 14:58:49 -070096 Error getDisplayIdentificationData(hwc2_display_t hwcDisplayId, uint8_t* outPort,
97 std::vector<uint8_t>* outData) const;
98
Dan Stoza651bf312015-10-23 17:03:17 -070099 Error createVirtualDisplay(uint32_t width, uint32_t height,
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700100 android::ui::PixelFormat* format, Display** outDisplay);
Steven Thomas94e35b92017-07-26 18:48:28 -0700101 void destroyDisplay(hwc2_display_t displayId);
Dan Stoza651bf312015-10-23 17:03:17 -0700102
Steven Thomas94e35b92017-07-26 18:48:28 -0700103 void onHotplug(hwc2_display_t displayId, Connection connection);
Dan Stoza651bf312015-10-23 17:03:17 -0700104
105 // Other Device methods
106
Steven Thomas94e35b92017-07-26 18:48:28 -0700107 Display* getDisplayById(hwc2_display_t id);
Dan Stoza09e7a272016-04-14 12:31:01 -0700108
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800109 android::Hwc2::Composer* getComposer() { return mComposer.get(); }
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800110
Chia-I Wuae5a6b82017-10-10 09:09:22 -0700111 // We buffer most state changes and flush them implicitly with
112 // Display::validate, Display::present, and Display::presentOrValidate.
113 // This method provides an explicit way to flush state changes to HWC.
114 Error flushCommands();
115
Dan Stoza651bf312015-10-23 17:03:17 -0700116private:
117 // Initialization methods
118
Dan Stoza651bf312015-10-23 17:03:17 -0700119 void loadCapabilities();
Dan Stoza651bf312015-10-23 17:03:17 -0700120
121 // Member variables
Chia-I Wuaab99f52016-10-05 12:59:58 +0800122 std::unique_ptr<android::Hwc2::Composer> mComposer;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700123 std::unordered_set<Capability> mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700124 std::unordered_map<hwc2_display_t, std::unique_ptr<Display>> mDisplays;
Lloyd Piquea822d522017-12-20 16:42:57 -0800125 bool mRegisteredCallback = false;
Dan Stoza651bf312015-10-23 17:03:17 -0700126};
127
Fabien Sanglard33960702016-11-29 17:58:21 -0800128// Convenience C++ class to access hwc2_device_t Display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -0800129class Display {
Dan Stoza651bf312015-10-23 17:03:17 -0700130public:
Ana Krulec4593b692019-01-11 22:07:25 -0800131 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -0700132
Ana Krulec4593b692019-01-11 22:07:25 -0800133 class Config {
Dan Stoza651bf312015-10-23 17:03:17 -0700134 public:
135 class Builder
136 {
137 public:
138 Builder(Display& display, hwc2_config_t id);
139
140 std::shared_ptr<const Config> build() {
141 return std::const_pointer_cast<const Config>(
142 std::move(mConfig));
143 }
144
145 Builder& setWidth(int32_t width) {
146 mConfig->mWidth = width;
147 return *this;
148 }
149 Builder& setHeight(int32_t height) {
150 mConfig->mHeight = height;
151 return *this;
152 }
153 Builder& setVsyncPeriod(int32_t vsyncPeriod) {
154 mConfig->mVsyncPeriod = vsyncPeriod;
155 return *this;
156 }
157 Builder& setDpiX(int32_t dpiX) {
158 if (dpiX == -1) {
159 mConfig->mDpiX = getDefaultDensity();
160 } else {
161 mConfig->mDpiX = dpiX / 1000.0f;
162 }
163 return *this;
164 }
165 Builder& setDpiY(int32_t dpiY) {
166 if (dpiY == -1) {
167 mConfig->mDpiY = getDefaultDensity();
168 } else {
169 mConfig->mDpiY = dpiY / 1000.0f;
170 }
171 return *this;
172 }
173
174 private:
175 float getDefaultDensity();
176 std::shared_ptr<Config> mConfig;
177 };
178
179 hwc2_display_t getDisplayId() const { return mDisplay.getId(); }
180 hwc2_config_t getId() const { return mId; }
181
182 int32_t getWidth() const { return mWidth; }
183 int32_t getHeight() const { return mHeight; }
David Sodman1afa8b02018-10-15 11:20:48 -0700184 nsecs_t getVsyncPeriod() const { return mVsyncPeriod; }
Dan Stoza651bf312015-10-23 17:03:17 -0700185 float getDpiX() const { return mDpiX; }
186 float getDpiY() const { return mDpiY; }
187
188 private:
189 Config(Display& display, hwc2_config_t id);
190
191 Display& mDisplay;
192 hwc2_config_t mId;
193
194 int32_t mWidth;
195 int32_t mHeight;
196 nsecs_t mVsyncPeriod;
197 float mDpiX;
198 float mDpiY;
199 };
200
Ana Krulec4593b692019-01-11 22:07:25 -0800201 virtual hwc2_display_t getId() const = 0;
202 virtual bool isConnected() const = 0;
203 virtual void setConnected(bool connected) = 0; // For use by Device only
204 virtual const std::unordered_set<DisplayCapability>& getCapabilities() const = 0;
Dan Stoza651bf312015-10-23 17:03:17 -0700205
Ana Krulec4593b692019-01-11 22:07:25 -0800206 [[clang::warn_unused_result]] virtual Error acceptChanges() = 0;
207 [[clang::warn_unused_result]] virtual Error createLayer(Layer** outLayer) = 0;
208 [[clang::warn_unused_result]] virtual Error destroyLayer(Layer* layer) = 0;
209 [[clang::warn_unused_result]] virtual Error getActiveConfig(
210 std::shared_ptr<const Config>* outConfig) const = 0;
211 [[clang::warn_unused_result]] virtual Error getActiveConfigIndex(int* outIndex) const = 0;
212 [[clang::warn_unused_result]] virtual Error getChangedCompositionTypes(
213 std::unordered_map<Layer*, Composition>* outTypes) = 0;
214 [[clang::warn_unused_result]] virtual Error getColorModes(
215 std::vector<android::ui::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +0800216 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -0800217 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
218 [[clang::warn_unused_result]] virtual Error getRenderIntents(
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700219 android::ui::ColorMode colorMode,
Ana Krulec4593b692019-01-11 22:07:25 -0800220 std::vector<android::ui::RenderIntent>* outRenderIntents) const = 0;
221 [[clang::warn_unused_result]] virtual Error getDataspaceSaturationMatrix(
222 android::ui::Dataspace dataspace, android::mat4* outMatrix) = 0;
223
224 // Doesn't call into the HWC2 device, so no Errors are possible
225 virtual std::vector<std::shared_ptr<const Config>> getConfigs() const = 0;
226
227 [[clang::warn_unused_result]] virtual Error getName(std::string* outName) const = 0;
228 [[clang::warn_unused_result]] virtual Error getRequests(
229 DisplayRequest* outDisplayRequests,
230 std::unordered_map<Layer*, LayerRequest>* outLayerRequests) = 0;
231 [[clang::warn_unused_result]] virtual Error getType(DisplayType* outType) const = 0;
232 [[clang::warn_unused_result]] virtual Error supportsDoze(bool* outSupport) const = 0;
233 [[clang::warn_unused_result]] virtual Error getHdrCapabilities(
234 android::HdrCapabilities* outCapabilities) const = 0;
235 [[clang::warn_unused_result]] virtual Error getDisplayedContentSamplingAttributes(
236 android::ui::PixelFormat* outFormat, android::ui::Dataspace* outDataspace,
237 uint8_t* outComponentMask) const = 0;
238 [[clang::warn_unused_result]] virtual Error setDisplayContentSamplingEnabled(
239 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
240 [[clang::warn_unused_result]] virtual Error getDisplayedContentSample(
241 uint64_t maxFrames, uint64_t timestamp,
242 android::DisplayedFrameStats* outStats) const = 0;
243 [[clang::warn_unused_result]] virtual Error getReleaseFences(
244 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
245 [[clang::warn_unused_result]] virtual Error present(
246 android::sp<android::Fence>* outPresentFence) = 0;
247 [[clang::warn_unused_result]] virtual Error setActiveConfig(
248 const std::shared_ptr<const Config>& config) = 0;
249 [[clang::warn_unused_result]] virtual Error setClientTarget(
250 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
251 const android::sp<android::Fence>& acquireFence, android::ui::Dataspace dataspace) = 0;
252 [[clang::warn_unused_result]] virtual Error setColorMode(
253 android::ui::ColorMode mode, android::ui::RenderIntent renderIntent) = 0;
254 [[clang::warn_unused_result]] virtual Error setColorTransform(
255 const android::mat4& matrix, android_color_transform_t hint) = 0;
256 [[clang::warn_unused_result]] virtual Error setOutputBuffer(
257 const android::sp<android::GraphicBuffer>& buffer,
258 const android::sp<android::Fence>& releaseFence) = 0;
259 [[clang::warn_unused_result]] virtual Error setPowerMode(PowerMode mode) = 0;
260 [[clang::warn_unused_result]] virtual Error setVsyncEnabled(Vsync enabled) = 0;
261 [[clang::warn_unused_result]] virtual Error validate(uint32_t* outNumTypes,
262 uint32_t* outNumRequests) = 0;
263 [[clang::warn_unused_result]] virtual Error presentOrValidate(
264 uint32_t* outNumTypes, uint32_t* outNumRequests,
265 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Dan Gittik57e63c52019-01-18 16:37:54 +0000266 [[clang::warn_unused_result]] virtual Error setDisplayBrightness(float brightness) const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800267};
268
269namespace impl {
270
271class Display : public HWC2::Display {
272public:
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800273 Display(android::Hwc2::Composer& composer, const std::unordered_set<Capability>& capabilities,
274 hwc2_display_t id, DisplayType type);
Ana Krulec4593b692019-01-11 22:07:25 -0800275 ~Display() override;
276
277 // Required by HWC2
278 Error acceptChanges() override;
279 Error createLayer(Layer** outLayer) override;
280 Error destroyLayer(Layer* layer) override;
281 Error getActiveConfig(std::shared_ptr<const Config>* outConfig) const override;
282 Error getActiveConfigIndex(int* outIndex) const override;
283 Error getChangedCompositionTypes(std::unordered_map<Layer*, Composition>* outTypes) override;
284 Error getColorModes(std::vector<android::ui::ColorMode>* outModes) const override;
285 // Returns a bitmask which contains HdrMetadata::Type::*.
286 int32_t getSupportedPerFrameMetadata() const override;
287 Error getRenderIntents(android::ui::ColorMode colorMode,
288 std::vector<android::ui::RenderIntent>* outRenderIntents) const override;
289 Error getDataspaceSaturationMatrix(android::ui::Dataspace dataspace,
290 android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700291
292 // Doesn't call into the HWC2 device, so no errors are possible
Ana Krulec4593b692019-01-11 22:07:25 -0800293 std::vector<std::shared_ptr<const Config>> getConfigs() const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700294
Ana Krulec4593b692019-01-11 22:07:25 -0800295 Error getName(std::string* outName) const override;
296 Error getRequests(DisplayRequest* outDisplayRequests,
297 std::unordered_map<Layer*, LayerRequest>* outLayerRequests) override;
298 Error getType(DisplayType* outType) const override;
299 Error supportsDoze(bool* outSupport) const override;
300 Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
301 Error getDisplayedContentSamplingAttributes(android::ui::PixelFormat* outFormat,
302 android::ui::Dataspace* outDataspace,
303 uint8_t* outComponentMask) const override;
304 Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
305 uint64_t maxFrames) const override;
306 Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
307 android::DisplayedFrameStats* outStats) const override;
308 Error getReleaseFences(
309 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const override;
310 Error present(android::sp<android::Fence>* outPresentFence) override;
311 Error setActiveConfig(const std::shared_ptr<const HWC2::Display::Config>& config) override;
312 Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
313 const android::sp<android::Fence>& acquireFence,
314 android::ui::Dataspace dataspace) override;
315 Error setColorMode(android::ui::ColorMode mode,
316 android::ui::RenderIntent renderIntent) override;
317 Error setColorTransform(const android::mat4& matrix, android_color_transform_t hint) override;
318 Error setOutputBuffer(const android::sp<android::GraphicBuffer>& buffer,
319 const android::sp<android::Fence>& releaseFence) override;
320 Error setPowerMode(PowerMode mode) override;
321 Error setVsyncEnabled(Vsync enabled) override;
322 Error validate(uint32_t* outNumTypes, uint32_t* outNumRequests) override;
323 Error presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests,
324 android::sp<android::Fence>* outPresentFence, uint32_t* state) override;
Dan Gittik57e63c52019-01-18 16:37:54 +0000325 Error setDisplayBrightness(float brightness) const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700326
327 // Other Display methods
Ana Krulec4593b692019-01-11 22:07:25 -0800328 hwc2_display_t getId() const override { return mId; }
329 bool isConnected() const override { return mIsConnected; }
330 void setConnected(bool connected) override; // For use by Device only
331 const std::unordered_set<DisplayCapability>& getCapabilities() const override {
Peiyong Lined531a32018-10-26 18:27:56 -0700332 return mDisplayCapabilities;
333 };
Dan Stoza651bf312015-10-23 17:03:17 -0700334
335private:
Dan Stoza651bf312015-10-23 17:03:17 -0700336 int32_t getAttribute(hwc2_config_t configId, Attribute attribute);
337 void loadConfig(hwc2_config_t configId);
338 void loadConfigs();
339
Dan Stoza651bf312015-10-23 17:03:17 -0700340 // This may fail (and return a null pointer) if no layer with this ID exists
341 // on this display
Steven Thomas94e35b92017-07-26 18:48:28 -0700342 Layer* getLayerById(hwc2_layer_t id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700343
Lloyd Piquebc792092018-01-17 11:52:30 -0800344 friend android::TestableSurfaceFlinger;
345
Dan Stoza651bf312015-10-23 17:03:17 -0700346 // Member variables
347
Steven Thomas94e35b92017-07-26 18:48:28 -0700348 // These are references to data owned by HWC2::Device, which will outlive
349 // this HWC2::Display, so these references are guaranteed to be valid for
350 // the lifetime of this object.
351 android::Hwc2::Composer& mComposer;
352 const std::unordered_set<Capability>& mCapabilities;
353
Dan Stoza651bf312015-10-23 17:03:17 -0700354 hwc2_display_t mId;
355 bool mIsConnected;
Chris Forbes016d73c2017-04-11 10:04:31 -0700356 DisplayType mType;
Steven Thomas94e35b92017-07-26 18:48:28 -0700357 std::unordered_map<hwc2_layer_t, std::unique_ptr<Layer>> mLayers;
Lloyd Pique3c085a02018-05-09 19:38:32 -0700358 std::unordered_map<hwc2_config_t, std::shared_ptr<const Config>> mConfigs;
Peiyong Lined531a32018-10-26 18:27:56 -0700359 std::unordered_set<DisplayCapability> mDisplayCapabilities;
Dan Stoza651bf312015-10-23 17:03:17 -0700360};
Ana Krulec4593b692019-01-11 22:07:25 -0800361} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700362
Lloyd Pique35d58242018-12-18 16:33:25 -0800363class Layer {
364public:
365 virtual ~Layer();
366
367 virtual hwc2_layer_t getId() const = 0;
368
369 [[clang::warn_unused_result]] virtual Error setCursorPosition(int32_t x, int32_t y) = 0;
370 [[clang::warn_unused_result]] virtual Error setBuffer(
371 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
372 const android::sp<android::Fence>& acquireFence) = 0;
373 [[clang::warn_unused_result]] virtual Error setSurfaceDamage(const android::Region& damage) = 0;
374
375 [[clang::warn_unused_result]] virtual Error setBlendMode(BlendMode mode) = 0;
376 [[clang::warn_unused_result]] virtual Error setColor(hwc_color_t color) = 0;
377 [[clang::warn_unused_result]] virtual Error setCompositionType(Composition type) = 0;
378 [[clang::warn_unused_result]] virtual Error setDataspace(android::ui::Dataspace dataspace) = 0;
379 [[clang::warn_unused_result]] virtual Error setPerFrameMetadata(
380 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
381 [[clang::warn_unused_result]] virtual Error setDisplayFrame(const android::Rect& frame) = 0;
382 [[clang::warn_unused_result]] virtual Error setPlaneAlpha(float alpha) = 0;
383 [[clang::warn_unused_result]] virtual Error setSidebandStream(
384 const native_handle_t* stream) = 0;
385 [[clang::warn_unused_result]] virtual Error setSourceCrop(const android::FloatRect& crop) = 0;
386 [[clang::warn_unused_result]] virtual Error setTransform(Transform transform) = 0;
387 [[clang::warn_unused_result]] virtual Error setVisibleRegion(const android::Region& region) = 0;
388 [[clang::warn_unused_result]] virtual Error setZOrder(uint32_t z) = 0;
389 [[clang::warn_unused_result]] virtual Error setInfo(uint32_t type, uint32_t appId) = 0;
390
391 // Composer HAL 2.3
392 [[clang::warn_unused_result]] virtual Error setColorTransform(const android::mat4& matrix) = 0;
393};
394
395namespace impl {
396
Fabien Sanglard33960702016-11-29 17:58:21 -0800397// Convenience C++ class to access hwc2_device_t Layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800398
399class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700400public:
Steven Thomas94e35b92017-07-26 18:48:28 -0700401 Layer(android::Hwc2::Composer& composer,
402 const std::unordered_set<Capability>& capabilities,
403 hwc2_display_t displayId, hwc2_layer_t layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800404 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700405
Lloyd Pique35d58242018-12-18 16:33:25 -0800406 hwc2_layer_t getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700407
Lloyd Pique35d58242018-12-18 16:33:25 -0800408 Error setCursorPosition(int32_t x, int32_t y) override;
409 Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
410 const android::sp<android::Fence>& acquireFence) override;
411 Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700412
Lloyd Pique35d58242018-12-18 16:33:25 -0800413 Error setBlendMode(BlendMode mode) override;
414 Error setColor(hwc_color_t color) override;
415 Error setCompositionType(Composition type) override;
416 Error setDataspace(android::ui::Dataspace dataspace) override;
417 Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
418 const android::HdrMetadata& metadata) override;
419 Error setDisplayFrame(const android::Rect& frame) override;
420 Error setPlaneAlpha(float alpha) override;
421 Error setSidebandStream(const native_handle_t* stream) override;
422 Error setSourceCrop(const android::FloatRect& crop) override;
423 Error setTransform(Transform transform) override;
424 Error setVisibleRegion(const android::Region& region) override;
425 Error setZOrder(uint32_t z) override;
426 Error setInfo(uint32_t type, uint32_t appId) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700427
Peiyong Lin698147a2018-09-14 13:27:18 -0700428 // Composer HAL 2.3
Lloyd Pique35d58242018-12-18 16:33:25 -0800429 Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700430
Dan Stoza651bf312015-10-23 17:03:17 -0700431private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700432 // These are references to data owned by HWC2::Device, which will outlive
433 // this HWC2::Layer, so these references are guaranteed to be valid for
434 // the lifetime of this object.
435 android::Hwc2::Composer& mComposer;
436 const std::unordered_set<Capability>& mCapabilities;
437
Dan Stoza651bf312015-10-23 17:03:17 -0700438 hwc2_display_t mDisplayId;
Dan Stoza651bf312015-10-23 17:03:17 -0700439 hwc2_layer_t mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800440
441 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
442 // multiple times.
443 android::Region mVisibleRegion = android::Region::INVALID_REGION;
444 android::Region mDamageRegion = android::Region::INVALID_REGION;
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700445 android::ui::Dataspace mDataSpace = android::ui::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700446 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700447 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800448 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700449};
450
Lloyd Pique35d58242018-12-18 16:33:25 -0800451} // namespace impl
452
Dan Stoza651bf312015-10-23 17:03:17 -0700453} // namespace HWC2
454
455#endif // ANDROID_SF_HWC2_H