From f69b35fa15f43747dde29addaeec845604d7e127 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 9 Apr 2010 17:27:06 +0800 Subject: [PATCH] st/egl: Remove pbuffer from the native interface. A pbuffer is an EGL resource. It does not need a native display to create. --- .../state_trackers/egl/common/egl_g3d.c | 41 +++++++---- .../state_trackers/egl/common/egl_g3d.h | 2 + .../state_trackers/egl/common/egl_g3d_st.c | 57 ++++++++++++++- .../state_trackers/egl/common/native.h | 8 --- .../state_trackers/egl/kms/native_kms.c | 32 +-------- .../state_trackers/egl/kms/native_kms.h | 6 -- .../state_trackers/egl/x11/native_dri2.c | 69 +------------------ .../state_trackers/egl/x11/native_ximage.c | 60 +++++----------- 8 files changed, 105 insertions(+), 170 deletions(-) diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index 5eabe10558a..21fa6c8d4f6 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -524,9 +524,6 @@ egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, case EGL_PIXMAP_BIT: err = "eglCreatePixmapSurface"; break; - case EGL_PBUFFER_BIT: - err = "eglCreatePBufferSurface"; - break; #ifdef EGL_MESA_screen_surface case EGL_SCREEN_BIT_MESA: err = "eglCreateScreenSurface"; @@ -558,10 +555,6 @@ egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, nsurf = gdpy->native->create_pixmap_surface(gdpy->native, arg->u.pix, gconf->native); break; - case EGL_PBUFFER_BIT: - nsurf = gdpy->native->create_pbuffer_surface(gdpy->native, - gconf->native, gsurf->base.Width, gsurf->base.Height); - break; #ifdef EGL_MESA_screen_surface case EGL_SCREEN_BIT_MESA: /* prefer back buffer (move to _eglInitSurface?) */ @@ -593,7 +586,7 @@ egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, gsurf->stfbi = egl_g3d_create_st_framebuffer(&gsurf->base); if (!gsurf->stfbi) { - gsurf->native->destroy(gsurf->native); + nsurf->destroy(nsurf); free(gsurf); return NULL; } @@ -636,12 +629,29 @@ static _EGLSurface * egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attribs) { - struct egl_g3d_create_surface_arg arg; + struct egl_g3d_config *gconf = egl_g3d_config(conf); + struct egl_g3d_surface *gsurf; - memset(&arg, 0, sizeof(arg)); - arg.type = EGL_PBUFFER_BIT; + gsurf = CALLOC_STRUCT(egl_g3d_surface); + if (!gsurf) { + _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface"); + return NULL; + } - return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); + if (!_eglInitSurface(&gsurf->base, dpy, EGL_PBUFFER_BIT, conf, attribs)) { + free(gsurf); + return NULL; + } + + gsurf->stvis = gconf->stvis; + + gsurf->stfbi = egl_g3d_create_st_framebuffer(&gsurf->base); + if (!gsurf->stfbi) { + free(gsurf); + return NULL; + } + + return &gsurf->base; } /** @@ -658,7 +668,8 @@ destroy_surface(_EGLDisplay *dpy, _EGLSurface *surf) pipe_texture_reference(&gsurf->render_texture, NULL); egl_g3d_destroy_st_framebuffer(gsurf->stfbi); - gsurf->native->destroy(gsurf->native); + if (gsurf->native) + gsurf->native->destroy(gsurf->native); free(gsurf); } @@ -879,7 +890,9 @@ egl_g3d_wait_native(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine) if (ctx && ctx->DrawSurface) { struct egl_g3d_surface *gsurf = egl_g3d_surface(ctx->DrawSurface); - gsurf->native->wait(gsurf->native); + + if (gsurf->native) + gsurf->native->wait(gsurf->native); } return EGL_TRUE; diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h index 2788f1bf4ac..ad1c2859aa6 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.h +++ b/src/gallium/state_trackers/egl/common/egl_g3d.h @@ -70,8 +70,10 @@ struct egl_g3d_surface { struct st_visual stvis; struct st_framebuffer_iface *stfbi; + /* the native surface; NULL for pbuffers */ struct native_surface *native; struct pipe_texture *render_texture; + unsigned int sequence_number; }; diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_st.c b/src/gallium/state_trackers/egl/common/egl_g3d_st.c index 9573ba09d12..f4934982edb 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_st.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d_st.c @@ -140,6 +140,53 @@ egl_g3d_destroy_st_manager(struct st_manager *smapi) free(gsmapi); } +static boolean +egl_g3d_st_framebuffer_flush_front_pbuffer(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + return TRUE; +} + +static boolean +egl_g3d_st_framebuffer_validate_pbuffer(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_texture **out) +{ + _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private; + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + struct pipe_texture templ; + unsigned i; + + for (i = 0; i < count; i++) { + out[i] = NULL; + + if (gsurf->stvis.render_buffer != statts[i]) + continue; + + if (!gsurf->render_texture) { + struct egl_g3d_display *gdpy = + egl_g3d_display(gsurf->base.Resource.Display); + struct pipe_screen *screen = gdpy->native->screen; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.last_level = 0; + templ.width0 = gsurf->base.Width; + templ.height0 = gsurf->base.Height; + templ.depth0 = 1; + templ.format = gsurf->stvis.color_format; + templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + + gsurf->render_texture = screen->texture_create(screen, &templ); + } + + pipe_texture_reference(&out[i], gsurf->render_texture); + } + + return TRUE; +} + static boolean egl_g3d_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, enum st_attachment_type statt) @@ -246,8 +293,14 @@ egl_g3d_create_st_framebuffer(_EGLSurface *surf) return NULL; stfbi->visual = &gsurf->stvis; - stfbi->flush_front = egl_g3d_st_framebuffer_flush_front; - stfbi->validate = egl_g3d_st_framebuffer_validate; + if (gsurf->base.Type != EGL_PBUFFER_BIT) { + stfbi->flush_front = egl_g3d_st_framebuffer_flush_front; + stfbi->validate = egl_g3d_st_framebuffer_validate; + } + else { + stfbi->flush_front = egl_g3d_st_framebuffer_flush_front_pbuffer; + stfbi->validate = egl_g3d_st_framebuffer_validate_pbuffer; + } stfbi->st_manager_private = (void *) &gsurf->base; return stfbi; diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h index 93c81b26e10..5062ea10764 100644 --- a/src/gallium/state_trackers/egl/common/native.h +++ b/src/gallium/state_trackers/egl/common/native.h @@ -197,14 +197,6 @@ struct native_display { EGLNativePixmapType pix, const struct native_config *nconf); - /** - * Create a pbuffer surface. Required unless no config has GLX_PBUFFER_BIT - * set. - */ - struct native_surface *(*create_pbuffer_surface)(struct native_display *ndpy, - const struct native_config *nconf, - uint width, uint height); - const struct native_display_modeset *modeset; }; diff --git a/src/gallium/state_trackers/egl/kms/native_kms.c b/src/gallium/state_trackers/egl/kms/native_kms.c index 31747744907..46d3b1c8b1e 100644 --- a/src/gallium/state_trackers/egl/kms/native_kms.c +++ b/src/gallium/state_trackers/egl/kms/native_kms.c @@ -53,9 +53,8 @@ kms_surface_validate(struct native_surface *nsurf, uint attachment_mask, templ.height0 = ksurf->height; templ.depth0 = 1; templ.format = ksurf->color_format; - templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - if (ksurf->type == KMS_SURFACE_TYPE_SCANOUT) - templ.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT; + templ.tex_usage = + PIPE_TEXTURE_USAGE_RENDER_TARGET | PIPE_TEXTURE_USAGE_SCANOUT; } /* create textures */ @@ -155,10 +154,6 @@ kms_surface_flush_frontbuffer(struct native_surface *nsurf) struct kms_surface *ksurf = kms_surface(nsurf); struct kms_display *kdpy = ksurf->kdpy; - /* pbuffer is private */ - if (ksurf->type == KMS_SURFACE_TYPE_PBUFFER) - return TRUE; - if (ksurf->front_fb.is_passive) drmModeDirtyFB(kdpy->fd, ksurf->front_fb.buffer_id, NULL, 0); #endif @@ -176,10 +171,6 @@ kms_surface_swap_buffers(struct native_surface *nsurf) struct pipe_texture *tmp_texture; int err; - /* pbuffer is private */ - if (ksurf->type == KMS_SURFACE_TYPE_PBUFFER) - return TRUE; - if (!ksurf->back_fb.buffer_id) { if (!kms_surface_init_framebuffers(&ksurf->base, TRUE)) return FALSE; @@ -244,7 +235,6 @@ kms_surface_destroy(struct native_surface *nsurf) static struct kms_surface * kms_display_create_surface(struct native_display *ndpy, - enum kms_surface_type type, const struct native_config *nconf, uint width, uint height) { @@ -257,7 +247,6 @@ kms_display_create_surface(struct native_display *ndpy, return NULL; ksurf->kdpy = kdpy; - ksurf->type = type; ksurf->color_format = kconf->base.color_format; ksurf->width = width; ksurf->height = height; @@ -567,24 +556,10 @@ kms_display_create_scanout_surface(struct native_display *ndpy, { struct kms_surface *ksurf; - ksurf = kms_display_create_surface(ndpy, - KMS_SURFACE_TYPE_SCANOUT, nconf, width, height); - return &ksurf->base; -} - -static struct native_surface * -kms_display_create_pbuffer_surface(struct native_display *ndpy, - const struct native_config *nconf, - uint width, uint height) -{ - struct kms_surface *ksurf; - - ksurf = kms_display_create_surface(ndpy, - KMS_SURFACE_TYPE_PBUFFER, nconf, width, height); + ksurf = kms_display_create_surface(ndpy, nconf, width, height); return &ksurf->base; } - static boolean kms_display_is_format_supported(struct native_display *ndpy, enum pipe_format fmt, boolean is_color) @@ -832,7 +807,6 @@ kms_create_display(EGLNativeDisplayType dpy, kdpy->base.destroy = kms_display_destroy; kdpy->base.get_param = kms_display_get_param; kdpy->base.get_configs = kms_display_get_configs; - kdpy->base.create_pbuffer_surface = kms_display_create_pbuffer_surface; kdpy->base.modeset = &kms_display_modeset; diff --git a/src/gallium/state_trackers/egl/kms/native_kms.h b/src/gallium/state_trackers/egl/kms/native_kms.h index f9cbcb158b5..b1d1b915b29 100644 --- a/src/gallium/state_trackers/egl/kms/native_kms.h +++ b/src/gallium/state_trackers/egl/kms/native_kms.h @@ -35,11 +35,6 @@ #include "common/native.h" -enum kms_surface_type { - KMS_SURFACE_TYPE_PBUFFER, - KMS_SURFACE_TYPE_SCANOUT -}; - struct kms_config; struct kms_connector; struct kms_mode; @@ -77,7 +72,6 @@ struct kms_framebuffer { struct kms_surface { struct native_surface base; - enum kms_surface_type type; enum pipe_format color_format; struct kms_display *kdpy; int width, height; diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c index 8c0553ce0d5..ad2fc24ed01 100644 --- a/src/gallium/state_trackers/egl/x11/native_dri2.c +++ b/src/gallium/state_trackers/egl/x11/native_dri2.c @@ -40,7 +40,6 @@ enum dri2_surface_type { DRI2_SURFACE_TYPE_WINDOW, DRI2_SURFACE_TYPE_PIXMAP, - DRI2_SURFACE_TYPE_PBUFFER }; struct dri2_display { @@ -257,47 +256,8 @@ static boolean dri2_surface_update_buffers(struct native_surface *nsurf, uint buffer_mask) { struct dri2_surface *dri2surf = dri2_surface(nsurf); - struct dri2_display *dri2dpy = dri2surf->dri2dpy; - - /* create textures for pbuffer */ - if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) { - struct pipe_screen *screen = dri2dpy->base.screen; - struct pipe_texture templ; - uint new_valid = 0x0; - int att; - buffer_mask &= ~dri2surf->valid_mask; - if (!buffer_mask) - return TRUE; - - memset(&templ, 0, sizeof(templ)); - templ.target = PIPE_TEXTURE_2D; - templ.last_level = 0; - templ.width0 = dri2surf->width; - templ.height0 = dri2surf->height; - templ.depth0 = 1; - templ.format = dri2surf->color_format; - templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - - for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { - if (native_attachment_mask_test(buffer_mask, att)) { - assert(!dri2surf->textures[att]); - - dri2surf->textures[att] = screen->texture_create(screen, &templ); - if (!dri2surf->textures[att]) - break; - - new_valid |= 1 << att; - if (new_valid == buffer_mask) - break; - } - } - dri2surf->valid_mask |= new_valid; - /* no need to update the stamps */ - } - else { - dri2_surface_get_buffers(&dri2surf->base, buffer_mask); - } + dri2_surface_get_buffers(&dri2surf->base, buffer_mask); return ((dri2surf->valid_mask & buffer_mask) == buffer_mask); } @@ -318,10 +278,6 @@ dri2_surface_flush_frontbuffer(struct native_surface *nsurf) struct dri2_surface *dri2surf = dri2_surface(nsurf); struct dri2_display *dri2dpy = dri2surf->dri2dpy; - /* pbuffer is private */ - if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) - return TRUE; - /* copy to real front buffer */ if (dri2surf->have_fake) x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, @@ -344,10 +300,6 @@ dri2_surface_swap_buffers(struct native_surface *nsurf) struct dri2_surface *dri2surf = dri2_surface(nsurf); struct dri2_display *dri2dpy = dri2surf->dri2dpy; - /* pbuffer is private */ - if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) - return TRUE; - /* copy to front buffer */ if (dri2surf->have_back) x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, @@ -504,22 +456,6 @@ dri2_display_create_pixmap_surface(struct native_display *ndpy, return (dri2surf) ? &dri2surf->base : NULL; } -static struct native_surface * -dri2_display_create_pbuffer_surface(struct native_display *ndpy, - const struct native_config *nconf, - uint width, uint height) -{ - struct dri2_surface *dri2surf; - - dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_PBUFFER, - (Drawable) None, nconf); - if (dri2surf) { - dri2surf->width = width; - dri2surf->height = height; - } - return (dri2surf) ? &dri2surf->base : NULL; -} - static int choose_color_format(const __GLcontextModes *mode, enum pipe_format formats[32]) { @@ -603,7 +539,7 @@ dri2_display_convert_config(struct native_display *ndpy, nconf->mode = *mode; nconf->mode.renderType = GLX_RGBA_BIT; nconf->mode.rgbMode = TRUE; - /* pbuffer is allocated locally and is always supported */ + /* pbuffer is always supported */ nconf->mode.drawableType |= GLX_PBUFFER_BIT; /* the swap method is always copy */ nconf->mode.swapMethod = GLX_SWAP_COPY_OML; @@ -877,7 +813,6 @@ x11_create_dri2_display(EGLNativeDisplayType dpy, dri2dpy->base.is_pixmap_supported = dri2_display_is_pixmap_supported; dri2dpy->base.create_window_surface = dri2_display_create_window_surface; dri2dpy->base.create_pixmap_surface = dri2_display_create_pixmap_surface; - dri2dpy->base.create_pbuffer_surface = dri2_display_create_pbuffer_surface; return &dri2dpy->base; } diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c index d69011ac5ee..fdb4825b5f2 100644 --- a/src/gallium/state_trackers/egl/x11/native_ximage.c +++ b/src/gallium/state_trackers/egl/x11/native_ximage.c @@ -47,7 +47,6 @@ enum ximage_surface_type { XIMAGE_SURFACE_TYPE_WINDOW, XIMAGE_SURFACE_TYPE_PIXMAP, - XIMAGE_SURFACE_TYPE_PBUFFER }; struct ximage_display { @@ -140,20 +139,19 @@ ximage_surface_alloc_buffer(struct native_surface *nsurf, templ.depth0 = 1; templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER) { - switch (which) { - case NATIVE_ATTACHMENT_FRONT_LEFT: - case NATIVE_ATTACHMENT_FRONT_RIGHT: - templ.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT; - break; - case NATIVE_ATTACHMENT_BACK_LEFT: - case NATIVE_ATTACHMENT_BACK_RIGHT: - templ.tex_usage |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET; - break; - default: - break; - } + switch (which) { + case NATIVE_ATTACHMENT_FRONT_LEFT: + case NATIVE_ATTACHMENT_FRONT_RIGHT: + templ.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT; + break; + case NATIVE_ATTACHMENT_BACK_LEFT: + case NATIVE_ATTACHMENT_BACK_RIGHT: + templ.tex_usage |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET; + break; + default: + break; } + xbuf->texture = screen->texture_create(screen, &templ); if (xbuf->texture) { xbuf->xdraw.visual = xsurf->visual.visual; @@ -182,10 +180,6 @@ ximage_surface_update_geometry(struct native_surface *nsurf) unsigned int w, h, border, depth; boolean updated = FALSE; - /* pbuffer has fixed geometry */ - if (xsurf->type == XIMAGE_SURFACE_TYPE_PBUFFER) - return FALSE; - ok = XGetGeometry(xsurf->xdpy->dpy, xsurf->drawable, &root, &x, &y, &w, &h, &border, &depth); if (ok && (xsurf->width != w || xsurf->height != h)) { @@ -263,9 +257,6 @@ ximage_surface_draw_buffer(struct native_surface *nsurf, struct pipe_screen *screen = xsurf->xdpy->base.screen; struct pipe_surface *psurf; - if (xsurf->type == XIMAGE_SURFACE_TYPE_PBUFFER) - return TRUE; - assert(xsurf->drawable && xbuf->texture); psurf = xsurf->draw_surface; @@ -404,12 +395,10 @@ ximage_display_create_surface(struct native_display *ndpy, xsurf->color_format = xconf->base.color_format; xsurf->drawable = drawable; - if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER) { - xsurf->drawable = drawable; - xsurf->visual = *xconf->visual; - /* initialize the geometry */ - ximage_surface_update_buffers(&xsurf->base, 0x0); - } + xsurf->drawable = drawable; + xsurf->visual = *xconf->visual; + /* initialize the geometry */ + ximage_surface_update_buffers(&xsurf->base, 0x0); xsurf->base.destroy = ximage_surface_destroy; xsurf->base.swap_buffers = ximage_surface_swap_buffers; @@ -444,22 +433,6 @@ ximage_display_create_pixmap_surface(struct native_display *ndpy, return (xsurf) ? &xsurf->base : NULL; } -static struct native_surface * -ximage_display_create_pbuffer_surface(struct native_display *ndpy, - const struct native_config *nconf, - uint width, uint height) -{ - struct ximage_surface *xsurf; - - xsurf = ximage_display_create_surface(ndpy, XIMAGE_SURFACE_TYPE_PBUFFER, - (Drawable) None, nconf); - if (xsurf) { - xsurf->width = width; - xsurf->height = height; - } - return (xsurf) ? &xsurf->base : NULL; -} - static enum pipe_format choose_format(const XVisualInfo *vinfo) { @@ -718,7 +691,6 @@ x11_create_ximage_display(EGLNativeDisplayType dpy, xdpy->base.is_pixmap_supported = ximage_display_is_pixmap_supported; xdpy->base.create_window_surface = ximage_display_create_window_surface; xdpy->base.create_pixmap_surface = ximage_display_create_pixmap_surface; - xdpy->base.create_pbuffer_surface = ximage_display_create_pbuffer_surface; return &xdpy->base; } -- 2.30.2