1 /*
2 * Copyright 2021, 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 #include "HalImpl.h"
18
19 #include <aidl/android/hardware/graphics/composer3/IComposerCallback.h>
20 #include <android-base/logging.h>
21 #include <hardware/hwcomposer2.h>
22
23 #include "ExynosDevice.h"
24 #include "ExynosDeviceModule.h"
25 #include "ExynosDisplay.h"
26 #include "ExynosHWCService.h"
27 #include "ExynosLayer.h"
28 #include "TranslateHwcAidl.h"
29 #include "Util.h"
30
31 using namespace SOC_VERSION;
32
33 namespace aidl::android::hardware::graphics::composer3::impl {
34
create()35 std::unique_ptr<IComposerHal> IComposerHal::create() {
36 auto device = std::make_unique<ExynosDeviceModule>();
37 if (!device) {
38 return nullptr;
39 }
40
41 return std::make_unique<HalImpl>(std::move(device));
42 }
43
44 namespace hook {
45
hotplug(hwc2_callback_data_t callbackData,hwc2_display_t hwcDisplay,int32_t connected)46 void hotplug(hwc2_callback_data_t callbackData, hwc2_display_t hwcDisplay,
47 int32_t connected) {
48 auto hal = static_cast<HalImpl*>(callbackData);
49 int64_t display;
50
51 h2a::translate(hwcDisplay, display);
52 hal->getEventCallback()->onHotplug(display, connected == HWC2_CONNECTION_CONNECTED);
53 }
54
refresh(hwc2_callback_data_t callbackData,hwc2_display_t hwcDisplay)55 void refresh(hwc2_callback_data_t callbackData, hwc2_display_t hwcDisplay) {
56 auto hal = static_cast<HalImpl*>(callbackData);
57 int64_t display;
58
59 h2a::translate(hwcDisplay, display);
60 hal->getEventCallback()->onRefresh(display);
61 }
62
vsync(hwc2_callback_data_t callbackData,hwc2_display_t hwcDisplay,int64_t timestamp,hwc2_vsync_period_t hwcVsyncPeriodNanos)63 void vsync(hwc2_callback_data_t callbackData, hwc2_display_t hwcDisplay,
64 int64_t timestamp, hwc2_vsync_period_t hwcVsyncPeriodNanos) {
65 auto hal = static_cast<HalImpl*>(callbackData);
66 int64_t display;
67 int32_t vsyncPeriodNanos;
68
69 h2a::translate(hwcDisplay, display);
70 h2a::translate(hwcVsyncPeriodNanos, vsyncPeriodNanos);
71 hal->getEventCallback()->onVsync(display, timestamp, vsyncPeriodNanos);
72 }
73
vsyncPeriodTimingChanged(hwc2_callback_data_t callbackData,hwc2_display_t hwcDisplay,hwc_vsync_period_change_timeline_t * hwcTimeline)74 void vsyncPeriodTimingChanged(hwc2_callback_data_t callbackData,
75 hwc2_display_t hwcDisplay,
76 hwc_vsync_period_change_timeline_t* hwcTimeline) {
77 auto hal = static_cast<HalImpl*>(callbackData);
78 int64_t display;
79 VsyncPeriodChangeTimeline timeline;
80
81 h2a::translate(hwcDisplay, display);
82 h2a::translate(*hwcTimeline, timeline);
83 hal->getEventCallback()->onVsyncPeriodTimingChanged(display, timeline);
84 }
85
vsyncIdle(hwc2_callback_data_t callbackData,hwc2_display_t hwcDisplay)86 void vsyncIdle(hwc2_callback_data_t callbackData, hwc2_display_t hwcDisplay) {
87 auto hal = static_cast<HalImpl*>(callbackData);
88 int64_t display;
89
90 h2a::translate(hwcDisplay, display);
91 hal->getEventCallback()->onVsyncIdle(display);
92 }
93
seamlessPossible(hwc2_callback_data_t callbackData,hwc2_display_t hwcDisplay)94 void seamlessPossible(hwc2_callback_data_t callbackData, hwc2_display_t hwcDisplay) {
95 auto hal = static_cast<HalImpl*>(callbackData);
96 int64_t display;
97
98 h2a::translate(hwcDisplay, display);
99 hal->getEventCallback()->onSeamlessPossible(display);
100 }
101
refreshRateChangedDebug(hwc2_callback_data_t callbackData,hwc2_display_t hwcDisplay,hwc2_vsync_period_t hwcVsyncPeriodNanos)102 void refreshRateChangedDebug(hwc2_callback_data_t callbackData, hwc2_display_t hwcDisplay,
103 hwc2_vsync_period_t hwcVsyncPeriodNanos) {
104 auto hal = static_cast<HalImpl*>(callbackData);
105 int64_t display;
106 int32_t vsyncPeriodNanos;
107
108 h2a::translate(hwcDisplay, display);
109 h2a::translate(hwcVsyncPeriodNanos, vsyncPeriodNanos);
110 hal->getEventCallback()->onRefreshRateChangedDebug(RefreshRateChangedDebugData{
111 .display = display,
112 .vsyncPeriodNanos = vsyncPeriodNanos,
113 });
114 }
115
116 } // nampesapce hook
117
HalImpl(std::unique_ptr<ExynosDevice> device)118 HalImpl::HalImpl(std::unique_ptr<ExynosDevice> device) : mDevice(std::move(device)) {
119 initCaps();
120 #ifdef USES_HWC_SERVICES
121 LOG(DEBUG) << "Start HWCService";
122 mHwcCtx = std::make_unique<ExynosHWCCtx>();
123 memset(&mHwcCtx->base, 0, sizeof(mHwcCtx->base));
124 mHwcCtx->device = mDevice.get();
125
126 auto hwcService = ::android::ExynosHWCService::getExynosHWCService();
127 hwcService->setExynosHWCCtx(mHwcCtx.get());
128 // This callback is for DP hotplug event if connected
129 // hwcService->setBootFinishedCallback(...);
130 #endif
131 }
132
initCaps()133 void HalImpl::initCaps() {
134 uint32_t count = 0;
135 mDevice->getCapabilities(&count, nullptr);
136
137 std::vector<int32_t> halCaps(count);
138 mDevice->getCapabilities(&count, halCaps.data());
139
140 for (auto hwcCap : halCaps) {
141 Capability cap;
142 h2a::translate(hwcCap, cap);
143 mCaps.insert(cap);
144 }
145
146 mCaps.insert(Capability::BOOT_DISPLAY_CONFIG);
147 mCaps.insert(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG);
148 }
149
getHalDisplay(int64_t display,ExynosDisplay * & halDisplay)150 int32_t HalImpl::getHalDisplay(int64_t display, ExynosDisplay*& halDisplay) {
151 hwc2_display_t hwcDisplay;
152 a2h::translate(display, hwcDisplay);
153 halDisplay = mDevice->getDisplay(static_cast<uint32_t>(hwcDisplay));
154
155 if (!halDisplay) { [[unlikely]]
156 return HWC2_ERROR_BAD_DISPLAY;
157 }
158 return HWC2_ERROR_NONE;
159 }
160
getHalLayer(int64_t display,int64_t layer,ExynosLayer * & halLayer)161 int32_t HalImpl::getHalLayer(int64_t display, int64_t layer, ExynosLayer*& halLayer) {
162 ExynosDisplay* halDisplay;
163 RET_IF_ERR(getHalDisplay(display, halDisplay));
164
165 hwc2_layer_t hwcLayer;
166 a2h::translate(layer, hwcLayer);
167 halLayer = halDisplay->checkLayer(hwcLayer);
168 if (!halLayer) { [[unlikely]]
169 return HWC2_ERROR_BAD_LAYER;
170 }
171
172 return HWC2_ERROR_NONE;
173 }
174
hasCapability(Capability cap)175 bool HalImpl::hasCapability(Capability cap) {
176 return mCaps.find(cap) != mCaps.end();
177 }
178
getCapabilities(std::vector<Capability> * caps)179 void HalImpl::getCapabilities(std::vector<Capability>* caps) {
180 caps->clear();
181 caps->insert(caps->begin(), mCaps.begin(), mCaps.end());
182 }
183
dumpDebugInfo(std::string * output)184 void HalImpl::dumpDebugInfo(std::string* output) {
185 if (output == nullptr) return;
186
187 String8 result;
188 mDevice->dump(result);
189
190 output->resize(result.size());
191 output->assign(result.c_str());
192 }
193
registerEventCallback(EventCallback * callback)194 void HalImpl::registerEventCallback(EventCallback* callback) {
195 mEventCallback = callback;
196
197 mDevice->registerCallback(HWC2_CALLBACK_HOTPLUG, this,
198 reinterpret_cast<hwc2_function_pointer_t>(hook::hotplug));
199 mDevice->registerCallback(HWC2_CALLBACK_REFRESH, this,
200 reinterpret_cast<hwc2_function_pointer_t>(hook::refresh));
201 mDevice->registerCallback(HWC2_CALLBACK_VSYNC_2_4, this,
202 reinterpret_cast<hwc2_function_pointer_t>(hook::vsync));
203 mDevice->registerCallback(HWC2_CALLBACK_VSYNC_PERIOD_TIMING_CHANGED, this,
204 reinterpret_cast<hwc2_function_pointer_t>(hook::vsyncPeriodTimingChanged));
205 mDevice->registerCallback(HWC2_CALLBACK_SEAMLESS_POSSIBLE, this,
206 reinterpret_cast<hwc2_function_pointer_t>(hook::seamlessPossible));
207
208 // register HWC3 Callback
209 mDevice->registerHwc3Callback(IComposerCallback::TRANSACTION_onVsyncIdle, this,
210 reinterpret_cast<hwc2_function_pointer_t>(hook::vsyncIdle));
211 mDevice->registerHwc3Callback(IComposerCallback::TRANSACTION_onRefreshRateChangedDebug, this,
212 reinterpret_cast<hwc2_function_pointer_t>(
213 hook::refreshRateChangedDebug));
214 }
215
unregisterEventCallback()216 void HalImpl::unregisterEventCallback() {
217 mDevice->registerCallback(HWC2_CALLBACK_HOTPLUG, this, nullptr);
218 mDevice->registerCallback(HWC2_CALLBACK_REFRESH, this, nullptr);
219 mDevice->registerCallback(HWC2_CALLBACK_VSYNC_2_4, this, nullptr);
220 mDevice->registerCallback(HWC2_CALLBACK_VSYNC_PERIOD_TIMING_CHANGED, this, nullptr);
221 mDevice->registerCallback(HWC2_CALLBACK_SEAMLESS_POSSIBLE, this, nullptr);
222
223 // unregister HWC3 Callback
224 mDevice->registerHwc3Callback(IComposerCallback::TRANSACTION_onVsyncIdle, this, nullptr);
225 mDevice->registerHwc3Callback(IComposerCallback::TRANSACTION_onRefreshRateChangedDebug, this,
226 nullptr);
227
228 mEventCallback = nullptr;
229 }
230
acceptDisplayChanges(int64_t display)231 int32_t HalImpl::acceptDisplayChanges(int64_t display) {
232 ExynosDisplay* halDisplay;
233 RET_IF_ERR(getHalDisplay(display, halDisplay));
234
235 return halDisplay->acceptDisplayChanges();
236 }
237
createLayer(int64_t display,int64_t * outLayer)238 int32_t HalImpl::createLayer(int64_t display, int64_t* outLayer) {
239 ExynosDisplay* halDisplay;
240 RET_IF_ERR(getHalDisplay(display, halDisplay));
241
242 hwc2_layer_t hwcLayer = 0;
243 RET_IF_ERR(halDisplay->createLayer(&hwcLayer));
244
245 h2a::translate(hwcLayer, *outLayer);
246 return HWC2_ERROR_NONE;
247 }
248
destroyLayer(int64_t display,int64_t layer)249 int32_t HalImpl::destroyLayer(int64_t display, int64_t layer) {
250 ExynosDisplay* halDisplay;
251 RET_IF_ERR(getHalDisplay(display, halDisplay));
252
253 ExynosLayer *halLayer;
254 RET_IF_ERR(getHalLayer(display, layer, halLayer));
255
256 return halDisplay->destroyLayer(reinterpret_cast<hwc2_layer_t>(halLayer));
257 }
258
createVirtualDisplay(uint32_t width,uint32_t height,AidlPixelFormat format,VirtualDisplay * outDisplay)259 int32_t HalImpl::createVirtualDisplay(uint32_t width, uint32_t height, AidlPixelFormat format,
260 VirtualDisplay* outDisplay) {
261 int32_t hwcFormat;
262 a2h::translate(format, hwcFormat);
263 hwc2_display_t hwcDisplay = getDisplayId(HWC_DISPLAY_VIRTUAL, 0);
264 auto halDisplay = mDevice->getDisplay(static_cast<uint32_t>(hwcDisplay));
265 if (!halDisplay) {
266 return HWC2_ERROR_BAD_PARAMETER;
267 }
268
269 RET_IF_ERR(mDevice->createVirtualDisplay(width, height, &hwcFormat, halDisplay));
270
271 h2a::translate(hwcDisplay, outDisplay->display);
272 h2a::translate(hwcFormat, outDisplay->format);
273
274 return HWC2_ERROR_NONE;
275 }
276
destroyVirtualDisplay(int64_t display)277 int32_t HalImpl::destroyVirtualDisplay(int64_t display) {
278 ExynosDisplay* halDisplay;
279 RET_IF_ERR(getHalDisplay(display, halDisplay));
280
281 return mDevice->destroyVirtualDisplay(halDisplay);
282 }
283
getActiveConfig(int64_t display,int32_t * outConfig)284 int32_t HalImpl::getActiveConfig(int64_t display, int32_t* outConfig) {
285 ExynosDisplay* halDisplay;
286 RET_IF_ERR(getHalDisplay(display, halDisplay));
287
288 hwc2_config_t hwcConfig;
289 RET_IF_ERR(halDisplay->getActiveConfig(&hwcConfig));
290
291 h2a::translate(hwcConfig, *outConfig);
292 return HWC2_ERROR_NONE;
293 }
294
getColorModes(int64_t display,std::vector<ColorMode> * outModes)295 int32_t HalImpl::getColorModes(int64_t display, std::vector<ColorMode>* outModes) {
296 ExynosDisplay* halDisplay;
297 RET_IF_ERR(getHalDisplay(display, halDisplay));
298
299 uint32_t count = 0;
300 RET_IF_ERR(halDisplay->getColorModes(&count, nullptr));
301
302 std::vector<int32_t> hwcModes(count);
303 RET_IF_ERR(halDisplay->getColorModes(&count, hwcModes.data()));
304
305 h2a::translate(hwcModes, *outModes);
306 return HWC2_ERROR_NONE;
307 }
308
getDataspaceSaturationMatrix(common::Dataspace dataspace,std::vector<float> * matrix)309 int32_t HalImpl::getDataspaceSaturationMatrix([[maybe_unused]] common::Dataspace dataspace,
310 std::vector<float>* matrix) {
311 // Pixel HWC does not support dataspace saturation matrix, return unit matrix.
312 std::vector<float> unitMatrix = {
313 1.0f, 0.0f, 0.0f, 0.0f,
314 0.0f, 1.0f, 0.0f, 0.0f,
315 0.0f, 0.0f, 1.0f, 0.0f,
316 0.0f, 0.0f, 0.0f, 1.0f,
317 };
318
319 *matrix = std::move(unitMatrix);
320 return HWC2_ERROR_NONE;
321 }
322
getDisplayAttribute(int64_t display,int32_t config,DisplayAttribute attribute,int32_t * outValue)323 int32_t HalImpl::getDisplayAttribute(int64_t display, int32_t config,
324 DisplayAttribute attribute, int32_t* outValue) {
325 ExynosDisplay* halDisplay;
326 RET_IF_ERR(getHalDisplay(display, halDisplay));
327
328 hwc2_config_t hwcConfig;
329 int32_t hwcAttr;
330 a2h::translate(config, hwcConfig);
331 a2h::translate(attribute, hwcAttr);
332
333 auto err = halDisplay->getDisplayAttribute(hwcConfig, hwcAttr, outValue);
334 if (err != HWC2_ERROR_NONE && *outValue == -1) {
335 return HWC2_ERROR_BAD_PARAMETER;
336 }
337 return HWC2_ERROR_NONE;
338 }
339
getDisplayBrightnessSupport(int64_t display,bool & outSupport)340 int32_t HalImpl::getDisplayBrightnessSupport(int64_t display, bool& outSupport) {
341 ExynosDisplay* halDisplay;
342 RET_IF_ERR(getHalDisplay(display, halDisplay));
343
344 return halDisplay->getDisplayBrightnessSupport(&outSupport);
345 }
346
getDisplayCapabilities(int64_t display,std::vector<DisplayCapability> * caps)347 int32_t HalImpl::getDisplayCapabilities(int64_t display,
348 std::vector<DisplayCapability>* caps) {
349 ExynosDisplay* halDisplay;
350 RET_IF_ERR(getHalDisplay(display, halDisplay));
351
352 uint32_t count = 0;
353 RET_IF_ERR(halDisplay->getDisplayCapabilities(&count, nullptr));
354
355 std::vector<uint32_t> hwcCaps(count);
356 RET_IF_ERR(halDisplay->getDisplayCapabilities(&count, hwcCaps.data()));
357
358 h2a::translate(hwcCaps, *caps);
359 return HWC2_ERROR_NONE;
360 }
361
getDisplayConfigs(int64_t display,std::vector<int32_t> * configs)362 int32_t HalImpl::getDisplayConfigs(int64_t display, std::vector<int32_t>* configs) {
363 ExynosDisplay* halDisplay;
364 RET_IF_ERR(getHalDisplay(display, halDisplay));
365
366 uint32_t count = 0;
367 RET_IF_ERR(halDisplay->getDisplayConfigs(&count, nullptr));
368
369 std::vector<hwc2_config_t> hwcConfigs(count);
370 RET_IF_ERR(halDisplay->getDisplayConfigs(&count, hwcConfigs.data()));
371
372 h2a::translate(hwcConfigs, *configs);
373 return HWC2_ERROR_NONE;
374 }
375
getDisplayConnectionType(int64_t display,DisplayConnectionType * outType)376 int32_t HalImpl::getDisplayConnectionType(int64_t display, DisplayConnectionType* outType) {
377 ExynosDisplay* halDisplay;
378 RET_IF_ERR(getHalDisplay(display, halDisplay));
379
380 uint32_t hwcType = HWC2_DISPLAY_CONNECTION_TYPE_INTERNAL;
381 RET_IF_ERR(halDisplay->getDisplayConnectionType(&hwcType));
382 h2a::translate(hwcType, *outType);
383
384 return HWC2_ERROR_NONE;
385 }
386
getDisplayIdentificationData(int64_t display,DisplayIdentification * id)387 int32_t HalImpl::getDisplayIdentificationData(int64_t display, DisplayIdentification *id) {
388 ExynosDisplay* halDisplay;
389 RET_IF_ERR(getHalDisplay(display, halDisplay));
390
391 uint8_t port;
392 uint32_t count = 0;
393 RET_IF_ERR(halDisplay->getDisplayIdentificationData(&port, &count, nullptr));
394
395 id->data.resize(count);
396 RET_IF_ERR(halDisplay->getDisplayIdentificationData(&port, &count, id->data.data()));
397
398 h2a::translate(port, id->port);
399 return HWC2_ERROR_NONE;
400 }
401
getDisplayName(int64_t display,std::string * outName)402 int32_t HalImpl::getDisplayName(int64_t display, std::string* outName) {
403 ExynosDisplay* halDisplay;
404 RET_IF_ERR(getHalDisplay(display, halDisplay));
405
406 uint32_t count = 0;
407 RET_IF_ERR(halDisplay->getDisplayName(&count, nullptr));
408
409 outName->resize(count);
410 RET_IF_ERR(halDisplay->getDisplayName(&count, outName->data()));
411
412 return HWC2_ERROR_NONE;
413 }
414
getDisplayVsyncPeriod(int64_t display,int32_t * outVsyncPeriod)415 int32_t HalImpl::getDisplayVsyncPeriod(int64_t display, int32_t* outVsyncPeriod) {
416 ExynosDisplay* halDisplay;
417 RET_IF_ERR(getHalDisplay(display, halDisplay));
418
419 hwc2_vsync_period_t hwcVsyncPeriod;
420 RET_IF_ERR(halDisplay->getDisplayVsyncPeriod(&hwcVsyncPeriod));
421
422 h2a::translate(hwcVsyncPeriod, *outVsyncPeriod);
423 return HWC2_ERROR_NONE;
424 }
425
getDisplayedContentSample(int64_t display,int64_t maxFrames,int64_t timestamp,DisplayContentSample * samples)426 int32_t HalImpl::getDisplayedContentSample([[maybe_unused]] int64_t display,
427 [[maybe_unused]] int64_t maxFrames,
428 [[maybe_unused]] int64_t timestamp,
429 [[maybe_unused]] DisplayContentSample* samples) {
430 return HWC2_ERROR_UNSUPPORTED;
431 }
432
getDisplayedContentSamplingAttributes(int64_t display,DisplayContentSamplingAttributes * attrs)433 int32_t HalImpl::getDisplayedContentSamplingAttributes(
434 [[maybe_unused]] int64_t display,
435 [[maybe_unused]] DisplayContentSamplingAttributes* attrs) {
436 return HWC2_ERROR_UNSUPPORTED;
437 }
438
getDisplayPhysicalOrientation(int64_t display,common::Transform * orientation)439 int32_t HalImpl::getDisplayPhysicalOrientation(int64_t display,
440 common::Transform* orientation) {
441 ExynosDisplay* halDisplay;
442 RET_IF_ERR(getHalDisplay(display, halDisplay));
443
444 HwcMountOrientation hwcOrientation;
445 RET_IF_ERR(halDisplay->getMountOrientation(&hwcOrientation));
446 h2a::translate(hwcOrientation, *orientation);
447
448 return HWC2_ERROR_NONE;
449 }
450
getDozeSupport(int64_t display,bool & support)451 int32_t HalImpl::getDozeSupport(int64_t display, bool& support) {
452 ExynosDisplay* halDisplay;
453 RET_IF_ERR(getHalDisplay(display, halDisplay));
454
455 int32_t hwcSupport;
456 RET_IF_ERR(halDisplay->getDozeSupport(&hwcSupport));
457
458 h2a::translate(hwcSupport, support);
459 return HWC2_ERROR_NONE;
460 }
461
getHdrCapabilities(int64_t display,HdrCapabilities * caps)462 int32_t HalImpl::getHdrCapabilities(int64_t display, HdrCapabilities* caps) {
463 ExynosDisplay* halDisplay;
464 RET_IF_ERR(getHalDisplay(display, halDisplay));
465
466 uint32_t count = 0;
467 RET_IF_ERR(halDisplay->getHdrCapabilities(&count, nullptr, &caps->maxLuminance,
468 &caps->maxAverageLuminance,
469 &caps->minLuminance));
470 std::vector<int32_t> hwcHdrTypes(count);
471 RET_IF_ERR(halDisplay->getHdrCapabilities(&count, hwcHdrTypes.data(),
472 &caps->maxLuminance,
473 &caps->maxAverageLuminance,
474 &caps->minLuminance));
475
476 h2a::translate(hwcHdrTypes, caps->types);
477 return HWC2_ERROR_NONE;
478 }
479
getOverlaySupport(OverlayProperties * caps)480 int32_t HalImpl::getOverlaySupport(OverlayProperties* caps) {
481 return mDevice->getOverlaySupport(caps);
482 }
483
getMaxVirtualDisplayCount(int32_t * count)484 int32_t HalImpl::getMaxVirtualDisplayCount(int32_t* count) {
485 uint32_t hwcCount = mDevice->getMaxVirtualDisplayCount();
486 h2a::translate(hwcCount, *count);
487
488 return HWC2_ERROR_NONE;
489 }
490
getPerFrameMetadataKeys(int64_t display,std::vector<PerFrameMetadataKey> * keys)491 int32_t HalImpl::getPerFrameMetadataKeys(int64_t display,
492 std::vector<PerFrameMetadataKey>* keys) {
493 ExynosDisplay* halDisplay;
494 RET_IF_ERR(getHalDisplay(display, halDisplay));
495
496 uint32_t numKeys = 0;
497 auto resManager = mDevice->mResourceManager;
498 if (resManager->hasHDR10PlusMPP()) {
499 numKeys = HWC2_HDR10_PLUS_SEI + 1;
500 } else {
501 numKeys = HWC2_MAX_FRAME_AVERAGE_LIGHT_LEVEL + 1;
502 }
503 for (uint32_t i = 0; i < numKeys; ++i) {
504 PerFrameMetadataKey key;
505 h2a::translate(i, key);
506 keys->push_back(key);
507 }
508
509 return HWC2_ERROR_NONE;
510 }
511
getReadbackBufferAttributes(int64_t display,ReadbackBufferAttributes * attrs)512 int32_t HalImpl::getReadbackBufferAttributes(int64_t display,
513 ReadbackBufferAttributes* attrs) {
514 ExynosDisplay* halDisplay;
515 RET_IF_ERR(getHalDisplay(display, halDisplay));
516
517 int32_t format = -1;
518 int32_t dataspace = -1;
519 RET_IF_ERR(halDisplay->getReadbackBufferAttributes(&format, &dataspace));
520
521 h2a::translate(format, attrs->format);
522 h2a::translate(dataspace, attrs->dataspace);
523
524 return HWC2_ERROR_NONE;
525 }
526
getReadbackBufferFence(int64_t display,ndk::ScopedFileDescriptor * acquireFence)527 int32_t HalImpl::getReadbackBufferFence(int64_t display,
528 ndk::ScopedFileDescriptor* acquireFence) {
529 ExynosDisplay* halDisplay;
530 RET_IF_ERR(getHalDisplay(display, halDisplay));
531
532 int32_t fd = -1;
533 RET_IF_ERR(halDisplay->getReadbackBufferFence(&fd));
534
535 h2a::translate(fd, *acquireFence);
536 return HWC2_ERROR_NONE;
537 }
538
getRenderIntents(int64_t display,ColorMode mode,std::vector<RenderIntent> * intents)539 int32_t HalImpl::getRenderIntents(int64_t display, ColorMode mode,
540 std::vector<RenderIntent>* intents) {
541 ExynosDisplay* halDisplay;
542 RET_IF_ERR(getHalDisplay(display, halDisplay));
543
544 int32_t hwcMode;
545 uint32_t count = 0;
546 a2h::translate(mode, hwcMode);
547 RET_IF_ERR(halDisplay->getRenderIntents(hwcMode, &count, nullptr));
548
549 std::vector<int32_t> hwcIntents(count);
550 RET_IF_ERR(halDisplay->getRenderIntents(hwcMode, &count, hwcIntents.data()));
551
552 h2a::translate(hwcIntents, *intents);
553 return HWC2_ERROR_NONE;
554 }
555
getSupportedContentTypes(int64_t display,std::vector<ContentType> * types)556 int32_t HalImpl::getSupportedContentTypes(int64_t display, std::vector<ContentType>* types) {
557 ExynosDisplay* halDisplay;
558 RET_IF_ERR(getHalDisplay(display, halDisplay));
559
560 uint32_t count = 0;
561 RET_IF_ERR(halDisplay->getSupportedContentTypes(&count, nullptr));
562
563 std::vector<uint32_t> hwcTypes(count);
564 RET_IF_ERR(halDisplay->getSupportedContentTypes(&count, hwcTypes.data()));
565
566 h2a::translate(hwcTypes, *types);
567 return HWC2_ERROR_NONE;
568 }
569
flushDisplayBrightnessChange(int64_t display)570 int32_t HalImpl::flushDisplayBrightnessChange(int64_t display) {
571 ExynosDisplay* halDisplay;
572 RET_IF_ERR(getHalDisplay(display, halDisplay));
573
574 return halDisplay->flushDisplayBrightnessChange();
575 }
576
presentDisplay(int64_t display,ndk::ScopedFileDescriptor & fence,std::vector<int64_t> * outLayers,std::vector<ndk::ScopedFileDescriptor> * outReleaseFences)577 int32_t HalImpl::presentDisplay(int64_t display, ndk::ScopedFileDescriptor& fence,
578 std::vector<int64_t>* outLayers,
579 std::vector<ndk::ScopedFileDescriptor>* outReleaseFences) {
580 ExynosDisplay* halDisplay;
581 RET_IF_ERR(getHalDisplay(display, halDisplay));
582
583 // TODO: not expect acceptDisplayChanges if there are no changes to accept
584 if (halDisplay->mRenderingState == RENDERING_STATE_VALIDATED) {
585 LOG(INFO) << halDisplay->mDisplayName.string()
586 << ": acceptDisplayChanges was not called";
587 if (halDisplay->acceptDisplayChanges() != HWC2_ERROR_NONE) {
588 LOG(ERROR) << halDisplay->mDisplayName.string()
589 << ": acceptDisplayChanges is failed";
590 }
591 }
592
593 int32_t hwcFence;
594 RET_IF_ERR(halDisplay->presentDisplay(&hwcFence));
595 h2a::translate(hwcFence, fence);
596
597 uint32_t count = 0;
598 RET_IF_ERR(halDisplay->getReleaseFences(&count, nullptr, nullptr));
599
600 std::vector<hwc2_layer_t> hwcLayers(count);
601 std::vector<int32_t> hwcFences(count);
602 RET_IF_ERR(halDisplay->getReleaseFences(&count, hwcLayers.data(), hwcFences.data()));
603
604 h2a::translate(hwcLayers, *outLayers);
605 h2a::translate(hwcFences, *outReleaseFences);
606
607 return HWC2_ERROR_NONE;
608 }
609
setActiveConfig(int64_t display,int32_t config)610 int32_t HalImpl::setActiveConfig(int64_t display, int32_t config) {
611 ExynosDisplay* halDisplay;
612 RET_IF_ERR(getHalDisplay(display, halDisplay));
613
614 hwc2_config_t hwcConfig;
615 a2h::translate(config, hwcConfig);
616 return halDisplay->setActiveConfig(hwcConfig);
617 }
618
setActiveConfigWithConstraints(int64_t display,int32_t config,const VsyncPeriodChangeConstraints & vsyncPeriodChangeConstraints,VsyncPeriodChangeTimeline * timeline)619 int32_t HalImpl::setActiveConfigWithConstraints(
620 int64_t display, int32_t config,
621 const VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
622 VsyncPeriodChangeTimeline* timeline) {
623 ExynosDisplay* halDisplay;
624 RET_IF_ERR(getHalDisplay(display, halDisplay));
625
626 hwc2_config_t hwcConfig;
627 hwc_vsync_period_change_constraints_t hwcConstraints;
628 hwc_vsync_period_change_timeline_t hwcTimeline;
629
630 a2h::translate(config, hwcConfig);
631 a2h::translate(vsyncPeriodChangeConstraints, hwcConstraints);
632 RET_IF_ERR(halDisplay->setActiveConfigWithConstraints(hwcConfig, &hwcConstraints, &hwcTimeline));
633
634 h2a::translate(hwcTimeline, *timeline);
635 return HWC2_ERROR_NONE;
636 }
637
setBootDisplayConfig(int64_t display,int32_t config)638 int32_t HalImpl::setBootDisplayConfig(int64_t display, int32_t config) {
639 ExynosDisplay* halDisplay;
640 RET_IF_ERR(getHalDisplay(display, halDisplay));
641
642 return halDisplay->setBootDisplayConfig(config);
643 }
644
clearBootDisplayConfig(int64_t display)645 int32_t HalImpl::clearBootDisplayConfig(int64_t display) {
646 ExynosDisplay* halDisplay;
647 RET_IF_ERR(getHalDisplay(display, halDisplay));
648
649 return halDisplay->clearBootDisplayConfig();
650 }
651
getPreferredBootDisplayConfig(int64_t display,int32_t * config)652 int32_t HalImpl::getPreferredBootDisplayConfig(int64_t display, int32_t* config) {
653 ExynosDisplay* halDisplay;
654 RET_IF_ERR(getHalDisplay(display, halDisplay));
655
656 return halDisplay->getPreferredBootDisplayConfig(config);
657 }
658
getHdrConversionCapabilities(std::vector<common::HdrConversionCapability> *)659 int32_t HalImpl::getHdrConversionCapabilities(std::vector<common::HdrConversionCapability>*) {
660 return HWC2_ERROR_UNSUPPORTED;
661 }
662
setHdrConversionStrategy(const common::HdrConversionStrategy &,common::Hdr *)663 int32_t HalImpl::setHdrConversionStrategy(const common::HdrConversionStrategy&, common::Hdr*) {
664 return HWC2_ERROR_UNSUPPORTED;
665 }
666
setAutoLowLatencyMode(int64_t display,bool on)667 int32_t HalImpl::setAutoLowLatencyMode(int64_t display, bool on) {
668 ExynosDisplay* halDisplay;
669 RET_IF_ERR(getHalDisplay(display, halDisplay));
670
671 return halDisplay->setAutoLowLatencyMode(on);
672 }
673
setClientTarget(int64_t display,buffer_handle_t target,const ndk::ScopedFileDescriptor & fence,common::Dataspace dataspace,const std::vector<common::Rect> & damage)674 int32_t HalImpl::setClientTarget(int64_t display, buffer_handle_t target,
675 const ndk::ScopedFileDescriptor& fence,
676 common::Dataspace dataspace,
677 const std::vector<common::Rect>& damage) {
678 ExynosDisplay* halDisplay;
679 RET_IF_ERR(getHalDisplay(display, halDisplay));
680
681 int32_t hwcFence;
682 int32_t hwcDataspace;
683 std::vector<hwc_rect_t> hwcDamage;
684
685 a2h::translate(fence, hwcFence);
686 a2h::translate(dataspace, hwcDataspace);
687 a2h::translate(damage, hwcDamage);
688 hwc_region_t region = { hwcDamage.size(), hwcDamage.data() };
689 UNUSED(region);
690
691 return halDisplay->setClientTarget(target, hwcFence, hwcDataspace);
692 }
693
getHasClientComposition(int64_t display,bool & outHasClientComp)694 int32_t HalImpl::getHasClientComposition(int64_t display, bool& outHasClientComp) {
695 ExynosDisplay* halDisplay;
696 RET_IF_ERR(getHalDisplay(display, halDisplay));
697
698 outHasClientComp = halDisplay->hasClientComposition();
699
700 return HWC2_ERROR_NONE;
701 }
702
setColorMode(int64_t display,ColorMode mode,RenderIntent intent)703 int32_t HalImpl::setColorMode(int64_t display, ColorMode mode, RenderIntent intent) {
704 ExynosDisplay* halDisplay;
705 RET_IF_ERR(getHalDisplay(display, halDisplay));
706
707 int32_t hwcMode;
708 int32_t hwcIntent;
709
710 a2h::translate(mode, hwcMode);
711 a2h::translate(intent, hwcIntent);
712 return halDisplay->setColorModeWithRenderIntent(hwcMode, hwcIntent);
713 }
714
setColorTransform(int64_t display,const std::vector<float> & matrix)715 int32_t HalImpl::setColorTransform(int64_t display, const std::vector<float>& matrix) {
716 // clang-format off
717 constexpr std::array<float, 16> kIdentity = {
718 1.0f, 0.0f, 0.0f, 0.0f,
719 0.0f, 1.0f, 0.0f, 0.0f,
720 0.0f, 0.0f, 1.0f, 0.0f,
721 0.0f, 0.0f, 0.0f, 1.0f,
722 };
723 // clang-format on
724 const bool isIdentity = (std::equal(matrix.begin(), matrix.end(), kIdentity.begin()));
725 const common::ColorTransform hint = isIdentity ? common::ColorTransform::IDENTITY
726 : common::ColorTransform::ARBITRARY_MATRIX;
727
728 ExynosDisplay* halDisplay;
729 RET_IF_ERR(getHalDisplay(display, halDisplay));
730
731 int32_t hwcHint;
732 a2h::translate(hint, hwcHint);
733 return halDisplay->setColorTransform(matrix.data(), hwcHint);
734 }
735
setContentType(int64_t display,ContentType contentType)736 int32_t HalImpl::setContentType(int64_t display, ContentType contentType) {
737 ExynosDisplay* halDisplay;
738 RET_IF_ERR(getHalDisplay(display, halDisplay));
739
740 int32_t type;
741 a2h::translate(contentType, type);
742 return halDisplay->setContentType(type);
743 }
744
setDisplayBrightness(int64_t display,float brightness)745 int32_t HalImpl::setDisplayBrightness(int64_t display, float brightness) {
746 ExynosDisplay* halDisplay;
747 RET_IF_ERR(getHalDisplay(display, halDisplay));
748
749 return halDisplay->setDisplayBrightness(brightness, true /* wait present */);
750 }
751
setDisplayedContentSamplingEnabled(int64_t display,bool enable,FormatColorComponent componentMask,int64_t maxFrames)752 int32_t HalImpl::setDisplayedContentSamplingEnabled(
753 [[maybe_unused]] int64_t display,
754 [[maybe_unused]] bool enable,
755 [[maybe_unused]] FormatColorComponent componentMask,
756 [[maybe_unused]] int64_t maxFrames) {
757 return HWC2_ERROR_UNSUPPORTED;
758 }
759
setLayerBlendMode(int64_t display,int64_t layer,common::BlendMode mode)760 int32_t HalImpl::setLayerBlendMode(int64_t display, int64_t layer, common::BlendMode mode) {
761 ExynosLayer *halLayer;
762 RET_IF_ERR(getHalLayer(display, layer, halLayer));
763
764 int32_t hwcMode;
765 a2h::translate(mode, hwcMode);
766 return halLayer->setLayerBlendMode(hwcMode);
767 }
768
setLayerBuffer(int64_t display,int64_t layer,buffer_handle_t buffer,const ndk::ScopedFileDescriptor & acquireFence)769 int32_t HalImpl::setLayerBuffer(int64_t display, int64_t layer, buffer_handle_t buffer,
770 const ndk::ScopedFileDescriptor& acquireFence) {
771 ExynosLayer *halLayer;
772 RET_IF_ERR(getHalLayer(display, layer, halLayer));
773
774 int32_t hwcFd;
775 a2h::translate(acquireFence, hwcFd);
776
777 return halLayer->setLayerBuffer(buffer, hwcFd);
778 }
779
setLayerColor(int64_t display,int64_t layer,Color color)780 int32_t HalImpl::setLayerColor(int64_t display, int64_t layer, Color color) {
781 ExynosLayer *halLayer;
782 RET_IF_ERR(getHalLayer(display, layer, halLayer));
783
784 hwc_color_t hwcColor;
785 a2h::translate(color, hwcColor);
786 return halLayer->setLayerColor(hwcColor);
787 }
788
setLayerColorTransform(int64_t display,int64_t layer,const std::vector<float> & matrix)789 int32_t HalImpl::setLayerColorTransform(int64_t display, int64_t layer,
790 const std::vector<float>& matrix) {
791 ExynosLayer *halLayer;
792 RET_IF_ERR(getHalLayer(display, layer, halLayer));
793
794 return halLayer->setLayerColorTransform(matrix.data());
795 }
796
setLayerCompositionType(int64_t display,int64_t layer,Composition type)797 int32_t HalImpl::setLayerCompositionType(int64_t display, int64_t layer, Composition type) {
798 ExynosLayer *halLayer;
799 RET_IF_ERR(getHalLayer(display, layer, halLayer));
800
801 int32_t hwcType;
802 a2h::translate(type, hwcType);
803 return halLayer->setLayerCompositionType(hwcType);
804 }
805
setLayerCursorPosition(int64_t display,int64_t layer,int32_t x,int32_t y)806 int32_t HalImpl::setLayerCursorPosition(int64_t display, int64_t layer, int32_t x, int32_t y) {
807 ExynosLayer *halLayer;
808 RET_IF_ERR(getHalLayer(display, layer, halLayer));
809
810 return halLayer->setCursorPosition(x, y);
811 }
812
setLayerDataspace(int64_t display,int64_t layer,common::Dataspace dataspace)813 int32_t HalImpl::setLayerDataspace(int64_t display, int64_t layer, common::Dataspace dataspace) {
814 ExynosLayer *halLayer;
815 RET_IF_ERR(getHalLayer(display, layer, halLayer));
816
817 int32_t hwcDataspace;
818 a2h::translate(dataspace, hwcDataspace);
819 return halLayer->setLayerDataspace(hwcDataspace);
820 }
821
setLayerDisplayFrame(int64_t display,int64_t layer,const common::Rect & frame)822 int32_t HalImpl::setLayerDisplayFrame(int64_t display, int64_t layer, const common::Rect& frame) {
823 ExynosLayer *halLayer;
824 RET_IF_ERR(getHalLayer(display, layer, halLayer));
825
826 hwc_rect_t hwcFrame;
827 a2h::translate(frame, hwcFrame);
828 return halLayer->setLayerDisplayFrame(hwcFrame);
829 }
830
setLayerPerFrameMetadata(int64_t display,int64_t layer,const std::vector<std::optional<PerFrameMetadata>> & metadata)831 int32_t HalImpl::setLayerPerFrameMetadata(int64_t display, int64_t layer,
832 const std::vector<std::optional<PerFrameMetadata>>& metadata) {
833 ExynosLayer *halLayer;
834 RET_IF_ERR(getHalLayer(display, layer, halLayer));
835
836 uint32_t count = metadata.size();
837 std::vector<int32_t> keys;
838 std::vector<float> values;
839
840 for (uint32_t ix = 0; ix < count; ++ix) {
841 if (metadata[ix]) {
842 int32_t key;
843 a2h::translate(metadata[ix]->key, key);
844 keys.push_back(key);
845 values.push_back(metadata[ix]->value);
846 }
847 }
848
849 return halLayer->setLayerPerFrameMetadata(count, keys.data(), values.data());
850 }
851
setLayerPerFrameMetadataBlobs(int64_t display,int64_t layer,const std::vector<std::optional<PerFrameMetadataBlob>> & blobs)852 int32_t HalImpl::setLayerPerFrameMetadataBlobs(int64_t display, int64_t layer,
853 const std::vector<std::optional<PerFrameMetadataBlob>>& blobs) {
854 ExynosLayer *halLayer;
855 RET_IF_ERR(getHalLayer(display, layer, halLayer));
856
857 uint32_t count = blobs.size();
858 std::vector<int32_t> keys;
859 std::vector<uint32_t> sizes;
860 std::vector<uint8_t> values;
861
862 for (uint32_t ix = 0; ix < count; ++ix) {
863 if (blobs[ix]) {
864 int32_t key;
865 a2h::translate(blobs[ix]->key, key);
866 keys.push_back(key);
867 sizes.push_back(blobs[ix]->blob.size());
868 values.insert(values.end(), blobs[ix]->blob.begin(), blobs[ix]->blob.end());
869 }
870 }
871
872 return halLayer->setLayerPerFrameMetadataBlobs(count, keys.data(), sizes.data(),
873 values.data());
874 }
875
setLayerPlaneAlpha(int64_t display,int64_t layer,float alpha)876 int32_t HalImpl::setLayerPlaneAlpha(int64_t display, int64_t layer, float alpha) {
877 ExynosLayer *halLayer;
878 RET_IF_ERR(getHalLayer(display, layer, halLayer));
879
880 return halLayer->setLayerPlaneAlpha(alpha);
881 }
882
setLayerSidebandStream(int64_t display,int64_t layer,buffer_handle_t stream)883 int32_t HalImpl::setLayerSidebandStream([[maybe_unused]] int64_t display,
884 [[maybe_unused]] int64_t layer,
885 [[maybe_unused]] buffer_handle_t stream) {
886 return HWC2_ERROR_UNSUPPORTED;
887 }
888
setLayerSourceCrop(int64_t display,int64_t layer,const common::FRect & crop)889 int32_t HalImpl::setLayerSourceCrop(int64_t display, int64_t layer, const common::FRect& crop) {
890 ExynosLayer *halLayer;
891 RET_IF_ERR(getHalLayer(display, layer, halLayer));
892
893 hwc_frect_t hwcCrop;
894 a2h::translate(crop, hwcCrop);
895 return halLayer->setLayerSourceCrop(hwcCrop);
896 }
897
setLayerSurfaceDamage(int64_t display,int64_t layer,const std::vector<std::optional<common::Rect>> & damage)898 int32_t HalImpl::setLayerSurfaceDamage(int64_t display, int64_t layer,
899 const std::vector<std::optional<common::Rect>>& damage) {
900 ExynosLayer *halLayer;
901 RET_IF_ERR(getHalLayer(display, layer, halLayer));
902
903 std::vector<hwc_rect_t> hwcDamage;
904 a2h::translate(damage, hwcDamage);
905 hwc_region_t region = { hwcDamage.size(), hwcDamage.data() };
906
907 return halLayer->setLayerSurfaceDamage(region);
908 }
909
setLayerTransform(int64_t display,int64_t layer,common::Transform transform)910 int32_t HalImpl::setLayerTransform(int64_t display, int64_t layer, common::Transform transform) {
911 ExynosLayer *halLayer;
912 RET_IF_ERR(getHalLayer(display, layer, halLayer));
913
914 int32_t hwcTransform;
915 a2h::translate(transform, hwcTransform);
916
917 return halLayer->setLayerTransform(hwcTransform);
918 }
919
setLayerVisibleRegion(int64_t display,int64_t layer,const std::vector<std::optional<common::Rect>> & visible)920 int32_t HalImpl::setLayerVisibleRegion(int64_t display, int64_t layer,
921 const std::vector<std::optional<common::Rect>>& visible) {
922 ExynosLayer *halLayer;
923 RET_IF_ERR(getHalLayer(display, layer, halLayer));
924
925 std::vector<hwc_rect_t> hwcVisible;
926 a2h::translate(visible, hwcVisible);
927 hwc_region_t region = { hwcVisible.size(), hwcVisible.data() };
928
929 return halLayer->setLayerVisibleRegion(region);
930 }
931
setLayerBrightness(int64_t display,int64_t layer,float brightness)932 int32_t HalImpl::setLayerBrightness(int64_t display, int64_t layer, float brightness) {
933 ExynosLayer *halLayer;
934 RET_IF_ERR(getHalLayer(display, layer, halLayer));
935
936 return halLayer->setLayerBrightness(brightness);
937 }
938
setLayerZOrder(int64_t display,int64_t layer,uint32_t z)939 int32_t HalImpl::setLayerZOrder(int64_t display, int64_t layer, uint32_t z) {
940 ExynosLayer *halLayer;
941 RET_IF_ERR(getHalLayer(display, layer, halLayer));
942
943 return halLayer->setLayerZOrder(z);
944 }
945
setOutputBuffer(int64_t display,buffer_handle_t buffer,const ndk::ScopedFileDescriptor & releaseFence)946 int32_t HalImpl::setOutputBuffer(int64_t display, buffer_handle_t buffer,
947 const ndk::ScopedFileDescriptor& releaseFence) {
948 ExynosDisplay* halDisplay;
949 RET_IF_ERR(getHalDisplay(display, halDisplay));
950
951 int32_t hwcFence;
952 a2h::translate(releaseFence, hwcFence);
953
954 auto err = halDisplay->setOutputBuffer(buffer, hwcFence);
955 // unlike in setClientTarget, releaseFence is owned by us
956 if (err == HWC2_ERROR_NONE && hwcFence >= 0) {
957 close(hwcFence);
958 }
959
960 return err;
961 }
962
setPowerMode(int64_t display,PowerMode mode)963 int32_t HalImpl::setPowerMode(int64_t display, PowerMode mode) {
964 if (mode == PowerMode::ON_SUSPEND || mode == PowerMode::DOZE_SUSPEND) {
965 return HWC2_ERROR_UNSUPPORTED;
966 }
967
968 ExynosDisplay* halDisplay;
969 RET_IF_ERR(getHalDisplay(display, halDisplay));
970
971 int32_t hwcMode;
972 a2h::translate(mode, hwcMode);
973 return halDisplay->setPowerMode(hwcMode);
974 }
975
setReadbackBuffer(int64_t display,buffer_handle_t buffer,const ndk::ScopedFileDescriptor & releaseFence)976 int32_t HalImpl::setReadbackBuffer(int64_t display, buffer_handle_t buffer,
977 const ndk::ScopedFileDescriptor& releaseFence) {
978 ExynosDisplay* halDisplay;
979 RET_IF_ERR(getHalDisplay(display, halDisplay));
980
981 int32_t hwcFence;
982 a2h::translate(releaseFence, hwcFence);
983
984 return halDisplay->setReadbackBuffer(buffer, hwcFence);
985 }
986
setVsyncEnabled(int64_t display,bool enabled)987 int32_t HalImpl::setVsyncEnabled(int64_t display, bool enabled) {
988 ExynosDisplay* halDisplay;
989 RET_IF_ERR(getHalDisplay(display, halDisplay));
990
991 hwc2_vsync_t hwcEnable;
992 a2h::translate(enabled, hwcEnable);
993 return halDisplay->setVsyncEnabled(hwcEnable);
994 }
995
setIdleTimerEnabled(int64_t display,int32_t timeout)996 int32_t HalImpl::setIdleTimerEnabled(int64_t display, int32_t timeout) {
997 ExynosDisplay* halDisplay;
998 RET_IF_ERR(getHalDisplay(display, halDisplay));
999
1000 return halDisplay->setDisplayIdleTimer(timeout);
1001 }
1002
validateDisplay(int64_t display,std::vector<int64_t> * outChangedLayers,std::vector<Composition> * outCompositionTypes,uint32_t * outDisplayRequestMask,std::vector<int64_t> * outRequestedLayers,std::vector<int32_t> * outRequestMasks,ClientTargetProperty * outClientTargetProperty,DimmingStage * outDimmingStage)1003 int32_t HalImpl::validateDisplay(int64_t display, std::vector<int64_t>* outChangedLayers,
1004 std::vector<Composition>* outCompositionTypes,
1005 uint32_t* outDisplayRequestMask,
1006 std::vector<int64_t>* outRequestedLayers,
1007 std::vector<int32_t>* outRequestMasks,
1008 ClientTargetProperty* outClientTargetProperty,
1009 DimmingStage* outDimmingStage) {
1010 ExynosDisplay* halDisplay;
1011 RET_IF_ERR(getHalDisplay(display, halDisplay));
1012
1013 uint32_t typesCount = 0;
1014 uint32_t reqsCount = 0;
1015 auto err = halDisplay->validateDisplay(&typesCount, &reqsCount);
1016
1017 if (err != HWC2_ERROR_NONE && err != HWC2_ERROR_HAS_CHANGES) {
1018 return err;
1019 }
1020
1021 std::vector<hwc2_layer_t> hwcChangedLayers(typesCount);
1022 std::vector<int32_t> hwcCompositionTypes(typesCount);
1023 RET_IF_ERR(halDisplay->getChangedCompositionTypes(&typesCount, hwcChangedLayers.data(),
1024 hwcCompositionTypes.data()));
1025
1026 int32_t displayReqs;
1027 std::vector<hwc2_layer_t> hwcRequestedLayers(reqsCount);
1028 outRequestMasks->resize(reqsCount);
1029 RET_IF_ERR(halDisplay->getDisplayRequests(&displayReqs, &reqsCount,
1030 hwcRequestedLayers.data(), outRequestMasks->data()));
1031
1032 h2a::translate(hwcChangedLayers, *outChangedLayers);
1033 h2a::translate(hwcCompositionTypes, *outCompositionTypes);
1034 *outDisplayRequestMask = displayReqs;
1035 h2a::translate(hwcRequestedLayers, *outRequestedLayers);
1036
1037 hwc_client_target_property hwcProperty;
1038 HwcDimmingStage hwcDimmingStage;
1039 if (!halDisplay->getClientTargetProperty(&hwcProperty, &hwcDimmingStage)) {
1040 h2a::translate(hwcDimmingStage, *outDimmingStage);
1041 h2a::translate(hwcProperty, *outClientTargetProperty);
1042 } // else ignore this error
1043
1044 return err;
1045 }
1046
setExpectedPresentTime(int64_t display,const std::optional<ClockMonotonicTimestamp> expectedPresentTime)1047 int HalImpl::setExpectedPresentTime(
1048 int64_t display, const std::optional<ClockMonotonicTimestamp> expectedPresentTime) {
1049 ExynosDisplay* halDisplay;
1050 RET_IF_ERR(getHalDisplay(display, halDisplay));
1051
1052 if (!expectedPresentTime.has_value()) return HWC2_ERROR_NONE;
1053
1054 if (halDisplay->getPendingExpectedPresentTime() != 0) {
1055 ALOGW("HalImpl: set expected present time multiple times in one frame");
1056 }
1057
1058 halDisplay->setExpectedPresentTime(expectedPresentTime->timestampNanos);
1059
1060 return HWC2_ERROR_NONE;
1061 }
1062
getRCDLayerSupport(int64_t display,bool & outSupport)1063 int32_t HalImpl::getRCDLayerSupport(int64_t display, bool& outSupport) {
1064 ExynosDisplay* halDisplay;
1065 RET_IF_ERR(getHalDisplay(display, halDisplay));
1066
1067 return halDisplay->getRCDLayerSupport(outSupport);
1068 }
1069
setLayerBlockingRegion(int64_t display,int64_t layer,const std::vector<std::optional<common::Rect>> & blockingRegion)1070 int32_t HalImpl::setLayerBlockingRegion(
1071 int64_t display, int64_t layer,
1072 const std::vector<std::optional<common::Rect>>& blockingRegion) {
1073 ExynosLayer* halLayer;
1074 RET_IF_ERR(getHalLayer(display, layer, halLayer));
1075
1076 std::vector<hwc_rect_t> halBlockingRegion;
1077 a2h::translate(blockingRegion, halBlockingRegion);
1078
1079 return halLayer->setLayerBlockingRegion(halBlockingRegion);
1080 }
1081
getDisplayIdleTimerSupport(int64_t display,bool & outSupport)1082 int32_t HalImpl::getDisplayIdleTimerSupport(int64_t display, bool& outSupport) {
1083 ExynosDisplay* halDisplay;
1084 RET_IF_ERR(getHalDisplay(display, halDisplay));
1085
1086 return halDisplay->getDisplayIdleTimerSupport(outSupport);
1087 }
1088
getDisplayMultiThreadedPresentSupport(const int64_t & display,bool & outSupport)1089 int32_t HalImpl::getDisplayMultiThreadedPresentSupport(const int64_t& display, bool& outSupport) {
1090 ExynosDisplay* halDisplay;
1091 RET_IF_ERR(getHalDisplay(display, halDisplay));
1092
1093 return halDisplay->getDisplayMultiThreadedPresentSupport(outSupport);
1094 }
1095
setRefreshRateChangedCallbackDebugEnabled(int64_t display,bool enabled)1096 int32_t HalImpl::setRefreshRateChangedCallbackDebugEnabled(int64_t display, bool enabled) {
1097 ExynosDisplay* halDisplay;
1098 RET_IF_ERR(getHalDisplay(display, halDisplay));
1099
1100 return halDisplay->setRefreshRateChangedCallbackDebugEnabled(enabled);
1101 }
1102
1103 } // namespace aidl::android::hardware::graphics::composer3::impl
1104