blob: c79caf48073e2d0a713eb167a00a0c8b46fce995 [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// #define LOG_NDEBUG 0
18
19#undef LOG_TAG
20#define LOG_TAG "HWC2"
21#define ATRACE_TAG ATRACE_TAG_GRAPHICS
22
23#include "HWC2.h"
Chia-I Wuaab99f52016-10-05 12:59:58 +080024#include "ComposerHal.h"
Dan Stoza651bf312015-10-23 17:03:17 -070025
26#include "FloatRect.h"
27
28#include <ui/Fence.h>
29#include <ui/GraphicBuffer.h>
30#include <ui/Region.h>
31
32#include <android/configuration.h>
33
Dan Stoza09e7a272016-04-14 12:31:01 -070034#include <algorithm>
Dan Stoza651bf312015-10-23 17:03:17 -070035#include <inttypes.h>
36
37extern "C" {
38 static void hotplug_hook(hwc2_callback_data_t callbackData,
39 hwc2_display_t displayId, int32_t intConnected) {
40 auto device = static_cast<HWC2::Device*>(callbackData);
41 auto display = device->getDisplayById(displayId);
42 if (display) {
43 auto connected = static_cast<HWC2::Connection>(intConnected);
44 device->callHotplug(std::move(display), connected);
45 } else {
46 ALOGE("Hotplug callback called with unknown display %" PRIu64,
47 displayId);
48 }
49 }
50
51 static void refresh_hook(hwc2_callback_data_t callbackData,
52 hwc2_display_t displayId) {
53 auto device = static_cast<HWC2::Device*>(callbackData);
54 auto display = device->getDisplayById(displayId);
55 if (display) {
56 device->callRefresh(std::move(display));
57 } else {
58 ALOGE("Refresh callback called with unknown display %" PRIu64,
59 displayId);
60 }
61 }
62
63 static void vsync_hook(hwc2_callback_data_t callbackData,
64 hwc2_display_t displayId, int64_t timestamp) {
65 auto device = static_cast<HWC2::Device*>(callbackData);
66 auto display = device->getDisplayById(displayId);
67 if (display) {
68 device->callVsync(std::move(display), timestamp);
69 } else {
70 ALOGE("Vsync callback called with unknown display %" PRIu64,
71 displayId);
72 }
73 }
74}
75
76using android::Fence;
77using android::FloatRect;
78using android::GraphicBuffer;
Dan Stoza7d7ae732016-03-16 12:23:40 -070079using android::HdrCapabilities;
Dan Stoza651bf312015-10-23 17:03:17 -070080using android::Rect;
81using android::Region;
82using android::sp;
Chia-I Wuaab99f52016-10-05 12:59:58 +080083using android::hardware::Return;
84using android::hardware::Void;
Dan Stoza651bf312015-10-23 17:03:17 -070085
86namespace HWC2 {
87
Chia-I Wuaab99f52016-10-05 12:59:58 +080088namespace Hwc2 = android::Hwc2;
89
Dan Stoza651bf312015-10-23 17:03:17 -070090// Device methods
91
Chia-I Wuaab99f52016-10-05 12:59:58 +080092#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -070093Device::Device(hwc2_device_t* device)
94 : mHwcDevice(device),
95 mCreateVirtualDisplay(nullptr),
96 mDestroyVirtualDisplay(nullptr),
97 mDump(nullptr),
98 mGetMaxVirtualDisplayCount(nullptr),
99 mRegisterCallback(nullptr),
100 mAcceptDisplayChanges(nullptr),
101 mCreateLayer(nullptr),
102 mDestroyLayer(nullptr),
103 mGetActiveConfig(nullptr),
104 mGetChangedCompositionTypes(nullptr),
Dan Stoza076ac672016-03-14 10:47:53 -0700105 mGetColorModes(nullptr),
Dan Stoza651bf312015-10-23 17:03:17 -0700106 mGetDisplayAttribute(nullptr),
107 mGetDisplayConfigs(nullptr),
108 mGetDisplayName(nullptr),
109 mGetDisplayRequests(nullptr),
110 mGetDisplayType(nullptr),
111 mGetDozeSupport(nullptr),
Dan Stoza7d7ae732016-03-16 12:23:40 -0700112 mGetHdrCapabilities(nullptr),
Dan Stoza651bf312015-10-23 17:03:17 -0700113 mGetReleaseFences(nullptr),
114 mPresentDisplay(nullptr),
115 mSetActiveConfig(nullptr),
116 mSetClientTarget(nullptr),
Dan Stoza076ac672016-03-14 10:47:53 -0700117 mSetColorMode(nullptr),
Dan Stoza5df2a862016-03-24 16:19:37 -0700118 mSetColorTransform(nullptr),
Dan Stoza651bf312015-10-23 17:03:17 -0700119 mSetOutputBuffer(nullptr),
120 mSetPowerMode(nullptr),
121 mSetVsyncEnabled(nullptr),
122 mValidateDisplay(nullptr),
123 mSetCursorPosition(nullptr),
124 mSetLayerBuffer(nullptr),
125 mSetLayerSurfaceDamage(nullptr),
126 mSetLayerBlendMode(nullptr),
127 mSetLayerColor(nullptr),
128 mSetLayerCompositionType(nullptr),
Dan Stoza5df2a862016-03-24 16:19:37 -0700129 mSetLayerDataspace(nullptr),
Dan Stoza651bf312015-10-23 17:03:17 -0700130 mSetLayerDisplayFrame(nullptr),
131 mSetLayerPlaneAlpha(nullptr),
132 mSetLayerSidebandStream(nullptr),
133 mSetLayerSourceCrop(nullptr),
134 mSetLayerTransform(nullptr),
135 mSetLayerVisibleRegion(nullptr),
136 mSetLayerZOrder(nullptr),
Chia-I Wuaab99f52016-10-05 12:59:58 +0800137#else
138Device::Device()
139 : mComposer(std::make_unique<Hwc2::Composer>()),
140#endif // BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700141 mCapabilities(),
142 mDisplays(),
143 mHotplug(),
144 mPendingHotplugs(),
145 mRefresh(),
146 mPendingRefreshes(),
147 mVsync(),
148 mPendingVsyncs()
149{
150 loadCapabilities();
151 loadFunctionPointers();
152 registerCallbacks();
153}
154
155Device::~Device()
156{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800157#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700158 if (mHwcDevice == nullptr) {
159 return;
160 }
Chia-I Wuaab99f52016-10-05 12:59:58 +0800161#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700162
163 for (auto element : mDisplays) {
Dan Stoza38628982016-07-13 15:48:58 -0700164 auto display = element.second.lock();
165 if (!display) {
166 ALOGE("~Device: Found a display (%" PRId64 " that has already been"
167 " destroyed", element.first);
168 continue;
169 }
Dan Stoza651bf312015-10-23 17:03:17 -0700170
171 DisplayType displayType = HWC2::DisplayType::Invalid;
172 auto error = display->getType(&displayType);
173 if (error != Error::None) {
174 ALOGE("~Device: Failed to determine type of display %" PRIu64
175 ": %s (%d)", display->getId(), to_string(error).c_str(),
176 static_cast<int32_t>(error));
177 continue;
178 }
179
180 if (displayType == HWC2::DisplayType::Physical) {
181 error = display->setVsyncEnabled(HWC2::Vsync::Disable);
182 if (error != Error::None) {
183 ALOGE("~Device: Failed to disable vsync for display %" PRIu64
184 ": %s (%d)", display->getId(), to_string(error).c_str(),
185 static_cast<int32_t>(error));
186 }
187 }
188 }
189
Chia-I Wuaab99f52016-10-05 12:59:58 +0800190#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700191 hwc2_close(mHwcDevice);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800192#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700193}
194
195// Required by HWC2 device
196
197std::string Device::dump() const
198{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800199#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700200 uint32_t numBytes = 0;
201 mDump(mHwcDevice, &numBytes, nullptr);
202
203 std::vector<char> buffer(numBytes);
204 mDump(mHwcDevice, &numBytes, buffer.data());
205
206 return std::string(buffer.data(), buffer.size());
Chia-I Wuaab99f52016-10-05 12:59:58 +0800207#else
208 return mComposer->dumpDebugInfo();
209#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700210}
211
212uint32_t Device::getMaxVirtualDisplayCount() const
213{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800214#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700215 return mGetMaxVirtualDisplayCount(mHwcDevice);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800216#else
217 return mComposer->getMaxVirtualDisplayCount();
218#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700219}
220
221Error Device::createVirtualDisplay(uint32_t width, uint32_t height,
Dan Stoza5cf424b2016-05-20 14:02:39 -0700222 android_pixel_format_t* format, std::shared_ptr<Display>* outDisplay)
Dan Stoza651bf312015-10-23 17:03:17 -0700223{
224 ALOGI("Creating virtual display");
225
226 hwc2_display_t displayId = 0;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800227#ifdef BYPASS_IHWC
Dan Stoza5cf424b2016-05-20 14:02:39 -0700228 int32_t intFormat = static_cast<int32_t>(*format);
Dan Stoza651bf312015-10-23 17:03:17 -0700229 int32_t intError = mCreateVirtualDisplay(mHwcDevice, width, height,
Dan Stoza5cf424b2016-05-20 14:02:39 -0700230 &intFormat, &displayId);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800231#else
232 auto intFormat = static_cast<Hwc2::PixelFormat>(*format);
233 auto intError = mComposer->createVirtualDisplay(width, height,
234 intFormat, displayId);
235#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700236 auto error = static_cast<Error>(intError);
237 if (error != Error::None) {
238 return error;
239 }
240
241 ALOGI("Created virtual display");
Dan Stoza5cf424b2016-05-20 14:02:39 -0700242 *format = static_cast<android_pixel_format_t>(intFormat);
Dan Stoza651bf312015-10-23 17:03:17 -0700243 *outDisplay = getDisplayById(displayId);
Dan Stoza38628982016-07-13 15:48:58 -0700244 if (!*outDisplay) {
245 ALOGE("Failed to get display by id");
246 return Error::BadDisplay;
247 }
Dan Stoza651bf312015-10-23 17:03:17 -0700248 (*outDisplay)->setVirtual();
249 return Error::None;
250}
251
252void Device::registerHotplugCallback(HotplugCallback hotplug)
253{
254 ALOGV("registerHotplugCallback");
255 mHotplug = hotplug;
256 for (auto& pending : mPendingHotplugs) {
257 auto& display = pending.first;
258 auto connected = pending.second;
259 ALOGV("Sending pending hotplug(%" PRIu64 ", %s)", display->getId(),
260 to_string(connected).c_str());
261 mHotplug(std::move(display), connected);
262 }
263}
264
265void Device::registerRefreshCallback(RefreshCallback refresh)
266{
267 mRefresh = refresh;
268 for (auto& pending : mPendingRefreshes) {
269 mRefresh(std::move(pending));
270 }
271}
272
273void Device::registerVsyncCallback(VsyncCallback vsync)
274{
275 mVsync = vsync;
276 for (auto& pending : mPendingVsyncs) {
277 auto& display = pending.first;
278 auto timestamp = pending.second;
279 mVsync(std::move(display), timestamp);
280 }
281}
282
283// For use by Device callbacks
284
285void Device::callHotplug(std::shared_ptr<Display> display, Connection connected)
286{
287 if (connected == Connection::Connected) {
288 if (!display->isConnected()) {
289 display->loadConfigs();
290 display->setConnected(true);
291 }
292 } else {
293 display->setConnected(false);
294 mDisplays.erase(display->getId());
295 }
296
297 if (mHotplug) {
298 mHotplug(std::move(display), connected);
299 } else {
300 ALOGV("callHotplug called, but no valid callback registered, storing");
301 mPendingHotplugs.emplace_back(std::move(display), connected);
302 }
303}
304
305void Device::callRefresh(std::shared_ptr<Display> display)
306{
307 if (mRefresh) {
308 mRefresh(std::move(display));
309 } else {
310 ALOGV("callRefresh called, but no valid callback registered, storing");
311 mPendingRefreshes.emplace_back(std::move(display));
312 }
313}
314
315void Device::callVsync(std::shared_ptr<Display> display, nsecs_t timestamp)
316{
317 if (mVsync) {
318 mVsync(std::move(display), timestamp);
319 } else {
320 ALOGV("callVsync called, but no valid callback registered, storing");
321 mPendingVsyncs.emplace_back(std::move(display), timestamp);
322 }
323}
324
325// Other Device methods
326
327std::shared_ptr<Display> Device::getDisplayById(hwc2_display_t id) {
328 if (mDisplays.count(id) != 0) {
Dan Stoza38628982016-07-13 15:48:58 -0700329 auto strongDisplay = mDisplays[id].lock();
330 ALOGE_IF(!strongDisplay, "Display %" PRId64 " is in mDisplays but is no"
331 " longer alive", id);
332 return strongDisplay;
Dan Stoza651bf312015-10-23 17:03:17 -0700333 }
334
335 auto display = std::make_shared<Display>(*this, id);
336 mDisplays.emplace(id, display);
337 return display;
338}
339
340// Device initialization methods
341
342void Device::loadCapabilities()
343{
344 static_assert(sizeof(Capability) == sizeof(int32_t),
345 "Capability size has changed");
Chia-I Wuaab99f52016-10-05 12:59:58 +0800346#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700347 uint32_t numCapabilities = 0;
348 mHwcDevice->getCapabilities(mHwcDevice, &numCapabilities, nullptr);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700349 std::vector<Capability> capabilities(numCapabilities);
350 auto asInt = reinterpret_cast<int32_t*>(capabilities.data());
Dan Stoza651bf312015-10-23 17:03:17 -0700351 mHwcDevice->getCapabilities(mHwcDevice, &numCapabilities, asInt);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700352 for (auto capability : capabilities) {
353 mCapabilities.emplace(capability);
354 }
Chia-I Wuaab99f52016-10-05 12:59:58 +0800355#else
356 auto capabilities = mComposer->getCapabilities();
357 for (auto capability : capabilities) {
358 mCapabilities.emplace(static_cast<Capability>(capability));
359 }
360#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700361}
362
Dan Stoza09e7a272016-04-14 12:31:01 -0700363bool Device::hasCapability(HWC2::Capability capability) const
364{
365 return std::find(mCapabilities.cbegin(), mCapabilities.cend(),
366 capability) != mCapabilities.cend();
367}
368
Dan Stoza651bf312015-10-23 17:03:17 -0700369void Device::loadFunctionPointers()
370{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800371#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700372 // For all of these early returns, we log an error message inside
373 // loadFunctionPointer specifying which function failed to load
374
375 // Display function pointers
Dan Stoza7d7ae732016-03-16 12:23:40 -0700376 if (!loadFunctionPointer(FunctionDescriptor::CreateVirtualDisplay,
Dan Stoza651bf312015-10-23 17:03:17 -0700377 mCreateVirtualDisplay)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700378 if (!loadFunctionPointer(FunctionDescriptor::DestroyVirtualDisplay,
Dan Stoza651bf312015-10-23 17:03:17 -0700379 mDestroyVirtualDisplay)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700380 if (!loadFunctionPointer(FunctionDescriptor::Dump, mDump)) return;
381 if (!loadFunctionPointer(FunctionDescriptor::GetMaxVirtualDisplayCount,
Dan Stoza651bf312015-10-23 17:03:17 -0700382 mGetMaxVirtualDisplayCount)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700383 if (!loadFunctionPointer(FunctionDescriptor::RegisterCallback,
Dan Stoza651bf312015-10-23 17:03:17 -0700384 mRegisterCallback)) return;
385
386 // Device function pointers
Dan Stoza7d7ae732016-03-16 12:23:40 -0700387 if (!loadFunctionPointer(FunctionDescriptor::AcceptDisplayChanges,
Dan Stoza651bf312015-10-23 17:03:17 -0700388 mAcceptDisplayChanges)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700389 if (!loadFunctionPointer(FunctionDescriptor::CreateLayer,
Dan Stoza651bf312015-10-23 17:03:17 -0700390 mCreateLayer)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700391 if (!loadFunctionPointer(FunctionDescriptor::DestroyLayer,
Dan Stoza651bf312015-10-23 17:03:17 -0700392 mDestroyLayer)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700393 if (!loadFunctionPointer(FunctionDescriptor::GetActiveConfig,
Dan Stoza651bf312015-10-23 17:03:17 -0700394 mGetActiveConfig)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700395 if (!loadFunctionPointer(FunctionDescriptor::GetChangedCompositionTypes,
Dan Stoza651bf312015-10-23 17:03:17 -0700396 mGetChangedCompositionTypes)) return;
Dan Stoza076ac672016-03-14 10:47:53 -0700397 if (!loadFunctionPointer(FunctionDescriptor::GetColorModes,
398 mGetColorModes)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700399 if (!loadFunctionPointer(FunctionDescriptor::GetDisplayAttribute,
Dan Stoza651bf312015-10-23 17:03:17 -0700400 mGetDisplayAttribute)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700401 if (!loadFunctionPointer(FunctionDescriptor::GetDisplayConfigs,
Dan Stoza651bf312015-10-23 17:03:17 -0700402 mGetDisplayConfigs)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700403 if (!loadFunctionPointer(FunctionDescriptor::GetDisplayName,
Dan Stoza651bf312015-10-23 17:03:17 -0700404 mGetDisplayName)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700405 if (!loadFunctionPointer(FunctionDescriptor::GetDisplayRequests,
Dan Stoza651bf312015-10-23 17:03:17 -0700406 mGetDisplayRequests)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700407 if (!loadFunctionPointer(FunctionDescriptor::GetDisplayType,
Dan Stoza651bf312015-10-23 17:03:17 -0700408 mGetDisplayType)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700409 if (!loadFunctionPointer(FunctionDescriptor::GetDozeSupport,
Dan Stoza651bf312015-10-23 17:03:17 -0700410 mGetDozeSupport)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700411 if (!loadFunctionPointer(FunctionDescriptor::GetHdrCapabilities,
412 mGetHdrCapabilities)) return;
413 if (!loadFunctionPointer(FunctionDescriptor::GetReleaseFences,
Dan Stoza651bf312015-10-23 17:03:17 -0700414 mGetReleaseFences)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700415 if (!loadFunctionPointer(FunctionDescriptor::PresentDisplay,
Dan Stoza651bf312015-10-23 17:03:17 -0700416 mPresentDisplay)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700417 if (!loadFunctionPointer(FunctionDescriptor::SetActiveConfig,
Dan Stoza651bf312015-10-23 17:03:17 -0700418 mSetActiveConfig)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700419 if (!loadFunctionPointer(FunctionDescriptor::SetClientTarget,
Dan Stoza651bf312015-10-23 17:03:17 -0700420 mSetClientTarget)) return;
Dan Stoza076ac672016-03-14 10:47:53 -0700421 if (!loadFunctionPointer(FunctionDescriptor::SetColorMode,
422 mSetColorMode)) return;
Dan Stoza5df2a862016-03-24 16:19:37 -0700423 if (!loadFunctionPointer(FunctionDescriptor::SetColorTransform,
424 mSetColorTransform)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700425 if (!loadFunctionPointer(FunctionDescriptor::SetOutputBuffer,
Dan Stoza651bf312015-10-23 17:03:17 -0700426 mSetOutputBuffer)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700427 if (!loadFunctionPointer(FunctionDescriptor::SetPowerMode,
Dan Stoza651bf312015-10-23 17:03:17 -0700428 mSetPowerMode)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700429 if (!loadFunctionPointer(FunctionDescriptor::SetVsyncEnabled,
Dan Stoza651bf312015-10-23 17:03:17 -0700430 mSetVsyncEnabled)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700431 if (!loadFunctionPointer(FunctionDescriptor::ValidateDisplay,
Dan Stoza651bf312015-10-23 17:03:17 -0700432 mValidateDisplay)) return;
433
434 // Layer function pointers
Dan Stoza7d7ae732016-03-16 12:23:40 -0700435 if (!loadFunctionPointer(FunctionDescriptor::SetCursorPosition,
Dan Stoza651bf312015-10-23 17:03:17 -0700436 mSetCursorPosition)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700437 if (!loadFunctionPointer(FunctionDescriptor::SetLayerBuffer,
Dan Stoza651bf312015-10-23 17:03:17 -0700438 mSetLayerBuffer)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700439 if (!loadFunctionPointer(FunctionDescriptor::SetLayerSurfaceDamage,
Dan Stoza651bf312015-10-23 17:03:17 -0700440 mSetLayerSurfaceDamage)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700441 if (!loadFunctionPointer(FunctionDescriptor::SetLayerBlendMode,
Dan Stoza651bf312015-10-23 17:03:17 -0700442 mSetLayerBlendMode)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700443 if (!loadFunctionPointer(FunctionDescriptor::SetLayerColor,
Dan Stoza651bf312015-10-23 17:03:17 -0700444 mSetLayerColor)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700445 if (!loadFunctionPointer(FunctionDescriptor::SetLayerCompositionType,
Dan Stoza651bf312015-10-23 17:03:17 -0700446 mSetLayerCompositionType)) return;
Dan Stoza5df2a862016-03-24 16:19:37 -0700447 if (!loadFunctionPointer(FunctionDescriptor::SetLayerDataspace,
448 mSetLayerDataspace)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700449 if (!loadFunctionPointer(FunctionDescriptor::SetLayerDisplayFrame,
Dan Stoza651bf312015-10-23 17:03:17 -0700450 mSetLayerDisplayFrame)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700451 if (!loadFunctionPointer(FunctionDescriptor::SetLayerPlaneAlpha,
Dan Stoza651bf312015-10-23 17:03:17 -0700452 mSetLayerPlaneAlpha)) return;
Dan Stoza09e7a272016-04-14 12:31:01 -0700453 if (hasCapability(Capability::SidebandStream)) {
454 if (!loadFunctionPointer(FunctionDescriptor::SetLayerSidebandStream,
455 mSetLayerSidebandStream)) return;
456 }
Dan Stoza7d7ae732016-03-16 12:23:40 -0700457 if (!loadFunctionPointer(FunctionDescriptor::SetLayerSourceCrop,
Dan Stoza651bf312015-10-23 17:03:17 -0700458 mSetLayerSourceCrop)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700459 if (!loadFunctionPointer(FunctionDescriptor::SetLayerTransform,
Dan Stoza651bf312015-10-23 17:03:17 -0700460 mSetLayerTransform)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700461 if (!loadFunctionPointer(FunctionDescriptor::SetLayerVisibleRegion,
Dan Stoza651bf312015-10-23 17:03:17 -0700462 mSetLayerVisibleRegion)) return;
Dan Stoza7d7ae732016-03-16 12:23:40 -0700463 if (!loadFunctionPointer(FunctionDescriptor::SetLayerZOrder,
Dan Stoza651bf312015-10-23 17:03:17 -0700464 mSetLayerZOrder)) return;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800465#endif // BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700466}
467
Chia-I Wuaab99f52016-10-05 12:59:58 +0800468namespace {
469class ComposerCallback : public Hwc2::IComposerCallback {
470public:
471 ComposerCallback(Device* device) : mDevice(device) {}
472
473 Return<void> onHotplug(Hwc2::Display display,
474 Connection connected) override
475 {
476 hotplug_hook(mDevice, display, static_cast<int32_t>(connected));
477 return Void();
478 }
479
480 Return<void> onRefresh(Hwc2::Display display) override
481 {
482 refresh_hook(mDevice, display);
483 return Void();
484 }
485
486 Return<void> onVsync(Hwc2::Display display, int64_t timestamp) override
487 {
488 vsync_hook(mDevice, display, timestamp);
489 return Void();
490 }
491
492private:
493 Device* mDevice;
494};
495} // namespace anonymous
496
Dan Stoza651bf312015-10-23 17:03:17 -0700497void Device::registerCallbacks()
498{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800499#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700500 registerCallback<HWC2_PFN_HOTPLUG>(Callback::Hotplug, hotplug_hook);
501 registerCallback<HWC2_PFN_REFRESH>(Callback::Refresh, refresh_hook);
502 registerCallback<HWC2_PFN_VSYNC>(Callback::Vsync, vsync_hook);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800503#else
504 sp<ComposerCallback> callback = new ComposerCallback(this);
505 mComposer->registerCallback(callback);
506#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700507}
508
509
510// For use by Display
511
512void Device::destroyVirtualDisplay(hwc2_display_t display)
513{
514 ALOGI("Destroying virtual display");
Chia-I Wuaab99f52016-10-05 12:59:58 +0800515#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700516 int32_t intError = mDestroyVirtualDisplay(mHwcDevice, display);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800517#else
518 auto intError = mComposer->destroyVirtualDisplay(display);
519#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700520 auto error = static_cast<Error>(intError);
521 ALOGE_IF(error != Error::None, "destroyVirtualDisplay(%" PRIu64 ") failed:"
522 " %s (%d)", display, to_string(error).c_str(), intError);
Dan Stoza38628982016-07-13 15:48:58 -0700523 mDisplays.erase(display);
Dan Stoza651bf312015-10-23 17:03:17 -0700524}
525
526// Display methods
527
528Display::Display(Device& device, hwc2_display_t id)
529 : mDevice(device),
530 mId(id),
531 mIsConnected(false),
532 mIsVirtual(false)
533{
534 ALOGV("Created display %" PRIu64, id);
535}
536
537Display::~Display()
538{
539 ALOGV("Destroyed display %" PRIu64, mId);
540 if (mIsVirtual) {
541 mDevice.destroyVirtualDisplay(mId);
542 }
543}
544
545Display::Config::Config(Display& display, hwc2_config_t id)
546 : mDisplay(display),
547 mId(id),
548 mWidth(-1),
549 mHeight(-1),
550 mVsyncPeriod(-1),
551 mDpiX(-1),
552 mDpiY(-1) {}
553
554Display::Config::Builder::Builder(Display& display, hwc2_config_t id)
555 : mConfig(new Config(display, id)) {}
556
557float Display::Config::Builder::getDefaultDensity() {
558 // Default density is based on TVs: 1080p displays get XHIGH density, lower-
559 // resolution displays get TV density. Maybe eventually we'll need to update
560 // it for 4k displays, though hopefully those will just report accurate DPI
561 // information to begin with. This is also used for virtual displays and
562 // older HWC implementations, so be careful about orientation.
563
564 auto longDimension = std::max(mConfig->mWidth, mConfig->mHeight);
565 if (longDimension >= 1080) {
566 return ACONFIGURATION_DENSITY_XHIGH;
567 } else {
568 return ACONFIGURATION_DENSITY_TV;
569 }
570}
571
572// Required by HWC2 display
573
574Error Display::acceptChanges()
575{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800576#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700577 int32_t intError = mDevice.mAcceptDisplayChanges(mDevice.mHwcDevice, mId);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800578#else
579 auto intError = mDevice.mComposer->acceptDisplayChanges(mId);
580#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700581 return static_cast<Error>(intError);
582}
583
584Error Display::createLayer(std::shared_ptr<Layer>* outLayer)
585{
586 hwc2_layer_t layerId = 0;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800587#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700588 int32_t intError = mDevice.mCreateLayer(mDevice.mHwcDevice, mId, &layerId);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800589#else
590 auto intError = mDevice.mComposer->createLayer(mId, layerId);
591#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700592 auto error = static_cast<Error>(intError);
593 if (error != Error::None) {
594 return error;
595 }
596
597 auto layer = std::make_shared<Layer>(shared_from_this(), layerId);
598 mLayers.emplace(layerId, layer);
599 *outLayer = std::move(layer);
600 return Error::None;
601}
602
603Error Display::getActiveConfig(
604 std::shared_ptr<const Display::Config>* outConfig) const
605{
606 ALOGV("[%" PRIu64 "] getActiveConfig", mId);
607 hwc2_config_t configId = 0;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800608#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700609 int32_t intError = mDevice.mGetActiveConfig(mDevice.mHwcDevice, mId,
610 &configId);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800611#else
612 auto intError = mDevice.mComposer->getActiveConfig(mId, configId);
613#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700614 auto error = static_cast<Error>(intError);
615
616 if (error != Error::None) {
617 return error;
618 }
619
620 if (mConfigs.count(configId) != 0) {
621 *outConfig = mConfigs.at(configId);
622 } else {
623 ALOGE("[%" PRIu64 "] getActiveConfig returned unknown config %u", mId,
624 configId);
625 // Return no error, but the caller needs to check for a null pointer to
626 // detect this case
627 *outConfig = nullptr;
628 }
629
630 return Error::None;
631}
632
633Error Display::getChangedCompositionTypes(
634 std::unordered_map<std::shared_ptr<Layer>, Composition>* outTypes)
635{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800636#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700637 uint32_t numElements = 0;
638 int32_t intError = mDevice.mGetChangedCompositionTypes(mDevice.mHwcDevice,
639 mId, &numElements, nullptr, nullptr);
640 auto error = static_cast<Error>(intError);
641 if (error != Error::None) {
642 return error;
643 }
644
645 std::vector<hwc2_layer_t> layerIds(numElements);
646 std::vector<int32_t> types(numElements);
647 intError = mDevice.mGetChangedCompositionTypes(mDevice.mHwcDevice, mId,
648 &numElements, layerIds.data(), types.data());
Chia-I Wuaab99f52016-10-05 12:59:58 +0800649#else
650 std::vector<Hwc2::Layer> layerIds;
651 std::vector<Hwc2::IComposer::Composition> types;
652 auto intError = mDevice.mComposer->getChangedCompositionTypes(mId,
653 layerIds, types);
654 uint32_t numElements = layerIds.size();
655 auto error = static_cast<Error>(intError);
656#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700657 error = static_cast<Error>(intError);
658 if (error != Error::None) {
659 return error;
660 }
661
662 outTypes->clear();
663 outTypes->reserve(numElements);
664 for (uint32_t element = 0; element < numElements; ++element) {
665 auto layer = getLayerById(layerIds[element]);
666 if (layer) {
667 auto type = static_cast<Composition>(types[element]);
668 ALOGV("getChangedCompositionTypes: adding %" PRIu64 " %s",
669 layer->getId(), to_string(type).c_str());
670 outTypes->emplace(layer, type);
671 } else {
672 ALOGE("getChangedCompositionTypes: invalid layer %" PRIu64 " found"
673 " on display %" PRIu64, layerIds[element], mId);
674 }
675 }
676
677 return Error::None;
678}
679
Michael Wright28f24d02016-07-12 13:30:53 -0700680Error Display::getColorModes(std::vector<android_color_mode_t>* outModes) const
Dan Stoza076ac672016-03-14 10:47:53 -0700681{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800682#ifdef BYPASS_IHWC
Dan Stoza076ac672016-03-14 10:47:53 -0700683 uint32_t numModes = 0;
684 int32_t intError = mDevice.mGetColorModes(mDevice.mHwcDevice, mId,
685 &numModes, nullptr);
686 auto error = static_cast<Error>(intError);
687 if (error != Error::None) {
688 return error;
689 }
690
691 std::vector<int32_t> modes(numModes);
692 intError = mDevice.mGetColorModes(mDevice.mHwcDevice, mId, &numModes,
693 modes.data());
694 error = static_cast<Error>(intError);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800695#else
696 std::vector<Hwc2::ColorMode> modes;
697 auto intError = mDevice.mComposer->getColorModes(mId, modes);
698 uint32_t numModes = modes.size();
699 auto error = static_cast<Error>(intError);
700#endif
Dan Stoza076ac672016-03-14 10:47:53 -0700701 if (error != Error::None) {
702 return error;
703 }
704
Michael Wright28f24d02016-07-12 13:30:53 -0700705 outModes->resize(numModes);
706 for (size_t i = 0; i < numModes; i++) {
707 (*outModes)[i] = static_cast<android_color_mode_t>(modes[i]);
708 }
Dan Stoza076ac672016-03-14 10:47:53 -0700709 return Error::None;
710}
711
Dan Stoza651bf312015-10-23 17:03:17 -0700712std::vector<std::shared_ptr<const Display::Config>> Display::getConfigs() const
713{
714 std::vector<std::shared_ptr<const Config>> configs;
715 for (const auto& element : mConfigs) {
716 configs.emplace_back(element.second);
717 }
718 return configs;
719}
720
721Error Display::getName(std::string* outName) const
722{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800723#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700724 uint32_t size;
725 int32_t intError = mDevice.mGetDisplayName(mDevice.mHwcDevice, mId, &size,
726 nullptr);
727 auto error = static_cast<Error>(intError);
728 if (error != Error::None) {
729 return error;
730 }
731
732 std::vector<char> rawName(size);
733 intError = mDevice.mGetDisplayName(mDevice.mHwcDevice, mId, &size,
734 rawName.data());
735 error = static_cast<Error>(intError);
736 if (error != Error::None) {
737 return error;
738 }
739
740 *outName = std::string(rawName.cbegin(), rawName.cend());
741 return Error::None;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800742#else
743 auto intError = mDevice.mComposer->getDisplayName(mId, *outName);
744 return static_cast<Error>(intError);
745#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700746}
747
748Error Display::getRequests(HWC2::DisplayRequest* outDisplayRequests,
749 std::unordered_map<std::shared_ptr<Layer>, LayerRequest>*
750 outLayerRequests)
751{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800752#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700753 int32_t intDisplayRequests = 0;
754 uint32_t numElements = 0;
755 int32_t intError = mDevice.mGetDisplayRequests(mDevice.mHwcDevice, mId,
756 &intDisplayRequests, &numElements, nullptr, nullptr);
757 auto error = static_cast<Error>(intError);
758 if (error != Error::None) {
759 return error;
760 }
761
762 std::vector<hwc2_layer_t> layerIds(numElements);
763 std::vector<int32_t> layerRequests(numElements);
764 intError = mDevice.mGetDisplayRequests(mDevice.mHwcDevice, mId,
765 &intDisplayRequests, &numElements, layerIds.data(),
766 layerRequests.data());
767 error = static_cast<Error>(intError);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800768#else
769 uint32_t intDisplayRequests;
770 std::vector<Hwc2::Layer> layerIds;
771 std::vector<uint32_t> layerRequests;
772 auto intError = mDevice.mComposer->getDisplayRequests(mId,
773 intDisplayRequests, layerIds, layerRequests);
774 uint32_t numElements = layerIds.size();
775 auto error = static_cast<Error>(intError);
776#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700777 if (error != Error::None) {
778 return error;
779 }
780
781 *outDisplayRequests = static_cast<DisplayRequest>(intDisplayRequests);
782 outLayerRequests->clear();
783 outLayerRequests->reserve(numElements);
784 for (uint32_t element = 0; element < numElements; ++element) {
785 auto layer = getLayerById(layerIds[element]);
786 if (layer) {
787 auto layerRequest =
788 static_cast<LayerRequest>(layerRequests[element]);
789 outLayerRequests->emplace(layer, layerRequest);
790 } else {
791 ALOGE("getRequests: invalid layer %" PRIu64 " found on display %"
792 PRIu64, layerIds[element], mId);
793 }
794 }
795
796 return Error::None;
797}
798
799Error Display::getType(DisplayType* outType) const
800{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800801#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700802 int32_t intType = 0;
803 int32_t intError = mDevice.mGetDisplayType(mDevice.mHwcDevice, mId,
804 &intType);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800805#else
806 Hwc2::IComposer::DisplayType intType =
807 Hwc2::IComposer::DisplayType::INVALID;
808 auto intError = mDevice.mComposer->getDisplayType(mId, intType);
809#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700810 auto error = static_cast<Error>(intError);
811 if (error != Error::None) {
812 return error;
813 }
814
815 *outType = static_cast<DisplayType>(intType);
816 return Error::None;
817}
818
819Error Display::supportsDoze(bool* outSupport) const
820{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800821#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700822 int32_t intSupport = 0;
823 int32_t intError = mDevice.mGetDozeSupport(mDevice.mHwcDevice, mId,
824 &intSupport);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800825#else
826 bool intSupport = false;
827 auto intError = mDevice.mComposer->getDozeSupport(mId, intSupport);
828#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700829 auto error = static_cast<Error>(intError);
830 if (error != Error::None) {
831 return error;
832 }
833 *outSupport = static_cast<bool>(intSupport);
834 return Error::None;
835}
836
Dan Stoza7d7ae732016-03-16 12:23:40 -0700837Error Display::getHdrCapabilities(
838 std::unique_ptr<HdrCapabilities>* outCapabilities) const
839{
840 uint32_t numTypes = 0;
841 float maxLuminance = -1.0f;
842 float maxAverageLuminance = -1.0f;
843 float minLuminance = -1.0f;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800844#ifdef BYPASS_IHWC
Dan Stoza7d7ae732016-03-16 12:23:40 -0700845 int32_t intError = mDevice.mGetHdrCapabilities(mDevice.mHwcDevice, mId,
846 &numTypes, nullptr, &maxLuminance, &maxAverageLuminance,
847 &minLuminance);
848 auto error = static_cast<HWC2::Error>(intError);
849 if (error != Error::None) {
850 return error;
851 }
852
853 std::vector<int32_t> types(numTypes);
854 intError = mDevice.mGetHdrCapabilities(mDevice.mHwcDevice, mId, &numTypes,
855 types.data(), &maxLuminance, &maxAverageLuminance, &minLuminance);
856 error = static_cast<HWC2::Error>(intError);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800857#else
858 std::vector<Hwc2::Hdr> intTypes;
859 auto intError = mDevice.mComposer->getHdrCapabilities(mId, intTypes,
860 maxLuminance, maxAverageLuminance, minLuminance);
861 auto error = static_cast<HWC2::Error>(intError);
862
863 std::vector<int32_t> types;
864 for (auto type : intTypes) {
865 types.push_back(static_cast<int32_t>(type));
866 }
867 numTypes = types.size();
868#endif
Dan Stoza7d7ae732016-03-16 12:23:40 -0700869 if (error != Error::None) {
870 return error;
871 }
872
873 *outCapabilities = std::make_unique<HdrCapabilities>(std::move(types),
874 maxLuminance, maxAverageLuminance, minLuminance);
875 return Error::None;
876}
877
Dan Stoza651bf312015-10-23 17:03:17 -0700878Error Display::getReleaseFences(
879 std::unordered_map<std::shared_ptr<Layer>, sp<Fence>>* outFences) const
880{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800881#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700882 uint32_t numElements = 0;
883 int32_t intError = mDevice.mGetReleaseFences(mDevice.mHwcDevice, mId,
884 &numElements, nullptr, nullptr);
885 auto error = static_cast<Error>(intError);
886 if (error != Error::None) {
887 return error;
888 }
889
890 std::vector<hwc2_layer_t> layerIds(numElements);
891 std::vector<int32_t> fenceFds(numElements);
892 intError = mDevice.mGetReleaseFences(mDevice.mHwcDevice, mId, &numElements,
893 layerIds.data(), fenceFds.data());
894 error = static_cast<Error>(intError);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800895#else
896 std::vector<Hwc2::Layer> layerIds;
897 std::vector<int> fenceFds;
898 auto intError = mDevice.mComposer->getReleaseFences(mId,
899 layerIds, fenceFds);
900 auto error = static_cast<Error>(intError);
901 uint32_t numElements = layerIds.size();
902#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700903 if (error != Error::None) {
904 return error;
905 }
906
907 std::unordered_map<std::shared_ptr<Layer>, sp<Fence>> releaseFences;
908 releaseFences.reserve(numElements);
909 for (uint32_t element = 0; element < numElements; ++element) {
910 auto layer = getLayerById(layerIds[element]);
911 if (layer) {
912 sp<Fence> fence(new Fence(fenceFds[element]));
913 releaseFences.emplace(std::move(layer), fence);
914 } else {
915 ALOGE("getReleaseFences: invalid layer %" PRIu64
916 " found on display %" PRIu64, layerIds[element], mId);
917 return Error::BadLayer;
918 }
919 }
920
921 *outFences = std::move(releaseFences);
922 return Error::None;
923}
924
925Error Display::present(sp<Fence>* outRetireFence)
926{
927 int32_t retireFenceFd = 0;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800928#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700929 int32_t intError = mDevice.mPresentDisplay(mDevice.mHwcDevice, mId,
930 &retireFenceFd);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800931#else
932 auto intError = mDevice.mComposer->presentDisplay(mId, retireFenceFd);
933#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700934 auto error = static_cast<Error>(intError);
935 if (error != Error::None) {
936 return error;
937 }
938
939 *outRetireFence = new Fence(retireFenceFd);
940 return Error::None;
941}
942
943Error Display::setActiveConfig(const std::shared_ptr<const Config>& config)
944{
945 if (config->getDisplayId() != mId) {
946 ALOGE("setActiveConfig received config %u for the wrong display %"
947 PRIu64 " (expected %" PRIu64 ")", config->getId(),
948 config->getDisplayId(), mId);
949 return Error::BadConfig;
950 }
Chia-I Wuaab99f52016-10-05 12:59:58 +0800951#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700952 int32_t intError = mDevice.mSetActiveConfig(mDevice.mHwcDevice, mId,
953 config->getId());
Chia-I Wuaab99f52016-10-05 12:59:58 +0800954#else
955 auto intError = mDevice.mComposer->setActiveConfig(mId, config->getId());
956#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700957 return static_cast<Error>(intError);
958}
959
960Error Display::setClientTarget(buffer_handle_t target,
961 const sp<Fence>& acquireFence, android_dataspace_t dataspace)
962{
Dan Stoza5cf424b2016-05-20 14:02:39 -0700963 // TODO: Properly encode client target surface damage
Dan Stoza651bf312015-10-23 17:03:17 -0700964 int32_t fenceFd = acquireFence->dup();
Chia-I Wuaab99f52016-10-05 12:59:58 +0800965#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -0700966 int32_t intError = mDevice.mSetClientTarget(mDevice.mHwcDevice, mId, target,
Dan Stoza5cf424b2016-05-20 14:02:39 -0700967 fenceFd, static_cast<int32_t>(dataspace), {0, nullptr});
Chia-I Wuaab99f52016-10-05 12:59:58 +0800968#else
969 auto intError = mDevice.mComposer->setClientTarget(mId, target, fenceFd,
970 static_cast<Hwc2::Dataspace>(dataspace),
971 std::vector<Hwc2::IComposer::Rect>());
972#endif
Dan Stoza651bf312015-10-23 17:03:17 -0700973 return static_cast<Error>(intError);
974}
975
Michael Wright28f24d02016-07-12 13:30:53 -0700976Error Display::setColorMode(android_color_mode_t mode)
Dan Stoza076ac672016-03-14 10:47:53 -0700977{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800978#ifdef BYPASS_IHWC
Dan Stoza076ac672016-03-14 10:47:53 -0700979 int32_t intError = mDevice.mSetColorMode(mDevice.mHwcDevice, mId, mode);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800980#else
981 auto intError = mDevice.mComposer->setColorMode(mId,
982 static_cast<Hwc2::ColorMode>(mode));
983#endif
Dan Stoza076ac672016-03-14 10:47:53 -0700984 return static_cast<Error>(intError);
985}
986
Dan Stoza5df2a862016-03-24 16:19:37 -0700987Error Display::setColorTransform(const android::mat4& matrix,
988 android_color_transform_t hint)
989{
Chia-I Wuaab99f52016-10-05 12:59:58 +0800990#ifdef BYPASS_IHWC
Dan Stoza5df2a862016-03-24 16:19:37 -0700991 int32_t intError = mDevice.mSetColorTransform(mDevice.mHwcDevice, mId,
992 matrix.asArray(), static_cast<int32_t>(hint));
Chia-I Wuaab99f52016-10-05 12:59:58 +0800993#else
994 auto intError = mDevice.mComposer->setColorTransform(mId,
995 matrix.asArray(), static_cast<Hwc2::ColorTransform>(hint));
996#endif
Dan Stoza5df2a862016-03-24 16:19:37 -0700997 return static_cast<Error>(intError);
998}
999
Dan Stoza651bf312015-10-23 17:03:17 -07001000Error Display::setOutputBuffer(const sp<GraphicBuffer>& buffer,
1001 const sp<Fence>& releaseFence)
1002{
1003 int32_t fenceFd = releaseFence->dup();
1004 auto handle = buffer->getNativeBuffer()->handle;
Chia-I Wuaab99f52016-10-05 12:59:58 +08001005#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001006 int32_t intError = mDevice.mSetOutputBuffer(mDevice.mHwcDevice, mId, handle,
1007 fenceFd);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001008#else
1009 auto intError = mDevice.mComposer->setOutputBuffer(mId, handle, fenceFd);
1010#endif
Dan Stoza38628982016-07-13 15:48:58 -07001011 close(fenceFd);
Dan Stoza651bf312015-10-23 17:03:17 -07001012 return static_cast<Error>(intError);
1013}
1014
1015Error Display::setPowerMode(PowerMode mode)
1016{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001017#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001018 auto intMode = static_cast<int32_t>(mode);
1019 int32_t intError = mDevice.mSetPowerMode(mDevice.mHwcDevice, mId, intMode);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001020#else
1021 auto intMode = static_cast<Hwc2::IComposer::PowerMode>(mode);
1022 auto intError = mDevice.mComposer->setPowerMode(mId, intMode);
1023#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001024 return static_cast<Error>(intError);
1025}
1026
1027Error Display::setVsyncEnabled(Vsync enabled)
1028{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001029#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001030 auto intEnabled = static_cast<int32_t>(enabled);
1031 int32_t intError = mDevice.mSetVsyncEnabled(mDevice.mHwcDevice, mId,
1032 intEnabled);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001033#else
1034 auto intEnabled = static_cast<Hwc2::IComposer::Vsync>(enabled);
1035 auto intError = mDevice.mComposer->setVsyncEnabled(mId, intEnabled);
1036#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001037 return static_cast<Error>(intError);
1038}
1039
1040Error Display::validate(uint32_t* outNumTypes, uint32_t* outNumRequests)
1041{
1042 uint32_t numTypes = 0;
1043 uint32_t numRequests = 0;
Chia-I Wuaab99f52016-10-05 12:59:58 +08001044#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001045 int32_t intError = mDevice.mValidateDisplay(mDevice.mHwcDevice, mId,
1046 &numTypes, &numRequests);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001047#else
1048 auto intError = mDevice.mComposer->validateDisplay(mId,
1049 numTypes, numRequests);
1050#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001051 auto error = static_cast<Error>(intError);
1052 if (error != Error::None && error != Error::HasChanges) {
1053 return error;
1054 }
1055
1056 *outNumTypes = numTypes;
1057 *outNumRequests = numRequests;
1058 return error;
1059}
1060
1061// For use by Device
1062
1063int32_t Display::getAttribute(hwc2_config_t configId, Attribute attribute)
1064{
1065 int32_t value = 0;
Chia-I Wuaab99f52016-10-05 12:59:58 +08001066#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001067 int32_t intError = mDevice.mGetDisplayAttribute(mDevice.mHwcDevice, mId,
1068 configId, static_cast<int32_t>(attribute), &value);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001069#else
1070 auto intError = mDevice.mComposer->getDisplayAttribute(mId,
1071 configId, static_cast<Hwc2::IComposer::Attribute>(attribute),
1072 value);
1073#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001074 auto error = static_cast<Error>(intError);
1075 if (error != Error::None) {
1076 ALOGE("getDisplayAttribute(%" PRIu64 ", %u, %s) failed: %s (%d)", mId,
1077 configId, to_string(attribute).c_str(),
1078 to_string(error).c_str(), intError);
1079 return -1;
1080 }
1081 return value;
1082}
1083
1084void Display::loadConfig(hwc2_config_t configId)
1085{
1086 ALOGV("[%" PRIu64 "] loadConfig(%u)", mId, configId);
1087
1088 auto config = Config::Builder(*this, configId)
1089 .setWidth(getAttribute(configId, Attribute::Width))
1090 .setHeight(getAttribute(configId, Attribute::Height))
1091 .setVsyncPeriod(getAttribute(configId, Attribute::VsyncPeriod))
1092 .setDpiX(getAttribute(configId, Attribute::DpiX))
1093 .setDpiY(getAttribute(configId, Attribute::DpiY))
1094 .build();
1095 mConfigs.emplace(configId, std::move(config));
1096}
1097
1098void Display::loadConfigs()
1099{
1100 ALOGV("[%" PRIu64 "] loadConfigs", mId);
1101
Chia-I Wuaab99f52016-10-05 12:59:58 +08001102#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001103 uint32_t numConfigs = 0;
1104 int32_t intError = mDevice.mGetDisplayConfigs(mDevice.mHwcDevice, mId,
1105 &numConfigs, nullptr);
1106 auto error = static_cast<Error>(intError);
1107 if (error != Error::None) {
1108 ALOGE("[%" PRIu64 "] getDisplayConfigs [1] failed: %s (%d)", mId,
1109 to_string(error).c_str(), intError);
1110 return;
1111 }
1112
1113 std::vector<hwc2_config_t> configIds(numConfigs);
1114 intError = mDevice.mGetDisplayConfigs(mDevice.mHwcDevice, mId, &numConfigs,
1115 configIds.data());
1116 error = static_cast<Error>(intError);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001117#else
1118 std::vector<Hwc2::Config> configIds;
1119 auto intError = mDevice.mComposer->getDisplayConfigs(mId, configIds);
1120 auto error = static_cast<Error>(intError);
1121#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001122 if (error != Error::None) {
1123 ALOGE("[%" PRIu64 "] getDisplayConfigs [2] failed: %s (%d)", mId,
1124 to_string(error).c_str(), intError);
1125 return;
1126 }
1127
1128 for (auto configId : configIds) {
1129 loadConfig(configId);
1130 }
1131}
1132
1133// For use by Layer
1134
1135void Display::destroyLayer(hwc2_layer_t layerId)
1136{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001137#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001138 int32_t intError = mDevice.mDestroyLayer(mDevice.mHwcDevice, mId, layerId);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001139#else
1140 auto intError =mDevice.mComposer->destroyLayer(mId, layerId);
1141#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001142 auto error = static_cast<Error>(intError);
1143 ALOGE_IF(error != Error::None, "destroyLayer(%" PRIu64 ", %" PRIu64 ")"
1144 " failed: %s (%d)", mId, layerId, to_string(error).c_str(),
1145 intError);
1146 mLayers.erase(layerId);
1147}
1148
1149// Other Display methods
1150
1151std::shared_ptr<Layer> Display::getLayerById(hwc2_layer_t id) const
1152{
1153 if (mLayers.count(id) == 0) {
1154 return nullptr;
1155 }
1156
1157 auto layer = mLayers.at(id).lock();
1158 return layer;
1159}
1160
1161// Layer methods
1162
1163Layer::Layer(const std::shared_ptr<Display>& display, hwc2_layer_t id)
1164 : mDisplay(display),
1165 mDisplayId(display->getId()),
1166 mDevice(display->getDevice()),
1167 mId(id)
1168{
1169 ALOGV("Created layer %" PRIu64 " on display %" PRIu64, id,
1170 display->getId());
1171}
1172
1173Layer::~Layer()
1174{
1175 auto display = mDisplay.lock();
1176 if (display) {
1177 display->destroyLayer(mId);
1178 }
1179}
1180
1181Error Layer::setCursorPosition(int32_t x, int32_t y)
1182{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001183#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001184 int32_t intError = mDevice.mSetCursorPosition(mDevice.mHwcDevice,
1185 mDisplayId, mId, x, y);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001186#else
1187 auto intError = mDevice.mComposer->setCursorPosition(mDisplayId,
1188 mId, x, y);
1189#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001190 return static_cast<Error>(intError);
1191}
1192
1193Error Layer::setBuffer(buffer_handle_t buffer,
1194 const sp<Fence>& acquireFence)
1195{
1196 int32_t fenceFd = acquireFence->dup();
Chia-I Wuaab99f52016-10-05 12:59:58 +08001197#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001198 int32_t intError = mDevice.mSetLayerBuffer(mDevice.mHwcDevice, mDisplayId,
1199 mId, buffer, fenceFd);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001200#else
1201 auto intError = mDevice.mComposer->setLayerBuffer(mDisplayId,
1202 mId, buffer, fenceFd);
1203#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001204 return static_cast<Error>(intError);
1205}
1206
1207Error Layer::setSurfaceDamage(const Region& damage)
1208{
1209 // We encode default full-screen damage as INVALID_RECT upstream, but as 0
1210 // rects for HWC
Chia-I Wuaab99f52016-10-05 12:59:58 +08001211#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001212 int32_t intError = 0;
Chia-I Wuaab99f52016-10-05 12:59:58 +08001213#else
1214 Hwc2::Error intError = Hwc2::Error::NONE;
1215#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001216 if (damage.isRect() && damage.getBounds() == Rect::INVALID_RECT) {
Chia-I Wuaab99f52016-10-05 12:59:58 +08001217#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001218 intError = mDevice.mSetLayerSurfaceDamage(mDevice.mHwcDevice,
1219 mDisplayId, mId, {0, nullptr});
Chia-I Wuaab99f52016-10-05 12:59:58 +08001220#else
1221 intError = mDevice.mComposer->setLayerSurfaceDamage(mDisplayId,
1222 mId, std::vector<Hwc2::IComposer::Rect>());
1223#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001224 } else {
1225 size_t rectCount = 0;
1226 auto rectArray = damage.getArray(&rectCount);
1227
Chia-I Wuaab99f52016-10-05 12:59:58 +08001228#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001229 std::vector<hwc_rect_t> hwcRects;
Chia-I Wuaab99f52016-10-05 12:59:58 +08001230#else
1231 std::vector<Hwc2::IComposer::Rect> hwcRects;
1232#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001233 for (size_t rect = 0; rect < rectCount; ++rect) {
1234 hwcRects.push_back({rectArray[rect].left, rectArray[rect].top,
1235 rectArray[rect].right, rectArray[rect].bottom});
1236 }
1237
Chia-I Wuaab99f52016-10-05 12:59:58 +08001238#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001239 hwc_region_t hwcRegion = {};
1240 hwcRegion.numRects = rectCount;
1241 hwcRegion.rects = hwcRects.data();
1242
1243 intError = mDevice.mSetLayerSurfaceDamage(mDevice.mHwcDevice,
1244 mDisplayId, mId, hwcRegion);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001245#else
1246 intError = mDevice.mComposer->setLayerSurfaceDamage(mDisplayId,
1247 mId, hwcRects);
1248#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001249 }
1250
1251 return static_cast<Error>(intError);
1252}
1253
1254Error Layer::setBlendMode(BlendMode mode)
1255{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001256#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001257 auto intMode = static_cast<int32_t>(mode);
1258 int32_t intError = mDevice.mSetLayerBlendMode(mDevice.mHwcDevice,
1259 mDisplayId, mId, intMode);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001260#else
1261 auto intMode = static_cast<Hwc2::IComposer::BlendMode>(mode);
1262 auto intError = mDevice.mComposer->setLayerBlendMode(mDisplayId,
1263 mId, intMode);
1264#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001265 return static_cast<Error>(intError);
1266}
1267
1268Error Layer::setColor(hwc_color_t color)
1269{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001270#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001271 int32_t intError = mDevice.mSetLayerColor(mDevice.mHwcDevice, mDisplayId,
1272 mId, color);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001273#else
1274 Hwc2::IComposer::Color hwcColor{color.r, color.g, color.b, color.a};
1275 auto intError = mDevice.mComposer->setLayerColor(mDisplayId,
1276 mId, hwcColor);
1277#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001278 return static_cast<Error>(intError);
1279}
1280
1281Error Layer::setCompositionType(Composition type)
1282{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001283#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001284 auto intType = static_cast<int32_t>(type);
1285 int32_t intError = mDevice.mSetLayerCompositionType(mDevice.mHwcDevice,
1286 mDisplayId, mId, intType);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001287#else
1288 auto intType = static_cast<Hwc2::IComposer::Composition>(type);
1289 auto intError = mDevice.mComposer->setLayerCompositionType(mDisplayId,
1290 mId, intType);
1291#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001292 return static_cast<Error>(intError);
1293}
1294
Dan Stoza5df2a862016-03-24 16:19:37 -07001295Error Layer::setDataspace(android_dataspace_t dataspace)
1296{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001297#ifdef BYPASS_IHWC
Dan Stoza5df2a862016-03-24 16:19:37 -07001298 auto intDataspace = static_cast<int32_t>(dataspace);
1299 int32_t intError = mDevice.mSetLayerDataspace(mDevice.mHwcDevice,
1300 mDisplayId, mId, intDataspace);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001301#else
1302 auto intDataspace = static_cast<Hwc2::Dataspace>(dataspace);
1303 auto intError = mDevice.mComposer->setLayerDataspace(mDisplayId,
1304 mId, intDataspace);
1305#endif
Dan Stoza5df2a862016-03-24 16:19:37 -07001306 return static_cast<Error>(intError);
1307}
1308
Dan Stoza651bf312015-10-23 17:03:17 -07001309Error Layer::setDisplayFrame(const Rect& frame)
1310{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001311#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001312 hwc_rect_t hwcRect{frame.left, frame.top, frame.right, frame.bottom};
1313 int32_t intError = mDevice.mSetLayerDisplayFrame(mDevice.mHwcDevice,
1314 mDisplayId, mId, hwcRect);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001315#else
1316 Hwc2::IComposer::Rect hwcRect{frame.left, frame.top,
1317 frame.right, frame.bottom};
1318 auto intError = mDevice.mComposer->setLayerDisplayFrame(mDisplayId,
1319 mId, hwcRect);
1320#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001321 return static_cast<Error>(intError);
1322}
1323
1324Error Layer::setPlaneAlpha(float alpha)
1325{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001326#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001327 int32_t intError = mDevice.mSetLayerPlaneAlpha(mDevice.mHwcDevice,
1328 mDisplayId, mId, alpha);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001329#else
1330 auto intError = mDevice.mComposer->setLayerPlaneAlpha(mDisplayId,
1331 mId, alpha);
1332#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001333 return static_cast<Error>(intError);
1334}
1335
1336Error Layer::setSidebandStream(const native_handle_t* stream)
1337{
Dan Stoza09e7a272016-04-14 12:31:01 -07001338 if (!mDevice.hasCapability(Capability::SidebandStream)) {
1339 ALOGE("Attempted to call setSidebandStream without checking that the "
1340 "device supports sideband streams");
1341 return Error::Unsupported;
1342 }
Chia-I Wuaab99f52016-10-05 12:59:58 +08001343#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001344 int32_t intError = mDevice.mSetLayerSidebandStream(mDevice.mHwcDevice,
1345 mDisplayId, mId, stream);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001346#else
1347 auto intError = mDevice.mComposer->setLayerSidebandStream(mDisplayId,
1348 mId, stream);
1349#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001350 return static_cast<Error>(intError);
1351}
1352
1353Error Layer::setSourceCrop(const FloatRect& crop)
1354{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001355#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001356 hwc_frect_t hwcRect{crop.left, crop.top, crop.right, crop.bottom};
1357 int32_t intError = mDevice.mSetLayerSourceCrop(mDevice.mHwcDevice,
1358 mDisplayId, mId, hwcRect);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001359#else
1360 Hwc2::IComposer::FRect hwcRect{
1361 crop.left, crop.top, crop.right, crop.bottom};
1362 auto intError = mDevice.mComposer->setLayerSourceCrop(mDisplayId,
1363 mId, hwcRect);
1364#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001365 return static_cast<Error>(intError);
1366}
1367
1368Error Layer::setTransform(Transform transform)
1369{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001370#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001371 auto intTransform = static_cast<int32_t>(transform);
1372 int32_t intError = mDevice.mSetLayerTransform(mDevice.mHwcDevice,
1373 mDisplayId, mId, intTransform);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001374#else
1375 auto intTransform = static_cast<Hwc2::Transform>(transform);
1376 auto intError = mDevice.mComposer->setLayerTransform(mDisplayId,
1377 mId, intTransform);
1378#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001379 return static_cast<Error>(intError);
1380}
1381
1382Error Layer::setVisibleRegion(const Region& region)
1383{
1384 size_t rectCount = 0;
1385 auto rectArray = region.getArray(&rectCount);
1386
Chia-I Wuaab99f52016-10-05 12:59:58 +08001387#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001388 std::vector<hwc_rect_t> hwcRects;
Chia-I Wuaab99f52016-10-05 12:59:58 +08001389#else
1390 std::vector<Hwc2::IComposer::Rect> hwcRects;
1391#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001392 for (size_t rect = 0; rect < rectCount; ++rect) {
1393 hwcRects.push_back({rectArray[rect].left, rectArray[rect].top,
1394 rectArray[rect].right, rectArray[rect].bottom});
1395 }
1396
Chia-I Wuaab99f52016-10-05 12:59:58 +08001397#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001398 hwc_region_t hwcRegion = {};
1399 hwcRegion.numRects = rectCount;
1400 hwcRegion.rects = hwcRects.data();
1401
1402 int32_t intError = mDevice.mSetLayerVisibleRegion(mDevice.mHwcDevice,
1403 mDisplayId, mId, hwcRegion);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001404#else
1405 auto intError = mDevice.mComposer->setLayerVisibleRegion(mDisplayId,
1406 mId, hwcRects);
1407#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001408 return static_cast<Error>(intError);
1409}
1410
1411Error Layer::setZOrder(uint32_t z)
1412{
Chia-I Wuaab99f52016-10-05 12:59:58 +08001413#ifdef BYPASS_IHWC
Dan Stoza651bf312015-10-23 17:03:17 -07001414 int32_t intError = mDevice.mSetLayerZOrder(mDevice.mHwcDevice, mDisplayId,
1415 mId, z);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001416#else
1417 auto intError = mDevice.mComposer->setLayerZOrder(mDisplayId, mId, z);
1418#endif
Dan Stoza651bf312015-10-23 17:03:17 -07001419 return static_cast<Error>(intError);
1420}
1421
1422} // namespace HWC2