drm_hwcomposer: support virtual displays
Virtual display support is mandatory for HWC version 1.4.
As a minimal implementation, we use frambuffer target and let SF take care of
GLES composition. We still need to handle the acquire and release fences for
both the virtual display and all layers in a separate worker thread.
BUG=24609829
TEST=screen casting to chromecast
Change-Id: Idb962f4b5bb852c9ec9ebcaa1679a653c01737fb
diff --git a/hwcomposer.cpp b/hwcomposer.cpp
index 3035362..a7c9e43 100644
--- a/hwcomposer.cpp
+++ b/hwcomposer.cpp
@@ -20,6 +20,7 @@
#include "drm_hwcomposer.h"
#include "drmresources.h"
#include "importer.h"
+#include "virtualcompositorworker.h"
#include "vsyncworker.h"
#include <stdlib.h>
@@ -133,6 +134,7 @@
}
~hwc_context_t() {
+ virtual_compositor_worker.Exit();
delete importer;
}
@@ -145,6 +147,7 @@
const gralloc_module_t *gralloc;
DummySwSyncTimeline dummy_timeline;
bool use_framebuffer_target;
+ VirtualCompositorWorker virtual_compositor_worker;
};
static native_handle_t *dup_buffer_handle(buffer_handle_t handle) {
@@ -346,17 +349,22 @@
if (!display_contents[i])
continue;
- DrmCrtc *crtc = ctx->drm.GetCrtcForDisplay(i);
- if (!crtc) {
- ALOGE("No crtc for display %d", i);
- return -ENODEV;
+ bool use_framebuffer_target = ctx->use_framebuffer_target;
+ if (i == HWC_DISPLAY_VIRTUAL) {
+ use_framebuffer_target = true;
+ } else {
+ DrmCrtc *crtc = ctx->drm.GetCrtcForDisplay(i);
+ if (!crtc) {
+ ALOGE("No crtc for display %d", i);
+ return -ENODEV;
+ }
}
int num_layers = display_contents[i]->numHwLayers;
for (int j = 0; j < num_layers; j++) {
hwc_layer_1_t *layer = &display_contents[i]->hwLayers[j];
- if (!ctx->use_framebuffer_target) {
+ if (!use_framebuffer_target) {
if (layer->compositionType == HWC_FRAMEBUFFER)
layer->compositionType = HWC_OVERLAY;
} else {
@@ -415,6 +423,11 @@
if (!sf_display_contents[i])
continue;
+ if (i == HWC_DISPLAY_VIRTUAL) {
+ ctx->virtual_compositor_worker.QueueComposite(dc);
+ continue;
+ }
+
std::ostringstream display_index_formatter;
display_index_formatter << "retire fence for display " << i;
std::string display_fence_description(display_index_formatter.str());
@@ -576,7 +589,7 @@
*value = 1000 * 1000 * 1000 / 60;
break;
case HWC_DISPLAY_TYPES_SUPPORTED:
- *value = HWC_DISPLAY_PRIMARY | HWC_DISPLAY_EXTERNAL;
+ *value = HWC_DISPLAY_PRIMARY | HWC_DISPLAY_EXTERNAL | HWC_DISPLAY_VIRTUAL;
break;
}
return 0;
@@ -789,6 +802,11 @@
}
}
+ ret = ctx->virtual_compositor_worker.Init();
+ if (ret) {
+ ALOGE("Failed to initialize virtual compositor worker");
+ return ret;
+ }
return 0;
}