Skip to content

Commit 7fdaf9d

Browse files
committed
hwcomposer: Support CrOS gralloc handle
Used by gralloc.minigbm_gbm_mesa
1 parent e9251da commit 7fdaf9d

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

hwcomposer/Android.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ cc_library_shared {
4444
],
4545
header_libs: [
4646
"libsystem_headers",
47+
"minigbm_headers",
4748
],
4849
include_dirs: [
4950
"system/core",

hwcomposer/hwcomposer.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <presentation-time-client-protocol.h>
3838
#include <viewporter-client-protocol.h>
3939
#include <gralloc_handle.h>
40+
#include <cros_gralloc/cros_gralloc_handle.h>
4041

4142
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
4243
#include <cutils/trace.h>
@@ -179,11 +180,19 @@ static struct buffer *get_wl_buffer(struct waydroid_hwc_composer_device_1 *pdev,
179180
if (pdev->display->gtype == GRALLOC_GBM) {
180181
struct gralloc_handle_t *drm_handle = (struct gralloc_handle_t *)layer->handle;
181182
if (pdev->display->dmabuf) {
182-
ret = create_dmabuf_wl_buffer(pdev->display, buf, drm_handle->width, drm_handle->height, drm_handle->format, drm_handle->prime_fd, drm_handle->stride, drm_handle->modifier);
183+
ret = create_dmabuf_wl_buffer(pdev->display, buf, drm_handle->width, drm_handle->height, drm_handle->format, drm_handle->prime_fd, drm_handle->stride, 0 /* offset */, drm_handle->modifier, false /* format_is_drm */);
183184
} else {
184185
ret = create_shm_wl_buffer(pdev->display, buf, drm_handle->width, drm_handle->height, drm_handle->format, drm_handle->stride, layer->handle);
185186
update_shm_buffer(pdev->display, buf);
186187
}
188+
} else if (pdev->display->gtype == GRALLOC_CROS) {
189+
const struct cros_gralloc_handle *cros_handle = (const struct cros_gralloc_handle *)layer->handle;
190+
if (pdev->display->dmabuf) {
191+
ret = create_dmabuf_wl_buffer(pdev->display, buf, cros_handle->width, cros_handle->height, cros_handle->format, cros_handle->fds[0], cros_handle->strides[0], cros_handle->offsets[0], cros_handle->format_modifier, true /* format_is_drm */);
192+
} else {
193+
ret = create_shm_wl_buffer(pdev->display, buf, cros_handle->width, cros_handle->height, cros_handle->droid_format, cros_handle->strides[0], layer->handle);
194+
update_shm_buffer(pdev->display, buf);
195+
}
187196
} else {
188197
// TODO: use the actual buffer size
189198
uint32_t format;
@@ -249,7 +258,7 @@ static struct wl_surface *get_surface(struct waydroid_hwc_composer_device_1 *pde
249258

250259
if (pdev->display->viewporter) {
251260
// can't correctly crop on other gralloc implementations yet
252-
if (pdev->display->gtype == GRALLOC_GBM) {
261+
if (pdev->display->gtype == GRALLOC_GBM || pdev->display->gtype == GRALLOC_CROS) {
253262
wp_viewport_set_source(window->viewports[window->lastLayer],
254263
wl_fixed_from_double(fmax(0, sourceCrop.left / (double)pdev->display->scale)),
255264
wl_fixed_from_double(fmax(0, sourceCrop.top / (double)pdev->display->scale)),

hwcomposer/wayland-hwc.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,19 @@ int ConvertHalFormatToDrm(struct display *display, uint32_t hal_format) {
202202
int
203203
create_dmabuf_wl_buffer(struct display *display, struct buffer *buffer,
204204
int width, int height, int format,
205-
int prime_fd, int stride, uint64_t modifier)
205+
int prime_fd, int stride, int offset, uint64_t modifier, bool format_is_drm)
206206
{
207207
struct zwp_linux_buffer_params_v1 *params;
208208

209209
assert(prime_fd >= 0);
210-
buffer->format = ConvertHalFormatToDrm(display, format);
210+
buffer->format = format_is_drm ? format : ConvertHalFormatToDrm(display, format);
211211
assert(buffer->format >= 0);
212212
buffer->width = width;
213213
buffer->height = height;
214214
buffer->stride = stride;
215215

216216
params = zwp_linux_dmabuf_v1_create_params(display->dmabuf);
217-
zwp_linux_buffer_params_v1_add(params, prime_fd, 0, 0, buffer->stride, modifier >> 32, modifier & 0xffffffff);
217+
zwp_linux_buffer_params_v1_add(params, prime_fd, 0, offset, buffer->stride, modifier >> 32, modifier & 0xffffffff);
218218
zwp_linux_buffer_params_v1_add_listener(params, &params_listener, buffer);
219219

220220
buffer->buffer = zwp_linux_buffer_params_v1_create_immed(params, buffer->width, buffer->height, buffer->format, 0);
@@ -1594,7 +1594,7 @@ registry_handle_global(void *data, struct wl_registry *registry,
15941594
(strcmp(interface, "android_wlegl") == 0)) {
15951595
d->android_wlegl = (struct android_wlegl*)wl_registry_bind(registry, id,
15961596
&android_wlegl_interface, 1);
1597-
} else if ((d->gtype == GRALLOC_GBM) &&
1597+
} else if ((d->gtype == GRALLOC_GBM || d->gtype == GRALLOC_CROS) &&
15981598
(strcmp(interface, "zwp_linux_dmabuf_v1") == 0)) {
15991599
if (version < 3)
16001600
return;
@@ -1626,6 +1626,8 @@ get_gralloc_type(const char *gralloc)
16261626
return GRALLOC_DEFAULT;
16271627
} else if (strcmp(gralloc, "gbm") == 0) {
16281628
return GRALLOC_GBM;
1629+
} else if (strcmp(gralloc, "minigbm_gbm_mesa") == 0) {
1630+
return GRALLOC_CROS;
16291631
} else {
16301632
return GRALLOC_ANDROID;
16311633
}

hwcomposer/wayland-hwc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static const char *INPUT_PIPE_NAME[INPUT_TOTAL] = {
6969
enum {
7070
GRALLOC_ANDROID,
7171
GRALLOC_GBM,
72+
GRALLOC_CROS,
7273
GRALLOC_DEFAULT
7374
};
7475

@@ -188,7 +189,7 @@ create_android_wl_buffer(struct display *display, struct buffer *buffer,
188189
int
189190
create_dmabuf_wl_buffer(struct display *display, struct buffer *buffer,
190191
int width, int height, int format,
191-
int prime_fd, int stride, uint64_t modifier);
192+
int prime_fd, int stride, int offset, uint64_t modifier, bool format_is_drm);
192193

193194
int
194195
create_shm_wl_buffer(struct display *display, struct buffer *buffer,

0 commit comments

Comments
 (0)