st/egl: add native_present_control

Replace the parameters of native_surface::present by a struct,
native_present_control.  Using a struct allows us to add more control
options without having to update each backend every time.
This commit is contained in:
Chia-I Wu
2011-09-02 21:26:24 +08:00
parent c0470bf77a
commit 08e1076fd2
11 changed files with 57 additions and 49 deletions
@@ -386,24 +386,22 @@ copy_resources(struct native_display *ndpy,
static boolean
android_surface_present(struct native_surface *nsurf,
enum native_attachment natt,
boolean preserve,
uint swap_interval)
const native_present_control *ctrl)
{
struct android_surface *asurf = android_surface(nsurf);
struct android_display *adpy = asurf->adpy;
boolean ret;
if (swap_interval || natt != NATIVE_ATTACHMENT_BACK_LEFT)
if (ctrl->swap_interval || ctrl->natt != NATIVE_ATTACHMENT_BACK_LEFT)
return FALSE;
/* we always render to color_res first when it exists */
if (asurf->color_res) {
copy_resources(&adpy->base, asurf->color_res, asurf->buf_res);
if (!preserve)
if (!ctrl->preserve)
pipe_resource_reference(&asurf->color_res, NULL);
}
else if (preserve) {
else if (ctrl->preserve) {
struct pipe_resource templ;
memset(&templ, 0, sizeof(templ));
@@ -551,6 +551,7 @@ egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
_EGLContext *ctx = _eglGetCurrentContext();
struct egl_g3d_context *gctx = NULL;
struct native_present_control ctrl;
/* no-op for pixmap or pbuffer surface */
if (gsurf->base.Type == EGL_PIXMAP_BIT ||
@@ -569,10 +570,12 @@ egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
gctx->stctxi->flush(gctx->stctxi, ST_FLUSH_FRONT, NULL);
}
return gsurf->native->present(gsurf->native,
NATIVE_ATTACHMENT_BACK_LEFT,
gsurf->base.SwapBehavior == EGL_BUFFER_PRESERVED,
gsurf->base.SwapInterval);
memset(&ctrl, 0, sizeof(ctrl));
ctrl.natt = NATIVE_ATTACHMENT_BACK_LEFT;
ctrl.preserve = (gsurf->base.SwapBehavior == EGL_BUFFER_PRESERVED);
ctrl.swap_interval = gsurf->base.SwapInterval;
return gsurf->native->present(gsurf->native, &ctrl);
}
static EGLBoolean
@@ -192,9 +192,12 @@ egl_g3d_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi,
{
_EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private;
struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
struct native_present_control ctrl;
return gsurf->native->present(gsurf->native,
NATIVE_ATTACHMENT_FRONT_LEFT, FALSE, 0);
memset(&ctrl, 0, sizeof(ctrl));
ctrl.natt = NATIVE_ATTACHMENT_FRONT_LEFT;
return gsurf->native->present(gsurf->native, &ctrl);
}
static boolean
+15 -3
View File
@@ -73,6 +73,20 @@ enum native_param_type {
NATIVE_PARAM_MAX_SWAP_INTERVAL
};
/**
* Control how a surface presentation should happen.
*/
struct native_present_control {
/**< the attachment to present */
enum native_attachment natt;
/**< the contents of the presented attachment should be preserved */
boolean preserve;
/**< wait until the given vsyncs has passed since the last presentation */
uint swap_interval;
};
struct native_surface {
/**
* Available for caller's use.
@@ -85,9 +99,7 @@ struct native_surface {
* Present the given buffer to the native engine.
*/
boolean (*present)(struct native_surface *nsurf,
enum native_attachment natt,
boolean preserve,
uint swap_interval);
const struct native_present_control *ctrl);
/**
* Validate the buffers of the surface. textures, if not NULL, points to an
@@ -393,12 +393,16 @@ native_display_copy_to_pixmap(struct native_display *ndpy,
dst = tmp[natt];
if (dst && dst->format == src->format) {
struct native_present_control ctrl;
struct pipe_box src_box;
u_box_origin_2d(src->width0, src->height0, &src_box);
pipe->resource_copy_region(pipe, dst, 0, 0, 0, 0, src, 0, &src_box);
pipe->flush(pipe, NULL);
nsurf->present(nsurf, natt, FALSE, 0);
memset(&ctrl, 0, sizeof(ctrl));
ctrl.natt = natt;
nsurf->present(nsurf, &ctrl);
}
if (dst)
+4 -6
View File
@@ -194,21 +194,19 @@ drm_surface_swap_buffers(struct native_surface *nsurf)
static boolean
drm_surface_present(struct native_surface *nsurf,
enum native_attachment natt,
boolean preserve,
uint swap_interval)
const struct native_present_control *ctrl)
{
boolean ret;
if (swap_interval)
if (ctrl->swap_interval)
return FALSE;
switch (natt) {
switch (ctrl->natt) {
case NATIVE_ATTACHMENT_FRONT_LEFT:
ret = drm_surface_flush_frontbuffer(nsurf);
break;
case NATIVE_ATTACHMENT_BACK_LEFT:
if (preserve)
if (ctrl->preserve)
ret = drm_surface_copy_swap(nsurf);
else
ret = drm_surface_swap_buffers(nsurf);
@@ -183,17 +183,15 @@ fbdev_surface_update_drawable(struct native_surface *nsurf,
static boolean
fbdev_surface_present(struct native_surface *nsurf,
enum native_attachment natt,
boolean preserve,
uint swap_interval)
const struct native_present_control *ctrl)
{
struct fbdev_surface *fbsurf = fbdev_surface(nsurf);
struct fbdev_display *fbdpy = fbsurf->fbdpy;
boolean ret = FALSE;
if (swap_interval)
if (ctrl->swap_interval)
return FALSE;
if (natt != NATIVE_ATTACHMENT_BACK_LEFT)
if (ctrl->natt != NATIVE_ATTACHMENT_BACK_LEFT)
return FALSE;
if (!fbdpy->assume_fixed_vinfo) {
@@ -206,7 +204,7 @@ fbdev_surface_present(struct native_surface *nsurf,
/* present the surface */
if (fbdev_surface_update_drawable(&fbsurf->base, &vinfo)) {
ret = resource_surface_present(fbsurf->rsurf,
natt, (void *) &fbsurf->drawable);
ctrl->natt, (void *) &fbsurf->drawable);
}
fbsurf->width = vinfo.xres;
@@ -223,7 +221,7 @@ fbdev_surface_present(struct native_surface *nsurf,
else {
/* the drawable never changes */
ret = resource_surface_present(fbsurf->rsurf,
natt, (void *) &fbsurf->drawable);
ctrl->natt, (void *) &fbsurf->drawable);
}
return ret;
@@ -161,16 +161,14 @@ gdi_surface_swap_buffers(struct native_surface *nsurf)
static boolean
gdi_surface_present(struct native_surface *nsurf,
enum native_attachment natt,
boolean preserve,
uint swap_interval)
const native_present_control *ctrl)
{
boolean ret;
if (preserve || swap_interval)
if (ctrl->preserve || ctrl->swap_interval)
return FALSE;
switch (natt) {
switch (ctrl->natt) {
case NATIVE_ATTACHMENT_FRONT_LEFT:
ret = gdi_surface_flush_frontbuffer(nsurf);
break;
@@ -294,18 +294,16 @@ wayland_surface_swap_buffers(struct native_surface *nsurf)
static boolean
wayland_surface_present(struct native_surface *nsurf,
enum native_attachment natt,
boolean preserve,
uint swap_interval)
const struct native_present_control *ctrl)
{
struct wayland_surface *surface = wayland_surface(nsurf);
uint width, height;
boolean ret;
if (preserve || swap_interval)
if (ctrl->preserve || ctrl->swap_interval)
return FALSE;
switch (natt) {
switch (ctrl->natt) {
case NATIVE_ATTACHMENT_FRONT_LEFT:
ret = TRUE;
break;
@@ -342,16 +342,14 @@ dri2_surface_swap_buffers(struct native_surface *nsurf)
static boolean
dri2_surface_present(struct native_surface *nsurf,
enum native_attachment natt,
boolean preserve,
uint swap_interval)
const struct native_present_control *ctrl)
{
boolean ret;
if (swap_interval)
if (ctrl->swap_interval)
return FALSE;
switch (natt) {
switch (ctrl->natt) {
case NATIVE_ATTACHMENT_FRONT_LEFT:
ret = dri2_surface_flush_frontbuffer(nsurf);
break;
@@ -170,16 +170,14 @@ ximage_surface_swap_buffers(struct native_surface *nsurf)
static boolean
ximage_surface_present(struct native_surface *nsurf,
enum native_attachment natt,
boolean preserve,
uint swap_interval)
const struct native_present_control *ctrl)
{
boolean ret;
if (preserve || swap_interval)
if (ctrl->preserve || ctrl->swap_interval)
return FALSE;
switch (natt) {
switch (ctrl->natt) {
case NATIVE_ATTACHMENT_FRONT_LEFT:
ret = ximage_surface_flush_frontbuffer(nsurf);
break;