From 5fdb5853878be164988f0c910c79fbde4ba849a9 Mon Sep 17 00:00:00 2001 From: Erfan Abdi Date: Tue, 29 Jun 2021 07:14:44 +0430 Subject: [PATCH] =?UTF-8?q?anbox:=20hwc:=20Don=E2=80=99t=20create=20dummy?= =?UTF-8?q?=20surface=20for=20single=20window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwcomposer/hwcomposer.cpp | 18 +++++++++++++----- hwcomposer/wayland-hwc.cpp | 29 +++++++++++++++-------------- hwcomposer/wayland-hwc.h | 2 +- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/hwcomposer/hwcomposer.cpp b/hwcomposer/hwcomposer.cpp index 64ce09e..3193235 100644 --- a/hwcomposer/hwcomposer.cpp +++ b/hwcomposer/hwcomposer.cpp @@ -143,8 +143,15 @@ static struct buffer *get_wl_buffer(struct anbox_hwc_composer_device_1 *pdev, hw return pdev->display->buffer_map[layer->handle]; } -static struct wl_surface *get_surface(struct anbox_hwc_composer_device_1 *pdev, hwc_layer_1_t *layer, struct window *window) +static struct wl_surface *get_surface(struct anbox_hwc_composer_device_1 *pdev, hwc_layer_1_t *layer, struct window *window, bool multi) { + if (!multi) { + pdev->display->layers[window->surface] = { + .x = layer->displayFrame.left, + .y = layer->displayFrame.top }; + return window->surface; + } + struct wl_surface *surface = NULL; struct wl_subsurface *subsurface = NULL; int left = layer->displayFrame.left; @@ -442,7 +449,7 @@ static int hwc_set(struct hwc_composer_device_1* dev,size_t numDisplays, if (active_apps == "full" || !pdev->use_subsurface) { // Show everything in a single window if (pdev->windows.find("full") == pdev->windows.end()) { - pdev->windows["full"] = create_window(pdev->display); + pdev->windows["full"] = create_window(pdev->display, pdev->use_subsurface); } window = pdev->windows["full"]; } else { @@ -455,7 +462,7 @@ static int hwc_set(struct hwc_composer_device_1* dev,size_t numDisplays, std::string app; while (std::getline(issAA, app, ':')) { if (app == AppID) - pdev->windows[AppID] = create_window(pdev->display); + pdev->windows[AppID] = create_window(pdev->display, pdev->use_subsurface); } } if (pdev->windows.find(AppID) != pdev->windows.end()) @@ -516,7 +523,7 @@ static int hwc_set(struct hwc_composer_device_1* dev,size_t numDisplays, } buf->timeline_fd = pdev->timeline_fd; - struct wl_surface *surface = get_surface(pdev, fb_layer, window); + struct wl_surface *surface = get_surface(pdev, fb_layer, window, pdev->use_subsurface); if (!surface) { ALOGE("Failed to get surface"); continue; @@ -536,7 +543,8 @@ static int hwc_set(struct hwc_composer_device_1* dev,size_t numDisplays, } wl_surface_commit(surface); - wl_surface_commit(window->surface); + if (pdev->use_subsurface) + wl_surface_commit(window->surface); const int kAcquireWarningMS = 100; err = sync_wait(fb_layer->acquireFenceFd, kAcquireWarningMS); diff --git a/hwcomposer/wayland-hwc.cpp b/hwcomposer/wayland-hwc.cpp index 9bcd296..004b7fc 100644 --- a/hwcomposer/wayland-hwc.cpp +++ b/hwcomposer/wayland-hwc.cpp @@ -247,7 +247,7 @@ destroy_window(struct window *window) } struct window * -create_window(struct display *display) +create_window(struct display *display, bool with_dummy) { struct window *window = new struct window(); if (!window) @@ -282,20 +282,21 @@ create_window(struct display *display) * * TODO: Drop this hack */ - int fd = syscall(SYS_memfd_create, "buffer", 0); - ftruncate(fd, 4); - void *shm_data = mmap(NULL, 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (shm_data == MAP_FAILED) { - fprintf(stderr, "mmap failed: %m\n"); - close(fd); - exit(1); + if (with_dummy) { + int fd = syscall(SYS_memfd_create, "buffer", 0); + ftruncate(fd, 4); + void *shm_data = mmap(NULL, 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (shm_data == MAP_FAILED) { + fprintf(stderr, "mmap failed: %m\n"); + close(fd); + exit(1); + } + struct wl_shm_pool *pool = wl_shm_create_pool(display->shm, fd, 4); + struct wl_buffer *buffer_shm = wl_shm_pool_create_buffer(pool, 0, 1, 1, 4, WL_SHM_FORMAT_ARGB8888); + wl_shm_pool_destroy(pool); + wl_surface_attach(window->surface, buffer_shm, 0, 0); + wl_surface_damage(window->surface, 0, 0, 1, 1); } - struct wl_shm_pool *pool = wl_shm_create_pool(display->shm, fd, 4); - struct wl_buffer *buffer_shm = wl_shm_pool_create_buffer(pool, 0, 1, 1, 4, WL_SHM_FORMAT_ARGB8888); - wl_shm_pool_destroy(pool); - wl_surface_attach(window->surface, buffer_shm, 0, 0); - wl_surface_damage(window->surface, 0, 0, 1, 1); - } else { assert(0); } diff --git a/hwcomposer/wayland-hwc.h b/hwcomposer/wayland-hwc.h index dfeee36..b6e1ee2 100644 --- a/hwcomposer/wayland-hwc.h +++ b/hwcomposer/wayland-hwc.h @@ -157,4 +157,4 @@ destroy_display(struct display *display); void destroy_window(struct window *window); struct window * -create_window(struct display *display); +create_window(struct display *display, bool with_dummy);