drm_hwcomposer: Remove HWC2 hooks for Virtual Displays
Change the Create/Destroy virtual display functions on DrmHwc to remove HWC2 API stuff. Implement the corresponding functions in the HWC3 and HWC2 frontends in terms of these functions. Change-Id: I410da9347ccb2cd008cc94b746c2b5604969b57e Signed-off-by: Drew Davenport <ddavenport@google.com>
This commit is contained in:
parent
c40f27b6ea
commit
1cca58e9e3
4 changed files with 58 additions and 39 deletions
|
|
@ -172,32 +172,30 @@ void DrmHwc::NotifyDisplayLinkStatus(
|
|||
DisplayStatus::kLinkTrainingFailed);
|
||||
}
|
||||
|
||||
HWC2::Error DrmHwc::CreateVirtualDisplay(
|
||||
uint32_t width, uint32_t height,
|
||||
int32_t *format, // NOLINT(readability-non-const-parameter)
|
||||
hwc2_display_t *display) {
|
||||
ALOGI("Creating virtual display %dx%d format %d", width, height, *format);
|
||||
std::optional<hwc2_display_t> DrmHwc::CreateVirtualDisplay(uint32_t width,
|
||||
uint32_t height) {
|
||||
ALOGI("Creating virtual display %dx%d", width, height);
|
||||
|
||||
auto virtual_pipeline = resource_manager_.GetVirtualDisplayPipeline();
|
||||
if (!virtual_pipeline)
|
||||
return HWC2::Error::Unsupported;
|
||||
return std::nullopt;
|
||||
|
||||
*display = ++last_display_handle_;
|
||||
auto disp = std::make_unique<HwcDisplay>(*display, /* is_virtual */ true,
|
||||
this);
|
||||
hwc2_display_t new_display_id = ++last_display_handle_;
|
||||
auto disp = std::make_unique<HwcDisplay>(new_display_id,
|
||||
/* is_virtual */ true, this);
|
||||
|
||||
disp->SetVirtualDisplayResolution(width, height);
|
||||
disp->SetPipeline(virtual_pipeline);
|
||||
displays_[*display] = std::move(disp);
|
||||
return HWC2::Error::None;
|
||||
displays_[new_display_id] = std::move(disp);
|
||||
return new_display_id;
|
||||
}
|
||||
|
||||
HWC2::Error DrmHwc::DestroyVirtualDisplay(hwc2_display_t display) {
|
||||
void DrmHwc::DestroyVirtualDisplay(hwc2_display_t display) {
|
||||
ALOGI("Destroying virtual display %" PRIu64, display);
|
||||
|
||||
if (displays_.count(display) == 0) {
|
||||
ALOGE("Trying to destroy non-existent display %" PRIu64, display);
|
||||
return HWC2::Error::BadDisplay;
|
||||
return;
|
||||
}
|
||||
|
||||
displays_[display]->SetPipeline({});
|
||||
|
|
@ -211,8 +209,6 @@ HWC2::Error DrmHwc::DestroyVirtualDisplay(hwc2_display_t display) {
|
|||
mutex.lock();
|
||||
|
||||
displays_.erase(display);
|
||||
|
||||
return HWC2::Error::None;
|
||||
}
|
||||
|
||||
auto DrmHwc::PullCompositionStats() -> std::map<int64_t, CompositionStats> {
|
||||
|
|
|
|||
|
|
@ -51,10 +51,10 @@ class DrmHwc : public PipelineToFrontendBindingInterface,
|
|||
|
||||
std::string DumpState();
|
||||
|
||||
// Device functions
|
||||
HWC2::Error CreateVirtualDisplay(uint32_t width, uint32_t height,
|
||||
int32_t *format, hwc2_display_t *display);
|
||||
HWC2::Error DestroyVirtualDisplay(hwc2_display_t display);
|
||||
// Virtual Display functions.
|
||||
std::optional<hwc2_display_t> CreateVirtualDisplay(uint32_t width,
|
||||
uint32_t height);
|
||||
void DestroyVirtualDisplay(hwc2_display_t display);
|
||||
uint32_t GetMaxVirtualDisplayCount();
|
||||
|
||||
auto GetDisplay(hwc2_display_t display_handle) {
|
||||
|
|
|
|||
|
|
@ -301,6 +301,36 @@ static int32_t Dump(hwc2_device_t *device, uint32_t *out_size,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t CreateVirtualDisplay(hwc2_device_t *device, uint32_t width,
|
||||
uint32_t height, int32_t * /*format*/,
|
||||
hwc2_display_t *out_display_id) {
|
||||
ALOGV("CreateVirtualDisplay");
|
||||
LOCK_COMPOSER(device);
|
||||
auto display_id = ihwc->CreateVirtualDisplay(width, height);
|
||||
if (!display_id) {
|
||||
return static_cast<int32_t>(HWC2::Error::Unsupported);
|
||||
}
|
||||
|
||||
*out_display_id = display_id.value();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t DestroyVirtualDisplay(hwc2_device_t *device,
|
||||
hwc2_display_t display) {
|
||||
ALOGV("DestroyVirtualDisplay");
|
||||
LOCK_COMPOSER(device);
|
||||
GET_DISPLAY(display);
|
||||
|
||||
ihwc->DestroyVirtualDisplay(display);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t GetMaxVirtualDisplayCount(hwc2_device_t *device) {
|
||||
ALOGV("GetMaxVirtualDisplayCount");
|
||||
LOCK_COMPOSER(device);
|
||||
return static_cast<int32_t>(ihwc->GetMaxVirtualDisplayCount());
|
||||
}
|
||||
|
||||
/* Display functions */
|
||||
static int32_t CreateLayer(hwc2_device_t *device, hwc2_display_t display,
|
||||
hwc2_layer_t *out_layer) {
|
||||
|
|
@ -1158,20 +1188,13 @@ static hwc2_function_pointer_t HookDevGetFunction(struct hwc2_device * /*dev*/,
|
|||
switch (func) {
|
||||
// Device functions
|
||||
case HWC2::FunctionDescriptor::CreateVirtualDisplay:
|
||||
return ToHook<HWC2_PFN_CREATE_VIRTUAL_DISPLAY>(
|
||||
DeviceHook<int32_t, decltype(&DrmHwcTwo::CreateVirtualDisplay),
|
||||
&DrmHwcTwo::CreateVirtualDisplay, uint32_t, uint32_t,
|
||||
int32_t *, hwc2_display_t *>);
|
||||
return (hwc2_function_pointer_t)CreateVirtualDisplay;
|
||||
case HWC2::FunctionDescriptor::DestroyVirtualDisplay:
|
||||
return ToHook<HWC2_PFN_DESTROY_VIRTUAL_DISPLAY>(
|
||||
DeviceHook<int32_t, decltype(&DrmHwcTwo::DestroyVirtualDisplay),
|
||||
&DrmHwcTwo::DestroyVirtualDisplay, hwc2_display_t>);
|
||||
return (hwc2_function_pointer_t)DestroyVirtualDisplay;
|
||||
case HWC2::FunctionDescriptor::Dump:
|
||||
return (hwc2_function_pointer_t)Dump;
|
||||
case HWC2::FunctionDescriptor::GetMaxVirtualDisplayCount:
|
||||
return ToHook<HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT>(
|
||||
DeviceHook<uint32_t, decltype(&DrmHwcTwo::GetMaxVirtualDisplayCount),
|
||||
&DrmHwcTwo::GetMaxVirtualDisplayCount>);
|
||||
return (hwc2_function_pointer_t)GetMaxVirtualDisplayCount;
|
||||
case HWC2::FunctionDescriptor::RegisterCallback:
|
||||
return ToHook<HWC2_PFN_REGISTER_CALLBACK>(
|
||||
DeviceHook<int32_t, decltype(&DrmHwcTwo::RegisterCallback),
|
||||
|
|
|
|||
|
|
@ -540,17 +540,14 @@ ndk::ScopedAStatus ComposerClient::createVirtualDisplay(
|
|||
DEBUG_FUNC();
|
||||
const std::unique_lock lock(hwc_->GetResMan().GetMainLock());
|
||||
|
||||
hwc2_display_t hwc2_display_id = 0;
|
||||
// TODO: Format is currently not used in drm_hwcomposer.
|
||||
int32_t hwc2_format = 0;
|
||||
auto err = Hwc2toHwc3Error(hwc_->CreateVirtualDisplay(width, height,
|
||||
&hwc2_format,
|
||||
&hwc2_display_id));
|
||||
if (err != hwc3::Error::kNone) {
|
||||
return ToBinderStatus(err);
|
||||
std::optional<hwc2_display_t>
|
||||
hwc2_display_id = hwc_->CreateVirtualDisplay(width, height);
|
||||
if (!hwc2_display_id) {
|
||||
return ToBinderStatus(hwc3::Error::kUnsupported);
|
||||
}
|
||||
|
||||
out_display->display = Hwc2DisplayToHwc3(hwc2_display_id);
|
||||
out_display->display = Hwc2DisplayToHwc3(hwc2_display_id.value());
|
||||
out_display->format = format_hint;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
|
@ -574,8 +571,11 @@ ndk::ScopedAStatus ComposerClient::destroyLayer(int64_t display_id,
|
|||
ndk::ScopedAStatus ComposerClient::destroyVirtualDisplay(int64_t display_id) {
|
||||
DEBUG_FUNC();
|
||||
const std::unique_lock lock(hwc_->GetResMan().GetMainLock());
|
||||
auto err = Hwc2toHwc3Error(hwc_->DestroyVirtualDisplay(display_id));
|
||||
return ToBinderStatus(err);
|
||||
if (GetDisplay(display_id) == nullptr) {
|
||||
return ToBinderStatus(hwc3::Error::kBadDisplay);
|
||||
}
|
||||
hwc_->DestroyVirtualDisplay(display_id);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::android::HwcDisplay* ComposerClient::GetDisplay(uint64_t display_id) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue