blob: 12f26f62ef4709fa770c9d0df7bd038d7b4426b0 [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
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070019#include <gui/HdrMetadata.h>
Mathias Agopian1d77b712017-02-17 15:46:13 -080020#include <math/mat4.h>
Dominik Laskowski55c85402020-01-21 16:25:47 -080021#include <ui/DisplayInfo.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070022#include <ui/HdrCapabilities.h>
Yichi Chen8366f562019-03-25 19:44:06 +080023#include <ui/Region.h>
Dan Stoza651bf312015-10-23 17:03:17 -070024#include <utils/Log.h>
25#include <utils/StrongPointer.h>
26#include <utils/Timers.h>
27
28#include <functional>
Dominik Laskowski5690bde2020-04-23 19:04:22 -070029#include <future>
Dan Stoza651bf312015-10-23 17:03:17 -070030#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 {
Lloyd Piquebc792092018-01-17 11:52:30 -080038
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070039class Fence;
40class FloatRect;
41class GraphicBuffer;
42class TestableSurfaceFlinger;
43struct DisplayedFrameStats;
44
45namespace Hwc2 {
46class Composer;
47} // namespace Hwc2
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.
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070064struct ComposerCallback {
65 virtual void onHotplugReceived(int32_t sequenceId, hal::HWDisplayId, hal::Connection) = 0;
66 virtual void onRefreshReceived(int32_t sequenceId, hal::HWDisplayId) = 0;
67 virtual void onVsyncReceived(int32_t sequenceId, hal::HWDisplayId, int64_t timestamp,
68 std::optional<hal::VsyncPeriodNanos>) = 0;
69 virtual void onVsyncPeriodTimingChangedReceived(int32_t sequenceId, hal::HWDisplayId,
70 const hal::VsyncPeriodChangeTimeline&) = 0;
71 virtual void onSeamlessPossible(int32_t sequenceId, hal::HWDisplayId) = 0;
Ady Abraham7159f572019-10-11 11:10:18 -070072
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070073protected:
74 ~ComposerCallback() = default;
Steven Thomas94e35b92017-07-26 18:48:28 -070075};
Dan Stoza651bf312015-10-23 17:03:17 -070076
Peiyong Line9d809e2020-04-14 13:10:48 -070077// Convenience C++ class to access per display functions directly.
Ana Krulec4593b692019-01-11 22:07:25 -080078class Display {
Dan Stoza651bf312015-10-23 17:03:17 -070079public:
Ana Krulec4593b692019-01-11 22:07:25 -080080 virtual ~Display();
Dan Stoza651bf312015-10-23 17:03:17 -070081
Ana Krulec4593b692019-01-11 22:07:25 -080082 class Config {
Dan Stoza651bf312015-10-23 17:03:17 -070083 public:
84 class Builder
85 {
86 public:
Peiyong Line9d809e2020-04-14 13:10:48 -070087 Builder(Display& display, hal::HWConfigId id);
Dan Stoza651bf312015-10-23 17:03:17 -070088
89 std::shared_ptr<const Config> build() {
90 return std::const_pointer_cast<const Config>(
91 std::move(mConfig));
92 }
93
94 Builder& setWidth(int32_t width) {
95 mConfig->mWidth = width;
96 return *this;
97 }
98 Builder& setHeight(int32_t height) {
99 mConfig->mHeight = height;
100 return *this;
101 }
102 Builder& setVsyncPeriod(int32_t vsyncPeriod) {
103 mConfig->mVsyncPeriod = vsyncPeriod;
104 return *this;
105 }
106 Builder& setDpiX(int32_t dpiX) {
107 if (dpiX == -1) {
108 mConfig->mDpiX = getDefaultDensity();
109 } else {
110 mConfig->mDpiX = dpiX / 1000.0f;
111 }
112 return *this;
113 }
114 Builder& setDpiY(int32_t dpiY) {
115 if (dpiY == -1) {
116 mConfig->mDpiY = getDefaultDensity();
117 } else {
118 mConfig->mDpiY = dpiY / 1000.0f;
119 }
120 return *this;
121 }
Ady Abraham7159f572019-10-11 11:10:18 -0700122 Builder& setConfigGroup(int32_t configGroup) {
123 mConfig->mConfigGroup = configGroup;
124 return *this;
125 }
Dan Stoza651bf312015-10-23 17:03:17 -0700126
127 private:
128 float getDefaultDensity();
129 std::shared_ptr<Config> mConfig;
130 };
131
Peiyong Line9d809e2020-04-14 13:10:48 -0700132 hal::HWDisplayId getDisplayId() const { return mDisplay.getId(); }
133 hal::HWConfigId getId() const { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700134
135 int32_t getWidth() const { return mWidth; }
136 int32_t getHeight() const { return mHeight; }
David Sodman1afa8b02018-10-15 11:20:48 -0700137 nsecs_t getVsyncPeriod() const { return mVsyncPeriod; }
Dan Stoza651bf312015-10-23 17:03:17 -0700138 float getDpiX() const { return mDpiX; }
139 float getDpiY() const { return mDpiY; }
Ady Abraham7159f572019-10-11 11:10:18 -0700140 int32_t getConfigGroup() const { return mConfigGroup; }
Dan Stoza651bf312015-10-23 17:03:17 -0700141
142 private:
Peiyong Line9d809e2020-04-14 13:10:48 -0700143 Config(Display& display, hal::HWConfigId id);
Dan Stoza651bf312015-10-23 17:03:17 -0700144
145 Display& mDisplay;
Peiyong Line9d809e2020-04-14 13:10:48 -0700146 hal::HWConfigId mId;
Dan Stoza651bf312015-10-23 17:03:17 -0700147
148 int32_t mWidth;
149 int32_t mHeight;
150 nsecs_t mVsyncPeriod;
151 float mDpiX;
152 float mDpiY;
Ady Abraham7159f572019-10-11 11:10:18 -0700153 int32_t mConfigGroup;
Dan Stoza651bf312015-10-23 17:03:17 -0700154 };
155
Peiyong Line9d809e2020-04-14 13:10:48 -0700156 virtual hal::HWDisplayId getId() const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800157 virtual bool isConnected() const = 0;
158 virtual void setConnected(bool connected) = 0; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -0700159 virtual const std::unordered_set<hal::DisplayCapability>& getCapabilities() const = 0;
Ady Abraham7159f572019-10-11 11:10:18 -0700160 virtual bool isVsyncPeriodSwitchSupported() const = 0;
Dan Stoza651bf312015-10-23 17:03:17 -0700161
Peiyong Line9d809e2020-04-14 13:10:48 -0700162 [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0;
163 [[clang::warn_unused_result]] virtual hal::Error createLayer(Layer** outLayer) = 0;
164 [[clang::warn_unused_result]] virtual hal::Error destroyLayer(Layer* layer) = 0;
165 [[clang::warn_unused_result]] virtual hal::Error getActiveConfig(
Ana Krulec4593b692019-01-11 22:07:25 -0800166 std::shared_ptr<const Config>* outConfig) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700167 [[clang::warn_unused_result]] virtual hal::Error getActiveConfigIndex(int* outIndex) const = 0;
168 [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes(
169 std::unordered_map<Layer*, hal::Composition>* outTypes) = 0;
170 [[clang::warn_unused_result]] virtual hal::Error getColorModes(
171 std::vector<hal::ColorMode>* outModes) const = 0;
Chia-I Wud7e01d72018-06-21 13:39:09 +0800172 // Returns a bitmask which contains HdrMetadata::Type::*.
Ana Krulec4593b692019-01-11 22:07:25 -0800173 [[clang::warn_unused_result]] virtual int32_t getSupportedPerFrameMetadata() const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700174 [[clang::warn_unused_result]] virtual hal::Error getRenderIntents(
175 hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const = 0;
176 [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix(
177 hal::Dataspace dataspace, android::mat4* outMatrix) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800178
Peiyong Line9d809e2020-04-14 13:10:48 -0700179 // Doesn't call into the HWC2 device, so no errors are possible
180 [[clang::warn_unused_result]] virtual std::vector<std::shared_ptr<const Config>> getConfigs()
181 const = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800182
Peiyong Line9d809e2020-04-14 13:10:48 -0700183 [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0;
184 [[clang::warn_unused_result]] virtual hal::Error getRequests(
185 hal::DisplayRequest* outDisplayRequests,
186 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0;
187 [[clang::warn_unused_result]] virtual hal::Error getConnectionType(
Dominik Laskowski55c85402020-01-21 16:25:47 -0800188 android::DisplayConnectionType*) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700189 [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0;
190 [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities(
Ana Krulec4593b692019-01-11 22:07:25 -0800191 android::HdrCapabilities* outCapabilities) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700192 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSamplingAttributes(
193 hal::PixelFormat* outFormat, hal::Dataspace* outDataspace,
Ana Krulec4593b692019-01-11 22:07:25 -0800194 uint8_t* outComponentMask) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700195 [[clang::warn_unused_result]] virtual hal::Error setDisplayContentSamplingEnabled(
Ana Krulec4593b692019-01-11 22:07:25 -0800196 bool enabled, uint8_t componentMask, uint64_t maxFrames) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700197 [[clang::warn_unused_result]] virtual hal::Error getDisplayedContentSample(
Ana Krulec4593b692019-01-11 22:07:25 -0800198 uint64_t maxFrames, uint64_t timestamp,
199 android::DisplayedFrameStats* outStats) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700200 [[clang::warn_unused_result]] virtual hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800201 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700202 [[clang::warn_unused_result]] virtual hal::Error present(
Ana Krulec4593b692019-01-11 22:07:25 -0800203 android::sp<android::Fence>* outPresentFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700204 [[clang::warn_unused_result]] virtual hal::Error setActiveConfig(
Ana Krulec4593b692019-01-11 22:07:25 -0800205 const std::shared_ptr<const Config>& config) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700206 [[clang::warn_unused_result]] virtual hal::Error setClientTarget(
Ana Krulec4593b692019-01-11 22:07:25 -0800207 uint32_t slot, const android::sp<android::GraphicBuffer>& target,
Peiyong Line9d809e2020-04-14 13:10:48 -0700208 const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0;
209 [[clang::warn_unused_result]] virtual hal::Error setColorMode(
210 hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
211 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
212 const android::mat4& matrix, hal::ColorTransform hint) = 0;
213 [[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
Ana Krulec4593b692019-01-11 22:07:25 -0800214 const android::sp<android::GraphicBuffer>& buffer,
215 const android::sp<android::Fence>& releaseFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700216 [[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
217 [[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
218 [[clang::warn_unused_result]] virtual hal::Error validate(uint32_t* outNumTypes,
219 uint32_t* outNumRequests) = 0;
220 [[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
Ana Krulec4593b692019-01-11 22:07:25 -0800221 uint32_t* outNumTypes, uint32_t* outNumRequests,
222 android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700223 [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
224 float brightness) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700225 [[clang::warn_unused_result]] virtual hal::Error getDisplayVsyncPeriod(
Ady Abraham7159f572019-10-11 11:10:18 -0700226 nsecs_t* outVsyncPeriod) const = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700227 [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
Ady Abraham7159f572019-10-11 11:10:18 -0700228 const std::shared_ptr<const HWC2::Display::Config>& config,
Peiyong Line9d809e2020-04-14 13:10:48 -0700229 const hal::VsyncPeriodChangeConstraints& constraints,
230 hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700231 [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700232 [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
233 std::vector<hal::ContentType>*) const = 0;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700234 [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700235 [[clang::warn_unused_result]] virtual hal::Error getClientTargetProperty(
236 hal::ClientTargetProperty* outClientTargetProperty) = 0;
Ana Krulec4593b692019-01-11 22:07:25 -0800237};
238
239namespace impl {
240
241class Display : public HWC2::Display {
242public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700243 Display(android::Hwc2::Composer& composer,
244 const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId id,
245 hal::DisplayType type);
Ana Krulec4593b692019-01-11 22:07:25 -0800246 ~Display() override;
247
248 // Required by HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700249 hal::Error acceptChanges() override;
250 hal::Error createLayer(Layer** outLayer) override;
251 hal::Error destroyLayer(Layer* layer) override;
252 hal::Error getActiveConfig(std::shared_ptr<const Config>* outConfig) const override;
253 hal::Error getActiveConfigIndex(int* outIndex) const override;
254 hal::Error getChangedCompositionTypes(
255 std::unordered_map<Layer*, hal::Composition>* outTypes) override;
256 hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override;
Ana Krulec4593b692019-01-11 22:07:25 -0800257 // Returns a bitmask which contains HdrMetadata::Type::*.
258 int32_t getSupportedPerFrameMetadata() const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700259 hal::Error getRenderIntents(hal::ColorMode colorMode,
260 std::vector<hal::RenderIntent>* outRenderIntents) const override;
261 hal::Error getDataspaceSaturationMatrix(hal::Dataspace dataspace,
262 android::mat4* outMatrix) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700263
264 // Doesn't call into the HWC2 device, so no errors are possible
Ana Krulec4593b692019-01-11 22:07:25 -0800265 std::vector<std::shared_ptr<const Config>> getConfigs() const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700266
Peiyong Line9d809e2020-04-14 13:10:48 -0700267 hal::Error getName(std::string* outName) const override;
268 hal::Error getRequests(
269 hal::DisplayRequest* outDisplayRequests,
270 std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) override;
271 hal::Error getConnectionType(android::DisplayConnectionType*) const override;
272 hal::Error supportsDoze(bool* outSupport) const override;
273 hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override;
274 hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat,
275 hal::Dataspace* outDataspace,
276 uint8_t* outComponentMask) const override;
277 hal::Error setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask,
278 uint64_t maxFrames) const override;
279 hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp,
280 android::DisplayedFrameStats* outStats) const override;
281 hal::Error getReleaseFences(
Ana Krulec4593b692019-01-11 22:07:25 -0800282 std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700283 hal::Error present(android::sp<android::Fence>* outPresentFence) override;
284 hal::Error setActiveConfig(const std::shared_ptr<const HWC2::Display::Config>& config) override;
285 hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target,
286 const android::sp<android::Fence>& acquireFence,
287 hal::Dataspace dataspace) override;
288 hal::Error setColorMode(hal::ColorMode mode, hal::RenderIntent renderIntent) override;
289 hal::Error setColorTransform(const android::mat4& matrix, hal::ColorTransform hint) override;
290 hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>& buffer,
291 const android::sp<android::Fence>& releaseFence) override;
292 hal::Error setPowerMode(hal::PowerMode mode) override;
293 hal::Error setVsyncEnabled(hal::Vsync enabled) override;
294 hal::Error validate(uint32_t* outNumTypes, uint32_t* outNumRequests) override;
295 hal::Error presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests,
296 android::sp<android::Fence>* outPresentFence,
297 uint32_t* state) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700298 std::future<hal::Error> setDisplayBrightness(float brightness) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700299 hal::Error getDisplayVsyncPeriod(nsecs_t* outVsyncPeriod) const override;
300 hal::Error setActiveConfigWithConstraints(
301 const std::shared_ptr<const HWC2::Display::Config>& config,
302 const hal::VsyncPeriodChangeConstraints& constraints,
303 hal::VsyncPeriodChangeTimeline* outTimeline) override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700304 hal::Error setAutoLowLatencyMode(bool on) override;
Peiyong Line9d809e2020-04-14 13:10:48 -0700305 hal::Error getSupportedContentTypes(
306 std::vector<hal::ContentType>* outSupportedContentTypes) const override;
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700307 hal::Error setContentType(hal::ContentType) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700308 hal::Error getClientTargetProperty(hal::ClientTargetProperty* outClientTargetProperty) override;
309
Dan Stoza651bf312015-10-23 17:03:17 -0700310 // Other Display methods
Peiyong Line9d809e2020-04-14 13:10:48 -0700311 hal::HWDisplayId getId() const override { return mId; }
Ana Krulec4593b692019-01-11 22:07:25 -0800312 bool isConnected() const override { return mIsConnected; }
313 void setConnected(bool connected) override; // For use by Device only
Peiyong Line9d809e2020-04-14 13:10:48 -0700314 const std::unordered_set<hal::DisplayCapability>& getCapabilities() const override {
Peiyong Lined531a32018-10-26 18:27:56 -0700315 return mDisplayCapabilities;
316 };
Ady Abraham7159f572019-10-11 11:10:18 -0700317 virtual bool isVsyncPeriodSwitchSupported() const override;
Dan Stoza651bf312015-10-23 17:03:17 -0700318
319private:
Peiyong Line9d809e2020-04-14 13:10:48 -0700320 int32_t getAttribute(hal::HWConfigId configId, hal::Attribute attribute);
321 void loadConfig(hal::HWConfigId configId);
Dan Stoza651bf312015-10-23 17:03:17 -0700322 void loadConfigs();
323
Dan Stoza651bf312015-10-23 17:03:17 -0700324 // This may fail (and return a null pointer) if no layer with this ID exists
325 // on this display
Peiyong Line9d809e2020-04-14 13:10:48 -0700326 Layer* getLayerById(hal::HWLayerId id) const;
Dan Stoza651bf312015-10-23 17:03:17 -0700327
Lloyd Piquebc792092018-01-17 11:52:30 -0800328 friend android::TestableSurfaceFlinger;
329
Dan Stoza651bf312015-10-23 17:03:17 -0700330 // Member variables
331
Steven Thomas94e35b92017-07-26 18:48:28 -0700332 // These are references to data owned by HWC2::Device, which will outlive
333 // this HWC2::Display, so these references are guaranteed to be valid for
334 // the lifetime of this object.
335 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700336 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700337
Peiyong Line9d809e2020-04-14 13:10:48 -0700338 const hal::HWDisplayId mId;
339 hal::DisplayType mType;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800340 bool mIsConnected = false;
Ady Abraham7159f572019-10-11 11:10:18 -0700341
Peiyong Line9d809e2020-04-14 13:10:48 -0700342 std::unordered_map<hal::HWLayerId, std::unique_ptr<Layer>> mLayers;
343 std::unordered_map<hal::HWConfigId, std::shared_ptr<const Config>> mConfigs;
Ady Abraham7159f572019-10-11 11:10:18 -0700344
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700345 std::once_flag mDisplayCapabilityQueryFlag;
Peiyong Line9d809e2020-04-14 13:10:48 -0700346 std::unordered_set<hal::DisplayCapability> mDisplayCapabilities;
Dan Stoza651bf312015-10-23 17:03:17 -0700347};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800348
Ana Krulec4593b692019-01-11 22:07:25 -0800349} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700350
Lloyd Pique35d58242018-12-18 16:33:25 -0800351class Layer {
352public:
353 virtual ~Layer();
354
Peiyong Line9d809e2020-04-14 13:10:48 -0700355 virtual hal::HWLayerId getId() const = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800356
Peiyong Line9d809e2020-04-14 13:10:48 -0700357 [[clang::warn_unused_result]] virtual hal::Error setCursorPosition(int32_t x, int32_t y) = 0;
358 [[clang::warn_unused_result]] virtual hal::Error setBuffer(
Lloyd Pique35d58242018-12-18 16:33:25 -0800359 uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
360 const android::sp<android::Fence>& acquireFence) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700361 [[clang::warn_unused_result]] virtual hal::Error setSurfaceDamage(
362 const android::Region& damage) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800363
Peiyong Line9d809e2020-04-14 13:10:48 -0700364 [[clang::warn_unused_result]] virtual hal::Error setBlendMode(hal::BlendMode mode) = 0;
365 [[clang::warn_unused_result]] virtual hal::Error setColor(hal::Color color) = 0;
366 [[clang::warn_unused_result]] virtual hal::Error setCompositionType(hal::Composition type) = 0;
367 [[clang::warn_unused_result]] virtual hal::Error setDataspace(hal::Dataspace dataspace) = 0;
368 [[clang::warn_unused_result]] virtual hal::Error setPerFrameMetadata(
Lloyd Pique35d58242018-12-18 16:33:25 -0800369 const int32_t supportedPerFrameMetadata, const android::HdrMetadata& metadata) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700370 [[clang::warn_unused_result]] virtual hal::Error setDisplayFrame(
371 const android::Rect& frame) = 0;
372 [[clang::warn_unused_result]] virtual hal::Error setPlaneAlpha(float alpha) = 0;
373 [[clang::warn_unused_result]] virtual hal::Error setSidebandStream(
Lloyd Pique35d58242018-12-18 16:33:25 -0800374 const native_handle_t* stream) = 0;
Peiyong Line9d809e2020-04-14 13:10:48 -0700375 [[clang::warn_unused_result]] virtual hal::Error setSourceCrop(
376 const android::FloatRect& crop) = 0;
377 [[clang::warn_unused_result]] virtual hal::Error setTransform(hal::Transform transform) = 0;
378 [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion(
379 const android::Region& region) = 0;
380 [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0;
381 [[clang::warn_unused_result]] virtual hal::Error setInfo(uint32_t type, uint32_t appId) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800382
383 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700384 [[clang::warn_unused_result]] virtual hal::Error setColorTransform(
385 const android::mat4& matrix) = 0;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800386
387 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700388 [[clang::warn_unused_result]] virtual hal::Error setLayerGenericMetadata(
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800389 const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
Lloyd Pique35d58242018-12-18 16:33:25 -0800390};
391
392namespace impl {
393
Peiyong Line9d809e2020-04-14 13:10:48 -0700394// Convenience C++ class to access per layer functions directly.
Lloyd Pique35d58242018-12-18 16:33:25 -0800395
396class Layer : public HWC2::Layer {
Dan Stoza651bf312015-10-23 17:03:17 -0700397public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700398 Layer(android::Hwc2::Composer& composer,
399 const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId displayId,
400 hal::HWLayerId layerId);
Lloyd Pique35d58242018-12-18 16:33:25 -0800401 ~Layer() override;
Dan Stoza651bf312015-10-23 17:03:17 -0700402
Peiyong Line9d809e2020-04-14 13:10:48 -0700403 hal::HWLayerId getId() const override { return mId; }
Dan Stoza651bf312015-10-23 17:03:17 -0700404
Peiyong Line9d809e2020-04-14 13:10:48 -0700405 hal::Error setCursorPosition(int32_t x, int32_t y) override;
406 hal::Error setBuffer(uint32_t slot, const android::sp<android::GraphicBuffer>& buffer,
407 const android::sp<android::Fence>& acquireFence) override;
408 hal::Error setSurfaceDamage(const android::Region& damage) override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700409
Peiyong Line9d809e2020-04-14 13:10:48 -0700410 hal::Error setBlendMode(hal::BlendMode mode) override;
411 hal::Error setColor(hal::Color color) override;
412 hal::Error setCompositionType(hal::Composition type) override;
413 hal::Error setDataspace(hal::Dataspace dataspace) override;
414 hal::Error setPerFrameMetadata(const int32_t supportedPerFrameMetadata,
415 const android::HdrMetadata& metadata) override;
416 hal::Error setDisplayFrame(const android::Rect& frame) override;
417 hal::Error setPlaneAlpha(float alpha) override;
418 hal::Error setSidebandStream(const native_handle_t* stream) override;
419 hal::Error setSourceCrop(const android::FloatRect& crop) override;
420 hal::Error setTransform(hal::Transform transform) override;
421 hal::Error setVisibleRegion(const android::Region& region) override;
422 hal::Error setZOrder(uint32_t z) override;
423 hal::Error setInfo(uint32_t type, uint32_t appId) override;
Dan Stoza651bf312015-10-23 17:03:17 -0700424
Peiyong Lin698147a2018-09-14 13:27:18 -0700425 // Composer HAL 2.3
Peiyong Line9d809e2020-04-14 13:10:48 -0700426 hal::Error setColorTransform(const android::mat4& matrix) override;
Peiyong Lin698147a2018-09-14 13:27:18 -0700427
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800428 // Composer HAL 2.4
Peiyong Line9d809e2020-04-14 13:10:48 -0700429 hal::Error setLayerGenericMetadata(const std::string& name, bool mandatory,
430 const std::vector<uint8_t>& value) override;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800431
Dan Stoza651bf312015-10-23 17:03:17 -0700432private:
Steven Thomas94e35b92017-07-26 18:48:28 -0700433 // These are references to data owned by HWC2::Device, which will outlive
434 // this HWC2::Layer, so these references are guaranteed to be valid for
435 // the lifetime of this object.
436 android::Hwc2::Composer& mComposer;
Peiyong Line9d809e2020-04-14 13:10:48 -0700437 const std::unordered_set<hal::Capability>& mCapabilities;
Steven Thomas94e35b92017-07-26 18:48:28 -0700438
Peiyong Line9d809e2020-04-14 13:10:48 -0700439 hal::HWDisplayId mDisplayId;
440 hal::HWLayerId mId;
Yichi Chen8366f562019-03-25 19:44:06 +0800441
442 // Cached HWC2 data, to ensure the same commands aren't sent to the HWC
443 // multiple times.
444 android::Region mVisibleRegion = android::Region::INVALID_REGION;
445 android::Region mDamageRegion = android::Region::INVALID_REGION;
Peiyong Line9d809e2020-04-14 13:10:48 -0700446 hal::Dataspace mDataSpace = hal::Dataspace::UNKNOWN;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700447 android::HdrMetadata mHdrMetadata;
Peiyong Lin698147a2018-09-14 13:27:18 -0700448 android::mat4 mColorMatrix;
Yichi Chen8366f562019-03-25 19:44:06 +0800449 uint32_t mBufferSlot;
Dan Stoza651bf312015-10-23 17:03:17 -0700450};
451
Lloyd Pique35d58242018-12-18 16:33:25 -0800452} // namespace impl
Dan Stoza651bf312015-10-23 17:03:17 -0700453} // namespace HWC2
Peiyong Line9d809e2020-04-14 13:10:48 -0700454} // namespace android