Automatic mk -> bp.
[android/platform-hardware-interfaces.git] / graphics / composer / 2.1 / default / Hwc.cpp
1 /*
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  */
17 #define LOG_TAG "HwcPassthrough"
19 #include "Hwc.h"
21 #include <type_traits>
22 #include <log/log.h>
24 #include "ComposerClient.h"
25 #include "hardware/hwcomposer.h"
26 #include "hwc2on1adapter/HWC2On1Adapter.h"
28 namespace android {
29 namespace hardware {
30 namespace graphics {
31 namespace composer {
32 namespace V2_1 {
33 namespace implementation {
36 HwcHal::HwcHal(const hw_module_t* module)
37     : mDevice(nullptr), mDispatch(), mAdapter()
38 {
39     // Determine what kind of module is available (HWC2 vs HWC1.X).
40     hw_device_t* device = nullptr;
41     int error = module->methods->open(module, HWC_HARDWARE_COMPOSER, &device);
42     if (error != 0) {
43         ALOGE("Failed to open HWC device (%s), aborting", strerror(-error));
44         abort();
45     }
46     uint32_t majorVersion = (device->version >> 24) & 0xF;
48     // If we don't have a HWC2, we need to wrap whatever we have in an adapter.
49     if (majorVersion != 2) {
50         uint32_t minorVersion = device->version & HARDWARE_API_VERSION_2_MAJ_MIN_MASK;
51         minorVersion = (minorVersion >> 16) & 0xF;
52         ALOGI("Found HWC implementation v%d.%d", majorVersion, minorVersion);
53         if (minorVersion < 1) {
54             ALOGE("Cannot adapt to HWC version %d.%d. Minimum supported is 1.1",
55                   majorVersion, minorVersion);
56             abort();
57         }
58         mAdapter = std::make_unique<HWC2On1Adapter>(
59                 reinterpret_cast<hwc_composer_device_1*>(device));
61         // Place the adapter in front of the device module.
62         mDevice = mAdapter.get();
63     } else {
64         mDevice = reinterpret_cast<hwc2_device_t*>(device);
65     }
67     initCapabilities();
68     if (majorVersion >= 2 &&
69         hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) {
70         ALOGE("Present fence must be reliable from HWC2 on.");
71         abort();
72     }
74     initDispatch();
75 }
77 HwcHal::~HwcHal()
78 {
79     hwc2_close(mDevice);
80 }
82 void HwcHal::initCapabilities()
83 {
84     uint32_t count = 0;
85     mDevice->getCapabilities(mDevice, &count, nullptr);
87     std::vector<Capability> caps(count);
88     mDevice->getCapabilities(mDevice, &count, reinterpret_cast<
89               std::underlying_type<Capability>::type*>(caps.data()));
90     caps.resize(count);
92     mCapabilities.insert(caps.cbegin(), caps.cend());
93 }
95 template<typename T>
96 void HwcHal::initDispatch(hwc2_function_descriptor_t desc, T* outPfn)
97 {
98     auto pfn = mDevice->getFunction(mDevice, desc);
99     if (!pfn) {
100         LOG_ALWAYS_FATAL("failed to get hwcomposer2 function %d", desc);
101     }
103     *outPfn = reinterpret_cast<T>(pfn);
106 void HwcHal::initDispatch()
108     initDispatch(HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES,
109             &mDispatch.acceptDisplayChanges);
110     initDispatch(HWC2_FUNCTION_CREATE_LAYER, &mDispatch.createLayer);
111     initDispatch(HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY,
112             &mDispatch.createVirtualDisplay);
113     initDispatch(HWC2_FUNCTION_DESTROY_LAYER, &mDispatch.destroyLayer);
114     initDispatch(HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY,
115             &mDispatch.destroyVirtualDisplay);
116     initDispatch(HWC2_FUNCTION_DUMP, &mDispatch.dump);
117     initDispatch(HWC2_FUNCTION_GET_ACTIVE_CONFIG, &mDispatch.getActiveConfig);
118     initDispatch(HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES,
119             &mDispatch.getChangedCompositionTypes);
120     initDispatch(HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT,
121             &mDispatch.getClientTargetSupport);
122     initDispatch(HWC2_FUNCTION_GET_COLOR_MODES, &mDispatch.getColorModes);
123     initDispatch(HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE,
124             &mDispatch.getDisplayAttribute);
125     initDispatch(HWC2_FUNCTION_GET_DISPLAY_CONFIGS,
126             &mDispatch.getDisplayConfigs);
127     initDispatch(HWC2_FUNCTION_GET_DISPLAY_NAME, &mDispatch.getDisplayName);
128     initDispatch(HWC2_FUNCTION_GET_DISPLAY_REQUESTS,
129             &mDispatch.getDisplayRequests);
130     initDispatch(HWC2_FUNCTION_GET_DISPLAY_TYPE, &mDispatch.getDisplayType);
131     initDispatch(HWC2_FUNCTION_GET_DOZE_SUPPORT, &mDispatch.getDozeSupport);
132     initDispatch(HWC2_FUNCTION_GET_HDR_CAPABILITIES,
133             &mDispatch.getHdrCapabilities);
134     initDispatch(HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT,
135             &mDispatch.getMaxVirtualDisplayCount);
136     initDispatch(HWC2_FUNCTION_GET_RELEASE_FENCES,
137             &mDispatch.getReleaseFences);
138     initDispatch(HWC2_FUNCTION_PRESENT_DISPLAY, &mDispatch.presentDisplay);
139     initDispatch(HWC2_FUNCTION_REGISTER_CALLBACK,
140             &mDispatch.registerCallback);
141     initDispatch(HWC2_FUNCTION_SET_ACTIVE_CONFIG, &mDispatch.setActiveConfig);
142     initDispatch(HWC2_FUNCTION_SET_CLIENT_TARGET, &mDispatch.setClientTarget);
143     initDispatch(HWC2_FUNCTION_SET_COLOR_MODE, &mDispatch.setColorMode);
144     initDispatch(HWC2_FUNCTION_SET_COLOR_TRANSFORM,
145             &mDispatch.setColorTransform);
146     initDispatch(HWC2_FUNCTION_SET_CURSOR_POSITION,
147             &mDispatch.setCursorPosition);
148     initDispatch(HWC2_FUNCTION_SET_LAYER_BLEND_MODE,
149             &mDispatch.setLayerBlendMode);
150     initDispatch(HWC2_FUNCTION_SET_LAYER_BUFFER, &mDispatch.setLayerBuffer);
151     initDispatch(HWC2_FUNCTION_SET_LAYER_COLOR, &mDispatch.setLayerColor);
152     initDispatch(HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE,
153             &mDispatch.setLayerCompositionType);
154     initDispatch(HWC2_FUNCTION_SET_LAYER_DATASPACE,
155             &mDispatch.setLayerDataspace);
156     initDispatch(HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME,
157             &mDispatch.setLayerDisplayFrame);
158     initDispatch(HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA,
159             &mDispatch.setLayerPlaneAlpha);
161     if (hasCapability(Capability::SIDEBAND_STREAM)) {
162         initDispatch(HWC2_FUNCTION_SET_LAYER_SIDEBAND_STREAM,
163                 &mDispatch.setLayerSidebandStream);
164     }
166     initDispatch(HWC2_FUNCTION_SET_LAYER_SOURCE_CROP,
167             &mDispatch.setLayerSourceCrop);
168     initDispatch(HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE,
169             &mDispatch.setLayerSurfaceDamage);
170     initDispatch(HWC2_FUNCTION_SET_LAYER_TRANSFORM,
171             &mDispatch.setLayerTransform);
172     initDispatch(HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION,
173             &mDispatch.setLayerVisibleRegion);
174     initDispatch(HWC2_FUNCTION_SET_LAYER_Z_ORDER, &mDispatch.setLayerZOrder);
175     initDispatch(HWC2_FUNCTION_SET_OUTPUT_BUFFER, &mDispatch.setOutputBuffer);
176     initDispatch(HWC2_FUNCTION_SET_POWER_MODE, &mDispatch.setPowerMode);
177     initDispatch(HWC2_FUNCTION_SET_VSYNC_ENABLED, &mDispatch.setVsyncEnabled);
178     initDispatch(HWC2_FUNCTION_VALIDATE_DISPLAY, &mDispatch.validateDisplay);
181 bool HwcHal::hasCapability(Capability capability) const
183     return (mCapabilities.count(capability) > 0);
186 Return<void> HwcHal::getCapabilities(getCapabilities_cb hidl_cb)
188     std::vector<Capability> caps(
189             mCapabilities.cbegin(), mCapabilities.cend());
191     hidl_vec<Capability> caps_reply;
192     caps_reply.setToExternal(caps.data(), caps.size());
193     hidl_cb(caps_reply);
195     return Void();
198 Return<void> HwcHal::dumpDebugInfo(dumpDebugInfo_cb hidl_cb)
200     uint32_t len = 0;
201     mDispatch.dump(mDevice, &len, nullptr);
203     std::vector<char> buf(len + 1);
204     mDispatch.dump(mDevice, &len, buf.data());
205     buf.resize(len + 1);
206     buf[len] = '\0';
208     hidl_string buf_reply;
209     buf_reply.setToExternal(buf.data(), len);
210     hidl_cb(buf_reply);
212     return Void();
215 Return<void> HwcHal::createClient(createClient_cb hidl_cb)
217     Error err = Error::NONE;
218     sp<ComposerClient> client;
220     {
221         std::lock_guard<std::mutex> lock(mClientMutex);
223         // only one client is allowed
224         if (mClient == nullptr) {
225             client = new ComposerClient(*this);
226             client->initialize();
227             mClient = client;
228         } else {
229             err = Error::NO_RESOURCES;
230         }
231     }
233     hidl_cb(err, client);
235     return Void();
238 sp<ComposerClient> HwcHal::getClient()
240     std::lock_guard<std::mutex> lock(mClientMutex);
241     return (mClient != nullptr) ? mClient.promote() : nullptr;
244 void HwcHal::removeClient()
246     std::lock_guard<std::mutex> lock(mClientMutex);
247     mClient = nullptr;
250 void HwcHal::hotplugHook(hwc2_callback_data_t callbackData,
251         hwc2_display_t display, int32_t connected)
253     auto hal = reinterpret_cast<HwcHal*>(callbackData);
254     auto client = hal->getClient();
255     if (client != nullptr) {
256         client->onHotplug(display,
257                 static_cast<IComposerCallback::Connection>(connected));
258     }
261 void HwcHal::refreshHook(hwc2_callback_data_t callbackData,
262         hwc2_display_t display)
264     auto hal = reinterpret_cast<HwcHal*>(callbackData);
265     auto client = hal->getClient();
266     if (client != nullptr) {
267         client->onRefresh(display);
268     }
271 void HwcHal::vsyncHook(hwc2_callback_data_t callbackData,
272         hwc2_display_t display, int64_t timestamp)
274     auto hal = reinterpret_cast<HwcHal*>(callbackData);
275     auto client = hal->getClient();
276     if (client != nullptr) {
277         client->onVsync(display, timestamp);
278     }
281 void HwcHal::enableCallback(bool enable)
283     if (enable) {
284         mDispatch.registerCallback(mDevice, HWC2_CALLBACK_HOTPLUG, this,
285                 reinterpret_cast<hwc2_function_pointer_t>(hotplugHook));
286         mDispatch.registerCallback(mDevice, HWC2_CALLBACK_REFRESH, this,
287                 reinterpret_cast<hwc2_function_pointer_t>(refreshHook));
288         mDispatch.registerCallback(mDevice, HWC2_CALLBACK_VSYNC, this,
289                 reinterpret_cast<hwc2_function_pointer_t>(vsyncHook));
290     } else {
291         mDispatch.registerCallback(mDevice, HWC2_CALLBACK_HOTPLUG, this,
292                 nullptr);
293         mDispatch.registerCallback(mDevice, HWC2_CALLBACK_REFRESH, this,
294                 nullptr);
295         mDispatch.registerCallback(mDevice, HWC2_CALLBACK_VSYNC, this,
296                 nullptr);
297     }
300 uint32_t HwcHal::getMaxVirtualDisplayCount()
302     return mDispatch.getMaxVirtualDisplayCount(mDevice);
305 Error HwcHal::createVirtualDisplay(uint32_t width, uint32_t height,
306     PixelFormat* format, Display* outDisplay)
308     int32_t hwc_format = static_cast<int32_t>(*format);
309     int32_t err = mDispatch.createVirtualDisplay(mDevice, width, height,
310             &hwc_format, outDisplay);
311     *format = static_cast<PixelFormat>(hwc_format);
313     return static_cast<Error>(err);
316 Error HwcHal::destroyVirtualDisplay(Display display)
318     int32_t err = mDispatch.destroyVirtualDisplay(mDevice, display);
319     return static_cast<Error>(err);
322 Error HwcHal::createLayer(Display display, Layer* outLayer)
324     int32_t err = mDispatch.createLayer(mDevice, display, outLayer);
325     return static_cast<Error>(err);
328 Error HwcHal::destroyLayer(Display display, Layer layer)
330     int32_t err = mDispatch.destroyLayer(mDevice, display, layer);
331     return static_cast<Error>(err);
334 Error HwcHal::getActiveConfig(Display display, Config* outConfig)
336     int32_t err = mDispatch.getActiveConfig(mDevice, display, outConfig);
337     return static_cast<Error>(err);
340 Error HwcHal::getClientTargetSupport(Display display,
341         uint32_t width, uint32_t height,
342         PixelFormat format, Dataspace dataspace)
344     int32_t err = mDispatch.getClientTargetSupport(mDevice, display,
345             width, height, static_cast<int32_t>(format),
346             static_cast<int32_t>(dataspace));
347     return static_cast<Error>(err);
350 Error HwcHal::getColorModes(Display display, hidl_vec<ColorMode>* outModes)
352     uint32_t count = 0;
353     int32_t err = mDispatch.getColorModes(mDevice, display, &count, nullptr);
354     if (err != HWC2_ERROR_NONE) {
355         return static_cast<Error>(err);
356     }
358     outModes->resize(count);
359     err = mDispatch.getColorModes(mDevice, display, &count,
360             reinterpret_cast<std::underlying_type<ColorMode>::type*>(
361                 outModes->data()));
362     if (err != HWC2_ERROR_NONE) {
363         *outModes = hidl_vec<ColorMode>();
364         return static_cast<Error>(err);
365     }
367     return Error::NONE;
370 Error HwcHal::getDisplayAttribute(Display display, Config config,
371         IComposerClient::Attribute attribute, int32_t* outValue)
373     int32_t err = mDispatch.getDisplayAttribute(mDevice, display, config,
374             static_cast<int32_t>(attribute), outValue);
375     return static_cast<Error>(err);
378 Error HwcHal::getDisplayConfigs(Display display, hidl_vec<Config>* outConfigs)
380     uint32_t count = 0;
381     int32_t err = mDispatch.getDisplayConfigs(mDevice, display,
382             &count, nullptr);
383     if (err != HWC2_ERROR_NONE) {
384         return static_cast<Error>(err);
385     }
387     outConfigs->resize(count);
388     err = mDispatch.getDisplayConfigs(mDevice, display,
389             &count, outConfigs->data());
390     if (err != HWC2_ERROR_NONE) {
391         *outConfigs = hidl_vec<Config>();
392         return static_cast<Error>(err);
393     }
395     return Error::NONE;
398 Error HwcHal::getDisplayName(Display display, hidl_string* outName)
400     uint32_t count = 0;
401     int32_t err = mDispatch.getDisplayName(mDevice, display, &count, nullptr);
402     if (err != HWC2_ERROR_NONE) {
403         return static_cast<Error>(err);
404     }
406     std::vector<char> buf(count + 1);
407     err = mDispatch.getDisplayName(mDevice, display, &count, buf.data());
408     if (err != HWC2_ERROR_NONE) {
409         return static_cast<Error>(err);
410     }
411     buf.resize(count + 1);
412     buf[count] = '\0';
414     *outName = buf.data();
416     return Error::NONE;
419 Error HwcHal::getDisplayType(Display display,
420         IComposerClient::DisplayType* outType)
422     int32_t hwc_type = HWC2_DISPLAY_TYPE_INVALID;
423     int32_t err = mDispatch.getDisplayType(mDevice, display, &hwc_type);
424     *outType = static_cast<IComposerClient::DisplayType>(hwc_type);
426     return static_cast<Error>(err);
429 Error HwcHal::getDozeSupport(Display display, bool* outSupport)
431     int32_t hwc_support = 0;
432     int32_t err = mDispatch.getDozeSupport(mDevice, display, &hwc_support);
433     *outSupport = hwc_support;
435     return static_cast<Error>(err);
438 Error HwcHal::getHdrCapabilities(Display display, hidl_vec<Hdr>* outTypes,
439         float* outMaxLuminance, float* outMaxAverageLuminance,
440         float* outMinLuminance)
442     uint32_t count = 0;
443     int32_t err = mDispatch.getHdrCapabilities(mDevice, display, &count,
444             nullptr, outMaxLuminance, outMaxAverageLuminance,
445             outMinLuminance);
446     if (err != HWC2_ERROR_NONE) {
447         return static_cast<Error>(err);
448     }
450     outTypes->resize(count);
451     err = mDispatch.getHdrCapabilities(mDevice, display, &count,
452             reinterpret_cast<std::underlying_type<Hdr>::type*>(
453                 outTypes->data()), outMaxLuminance,
454             outMaxAverageLuminance, outMinLuminance);
455     if (err != HWC2_ERROR_NONE) {
456         *outTypes = hidl_vec<Hdr>();
457         return static_cast<Error>(err);
458     }
460     return Error::NONE;
463 Error HwcHal::setActiveConfig(Display display, Config config)
465     int32_t err = mDispatch.setActiveConfig(mDevice, display, config);
466     return static_cast<Error>(err);
469 Error HwcHal::setColorMode(Display display, ColorMode mode)
471     int32_t err = mDispatch.setColorMode(mDevice, display,
472             static_cast<int32_t>(mode));
473     return static_cast<Error>(err);
476 Error HwcHal::setPowerMode(Display display, IComposerClient::PowerMode mode)
478     int32_t err = mDispatch.setPowerMode(mDevice, display,
479             static_cast<int32_t>(mode));
480     return static_cast<Error>(err);
483 Error HwcHal::setVsyncEnabled(Display display, IComposerClient::Vsync enabled)
485     int32_t err = mDispatch.setVsyncEnabled(mDevice, display,
486             static_cast<int32_t>(enabled));
487     return static_cast<Error>(err);
490 Error HwcHal::setColorTransform(Display display, const float* matrix,
491         int32_t hint)
493     int32_t err = mDispatch.setColorTransform(mDevice, display, matrix, hint);
494     return static_cast<Error>(err);
497 Error HwcHal::setClientTarget(Display display, buffer_handle_t target,
498         int32_t acquireFence, int32_t dataspace,
499         const std::vector<hwc_rect_t>& damage)
501     hwc_region region = { damage.size(), damage.data() };
502     int32_t err = mDispatch.setClientTarget(mDevice, display, target,
503             acquireFence, dataspace, region);
504     return static_cast<Error>(err);
507 Error HwcHal::setOutputBuffer(Display display, buffer_handle_t buffer,
508         int32_t releaseFence)
510     int32_t err = mDispatch.setOutputBuffer(mDevice, display, buffer,
511             releaseFence);
512     // unlike in setClientTarget, releaseFence is owned by us
513     if (err == HWC2_ERROR_NONE && releaseFence >= 0) {
514         close(releaseFence);
515     }
517     return static_cast<Error>(err);
520 Error HwcHal::validateDisplay(Display display,
521         std::vector<Layer>* outChangedLayers,
522         std::vector<IComposerClient::Composition>* outCompositionTypes,
523         uint32_t* outDisplayRequestMask,
524         std::vector<Layer>* outRequestedLayers,
525         std::vector<uint32_t>* outRequestMasks)
527     uint32_t types_count = 0;
528     uint32_t reqs_count = 0;
529     int32_t err = mDispatch.validateDisplay(mDevice, display,
530             &types_count, &reqs_count);
531     if (err != HWC2_ERROR_NONE && err != HWC2_ERROR_HAS_CHANGES) {
532         return static_cast<Error>(err);
533     }
535     err = mDispatch.getChangedCompositionTypes(mDevice, display,
536             &types_count, nullptr, nullptr);
537     if (err != HWC2_ERROR_NONE) {
538         return static_cast<Error>(err);
539     }
541     outChangedLayers->resize(types_count);
542     outCompositionTypes->resize(types_count);
543     err = mDispatch.getChangedCompositionTypes(mDevice, display,
544             &types_count, outChangedLayers->data(),
545             reinterpret_cast<
546             std::underlying_type<IComposerClient::Composition>::type*>(
547                 outCompositionTypes->data()));
548     if (err != HWC2_ERROR_NONE) {
549         outChangedLayers->clear();
550         outCompositionTypes->clear();
551         return static_cast<Error>(err);
552     }
554     int32_t display_reqs = 0;
555     err = mDispatch.getDisplayRequests(mDevice, display, &display_reqs,
556             &reqs_count, nullptr, nullptr);
557     if (err != HWC2_ERROR_NONE) {
558         outChangedLayers->clear();
559         outCompositionTypes->clear();
560         return static_cast<Error>(err);
561     }
563     outRequestedLayers->resize(reqs_count);
564     outRequestMasks->resize(reqs_count);
565     err = mDispatch.getDisplayRequests(mDevice, display, &display_reqs,
566             &reqs_count, outRequestedLayers->data(),
567             reinterpret_cast<int32_t*>(outRequestMasks->data()));
568     if (err != HWC2_ERROR_NONE) {
569         outChangedLayers->clear();
570         outCompositionTypes->clear();
572         outRequestedLayers->clear();
573         outRequestMasks->clear();
574         return static_cast<Error>(err);
575     }
577     *outDisplayRequestMask = display_reqs;
579     return static_cast<Error>(err);
582 Error HwcHal::acceptDisplayChanges(Display display)
584     int32_t err = mDispatch.acceptDisplayChanges(mDevice, display);
585     return static_cast<Error>(err);
588 Error HwcHal::presentDisplay(Display display, int32_t* outPresentFence,
589         std::vector<Layer>* outLayers, std::vector<int32_t>* outReleaseFences)
591     *outPresentFence = -1;
592     int32_t err = mDispatch.presentDisplay(mDevice, display, outPresentFence);
593     if (err != HWC2_ERROR_NONE) {
594         return static_cast<Error>(err);
595     }
597     uint32_t count = 0;
598     err = mDispatch.getReleaseFences(mDevice, display, &count,
599             nullptr, nullptr);
600     if (err != HWC2_ERROR_NONE) {
601         ALOGW("failed to get release fences");
602         return Error::NONE;
603     }
605     outLayers->resize(count);
606     outReleaseFences->resize(count);
607     err = mDispatch.getReleaseFences(mDevice, display, &count,
608             outLayers->data(), outReleaseFences->data());
609     if (err != HWC2_ERROR_NONE) {
610         ALOGW("failed to get release fences");
611         outLayers->clear();
612         outReleaseFences->clear();
613         return Error::NONE;
614     }
616     return static_cast<Error>(err);
619 Error HwcHal::setLayerCursorPosition(Display display, Layer layer,
620         int32_t x, int32_t y)
622     int32_t err = mDispatch.setCursorPosition(mDevice, display, layer, x, y);
623     return static_cast<Error>(err);
626 Error HwcHal::setLayerBuffer(Display display, Layer layer,
627         buffer_handle_t buffer, int32_t acquireFence)
629     int32_t err = mDispatch.setLayerBuffer(mDevice, display, layer,
630             buffer, acquireFence);
631     return static_cast<Error>(err);
634 Error HwcHal::setLayerSurfaceDamage(Display display, Layer layer,
635         const std::vector<hwc_rect_t>& damage)
637     hwc_region region = { damage.size(), damage.data() };
638     int32_t err = mDispatch.setLayerSurfaceDamage(mDevice, display, layer,
639             region);
640     return static_cast<Error>(err);
643 Error HwcHal::setLayerBlendMode(Display display, Layer layer, int32_t mode)
645     int32_t err = mDispatch.setLayerBlendMode(mDevice, display, layer, mode);
646     return static_cast<Error>(err);
649 Error HwcHal::setLayerColor(Display display, Layer layer,
650         IComposerClient::Color color)
652     hwc_color_t hwc_color{color.r, color.g, color.b, color.a};
653     int32_t err = mDispatch.setLayerColor(mDevice, display, layer, hwc_color);
654     return static_cast<Error>(err);
657 Error HwcHal::setLayerCompositionType(Display display, Layer layer,
658         int32_t type)
660     int32_t err = mDispatch.setLayerCompositionType(mDevice, display, layer,
661             type);
662     return static_cast<Error>(err);
665 Error HwcHal::setLayerDataspace(Display display, Layer layer,
666         int32_t dataspace)
668     int32_t err = mDispatch.setLayerDataspace(mDevice, display, layer,
669             dataspace);
670     return static_cast<Error>(err);
673 Error HwcHal::setLayerDisplayFrame(Display display, Layer layer,
674         const hwc_rect_t& frame)
676     int32_t err = mDispatch.setLayerDisplayFrame(mDevice, display, layer,
677             frame);
678     return static_cast<Error>(err);
681 Error HwcHal::setLayerPlaneAlpha(Display display, Layer layer, float alpha)
683     int32_t err = mDispatch.setLayerPlaneAlpha(mDevice, display, layer,
684             alpha);
685     return static_cast<Error>(err);
688 Error HwcHal::setLayerSidebandStream(Display display, Layer layer,
689         buffer_handle_t stream)
691     int32_t err = mDispatch.setLayerSidebandStream(mDevice, display, layer,
692             stream);
693     return static_cast<Error>(err);
696 Error HwcHal::setLayerSourceCrop(Display display, Layer layer,
697         const hwc_frect_t& crop)
699     int32_t err = mDispatch.setLayerSourceCrop(mDevice, display, layer, crop);
700     return static_cast<Error>(err);
703 Error HwcHal::setLayerTransform(Display display, Layer layer,
704         int32_t transform)
706     int32_t err = mDispatch.setLayerTransform(mDevice, display, layer,
707             transform);
708     return static_cast<Error>(err);
711 Error HwcHal::setLayerVisibleRegion(Display display, Layer layer,
712         const std::vector<hwc_rect_t>& visible)
714     hwc_region_t region = { visible.size(), visible.data() };
715     int32_t err = mDispatch.setLayerVisibleRegion(mDevice, display, layer,
716             region);
717     return static_cast<Error>(err);
720 Error HwcHal::setLayerZOrder(Display display, Layer layer, uint32_t z)
722     int32_t err = mDispatch.setLayerZOrder(mDevice, display, layer, z);
723     return static_cast<Error>(err);
726 IComposer* HIDL_FETCH_IComposer(const char*)
728     const hw_module_t* module = nullptr;
729     int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &module);
730     if (err) {
731         ALOGE("failed to get hwcomposer module");
732         return nullptr;
733     }
735     return new HwcHal(module);
738 } // namespace implementation
739 } // namespace V2_1
740 } // namespace composer
741 } // namespace graphics
742 } // namespace hardware
743 } // namespace android