Mesa (master): st/egl: Cache the pipe surface used in flush_frontbuffer.

Chia-I Wu olv at kemper.freedesktop.org
Sat Mar 13 05:05:33 UTC 2010


Module: Mesa
Branch: master
Commit: 9222c0934910172daf2405b0e581becdfbc80405
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9222c0934910172daf2405b0e581becdfbc80405

Author: Chia-I Wu <olv at lunarg.com>
Date:   Sat Mar 13 00:48:23 2010 +0800

st/egl: Cache the pipe surface used in flush_frontbuffer.

It is very likely that the same surface will be flushed again and again.
Caching the surface should reduce the overhead of surface creation.

---

 src/gallium/state_trackers/egl/x11/native_ximage.c |   22 +++++++++++++------
 1 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c
index e0d12ac..c6b1635 100644
--- a/src/gallium/state_trackers/egl/x11/native_ximage.c
+++ b/src/gallium/state_trackers/egl/x11/native_ximage.c
@@ -82,6 +82,8 @@ struct ximage_surface {
    int width, height;
    struct ximage_buffer buffers[NUM_NATIVE_ATTACHMENTS];
    uint valid_mask;
+
+   struct pipe_surface *draw_surface;
 };
 
 struct ximage_config {
@@ -266,15 +268,19 @@ ximage_surface_draw_buffer(struct native_surface *nsurf,
 
    assert(xsurf->drawable && xbuf->texture);
 
-   /* what's the cost of surface creation? */
-   psurf = screen->get_tex_surface(screen,
-         xbuf->texture, 0, 0, 0, PIPE_BUFFER_USAGE_CPU_READ);
-   if (!psurf)
-      return FALSE;
+   psurf = xsurf->draw_surface;
+   if (!psurf || psurf->texture != xbuf->texture) {
+      pipe_surface_reference(&xsurf->draw_surface, NULL);
 
-   screen->flush_frontbuffer(screen, psurf, &xbuf->xdraw);
+      psurf = screen->get_tex_surface(screen,
+            xbuf->texture, 0, 0, 0, PIPE_BUFFER_USAGE_CPU_READ);
+      if (!psurf)
+         return FALSE;
 
-   pipe_surface_reference(&psurf, NULL);
+      xsurf->draw_surface = psurf;
+   }
+
+   screen->flush_frontbuffer(screen, psurf, &xbuf->xdraw);
 
    return TRUE;
 }
@@ -371,6 +377,8 @@ ximage_surface_destroy(struct native_surface *nsurf)
    struct ximage_surface *xsurf = ximage_surface(nsurf);
    int i;
 
+   pipe_surface_reference(&xsurf->draw_surface, NULL);
+
    for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++)
       ximage_surface_free_buffer(&xsurf->base, i);
 




More information about the mesa-commit mailing list