blob: c4f845d6b9a9a7ca12954a99a3006a7c417ae901 [file] [log] [blame]
Dan Stozac6998d22015-09-24 17:03:36 -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 "HWC2On1Adapter"
21#define ATRACE_TAG ATRACE_TAG_GRAPHICS
22
23#include "HWC2On1Adapter.h"
24
25#include <hardware/hwcomposer.h>
26#include <log/log.h>
27#include <utils/Trace.h>
28
29#include <cstdlib>
30#include <chrono>
31#include <inttypes.h>
32#include <sstream>
33
34using namespace std::chrono_literals;
35
36static bool operator==(const hwc_color_t& lhs, const hwc_color_t& rhs) {
37 return lhs.r == rhs.r &&
38 lhs.g == rhs.g &&
39 lhs.b == rhs.b &&
40 lhs.a == rhs.a;
41}
42
43static bool operator==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
44 return lhs.left == rhs.left &&
45 lhs.top == rhs.top &&
46 lhs.right == rhs.right &&
47 lhs.bottom == rhs.bottom;
48}
49
50static bool operator==(const hwc_frect_t& lhs, const hwc_frect_t& rhs) {
51 return lhs.left == rhs.left &&
52 lhs.top == rhs.top &&
53 lhs.right == rhs.right &&
54 lhs.bottom == rhs.bottom;
55}
56
57template <typename T>
58static inline bool operator!=(const T& lhs, const T& rhs)
59{
60 return !(lhs == rhs);
61}
62
63static uint8_t getMinorVersion(struct hwc_composer_device_1* device)
64{
65 auto version = device->common.version & HARDWARE_API_VERSION_2_MAJ_MIN_MASK;
66 return (version >> 16) & 0xF;
67}
68
69template <typename PFN, typename T>
70static hwc2_function_pointer_t asFP(T function)
71{
72 static_assert(std::is_same<PFN, T>::value, "Incompatible function pointer");
73 return reinterpret_cast<hwc2_function_pointer_t>(function);
74}
75
76using namespace HWC2;
77
Michael Wright28f24d02016-07-12 13:30:53 -070078static constexpr Attribute ColorMode = static_cast<Attribute>(6);
Dan Stoza076ac672016-03-14 10:47:53 -070079
Dan Stozac6998d22015-09-24 17:03:36 -070080namespace android {
81
82void HWC2On1Adapter::DisplayContentsDeleter::operator()(
83 hwc_display_contents_1_t* contents)
84{
85 if (contents != nullptr) {
86 for (size_t l = 0; l < contents->numHwLayers; ++l) {
87 auto& layer = contents->hwLayers[l];
88 std::free(const_cast<hwc_rect_t*>(layer.visibleRegionScreen.rects));
Fabien Sanglardec0a9562016-12-13 11:57:33 -080089 std::free(const_cast<hwc_rect_t*>(layer.surfaceDamage.rects));
Dan Stozac6998d22015-09-24 17:03:36 -070090 }
91 }
92 std::free(contents);
93}
94
95class HWC2On1Adapter::Callbacks : public hwc_procs_t {
96 public:
Chih-Hung Hsiehc4067912016-05-03 14:03:27 -070097 explicit Callbacks(HWC2On1Adapter& adapter) : mAdapter(adapter) {
Dan Stozac6998d22015-09-24 17:03:36 -070098 invalidate = &invalidateHook;
99 vsync = &vsyncHook;
100 hotplug = &hotplugHook;
101 }
102
103 static void invalidateHook(const hwc_procs_t* procs) {
104 auto callbacks = static_cast<const Callbacks*>(procs);
105 callbacks->mAdapter.hwc1Invalidate();
106 }
107
108 static void vsyncHook(const hwc_procs_t* procs, int display,
109 int64_t timestamp) {
110 auto callbacks = static_cast<const Callbacks*>(procs);
111 callbacks->mAdapter.hwc1Vsync(display, timestamp);
112 }
113
114 static void hotplugHook(const hwc_procs_t* procs, int display,
115 int connected) {
116 auto callbacks = static_cast<const Callbacks*>(procs);
117 callbacks->mAdapter.hwc1Hotplug(display, connected);
118 }
119
120 private:
121 HWC2On1Adapter& mAdapter;
122};
123
124static int closeHook(hw_device_t* /*device*/)
125{
126 // Do nothing, since the real work is done in the class destructor, but we
127 // need to provide a valid function pointer for hwc2_close to call
128 return 0;
129}
130
131HWC2On1Adapter::HWC2On1Adapter(hwc_composer_device_1_t* hwc1Device)
132 : mDumpString(),
133 mHwc1Device(hwc1Device),
134 mHwc1MinorVersion(getMinorVersion(hwc1Device)),
135 mHwc1SupportsVirtualDisplays(false),
Fabien Sanglardeb3db612016-11-18 16:12:31 -0800136 mHwc1SupportsBackgroundColor(false),
Dan Stozac6998d22015-09-24 17:03:36 -0700137 mHwc1Callbacks(std::make_unique<Callbacks>(*this)),
138 mCapabilities(),
139 mLayers(),
140 mHwc1VirtualDisplay(),
141 mStateMutex(),
142 mCallbacks(),
143 mHasPendingInvalidate(false),
144 mPendingVsyncs(),
145 mPendingHotplugs(),
146 mDisplays(),
147 mHwc1DisplayMap()
148{
149 common.close = closeHook;
150 getCapabilities = getCapabilitiesHook;
151 getFunction = getFunctionHook;
152 populateCapabilities();
153 populatePrimary();
154 mHwc1Device->registerProcs(mHwc1Device,
155 static_cast<const hwc_procs_t*>(mHwc1Callbacks.get()));
156}
157
158HWC2On1Adapter::~HWC2On1Adapter() {
159 hwc_close_1(mHwc1Device);
160}
161
162void HWC2On1Adapter::doGetCapabilities(uint32_t* outCount,
163 int32_t* outCapabilities)
164{
165 if (outCapabilities == nullptr) {
166 *outCount = mCapabilities.size();
167 return;
168 }
169
170 auto capabilityIter = mCapabilities.cbegin();
171 for (size_t written = 0; written < *outCount; ++written) {
172 if (capabilityIter == mCapabilities.cend()) {
173 return;
174 }
175 outCapabilities[written] = static_cast<int32_t>(*capabilityIter);
176 ++capabilityIter;
177 }
178}
179
180hwc2_function_pointer_t HWC2On1Adapter::doGetFunction(
181 FunctionDescriptor descriptor)
182{
183 switch (descriptor) {
184 // Device functions
185 case FunctionDescriptor::CreateVirtualDisplay:
186 return asFP<HWC2_PFN_CREATE_VIRTUAL_DISPLAY>(
187 createVirtualDisplayHook);
188 case FunctionDescriptor::DestroyVirtualDisplay:
189 return asFP<HWC2_PFN_DESTROY_VIRTUAL_DISPLAY>(
190 destroyVirtualDisplayHook);
191 case FunctionDescriptor::Dump:
192 return asFP<HWC2_PFN_DUMP>(dumpHook);
193 case FunctionDescriptor::GetMaxVirtualDisplayCount:
194 return asFP<HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT>(
195 getMaxVirtualDisplayCountHook);
196 case FunctionDescriptor::RegisterCallback:
197 return asFP<HWC2_PFN_REGISTER_CALLBACK>(registerCallbackHook);
198
199 // Display functions
200 case FunctionDescriptor::AcceptDisplayChanges:
201 return asFP<HWC2_PFN_ACCEPT_DISPLAY_CHANGES>(
202 displayHook<decltype(&Display::acceptChanges),
203 &Display::acceptChanges>);
204 case FunctionDescriptor::CreateLayer:
205 return asFP<HWC2_PFN_CREATE_LAYER>(
206 displayHook<decltype(&Display::createLayer),
207 &Display::createLayer, hwc2_layer_t*>);
208 case FunctionDescriptor::DestroyLayer:
209 return asFP<HWC2_PFN_DESTROY_LAYER>(
210 displayHook<decltype(&Display::destroyLayer),
211 &Display::destroyLayer, hwc2_layer_t>);
212 case FunctionDescriptor::GetActiveConfig:
213 return asFP<HWC2_PFN_GET_ACTIVE_CONFIG>(
214 displayHook<decltype(&Display::getActiveConfig),
215 &Display::getActiveConfig, hwc2_config_t*>);
216 case FunctionDescriptor::GetChangedCompositionTypes:
217 return asFP<HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES>(
218 displayHook<decltype(&Display::getChangedCompositionTypes),
219 &Display::getChangedCompositionTypes, uint32_t*,
220 hwc2_layer_t*, int32_t*>);
Dan Stoza076ac672016-03-14 10:47:53 -0700221 case FunctionDescriptor::GetColorModes:
222 return asFP<HWC2_PFN_GET_COLOR_MODES>(
223 displayHook<decltype(&Display::getColorModes),
224 &Display::getColorModes, uint32_t*, int32_t*>);
Dan Stozac6998d22015-09-24 17:03:36 -0700225 case FunctionDescriptor::GetDisplayAttribute:
226 return asFP<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>(
227 getDisplayAttributeHook);
228 case FunctionDescriptor::GetDisplayConfigs:
229 return asFP<HWC2_PFN_GET_DISPLAY_CONFIGS>(
230 displayHook<decltype(&Display::getConfigs),
231 &Display::getConfigs, uint32_t*, hwc2_config_t*>);
232 case FunctionDescriptor::GetDisplayName:
233 return asFP<HWC2_PFN_GET_DISPLAY_NAME>(
234 displayHook<decltype(&Display::getName),
235 &Display::getName, uint32_t*, char*>);
236 case FunctionDescriptor::GetDisplayRequests:
237 return asFP<HWC2_PFN_GET_DISPLAY_REQUESTS>(
238 displayHook<decltype(&Display::getRequests),
239 &Display::getRequests, int32_t*, uint32_t*, hwc2_layer_t*,
240 int32_t*>);
241 case FunctionDescriptor::GetDisplayType:
242 return asFP<HWC2_PFN_GET_DISPLAY_TYPE>(
243 displayHook<decltype(&Display::getType),
244 &Display::getType, int32_t*>);
245 case FunctionDescriptor::GetDozeSupport:
246 return asFP<HWC2_PFN_GET_DOZE_SUPPORT>(
247 displayHook<decltype(&Display::getDozeSupport),
248 &Display::getDozeSupport, int32_t*>);
Dan Stozaed40eba2016-03-16 12:33:52 -0700249 case FunctionDescriptor::GetHdrCapabilities:
250 return asFP<HWC2_PFN_GET_HDR_CAPABILITIES>(
251 displayHook<decltype(&Display::getHdrCapabilities),
252 &Display::getHdrCapabilities, uint32_t*, int32_t*, float*,
253 float*, float*>);
Dan Stozac6998d22015-09-24 17:03:36 -0700254 case FunctionDescriptor::GetReleaseFences:
255 return asFP<HWC2_PFN_GET_RELEASE_FENCES>(
256 displayHook<decltype(&Display::getReleaseFences),
257 &Display::getReleaseFences, uint32_t*, hwc2_layer_t*,
258 int32_t*>);
259 case FunctionDescriptor::PresentDisplay:
260 return asFP<HWC2_PFN_PRESENT_DISPLAY>(
261 displayHook<decltype(&Display::present),
262 &Display::present, int32_t*>);
263 case FunctionDescriptor::SetActiveConfig:
264 return asFP<HWC2_PFN_SET_ACTIVE_CONFIG>(
265 displayHook<decltype(&Display::setActiveConfig),
266 &Display::setActiveConfig, hwc2_config_t>);
267 case FunctionDescriptor::SetClientTarget:
268 return asFP<HWC2_PFN_SET_CLIENT_TARGET>(
269 displayHook<decltype(&Display::setClientTarget),
270 &Display::setClientTarget, buffer_handle_t, int32_t,
Dan Stoza5cf424b2016-05-20 14:02:39 -0700271 int32_t, hwc_region_t>);
Dan Stoza076ac672016-03-14 10:47:53 -0700272 case FunctionDescriptor::SetColorMode:
Michael Wright28f24d02016-07-12 13:30:53 -0700273 return asFP<HWC2_PFN_SET_COLOR_MODE>(setColorModeHook);
Dan Stoza5df2a862016-03-24 16:19:37 -0700274 case FunctionDescriptor::SetColorTransform:
275 return asFP<HWC2_PFN_SET_COLOR_TRANSFORM>(setColorTransformHook);
Dan Stozac6998d22015-09-24 17:03:36 -0700276 case FunctionDescriptor::SetOutputBuffer:
277 return asFP<HWC2_PFN_SET_OUTPUT_BUFFER>(
278 displayHook<decltype(&Display::setOutputBuffer),
279 &Display::setOutputBuffer, buffer_handle_t, int32_t>);
280 case FunctionDescriptor::SetPowerMode:
281 return asFP<HWC2_PFN_SET_POWER_MODE>(setPowerModeHook);
282 case FunctionDescriptor::SetVsyncEnabled:
283 return asFP<HWC2_PFN_SET_VSYNC_ENABLED>(setVsyncEnabledHook);
284 case FunctionDescriptor::ValidateDisplay:
285 return asFP<HWC2_PFN_VALIDATE_DISPLAY>(
286 displayHook<decltype(&Display::validate),
287 &Display::validate, uint32_t*, uint32_t*>);
288
289 // Layer functions
290 case FunctionDescriptor::SetCursorPosition:
291 return asFP<HWC2_PFN_SET_CURSOR_POSITION>(
292 layerHook<decltype(&Layer::setCursorPosition),
293 &Layer::setCursorPosition, int32_t, int32_t>);
294 case FunctionDescriptor::SetLayerBuffer:
295 return asFP<HWC2_PFN_SET_LAYER_BUFFER>(
296 layerHook<decltype(&Layer::setBuffer), &Layer::setBuffer,
297 buffer_handle_t, int32_t>);
298 case FunctionDescriptor::SetLayerSurfaceDamage:
299 return asFP<HWC2_PFN_SET_LAYER_SURFACE_DAMAGE>(
300 layerHook<decltype(&Layer::setSurfaceDamage),
301 &Layer::setSurfaceDamage, hwc_region_t>);
302
303 // Layer state functions
304 case FunctionDescriptor::SetLayerBlendMode:
305 return asFP<HWC2_PFN_SET_LAYER_BLEND_MODE>(
306 setLayerBlendModeHook);
307 case FunctionDescriptor::SetLayerColor:
308 return asFP<HWC2_PFN_SET_LAYER_COLOR>(
309 layerHook<decltype(&Layer::setColor), &Layer::setColor,
310 hwc_color_t>);
311 case FunctionDescriptor::SetLayerCompositionType:
312 return asFP<HWC2_PFN_SET_LAYER_COMPOSITION_TYPE>(
313 setLayerCompositionTypeHook);
Dan Stoza5df2a862016-03-24 16:19:37 -0700314 case FunctionDescriptor::SetLayerDataspace:
315 return asFP<HWC2_PFN_SET_LAYER_DATASPACE>(setLayerDataspaceHook);
Dan Stozac6998d22015-09-24 17:03:36 -0700316 case FunctionDescriptor::SetLayerDisplayFrame:
317 return asFP<HWC2_PFN_SET_LAYER_DISPLAY_FRAME>(
318 layerHook<decltype(&Layer::setDisplayFrame),
319 &Layer::setDisplayFrame, hwc_rect_t>);
320 case FunctionDescriptor::SetLayerPlaneAlpha:
321 return asFP<HWC2_PFN_SET_LAYER_PLANE_ALPHA>(
322 layerHook<decltype(&Layer::setPlaneAlpha),
323 &Layer::setPlaneAlpha, float>);
324 case FunctionDescriptor::SetLayerSidebandStream:
325 return asFP<HWC2_PFN_SET_LAYER_SIDEBAND_STREAM>(
326 layerHook<decltype(&Layer::setSidebandStream),
327 &Layer::setSidebandStream, const native_handle_t*>);
328 case FunctionDescriptor::SetLayerSourceCrop:
329 return asFP<HWC2_PFN_SET_LAYER_SOURCE_CROP>(
330 layerHook<decltype(&Layer::setSourceCrop),
331 &Layer::setSourceCrop, hwc_frect_t>);
332 case FunctionDescriptor::SetLayerTransform:
333 return asFP<HWC2_PFN_SET_LAYER_TRANSFORM>(setLayerTransformHook);
334 case FunctionDescriptor::SetLayerVisibleRegion:
335 return asFP<HWC2_PFN_SET_LAYER_VISIBLE_REGION>(
336 layerHook<decltype(&Layer::setVisibleRegion),
337 &Layer::setVisibleRegion, hwc_region_t>);
338 case FunctionDescriptor::SetLayerZOrder:
339 return asFP<HWC2_PFN_SET_LAYER_Z_ORDER>(setLayerZOrderHook);
340
341 default:
342 ALOGE("doGetFunction: Unknown function descriptor: %d (%s)",
343 static_cast<int32_t>(descriptor),
344 to_string(descriptor).c_str());
345 return nullptr;
346 }
347}
348
349// Device functions
350
351Error HWC2On1Adapter::createVirtualDisplay(uint32_t width,
352 uint32_t height, hwc2_display_t* outDisplay)
353{
Dan Stozafc4e2022016-02-23 11:43:19 -0800354 std::unique_lock<std::recursive_timed_mutex> lock(mStateMutex);
Dan Stozac6998d22015-09-24 17:03:36 -0700355
356 if (mHwc1VirtualDisplay) {
357 // We have already allocated our only HWC1 virtual display
358 ALOGE("createVirtualDisplay: HWC1 virtual display already allocated");
359 return Error::NoResources;
360 }
361
362 if (MAX_VIRTUAL_DISPLAY_DIMENSION != 0 &&
363 (width > MAX_VIRTUAL_DISPLAY_DIMENSION ||
364 height > MAX_VIRTUAL_DISPLAY_DIMENSION)) {
365 ALOGE("createVirtualDisplay: Can't create a virtual display with"
366 " a dimension > %u (tried %u x %u)",
367 MAX_VIRTUAL_DISPLAY_DIMENSION, width, height);
368 return Error::NoResources;
369 }
370
371 mHwc1VirtualDisplay = std::make_shared<HWC2On1Adapter::Display>(*this,
372 HWC2::DisplayType::Virtual);
373 mHwc1VirtualDisplay->populateConfigs(width, height);
374 const auto displayId = mHwc1VirtualDisplay->getId();
375 mHwc1DisplayMap[HWC_DISPLAY_VIRTUAL] = displayId;
376 mHwc1VirtualDisplay->setHwc1Id(HWC_DISPLAY_VIRTUAL);
377 mDisplays.emplace(displayId, mHwc1VirtualDisplay);
378 *outDisplay = displayId;
379
380 return Error::None;
381}
382
383Error HWC2On1Adapter::destroyVirtualDisplay(hwc2_display_t displayId)
384{
Dan Stozafc4e2022016-02-23 11:43:19 -0800385 std::unique_lock<std::recursive_timed_mutex> lock(mStateMutex);
Dan Stozac6998d22015-09-24 17:03:36 -0700386
387 if (!mHwc1VirtualDisplay || (mHwc1VirtualDisplay->getId() != displayId)) {
388 return Error::BadDisplay;
389 }
390
391 mHwc1VirtualDisplay.reset();
392 mHwc1DisplayMap.erase(HWC_DISPLAY_VIRTUAL);
393 mDisplays.erase(displayId);
394
395 return Error::None;
396}
397
398void HWC2On1Adapter::dump(uint32_t* outSize, char* outBuffer)
399{
400 if (outBuffer != nullptr) {
401 auto copiedBytes = mDumpString.copy(outBuffer, *outSize);
402 *outSize = static_cast<uint32_t>(copiedBytes);
403 return;
404 }
405
406 std::stringstream output;
407
408 output << "-- HWC2On1Adapter --\n";
409
410 output << "Adapting to a HWC 1." << static_cast<int>(mHwc1MinorVersion) <<
411 " device\n";
412
413 // Attempt to acquire the lock for 1 second, but proceed without the lock
414 // after that, so we can still get some information if we're deadlocked
Dan Stozafc4e2022016-02-23 11:43:19 -0800415 std::unique_lock<std::recursive_timed_mutex> lock(mStateMutex,
416 std::defer_lock);
Dan Stozac6998d22015-09-24 17:03:36 -0700417 lock.try_lock_for(1s);
418
419 if (mCapabilities.empty()) {
420 output << "Capabilities: None\n";
421 } else {
422 output << "Capabilities:\n";
423 for (auto capability : mCapabilities) {
424 output << " " << to_string(capability) << '\n';
425 }
426 }
427
428 output << "Displays:\n";
429 for (const auto& element : mDisplays) {
430 const auto& display = element.second;
431 output << display->dump();
432 }
433 output << '\n';
434
Dan Stozafc4e2022016-02-23 11:43:19 -0800435 // Release the lock before calling into HWC1, and since we no longer require
436 // mutual exclusion to access mCapabilities or mDisplays
437 lock.unlock();
438
Dan Stozac6998d22015-09-24 17:03:36 -0700439 if (mHwc1Device->dump) {
440 output << "HWC1 dump:\n";
441 std::vector<char> hwc1Dump(4096);
442 // Call with size - 1 to preserve a null character at the end
443 mHwc1Device->dump(mHwc1Device, hwc1Dump.data(),
444 static_cast<int>(hwc1Dump.size() - 1));
445 output << hwc1Dump.data();
446 }
447
448 mDumpString = output.str();
449 *outSize = static_cast<uint32_t>(mDumpString.size());
450}
451
452uint32_t HWC2On1Adapter::getMaxVirtualDisplayCount()
453{
454 return mHwc1SupportsVirtualDisplays ? 1 : 0;
455}
456
457static bool isValid(Callback descriptor) {
458 switch (descriptor) {
459 case Callback::Hotplug: // Fall-through
460 case Callback::Refresh: // Fall-through
461 case Callback::Vsync: return true;
462 default: return false;
463 }
464}
465
466Error HWC2On1Adapter::registerCallback(Callback descriptor,
467 hwc2_callback_data_t callbackData, hwc2_function_pointer_t pointer)
468{
469 if (!isValid(descriptor)) {
470 return Error::BadParameter;
471 }
472
473 ALOGV("registerCallback(%s, %p, %p)", to_string(descriptor).c_str(),
474 callbackData, pointer);
475
Dan Stozafc4e2022016-02-23 11:43:19 -0800476 std::unique_lock<std::recursive_timed_mutex> lock(mStateMutex);
Dan Stozac6998d22015-09-24 17:03:36 -0700477
478 mCallbacks[descriptor] = {callbackData, pointer};
479
480 bool hasPendingInvalidate = false;
481 std::vector<hwc2_display_t> displayIds;
482 std::vector<std::pair<hwc2_display_t, int64_t>> pendingVsyncs;
483 std::vector<std::pair<hwc2_display_t, int>> pendingHotplugs;
484
485 if (descriptor == Callback::Refresh) {
486 hasPendingInvalidate = mHasPendingInvalidate;
487 if (hasPendingInvalidate) {
488 for (auto& displayPair : mDisplays) {
489 displayIds.emplace_back(displayPair.first);
490 }
491 }
492 mHasPendingInvalidate = false;
493 } else if (descriptor == Callback::Vsync) {
494 for (auto pending : mPendingVsyncs) {
495 auto hwc1DisplayId = pending.first;
496 if (mHwc1DisplayMap.count(hwc1DisplayId) == 0) {
497 ALOGE("hwc1Vsync: Couldn't find display for HWC1 id %d",
498 hwc1DisplayId);
499 continue;
500 }
501 auto displayId = mHwc1DisplayMap[hwc1DisplayId];
502 auto timestamp = pending.second;
503 pendingVsyncs.emplace_back(displayId, timestamp);
504 }
505 mPendingVsyncs.clear();
506 } else if (descriptor == Callback::Hotplug) {
507 // Hotplug the primary display
508 pendingHotplugs.emplace_back(mHwc1DisplayMap[HWC_DISPLAY_PRIMARY],
509 static_cast<int32_t>(Connection::Connected));
510
511 for (auto pending : mPendingHotplugs) {
512 auto hwc1DisplayId = pending.first;
513 if (mHwc1DisplayMap.count(hwc1DisplayId) == 0) {
514 ALOGE("hwc1Hotplug: Couldn't find display for HWC1 id %d",
515 hwc1DisplayId);
516 continue;
517 }
518 auto displayId = mHwc1DisplayMap[hwc1DisplayId];
519 auto connected = pending.second;
520 pendingHotplugs.emplace_back(displayId, connected);
521 }
522 }
523
524 // Call pending callbacks without the state lock held
525 lock.unlock();
526
527 if (hasPendingInvalidate) {
528 auto refresh = reinterpret_cast<HWC2_PFN_REFRESH>(pointer);
529 for (auto displayId : displayIds) {
530 refresh(callbackData, displayId);
531 }
532 }
533 if (!pendingVsyncs.empty()) {
534 auto vsync = reinterpret_cast<HWC2_PFN_VSYNC>(pointer);
535 for (auto& pendingVsync : pendingVsyncs) {
536 vsync(callbackData, pendingVsync.first, pendingVsync.second);
537 }
538 }
539 if (!pendingHotplugs.empty()) {
540 auto hotplug = reinterpret_cast<HWC2_PFN_HOTPLUG>(pointer);
541 for (auto& pendingHotplug : pendingHotplugs) {
542 hotplug(callbackData, pendingHotplug.first, pendingHotplug.second);
543 }
544 }
545 return Error::None;
546}
547
548// Display functions
549
550std::atomic<hwc2_display_t> HWC2On1Adapter::Display::sNextId(1);
551
552HWC2On1Adapter::Display::Display(HWC2On1Adapter& device, HWC2::DisplayType type)
553 : mId(sNextId++),
554 mDevice(device),
555 mDirtyCount(0),
556 mStateMutex(),
557 mZIsDirty(false),
558 mHwc1RequestedContents(nullptr),
559 mHwc1ReceivedContents(nullptr),
560 mRetireFence(),
561 mChanges(),
562 mHwc1Id(-1),
563 mConfigs(),
564 mActiveConfig(nullptr),
Michael Wrightc75ca512016-07-20 21:34:48 +0100565 mActiveColorMode(static_cast<android_color_mode_t>(-1)),
Dan Stozac6998d22015-09-24 17:03:36 -0700566 mName(),
567 mType(type),
568 mPowerMode(PowerMode::Off),
569 mVsyncEnabled(Vsync::Invalid),
570 mClientTarget(),
571 mOutputBuffer(),
Dan Stoza5df2a862016-03-24 16:19:37 -0700572 mHasColorTransform(false),
Dan Stozafc4e2022016-02-23 11:43:19 -0800573 mLayers(),
574 mHwc1LayerMap() {}
Dan Stozac6998d22015-09-24 17:03:36 -0700575
576Error HWC2On1Adapter::Display::acceptChanges()
577{
578 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
579
580 if (!mChanges) {
581 ALOGV("[%" PRIu64 "] acceptChanges failed, not validated", mId);
582 return Error::NotValidated;
583 }
584
585 ALOGV("[%" PRIu64 "] acceptChanges", mId);
586
587 for (auto& change : mChanges->getTypeChanges()) {
588 auto layerId = change.first;
589 auto type = change.second;
590 auto layer = mDevice.mLayers[layerId];
591 layer->setCompositionType(type);
592 }
593
594 mChanges->clearTypeChanges();
595
596 mHwc1RequestedContents = std::move(mHwc1ReceivedContents);
597
598 return Error::None;
599}
600
601Error HWC2On1Adapter::Display::createLayer(hwc2_layer_t* outLayerId)
602{
603 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
604
605 auto layer = *mLayers.emplace(std::make_shared<Layer>(*this));
606 mDevice.mLayers.emplace(std::make_pair(layer->getId(), layer));
607 *outLayerId = layer->getId();
608 ALOGV("[%" PRIu64 "] created layer %" PRIu64, mId, *outLayerId);
609 return Error::None;
610}
611
612Error HWC2On1Adapter::Display::destroyLayer(hwc2_layer_t layerId)
613{
614 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
615
616 const auto mapLayer = mDevice.mLayers.find(layerId);
617 if (mapLayer == mDevice.mLayers.end()) {
618 ALOGV("[%" PRIu64 "] destroyLayer(%" PRIu64 ") failed: no such layer",
619 mId, layerId);
620 return Error::BadLayer;
621 }
622 const auto layer = mapLayer->second;
623 mDevice.mLayers.erase(mapLayer);
624 const auto zRange = mLayers.equal_range(layer);
625 for (auto current = zRange.first; current != zRange.second; ++current) {
626 if (**current == *layer) {
627 current = mLayers.erase(current);
628 break;
629 }
630 }
631 ALOGV("[%" PRIu64 "] destroyed layer %" PRIu64, mId, layerId);
632 return Error::None;
633}
634
635Error HWC2On1Adapter::Display::getActiveConfig(hwc2_config_t* outConfig)
636{
637 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
638
639 if (!mActiveConfig) {
640 ALOGV("[%" PRIu64 "] getActiveConfig --> %s", mId,
641 to_string(Error::BadConfig).c_str());
642 return Error::BadConfig;
643 }
644 auto configId = mActiveConfig->getId();
645 ALOGV("[%" PRIu64 "] getActiveConfig --> %u", mId, configId);
646 *outConfig = configId;
647 return Error::None;
648}
649
650Error HWC2On1Adapter::Display::getAttribute(hwc2_config_t configId,
651 Attribute attribute, int32_t* outValue)
652{
653 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
654
655 if (configId > mConfigs.size() || !mConfigs[configId]->isOnDisplay(*this)) {
656 ALOGV("[%" PRIu64 "] getAttribute failed: bad config (%u)", mId,
657 configId);
658 return Error::BadConfig;
659 }
660 *outValue = mConfigs[configId]->getAttribute(attribute);
661 ALOGV("[%" PRIu64 "] getAttribute(%u, %s) --> %d", mId, configId,
662 to_string(attribute).c_str(), *outValue);
663 return Error::None;
664}
665
666Error HWC2On1Adapter::Display::getChangedCompositionTypes(
667 uint32_t* outNumElements, hwc2_layer_t* outLayers, int32_t* outTypes)
668{
669 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
670
671 if (!mChanges) {
672 ALOGE("[%" PRIu64 "] getChangedCompositionTypes failed: not validated",
673 mId);
674 return Error::NotValidated;
675 }
676
677 if ((outLayers == nullptr) || (outTypes == nullptr)) {
678 *outNumElements = mChanges->getTypeChanges().size();
679 return Error::None;
680 }
681
682 uint32_t numWritten = 0;
683 for (const auto& element : mChanges->getTypeChanges()) {
684 if (numWritten == *outNumElements) {
685 break;
686 }
687 auto layerId = element.first;
688 auto intType = static_cast<int32_t>(element.second);
689 ALOGV("Adding %" PRIu64 " %s", layerId,
690 to_string(element.second).c_str());
691 outLayers[numWritten] = layerId;
692 outTypes[numWritten] = intType;
693 ++numWritten;
694 }
695 *outNumElements = numWritten;
696
697 return Error::None;
698}
699
Dan Stoza076ac672016-03-14 10:47:53 -0700700Error HWC2On1Adapter::Display::getColorModes(uint32_t* outNumModes,
701 int32_t* outModes)
702{
703 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
704
705 if (!outModes) {
706 *outNumModes = mColorModes.size();
707 return Error::None;
708 }
709 uint32_t numModes = std::min(*outNumModes,
710 static_cast<uint32_t>(mColorModes.size()));
711 std::copy_n(mColorModes.cbegin(), numModes, outModes);
712 *outNumModes = numModes;
713 return Error::None;
714}
715
Dan Stozac6998d22015-09-24 17:03:36 -0700716Error HWC2On1Adapter::Display::getConfigs(uint32_t* outNumConfigs,
717 hwc2_config_t* outConfigs)
718{
719 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
720
721 if (!outConfigs) {
722 *outNumConfigs = mConfigs.size();
723 return Error::None;
724 }
725 uint32_t numWritten = 0;
726 for (const auto& config : mConfigs) {
727 if (numWritten == *outNumConfigs) {
728 break;
729 }
730 outConfigs[numWritten] = config->getId();
731 ++numWritten;
732 }
733 *outNumConfigs = numWritten;
734 return Error::None;
735}
736
737Error HWC2On1Adapter::Display::getDozeSupport(int32_t* outSupport)
738{
739 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
740
741 if (mDevice.mHwc1MinorVersion < 4 || mHwc1Id != 0) {
742 *outSupport = 0;
743 } else {
744 *outSupport = 1;
745 }
746 return Error::None;
747}
748
Dan Stozaed40eba2016-03-16 12:33:52 -0700749Error HWC2On1Adapter::Display::getHdrCapabilities(uint32_t* outNumTypes,
750 int32_t* /*outTypes*/, float* /*outMaxLuminance*/,
751 float* /*outMaxAverageLuminance*/, float* /*outMinLuminance*/)
752{
753 // This isn't supported on HWC1, so per the HWC2 header, return numTypes = 0
754 *outNumTypes = 0;
755 return Error::None;
756}
757
Dan Stozac6998d22015-09-24 17:03:36 -0700758Error HWC2On1Adapter::Display::getName(uint32_t* outSize, char* outName)
759{
760 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
761
762 if (!outName) {
763 *outSize = mName.size();
764 return Error::None;
765 }
766 auto numCopied = mName.copy(outName, *outSize);
767 *outSize = numCopied;
768 return Error::None;
769}
770
771Error HWC2On1Adapter::Display::getReleaseFences(uint32_t* outNumElements,
772 hwc2_layer_t* outLayers, int32_t* outFences)
773{
774 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
775
776 uint32_t numWritten = 0;
777 bool outputsNonNull = (outLayers != nullptr) && (outFences != nullptr);
778 for (const auto& layer : mLayers) {
779 if (outputsNonNull && (numWritten == *outNumElements)) {
780 break;
781 }
782
783 auto releaseFence = layer->getReleaseFence();
784 if (releaseFence != Fence::NO_FENCE) {
785 if (outputsNonNull) {
786 outLayers[numWritten] = layer->getId();
787 outFences[numWritten] = releaseFence->dup();
788 }
789 ++numWritten;
790 }
791 }
792 *outNumElements = numWritten;
793
794 return Error::None;
795}
796
797Error HWC2On1Adapter::Display::getRequests(int32_t* outDisplayRequests,
798 uint32_t* outNumElements, hwc2_layer_t* outLayers,
799 int32_t* outLayerRequests)
800{
801 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
802
803 if (!mChanges) {
804 return Error::NotValidated;
805 }
806
807 if (outLayers == nullptr || outLayerRequests == nullptr) {
808 *outNumElements = mChanges->getNumLayerRequests();
809 return Error::None;
810 }
811
Fabien Sanglard601938c2016-11-29 11:10:40 -0800812 // Display requests (HWC2::DisplayRequest) are not supported by hwc1:
813 // A hwc1 has always zero requests for the client.
814 *outDisplayRequests = 0;
815
Dan Stozac6998d22015-09-24 17:03:36 -0700816 uint32_t numWritten = 0;
817 for (const auto& request : mChanges->getLayerRequests()) {
818 if (numWritten == *outNumElements) {
819 break;
820 }
821 outLayers[numWritten] = request.first;
822 outLayerRequests[numWritten] = static_cast<int32_t>(request.second);
823 ++numWritten;
824 }
825
826 return Error::None;
827}
828
829Error HWC2On1Adapter::Display::getType(int32_t* outType)
830{
831 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
832
833 *outType = static_cast<int32_t>(mType);
834 return Error::None;
835}
836
837Error HWC2On1Adapter::Display::present(int32_t* outRetireFence)
838{
839 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
840
841 if (mChanges) {
842 Error error = mDevice.setAllDisplays();
843 if (error != Error::None) {
844 ALOGE("[%" PRIu64 "] present: setAllDisplaysFailed (%s)", mId,
845 to_string(error).c_str());
846 return error;
847 }
848 }
849
850 *outRetireFence = mRetireFence.get()->dup();
851 ALOGV("[%" PRIu64 "] present returning retire fence %d", mId,
852 *outRetireFence);
853
854 return Error::None;
855}
856
857Error HWC2On1Adapter::Display::setActiveConfig(hwc2_config_t configId)
858{
859 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
860
861 auto config = getConfig(configId);
862 if (!config) {
863 return Error::BadConfig;
864 }
Dan Stoza076ac672016-03-14 10:47:53 -0700865 if (config == mActiveConfig) {
866 return Error::None;
Dan Stozac6998d22015-09-24 17:03:36 -0700867 }
Dan Stoza076ac672016-03-14 10:47:53 -0700868
869 if (mDevice.mHwc1MinorVersion >= 4) {
870 uint32_t hwc1Id = 0;
871 auto error = config->getHwc1IdForColorMode(mActiveColorMode, &hwc1Id);
872 if (error != Error::None) {
873 return error;
874 }
875
876 int intError = mDevice.mHwc1Device->setActiveConfig(mDevice.mHwc1Device,
877 mHwc1Id, static_cast<int>(hwc1Id));
878 if (intError != 0) {
879 ALOGE("setActiveConfig: Failed to set active config on HWC1 (%d)",
880 intError);
881 return Error::BadConfig;
882 }
883 mActiveConfig = config;
884 }
885
Dan Stozac6998d22015-09-24 17:03:36 -0700886 return Error::None;
887}
888
889Error HWC2On1Adapter::Display::setClientTarget(buffer_handle_t target,
Dan Stoza5cf424b2016-05-20 14:02:39 -0700890 int32_t acquireFence, int32_t /*dataspace*/, hwc_region_t /*damage*/)
Dan Stozac6998d22015-09-24 17:03:36 -0700891{
892 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
893
894 ALOGV("[%" PRIu64 "] setClientTarget(%p, %d)", mId, target, acquireFence);
895 mClientTarget.setBuffer(target);
896 mClientTarget.setFence(acquireFence);
Dan Stoza5cf424b2016-05-20 14:02:39 -0700897 // dataspace and damage can't be used by HWC1, so ignore them
Dan Stozac6998d22015-09-24 17:03:36 -0700898 return Error::None;
899}
900
Michael Wright28f24d02016-07-12 13:30:53 -0700901Error HWC2On1Adapter::Display::setColorMode(android_color_mode_t mode)
Dan Stoza076ac672016-03-14 10:47:53 -0700902{
903 std::unique_lock<std::recursive_mutex> lock (mStateMutex);
904
905 ALOGV("[%" PRIu64 "] setColorMode(%d)", mId, mode);
906
907 if (mode == mActiveColorMode) {
908 return Error::None;
909 }
910 if (mColorModes.count(mode) == 0) {
911 ALOGE("[%" PRIu64 "] Mode %d not found in mColorModes", mId, mode);
912 return Error::Unsupported;
913 }
914
915 uint32_t hwc1Config = 0;
916 auto error = mActiveConfig->getHwc1IdForColorMode(mode, &hwc1Config);
917 if (error != Error::None) {
918 return error;
919 }
920
921 ALOGV("[%" PRIu64 "] Setting HWC1 config %u", mId, hwc1Config);
922 int intError = mDevice.mHwc1Device->setActiveConfig(mDevice.mHwc1Device,
923 mHwc1Id, hwc1Config);
924 if (intError != 0) {
925 ALOGE("[%" PRIu64 "] Failed to set HWC1 config (%d)", mId, intError);
926 return Error::Unsupported;
927 }
928
929 mActiveColorMode = mode;
930 return Error::None;
931}
932
Dan Stoza5df2a862016-03-24 16:19:37 -0700933Error HWC2On1Adapter::Display::setColorTransform(android_color_transform_t hint)
934{
935 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
936
937 ALOGV("%" PRIu64 "] setColorTransform(%d)", mId,
938 static_cast<int32_t>(hint));
939 mHasColorTransform = (hint != HAL_COLOR_TRANSFORM_IDENTITY);
940 return Error::None;
941}
942
Dan Stozac6998d22015-09-24 17:03:36 -0700943Error HWC2On1Adapter::Display::setOutputBuffer(buffer_handle_t buffer,
944 int32_t releaseFence)
945{
946 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
947
948 ALOGV("[%" PRIu64 "] setOutputBuffer(%p, %d)", mId, buffer, releaseFence);
949 mOutputBuffer.setBuffer(buffer);
950 mOutputBuffer.setFence(releaseFence);
951 return Error::None;
952}
953
954static bool isValid(PowerMode mode)
955{
956 switch (mode) {
957 case PowerMode::Off: // Fall-through
958 case PowerMode::DozeSuspend: // Fall-through
959 case PowerMode::Doze: // Fall-through
960 case PowerMode::On: return true;
961 default: return false;
962 }
963}
964
965static int getHwc1PowerMode(PowerMode mode)
966{
967 switch (mode) {
968 case PowerMode::Off: return HWC_POWER_MODE_OFF;
969 case PowerMode::DozeSuspend: return HWC_POWER_MODE_DOZE_SUSPEND;
970 case PowerMode::Doze: return HWC_POWER_MODE_DOZE;
971 case PowerMode::On: return HWC_POWER_MODE_NORMAL;
972 default: return HWC_POWER_MODE_OFF;
973 }
974}
975
976Error HWC2On1Adapter::Display::setPowerMode(PowerMode mode)
977{
978 if (!isValid(mode)) {
979 return Error::BadParameter;
980 }
981 if (mode == mPowerMode) {
982 return Error::None;
983 }
984
985 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
986
987 int error = 0;
988 if (mDevice.mHwc1MinorVersion < 4) {
989 error = mDevice.mHwc1Device->blank(mDevice.mHwc1Device, mHwc1Id,
990 mode == PowerMode::Off);
991 } else {
992 error = mDevice.mHwc1Device->setPowerMode(mDevice.mHwc1Device,
993 mHwc1Id, getHwc1PowerMode(mode));
994 }
995 ALOGE_IF(error != 0, "setPowerMode: Failed to set power mode on HWC1 (%d)",
996 error);
997
998 ALOGV("[%" PRIu64 "] setPowerMode(%s)", mId, to_string(mode).c_str());
999 mPowerMode = mode;
1000 return Error::None;
1001}
1002
1003static bool isValid(Vsync enable) {
1004 switch (enable) {
1005 case Vsync::Enable: // Fall-through
1006 case Vsync::Disable: return true;
1007 default: return false;
1008 }
1009}
1010
1011Error HWC2On1Adapter::Display::setVsyncEnabled(Vsync enable)
1012{
1013 if (!isValid(enable)) {
1014 return Error::BadParameter;
1015 }
1016 if (enable == mVsyncEnabled) {
1017 return Error::None;
1018 }
1019
1020 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1021
1022 int error = mDevice.mHwc1Device->eventControl(mDevice.mHwc1Device,
1023 mHwc1Id, HWC_EVENT_VSYNC, enable == Vsync::Enable);
1024 ALOGE_IF(error != 0, "setVsyncEnabled: Failed to set vsync on HWC1 (%d)",
1025 error);
1026
1027 mVsyncEnabled = enable;
1028 return Error::None;
1029}
1030
1031Error HWC2On1Adapter::Display::validate(uint32_t* outNumTypes,
1032 uint32_t* outNumRequests)
1033{
1034 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1035
1036 ALOGV("[%" PRIu64 "] Entering validate", mId);
1037
1038 if (!mChanges) {
1039 if (!mDevice.prepareAllDisplays()) {
1040 return Error::BadDisplay;
1041 }
1042 }
1043
1044 *outNumTypes = mChanges->getNumTypes();
1045 *outNumRequests = mChanges->getNumLayerRequests();
1046 ALOGV("[%" PRIu64 "] validate --> %u types, %u requests", mId, *outNumTypes,
1047 *outNumRequests);
1048 for (auto request : mChanges->getTypeChanges()) {
1049 ALOGV("Layer %" PRIu64 " --> %s", request.first,
1050 to_string(request.second).c_str());
1051 }
1052 return *outNumTypes > 0 ? Error::HasChanges : Error::None;
1053}
1054
1055// Display helpers
1056
1057Error HWC2On1Adapter::Display::updateLayerZ(hwc2_layer_t layerId, uint32_t z)
1058{
1059 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1060
1061 const auto mapLayer = mDevice.mLayers.find(layerId);
1062 if (mapLayer == mDevice.mLayers.end()) {
1063 ALOGE("[%" PRIu64 "] updateLayerZ failed to find layer", mId);
1064 return Error::BadLayer;
1065 }
1066
1067 const auto layer = mapLayer->second;
1068 const auto zRange = mLayers.equal_range(layer);
1069 bool layerOnDisplay = false;
1070 for (auto current = zRange.first; current != zRange.second; ++current) {
1071 if (**current == *layer) {
1072 if ((*current)->getZ() == z) {
1073 // Don't change anything if the Z hasn't changed
1074 return Error::None;
1075 }
1076 current = mLayers.erase(current);
1077 layerOnDisplay = true;
1078 break;
1079 }
1080 }
1081
1082 if (!layerOnDisplay) {
1083 ALOGE("[%" PRIu64 "] updateLayerZ failed to find layer on display",
1084 mId);
1085 return Error::BadLayer;
1086 }
1087
1088 layer->setZ(z);
1089 mLayers.emplace(std::move(layer));
1090 mZIsDirty = true;
1091
1092 return Error::None;
1093}
1094
Dan Stoza076ac672016-03-14 10:47:53 -07001095static constexpr uint32_t ATTRIBUTES_WITH_COLOR[] = {
1096 HWC_DISPLAY_VSYNC_PERIOD,
1097 HWC_DISPLAY_WIDTH,
1098 HWC_DISPLAY_HEIGHT,
1099 HWC_DISPLAY_DPI_X,
1100 HWC_DISPLAY_DPI_Y,
1101 HWC_DISPLAY_COLOR_TRANSFORM,
1102 HWC_DISPLAY_NO_ATTRIBUTE,
1103};
1104
1105static constexpr uint32_t ATTRIBUTES_WITHOUT_COLOR[] = {
Dan Stozac6998d22015-09-24 17:03:36 -07001106 HWC_DISPLAY_VSYNC_PERIOD,
1107 HWC_DISPLAY_WIDTH,
1108 HWC_DISPLAY_HEIGHT,
1109 HWC_DISPLAY_DPI_X,
1110 HWC_DISPLAY_DPI_Y,
1111 HWC_DISPLAY_NO_ATTRIBUTE,
1112};
Dan Stozac6998d22015-09-24 17:03:36 -07001113
Dan Stoza076ac672016-03-14 10:47:53 -07001114static constexpr size_t NUM_ATTRIBUTES_WITH_COLOR =
1115 sizeof(ATTRIBUTES_WITH_COLOR) / sizeof(uint32_t);
1116static_assert(sizeof(ATTRIBUTES_WITH_COLOR) > sizeof(ATTRIBUTES_WITHOUT_COLOR),
1117 "Attribute tables have unexpected sizes");
1118
1119static constexpr uint32_t ATTRIBUTE_MAP_WITH_COLOR[] = {
1120 6, // HWC_DISPLAY_NO_ATTRIBUTE = 0
1121 0, // HWC_DISPLAY_VSYNC_PERIOD = 1,
1122 1, // HWC_DISPLAY_WIDTH = 2,
1123 2, // HWC_DISPLAY_HEIGHT = 3,
1124 3, // HWC_DISPLAY_DPI_X = 4,
1125 4, // HWC_DISPLAY_DPI_Y = 5,
1126 5, // HWC_DISPLAY_COLOR_TRANSFORM = 6,
1127};
1128
1129static constexpr uint32_t ATTRIBUTE_MAP_WITHOUT_COLOR[] = {
Dan Stozac6998d22015-09-24 17:03:36 -07001130 5, // HWC_DISPLAY_NO_ATTRIBUTE = 0
1131 0, // HWC_DISPLAY_VSYNC_PERIOD = 1,
1132 1, // HWC_DISPLAY_WIDTH = 2,
1133 2, // HWC_DISPLAY_HEIGHT = 3,
1134 3, // HWC_DISPLAY_DPI_X = 4,
1135 4, // HWC_DISPLAY_DPI_Y = 5,
1136};
1137
1138template <uint32_t attribute>
1139static constexpr bool attributesMatch()
1140{
Dan Stoza076ac672016-03-14 10:47:53 -07001141 bool match = (attribute ==
1142 ATTRIBUTES_WITH_COLOR[ATTRIBUTE_MAP_WITH_COLOR[attribute]]);
1143 if (attribute == HWC_DISPLAY_COLOR_TRANSFORM) {
1144 return match;
1145 }
1146
1147 return match && (attribute ==
1148 ATTRIBUTES_WITHOUT_COLOR[ATTRIBUTE_MAP_WITHOUT_COLOR[attribute]]);
Dan Stozac6998d22015-09-24 17:03:36 -07001149}
1150static_assert(attributesMatch<HWC_DISPLAY_VSYNC_PERIOD>(),
1151 "Tables out of sync");
1152static_assert(attributesMatch<HWC_DISPLAY_WIDTH>(), "Tables out of sync");
1153static_assert(attributesMatch<HWC_DISPLAY_HEIGHT>(), "Tables out of sync");
1154static_assert(attributesMatch<HWC_DISPLAY_DPI_X>(), "Tables out of sync");
1155static_assert(attributesMatch<HWC_DISPLAY_DPI_Y>(), "Tables out of sync");
Dan Stoza076ac672016-03-14 10:47:53 -07001156static_assert(attributesMatch<HWC_DISPLAY_COLOR_TRANSFORM>(),
1157 "Tables out of sync");
Dan Stozac6998d22015-09-24 17:03:36 -07001158
1159void HWC2On1Adapter::Display::populateConfigs()
1160{
1161 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1162
1163 ALOGV("[%" PRIu64 "] populateConfigs", mId);
1164
1165 if (mHwc1Id == -1) {
1166 ALOGE("populateConfigs: HWC1 ID not set");
1167 return;
1168 }
1169
1170 const size_t MAX_NUM_CONFIGS = 128;
1171 uint32_t configs[MAX_NUM_CONFIGS] = {};
1172 size_t numConfigs = MAX_NUM_CONFIGS;
1173 mDevice.mHwc1Device->getDisplayConfigs(mDevice.mHwc1Device, mHwc1Id,
1174 configs, &numConfigs);
1175
1176 for (size_t c = 0; c < numConfigs; ++c) {
1177 uint32_t hwc1ConfigId = configs[c];
Dan Stoza076ac672016-03-14 10:47:53 -07001178 auto newConfig = std::make_shared<Config>(*this);
Dan Stozac6998d22015-09-24 17:03:36 -07001179
Dan Stoza076ac672016-03-14 10:47:53 -07001180 int32_t values[NUM_ATTRIBUTES_WITH_COLOR] = {};
1181 bool hasColor = true;
1182 auto result = mDevice.mHwc1Device->getDisplayAttributes(
1183 mDevice.mHwc1Device, mHwc1Id, hwc1ConfigId,
1184 ATTRIBUTES_WITH_COLOR, values);
1185 if (result != 0) {
1186 mDevice.mHwc1Device->getDisplayAttributes(mDevice.mHwc1Device,
1187 mHwc1Id, hwc1ConfigId, ATTRIBUTES_WITHOUT_COLOR, values);
1188 hasColor = false;
Dan Stozac6998d22015-09-24 17:03:36 -07001189 }
Dan Stoza076ac672016-03-14 10:47:53 -07001190
1191 auto attributeMap = hasColor ?
1192 ATTRIBUTE_MAP_WITH_COLOR : ATTRIBUTE_MAP_WITHOUT_COLOR;
1193
1194 newConfig->setAttribute(Attribute::VsyncPeriod,
1195 values[attributeMap[HWC_DISPLAY_VSYNC_PERIOD]]);
1196 newConfig->setAttribute(Attribute::Width,
1197 values[attributeMap[HWC_DISPLAY_WIDTH]]);
1198 newConfig->setAttribute(Attribute::Height,
1199 values[attributeMap[HWC_DISPLAY_HEIGHT]]);
1200 newConfig->setAttribute(Attribute::DpiX,
1201 values[attributeMap[HWC_DISPLAY_DPI_X]]);
1202 newConfig->setAttribute(Attribute::DpiY,
1203 values[attributeMap[HWC_DISPLAY_DPI_Y]]);
1204 if (hasColor) {
Michael Wright28f24d02016-07-12 13:30:53 -07001205 // In HWC1, color modes are referred to as color transforms. To avoid confusion with
1206 // the HWC2 concept of color transforms, we internally refer to them as color modes for
1207 // both HWC1 and 2.
1208 newConfig->setAttribute(ColorMode,
Dan Stoza076ac672016-03-14 10:47:53 -07001209 values[attributeMap[HWC_DISPLAY_COLOR_TRANSFORM]]);
1210 }
1211
Michael Wright28f24d02016-07-12 13:30:53 -07001212 // We can only do this after attempting to read the color mode
Dan Stoza076ac672016-03-14 10:47:53 -07001213 newConfig->setHwc1Id(hwc1ConfigId);
1214
1215 for (auto& existingConfig : mConfigs) {
1216 if (existingConfig->merge(*newConfig)) {
1217 ALOGV("Merged config %d with existing config %u: %s",
1218 hwc1ConfigId, existingConfig->getId(),
1219 existingConfig->toString().c_str());
1220 newConfig.reset();
1221 break;
1222 }
1223 }
1224
1225 // If it wasn't merged with any existing config, add it to the end
1226 if (newConfig) {
1227 newConfig->setId(static_cast<hwc2_config_t>(mConfigs.size()));
1228 ALOGV("Found new config %u: %s", newConfig->getId(),
1229 newConfig->toString().c_str());
1230 mConfigs.emplace_back(std::move(newConfig));
1231 }
Dan Stozac6998d22015-09-24 17:03:36 -07001232 }
Dan Stoza076ac672016-03-14 10:47:53 -07001233
1234 initializeActiveConfig();
1235 populateColorModes();
Dan Stozac6998d22015-09-24 17:03:36 -07001236}
1237
1238void HWC2On1Adapter::Display::populateConfigs(uint32_t width, uint32_t height)
1239{
1240 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1241
Dan Stoza076ac672016-03-14 10:47:53 -07001242 mConfigs.emplace_back(std::make_shared<Config>(*this));
Dan Stozac6998d22015-09-24 17:03:36 -07001243 auto& config = mConfigs[0];
1244
1245 config->setAttribute(Attribute::Width, static_cast<int32_t>(width));
1246 config->setAttribute(Attribute::Height, static_cast<int32_t>(height));
Dan Stoza076ac672016-03-14 10:47:53 -07001247 config->setHwc1Id(0);
1248 config->setId(0);
Dan Stozac6998d22015-09-24 17:03:36 -07001249 mActiveConfig = config;
1250}
1251
1252bool HWC2On1Adapter::Display::prepare()
1253{
1254 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1255
1256 // Only prepare display contents for displays HWC1 knows about
1257 if (mHwc1Id == -1) {
1258 return true;
1259 }
1260
1261 // It doesn't make sense to prepare a display for which there is no active
1262 // config, so return early
1263 if (!mActiveConfig) {
1264 ALOGE("[%" PRIu64 "] Attempted to prepare, but no config active", mId);
1265 return false;
1266 }
1267
1268 ALOGV("[%" PRIu64 "] Entering prepare", mId);
1269
1270 auto currentCount = mHwc1RequestedContents ?
1271 mHwc1RequestedContents->numHwLayers : 0;
1272 auto requiredCount = mLayers.size() + 1;
1273 ALOGV("[%" PRIu64 "] Requires %zd layers, %zd allocated in %p", mId,
1274 requiredCount, currentCount, mHwc1RequestedContents.get());
1275
1276 bool layerCountChanged = (currentCount != requiredCount);
1277 if (layerCountChanged) {
1278 reallocateHwc1Contents();
1279 }
1280
1281 bool applyAllState = false;
1282 if (layerCountChanged || mZIsDirty) {
1283 assignHwc1LayerIds();
1284 mZIsDirty = false;
1285 applyAllState = true;
1286 }
1287
1288 mHwc1RequestedContents->retireFenceFd = -1;
1289 mHwc1RequestedContents->flags = 0;
1290 if (isDirty() || applyAllState) {
1291 mHwc1RequestedContents->flags |= HWC_GEOMETRY_CHANGED;
1292 }
1293
1294 for (auto& layer : mLayers) {
1295 auto& hwc1Layer = mHwc1RequestedContents->hwLayers[layer->getHwc1Id()];
1296 hwc1Layer.releaseFenceFd = -1;
1297 layer->applyState(hwc1Layer, applyAllState);
1298 }
1299
1300 mHwc1RequestedContents->outbuf = mOutputBuffer.getBuffer();
1301 mHwc1RequestedContents->outbufAcquireFenceFd = mOutputBuffer.getFence();
1302
1303 prepareFramebufferTarget();
1304
1305 return true;
1306}
1307
1308static void cloneHWCRegion(hwc_region_t& region)
1309{
1310 auto size = sizeof(hwc_rect_t) * region.numRects;
1311 auto newRects = static_cast<hwc_rect_t*>(std::malloc(size));
1312 std::copy_n(region.rects, region.numRects, newRects);
1313 region.rects = newRects;
1314}
1315
1316HWC2On1Adapter::Display::HWC1Contents
1317 HWC2On1Adapter::Display::cloneRequestedContents() const
1318{
1319 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1320
1321 size_t size = sizeof(hwc_display_contents_1_t) +
1322 sizeof(hwc_layer_1_t) * (mHwc1RequestedContents->numHwLayers);
1323 auto contents = static_cast<hwc_display_contents_1_t*>(std::malloc(size));
1324 std::memcpy(contents, mHwc1RequestedContents.get(), size);
1325 for (size_t layerId = 0; layerId < contents->numHwLayers; ++layerId) {
1326 auto& layer = contents->hwLayers[layerId];
1327 // Deep copy the regions to avoid double-frees
1328 cloneHWCRegion(layer.visibleRegionScreen);
1329 cloneHWCRegion(layer.surfaceDamage);
1330 }
1331 return HWC1Contents(contents);
1332}
1333
1334void HWC2On1Adapter::Display::setReceivedContents(HWC1Contents contents)
1335{
1336 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1337
1338 mHwc1ReceivedContents = std::move(contents);
1339
1340 mChanges.reset(new Changes);
1341
1342 size_t numLayers = mHwc1ReceivedContents->numHwLayers;
1343 for (size_t hwc1Id = 0; hwc1Id < numLayers; ++hwc1Id) {
1344 const auto& receivedLayer = mHwc1ReceivedContents->hwLayers[hwc1Id];
1345 if (mHwc1LayerMap.count(hwc1Id) == 0) {
1346 ALOGE_IF(receivedLayer.compositionType != HWC_FRAMEBUFFER_TARGET,
1347 "setReceivedContents: HWC1 layer %zd doesn't have a"
1348 " matching HWC2 layer, and isn't the framebuffer target",
1349 hwc1Id);
1350 continue;
1351 }
1352
1353 Layer& layer = *mHwc1LayerMap[hwc1Id];
1354 updateTypeChanges(receivedLayer, layer);
1355 updateLayerRequests(receivedLayer, layer);
1356 }
1357}
1358
1359bool HWC2On1Adapter::Display::hasChanges() const
1360{
1361 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1362 return mChanges != nullptr;
1363}
1364
1365Error HWC2On1Adapter::Display::set(hwc_display_contents_1& hwcContents)
1366{
1367 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1368
1369 if (!mChanges || (mChanges->getNumTypes() > 0)) {
1370 ALOGE("[%" PRIu64 "] set failed: not validated", mId);
1371 return Error::NotValidated;
1372 }
1373
1374 // Set up the client/framebuffer target
1375 auto numLayers = hwcContents.numHwLayers;
1376
1377 // Close acquire fences on FRAMEBUFFER layers, since they will not be used
1378 // by HWC
1379 for (size_t l = 0; l < numLayers - 1; ++l) {
1380 auto& layer = hwcContents.hwLayers[l];
1381 if (layer.compositionType == HWC_FRAMEBUFFER) {
1382 ALOGV("Closing fence %d for layer %zd", layer.acquireFenceFd, l);
1383 close(layer.acquireFenceFd);
1384 layer.acquireFenceFd = -1;
1385 }
1386 }
1387
1388 auto& clientTargetLayer = hwcContents.hwLayers[numLayers - 1];
1389 if (clientTargetLayer.compositionType == HWC_FRAMEBUFFER_TARGET) {
1390 clientTargetLayer.handle = mClientTarget.getBuffer();
1391 clientTargetLayer.acquireFenceFd = mClientTarget.getFence();
1392 } else {
1393 ALOGE("[%" PRIu64 "] set: last HWC layer wasn't FRAMEBUFFER_TARGET",
1394 mId);
1395 }
1396
1397 mChanges.reset();
1398
1399 return Error::None;
1400}
1401
1402void HWC2On1Adapter::Display::addRetireFence(int fenceFd)
1403{
1404 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1405 mRetireFence.add(fenceFd);
1406}
1407
1408void HWC2On1Adapter::Display::addReleaseFences(
1409 const hwc_display_contents_1_t& hwcContents)
1410{
1411 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1412
1413 size_t numLayers = hwcContents.numHwLayers;
1414 for (size_t hwc1Id = 0; hwc1Id < numLayers; ++hwc1Id) {
1415 const auto& receivedLayer = hwcContents.hwLayers[hwc1Id];
1416 if (mHwc1LayerMap.count(hwc1Id) == 0) {
1417 if (receivedLayer.compositionType != HWC_FRAMEBUFFER_TARGET) {
1418 ALOGE("addReleaseFences: HWC1 layer %zd doesn't have a"
1419 " matching HWC2 layer, and isn't the framebuffer"
1420 " target", hwc1Id);
1421 }
1422 // Close the framebuffer target release fence since we will use the
1423 // display retire fence instead
1424 if (receivedLayer.releaseFenceFd != -1) {
1425 close(receivedLayer.releaseFenceFd);
1426 }
1427 continue;
1428 }
1429
1430 Layer& layer = *mHwc1LayerMap[hwc1Id];
1431 ALOGV("Adding release fence %d to layer %" PRIu64,
1432 receivedLayer.releaseFenceFd, layer.getId());
1433 layer.addReleaseFence(receivedLayer.releaseFenceFd);
1434 }
1435}
1436
Dan Stoza5df2a862016-03-24 16:19:37 -07001437bool HWC2On1Adapter::Display::hasColorTransform() const
1438{
1439 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1440 return mHasColorTransform;
1441}
1442
Dan Stozac6998d22015-09-24 17:03:36 -07001443static std::string hwc1CompositionString(int32_t type)
1444{
1445 switch (type) {
1446 case HWC_FRAMEBUFFER: return "Framebuffer";
1447 case HWC_OVERLAY: return "Overlay";
1448 case HWC_BACKGROUND: return "Background";
1449 case HWC_FRAMEBUFFER_TARGET: return "FramebufferTarget";
1450 case HWC_SIDEBAND: return "Sideband";
1451 case HWC_CURSOR_OVERLAY: return "CursorOverlay";
1452 default:
1453 return std::string("Unknown (") + std::to_string(type) + ")";
1454 }
1455}
1456
1457static std::string hwc1TransformString(int32_t transform)
1458{
1459 switch (transform) {
1460 case 0: return "None";
1461 case HWC_TRANSFORM_FLIP_H: return "FlipH";
1462 case HWC_TRANSFORM_FLIP_V: return "FlipV";
1463 case HWC_TRANSFORM_ROT_90: return "Rotate90";
1464 case HWC_TRANSFORM_ROT_180: return "Rotate180";
1465 case HWC_TRANSFORM_ROT_270: return "Rotate270";
1466 case HWC_TRANSFORM_FLIP_H_ROT_90: return "FlipHRotate90";
1467 case HWC_TRANSFORM_FLIP_V_ROT_90: return "FlipVRotate90";
1468 default:
1469 return std::string("Unknown (") + std::to_string(transform) + ")";
1470 }
1471}
1472
1473static std::string hwc1BlendModeString(int32_t mode)
1474{
1475 switch (mode) {
1476 case HWC_BLENDING_NONE: return "None";
1477 case HWC_BLENDING_PREMULT: return "Premultiplied";
1478 case HWC_BLENDING_COVERAGE: return "Coverage";
1479 default:
1480 return std::string("Unknown (") + std::to_string(mode) + ")";
1481 }
1482}
1483
1484static std::string rectString(hwc_rect_t rect)
1485{
1486 std::stringstream output;
1487 output << "[" << rect.left << ", " << rect.top << ", ";
1488 output << rect.right << ", " << rect.bottom << "]";
1489 return output.str();
1490}
1491
1492static std::string approximateFloatString(float f)
1493{
1494 if (static_cast<int32_t>(f) == f) {
1495 return std::to_string(static_cast<int32_t>(f));
1496 }
1497 int32_t truncated = static_cast<int32_t>(f * 10);
1498 bool approximate = (static_cast<float>(truncated) != f * 10);
1499 const size_t BUFFER_SIZE = 32;
1500 char buffer[BUFFER_SIZE] = {};
1501 auto bytesWritten = snprintf(buffer, BUFFER_SIZE,
1502 "%s%.1f", approximate ? "~" : "", f);
1503 return std::string(buffer, bytesWritten);
1504}
1505
1506static std::string frectString(hwc_frect_t frect)
1507{
1508 std::stringstream output;
1509 output << "[" << approximateFloatString(frect.left) << ", ";
1510 output << approximateFloatString(frect.top) << ", ";
1511 output << approximateFloatString(frect.right) << ", ";
1512 output << approximateFloatString(frect.bottom) << "]";
1513 return output.str();
1514}
1515
1516static std::string colorString(hwc_color_t color)
1517{
1518 std::stringstream output;
1519 output << "RGBA [";
1520 output << static_cast<int32_t>(color.r) << ", ";
1521 output << static_cast<int32_t>(color.g) << ", ";
1522 output << static_cast<int32_t>(color.b) << ", ";
1523 output << static_cast<int32_t>(color.a) << "]";
1524 return output.str();
1525}
1526
1527static std::string alphaString(float f)
1528{
1529 const size_t BUFFER_SIZE = 8;
1530 char buffer[BUFFER_SIZE] = {};
1531 auto bytesWritten = snprintf(buffer, BUFFER_SIZE, "%.3f", f);
1532 return std::string(buffer, bytesWritten);
1533}
1534
1535static std::string to_string(const hwc_layer_1_t& hwcLayer,
1536 int32_t hwc1MinorVersion)
1537{
1538 const char* fill = " ";
1539
1540 std::stringstream output;
1541
1542 output << " Composition: " <<
1543 hwc1CompositionString(hwcLayer.compositionType);
1544
1545 if (hwcLayer.compositionType == HWC_BACKGROUND) {
1546 output << " Color: " << colorString(hwcLayer.backgroundColor) << '\n';
1547 } else if (hwcLayer.compositionType == HWC_SIDEBAND) {
1548 output << " Stream: " << hwcLayer.sidebandStream << '\n';
1549 } else {
1550 output << " Buffer: " << hwcLayer.handle << "/" <<
1551 hwcLayer.acquireFenceFd << '\n';
1552 }
1553
1554 output << fill << "Display frame: " << rectString(hwcLayer.displayFrame) <<
1555 '\n';
1556
1557 output << fill << "Source crop: ";
1558 if (hwc1MinorVersion >= 3) {
1559 output << frectString(hwcLayer.sourceCropf) << '\n';
1560 } else {
1561 output << rectString(hwcLayer.sourceCropi) << '\n';
1562 }
1563
1564 output << fill << "Transform: " << hwc1TransformString(hwcLayer.transform);
1565 output << " Blend mode: " << hwc1BlendModeString(hwcLayer.blending);
1566 if (hwcLayer.planeAlpha != 0xFF) {
1567 output << " Alpha: " << alphaString(hwcLayer.planeAlpha / 255.0f);
1568 }
1569 output << '\n';
1570
1571 if (hwcLayer.hints != 0) {
1572 output << fill << "Hints:";
1573 if ((hwcLayer.hints & HWC_HINT_TRIPLE_BUFFER) != 0) {
1574 output << " TripleBuffer";
1575 }
1576 if ((hwcLayer.hints & HWC_HINT_CLEAR_FB) != 0) {
1577 output << " ClearFB";
1578 }
1579 output << '\n';
1580 }
1581
1582 if (hwcLayer.flags != 0) {
1583 output << fill << "Flags:";
1584 if ((hwcLayer.flags & HWC_SKIP_LAYER) != 0) {
1585 output << " SkipLayer";
1586 }
1587 if ((hwcLayer.flags & HWC_IS_CURSOR_LAYER) != 0) {
1588 output << " IsCursorLayer";
1589 }
1590 output << '\n';
1591 }
1592
1593 return output.str();
1594}
1595
1596static std::string to_string(const hwc_display_contents_1_t& hwcContents,
1597 int32_t hwc1MinorVersion)
1598{
1599 const char* fill = " ";
1600
1601 std::stringstream output;
1602 output << fill << "Geometry changed: " <<
1603 ((hwcContents.flags & HWC_GEOMETRY_CHANGED) != 0 ? "Y\n" : "N\n");
1604
1605 output << fill << hwcContents.numHwLayers << " Layer" <<
1606 ((hwcContents.numHwLayers == 1) ? "\n" : "s\n");
1607 for (size_t layer = 0; layer < hwcContents.numHwLayers; ++layer) {
1608 output << fill << " Layer " << layer;
1609 output << to_string(hwcContents.hwLayers[layer], hwc1MinorVersion);
1610 }
1611
1612 if (hwcContents.outbuf != nullptr) {
1613 output << fill << "Output buffer: " << hwcContents.outbuf << "/" <<
1614 hwcContents.outbufAcquireFenceFd << '\n';
1615 }
1616
1617 return output.str();
1618}
1619
1620std::string HWC2On1Adapter::Display::dump() const
1621{
1622 std::unique_lock<std::recursive_mutex> lock(mStateMutex);
1623
1624 std::stringstream output;
1625
1626 output << " Display " << mId << ": ";
1627 output << to_string(mType) << " ";
1628 output << "HWC1 ID: " << mHwc1Id << " ";
1629 output << "Power mode: " << to_string(mPowerMode) << " ";
1630 output << "Vsync: " << to_string(mVsyncEnabled) << '\n';
1631
Dan Stoza076ac672016-03-14 10:47:53 -07001632 output << " Color modes [active]:";
1633 for (const auto& mode : mColorModes) {
1634 if (mode == mActiveColorMode) {
1635 output << " [" << mode << ']';
Dan Stozac6998d22015-09-24 17:03:36 -07001636 } else {
Dan Stoza076ac672016-03-14 10:47:53 -07001637 output << " " << mode;
Dan Stozac6998d22015-09-24 17:03:36 -07001638 }
1639 }
1640 output << '\n';
1641
Dan Stoza076ac672016-03-14 10:47:53 -07001642 output << " " << mConfigs.size() << " Config" <<
1643 (mConfigs.size() == 1 ? "" : "s") << " (* active)\n";
1644 for (const auto& config : mConfigs) {
1645 output << (config == mActiveConfig ? " * " : " ");
1646 output << config->toString(true) << '\n';
1647 }
1648
Dan Stozac6998d22015-09-24 17:03:36 -07001649 output << " " << mLayers.size() << " Layer" <<
1650 (mLayers.size() == 1 ? "" : "s") << '\n';
1651 for (const auto& layer : mLayers) {
1652 output << layer->dump();
1653 }
1654
1655 output << " Client target: " << mClientTarget.getBuffer() << '\n';
1656
1657 if (mOutputBuffer.getBuffer() != nullptr) {
1658 output << " Output buffer: " << mOutputBuffer.getBuffer() << '\n';
1659 }
1660
1661 if (mHwc1ReceivedContents) {
1662 output << " Last received HWC1 state\n";
1663 output << to_string(*mHwc1ReceivedContents, mDevice.mHwc1MinorVersion);
1664 } else if (mHwc1RequestedContents) {
1665 output << " Last requested HWC1 state\n";
1666 output << to_string(*mHwc1RequestedContents, mDevice.mHwc1MinorVersion);
1667 }
1668
1669 return output.str();
1670}
1671
1672void HWC2On1Adapter::Display::Config::setAttribute(HWC2::Attribute attribute,
1673 int32_t value)
1674{
1675 mAttributes[attribute] = value;
1676}
1677
1678int32_t HWC2On1Adapter::Display::Config::getAttribute(Attribute attribute) const
1679{
1680 if (mAttributes.count(attribute) == 0) {
1681 return -1;
1682 }
1683 return mAttributes.at(attribute);
1684}
1685
Dan Stoza076ac672016-03-14 10:47:53 -07001686void HWC2On1Adapter::Display::Config::setHwc1Id(uint32_t id)
1687{
Michael Wright28f24d02016-07-12 13:30:53 -07001688 android_color_mode_t colorMode = static_cast<android_color_mode_t>(getAttribute(ColorMode));
1689 mHwc1Ids.emplace(colorMode, id);
Dan Stoza076ac672016-03-14 10:47:53 -07001690}
1691
1692bool HWC2On1Adapter::Display::Config::hasHwc1Id(uint32_t id) const
1693{
1694 for (const auto& idPair : mHwc1Ids) {
1695 if (id == idPair.second) {
1696 return true;
1697 }
1698 }
1699 return false;
1700}
1701
Michael Wright28f24d02016-07-12 13:30:53 -07001702Error HWC2On1Adapter::Display::Config::getColorModeForHwc1Id(
1703 uint32_t id, android_color_mode_t* outMode) const
Dan Stoza076ac672016-03-14 10:47:53 -07001704{
1705 for (const auto& idPair : mHwc1Ids) {
1706 if (id == idPair.second) {
Michael Wright28f24d02016-07-12 13:30:53 -07001707 *outMode = idPair.first;
1708 return Error::None;
Dan Stoza076ac672016-03-14 10:47:53 -07001709 }
1710 }
Michael Wright28f24d02016-07-12 13:30:53 -07001711 ALOGE("Unable to find color mode for HWC ID %" PRIu32 " on config %u", id, mId);
1712 return Error::BadParameter;
Dan Stoza076ac672016-03-14 10:47:53 -07001713}
1714
Michael Wright28f24d02016-07-12 13:30:53 -07001715Error HWC2On1Adapter::Display::Config::getHwc1IdForColorMode(android_color_mode_t mode,
Dan Stoza076ac672016-03-14 10:47:53 -07001716 uint32_t* outId) const
1717{
1718 for (const auto& idPair : mHwc1Ids) {
1719 if (mode == idPair.first) {
1720 *outId = idPair.second;
1721 return Error::None;
1722 }
1723 }
1724 ALOGE("Unable to find HWC1 ID for color mode %d on config %u", mode, mId);
1725 return Error::BadParameter;
1726}
1727
1728bool HWC2On1Adapter::Display::Config::merge(const Config& other)
1729{
1730 auto attributes = {HWC2::Attribute::Width, HWC2::Attribute::Height,
1731 HWC2::Attribute::VsyncPeriod, HWC2::Attribute::DpiX,
1732 HWC2::Attribute::DpiY};
1733 for (auto attribute : attributes) {
1734 if (getAttribute(attribute) != other.getAttribute(attribute)) {
1735 return false;
1736 }
1737 }
Michael Wright28f24d02016-07-12 13:30:53 -07001738 android_color_mode_t otherColorMode =
1739 static_cast<android_color_mode_t>(other.getAttribute(ColorMode));
1740 if (mHwc1Ids.count(otherColorMode) != 0) {
Dan Stoza076ac672016-03-14 10:47:53 -07001741 ALOGE("Attempted to merge two configs (%u and %u) which appear to be "
Michael Wright28f24d02016-07-12 13:30:53 -07001742 "identical", mHwc1Ids.at(otherColorMode),
1743 other.mHwc1Ids.at(otherColorMode));
Dan Stoza076ac672016-03-14 10:47:53 -07001744 return false;
1745 }
Michael Wright28f24d02016-07-12 13:30:53 -07001746 mHwc1Ids.emplace(otherColorMode,
1747 other.mHwc1Ids.at(otherColorMode));
Dan Stoza076ac672016-03-14 10:47:53 -07001748 return true;
1749}
1750
Michael Wright28f24d02016-07-12 13:30:53 -07001751std::set<android_color_mode_t> HWC2On1Adapter::Display::Config::getColorModes() const
Dan Stoza076ac672016-03-14 10:47:53 -07001752{
Michael Wright28f24d02016-07-12 13:30:53 -07001753 std::set<android_color_mode_t> colorModes;
Dan Stoza076ac672016-03-14 10:47:53 -07001754 for (const auto& idPair : mHwc1Ids) {
Michael Wright28f24d02016-07-12 13:30:53 -07001755 colorModes.emplace(idPair.first);
Dan Stoza076ac672016-03-14 10:47:53 -07001756 }
Michael Wright28f24d02016-07-12 13:30:53 -07001757 return colorModes;
Dan Stoza076ac672016-03-14 10:47:53 -07001758}
1759
1760std::string HWC2On1Adapter::Display::Config::toString(bool splitLine) const
Dan Stozac6998d22015-09-24 17:03:36 -07001761{
1762 std::string output;
1763
1764 const size_t BUFFER_SIZE = 100;
1765 char buffer[BUFFER_SIZE] = {};
1766 auto writtenBytes = snprintf(buffer, BUFFER_SIZE,
Dan Stoza076ac672016-03-14 10:47:53 -07001767 "%u x %u", mAttributes.at(HWC2::Attribute::Width),
Dan Stozac6998d22015-09-24 17:03:36 -07001768 mAttributes.at(HWC2::Attribute::Height));
1769 output.append(buffer, writtenBytes);
1770
1771 if (mAttributes.count(HWC2::Attribute::VsyncPeriod) != 0) {
1772 std::memset(buffer, 0, BUFFER_SIZE);
1773 writtenBytes = snprintf(buffer, BUFFER_SIZE, " @ %.1f Hz",
1774 1e9 / mAttributes.at(HWC2::Attribute::VsyncPeriod));
1775 output.append(buffer, writtenBytes);
1776 }
1777
1778 if (mAttributes.count(HWC2::Attribute::DpiX) != 0 &&
1779 mAttributes.at(HWC2::Attribute::DpiX) != -1) {
1780 std::memset(buffer, 0, BUFFER_SIZE);
1781 writtenBytes = snprintf(buffer, BUFFER_SIZE,
1782 ", DPI: %.1f x %.1f",
1783 mAttributes.at(HWC2::Attribute::DpiX) / 1000.0f,
1784 mAttributes.at(HWC2::Attribute::DpiY) / 1000.0f);
1785 output.append(buffer, writtenBytes);
1786 }
1787
Dan Stoza076ac672016-03-14 10:47:53 -07001788 std::memset(buffer, 0, BUFFER_SIZE);
1789 if (splitLine) {
1790 writtenBytes = snprintf(buffer, BUFFER_SIZE,
1791 "\n HWC1 ID/Color transform:");
1792 } else {
1793 writtenBytes = snprintf(buffer, BUFFER_SIZE,
1794 ", HWC1 ID/Color transform:");
1795 }
1796 output.append(buffer, writtenBytes);
1797
1798
1799 for (const auto& id : mHwc1Ids) {
Michael Wright28f24d02016-07-12 13:30:53 -07001800 android_color_mode_t colorMode = id.first;
Dan Stoza076ac672016-03-14 10:47:53 -07001801 uint32_t hwc1Id = id.second;
1802 std::memset(buffer, 0, BUFFER_SIZE);
Michael Wright28f24d02016-07-12 13:30:53 -07001803 if (colorMode == mDisplay.mActiveColorMode) {
Dan Stoza076ac672016-03-14 10:47:53 -07001804 writtenBytes = snprintf(buffer, BUFFER_SIZE, " [%u/%d]", hwc1Id,
Michael Wright28f24d02016-07-12 13:30:53 -07001805 colorMode);
Dan Stoza076ac672016-03-14 10:47:53 -07001806 } else {
1807 writtenBytes = snprintf(buffer, BUFFER_SIZE, " %u/%d", hwc1Id,
Michael Wright28f24d02016-07-12 13:30:53 -07001808 colorMode);
Dan Stoza076ac672016-03-14 10:47:53 -07001809 }
1810 output.append(buffer, writtenBytes);
1811 }
1812
Dan Stozac6998d22015-09-24 17:03:36 -07001813 return output;
1814}
1815
1816std::shared_ptr<const HWC2On1Adapter::Display::Config>
1817 HWC2On1Adapter::Display::getConfig(hwc2_config_t configId) const
1818{
1819 if (configId > mConfigs.size() || !mConfigs[configId]->isOnDisplay(*this)) {
1820 return nullptr;
1821 }
1822 return mConfigs[configId];
1823}
1824
Dan Stoza076ac672016-03-14 10:47:53 -07001825void HWC2On1Adapter::Display::populateColorModes()
1826{
Michael Wright28f24d02016-07-12 13:30:53 -07001827 mColorModes = mConfigs[0]->getColorModes();
Dan Stoza076ac672016-03-14 10:47:53 -07001828 for (const auto& config : mConfigs) {
Michael Wright28f24d02016-07-12 13:30:53 -07001829 std::set<android_color_mode_t> intersection;
1830 auto configModes = config->getColorModes();
Dan Stoza076ac672016-03-14 10:47:53 -07001831 std::set_intersection(mColorModes.cbegin(), mColorModes.cend(),
1832 configModes.cbegin(), configModes.cend(),
1833 std::inserter(intersection, intersection.begin()));
1834 std::swap(intersection, mColorModes);
1835 }
1836}
1837
1838void HWC2On1Adapter::Display::initializeActiveConfig()
1839{
1840 if (mDevice.mHwc1Device->getActiveConfig == nullptr) {
1841 ALOGV("getActiveConfig is null, choosing config 0");
1842 mActiveConfig = mConfigs[0];
Michael Wright28f24d02016-07-12 13:30:53 -07001843 mActiveColorMode = HAL_COLOR_MODE_NATIVE;
Dan Stoza076ac672016-03-14 10:47:53 -07001844 return;
1845 }
1846
1847 auto activeConfig = mDevice.mHwc1Device->getActiveConfig(
1848 mDevice.mHwc1Device, mHwc1Id);
Fabien Sanglardb7432cc2016-11-11 09:40:27 -08001849
1850 // Some devices startup without an activeConfig:
1851 // We need to set one ourselves.
1852 if (activeConfig == HWC_ERROR) {
1853 ALOGV("There is no active configuration: Picking the first one: 0.");
1854 const int defaultIndex = 0;
1855 mDevice.mHwc1Device->setActiveConfig(mDevice.mHwc1Device, mHwc1Id, defaultIndex);
1856 activeConfig = defaultIndex;
1857 }
1858
1859 for (const auto& config : mConfigs) {
1860 if (config->hasHwc1Id(activeConfig)) {
1861 ALOGE("Setting active config to %d for HWC1 config %u", config->getId(), activeConfig);
1862 mActiveConfig = config;
1863 if (config->getColorModeForHwc1Id(activeConfig, &mActiveColorMode) != Error::None) {
1864 // This should never happen since we checked for the config's presence before
1865 // setting it as active.
1866 ALOGE("Unable to find color mode for active HWC1 config %d", config->getId());
1867 mActiveColorMode = HAL_COLOR_MODE_NATIVE;
Dan Stoza076ac672016-03-14 10:47:53 -07001868 }
Fabien Sanglardb7432cc2016-11-11 09:40:27 -08001869 break;
Dan Stoza076ac672016-03-14 10:47:53 -07001870 }
1871 }
Fabien Sanglardb7432cc2016-11-11 09:40:27 -08001872 if (!mActiveConfig) {
1873 ALOGV("Unable to find active HWC1 config %u, defaulting to "
1874 "config 0", activeConfig);
1875 mActiveConfig = mConfigs[0];
1876 mActiveColorMode = HAL_COLOR_MODE_NATIVE;
1877 }
1878
1879
1880
1881
Dan Stoza076ac672016-03-14 10:47:53 -07001882}
1883
Dan Stozac6998d22015-09-24 17:03:36 -07001884void HWC2On1Adapter::Display::reallocateHwc1Contents()
1885{
1886 // Allocate an additional layer for the framebuffer target
1887 auto numLayers = mLayers.size() + 1;
1888 size_t size = sizeof(hwc_display_contents_1_t) +
1889 sizeof(hwc_layer_1_t) * numLayers;
1890 ALOGV("[%" PRIu64 "] reallocateHwc1Contents creating %zd layer%s", mId,
1891 numLayers, numLayers != 1 ? "s" : "");
1892 auto contents =
1893 static_cast<hwc_display_contents_1_t*>(std::calloc(size, 1));
1894 contents->numHwLayers = numLayers;
1895 mHwc1RequestedContents.reset(contents);
1896}
1897
1898void HWC2On1Adapter::Display::assignHwc1LayerIds()
1899{
1900 mHwc1LayerMap.clear();
1901 size_t nextHwc1Id = 0;
1902 for (auto& layer : mLayers) {
1903 mHwc1LayerMap[nextHwc1Id] = layer;
1904 layer->setHwc1Id(nextHwc1Id++);
1905 }
1906}
1907
1908void HWC2On1Adapter::Display::updateTypeChanges(const hwc_layer_1_t& hwc1Layer,
1909 const Layer& layer)
1910{
1911 auto layerId = layer.getId();
1912 switch (hwc1Layer.compositionType) {
1913 case HWC_FRAMEBUFFER:
1914 if (layer.getCompositionType() != Composition::Client) {
1915 mChanges->addTypeChange(layerId, Composition::Client);
1916 }
1917 break;
1918 case HWC_OVERLAY:
1919 if (layer.getCompositionType() != Composition::Device) {
1920 mChanges->addTypeChange(layerId, Composition::Device);
1921 }
1922 break;
1923 case HWC_BACKGROUND:
1924 ALOGE_IF(layer.getCompositionType() != Composition::SolidColor,
1925 "updateTypeChanges: HWC1 requested BACKGROUND, but HWC2"
1926 " wasn't expecting SolidColor");
1927 break;
1928 case HWC_FRAMEBUFFER_TARGET:
1929 // Do nothing, since it shouldn't be modified by HWC1
1930 break;
1931 case HWC_SIDEBAND:
1932 ALOGE_IF(layer.getCompositionType() != Composition::Sideband,
1933 "updateTypeChanges: HWC1 requested SIDEBAND, but HWC2"
1934 " wasn't expecting Sideband");
1935 break;
1936 case HWC_CURSOR_OVERLAY:
1937 ALOGE_IF(layer.getCompositionType() != Composition::Cursor,
1938 "updateTypeChanges: HWC1 requested CURSOR_OVERLAY, but"
1939 " HWC2 wasn't expecting Cursor");
1940 break;
1941 }
1942}
1943
1944void HWC2On1Adapter::Display::updateLayerRequests(
1945 const hwc_layer_1_t& hwc1Layer, const Layer& layer)
1946{
1947 if ((hwc1Layer.hints & HWC_HINT_CLEAR_FB) != 0) {
1948 mChanges->addLayerRequest(layer.getId(),
1949 LayerRequest::ClearClientTarget);
1950 }
1951}
1952
1953void HWC2On1Adapter::Display::prepareFramebufferTarget()
1954{
1955 // We check that mActiveConfig is valid in Display::prepare
1956 int32_t width = mActiveConfig->getAttribute(Attribute::Width);
1957 int32_t height = mActiveConfig->getAttribute(Attribute::Height);
1958
1959 auto& hwc1Target = mHwc1RequestedContents->hwLayers[mLayers.size()];
1960 hwc1Target.compositionType = HWC_FRAMEBUFFER_TARGET;
1961 hwc1Target.releaseFenceFd = -1;
1962 hwc1Target.hints = 0;
1963 hwc1Target.flags = 0;
1964 hwc1Target.transform = 0;
1965 hwc1Target.blending = HWC_BLENDING_PREMULT;
1966 if (mDevice.getHwc1MinorVersion() < 3) {
1967 hwc1Target.sourceCropi = {0, 0, width, height};
1968 } else {
1969 hwc1Target.sourceCropf = {0.0f, 0.0f, static_cast<float>(width),
1970 static_cast<float>(height)};
1971 }
1972 hwc1Target.displayFrame = {0, 0, width, height};
1973 hwc1Target.planeAlpha = 255;
1974 hwc1Target.visibleRegionScreen.numRects = 1;
1975 auto rects = static_cast<hwc_rect_t*>(std::malloc(sizeof(hwc_rect_t)));
1976 rects[0].left = 0;
1977 rects[0].top = 0;
1978 rects[0].right = width;
1979 rects[0].bottom = height;
1980 hwc1Target.visibleRegionScreen.rects = rects;
1981
1982 // We will set this to the correct value in set
1983 hwc1Target.acquireFenceFd = -1;
1984}
1985
1986// Layer functions
1987
1988std::atomic<hwc2_layer_t> HWC2On1Adapter::Layer::sNextId(1);
1989
1990HWC2On1Adapter::Layer::Layer(Display& display)
1991 : mId(sNextId++),
1992 mDisplay(display),
Dan Stozafc4e2022016-02-23 11:43:19 -08001993 mDirtyCount(0),
1994 mBuffer(),
1995 mSurfaceDamage(),
Dan Stozac6998d22015-09-24 17:03:36 -07001996 mBlendMode(*this, BlendMode::None),
1997 mColor(*this, {0, 0, 0, 0}),
1998 mCompositionType(*this, Composition::Invalid),
1999 mDisplayFrame(*this, {0, 0, -1, -1}),
2000 mPlaneAlpha(*this, 0.0f),
2001 mSidebandStream(*this, nullptr),
2002 mSourceCrop(*this, {0.0f, 0.0f, -1.0f, -1.0f}),
2003 mTransform(*this, Transform::None),
2004 mVisibleRegion(*this, std::vector<hwc_rect_t>()),
2005 mZ(0),
Dan Stozafc4e2022016-02-23 11:43:19 -08002006 mReleaseFence(),
Dan Stozac6998d22015-09-24 17:03:36 -07002007 mHwc1Id(0),
Dan Stoza5df2a862016-03-24 16:19:37 -07002008 mHasUnsupportedDataspace(false),
Dan Stozac6998d22015-09-24 17:03:36 -07002009 mHasUnsupportedPlaneAlpha(false) {}
2010
2011bool HWC2On1Adapter::SortLayersByZ::operator()(
2012 const std::shared_ptr<Layer>& lhs, const std::shared_ptr<Layer>& rhs)
2013{
2014 return lhs->getZ() < rhs->getZ();
2015}
2016
2017Error HWC2On1Adapter::Layer::setBuffer(buffer_handle_t buffer,
2018 int32_t acquireFence)
2019{
2020 ALOGV("Setting acquireFence to %d for layer %" PRIu64, acquireFence, mId);
2021 mBuffer.setBuffer(buffer);
2022 mBuffer.setFence(acquireFence);
2023 return Error::None;
2024}
2025
2026Error HWC2On1Adapter::Layer::setCursorPosition(int32_t x, int32_t y)
2027{
2028 if (mCompositionType.getValue() != Composition::Cursor) {
2029 return Error::BadLayer;
2030 }
2031
2032 if (mDisplay.hasChanges()) {
2033 return Error::NotValidated;
2034 }
2035
2036 auto displayId = mDisplay.getHwc1Id();
2037 auto hwc1Device = mDisplay.getDevice().getHwc1Device();
2038 hwc1Device->setCursorPositionAsync(hwc1Device, displayId, x, y);
2039 return Error::None;
2040}
2041
2042Error HWC2On1Adapter::Layer::setSurfaceDamage(hwc_region_t damage)
2043{
2044 mSurfaceDamage.resize(damage.numRects);
2045 std::copy_n(damage.rects, damage.numRects, mSurfaceDamage.begin());
2046 return Error::None;
2047}
2048
2049// Layer state functions
2050
2051Error HWC2On1Adapter::Layer::setBlendMode(BlendMode mode)
2052{
2053 mBlendMode.setPending(mode);
2054 return Error::None;
2055}
2056
2057Error HWC2On1Adapter::Layer::setColor(hwc_color_t color)
2058{
2059 mColor.setPending(color);
2060 return Error::None;
2061}
2062
2063Error HWC2On1Adapter::Layer::setCompositionType(Composition type)
2064{
2065 mCompositionType.setPending(type);
2066 return Error::None;
2067}
2068
Dan Stoza5df2a862016-03-24 16:19:37 -07002069Error HWC2On1Adapter::Layer::setDataspace(android_dataspace_t dataspace)
2070{
2071 mHasUnsupportedDataspace = (dataspace != HAL_DATASPACE_UNKNOWN);
2072 return Error::None;
2073}
2074
Dan Stozac6998d22015-09-24 17:03:36 -07002075Error HWC2On1Adapter::Layer::setDisplayFrame(hwc_rect_t frame)
2076{
2077 mDisplayFrame.setPending(frame);
2078 return Error::None;
2079}
2080
2081Error HWC2On1Adapter::Layer::setPlaneAlpha(float alpha)
2082{
2083 mPlaneAlpha.setPending(alpha);
2084 return Error::None;
2085}
2086
2087Error HWC2On1Adapter::Layer::setSidebandStream(const native_handle_t* stream)
2088{
2089 mSidebandStream.setPending(stream);
2090 return Error::None;
2091}
2092
2093Error HWC2On1Adapter::Layer::setSourceCrop(hwc_frect_t crop)
2094{
2095 mSourceCrop.setPending(crop);
2096 return Error::None;
2097}
2098
2099Error HWC2On1Adapter::Layer::setTransform(Transform transform)
2100{
2101 mTransform.setPending(transform);
2102 return Error::None;
2103}
2104
2105Error HWC2On1Adapter::Layer::setVisibleRegion(hwc_region_t rawVisible)
2106{
2107 std::vector<hwc_rect_t> visible(rawVisible.rects,
2108 rawVisible.rects + rawVisible.numRects);
2109 mVisibleRegion.setPending(std::move(visible));
2110 return Error::None;
2111}
2112
2113Error HWC2On1Adapter::Layer::setZ(uint32_t z)
2114{
2115 mZ = z;
2116 return Error::None;
2117}
2118
2119void HWC2On1Adapter::Layer::addReleaseFence(int fenceFd)
2120{
2121 ALOGV("addReleaseFence %d to layer %" PRIu64, fenceFd, mId);
2122 mReleaseFence.add(fenceFd);
2123}
2124
2125const sp<Fence>& HWC2On1Adapter::Layer::getReleaseFence() const
2126{
2127 return mReleaseFence.get();
2128}
2129
2130void HWC2On1Adapter::Layer::applyState(hwc_layer_1_t& hwc1Layer,
2131 bool applyAllState)
2132{
2133 applyCommonState(hwc1Layer, applyAllState);
2134 auto compositionType = mCompositionType.getPendingValue();
2135 if (compositionType == Composition::SolidColor) {
2136 applySolidColorState(hwc1Layer, applyAllState);
2137 } else if (compositionType == Composition::Sideband) {
2138 applySidebandState(hwc1Layer, applyAllState);
2139 } else {
2140 applyBufferState(hwc1Layer);
2141 }
2142 applyCompositionType(hwc1Layer, applyAllState);
2143}
2144
2145// Layer dump helpers
2146
2147static std::string regionStrings(const std::vector<hwc_rect_t>& visibleRegion,
2148 const std::vector<hwc_rect_t>& surfaceDamage)
2149{
2150 std::string regions;
2151 regions += " Visible Region";
2152 regions.resize(40, ' ');
2153 regions += "Surface Damage\n";
2154
2155 size_t numPrinted = 0;
2156 size_t maxSize = std::max(visibleRegion.size(), surfaceDamage.size());
2157 while (numPrinted < maxSize) {
2158 std::string line(" ");
2159 if (visibleRegion.empty() && numPrinted == 0) {
2160 line += "None";
2161 } else if (numPrinted < visibleRegion.size()) {
2162 line += rectString(visibleRegion[numPrinted]);
2163 }
2164 line.resize(40, ' ');
2165 if (surfaceDamage.empty() && numPrinted == 0) {
2166 line += "None";
2167 } else if (numPrinted < surfaceDamage.size()) {
2168 line += rectString(surfaceDamage[numPrinted]);
2169 }
2170 line += '\n';
2171 regions += line;
2172 ++numPrinted;
2173 }
2174 return regions;
2175}
2176
2177std::string HWC2On1Adapter::Layer::dump() const
2178{
2179 std::stringstream output;
2180 const char* fill = " ";
2181
2182 output << fill << to_string(mCompositionType.getPendingValue());
2183 output << " Layer HWC2/1: " << mId << "/" << mHwc1Id << " ";
2184 output << "Z: " << mZ;
2185 if (mCompositionType.getValue() == HWC2::Composition::SolidColor) {
2186 output << " " << colorString(mColor.getValue());
2187 } else if (mCompositionType.getValue() == HWC2::Composition::Sideband) {
2188 output << " Handle: " << mSidebandStream.getValue() << '\n';
2189 } else {
2190 output << " Buffer: " << mBuffer.getBuffer() << "/" <<
2191 mBuffer.getFence() << '\n';
2192 output << fill << " Display frame [LTRB]: " <<
2193 rectString(mDisplayFrame.getValue()) << '\n';
2194 output << fill << " Source crop: " <<
2195 frectString(mSourceCrop.getValue()) << '\n';
2196 output << fill << " Transform: " << to_string(mTransform.getValue());
2197 output << " Blend mode: " << to_string(mBlendMode.getValue());
2198 if (mPlaneAlpha.getValue() != 1.0f) {
2199 output << " Alpha: " <<
2200 alphaString(mPlaneAlpha.getValue()) << '\n';
2201 } else {
2202 output << '\n';
2203 }
2204 output << regionStrings(mVisibleRegion.getValue(), mSurfaceDamage);
2205 }
2206 return output.str();
2207}
2208
2209static int getHwc1Blending(HWC2::BlendMode blendMode)
2210{
2211 switch (blendMode) {
2212 case BlendMode::Coverage: return HWC_BLENDING_COVERAGE;
2213 case BlendMode::Premultiplied: return HWC_BLENDING_PREMULT;
2214 default: return HWC_BLENDING_NONE;
2215 }
2216}
2217
2218void HWC2On1Adapter::Layer::applyCommonState(hwc_layer_1_t& hwc1Layer,
2219 bool applyAllState)
2220{
2221 auto minorVersion = mDisplay.getDevice().getHwc1MinorVersion();
2222 if (applyAllState || mBlendMode.isDirty()) {
2223 hwc1Layer.blending = getHwc1Blending(mBlendMode.getPendingValue());
2224 mBlendMode.latch();
2225 }
2226 if (applyAllState || mDisplayFrame.isDirty()) {
2227 hwc1Layer.displayFrame = mDisplayFrame.getPendingValue();
2228 mDisplayFrame.latch();
2229 }
2230 if (applyAllState || mPlaneAlpha.isDirty()) {
2231 auto pendingAlpha = mPlaneAlpha.getPendingValue();
2232 if (minorVersion < 2) {
2233 mHasUnsupportedPlaneAlpha = pendingAlpha < 1.0f;
2234 } else {
2235 hwc1Layer.planeAlpha =
2236 static_cast<uint8_t>(255.0f * pendingAlpha + 0.5f);
2237 }
2238 mPlaneAlpha.latch();
2239 }
2240 if (applyAllState || mSourceCrop.isDirty()) {
2241 if (minorVersion < 3) {
2242 auto pending = mSourceCrop.getPendingValue();
2243 hwc1Layer.sourceCropi.left =
2244 static_cast<int32_t>(std::ceil(pending.left));
2245 hwc1Layer.sourceCropi.top =
2246 static_cast<int32_t>(std::ceil(pending.top));
2247 hwc1Layer.sourceCropi.right =
2248 static_cast<int32_t>(std::floor(pending.right));
2249 hwc1Layer.sourceCropi.bottom =
2250 static_cast<int32_t>(std::floor(pending.bottom));
2251 } else {
2252 hwc1Layer.sourceCropf = mSourceCrop.getPendingValue();
2253 }
2254 mSourceCrop.latch();
2255 }
2256 if (applyAllState || mTransform.isDirty()) {
2257 hwc1Layer.transform =
2258 static_cast<uint32_t>(mTransform.getPendingValue());
2259 mTransform.latch();
2260 }
2261 if (applyAllState || mVisibleRegion.isDirty()) {
2262 auto& hwc1VisibleRegion = hwc1Layer.visibleRegionScreen;
2263
2264 std::free(const_cast<hwc_rect_t*>(hwc1VisibleRegion.rects));
2265
2266 auto pending = mVisibleRegion.getPendingValue();
2267 hwc_rect_t* newRects = static_cast<hwc_rect_t*>(
2268 std::malloc(sizeof(hwc_rect_t) * pending.size()));
2269 std::copy(pending.begin(), pending.end(), newRects);
2270 hwc1VisibleRegion.rects = const_cast<const hwc_rect_t*>(newRects);
2271 hwc1VisibleRegion.numRects = pending.size();
2272 mVisibleRegion.latch();
2273 }
2274}
2275
2276void HWC2On1Adapter::Layer::applySolidColorState(hwc_layer_1_t& hwc1Layer,
2277 bool applyAllState)
2278{
2279 if (applyAllState || mColor.isDirty()) {
Fabien Sanglardeb3db612016-11-18 16:12:31 -08002280 // If the device does not support background color it is likely to make
2281 // assumption regarding backgroundColor and handle (both fields occupy
2282 // the same location in hwc_layer_1_t union).
2283 // To not confuse these devices we don't set background color and we
2284 // make sure handle is a null pointer.
2285 if (mDisplay.getDevice().supportsBackgroundColor()) {
2286 hwc1Layer.backgroundColor = mColor.getPendingValue();
2287 mHasUnsupportedBackgroundColor = false;
2288 } else {
2289 hwc1Layer.handle = nullptr;
2290 mHasUnsupportedBackgroundColor = true;
2291 }
Dan Stozac6998d22015-09-24 17:03:36 -07002292 mColor.latch();
2293 }
2294}
2295
2296void HWC2On1Adapter::Layer::applySidebandState(hwc_layer_1_t& hwc1Layer,
2297 bool applyAllState)
2298{
2299 if (applyAllState || mSidebandStream.isDirty()) {
2300 hwc1Layer.sidebandStream = mSidebandStream.getPendingValue();
2301 mSidebandStream.latch();
2302 }
2303}
2304
2305void HWC2On1Adapter::Layer::applyBufferState(hwc_layer_1_t& hwc1Layer)
2306{
2307 hwc1Layer.handle = mBuffer.getBuffer();
2308 hwc1Layer.acquireFenceFd = mBuffer.getFence();
2309}
2310
2311void HWC2On1Adapter::Layer::applyCompositionType(hwc_layer_1_t& hwc1Layer,
2312 bool applyAllState)
2313{
Dan Stoza5df2a862016-03-24 16:19:37 -07002314 // HWC1 never supports color transforms or dataspaces and only sometimes
2315 // supports plane alpha (depending on the version). These require us to drop
2316 // some or all layers to client composition.
2317 if (mHasUnsupportedDataspace || mHasUnsupportedPlaneAlpha ||
Fabien Sanglardeb3db612016-11-18 16:12:31 -08002318 mDisplay.hasColorTransform() || mHasUnsupportedBackgroundColor) {
Dan Stozac6998d22015-09-24 17:03:36 -07002319 hwc1Layer.compositionType = HWC_FRAMEBUFFER;
2320 hwc1Layer.flags = HWC_SKIP_LAYER;
2321 return;
2322 }
2323
2324 if (applyAllState || mCompositionType.isDirty()) {
2325 hwc1Layer.flags = 0;
2326 switch (mCompositionType.getPendingValue()) {
2327 case Composition::Client:
2328 hwc1Layer.compositionType = HWC_FRAMEBUFFER;
2329 hwc1Layer.flags |= HWC_SKIP_LAYER;
2330 break;
2331 case Composition::Device:
2332 hwc1Layer.compositionType = HWC_FRAMEBUFFER;
2333 break;
2334 case Composition::SolidColor:
Dan Stoza5df47cb2016-09-15 16:38:42 -07002335 // In theory the following line should work, but since the HWC1
2336 // version of SurfaceFlinger never used HWC_BACKGROUND, HWC1
2337 // devices may not work correctly. To be on the safe side, we
2338 // fall back to client composition.
2339 //
2340 // hwc1Layer.compositionType = HWC_BACKGROUND;
2341 hwc1Layer.compositionType = HWC_FRAMEBUFFER;
2342 hwc1Layer.flags |= HWC_SKIP_LAYER;
Dan Stozac6998d22015-09-24 17:03:36 -07002343 break;
2344 case Composition::Cursor:
2345 hwc1Layer.compositionType = HWC_FRAMEBUFFER;
2346 if (mDisplay.getDevice().getHwc1MinorVersion() >= 4) {
2347 hwc1Layer.hints |= HWC_IS_CURSOR_LAYER;
2348 }
2349 break;
2350 case Composition::Sideband:
2351 if (mDisplay.getDevice().getHwc1MinorVersion() < 4) {
2352 hwc1Layer.compositionType = HWC_SIDEBAND;
2353 } else {
2354 hwc1Layer.compositionType = HWC_FRAMEBUFFER;
2355 hwc1Layer.flags |= HWC_SKIP_LAYER;
2356 }
2357 break;
2358 default:
2359 hwc1Layer.compositionType = HWC_FRAMEBUFFER;
2360 hwc1Layer.flags |= HWC_SKIP_LAYER;
2361 break;
2362 }
2363 ALOGV("Layer %" PRIu64 " %s set to %d", mId,
2364 to_string(mCompositionType.getPendingValue()).c_str(),
2365 hwc1Layer.compositionType);
2366 ALOGV_IF(hwc1Layer.flags & HWC_SKIP_LAYER, " and skipping");
2367 mCompositionType.latch();
2368 }
2369}
2370
2371// Adapter helpers
2372
2373void HWC2On1Adapter::populateCapabilities()
2374{
2375 ALOGV("populateCapabilities");
2376 if (mHwc1MinorVersion >= 3U) {
2377 int supportedTypes = 0;
2378 auto result = mHwc1Device->query(mHwc1Device,
2379 HWC_DISPLAY_TYPES_SUPPORTED, &supportedTypes);
Fred Fettingerc50c01e2016-06-14 17:53:10 -05002380 if ((result == 0) && ((supportedTypes & HWC_DISPLAY_VIRTUAL_BIT) != 0)) {
Dan Stozac6998d22015-09-24 17:03:36 -07002381 ALOGI("Found support for HWC virtual displays");
2382 mHwc1SupportsVirtualDisplays = true;
2383 }
2384 }
2385 if (mHwc1MinorVersion >= 4U) {
2386 mCapabilities.insert(Capability::SidebandStream);
2387 }
Fabien Sanglardeb3db612016-11-18 16:12:31 -08002388
2389 // Check for HWC background color layer support.
2390 if (mHwc1MinorVersion >= 1U) {
2391 int backgroundColorSupported = 0;
2392 auto result = mHwc1Device->query(mHwc1Device,
2393 HWC_BACKGROUND_LAYER_SUPPORTED,
2394 &backgroundColorSupported);
2395 if ((result == 0) && (backgroundColorSupported == 1)) {
2396 ALOGV("Found support for HWC background color");
2397 mHwc1SupportsBackgroundColor = true;
2398 }
2399 }
Dan Stozac6998d22015-09-24 17:03:36 -07002400}
2401
2402HWC2On1Adapter::Display* HWC2On1Adapter::getDisplay(hwc2_display_t id)
2403{
Dan Stozafc4e2022016-02-23 11:43:19 -08002404 std::unique_lock<std::recursive_timed_mutex> lock(mStateMutex);
Dan Stozac6998d22015-09-24 17:03:36 -07002405
2406 auto display = mDisplays.find(id);
2407 if (display == mDisplays.end()) {
2408 return nullptr;
2409 }
2410
2411 return display->second.get();
2412}
2413
2414std::tuple<HWC2On1Adapter::Layer*, Error> HWC2On1Adapter::getLayer(
2415 hwc2_display_t displayId, hwc2_layer_t layerId)
2416{
2417 auto display = getDisplay(displayId);
2418 if (!display) {
2419 return std::make_tuple(static_cast<Layer*>(nullptr), Error::BadDisplay);
2420 }
2421
2422 auto layerEntry = mLayers.find(layerId);
2423 if (layerEntry == mLayers.end()) {
2424 return std::make_tuple(static_cast<Layer*>(nullptr), Error::BadLayer);
2425 }
2426
2427 auto layer = layerEntry->second;
2428 if (layer->getDisplay().getId() != displayId) {
2429 return std::make_tuple(static_cast<Layer*>(nullptr), Error::BadLayer);
2430 }
2431 return std::make_tuple(layer.get(), Error::None);
2432}
2433
2434void HWC2On1Adapter::populatePrimary()
2435{
2436 ALOGV("populatePrimary");
2437
Dan Stozafc4e2022016-02-23 11:43:19 -08002438 std::unique_lock<std::recursive_timed_mutex> lock(mStateMutex);
Dan Stozac6998d22015-09-24 17:03:36 -07002439
2440 auto display =
2441 std::make_shared<Display>(*this, HWC2::DisplayType::Physical);
2442 mHwc1DisplayMap[HWC_DISPLAY_PRIMARY] = display->getId();
2443 display->setHwc1Id(HWC_DISPLAY_PRIMARY);
2444 display->populateConfigs();
2445 mDisplays.emplace(display->getId(), std::move(display));
2446}
2447
2448bool HWC2On1Adapter::prepareAllDisplays()
2449{
2450 ATRACE_CALL();
2451
Dan Stozafc4e2022016-02-23 11:43:19 -08002452 std::unique_lock<std::recursive_timed_mutex> lock(mStateMutex);
Dan Stozac6998d22015-09-24 17:03:36 -07002453
2454 for (const auto& displayPair : mDisplays) {
2455 auto& display = displayPair.second;
2456 if (!display->prepare()) {
2457 return false;
2458 }
2459 }
2460
2461 if (mHwc1DisplayMap.count(0) == 0) {
2462 ALOGE("prepareAllDisplays: Unable to find primary HWC1 display");
2463 return false;
2464 }
2465
2466 // Always push the primary display
2467 std::vector<HWC2On1Adapter::Display::HWC1Contents> requestedContents;
2468 auto primaryDisplayId = mHwc1DisplayMap[HWC_DISPLAY_PRIMARY];
2469 auto& primaryDisplay = mDisplays[primaryDisplayId];
2470 auto primaryDisplayContents = primaryDisplay->cloneRequestedContents();
2471 requestedContents.push_back(std::move(primaryDisplayContents));
2472
2473 // Push the external display, if present
2474 if (mHwc1DisplayMap.count(HWC_DISPLAY_EXTERNAL) != 0) {
2475 auto externalDisplayId = mHwc1DisplayMap[HWC_DISPLAY_EXTERNAL];
2476 auto& externalDisplay = mDisplays[externalDisplayId];
2477 auto externalDisplayContents =
2478 externalDisplay->cloneRequestedContents();
2479 requestedContents.push_back(std::move(externalDisplayContents));
2480 } else {
2481 // Even if an external display isn't present, we still need to send
2482 // at least two displays down to HWC1
2483 requestedContents.push_back(nullptr);
2484 }
2485
2486 // Push the hardware virtual display, if supported and present
2487 if (mHwc1MinorVersion >= 3) {
2488 if (mHwc1DisplayMap.count(HWC_DISPLAY_VIRTUAL) != 0) {
2489 auto virtualDisplayId = mHwc1DisplayMap[HWC_DISPLAY_VIRTUAL];
2490 auto& virtualDisplay = mDisplays[virtualDisplayId];
2491 auto virtualDisplayContents =
2492 virtualDisplay->cloneRequestedContents();
2493 requestedContents.push_back(std::move(virtualDisplayContents));
2494 } else {
2495 requestedContents.push_back(nullptr);
2496 }
2497 }
2498
2499 mHwc1Contents.clear();
2500 for (auto& displayContents : requestedContents) {
2501 mHwc1Contents.push_back(displayContents.get());
2502 if (!displayContents) {
2503 continue;
2504 }
2505
2506 ALOGV("Display %zd layers:", mHwc1Contents.size() - 1);
2507 for (size_t l = 0; l < displayContents->numHwLayers; ++l) {
2508 auto& layer = displayContents->hwLayers[l];
2509 ALOGV(" %zd: %d", l, layer.compositionType);
2510 }
2511 }
2512
2513 ALOGV("Calling HWC1 prepare");
2514 {
2515 ATRACE_NAME("HWC1 prepare");
2516 mHwc1Device->prepare(mHwc1Device, mHwc1Contents.size(),
2517 mHwc1Contents.data());
2518 }
2519
2520 for (size_t c = 0; c < mHwc1Contents.size(); ++c) {
2521 auto& contents = mHwc1Contents[c];
2522 if (!contents) {
2523 continue;
2524 }
2525 ALOGV("Display %zd layers:", c);
2526 for (size_t l = 0; l < contents->numHwLayers; ++l) {
2527 ALOGV(" %zd: %d", l, contents->hwLayers[l].compositionType);
2528 }
2529 }
2530
2531 // Return the received contents to their respective displays
2532 for (size_t hwc1Id = 0; hwc1Id < mHwc1Contents.size(); ++hwc1Id) {
2533 if (mHwc1Contents[hwc1Id] == nullptr) {
2534 continue;
2535 }
2536
2537 auto displayId = mHwc1DisplayMap[hwc1Id];
2538 auto& display = mDisplays[displayId];
2539 display->setReceivedContents(std::move(requestedContents[hwc1Id]));
2540 }
2541
2542 return true;
2543}
2544
2545Error HWC2On1Adapter::setAllDisplays()
2546{
2547 ATRACE_CALL();
2548
Dan Stozafc4e2022016-02-23 11:43:19 -08002549 std::unique_lock<std::recursive_timed_mutex> lock(mStateMutex);
Dan Stozac6998d22015-09-24 17:03:36 -07002550
2551 // Make sure we're ready to validate
2552 for (size_t hwc1Id = 0; hwc1Id < mHwc1Contents.size(); ++hwc1Id) {
2553 if (mHwc1Contents[hwc1Id] == nullptr) {
2554 continue;
2555 }
2556
2557 auto displayId = mHwc1DisplayMap[hwc1Id];
2558 auto& display = mDisplays[displayId];
2559 Error error = display->set(*mHwc1Contents[hwc1Id]);
2560 if (error != Error::None) {
2561 ALOGE("setAllDisplays: Failed to set display %zd: %s", hwc1Id,
2562 to_string(error).c_str());
2563 return error;
2564 }
2565 }
2566
2567 ALOGV("Calling HWC1 set");
2568 {
2569 ATRACE_NAME("HWC1 set");
2570 mHwc1Device->set(mHwc1Device, mHwc1Contents.size(),
2571 mHwc1Contents.data());
2572 }
2573
2574 // Add retire and release fences
2575 for (size_t hwc1Id = 0; hwc1Id < mHwc1Contents.size(); ++hwc1Id) {
2576 if (mHwc1Contents[hwc1Id] == nullptr) {
2577 continue;
2578 }
2579
2580 auto displayId = mHwc1DisplayMap[hwc1Id];
2581 auto& display = mDisplays[displayId];
2582 auto retireFenceFd = mHwc1Contents[hwc1Id]->retireFenceFd;
2583 ALOGV("setAllDisplays: Adding retire fence %d to display %zd",
2584 retireFenceFd, hwc1Id);
2585 display->addRetireFence(mHwc1Contents[hwc1Id]->retireFenceFd);
2586 display->addReleaseFences(*mHwc1Contents[hwc1Id]);
2587 }
2588
2589 return Error::None;
2590}
2591
2592void HWC2On1Adapter::hwc1Invalidate()
2593{
2594 ALOGV("Received hwc1Invalidate");
2595
Dan Stozafc4e2022016-02-23 11:43:19 -08002596 std::unique_lock<std::recursive_timed_mutex> lock(mStateMutex);
Dan Stozac6998d22015-09-24 17:03:36 -07002597
2598 // If the HWC2-side callback hasn't been registered yet, buffer this until
2599 // it is registered
2600 if (mCallbacks.count(Callback::Refresh) == 0) {
2601 mHasPendingInvalidate = true;
2602 return;
2603 }
2604
2605 const auto& callbackInfo = mCallbacks[Callback::Refresh];
2606 std::vector<hwc2_display_t> displays;
2607 for (const auto& displayPair : mDisplays) {
2608 displays.emplace_back(displayPair.first);
2609 }
2610
2611 // Call back without the state lock held
2612 lock.unlock();
2613
2614 auto refresh = reinterpret_cast<HWC2_PFN_REFRESH>(callbackInfo.pointer);
2615 for (auto display : displays) {
2616 refresh(callbackInfo.data, display);
2617 }
2618}
2619
2620void HWC2On1Adapter::hwc1Vsync(int hwc1DisplayId, int64_t timestamp)
2621{
2622 ALOGV("Received hwc1Vsync(%d, %" PRId64 ")", hwc1DisplayId, timestamp);
2623
Dan Stozafc4e2022016-02-23 11:43:19 -08002624 std::unique_lock<std::recursive_timed_mutex> lock(mStateMutex);
Dan Stozac6998d22015-09-24 17:03:36 -07002625
2626 // If the HWC2-side callback hasn't been registered yet, buffer this until
2627 // it is registered
2628 if (mCallbacks.count(Callback::Vsync) == 0) {
2629 mPendingVsyncs.emplace_back(hwc1DisplayId, timestamp);
2630 return;
2631 }
2632
2633 if (mHwc1DisplayMap.count(hwc1DisplayId) == 0) {
2634 ALOGE("hwc1Vsync: Couldn't find display for HWC1 id %d", hwc1DisplayId);
2635 return;
2636 }
2637
2638 const auto& callbackInfo = mCallbacks[Callback::Vsync];
2639 auto displayId = mHwc1DisplayMap[hwc1DisplayId];
2640
2641 // Call back without the state lock held
2642 lock.unlock();
2643
2644 auto vsync = reinterpret_cast<HWC2_PFN_VSYNC>(callbackInfo.pointer);
2645 vsync(callbackInfo.data, displayId, timestamp);
2646}
2647
2648void HWC2On1Adapter::hwc1Hotplug(int hwc1DisplayId, int connected)
2649{
2650 ALOGV("Received hwc1Hotplug(%d, %d)", hwc1DisplayId, connected);
2651
2652 if (hwc1DisplayId != HWC_DISPLAY_EXTERNAL) {
2653 ALOGE("hwc1Hotplug: Received hotplug for non-external display");
2654 return;
2655 }
2656
Dan Stozafc4e2022016-02-23 11:43:19 -08002657 std::unique_lock<std::recursive_timed_mutex> lock(mStateMutex);
Dan Stozac6998d22015-09-24 17:03:36 -07002658
2659 // If the HWC2-side callback hasn't been registered yet, buffer this until
2660 // it is registered
2661 if (mCallbacks.count(Callback::Hotplug) == 0) {
2662 mPendingHotplugs.emplace_back(hwc1DisplayId, connected);
2663 return;
2664 }
2665
2666 hwc2_display_t displayId = UINT64_MAX;
2667 if (mHwc1DisplayMap.count(hwc1DisplayId) == 0) {
2668 if (connected == 0) {
2669 ALOGW("hwc1Hotplug: Received disconnect for unconnected display");
2670 return;
2671 }
2672
2673 // Create a new display on connect
2674 auto display = std::make_shared<HWC2On1Adapter::Display>(*this,
2675 HWC2::DisplayType::Physical);
2676 display->setHwc1Id(HWC_DISPLAY_EXTERNAL);
2677 display->populateConfigs();
2678 displayId = display->getId();
2679 mHwc1DisplayMap[HWC_DISPLAY_EXTERNAL] = displayId;
2680 mDisplays.emplace(displayId, std::move(display));
2681 } else {
2682 if (connected != 0) {
2683 ALOGW("hwc1Hotplug: Received connect for previously connected "
2684 "display");
2685 return;
2686 }
2687
2688 // Disconnect an existing display
2689 displayId = mHwc1DisplayMap[hwc1DisplayId];
2690 mHwc1DisplayMap.erase(HWC_DISPLAY_EXTERNAL);
2691 mDisplays.erase(displayId);
2692 }
2693
2694 const auto& callbackInfo = mCallbacks[Callback::Hotplug];
2695
2696 // Call back without the state lock held
2697 lock.unlock();
2698
2699 auto hotplug = reinterpret_cast<HWC2_PFN_HOTPLUG>(callbackInfo.pointer);
2700 auto hwc2Connected = (connected == 0) ?
2701 HWC2::Connection::Disconnected : HWC2::Connection::Connected;
2702 hotplug(callbackInfo.data, displayId, static_cast<int32_t>(hwc2Connected));
2703}
2704
2705} // namespace android