[Mesa-dev] [PATCH 2/2] st/egl: Implement EGL_NOK_swap_region for x11

2011-12-14 Thread Fredrik Höglund
v2: inline x11_drawable_copy_buffers().

Signed-off-by: Fredrik Höglund fred...@kde.org
---
 src/gallium/state_trackers/egl/x11/native_dri2.c |   36 --
 src/gallium/state_trackers/egl/x11/x11_screen.c  |   21 +++-
 src/gallium/state_trackers/egl/x11/x11_screen.h  |   14 -
 3 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c 
b/src/gallium/state_trackers/egl/x11/native_dri2.c
index 4754744..9ea3b80 100644
--- a/src/gallium/state_trackers/egl/x11/native_dri2.c
+++ b/src/gallium/state_trackers/egl/x11/native_dri2.c
@@ -313,22 +313,35 @@ dri2_surface_flush_frontbuffer(struct native_surface 
*nsurf)
 }
 
 static boolean
-dri2_surface_swap_buffers(struct native_surface *nsurf)
+dri2_surface_swap_buffers(struct native_surface *nsurf, int num_rects,
+  const int *rects)
 {
struct dri2_surface *dri2surf = dri2_surface(nsurf);
struct dri2_display *dri2dpy = dri2surf-dri2dpy;
 
/* copy to front buffer */
-   if (dri2surf-have_back)
-  x11_drawable_copy_buffers(dri2dpy-xscr, dri2surf-drawable,
-0, 0, dri2surf-width, dri2surf-height,
-DRI2BufferBackLeft, DRI2BufferFrontLeft);
+   if (dri2surf-have_back) {
+  if (num_rects  0)
+ x11_drawable_copy_buffers_region(dri2dpy-xscr, dri2surf-drawable,
+   num_rects, rects,
+   DRI2BufferBackLeft, DRI2BufferFrontLeft);
+  else
+ x11_drawable_copy_buffers(dri2dpy-xscr, dri2surf-drawable,
+   0, 0, dri2surf-width, dri2surf-height,
+   DRI2BufferBackLeft, DRI2BufferFrontLeft);
+   }
 
/* and update fake front buffer */
-   if (dri2surf-have_fake)
-  x11_drawable_copy_buffers(dri2dpy-xscr, dri2surf-drawable,
-0, 0, dri2surf-width, dri2surf-height,
-DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
+   if (dri2surf-have_fake) {
+  if (num_rects  0)
+ x11_drawable_copy_buffers_region(dri2dpy-xscr, dri2surf-drawable,
+   num_rects, rects,
+   DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
+  else
+ x11_drawable_copy_buffers(dri2dpy-xscr, dri2surf-drawable,
+   0, 0, dri2surf-width, dri2surf-height,
+   DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
+   }
 
/* force buffers to be updated in next validation call */
if (!dri2_surface_receive_events(dri2surf-base)) {
@@ -354,7 +367,7 @@ dri2_surface_present(struct native_surface *nsurf,
   ret = dri2_surface_flush_frontbuffer(nsurf);
   break;
case NATIVE_ATTACHMENT_BACK_LEFT:
-  ret = dri2_surface_swap_buffers(nsurf);
+  ret = dri2_surface_swap_buffers(nsurf, ctrl-num_rects, ctrl-rects);
   break;
default:
   ret = FALSE;
@@ -722,6 +735,9 @@ dri2_display_get_param(struct native_display *ndpy,
   /* DRI2CopyRegion is used */
   val = TRUE;
   break;
+   case NATIVE_PARAM_PRESENT_REGION:
+  val = TRUE;
+  break;
case NATIVE_PARAM_MAX_SWAP_INTERVAL:
default:
   val = 0;
diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.c 
b/src/gallium/state_trackers/egl/x11/x11_screen.c
index 6155b4d..1e20f94 100644
--- a/src/gallium/state_trackers/egl/x11/x11_screen.c
+++ b/src/gallium/state_trackers/egl/x11/x11_screen.c
@@ -341,21 +341,24 @@ x11_drawable_enable_dri2(struct x11_screen *xscr,
  * Copy between buffers of the DRI2 drawable.
  */
 void
-x11_drawable_copy_buffers(struct x11_screen *xscr, Drawable drawable,
-  int x, int y, int width, int height,
-  int src_buf, int dst_buf)
+x11_drawable_copy_buffers_region(struct x11_screen *xscr, Drawable drawable,
+ int num_rects, const int *rects,
+ int src_buf, int dst_buf)
 {
-   XRectangle rect;
XserverRegion region;
+   XRectangle *rectangles = CALLOC(num_rects, sizeof(XRectangle));
 
-   rect.x = x;
-   rect.y = y;
-   rect.width = width;
-   rect.height = height;
+   for (int i = 0; i  num_rects; i++) {
+  rectangles[i].x = rects[i * 4 + 0];
+  rectangles[i].y = rects[i * 4 + 1];
+  rectangles[i].width = rects[i * 4 + 2];
+  rectangles[i].height = rects[i * 4 + 3];
+   }
 
-   region = XFixesCreateRegion(xscr-dpy, rect, 1);
+   region = XFixesCreateRegion(xscr-dpy, rectangles, num_rects);
DRI2CopyRegion(xscr-dpy, drawable, region, dst_buf, src_buf);
XFixesDestroyRegion(xscr-dpy, region);
+   FREE(rectangles);
 }
 
 /**
diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.h 
b/src/gallium/state_trackers/egl/x11/x11_screen.h
index acf1300..db1b218 100644
--- a/src/gallium/state_trackers/egl/x11/x11_screen.h
+++ b/src/gallium/state_trackers/egl/x11/x11_screen.h
@@ -108,9 +108,21 @@ x11_drawable_enable_dri2(struct x11_screen *xscr,
  Drawable drawable, boolean on);
 
 void
+x11_drawable_copy_buffers_region(struct x11_screen 

[Mesa-dev] [PATCH 2/2] st/egl: Implement EGL_NOK_swap_region for x11

2011-12-09 Thread Fredrik Höglund
Signed-off-by: Fredrik Höglund fred...@kde.org
---
 src/gallium/state_trackers/egl/x11/native_dri2.c |   16 +-
 src/gallium/state_trackers/egl/x11/x11_screen.c  |   24 ++
 src/gallium/state_trackers/egl/x11/x11_screen.h  |5 
 3 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c 
b/src/gallium/state_trackers/egl/x11/native_dri2.c
index 4754744..a976dd4 100644
--- a/src/gallium/state_trackers/egl/x11/native_dri2.c
+++ b/src/gallium/state_trackers/egl/x11/native_dri2.c
@@ -313,21 +313,22 @@ dri2_surface_flush_frontbuffer(struct native_surface 
*nsurf)
 }
 
 static boolean
-dri2_surface_swap_buffers(struct native_surface *nsurf)
+dri2_surface_swap_buffers(struct native_surface *nsurf, int num_rects,
+  const int *rects)
 {
struct dri2_surface *dri2surf = dri2_surface(nsurf);
struct dri2_display *dri2dpy = dri2surf-dri2dpy;
 
/* copy to front buffer */
if (dri2surf-have_back)
-  x11_drawable_copy_buffers(dri2dpy-xscr, dri2surf-drawable,
-0, 0, dri2surf-width, dri2surf-height,
+  x11_drawable_copy_buffers_region(dri2dpy-xscr, dri2surf-drawable,
+num_rects, rects,
 DRI2BufferBackLeft, DRI2BufferFrontLeft);
 
/* and update fake front buffer */
if (dri2surf-have_fake)
-  x11_drawable_copy_buffers(dri2dpy-xscr, dri2surf-drawable,
-0, 0, dri2surf-width, dri2surf-height,
+  x11_drawable_copy_buffers_region(dri2dpy-xscr, dri2surf-drawable,
+num_rects, rects,
 DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
 
/* force buffers to be updated in next validation call */
@@ -354,7 +355,7 @@ dri2_surface_present(struct native_surface *nsurf,
   ret = dri2_surface_flush_frontbuffer(nsurf);
   break;
case NATIVE_ATTACHMENT_BACK_LEFT:
-  ret = dri2_surface_swap_buffers(nsurf);
+  ret = dri2_surface_swap_buffers(nsurf, ctrl-num_rects, ctrl-rects);
   break;
default:
   ret = FALSE;
@@ -722,6 +723,9 @@ dri2_display_get_param(struct native_display *ndpy,
   /* DRI2CopyRegion is used */
   val = TRUE;
   break;
+   case NATIVE_PARAM_PRESENT_REGION:
+  val = TRUE;
+  break;
case NATIVE_PARAM_MAX_SWAP_INTERVAL:
default:
   val = 0;
diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.c 
b/src/gallium/state_trackers/egl/x11/x11_screen.c
index 6155b4d..45b5464 100644
--- a/src/gallium/state_trackers/egl/x11/x11_screen.c
+++ b/src/gallium/state_trackers/egl/x11/x11_screen.c
@@ -341,6 +341,30 @@ x11_drawable_enable_dri2(struct x11_screen *xscr,
  * Copy between buffers of the DRI2 drawable.
  */
 void
+x11_drawable_copy_buffers_region(struct x11_screen *xscr, Drawable drawable,
+ int num_rects, const int *rects,
+ int src_buf, int dst_buf)
+{
+   XserverRegion region;
+   XRectangle *rectangles = CALLOC(num_rects, sizeof(XRectangle));
+
+   for (int i = 0; i  num_rects; i++) {
+  rectangles[i].x = rects[i * 4 + 0];
+  rectangles[i].y = rects[i * 4 + 1];
+  rectangles[i].width = rects[i * 4 + 2];
+  rectangles[i].height = rects[i * 4 + 3];
+   }
+
+   region = XFixesCreateRegion(xscr-dpy, rectangles, num_rects);
+   DRI2CopyRegion(xscr-dpy, drawable, region, dst_buf, src_buf);
+   XFixesDestroyRegion(xscr-dpy, region);
+   FREE(rectangles);
+}
+
+/**
+ * Copy between buffers of the DRI2 drawable.
+ */
+void
 x11_drawable_copy_buffers(struct x11_screen *xscr, Drawable drawable,
   int x, int y, int width, int height,
   int src_buf, int dst_buf)
diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.h 
b/src/gallium/state_trackers/egl/x11/x11_screen.h
index acf1300..1fa3464 100644
--- a/src/gallium/state_trackers/egl/x11/x11_screen.h
+++ b/src/gallium/state_trackers/egl/x11/x11_screen.h
@@ -112,6 +112,11 @@ x11_drawable_copy_buffers(struct x11_screen *xscr, 
Drawable drawable,
   int x, int y, int width, int height,
   int src_buf, int dst_buf);
 
+void
+x11_drawable_copy_buffers_region(struct x11_screen *xscr, Drawable drawable,
+ int num_rects, const int *rects,
+ int src_buf, int dst_buf);
+
 struct x11_drawable_buffer *
 x11_drawable_get_buffers(struct x11_screen *xscr, Drawable drawable,
  int *width, int *height, unsigned int *attachments,
-- 
1.7.7.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev