2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
20 #include "utils_android.h"
24 #include <android/log.h>
25 #include <cutils/properties.h>
26 #include <hardware/hardware.h>
27 #include <hardware/hwcomposer2.h>
28 #include <system/graphics.h>
30 #include <gpudevice.h>
32 #include <nativedisplay.h>
33 #include "mosaicdisplay.h"
42 class IAVsyncCallback : public hwcomposer::VsyncCallback {
44 IAVsyncCallback(hwc2_callback_data_t data, hwc2_function_pointer_t hook)
45 : data_(data), hook_(hook) {
48 void Callback(uint32_t display, int64_t timestamp) {
50 auto hook = reinterpret_cast<HWC2_PFN_VSYNC>(hook_);
51 hook(data_, display, timestamp);
56 hwc2_callback_data_t data_;
57 hwc2_function_pointer_t hook_;
60 class IARefreshCallback : public hwcomposer::RefreshCallback {
62 IARefreshCallback(hwc2_callback_data_t data, hwc2_function_pointer_t hook)
63 : data_(data), hook_(hook) {
66 void Callback(uint32_t display) {
68 auto hook = reinterpret_cast<HWC2_PFN_REFRESH>(hook_);
74 hwc2_callback_data_t data_;
75 hwc2_function_pointer_t hook_;
78 class IAHotPlugEventCallback : public hwcomposer::HotPlugCallback {
80 IAHotPlugEventCallback(hwc2_callback_data_t data,
81 hwc2_function_pointer_t hook,
82 IAHWC2::HwcDisplay *display)
83 : data_(data), hook_(hook), display_(display) {
86 void Callback(uint32_t display, bool connected) {
88 #ifdef ENABLE_PANORAMA
90 uint32_t size = sizeof(dispname);
91 memset(dispname, 0, sizeof(dispname));
92 display_->GetDisplayName(&size, dispname);
93 if (strstr(dispname, "Panorama")) {
94 // Allow the hotplug events to be emitted.
105 // SF expects primary display to be always
106 // connected. Let's notify it first time and ignore
107 // any followup status changes.
117 auto hook = reinterpret_cast<HWC2_PFN_HOTPLUG>(hook_);
118 int32_t status = static_cast<int32_t>(HWC2::Connection::Connected);
120 status = static_cast<int32_t>(HWC2::Connection::Disconnected);
124 "IAHotPlugEventCallback called displayid: %d status: %d \n", display,
127 hook(data_, display, status);
129 // FIXME: SurfaceFlinger doesn't seem to reset layers correctly
130 // when display is connected/disconnected. We force it here.
131 // Remove this workaround once fixed correctly in SurfaceFlinger.
132 if (!connected && display > 0) {
133 display_->FreeAllLayers();
138 hwc2_callback_data_t data_;
139 hwc2_function_pointer_t hook_;
140 IAHWC2::HwcDisplay *display_;
141 bool notified_ = false;
145 common.tag = HARDWARE_DEVICE_TAG;
146 common.version = HWC_DEVICE_API_VERSION_2_0;
147 common.close = HookDevClose;
148 getCapabilities = HookDevGetCapabilities;
149 getFunction = HookDevGetFunction;
152 HWC2::Error IAHWC2::Init() {
153 char value[PROPERTY_VALUE_MAX];
154 property_get("board.disable.explicit.sync", value, "0");
155 disable_explicit_sync_ = atoi(value);
156 if (disable_explicit_sync_)
157 ALOGI("EXPLICIT SYNC support is disabled");
159 ALOGI("EXPLICIT SYNC support is enabled");
161 property_get("board.hwc.scaling.mode", value, "2");
162 scaling_mode_ = atoi(value);
163 switch (scaling_mode_) {
165 ALOGI("HWC Scaling Mode Fast");
168 ALOGI("HWC Scaling Mode High Quality");
171 ALOGI("Unsupport HWC Scaling Mode");
175 if (!device_.Initialize()) {
176 ALOGE("Can't initialize drm object.");
177 return HWC2::Error::NoResources;
180 const std::vector<NativeDisplay *> &displays = device_.GetAllDisplays();
181 NativeDisplay *primary_display = displays.at(0);
182 uint32_t external_display_id = 1;
183 primary_display_.Init(primary_display, 0, disable_explicit_sync_,
185 size_t size = displays.size();
187 for (size_t i = 0; i < size; ++i) {
188 hwcomposer::NativeDisplay *display = displays.at(i);
189 if (display == primary_display)
192 std::unique_ptr<HwcDisplay> temp(new HwcDisplay());
193 temp->Init(display, external_display_id, disable_explicit_sync_,
195 extended_displays_.emplace_back(std::move(temp));
196 external_display_id++;
198 // Let's not confuse things with Virtual Display.
199 if (external_display_id == HWC_DISPLAY_VIRTUAL)
200 external_display_id = HWC_DISPLAY_VIRTUAL + 1;
203 // Start the hwc service
204 hwcService_.Start(*this);
206 return HWC2::Error::None;
209 template <typename... Args>
210 static inline HWC2::Error unsupported(char const *func, Args... /*args*/) {
211 ALOGV("Unsupported function: %s", func);
212 return HWC2::Error::Unsupported;
215 static inline void supported(char const *func) {
216 ALOGV("supported function: %s", func);
219 HWC2::Error IAHWC2::CreateVirtualDisplay(uint32_t width, uint32_t height,
221 hwc2_display_t *display) {
222 *display = (hwc2_display_t)(virtual_display_index_ + HWC_DISPLAY_VIRTUAL +
224 std::unique_ptr<HwcDisplay> temp(new HwcDisplay());
225 temp->InitVirtualDisplay(device_.CreateVirtualDisplay(virtual_display_index_),
226 width, height, virtual_display_index_,
227 disable_explicit_sync_);
228 virtual_displays_.emplace(virtual_display_index_, std::move(temp));
229 virtual_display_index_++;
231 if (*format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
232 // fallback to RGBA_8888, align with framework requirement
233 *format = HAL_PIXEL_FORMAT_RGBA_8888;
236 return HWC2::Error::None;
239 HWC2::Error IAHWC2::DestroyVirtualDisplay(hwc2_display_t display) {
240 if (display < (hwc2_display_t)(HWC_DISPLAY_VIRTUAL + VDS_OFFSET)) {
241 ALOGE("Not Virtual Display Type in DestroyVirtualDisplay");
242 return HWC2::Error::BadDisplay;
245 device_.DestroyVirtualDisplay(display - HWC_DISPLAY_VIRTUAL - VDS_OFFSET);
246 virtual_displays_.at(display - HWC_DISPLAY_VIRTUAL - VDS_OFFSET)
248 virtual_displays_.erase(display - HWC_DISPLAY_VIRTUAL - VDS_OFFSET);
249 virtual_display_index_--;
251 return HWC2::Error::None;
254 void IAHWC2::Dump(uint32_t *size, char *buffer) {
255 // TODO: Implement dump
256 unsupported(__func__, size, buffer);
259 uint32_t IAHWC2::GetMaxVirtualDisplayCount() {
263 HWC2::Error IAHWC2::RegisterCallback(int32_t descriptor,
264 hwc2_callback_data_t data,
265 hwc2_function_pointer_t function) {
267 auto callback = static_cast<HWC2::Callback>(descriptor);
268 size_t size = extended_displays_.size();
269 HWC2::Error error = HWC2::Error::None;
272 case HWC2::Callback::Hotplug: {
273 primary_display_.RegisterHotPlugCallback(data, function);
274 for (size_t i = 0; i < size; ++i) {
275 IAHWC2::HwcDisplay *display = extended_displays_.at(i).get();
276 display->RegisterHotPlugCallback(data, function);
281 case HWC2::Callback::Vsync: {
282 primary_display_.RegisterVsyncCallback(data, function);
283 for (size_t i = 0; i < size; ++i) {
284 IAHWC2::HwcDisplay *display = extended_displays_.at(i).get();
285 display->RegisterVsyncCallback(data, function);
290 case HWC2::Callback::Refresh: {
291 primary_display_.RegisterRefreshCallback(data, function);
292 for (size_t i = 0; i < size; ++i) {
293 IAHWC2::HwcDisplay *display = extended_displays_.at(i).get();
294 display->RegisterRefreshCallback(data, function);
300 error = HWC2::Error::BadParameter;
306 IAHWC2::HwcDisplay::HwcDisplay()
309 type_(HWC2::DisplayType::Invalid),
311 check_validate_display_(false),
312 disable_explicit_sync_(false),
313 enable_nested_display_compose_(false),
318 // This function will be called only for Virtual Display Init
319 HWC2::Error IAHWC2::HwcDisplay::InitVirtualDisplay(
320 hwcomposer::NativeDisplay *display, uint32_t width, uint32_t height,
321 uint32_t display_index, bool disable_explicit_sync) {
324 type_ = HWC2::DisplayType::Virtual;
325 handle_ = display_index + HWC_DISPLAY_VIRTUAL + VDS_OFFSET;
326 display_->InitVirtualDisplay(width, height);
327 disable_explicit_sync_ = disable_explicit_sync;
328 display_->SetDisableExplicitSync(disable_explicit_sync_);
329 return HWC2::Error::None;
332 HWC2::Error IAHWC2::HwcDisplay::Init(hwcomposer::NativeDisplay *display,
334 bool disable_explicit_sync,
335 uint32_t scaling_mode) {
338 type_ = HWC2::DisplayType::Physical;
339 handle_ = display_index;
341 disable_explicit_sync_ = disable_explicit_sync;
342 scaling_mode_ = scaling_mode;
343 display_->SetDisableExplicitSync(disable_explicit_sync_);
344 display_->SetVideoScalingMode(scaling_mode_);
346 if (!display_->IsConnected()) {
347 return HWC2::Error::None;
349 // Fetch the number of modes from the display
350 uint32_t num_configs;
351 HWC2::Error err = GetDisplayConfigs(&num_configs, NULL);
352 if (err != HWC2::Error::None || !num_configs)
355 // Grab the first mode, we'll choose this as the active mode
356 hwc2_config_t default_config;
358 err = GetDisplayConfigs(&num_configs, &default_config);
359 if (err != HWC2::Error::None)
362 display_->InitializeLayerHashGenerator(32);
364 return SetActiveConfig(default_config);
367 HWC2::Error IAHWC2::HwcDisplay::RegisterVsyncCallback(
368 hwc2_callback_data_t data, hwc2_function_pointer_t func) {
370 auto callback = std::make_shared<IAVsyncCallback>(data, func);
371 int ret = display_->RegisterVsyncCallback(std::move(callback),
372 static_cast<int>(handle_));
374 ALOGE("Failed to register callback d=%" PRIu64 " ret=%d", handle_, ret);
375 return HWC2::Error::BadDisplay;
377 return HWC2::Error::None;
380 HWC2::Error IAHWC2::HwcDisplay::RegisterRefreshCallback(
381 hwc2_callback_data_t data, hwc2_function_pointer_t func) {
383 auto callback = std::make_shared<IARefreshCallback>(data, func);
384 display_->RegisterRefreshCallback(std::move(callback),
385 static_cast<int>(handle_));
386 return HWC2::Error::None;
389 HWC2::Error IAHWC2::HwcDisplay::RegisterHotPlugCallback(
390 hwc2_callback_data_t data, hwc2_function_pointer_t func) {
392 auto callback = std::make_shared<IAHotPlugEventCallback>(data, func, this);
393 display_->RegisterHotPlugCallback(std::move(callback),
394 static_cast<int>(handle_));
395 return HWC2::Error::None;
398 HWC2::Error IAHWC2::HwcDisplay::AcceptDisplayChanges() {
400 if (!check_validate_display_) {
401 ALOGV("AcceptChanges failed, not validated");
402 return HWC2::Error::NotValidated;
405 for (std::pair<const hwc2_layer_t, IAHWC2::Hwc2Layer> &l : layers_)
406 l.second.accept_type_change();
408 // reset the value to false
409 check_validate_display_ = false;
410 return HWC2::Error::None;
413 HWC2::Error IAHWC2::HwcDisplay::CreateLayer(hwc2_layer_t *layer) {
415 uint64_t id = display_->AcquireId();
416 layers_.emplace(static_cast<hwc2_layer_t>(id), IAHWC2::Hwc2Layer());
417 layers_.at(id).XTranslateCoordinates(display_->GetXTranslation());
418 layers_.at(id).YTranslateCoordinates(display_->GetYTranslation());
419 *layer = static_cast<hwc2_layer_t>(id);
420 return HWC2::Error::None;
423 HWC2::Error IAHWC2::HwcDisplay::DestroyLayer(hwc2_layer_t layer) {
426 return HWC2::Error::None;
428 if (layers_.erase(layer))
429 display_->ReleaseId(layer);
431 return HWC2::Error::None;
434 void IAHWC2::HwcDisplay::FreeAllLayers() {
438 display_->ResetLayerHashGenerator();
439 std::map<hwc2_layer_t, Hwc2Layer>().swap(layers_);
442 HWC2::Error IAHWC2::HwcDisplay::GetActiveConfig(hwc2_config_t *config) {
444 IHOTPLUGEVENTTRACE("GetActiveConfig called for Display: %p \n", display_);
446 if (!display_->GetActiveConfig(config))
447 return HWC2::Error::BadConfig;
449 return HWC2::Error::None;
452 HWC2::Error IAHWC2::HwcDisplay::GetChangedCompositionTypes(
453 uint32_t *num_elements, hwc2_layer_t *layers, int32_t *types) {
455 uint32_t num_changes = 0;
456 for (std::pair<const hwc2_layer_t, IAHWC2::Hwc2Layer> &l : layers_) {
457 if (l.second.type_changed()) {
458 if (layers && num_changes < *num_elements)
459 layers[num_changes] = l.first;
460 if (types && num_changes < *num_elements)
461 types[num_changes] = static_cast<int32_t>(l.second.validated_type());
465 if (!layers && !types)
466 *num_elements = num_changes;
467 return HWC2::Error::None;
470 HWC2::Error IAHWC2::HwcDisplay::GetClientTargetSupport(uint32_t width,
474 if (width != display_->Width() || height != display_->Height()) {
475 return HWC2::Error::Unsupported;
478 if (format == HAL_PIXEL_FORMAT_RGBA_8888 &&
479 (dataspace == HAL_DATASPACE_UNKNOWN ||
480 dataspace == HAL_DATASPACE_STANDARD_UNSPECIFIED)) {
481 return HWC2::Error::None;
483 // Convert HAL to fourcc-based DRM formats
484 uint32_t drm_format = GetDrmFormatFromHALFormat(format);
485 if (display_->CheckPlaneFormat(drm_format) &&
486 (dataspace == HAL_DATASPACE_UNKNOWN ||
487 dataspace == HAL_DATASPACE_STANDARD_UNSPECIFIED))
488 return HWC2::Error::None;
491 return HWC2::Error::Unsupported;
494 HWC2::Error IAHWC2::HwcDisplay::GetColorModes(uint32_t *num_modes,
501 *modes = HAL_COLOR_MODE_NATIVE;
503 return HWC2::Error::None;
506 HWC2::Error IAHWC2::HwcDisplay::GetDisplayAttribute(hwc2_config_t config,
507 int32_t attribute_in,
510 auto attribute = static_cast<HWC2::Attribute>(attribute_in);
512 case HWC2::Attribute::Width:
513 display_->GetDisplayAttribute(
514 config, hwcomposer::HWCDisplayAttribute::kWidth, value);
516 case HWC2::Attribute::Height:
517 display_->GetDisplayAttribute(
518 config, hwcomposer::HWCDisplayAttribute::kHeight, value);
520 case HWC2::Attribute::VsyncPeriod:
522 display_->GetDisplayAttribute(
523 config, hwcomposer::HWCDisplayAttribute::kRefreshRate, value);
525 case HWC2::Attribute::DpiX:
526 // Dots per 1000 inches
527 display_->GetDisplayAttribute(
528 config, hwcomposer::HWCDisplayAttribute::kDpiX, value);
530 case HWC2::Attribute::DpiY:
531 // Dots per 1000 inches
532 display_->GetDisplayAttribute(
533 config, hwcomposer::HWCDisplayAttribute::kDpiY, value);
537 return HWC2::Error::BadConfig;
539 return HWC2::Error::None;
542 HWC2::Error IAHWC2::HwcDisplay::GetDisplayConfigs(uint32_t *num_configs,
543 hwc2_config_t *configs) {
545 if (!display_->GetDisplayConfigs(num_configs, configs))
546 return HWC2::Error::BadDisplay;
548 return HWC2::Error::None;
551 HWC2::Error IAHWC2::HwcDisplay::GetDisplayName(uint32_t *size, char *name) {
553 if (!display_->GetDisplayName(size, name))
554 return HWC2::Error::BadDisplay;
556 return HWC2::Error::None;
559 HWC2::Error IAHWC2::HwcDisplay::GetDisplayRequests(int32_t *display_requests,
560 uint32_t *num_elements,
561 hwc2_layer_t *layers,
562 int32_t *layer_requests) {
564 // TODO: I think virtual display should request
565 // HWC2_DISPLAY_REQUEST_WRITE_CLIENT_TARGET_TO_OUTPUT here
566 unsupported(__func__, display_requests, num_elements, layers, layer_requests);
568 return HWC2::Error::None;
571 HWC2::Error IAHWC2::HwcDisplay::GetDisplayType(int32_t *type) {
573 *type = static_cast<int32_t>(type_);
574 return HWC2::Error::None;
577 HWC2::Error IAHWC2::HwcDisplay::GetDozeSupport(int32_t *support) {
580 return HWC2::Error::None;
583 HWC2::Error IAHWC2::HwcDisplay::GetHdrCapabilities(
584 uint32_t *num_types, int32_t * /*types*/, float * /*max_luminance*/,
585 float * /*max_average_luminance*/, float * /*min_luminance*/) {
588 return HWC2::Error::None;
591 HWC2::Error IAHWC2::HwcDisplay::GetReleaseFences(uint32_t *num_elements,
592 hwc2_layer_t *layers,
595 if (layers == NULL || fences == NULL) {
596 *num_elements = layers_.size();
597 return HWC2::Error::None;
600 uint32_t num_layers = 0;
601 for (std::pair<const hwc2_layer_t, IAHWC2::Hwc2Layer> &l : layers_) {
603 if (num_layers > *num_elements) {
604 ALOGW("Overflow num_elements %d/%d", num_layers, *num_elements);
605 return HWC2::Error::None;
608 layers[num_layers - 1] = l.first;
609 fences[num_layers - 1] = l.second.GetLayer()->GetReleaseFence();
612 *num_elements = num_layers;
613 return HWC2::Error::None;
616 HWC2::Error IAHWC2::HwcDisplay::PresentDisplay(int32_t *retire_fence) {
618 // order the layers by z-order
619 bool use_client_layer = false;
620 uint32_t client_z_order = 0;
621 bool use_cursor_layer = false;
622 uint32_t cursor_z_order = 0;
623 IAHWC2::Hwc2Layer *cursor_layer;
625 std::map<uint32_t, IAHWC2::Hwc2Layer *> z_map;
627 // if the power mode is doze suspend then its the hint that the drawing
628 // into the display has suspended and remain in the low power state and
629 // continue displaying the current state and stop applying display
630 // update from the client
631 if (display_->PowerMode() == HWC2_POWER_MODE_DOZE_SUSPEND)
632 return HWC2::Error::None;
633 for (std::pair<const hwc2_layer_t, IAHWC2::Hwc2Layer> &l : layers_) {
634 if (l.second.IsCursorLayer()) {
635 use_cursor_layer = true;
636 cursor_layer = &l.second;
637 cursor_z_order = l.second.z_order();
641 if ((l.second.validated_type() != HWC2::Composition::SolidColor) &&
642 (l.second.GetLayer()->GetNativeHandle() == NULL)) {
644 "HWC don't support layer without buffer if not in type SolidColor");
648 switch (l.second.validated_type()) {
649 case HWC2::Composition::Device:
650 case HWC2::Composition::SolidColor:
651 z_map.emplace(std::make_pair(l.second.z_order(), &l.second));
653 case HWC2::Composition::Client:
654 // Place it at the z_order of the highest client layer
655 use_client_layer = true;
656 client_z_order = std::max(client_z_order, l.second.z_order());
662 if (use_client_layer && client_layer_.GetLayer() &&
663 client_layer_.GetLayer()->GetNativeHandle() &&
664 client_layer_.GetLayer()->GetNativeHandle()->handle_) {
665 z_map.emplace(std::make_pair(client_z_order, &client_layer_));
668 // Place the cursor at the highest z-order
669 if (use_cursor_layer) {
671 if (z_map.rbegin()->second->z_order() > cursor_z_order)
672 cursor_z_order = z_map.rbegin()->second->z_order() + 1;
673 else if (client_z_order > cursor_z_order)
674 cursor_z_order = client_z_order + 1;
676 z_map.emplace(std::make_pair(cursor_z_order, cursor_layer));
679 std::vector<hwcomposer::HwcLayer *> layers;
680 // now that they're ordered by z, add them to the composition
681 for (std::pair<const uint32_t, IAHWC2::Hwc2Layer *> &l : z_map) {
682 layers.emplace_back(l.second->GetLayer());
686 return HWC2::Error::None;
688 IHOTPLUGEVENTTRACE("PhysicalDisplay called for Display: %p \n", display_);
690 bool success = display_->Present(layers, retire_fence);
692 ALOGE("Failed to set layers in the composition");
693 return HWC2::Error::BadLayer;
698 return HWC2::Error::None;
701 HWC2::Error IAHWC2::HwcDisplay::SetActiveConfig(hwc2_config_t config) {
703 if (!display_->SetActiveConfig(config)) {
704 ALOGE("Could not find active mode for %d", config);
705 return HWC2::Error::BadConfig;
708 // Setup the client layer's dimensions
709 hwc_rect_t display_frame = {.left = 0,
711 .right = static_cast<int>(display_->Width()),
712 .bottom = static_cast<int>(display_->Height())};
713 client_layer_.SetLayerDisplayFrame(display_frame);
714 hwc_frect_t source_crop = {.left = 0.0f,
716 .right = display_->Width() + 0.0f,
717 .bottom = display_->Height() + 0.0f};
718 client_layer_.SetLayerSourceCrop(source_crop);
720 return HWC2::Error::None;
723 HWC2::Error IAHWC2::HwcDisplay::SetClientTarget(buffer_handle_t target,
724 int32_t acquire_fence,
726 hwc_region_t damage) {
728 client_layer_.set_buffer(target);
729 client_layer_.set_acquire_fence(acquire_fence);
730 client_layer_.SetLayerDataspace(dataspace);
731 client_layer_.SetLayerSurfaceDamage(damage);
733 return HWC2::Error::None;
736 HWC2::Error IAHWC2::HwcDisplay::SetColorMode(int32_t mode) {
738 // TODO: Use the parameter mode to set the color mode for the display to be
741 return HWC2::Error::None;
744 HWC2::Error IAHWC2::HwcDisplay::SetColorTransform(const float *matrix,
747 // TODO: Force client composition if we get this
749 if (hint != HAL_COLOR_TRANSFORM_IDENTITY &&
750 hint != HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX &&
751 hint != HAL_COLOR_TRANSFORM_VALUE_INVERSE &&
752 hint != HAL_COLOR_TRANSFORM_GRAYSCALE &&
753 hint != HAL_COLOR_TRANSFORM_CORRECT_PROTANOPIA &&
754 hint != HAL_COLOR_TRANSFORM_CORRECT_DEUTERANOPIA &&
755 hint != HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA)
756 return HWC2::Error::BadParameter;
758 display_->SetColorTransform(matrix, (HWCColorTransform)hint);
760 return HWC2::Error::None;
763 HWC2::Error IAHWC2::HwcDisplay::SetOutputBuffer(buffer_handle_t buffer,
764 int32_t release_fence) {
767 struct gralloc_handle *temp = new struct gralloc_handle();
768 temp->handle_ = buffer;
769 display_->SetOutputBuffer(temp, release_fence);
770 return HWC2::Error::None;
773 HWC2::Error IAHWC2::HwcDisplay::SetPowerMode(int32_t mode_in) {
775 uint32_t power_mode = 0;
776 auto mode = static_cast<HWC2::PowerMode>(mode_in);
778 case HWC2::PowerMode::Off:
779 power_mode = HWC2_POWER_MODE_OFF;
781 case HWC2::PowerMode::Doze:
782 power_mode = HWC2_POWER_MODE_DOZE;
784 case HWC2::PowerMode::DozeSuspend:
785 power_mode = HWC2_POWER_MODE_DOZE_SUSPEND;
787 case HWC2::PowerMode::On:
788 power_mode = HWC2_POWER_MODE_ON;
791 ALOGI("Power mode %d is unsupported\n", mode);
792 return HWC2::Error::BadParameter;
795 display_->SetPowerMode(power_mode);
797 return HWC2::Error::None;
800 HWC2::Error IAHWC2::HwcDisplay::SetVsyncEnabled(int32_t enabled) {
803 case HWC2_VSYNC_ENABLE:
804 display_->VSyncControl(true);
806 case HWC2_VSYNC_DISABLE:
807 display_->VSyncControl(false);
810 ALOGE("SetVsyncEnabled called with invalid parameter");
811 return HWC2::Error::BadParameter;
813 return HWC2::Error::None;
816 HWC2::Error IAHWC2::HwcDisplay::ValidateDisplay(uint32_t *num_types,
817 uint32_t *num_requests) {
821 for (std::pair<const hwc2_layer_t, IAHWC2::Hwc2Layer> &l : layers_) {
822 IAHWC2::Hwc2Layer &layer = l.second;
824 switch (layer.sf_type()) {
825 case HWC2::Composition::Sideband:
826 layer.set_validated_type(HWC2::Composition::Client);
829 case HWC2::Composition::Cursor:
830 layer.set_validated_type(HWC2::Composition::Device);
834 if (disable_explicit_sync_ ||
835 display_->PowerMode() == HWC2_POWER_MODE_DOZE_SUSPEND) {
836 layer.set_validated_type(HWC2::Composition::Client);
838 layer.set_validated_type(layer.sf_type());
844 check_validate_display_ = true;
845 return HWC2::Error::None;
848 HWC2::Error IAHWC2::Hwc2Layer::SetCursorPosition(int32_t /*x*/, int32_t /*y*/) {
850 return HWC2::Error::None;
853 HWC2::Error IAHWC2::Hwc2Layer::SetLayerBlendMode(int32_t mode) {
855 switch (static_cast<HWC2::BlendMode>(mode)) {
856 case HWC2::BlendMode::None:
857 hwc_layer_.SetBlending(hwcomposer::HWCBlending::kBlendingNone);
859 case HWC2::BlendMode::Premultiplied:
860 hwc_layer_.SetBlending(hwcomposer::HWCBlending::kBlendingPremult);
862 case HWC2::BlendMode::Coverage:
863 hwc_layer_.SetBlending(hwcomposer::HWCBlending::kBlendingCoverage);
866 ALOGE("Unknown blending mode b=%d", mode);
867 hwc_layer_.SetBlending(hwcomposer::HWCBlending::kBlendingNone);
870 return HWC2::Error::None;
873 HWC2::Error IAHWC2::Hwc2Layer::SetLayerBuffer(buffer_handle_t buffer,
874 int32_t acquire_fence) {
877 // The buffer and acquire_fence are handled elsewhere
878 if (sf_type_ == HWC2::Composition::Client ||
879 sf_type_ == HWC2::Composition::Sideband)
880 return HWC2::Error::None;
882 native_handle_.handle_ = buffer;
883 hwc_layer_.SetNativeHandle(&native_handle_);
884 if (acquire_fence > 0)
885 hwc_layer_.SetAcquireFence(acquire_fence);
886 return HWC2::Error::None;
889 HWC2::Error IAHWC2::Hwc2Layer::SetLayerColor(hwc_color_t color) {
890 if (sf_type_ == HWC2::Composition::SolidColor) {
891 hwc_layer_.SetLayerCompositionType(hwcomposer::Composition_SolidColor);
892 uint32_t hwc_layer_color = (uint32_t)color.r << 24 |
893 (uint32_t)color.g << 16 |
894 (uint32_t)color.b << 8 | (uint32_t)color.a;
895 hwc_layer_.SetSolidColor(hwc_layer_color);
897 sf_type_ = HWC2::Composition::Client;
899 return HWC2::Error::None;
902 HWC2::Error IAHWC2::Hwc2Layer::SetLayerCompositionType(int32_t type) {
903 sf_type_ = static_cast<HWC2::Composition>(type);
904 if (sf_type_ == HWC2::Composition::Cursor) {
905 hwc_layer_.MarkAsCursorLayer();
908 return HWC2::Error::None;
911 HWC2::Error IAHWC2::Hwc2Layer::SetLayerDataspace(int32_t dataspace) {
913 dataspace_ = static_cast<android_dataspace_t>(dataspace);
914 hwc_layer_.SetDataSpace(dataspace_);
915 return HWC2::Error::None;
918 HWC2::Error IAHWC2::Hwc2Layer::SetLayerDisplayFrame(hwc_rect_t frame) {
920 hwc_layer_.SetDisplayFrame(
921 hwcomposer::HwcRect<int>(frame.left, frame.top, frame.right,
923 x_translation_, y_translation_);
924 return HWC2::Error::None;
927 HWC2::Error IAHWC2::Hwc2Layer::SetLayerPlaneAlpha(float alpha) {
929 hwc_layer_.SetAlpha(static_cast<uint8_t>(255.0f * alpha + 0.5f));
930 return HWC2::Error::None;
933 HWC2::Error IAHWC2::Hwc2Layer::SetLayerSidebandStream(
934 const native_handle_t *stream) {
936 // TODO: We don't support sideband
937 return unsupported(__func__, stream);
940 HWC2::Error IAHWC2::Hwc2Layer::SetLayerSourceCrop(hwc_frect_t crop) {
942 hwc_layer_.SetSourceCrop(
943 hwcomposer::HwcRect<float>(crop.left, crop.top, crop.right, crop.bottom));
944 return HWC2::Error::None;
947 HWC2::Error IAHWC2::Hwc2Layer::SetLayerSurfaceDamage(hwc_region_t damage) {
948 uint32_t num_rects = damage.numRects;
949 hwcomposer::HwcRegion hwc_region;
951 for (size_t rect = 0; rect < num_rects; ++rect) {
952 if (!(damage.rects[rect].left == 0 && damage.rects[rect].top == 0 &&
953 damage.rects[rect].right == 0 && damage.rects[rect].bottom == 0)) {
954 hwc_region.emplace_back(damage.rects[rect].left, damage.rects[rect].top,
955 damage.rects[rect].right,
956 damage.rects[rect].bottom);
960 hwc_layer_.SetSurfaceDamage(hwc_region);
962 return HWC2::Error::None;
965 HWC2::Error IAHWC2::Hwc2Layer::SetLayerTransform(int32_t transform) {
967 // 270* and 180* cannot be combined with flips. More specifically, they
968 // already contain both horizontal and vertical flips, so those fields are
969 // redundant in this case. 90* rotation can be combined with either horizontal
970 // flip or vertical flip, so treat it differently
972 if (transform == HWC_TRANSFORM_ROT_270) {
973 temp = hwcomposer::HWCTransform::kTransform270;
974 } else if (transform == HWC_TRANSFORM_ROT_180) {
975 temp = hwcomposer::HWCTransform::kTransform180;
977 if (transform & HWC_TRANSFORM_FLIP_H)
978 temp |= hwcomposer::HWCTransform::kReflectX;
979 if (transform & HWC_TRANSFORM_FLIP_V)
980 temp |= hwcomposer::HWCTransform::kReflectY;
981 if (transform & HWC_TRANSFORM_ROT_90)
982 temp |= hwcomposer::HWCTransform::kTransform90;
984 hwc_layer_.SetTransform(temp);
985 return HWC2::Error::None;
988 HWC2::Error IAHWC2::Hwc2Layer::SetLayerVisibleRegion(hwc_region_t visible) {
989 uint32_t num_rects = visible.numRects;
990 hwcomposer::HwcRegion hwc_region;
992 for (size_t rect = 0; rect < num_rects; ++rect) {
993 hwc_region.emplace_back(visible.rects[rect].left, visible.rects[rect].top,
994 visible.rects[rect].right,
995 visible.rects[rect].bottom);
998 hwc_layer_.SetVisibleRegion(hwc_region);
999 return HWC2::Error::None;
1002 HWC2::Error IAHWC2::Hwc2Layer::SetLayerZOrder(uint32_t order) {
1003 supported(__func__);
1005 hwc_layer_.SetLayerZOrder(order);
1006 return HWC2::Error::None;
1010 int IAHWC2::HookDevClose(hw_device_t * /*dev*/) {
1011 unsupported(__func__);
1016 void IAHWC2::HookDevGetCapabilities(hwc2_device_t * /*dev*/,
1017 uint32_t *out_count,
1018 int32_t * /*out_capabilities*/) {
1019 supported(__func__);
1024 hwc2_function_pointer_t IAHWC2::HookDevGetFunction(struct hwc2_device * /*dev*/,
1025 int32_t descriptor) {
1026 supported(__func__);
1027 auto func = static_cast<HWC2::FunctionDescriptor>(descriptor);
1030 case HWC2::FunctionDescriptor::CreateVirtualDisplay:
1031 return ToHook<HWC2_PFN_CREATE_VIRTUAL_DISPLAY>(
1032 DeviceHook<int32_t, decltype(&IAHWC2::CreateVirtualDisplay),
1033 &IAHWC2::CreateVirtualDisplay, uint32_t, uint32_t,
1034 int32_t *, hwc2_display_t *>);
1035 case HWC2::FunctionDescriptor::DestroyVirtualDisplay:
1036 return ToHook<HWC2_PFN_DESTROY_VIRTUAL_DISPLAY>(
1037 DeviceHook<int32_t, decltype(&IAHWC2::DestroyVirtualDisplay),
1038 &IAHWC2::DestroyVirtualDisplay, hwc2_display_t>);
1039 case HWC2::FunctionDescriptor::Dump:
1040 return ToHook<HWC2_PFN_DUMP>(DeviceHook<
1041 void, decltype(&IAHWC2::Dump), &IAHWC2::Dump, uint32_t *, char *>);
1042 case HWC2::FunctionDescriptor::GetMaxVirtualDisplayCount:
1043 return ToHook<HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT>(
1044 DeviceHook<uint32_t, decltype(&IAHWC2::GetMaxVirtualDisplayCount),
1045 &IAHWC2::GetMaxVirtualDisplayCount>);
1046 case HWC2::FunctionDescriptor::RegisterCallback:
1047 return ToHook<HWC2_PFN_REGISTER_CALLBACK>(
1048 DeviceHook<int32_t, decltype(&IAHWC2::RegisterCallback),
1049 &IAHWC2::RegisterCallback, int32_t, hwc2_callback_data_t,
1050 hwc2_function_pointer_t>);
1052 // Display functions
1053 case HWC2::FunctionDescriptor::AcceptDisplayChanges:
1054 return ToHook<HWC2_PFN_ACCEPT_DISPLAY_CHANGES>(
1055 DisplayHook<decltype(&HwcDisplay::AcceptDisplayChanges),
1056 &HwcDisplay::AcceptDisplayChanges>);
1057 case HWC2::FunctionDescriptor::CreateLayer:
1058 return ToHook<HWC2_PFN_CREATE_LAYER>(
1059 DisplayHook<decltype(&HwcDisplay::CreateLayer),
1060 &HwcDisplay::CreateLayer, hwc2_layer_t *>);
1061 case HWC2::FunctionDescriptor::DestroyLayer:
1062 return ToHook<HWC2_PFN_DESTROY_LAYER>(
1063 DisplayHook<decltype(&HwcDisplay::DestroyLayer),
1064 &HwcDisplay::DestroyLayer, hwc2_layer_t>);
1065 case HWC2::FunctionDescriptor::GetActiveConfig:
1066 return ToHook<HWC2_PFN_GET_ACTIVE_CONFIG>(
1067 DisplayHook<decltype(&HwcDisplay::GetActiveConfig),
1068 &HwcDisplay::GetActiveConfig, hwc2_config_t *>);
1069 case HWC2::FunctionDescriptor::GetChangedCompositionTypes:
1070 return ToHook<HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES>(
1071 DisplayHook<decltype(&HwcDisplay::GetChangedCompositionTypes),
1072 &HwcDisplay::GetChangedCompositionTypes, uint32_t *,
1073 hwc2_layer_t *, int32_t *>);
1074 case HWC2::FunctionDescriptor::GetClientTargetSupport:
1075 return ToHook<HWC2_PFN_GET_CLIENT_TARGET_SUPPORT>(
1076 DisplayHook<decltype(&HwcDisplay::GetClientTargetSupport),
1077 &HwcDisplay::GetClientTargetSupport, uint32_t, uint32_t,
1079 case HWC2::FunctionDescriptor::GetColorModes:
1080 return ToHook<HWC2_PFN_GET_COLOR_MODES>(
1081 DisplayHook<decltype(&HwcDisplay::GetColorModes),
1082 &HwcDisplay::GetColorModes, uint32_t *, int32_t *>);
1083 case HWC2::FunctionDescriptor::GetDisplayAttribute:
1084 return ToHook<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>(DisplayHook<
1085 decltype(&HwcDisplay::GetDisplayAttribute),
1086 &HwcDisplay::GetDisplayAttribute, hwc2_config_t, int32_t, int32_t *>);
1087 case HWC2::FunctionDescriptor::GetDisplayConfigs:
1088 return ToHook<HWC2_PFN_GET_DISPLAY_CONFIGS>(DisplayHook<
1089 decltype(&HwcDisplay::GetDisplayConfigs),
1090 &HwcDisplay::GetDisplayConfigs, uint32_t *, hwc2_config_t *>);
1091 case HWC2::FunctionDescriptor::GetDisplayName:
1092 return ToHook<HWC2_PFN_GET_DISPLAY_NAME>(
1093 DisplayHook<decltype(&HwcDisplay::GetDisplayName),
1094 &HwcDisplay::GetDisplayName, uint32_t *, char *>);
1095 case HWC2::FunctionDescriptor::GetDisplayRequests:
1096 return ToHook<HWC2_PFN_GET_DISPLAY_REQUESTS>(
1097 DisplayHook<decltype(&HwcDisplay::GetDisplayRequests),
1098 &HwcDisplay::GetDisplayRequests, int32_t *, uint32_t *,
1099 hwc2_layer_t *, int32_t *>);
1100 case HWC2::FunctionDescriptor::GetDisplayType:
1101 return ToHook<HWC2_PFN_GET_DISPLAY_TYPE>(
1102 DisplayHook<decltype(&HwcDisplay::GetDisplayType),
1103 &HwcDisplay::GetDisplayType, int32_t *>);
1104 case HWC2::FunctionDescriptor::GetDozeSupport:
1105 return ToHook<HWC2_PFN_GET_DOZE_SUPPORT>(
1106 DisplayHook<decltype(&HwcDisplay::GetDozeSupport),
1107 &HwcDisplay::GetDozeSupport, int32_t *>);
1108 case HWC2::FunctionDescriptor::GetHdrCapabilities:
1109 return ToHook<HWC2_PFN_GET_HDR_CAPABILITIES>(
1110 DisplayHook<decltype(&HwcDisplay::GetHdrCapabilities),
1111 &HwcDisplay::GetHdrCapabilities, uint32_t *, int32_t *,
1112 float *, float *, float *>);
1113 case HWC2::FunctionDescriptor::GetReleaseFences:
1114 return ToHook<HWC2_PFN_GET_RELEASE_FENCES>(
1115 DisplayHook<decltype(&HwcDisplay::GetReleaseFences),
1116 &HwcDisplay::GetReleaseFences, uint32_t *, hwc2_layer_t *,
1118 case HWC2::FunctionDescriptor::PresentDisplay:
1119 return ToHook<HWC2_PFN_PRESENT_DISPLAY>(
1120 DisplayHook<decltype(&HwcDisplay::PresentDisplay),
1121 &HwcDisplay::PresentDisplay, int32_t *>);
1122 case HWC2::FunctionDescriptor::SetActiveConfig:
1123 return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG>(
1124 DisplayHook<decltype(&HwcDisplay::SetActiveConfig),
1125 &HwcDisplay::SetActiveConfig, hwc2_config_t>);
1126 case HWC2::FunctionDescriptor::SetClientTarget:
1127 return ToHook<HWC2_PFN_SET_CLIENT_TARGET>(DisplayHook<
1128 decltype(&HwcDisplay::SetClientTarget), &HwcDisplay::SetClientTarget,
1129 buffer_handle_t, int32_t, int32_t, hwc_region_t>);
1130 case HWC2::FunctionDescriptor::SetColorMode:
1131 return ToHook<HWC2_PFN_SET_COLOR_MODE>(
1132 DisplayHook<decltype(&HwcDisplay::SetColorMode),
1133 &HwcDisplay::SetColorMode, int32_t>);
1134 case HWC2::FunctionDescriptor::SetColorTransform:
1135 return ToHook<HWC2_PFN_SET_COLOR_TRANSFORM>(
1136 DisplayHook<decltype(&HwcDisplay::SetColorTransform),
1137 &HwcDisplay::SetColorTransform, const float *, int32_t>);
1138 case HWC2::FunctionDescriptor::SetOutputBuffer:
1139 return ToHook<HWC2_PFN_SET_OUTPUT_BUFFER>(
1140 DisplayHook<decltype(&HwcDisplay::SetOutputBuffer),
1141 &HwcDisplay::SetOutputBuffer, buffer_handle_t, int32_t>);
1142 case HWC2::FunctionDescriptor::SetPowerMode:
1143 return ToHook<HWC2_PFN_SET_POWER_MODE>(
1144 DisplayHook<decltype(&HwcDisplay::SetPowerMode),
1145 &HwcDisplay::SetPowerMode, int32_t>);
1146 case HWC2::FunctionDescriptor::SetVsyncEnabled:
1147 return ToHook<HWC2_PFN_SET_VSYNC_ENABLED>(
1148 DisplayHook<decltype(&HwcDisplay::SetVsyncEnabled),
1149 &HwcDisplay::SetVsyncEnabled, int32_t>);
1150 case HWC2::FunctionDescriptor::ValidateDisplay:
1151 return ToHook<HWC2_PFN_VALIDATE_DISPLAY>(
1152 DisplayHook<decltype(&HwcDisplay::ValidateDisplay),
1153 &HwcDisplay::ValidateDisplay, uint32_t *, uint32_t *>);
1156 case HWC2::FunctionDescriptor::SetCursorPosition:
1157 return ToHook<HWC2_PFN_SET_CURSOR_POSITION>(
1158 LayerHook<decltype(&Hwc2Layer::SetCursorPosition),
1159 &Hwc2Layer::SetCursorPosition, int32_t, int32_t>);
1160 case HWC2::FunctionDescriptor::SetLayerBlendMode:
1161 return ToHook<HWC2_PFN_SET_LAYER_BLEND_MODE>(
1162 LayerHook<decltype(&Hwc2Layer::SetLayerBlendMode),
1163 &Hwc2Layer::SetLayerBlendMode, int32_t>);
1164 case HWC2::FunctionDescriptor::SetLayerBuffer:
1165 return ToHook<HWC2_PFN_SET_LAYER_BUFFER>(
1166 LayerHook<decltype(&Hwc2Layer::SetLayerBuffer),
1167 &Hwc2Layer::SetLayerBuffer, buffer_handle_t, int32_t>);
1168 case HWC2::FunctionDescriptor::SetLayerColor:
1169 return ToHook<HWC2_PFN_SET_LAYER_COLOR>(
1170 LayerHook<decltype(&Hwc2Layer::SetLayerColor),
1171 &Hwc2Layer::SetLayerColor, hwc_color_t>);
1172 case HWC2::FunctionDescriptor::SetLayerCompositionType:
1173 return ToHook<HWC2_PFN_SET_LAYER_COMPOSITION_TYPE>(
1174 LayerHook<decltype(&Hwc2Layer::SetLayerCompositionType),
1175 &Hwc2Layer::SetLayerCompositionType, int32_t>);
1176 case HWC2::FunctionDescriptor::SetLayerDataspace:
1177 return ToHook<HWC2_PFN_SET_LAYER_DATASPACE>(
1178 LayerHook<decltype(&Hwc2Layer::SetLayerDataspace),
1179 &Hwc2Layer::SetLayerDataspace, int32_t>);
1180 case HWC2::FunctionDescriptor::SetLayerDisplayFrame:
1181 return ToHook<HWC2_PFN_SET_LAYER_DISPLAY_FRAME>(
1182 LayerHook<decltype(&Hwc2Layer::SetLayerDisplayFrame),
1183 &Hwc2Layer::SetLayerDisplayFrame, hwc_rect_t>);
1184 case HWC2::FunctionDescriptor::SetLayerPlaneAlpha:
1185 return ToHook<HWC2_PFN_SET_LAYER_PLANE_ALPHA>(
1186 LayerHook<decltype(&Hwc2Layer::SetLayerPlaneAlpha),
1187 &Hwc2Layer::SetLayerPlaneAlpha, float>);
1188 case HWC2::FunctionDescriptor::SetLayerSidebandStream:
1189 return ToHook<HWC2_PFN_SET_LAYER_SIDEBAND_STREAM>(LayerHook<
1190 decltype(&Hwc2Layer::SetLayerSidebandStream),
1191 &Hwc2Layer::SetLayerSidebandStream, const native_handle_t *>);
1192 case HWC2::FunctionDescriptor::SetLayerSourceCrop:
1193 return ToHook<HWC2_PFN_SET_LAYER_SOURCE_CROP>(
1194 LayerHook<decltype(&Hwc2Layer::SetLayerSourceCrop),
1195 &Hwc2Layer::SetLayerSourceCrop, hwc_frect_t>);
1196 case HWC2::FunctionDescriptor::SetLayerSurfaceDamage:
1197 return ToHook<HWC2_PFN_SET_LAYER_SURFACE_DAMAGE>(
1198 LayerHook<decltype(&Hwc2Layer::SetLayerSurfaceDamage),
1199 &Hwc2Layer::SetLayerSurfaceDamage, hwc_region_t>);
1200 case HWC2::FunctionDescriptor::SetLayerTransform:
1201 return ToHook<HWC2_PFN_SET_LAYER_TRANSFORM>(
1202 LayerHook<decltype(&Hwc2Layer::SetLayerTransform),
1203 &Hwc2Layer::SetLayerTransform, int32_t>);
1204 case HWC2::FunctionDescriptor::SetLayerVisibleRegion:
1205 return ToHook<HWC2_PFN_SET_LAYER_VISIBLE_REGION>(
1206 LayerHook<decltype(&Hwc2Layer::SetLayerVisibleRegion),
1207 &Hwc2Layer::SetLayerVisibleRegion, hwc_region_t>);
1208 case HWC2::FunctionDescriptor::SetLayerZOrder:
1209 return ToHook<HWC2_PFN_SET_LAYER_Z_ORDER>(
1210 LayerHook<decltype(&Hwc2Layer::SetLayerZOrder),
1211 &Hwc2Layer::SetLayerZOrder, uint32_t>);
1212 case HWC2::FunctionDescriptor::Invalid:
1219 int IAHWC2::HookDevOpen(const struct hw_module_t *module, const char *name,
1220 struct hw_device_t **dev) {
1221 supported(__func__);
1222 if (strcmp(name, HWC_HARDWARE_COMPOSER)) {
1223 ALOGE("Invalid module name- %s", name);
1227 std::unique_ptr<IAHWC2> ctx(new IAHWC2());
1229 ALOGE("Failed to allocate IAHWC2");
1233 HWC2::Error err = ctx->Init();
1234 if (err != HWC2::Error::None) {
1235 ALOGE("Failed to initialize IAHWC2 err=%d\n", err);
1239 ctx->common.module = const_cast<hw_module_t *>(module);
1240 *dev = &ctx->common;
1245 hwcomposer::NativeDisplay *IAHWC2::GetExtendedDisplay(uint32_t dispIndex) {
1246 return extended_displays_.at(dispIndex)->GetDisplay();
1249 hwcomposer::NativeDisplay *IAHWC2::GetPrimaryDisplay() {
1250 return primary_display_.GetDisplay();
1253 hwcomposer::NativeDisplay *IAHWC2::HwcDisplay::GetDisplay() {
1257 void IAHWC2::EnableHDCPSessionForDisplay(uint32_t connector,
1258 EHwcsContentType content_type) {
1259 HWCContentType type = kCONTENT_TYPE0;
1260 if (content_type == HWCS_CP_CONTENT_TYPE1) {
1261 type = kCONTENT_TYPE1;
1264 device_.EnableHDCPSessionForDisplay(connector, type);
1267 void IAHWC2::EnableHDCPSessionForAllDisplays(EHwcsContentType content_type) {
1268 HWCContentType type = kCONTENT_TYPE0;
1269 if (content_type == HWCS_CP_CONTENT_TYPE1) {
1270 type = kCONTENT_TYPE1;
1272 device_.EnableHDCPSessionForAllDisplays(type);
1275 void IAHWC2::DisableHDCPSessionForDisplay(uint32_t connector) {
1276 device_.DisableHDCPSessionForDisplay(connector);
1279 void IAHWC2::DisableHDCPSessionForAllDisplays() {
1280 device_.DisableHDCPSessionForAllDisplays();
1283 #ifdef ENABLE_PANORAMA
1284 void IAHWC2::TriggerPanorama(uint32_t hotplug_simulation) {
1285 device_.TriggerPanorama(hotplug_simulation);
1288 void IAHWC2::ShutdownPanorama(uint32_t hotplug_simulation) {
1289 device_.ShutdownPanorama(hotplug_simulation);
1293 void IAHWC2::SetPAVPSessionStatus(bool enabled, uint32_t papv_session_id,
1294 uint32_t pavp_instance_id) {
1295 device_.SetPAVPSessionStatus(enabled, papv_session_id, pavp_instance_id);
1298 void IAHWC2::SetHDCPSRMForAllDisplays(const int8_t *SRM, uint32_t SRMLength) {
1300 ETRACE("Error:HDCP Set NULL SRM");
1303 device_.SetHDCPSRMForAllDisplays(SRM, SRMLength);
1306 uint32_t IAHWC2::GetDisplayIDFromConnectorID(const uint32_t connector_id) {
1307 return device_.GetDisplayIDFromConnectorID(connector_id);
1310 bool IAHWC2::EnableDRMCommit(bool enable, uint32_t display_id) {
1311 return device_.EnableDRMCommit(enable, display_id);
1314 void IAHWC2::SetHDCPSRMForDisplay(uint32_t connector, const int8_t *SRM,
1315 uint32_t SRMLength) {
1317 ETRACE("Error:HDCP Set NULL SRM");
1320 device_.SetHDCPSRMForDisplay(connector, SRM, SRMLength);
1323 } // namespace android
1325 static struct hw_module_methods_t hwc2_module_methods = {
1326 .open = android::IAHWC2::HookDevOpen,
1329 hw_module_t HAL_MODULE_INFO_SYM = {
1330 .tag = HARDWARE_MODULE_TAG,
1331 .module_api_version = HARDWARE_MODULE_API_VERSION(2, 0),
1332 .id = HWC_HARDWARE_MODULE_ID,
1333 .name = "IA-Hardware-Composer",
1334 .author = "The Android Open Source Project",
1335 .methods = &hwc2_module_methods,