disp->DriverData = NULL;
}
+__DRIbuffer *
+dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
+ unsigned int att, unsigned int format)
+{
+ struct dri2_egl_display *dri2_dpy =
+ dri2_egl_display(dri2_surf->base.Resource.Display);
+
+ if (att >= ARRAY_SIZE(dri2_surf->local_buffers))
+ return NULL;
+
+ if (!dri2_surf->local_buffers[att]) {
+ dri2_surf->local_buffers[att] =
+ dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen, att, format,
+ dri2_surf->base.Width, dri2_surf->base.Height);
+ }
+
+ return dri2_surf->local_buffers[att];
+}
+
+void
+dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf)
+{
+ struct dri2_egl_display *dri2_dpy =
+ dri2_egl_display(dri2_surf->base.Resource.Display);
+
+ for (int i = 0; i < ARRAY_SIZE(dri2_surf->local_buffers); i++) {
+ if (dri2_surf->local_buffers[i]) {
+ dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen,
+ dri2_surf->local_buffers[i]);
+ dri2_surf->local_buffers[i] = NULL;
+ }
+ }
+}
+
/**
* Called via eglTerminate(), drv->API.Terminate().
*
struct gbm_dri_surface *gbm_surf;
#endif
+ /* EGL-owned buffers */
+ __DRIbuffer *local_buffers[__DRI_BUFFER_COUNT];
+
#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
- __DRIbuffer *dri_buffers[__DRI_BUFFER_COUNT];
struct {
#ifdef HAVE_WAYLAND_PLATFORM
struct wl_buffer *wl_buffer;
__DRIimage *dri_image_back;
__DRIimage *dri_image_front;
- /* EGL-owned buffers */
- __DRIbuffer *local_buffers[__DRI_BUFFER_COUNT];
-
/* Used to record all the buffers created by ANativeWindow and their ages.
* Usually Android uses at most triple buffers in ANativeWindow
* so hardcode the number of color_buffers to 3.
void
dri2_display_destroy(_EGLDisplay *disp);
+__DRIbuffer *
+dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
+ unsigned int att, unsigned int format);
+
+void
+dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf);
+
#endif /* EGL_DRI2_INCLUDED */
}
}
-static __DRIbuffer *
-droid_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
- unsigned int att, unsigned int format)
-{
- struct dri2_egl_display *dri2_dpy =
- dri2_egl_display(dri2_surf->base.Resource.Display);
-
- if (att >= ARRAY_SIZE(dri2_surf->local_buffers))
- return NULL;
-
- if (!dri2_surf->local_buffers[att]) {
- dri2_surf->local_buffers[att] =
- dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen, att, format,
- dri2_surf->base.Width, dri2_surf->base.Height);
- }
-
- return dri2_surf->local_buffers[att];
-}
-
-static void
-droid_free_local_buffers(struct dri2_egl_surface *dri2_surf)
-{
- struct dri2_egl_display *dri2_dpy =
- dri2_egl_display(dri2_surf->base.Resource.Display);
-
- for (int i = 0; i < ARRAY_SIZE(dri2_surf->local_buffers); i++) {
- if (dri2_surf->local_buffers[i]) {
- dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen,
- dri2_surf->local_buffers[i]);
- dri2_surf->local_buffers[i] = NULL;
- }
- }
-}
-
static _EGLSurface *
droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
_EGLConfig *conf, void *native_window,
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
- droid_free_local_buffers(dri2_surf);
+ dri2_egl_surface_free_local_buffers(dri2_surf);
if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
if (dri2_surf->buffer)
/* free outdated buffers and update the surface size */
if (dri2_surf->base.Width != dri2_surf->buffer->width ||
dri2_surf->base.Height != dri2_surf->buffer->height) {
- droid_free_local_buffers(dri2_surf);
+ dri2_egl_surface_free_local_buffers(dri2_surf);
dri2_surf->base.Width = dri2_surf->buffer->width;
dri2_surf->base.Height = dri2_surf->buffer->height;
}
case __DRI_BUFFER_ACCUM:
case __DRI_BUFFER_DEPTH_STENCIL:
case __DRI_BUFFER_HIZ:
- local = droid_alloc_local_buffer(dri2_surf,
+ local = dri2_egl_surface_alloc_local_buffer(dri2_surf,
attachments[i], attachments[i + 1]);
if (local) {
gbm_bo_destroy(dri2_surf->color_buffers[i].bo);
}
- for (unsigned i = 0; i < __DRI_BUFFER_COUNT; i++) {
- if (dri2_surf->dri_buffers[i])
- dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen,
- dri2_surf->dri_buffers[i]);
- }
+ dri2_egl_surface_free_local_buffers(dri2_surf);
free(surf);
buffer->flags = 0;
}
-static int
-get_aux_bo(struct dri2_egl_surface *dri2_surf,
- unsigned int attachment, unsigned int format, __DRIbuffer *buffer)
-{
- struct dri2_egl_display *dri2_dpy =
- dri2_egl_display(dri2_surf->base.Resource.Display);
- __DRIbuffer *b = dri2_surf->dri_buffers[attachment];
-
- if (b == NULL) {
- b = dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen,
- attachment, format,
- dri2_surf->base.Width,
- dri2_surf->base.Height);
- dri2_surf->dri_buffers[attachment] = b;
- }
- if (b == NULL)
- return -1;
-
- memcpy(buffer, b, sizeof *buffer);
-
- return 0;
-}
-
static __DRIbuffer *
dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable,
- int *width, int *height,
- unsigned int *attachments, int count,
- int *out_count, void *loaderPrivate)
+ int *width, int *height,
+ unsigned int *attachments, int count,
+ int *out_count, void *loaderPrivate)
{
struct dri2_egl_surface *dri2_surf = loaderPrivate;
int i, j;
for (i = 0, j = 0; i < 2 * count; i += 2, j++) {
+ __DRIbuffer *local;
+
assert(attachments[i] < __DRI_BUFFER_COUNT);
assert(j < ARRAY_SIZE(dri2_surf->buffers));
back_bo_to_dri_buffer(dri2_surf, &dri2_surf->buffers[j]);
break;
default:
- if (get_aux_bo(dri2_surf, attachments[i], attachments[i + 1],
- &dri2_surf->buffers[j]) < 0) {
- _eglError(EGL_BAD_ALLOC, "failed to allocate aux buffer");
+ local = dri2_egl_surface_alloc_local_buffer(dri2_surf, attachments[i],
+ attachments[i + 1]);
+
+ if (!local) {
+ _eglError(EGL_BAD_ALLOC, "failed to allocate local buffer");
return NULL;
}
+ dri2_surf->buffers[j] = *local;
break;
}
}
dri2_surf->color_buffers[i].data_size);
}
- if (dri2_dpy->dri2) {
- for (int i = 0; i < __DRI_BUFFER_COUNT; i++)
- if (dri2_surf->dri_buffers[i] &&
- dri2_surf->dri_buffers[i]->attachment != __DRI_BUFFER_BACK_LEFT)
- dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen,
- dri2_surf->dri_buffers[i]);
- }
+ if (dri2_dpy->dri2)
+ dri2_egl_surface_free_local_buffers(dri2_surf);
if (dri2_surf->throttle_callback)
wl_callback_destroy(dri2_surf->throttle_callback);
dri2_surf->color_buffers[i].locked = false;
}
- if (dri2_dpy->dri2) {
- for (int i = 0; i < __DRI_BUFFER_COUNT; i++)
- if (dri2_surf->dri_buffers[i] &&
- dri2_surf->dri_buffers[i]->attachment != __DRI_BUFFER_BACK_LEFT)
- dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen,
- dri2_surf->dri_buffers[i]);
- }
+ if (dri2_dpy->dri2)
+ dri2_egl_surface_free_local_buffers(dri2_surf);
}
static int
buffer->flags = 0;
}
-static int
-get_aux_bo(struct dri2_egl_surface *dri2_surf,
- unsigned int attachment, unsigned int format, __DRIbuffer *buffer)
-{
- struct dri2_egl_display *dri2_dpy =
- dri2_egl_display(dri2_surf->base.Resource.Display);
- __DRIbuffer *b = dri2_surf->dri_buffers[attachment];
-
- if (b == NULL) {
- b = dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen,
- attachment, format,
- dri2_surf->base.Width,
- dri2_surf->base.Height);
- dri2_surf->dri_buffers[attachment] = b;
- }
- if (b == NULL)
- return -1;
-
- memcpy(buffer, b, sizeof *buffer);
-
- return 0;
-}
-
static int
update_buffers(struct dri2_egl_surface *dri2_surf)
{
return NULL;
for (i = 0, j = 0; i < 2 * count; i += 2, j++) {
+ __DRIbuffer *local;
+
switch (attachments[i]) {
case __DRI_BUFFER_BACK_LEFT:
back_bo_to_dri_buffer(dri2_surf, &dri2_surf->buffers[j]);
break;
default:
- if (get_aux_bo(dri2_surf, attachments[i], attachments[i + 1],
- &dri2_surf->buffers[j]) < 0) {
- _eglError(EGL_BAD_ALLOC, "failed to allocate aux buffer");
+ local = dri2_egl_surface_alloc_local_buffer(dri2_surf, attachments[i],
+ attachments[i + 1]);
+
+ if (!local) {
+ _eglError(EGL_BAD_ALLOC, "failed to allocate local buffer");
return NULL;
}
+ dri2_surf->buffers[j] = *local;
break;
}
}