blob: 7fa511974f6000468a7a562b623f94fe987e4102 [file] [log] [blame]
Chia-I Wu7f8d3962016-09-28 21:04:23 +08001/*
2 * Copyright 2016 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_TAG "HwcPassthrough"
18
19#include <mutex>
20#include <type_traits>
21#include <unordered_map>
22#include <unordered_set>
23#include <utility>
24#include <vector>
25
26#include <hardware/gralloc.h>
27#include <hardware/gralloc1.h>
28#include <hardware/hwcomposer2.h>
29#include <log/log.h>
30
31#include "Hwc.h"
32
33namespace android {
34namespace hardware {
35namespace graphics {
36namespace composer {
37namespace V2_1 {
38namespace implementation {
39
Chia-I Wu1c457272016-11-17 10:11:32 +080040using android::hardware::graphics::common::V1_0::PixelFormat;
41using android::hardware::graphics::common::V1_0::Transform;
42using android::hardware::graphics::common::V1_0::Dataspace;
43using android::hardware::graphics::common::V1_0::ColorMode;
44using android::hardware::graphics::common::V1_0::ColorTransform;
45using android::hardware::graphics::common::V1_0::Hdr;
Chia-I Wu7f8d3962016-09-28 21:04:23 +080046
47namespace {
48
49class HandleImporter {
50public:
51 HandleImporter() : mInitialized(false) {}
52
53 bool initialize()
54 {
55 // allow only one client
56 if (mInitialized) {
57 return false;
58 }
59
60 if (!openGralloc()) {
61 return false;
62 }
63
64 mInitialized = true;
65 return true;
66 }
67
68 void cleanup()
69 {
70 if (!mInitialized) {
71 return;
72 }
73
74 closeGralloc();
75 mInitialized = false;
76 }
77
78 // In IComposer, any buffer_handle_t is owned by the caller and we need to
79 // make a clone for hwcomposer2. We also need to translate empty handle
80 // to nullptr. This function does that, in-place.
81 bool importBuffer(buffer_handle_t& handle)
82 {
83 if (!handle->numFds && !handle->numInts) {
84 handle = nullptr;
85 return true;
86 }
87
88 buffer_handle_t clone = cloneBuffer(handle);
89 if (!clone) {
90 return false;
91 }
92
93 handle = clone;
94 return true;
95 }
96
97 void freeBuffer(buffer_handle_t handle)
98 {
99 if (!handle) {
100 return;
101 }
102
103 releaseBuffer(handle);
104 }
105
106 bool importFence(const native_handle_t* handle, int& fd)
107 {
108 if (handle->numFds == 0) {
109 fd = -1;
110 } else if (handle->numFds == 1) {
111 fd = dup(handle->data[0]);
112 if (fd < 0) {
113 ALOGE("failed to dup fence fd %d", handle->data[0]);
114 return false;
115 }
116 } else {
117 ALOGE("invalid fence handle with %d file descriptors",
118 handle->numFds);
119 return false;
120 }
121
122 return true;
123 }
124
125 void closeFence(int fd)
126 {
127 if (fd >= 0) {
128 close(fd);
129 }
130 }
131
132private:
133 bool mInitialized;
134
135 // Some existing gralloc drivers do not support retaining more than once,
136 // when we are in passthrough mode.
137#ifdef BINDERIZED
138 bool openGralloc()
139 {
140 const hw_module_t* module;
141 int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
142 if (err) {
143 ALOGE("failed to get gralloc module");
144 return false;
145 }
146
147 uint8_t major = (module->module_api_version >> 8) & 0xff;
148 if (major > 1) {
149 ALOGE("unknown gralloc module major version %d", major);
150 return false;
151 }
152
153 if (major == 1) {
154 err = gralloc1_open(module, &mDevice);
155 if (err) {
156 ALOGE("failed to open gralloc1 device");
157 return false;
158 }
159
160 mRetain = reinterpret_cast<GRALLOC1_PFN_RETAIN>(
161 mDevice->getFunction(mDevice, GRALLOC1_FUNCTION_RETAIN));
162 mRelease = reinterpret_cast<GRALLOC1_PFN_RELEASE>(
163 mDevice->getFunction(mDevice, GRALLOC1_FUNCTION_RELEASE));
164 if (!mRetain || !mRelease) {
165 ALOGE("invalid gralloc1 device");
166 gralloc1_close(mDevice);
167 return false;
168 }
169 } else {
170 mModule = reinterpret_cast<const gralloc_module_t*>(module);
171 }
172
173 return true;
174 }
175
176 void closeGralloc()
177 {
178 if (mDevice) {
179 gralloc1_close(mDevice);
180 }
181 }
182
183 buffer_handle_t cloneBuffer(buffer_handle_t handle)
184 {
185 native_handle_t* clone = native_handle_clone(handle);
186 if (!clone) {
187 ALOGE("failed to clone buffer %p", handle);
188 return nullptr;
189 }
190
191 bool err;
192 if (mDevice) {
193 err = (mRetain(mDevice, clone) != GRALLOC1_ERROR_NONE);
194 } else {
195 err = (mModule->registerBuffer(mModule, clone) != 0);
196 }
197
198 if (err) {
199 ALOGE("failed to retain/register buffer %p", clone);
200 native_handle_close(clone);
201 native_handle_delete(clone);
202 return nullptr;
203 }
204
205 return clone;
206 }
207
208 void releaseBuffer(buffer_handle_t handle)
209 {
210 if (mDevice) {
211 mRelease(mDevice, handle);
212 } else {
213 mModule->unregisterBuffer(mModule, handle);
214 native_handle_close(handle);
215 native_handle_delete(const_cast<native_handle_t*>(handle));
216 }
217 }
218
219 // gralloc1
220 gralloc1_device_t* mDevice;
221 GRALLOC1_PFN_RETAIN mRetain;
222 GRALLOC1_PFN_RELEASE mRelease;
223
224 // gralloc0
225 const gralloc_module_t* mModule;
226#else
227 bool openGralloc() { return true; }
228 void closeGralloc() {}
229 buffer_handle_t cloneBuffer(buffer_handle_t handle) { return handle; }
230 void releaseBuffer(buffer_handle_t) {}
231#endif
232};
233
234HandleImporter sHandleImporter;
235
236class BufferClone {
237public:
238 BufferClone() : mHandle(nullptr) {}
239
240 BufferClone(BufferClone&& other)
241 {
242 mHandle = other.mHandle;
243 other.mHandle = nullptr;
244 }
245
246 BufferClone(const BufferClone& other) = delete;
247 BufferClone& operator=(const BufferClone& other) = delete;
248
249 BufferClone& operator=(buffer_handle_t handle)
250 {
251 clear();
252 mHandle = handle;
253 return *this;
254 }
255
256 ~BufferClone()
257 {
258 clear();
259 }
260
261private:
262 void clear()
263 {
264 if (mHandle) {
265 sHandleImporter.freeBuffer(mHandle);
266 }
267 }
268
269 buffer_handle_t mHandle;
270};
271
272} // anonymous namespace
273
274class HwcHal : public IComposer {
275public:
276 HwcHal(const hw_module_t* module);
277 virtual ~HwcHal();
278
279 // IComposer interface
280 Return<void> getCapabilities(getCapabilities_cb hidl_cb) override;
281 Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
282 Return<void> registerCallback(const sp<IComposerCallback>& callback) override;
283 Return<uint32_t> getMaxVirtualDisplayCount() override;
284 Return<void> createVirtualDisplay(uint32_t width, uint32_t height,
285 PixelFormat formatHint, createVirtualDisplay_cb hidl_cb) override;
286 Return<Error> destroyVirtualDisplay(Display display) override;
287 Return<Error> acceptDisplayChanges(Display display) override;
288 Return<void> createLayer(Display display,
289 createLayer_cb hidl_cb) override;
290 Return<Error> destroyLayer(Display display, Layer layer) override;
291 Return<void> getActiveConfig(Display display,
292 getActiveConfig_cb hidl_cb) override;
293 Return<void> getChangedCompositionTypes(Display display,
294 getChangedCompositionTypes_cb hidl_cb) override;
295 Return<Error> getClientTargetSupport(Display display,
296 uint32_t width, uint32_t height,
297 PixelFormat format, Dataspace dataspace) override;
298 Return<void> getColorModes(Display display,
299 getColorModes_cb hidl_cb) override;
300 Return<void> getDisplayAttribute(Display display,
301 Config config, Attribute attribute,
302 getDisplayAttribute_cb hidl_cb) override;
303 Return<void> getDisplayConfigs(Display display,
304 getDisplayConfigs_cb hidl_cb) override;
305 Return<void> getDisplayName(Display display,
306 getDisplayName_cb hidl_cb) override;
307 Return<void> getDisplayRequests(Display display,
308 getDisplayRequests_cb hidl_cb) override;
309 Return<void> getDisplayType(Display display,
310 getDisplayType_cb hidl_cb) override;
311 Return<void> getDozeSupport(Display display,
312 getDozeSupport_cb hidl_cb) override;
313 Return<void> getHdrCapabilities(Display display,
314 getHdrCapabilities_cb hidl_cb) override;
315 Return<void> getReleaseFences(Display display,
316 getReleaseFences_cb hidl_cb) override;
317 Return<void> presentDisplay(Display display,
318 presentDisplay_cb hidl_cb) override;
319 Return<Error> setActiveConfig(Display display, Config config) override;
320 Return<Error> setClientTarget(Display display,
321 const native_handle_t* target,
322 const native_handle_t* acquireFence,
323 Dataspace dataspace, const hidl_vec<Rect>& damage) override;
324 Return<Error> setColorMode(Display display, ColorMode mode) override;
325 Return<Error> setColorTransform(Display display,
326 const hidl_vec<float>& matrix, ColorTransform hint) override;
327 Return<Error> setOutputBuffer(Display display,
328 const native_handle_t* buffer,
329 const native_handle_t* releaseFence) override;
330 Return<Error> setPowerMode(Display display, PowerMode mode) override;
331 Return<Error> setVsyncEnabled(Display display, Vsync enabled) override;
332 Return<void> validateDisplay(Display display,
333 validateDisplay_cb hidl_cb) override;
334 Return<Error> setCursorPosition(Display display,
335 Layer layer, int32_t x, int32_t y) override;
336 Return<Error> setLayerBuffer(Display display,
337 Layer layer, const native_handle_t* buffer,
338 const native_handle_t* acquireFence) override;
339 Return<Error> setLayerSurfaceDamage(Display display,
340 Layer layer, const hidl_vec<Rect>& damage) override;
341 Return<Error> setLayerBlendMode(Display display,
342 Layer layer, BlendMode mode) override;
343 Return<Error> setLayerColor(Display display,
344 Layer layer, const Color& color) override;
345 Return<Error> setLayerCompositionType(Display display,
346 Layer layer, Composition type) override;
347 Return<Error> setLayerDataspace(Display display,
348 Layer layer, Dataspace dataspace) override;
349 Return<Error> setLayerDisplayFrame(Display display,
350 Layer layer, const Rect& frame) override;
351 Return<Error> setLayerPlaneAlpha(Display display,
352 Layer layer, float alpha) override;
353 Return<Error> setLayerSidebandStream(Display display,
354 Layer layer, const native_handle_t* stream) override;
355 Return<Error> setLayerSourceCrop(Display display,
356 Layer layer, const FRect& crop) override;
357 Return<Error> setLayerTransform(Display display,
358 Layer layer, Transform transform) override;
359 Return<Error> setLayerVisibleRegion(Display display,
360 Layer layer, const hidl_vec<Rect>& visible) override;
361 Return<Error> setLayerZOrder(Display display,
362 Layer layer, uint32_t z) override;
363
364private:
365 void initCapabilities();
366
367 template<typename T>
368 void initDispatch(T& func, hwc2_function_descriptor_t desc);
369 void initDispatch();
370
371 bool hasCapability(Capability capability) const;
372
373 static void hotplugHook(hwc2_callback_data_t callbackData,
374 hwc2_display_t display, int32_t connected);
375 static void refreshHook(hwc2_callback_data_t callbackData,
376 hwc2_display_t display);
377 static void vsyncHook(hwc2_callback_data_t callbackData,
378 hwc2_display_t display, int64_t timestamp);
379
380 hwc2_device_t* mDevice;
381
382 std::unordered_set<Capability> mCapabilities;
383
384 struct {
385 HWC2_PFN_ACCEPT_DISPLAY_CHANGES acceptDisplayChanges;
386 HWC2_PFN_CREATE_LAYER createLayer;
387 HWC2_PFN_CREATE_VIRTUAL_DISPLAY createVirtualDisplay;
388 HWC2_PFN_DESTROY_LAYER destroyLayer;
389 HWC2_PFN_DESTROY_VIRTUAL_DISPLAY destroyVirtualDisplay;
390 HWC2_PFN_DUMP dump;
391 HWC2_PFN_GET_ACTIVE_CONFIG getActiveConfig;
392 HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES getChangedCompositionTypes;
393 HWC2_PFN_GET_CLIENT_TARGET_SUPPORT getClientTargetSupport;
394 HWC2_PFN_GET_COLOR_MODES getColorModes;
395 HWC2_PFN_GET_DISPLAY_ATTRIBUTE getDisplayAttribute;
396 HWC2_PFN_GET_DISPLAY_CONFIGS getDisplayConfigs;
397 HWC2_PFN_GET_DISPLAY_NAME getDisplayName;
398 HWC2_PFN_GET_DISPLAY_REQUESTS getDisplayRequests;
399 HWC2_PFN_GET_DISPLAY_TYPE getDisplayType;
400 HWC2_PFN_GET_DOZE_SUPPORT getDozeSupport;
401 HWC2_PFN_GET_HDR_CAPABILITIES getHdrCapabilities;
402 HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT getMaxVirtualDisplayCount;
403 HWC2_PFN_GET_RELEASE_FENCES getReleaseFences;
404 HWC2_PFN_PRESENT_DISPLAY presentDisplay;
405 HWC2_PFN_REGISTER_CALLBACK registerCallback;
406 HWC2_PFN_SET_ACTIVE_CONFIG setActiveConfig;
407 HWC2_PFN_SET_CLIENT_TARGET setClientTarget;
408 HWC2_PFN_SET_COLOR_MODE setColorMode;
409 HWC2_PFN_SET_COLOR_TRANSFORM setColorTransform;
410 HWC2_PFN_SET_CURSOR_POSITION setCursorPosition;
411 HWC2_PFN_SET_LAYER_BLEND_MODE setLayerBlendMode;
412 HWC2_PFN_SET_LAYER_BUFFER setLayerBuffer;
413 HWC2_PFN_SET_LAYER_COLOR setLayerColor;
414 HWC2_PFN_SET_LAYER_COMPOSITION_TYPE setLayerCompositionType;
415 HWC2_PFN_SET_LAYER_DATASPACE setLayerDataspace;
416 HWC2_PFN_SET_LAYER_DISPLAY_FRAME setLayerDisplayFrame;
417 HWC2_PFN_SET_LAYER_PLANE_ALPHA setLayerPlaneAlpha;
418 HWC2_PFN_SET_LAYER_SIDEBAND_STREAM setLayerSidebandStream;
419 HWC2_PFN_SET_LAYER_SOURCE_CROP setLayerSourceCrop;
420 HWC2_PFN_SET_LAYER_SURFACE_DAMAGE setLayerSurfaceDamage;
421 HWC2_PFN_SET_LAYER_TRANSFORM setLayerTransform;
422 HWC2_PFN_SET_LAYER_VISIBLE_REGION setLayerVisibleRegion;
423 HWC2_PFN_SET_LAYER_Z_ORDER setLayerZOrder;
424 HWC2_PFN_SET_OUTPUT_BUFFER setOutputBuffer;
425 HWC2_PFN_SET_POWER_MODE setPowerMode;
426 HWC2_PFN_SET_VSYNC_ENABLED setVsyncEnabled;
427 HWC2_PFN_VALIDATE_DISPLAY validateDisplay;
428 } mDispatch;
429
430 // cloned buffers for a display
431 struct DisplayBuffers {
432 BufferClone ClientTarget;
433 BufferClone OutputBuffer;
434
435 std::unordered_map<Layer, BufferClone> LayerBuffers;
436 std::unordered_map<Layer, BufferClone> LayerSidebandStreams;
437 };
438
439 std::mutex mCallbackMutex;
440 sp<IComposerCallback> mCallback;
441
442 std::mutex mDisplayMutex;
443 std::unordered_map<Display, DisplayBuffers> mDisplays;
444};
445
446HwcHal::HwcHal(const hw_module_t* module)
447 : mDevice(nullptr), mDispatch()
448{
449 if (!sHandleImporter.initialize()) {
450 LOG_ALWAYS_FATAL("failed to initialize handle importer");
451 }
452
453 int status = hwc2_open(module, &mDevice);
454 if (status) {
455 LOG_ALWAYS_FATAL("failed to open hwcomposer2 device: %s",
456 strerror(-status));
457 }
458
459 initCapabilities();
460 initDispatch();
461}
462
463HwcHal::~HwcHal()
464{
465 hwc2_close(mDevice);
466 mDisplays.clear();
467 sHandleImporter.cleanup();
468}
469
470void HwcHal::initCapabilities()
471{
472 uint32_t count = 0;
473 mDevice->getCapabilities(mDevice, &count, nullptr);
474
475 std::vector<Capability> caps(count);
476 mDevice->getCapabilities(mDevice, &count, reinterpret_cast<
477 std::underlying_type<Capability>::type*>(caps.data()));
478 caps.resize(count);
479
480 mCapabilities.insert(caps.cbegin(), caps.cend());
481}
482
483template<typename T>
484void HwcHal::initDispatch(T& func, hwc2_function_descriptor_t desc)
485{
486 auto pfn = mDevice->getFunction(mDevice, desc);
487 if (!pfn) {
488 LOG_ALWAYS_FATAL("failed to get hwcomposer2 function %d", desc);
489 }
490
491 func = reinterpret_cast<T>(pfn);
492}
493
494void HwcHal::initDispatch()
495{
496 initDispatch(mDispatch.acceptDisplayChanges,
497 HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES);
498 initDispatch(mDispatch.createLayer, HWC2_FUNCTION_CREATE_LAYER);
499 initDispatch(mDispatch.createVirtualDisplay,
500 HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY);
501 initDispatch(mDispatch.destroyLayer, HWC2_FUNCTION_DESTROY_LAYER);
502 initDispatch(mDispatch.destroyVirtualDisplay,
503 HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY);
504 initDispatch(mDispatch.dump, HWC2_FUNCTION_DUMP);
505 initDispatch(mDispatch.getActiveConfig, HWC2_FUNCTION_GET_ACTIVE_CONFIG);
506 initDispatch(mDispatch.getChangedCompositionTypes,
507 HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES);
508 initDispatch(mDispatch.getClientTargetSupport,
509 HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT);
510 initDispatch(mDispatch.getColorModes, HWC2_FUNCTION_GET_COLOR_MODES);
511 initDispatch(mDispatch.getDisplayAttribute,
512 HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE);
513 initDispatch(mDispatch.getDisplayConfigs,
514 HWC2_FUNCTION_GET_DISPLAY_CONFIGS);
515 initDispatch(mDispatch.getDisplayName, HWC2_FUNCTION_GET_DISPLAY_NAME);
516 initDispatch(mDispatch.getDisplayRequests,
517 HWC2_FUNCTION_GET_DISPLAY_REQUESTS);
518 initDispatch(mDispatch.getDisplayType, HWC2_FUNCTION_GET_DISPLAY_TYPE);
519 initDispatch(mDispatch.getDozeSupport, HWC2_FUNCTION_GET_DOZE_SUPPORT);
520 initDispatch(mDispatch.getHdrCapabilities,
521 HWC2_FUNCTION_GET_HDR_CAPABILITIES);
522 initDispatch(mDispatch.getMaxVirtualDisplayCount,
523 HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT);
524 initDispatch(mDispatch.getReleaseFences,
525 HWC2_FUNCTION_GET_RELEASE_FENCES);
526 initDispatch(mDispatch.presentDisplay, HWC2_FUNCTION_PRESENT_DISPLAY);
527 initDispatch(mDispatch.registerCallback, HWC2_FUNCTION_REGISTER_CALLBACK);
528 initDispatch(mDispatch.setActiveConfig, HWC2_FUNCTION_SET_ACTIVE_CONFIG);
529 initDispatch(mDispatch.setClientTarget, HWC2_FUNCTION_SET_CLIENT_TARGET);
530 initDispatch(mDispatch.setColorMode, HWC2_FUNCTION_SET_COLOR_MODE);
531 initDispatch(mDispatch.setColorTransform,
532 HWC2_FUNCTION_SET_COLOR_TRANSFORM);
533 initDispatch(mDispatch.setCursorPosition,
534 HWC2_FUNCTION_SET_CURSOR_POSITION);
535 initDispatch(mDispatch.setLayerBlendMode,
536 HWC2_FUNCTION_SET_LAYER_BLEND_MODE);
537 initDispatch(mDispatch.setLayerBuffer, HWC2_FUNCTION_SET_LAYER_BUFFER);
538 initDispatch(mDispatch.setLayerColor, HWC2_FUNCTION_SET_LAYER_COLOR);
539 initDispatch(mDispatch.setLayerCompositionType,
540 HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE);
541 initDispatch(mDispatch.setLayerDataspace,
542 HWC2_FUNCTION_SET_LAYER_DATASPACE);
543 initDispatch(mDispatch.setLayerDisplayFrame,
544 HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME);
545 initDispatch(mDispatch.setLayerPlaneAlpha,
546 HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA);
547
548 if (hasCapability(Capability::SIDEBAND_STREAM)) {
549 initDispatch(mDispatch.setLayerSidebandStream,
550 HWC2_FUNCTION_SET_LAYER_SIDEBAND_STREAM);
551 }
552
553 initDispatch(mDispatch.setLayerSourceCrop,
554 HWC2_FUNCTION_SET_LAYER_SOURCE_CROP);
555 initDispatch(mDispatch.setLayerSurfaceDamage,
556 HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE);
557 initDispatch(mDispatch.setLayerTransform,
558 HWC2_FUNCTION_SET_LAYER_TRANSFORM);
559 initDispatch(mDispatch.setLayerVisibleRegion,
560 HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION);
561 initDispatch(mDispatch.setLayerZOrder, HWC2_FUNCTION_SET_LAYER_Z_ORDER);
562 initDispatch(mDispatch.setOutputBuffer, HWC2_FUNCTION_SET_OUTPUT_BUFFER);
563 initDispatch(mDispatch.setPowerMode, HWC2_FUNCTION_SET_POWER_MODE);
564 initDispatch(mDispatch.setVsyncEnabled, HWC2_FUNCTION_SET_VSYNC_ENABLED);
565 initDispatch(mDispatch.validateDisplay, HWC2_FUNCTION_VALIDATE_DISPLAY);
566}
567
568bool HwcHal::hasCapability(Capability capability) const
569{
570 return (mCapabilities.count(capability) > 0);
571}
572
573Return<void> HwcHal::getCapabilities(getCapabilities_cb hidl_cb)
574{
575 std::vector<Capability> caps(
576 mCapabilities.cbegin(), mCapabilities.cend());
577
578 hidl_vec<Capability> caps_reply;
579 caps_reply.setToExternal(caps.data(), caps.size());
580 hidl_cb(caps_reply);
581
582 return Void();
583}
584
585Return<void> HwcHal::dumpDebugInfo(dumpDebugInfo_cb hidl_cb)
586{
587 uint32_t len;
588 mDispatch.dump(mDevice, &len, nullptr);
589
590 std::vector<char> buf(len + 1);
591 mDispatch.dump(mDevice, &len, buf.data());
592 buf.resize(len + 1);
593 buf[len] = '\0';
594
595 hidl_string buf_reply;
596 buf_reply.setToExternal(buf.data(), len);
597 hidl_cb(buf_reply);
598
599 return Void();
600}
601
602void HwcHal::hotplugHook(hwc2_callback_data_t callbackData,
603 hwc2_display_t display, int32_t connected)
604{
605 auto hal = reinterpret_cast<HwcHal*>(callbackData);
606
607 {
608 std::lock_guard<std::mutex> lock(hal->mDisplayMutex);
609
610 if (connected == HWC2_CONNECTION_CONNECTED) {
611 hal->mDisplays.emplace(display, DisplayBuffers());
612 } else if (connected == HWC2_CONNECTION_DISCONNECTED) {
613 hal->mDisplays.erase(display);
614 }
615 }
616
617 hal->mCallback->onHotplug(display,
618 static_cast<IComposerCallback::Connection>(connected));
619}
620
621void HwcHal::refreshHook(hwc2_callback_data_t callbackData,
622 hwc2_display_t display)
623{
624 auto hal = reinterpret_cast<HwcHal*>(callbackData);
625 hal->mCallback->onRefresh(display);
626}
627
628void HwcHal::vsyncHook(hwc2_callback_data_t callbackData,
629 hwc2_display_t display, int64_t timestamp)
630{
631 auto hal = reinterpret_cast<HwcHal*>(callbackData);
632 hal->mCallback->onVsync(display, timestamp);
633}
634
635Return<void> HwcHal::registerCallback(const sp<IComposerCallback>& callback)
636{
637 std::lock_guard<std::mutex> lock(mCallbackMutex);
638
639 mCallback = callback;
640
641 mDispatch.registerCallback(mDevice, HWC2_CALLBACK_HOTPLUG, this,
642 reinterpret_cast<hwc2_function_pointer_t>(hotplugHook));
643 mDispatch.registerCallback(mDevice, HWC2_CALLBACK_REFRESH, this,
644 reinterpret_cast<hwc2_function_pointer_t>(refreshHook));
645 mDispatch.registerCallback(mDevice, HWC2_CALLBACK_VSYNC, this,
646 reinterpret_cast<hwc2_function_pointer_t>(vsyncHook));
647
648 return Void();
649}
650
651Return<uint32_t> HwcHal::getMaxVirtualDisplayCount()
652{
653 return mDispatch.getMaxVirtualDisplayCount(mDevice);
654}
655
656Return<void> HwcHal::createVirtualDisplay(uint32_t width, uint32_t height,
657 PixelFormat formatHint, createVirtualDisplay_cb hidl_cb)
658{
659 int32_t format = static_cast<int32_t>(formatHint);
660 hwc2_display_t display;
661 auto error = mDispatch.createVirtualDisplay(mDevice, width, height,
662 &format, &display);
663 if (error == HWC2_ERROR_NONE) {
664 std::lock_guard<std::mutex> lock(mDisplayMutex);
665
666 mDisplays.emplace(display, DisplayBuffers());
667 }
668
669 hidl_cb(static_cast<Error>(error), display,
670 static_cast<PixelFormat>(format));
671
672 return Void();
673}
674
675Return<Error> HwcHal::destroyVirtualDisplay(Display display)
676{
677 auto error = mDispatch.destroyVirtualDisplay(mDevice, display);
678 if (error == HWC2_ERROR_NONE) {
679 std::lock_guard<std::mutex> lock(mDisplayMutex);
680
681 mDisplays.erase(display);
682 }
683
684 return static_cast<Error>(error);
685}
686
687Return<Error> HwcHal::acceptDisplayChanges(Display display)
688{
689 auto error = mDispatch.acceptDisplayChanges(mDevice, display);
690 return static_cast<Error>(error);
691}
692
693Return<void> HwcHal::createLayer(Display display, createLayer_cb hidl_cb)
694{
695 hwc2_layer_t layer;
696 auto error = mDispatch.createLayer(mDevice, display, &layer);
697
698 hidl_cb(static_cast<Error>(error), layer);
699
700 return Void();
701}
702
703Return<Error> HwcHal::destroyLayer(Display display, Layer layer)
704{
705 auto error = mDispatch.destroyLayer(mDevice, display, layer);
Chia-I Wu0c6b7f42016-10-19 06:57:54 +0800706 if (error == HWC2_ERROR_NONE) {
707 std::lock_guard<std::mutex> lock(mDisplayMutex);
708
709 auto dpy = mDisplays.find(display);
710 dpy->second.LayerBuffers.erase(layer);
711 dpy->second.LayerSidebandStreams.erase(layer);
712 }
713
Chia-I Wu7f8d3962016-09-28 21:04:23 +0800714 return static_cast<Error>(error);
715}
716
717Return<void> HwcHal::getActiveConfig(Display display,
718 getActiveConfig_cb hidl_cb)
719{
720 hwc2_config_t config;
721 auto error = mDispatch.getActiveConfig(mDevice, display, &config);
722
723 hidl_cb(static_cast<Error>(error), config);
724
725 return Void();
726}
727
728Return<void> HwcHal::getChangedCompositionTypes(Display display,
729 getChangedCompositionTypes_cb hidl_cb)
730{
731 uint32_t count = 0;
732 auto error = mDispatch.getChangedCompositionTypes(mDevice, display,
733 &count, nullptr, nullptr);
734 if (error != HWC2_ERROR_NONE) {
735 count = 0;
736 }
737
738 std::vector<hwc2_layer_t> layers(count);
739 std::vector<Composition> types(count);
740 error = mDispatch.getChangedCompositionTypes(mDevice, display,
741 &count, layers.data(),
742 reinterpret_cast<std::underlying_type<Composition>::type*>(
743 types.data()));
744 if (error != HWC2_ERROR_NONE) {
745 count = 0;
746 }
747 layers.resize(count);
748 types.resize(count);
749
750 hidl_vec<Layer> layers_reply;
751 layers_reply.setToExternal(layers.data(), layers.size());
752
753 hidl_vec<Composition> types_reply;
754 types_reply.setToExternal(types.data(), types.size());
755
756 hidl_cb(static_cast<Error>(error), layers_reply, types_reply);
757
758 return Void();
759}
760
761Return<Error> HwcHal::getClientTargetSupport(Display display,
762 uint32_t width, uint32_t height,
763 PixelFormat format, Dataspace dataspace)
764{
765 auto error = mDispatch.getClientTargetSupport(mDevice, display,
766 width, height, static_cast<int32_t>(format),
767 static_cast<int32_t>(dataspace));
768 return static_cast<Error>(error);
769}
770
771Return<void> HwcHal::getColorModes(Display display, getColorModes_cb hidl_cb)
772{
773 uint32_t count = 0;
774 auto error = mDispatch.getColorModes(mDevice, display, &count, nullptr);
775 if (error != HWC2_ERROR_NONE) {
776 count = 0;
777 }
778
779 std::vector<ColorMode> modes(count);
780 error = mDispatch.getColorModes(mDevice, display, &count,
781 reinterpret_cast<std::underlying_type<ColorMode>::type*>(
782 modes.data()));
783 if (error != HWC2_ERROR_NONE) {
784 count = 0;
785 }
786 modes.resize(count);
787
788 hidl_vec<ColorMode> modes_reply;
789 modes_reply.setToExternal(modes.data(), modes.size());
790 hidl_cb(static_cast<Error>(error), modes_reply);
791
792 return Void();
793}
794
795Return<void> HwcHal::getDisplayAttribute(Display display,
796 Config config, Attribute attribute,
797 getDisplayAttribute_cb hidl_cb)
798{
799 int32_t value;
800 auto error = mDispatch.getDisplayAttribute(mDevice, display, config,
801 static_cast<int32_t>(attribute), &value);
802
803 hidl_cb(static_cast<Error>(error), value);
804
805 return Void();
806}
807
808Return<void> HwcHal::getDisplayConfigs(Display display,
809 getDisplayConfigs_cb hidl_cb)
810{
811 uint32_t count = 0;
812 auto error = mDispatch.getDisplayConfigs(mDevice, display,
813 &count, nullptr);
814 if (error != HWC2_ERROR_NONE) {
815 count = 0;
816 }
817
818 std::vector<hwc2_config_t> configs(count);
819 error = mDispatch.getDisplayConfigs(mDevice, display,
820 &count, configs.data());
821 if (error != HWC2_ERROR_NONE) {
822 count = 0;
823 }
824 configs.resize(count);
825
826 hidl_vec<Config> configs_reply;
827 configs_reply.setToExternal(configs.data(), configs.size());
828 hidl_cb(static_cast<Error>(error), configs_reply);
829
830 return Void();
831}
832
833Return<void> HwcHal::getDisplayName(Display display,
834 getDisplayName_cb hidl_cb)
835{
836 uint32_t count = 0;
837 auto error = mDispatch.getDisplayName(mDevice, display, &count, nullptr);
838 if (error != HWC2_ERROR_NONE) {
839 count = 0;
840 }
841
842 std::vector<char> name(count + 1);
843 error = mDispatch.getDisplayName(mDevice, display, &count, name.data());
844 if (error != HWC2_ERROR_NONE) {
845 count = 0;
846 }
847 name.resize(count + 1);
848 name[count] = '\0';
849
850 hidl_string name_reply;
851 name_reply.setToExternal(name.data(), count);
852 hidl_cb(static_cast<Error>(error), name_reply);
853
854 return Void();
855}
856
857Return<void> HwcHal::getDisplayRequests(Display display,
858 getDisplayRequests_cb hidl_cb)
859{
860 int32_t display_reqs;
861 uint32_t count = 0;
862 auto error = mDispatch.getDisplayRequests(mDevice, display,
863 &display_reqs, &count, nullptr, nullptr);
864 if (error != HWC2_ERROR_NONE) {
865 count = 0;
866 }
867
868 std::vector<hwc2_layer_t> layers(count);
869 std::vector<int32_t> layer_reqs(count);
870 error = mDispatch.getDisplayRequests(mDevice, display,
871 &display_reqs, &count, layers.data(), layer_reqs.data());
872 if (error != HWC2_ERROR_NONE) {
873 count = 0;
874 }
875 layers.resize(count);
876 layer_reqs.resize(count);
877
878 hidl_vec<Layer> layers_reply;
879 layers_reply.setToExternal(layers.data(), layers.size());
880
881 hidl_vec<uint32_t> layer_reqs_reply;
882 layer_reqs_reply.setToExternal(
883 reinterpret_cast<uint32_t*>(layer_reqs.data()),
884 layer_reqs.size());
885
886 hidl_cb(static_cast<Error>(error), display_reqs,
887 layers_reply, layer_reqs_reply);
888
889 return Void();
890}
891
892Return<void> HwcHal::getDisplayType(Display display,
893 getDisplayType_cb hidl_cb)
894{
895 int32_t type;
896 auto error = mDispatch.getDisplayType(mDevice, display, &type);
897
898 hidl_cb(static_cast<Error>(error), static_cast<DisplayType>(type));
899
900 return Void();
901}
902
903Return<void> HwcHal::getDozeSupport(Display display,
904 getDozeSupport_cb hidl_cb)
905{
906 int32_t support;
907 auto error = mDispatch.getDozeSupport(mDevice, display, &support);
908
909 hidl_cb(static_cast<Error>(error), support);
910
911 return Void();
912}
913
914Return<void> HwcHal::getHdrCapabilities(Display display,
915 getHdrCapabilities_cb hidl_cb)
916{
917 float max_lumi, max_avg_lumi, min_lumi;
918 uint32_t count = 0;
919 auto error = mDispatch.getHdrCapabilities(mDevice, display,
920 &count, nullptr, &max_lumi, &max_avg_lumi, &min_lumi);
921 if (error != HWC2_ERROR_NONE) {
922 count = 0;
923 }
924
925 std::vector<Hdr> types(count);
926 error = mDispatch.getHdrCapabilities(mDevice, display, &count,
927 reinterpret_cast<std::underlying_type<Hdr>::type*>(types.data()),
928 &max_lumi, &max_avg_lumi, &min_lumi);
929 if (error != HWC2_ERROR_NONE) {
930 count = 0;
931 }
932 types.resize(count);
933
934 hidl_vec<Hdr> types_reply;
935 types_reply.setToExternal(types.data(), types.size());
936 hidl_cb(static_cast<Error>(error), types_reply,
937 max_lumi, max_avg_lumi, min_lumi);
938
939 return Void();
940}
941
942Return<void> HwcHal::getReleaseFences(Display display,
943 getReleaseFences_cb hidl_cb)
944{
945 uint32_t count = 0;
946 auto error = mDispatch.getReleaseFences(mDevice, display,
947 &count, nullptr, nullptr);
948 if (error != HWC2_ERROR_NONE) {
949 count = 0;
950 }
951
952 std::vector<hwc2_layer_t> layers(count);
953 std::vector<int32_t> fences(count);
954 error = mDispatch.getReleaseFences(mDevice, display,
955 &count, layers.data(), fences.data());
956 if (error != HWC2_ERROR_NONE) {
957 count = 0;
958 }
959 layers.resize(count);
960 fences.resize(count);
961
962 // filter out layers with release fence -1
963 std::vector<hwc2_layer_t> filtered_layers;
964 std::vector<int> filtered_fences;
965 for (size_t i = 0; i < layers.size(); i++) {
966 if (fences[i] >= 0) {
967 filtered_layers.push_back(layers[i]);
968 filtered_fences.push_back(fences[i]);
969 }
970 }
971
972 hidl_vec<Layer> layers_reply;
973 native_handle_t* fences_reply =
974 native_handle_create(filtered_fences.size(), 0);
975 if (fences_reply) {
976 layers_reply.setToExternal(filtered_layers.data(),
977 filtered_layers.size());
978 memcpy(fences_reply->data, filtered_fences.data(),
979 sizeof(int) * filtered_fences.size());
980
981 hidl_cb(static_cast<Error>(error), layers_reply, fences_reply);
982
983 native_handle_close(fences_reply);
984 native_handle_delete(fences_reply);
985 } else {
986 NATIVE_HANDLE_DECLARE_STORAGE(fences_storage, 0, 0);
987 fences_reply = native_handle_init(fences_storage, 0, 0);
988
989 hidl_cb(Error::NO_RESOURCES, layers_reply, fences_reply);
990
991 for (auto fence : filtered_fences) {
992 close(fence);
993 }
994 }
995
996 return Void();
997}
998
999Return<void> HwcHal::presentDisplay(Display display,
1000 presentDisplay_cb hidl_cb)
1001{
1002 int32_t fence = -1;
1003 auto error = mDispatch.presentDisplay(mDevice, display, &fence);
1004
1005 NATIVE_HANDLE_DECLARE_STORAGE(fence_storage, 1, 0);
1006 native_handle_t* fence_reply;
1007 if (fence >= 0) {
1008 fence_reply = native_handle_init(fence_storage, 1, 0);
1009 fence_reply->data[0] = fence;
1010 } else {
1011 fence_reply = native_handle_init(fence_storage, 0, 0);
1012 }
1013
1014 hidl_cb(static_cast<Error>(error), fence_reply);
1015
1016 if (fence >= 0) {
1017 close(fence);
1018 }
1019
1020 return Void();
1021}
1022
1023Return<Error> HwcHal::setActiveConfig(Display display, Config config)
1024{
1025 auto error = mDispatch.setActiveConfig(mDevice, display, config);
1026 return static_cast<Error>(error);
1027}
1028
1029Return<Error> HwcHal::setClientTarget(Display display,
1030 const native_handle_t* target,
1031 const native_handle_t* acquireFence,
1032 Dataspace dataspace, const hidl_vec<Rect>& damage)
1033{
1034 if (!sHandleImporter.importBuffer(target)) {
1035 return Error::NO_RESOURCES;
1036 }
1037
1038 int32_t fence;
1039 if (!sHandleImporter.importFence(acquireFence, fence)) {
1040 sHandleImporter.freeBuffer(target);
1041 return Error::NO_RESOURCES;
1042 }
1043
1044 hwc_region_t damage_region = { damage.size(),
1045 reinterpret_cast<const hwc_rect_t*>(&damage[0]) };
1046
1047 int32_t error = mDispatch.setClientTarget(mDevice, display,
1048 target, fence, static_cast<int32_t>(dataspace),
1049 damage_region);
1050 if (error == HWC2_ERROR_NONE) {
1051 std::lock_guard<std::mutex> lock(mDisplayMutex);
1052
1053 auto dpy = mDisplays.find(display);
1054 dpy->second.ClientTarget = target;
1055 } else {
1056 sHandleImporter.freeBuffer(target);
1057 sHandleImporter.closeFence(fence);
1058 }
1059
1060 return static_cast<Error>(error);
1061}
1062
1063Return<Error> HwcHal::setColorMode(Display display, ColorMode mode)
1064{
1065 auto error = mDispatch.setColorMode(mDevice, display,
1066 static_cast<int32_t>(mode));
1067 return static_cast<Error>(error);
1068}
1069
1070Return<Error> HwcHal::setColorTransform(Display display,
1071 const hidl_vec<float>& matrix, ColorTransform hint)
1072{
1073 auto error = mDispatch.setColorTransform(mDevice, display,
1074 &matrix[0], static_cast<int32_t>(hint));
1075 return static_cast<Error>(error);
1076}
1077
1078Return<Error> HwcHal::setOutputBuffer(Display display,
1079 const native_handle_t* buffer,
1080 const native_handle_t* releaseFence)
1081{
1082 if (!sHandleImporter.importBuffer(buffer)) {
1083 return Error::NO_RESOURCES;
1084 }
1085
1086 int32_t fence;
1087 if (!sHandleImporter.importFence(releaseFence, fence)) {
1088 sHandleImporter.freeBuffer(buffer);
1089 return Error::NO_RESOURCES;
1090 }
1091
1092 int32_t error = mDispatch.setOutputBuffer(mDevice,
1093 display, buffer, fence);
1094 if (error == HWC2_ERROR_NONE) {
1095 std::lock_guard<std::mutex> lock(mDisplayMutex);
1096
1097 auto dpy = mDisplays.find(display);
1098 dpy->second.OutputBuffer = buffer;
1099 } else {
1100 sHandleImporter.freeBuffer(buffer);
1101 }
1102
1103 // unlike in setClientTarget, fence is owned by us and is always closed
1104 sHandleImporter.closeFence(fence);
1105
1106 return static_cast<Error>(error);
1107}
1108
1109Return<Error> HwcHal::setPowerMode(Display display, PowerMode mode)
1110{
1111 auto error = mDispatch.setPowerMode(mDevice, display,
1112 static_cast<int32_t>(mode));
1113 return static_cast<Error>(error);
1114}
1115
1116Return<Error> HwcHal::setVsyncEnabled(Display display,
1117 Vsync enabled)
1118{
1119 auto error = mDispatch.setVsyncEnabled(mDevice, display,
1120 static_cast<int32_t>(enabled));
1121 return static_cast<Error>(error);
1122}
1123
1124Return<void> HwcHal::validateDisplay(Display display,
1125 validateDisplay_cb hidl_cb)
1126{
1127 uint32_t types_count = 0;
1128 uint32_t reqs_count = 0;
1129 auto error = mDispatch.validateDisplay(mDevice, display,
1130 &types_count, &reqs_count);
1131
1132 hidl_cb(static_cast<Error>(error), types_count, reqs_count);
1133
1134 return Void();
1135}
1136
1137Return<Error> HwcHal::setCursorPosition(Display display,
1138 Layer layer, int32_t x, int32_t y)
1139{
1140 auto error = mDispatch.setCursorPosition(mDevice, display, layer, x, y);
1141 return static_cast<Error>(error);
1142}
1143
1144Return<Error> HwcHal::setLayerBuffer(Display display,
1145 Layer layer, const native_handle_t* buffer,
1146 const native_handle_t* acquireFence)
1147{
1148 if (!sHandleImporter.importBuffer(buffer)) {
1149 return Error::NO_RESOURCES;
1150 }
1151
1152 int32_t fence;
1153 if (!sHandleImporter.importFence(acquireFence, fence)) {
1154 sHandleImporter.freeBuffer(buffer);
1155 return Error::NO_RESOURCES;
1156 }
1157
1158 int32_t error = mDispatch.setLayerBuffer(mDevice,
1159 display, layer, buffer, fence);
1160 if (error == HWC2_ERROR_NONE) {
1161 std::lock_guard<std::mutex> lock(mDisplayMutex);
1162
1163 auto dpy = mDisplays.find(display);
1164 dpy->second.LayerBuffers[layer] = buffer;
1165 } else {
1166 sHandleImporter.freeBuffer(buffer);
1167 sHandleImporter.closeFence(fence);
1168 }
1169
1170 return static_cast<Error>(error);
1171}
1172
1173Return<Error> HwcHal::setLayerSurfaceDamage(Display display,
1174 Layer layer, const hidl_vec<Rect>& damage)
1175{
1176 hwc_region_t damage_region = { damage.size(),
1177 reinterpret_cast<const hwc_rect_t*>(&damage[0]) };
1178
1179 auto error = mDispatch.setLayerSurfaceDamage(mDevice, display, layer,
1180 damage_region);
1181 return static_cast<Error>(error);
1182}
1183
1184Return<Error> HwcHal::setLayerBlendMode(Display display,
1185 Layer layer, BlendMode mode)
1186{
1187 auto error = mDispatch.setLayerBlendMode(mDevice, display, layer,
1188 static_cast<int32_t>(mode));
1189 return static_cast<Error>(error);
1190}
1191
1192Return<Error> HwcHal::setLayerColor(Display display,
1193 Layer layer, const Color& color)
1194{
1195 hwc_color_t hwc_color{color.r, color.g, color.b, color.a};
1196 auto error = mDispatch.setLayerColor(mDevice, display, layer, hwc_color);
1197 return static_cast<Error>(error);
1198}
1199
1200Return<Error> HwcHal::setLayerCompositionType(Display display,
1201 Layer layer, Composition type)
1202{
1203 auto error = mDispatch.setLayerCompositionType(mDevice, display, layer,
1204 static_cast<int32_t>(type));
1205 return static_cast<Error>(error);
1206}
1207
1208Return<Error> HwcHal::setLayerDataspace(Display display,
1209 Layer layer, Dataspace dataspace)
1210{
1211 auto error = mDispatch.setLayerDataspace(mDevice, display, layer,
1212 static_cast<int32_t>(dataspace));
1213 return static_cast<Error>(error);
1214}
1215
1216Return<Error> HwcHal::setLayerDisplayFrame(Display display,
1217 Layer layer, const Rect& frame)
1218{
1219 hwc_rect_t hwc_frame{frame.left, frame.top, frame.right, frame.bottom};
1220 auto error = mDispatch.setLayerDisplayFrame(mDevice, display, layer,
1221 hwc_frame);
1222 return static_cast<Error>(error);
1223}
1224
1225Return<Error> HwcHal::setLayerPlaneAlpha(Display display,
1226 Layer layer, float alpha)
1227{
1228 auto error = mDispatch.setLayerPlaneAlpha(mDevice, display, layer, alpha);
1229 return static_cast<Error>(error);
1230}
1231
1232Return<Error> HwcHal::setLayerSidebandStream(Display display,
1233 Layer layer, const native_handle_t* stream)
1234{
1235 if (!sHandleImporter.importBuffer(stream)) {
1236 return Error::NO_RESOURCES;
1237 }
1238
1239 int32_t error = mDispatch.setLayerSidebandStream(mDevice,
1240 display, layer, stream);
1241 if (error == HWC2_ERROR_NONE) {
1242 std::lock_guard<std::mutex> lock(mDisplayMutex);
1243
1244 auto dpy = mDisplays.find(display);
1245 dpy->second.LayerSidebandStreams[layer] = stream;
1246 } else {
1247 sHandleImporter.freeBuffer(stream);
1248 }
1249
1250 return static_cast<Error>(error);
1251}
1252
1253Return<Error> HwcHal::setLayerSourceCrop(Display display,
1254 Layer layer, const FRect& crop)
1255{
1256 hwc_frect_t hwc_crop{crop.left, crop.top, crop.right, crop.bottom};
1257 auto error = mDispatch.setLayerSourceCrop(mDevice, display, layer,
1258 hwc_crop);
1259 return static_cast<Error>(error);
1260}
1261
1262Return<Error> HwcHal::setLayerTransform(Display display,
1263 Layer layer, Transform transform)
1264{
1265 auto error = mDispatch.setLayerTransform(mDevice, display, layer,
1266 static_cast<int32_t>(transform));
1267 return static_cast<Error>(error);
1268}
1269
1270Return<Error> HwcHal::setLayerVisibleRegion(Display display,
1271 Layer layer, const hidl_vec<Rect>& visible)
1272{
1273 hwc_region_t visible_region = { visible.size(),
1274 reinterpret_cast<const hwc_rect_t*>(&visible[0]) };
1275
1276 auto error = mDispatch.setLayerVisibleRegion(mDevice, display, layer,
1277 visible_region);
1278 return static_cast<Error>(error);
1279}
1280
1281Return<Error> HwcHal::setLayerZOrder(Display display,
1282 Layer layer, uint32_t z)
1283{
1284 auto error = mDispatch.setLayerZOrder(mDevice, display, layer, z);
1285 return static_cast<Error>(error);
1286}
1287
1288IComposer* HIDL_FETCH_IComposer(const char*)
1289{
1290 const hw_module_t* module;
1291 int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &module);
1292 if (err) {
1293 ALOGE("failed to get hwcomposer module");
1294 return nullptr;
1295 }
1296
1297 return new HwcHal(module);
1298}
1299
1300} // namespace implementation
1301} // namespace V2_1
1302} // namespace composer
1303} // namespace graphics
1304} // namespace hardware
1305} // namespace android