Skip to content
This repository has been archived by the owner on Aug 27, 2021. It is now read-only.

Commit

Permalink
anbox: hwc: Don’t create dummy surface for single window
Browse files Browse the repository at this point in the history
  • Loading branch information
erfanoabdi committed Jun 29, 2021
1 parent 2c28446 commit 5fdb585
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
18 changes: 13 additions & 5 deletions hwcomposer/hwcomposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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())
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
29 changes: 15 additions & 14 deletions hwcomposer/wayland-hwc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion hwcomposer/wayland-hwc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 5fdb585

Please sign in to comment.