[cairo-commit] glitz/src glitz_buffer.c, 1.9, 1.10 glitz_drawable.c, 1.6, 1.7 glitz_framebuffer.c, 1.5, 1.6 glitz_gl.h, 1.19, 1.20 glitz_pixel.c, 1.27, 1.28 glitz_surface.c, 1.33, 1.34 glitzint.h, 1.40, 1.41

David Reveman commit at pdx.freedesktop.org
Mon Mar 13 06:23:46 PST 2006


Committed by: davidr

Update of /cvs/cairo/glitz/src
In directory kemper:/tmp/cvs-serv20671/src

Modified Files:
	glitz_buffer.c glitz_drawable.c glitz_framebuffer.c glitz_gl.h 
	glitz_pixel.c glitz_surface.c glitzint.h 
Log Message:
Add support for avoiding context switches

Index: glitz_buffer.c
===================================================================
RCS file: /cvs/cairo/glitz/src/glitz_buffer.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- glitz_buffer.c	14 Feb 2006 14:23:47 -0000	1.9
+++ glitz_buffer.c	13 Mar 2006 14:23:44 -0000	1.10
@@ -80,7 +80,7 @@
 	glitz_drawable_reference (drawable);
 
 	drawable->backend->push_current (drawable, NULL,
-					 GLITZ_ANY_CONTEXT_CURRENT);
+					 GLITZ_ANY_CONTEXT_CURRENT, NULL);
 
 	gl->gen_buffers (1, &buffer->name);
 	if (buffer->name) {
@@ -219,7 +219,8 @@
 
     if (buffer->drawable) {
 	buffer->drawable->backend->push_current (buffer->drawable, NULL,
-						 GLITZ_ANY_CONTEXT_CURRENT);
+						 GLITZ_ANY_CONTEXT_CURRENT,
+						 NULL);
 	buffer->drawable->backend->gl->delete_buffers (1, &buffer->name);
 	buffer->drawable->backend->pop_current (buffer->drawable);
 	glitz_drawable_destroy (buffer->drawable);
@@ -248,7 +249,8 @@
 	GLITZ_GL_DRAWABLE (buffer->drawable);
 
 	buffer->drawable->backend->push_current (buffer->drawable, NULL,
-						 GLITZ_ANY_CONTEXT_CURRENT);
+						 GLITZ_ANY_CONTEXT_CURRENT,
+						 NULL);
 	gl->bind_buffer (buffer->target, buffer->name);
 	gl->buffer_sub_data (buffer->target, offset, size, data);
 	gl->bind_buffer (buffer->target, 0);
@@ -268,8 +270,8 @@
 	GLITZ_GL_DRAWABLE (buffer->drawable);
 
 	buffer->drawable->backend->push_current (buffer->drawable, NULL,
-						 GLITZ_ANY_CONTEXT_CURRENT);
-
+						 GLITZ_ANY_CONTEXT_CURRENT,
+						 NULL);
 	gl->bind_buffer (buffer->target, buffer->name);
 	gl->get_buffer_sub_data (buffer->target, offset, size, data);
 	gl->bind_buffer (buffer->target, 0);
@@ -292,7 +294,8 @@
 	GLITZ_GL_DRAWABLE (buffer->drawable);
 
 	buffer->drawable->backend->push_current (buffer->drawable, NULL,
-						 GLITZ_ANY_CONTEXT_CURRENT);
+						 GLITZ_ANY_CONTEXT_CURRENT,
+						 NULL);
 
 	switch (access) {
 	case GLITZ_BUFFER_ACCESS_READ_ONLY:
@@ -328,7 +331,8 @@
 	GLITZ_GL_DRAWABLE (buffer->drawable);
 
 	buffer->drawable->backend->push_current (buffer->drawable, NULL,
-						 GLITZ_ANY_CONTEXT_CURRENT);
+						 GLITZ_ANY_CONTEXT_CURRENT,
+						 NULL);
 
 	gl->bind_buffer (buffer->target, buffer->name);
 

Index: glitz_drawable.c
===================================================================
RCS file: /cvs/cairo/glitz/src/glitz_drawable.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- glitz_drawable.c	13 Mar 2006 13:42:46 -0000	1.6
+++ glitz_drawable.c	13 Mar 2006 14:23:44 -0000	1.7
@@ -53,6 +53,8 @@
     drawable->viewport.height = 65535;
 
     drawable->update_all = 1;
+    drawable->flushed    = 0;
+    drawable->finished   = 0;
 }
 
 void
@@ -273,7 +275,7 @@
     if (!surface)
     {
 	if (drawable->backend->push_current (drawable, NULL,
-					     GLITZ_DRAWABLE_CURRENT))
+					     GLITZ_DRAWABLE_CURRENT, NULL))
 	{
 	    drawable->update_all = 1;
 
@@ -341,6 +343,7 @@
     }
 
     drawable->backend->gl->flush ();
+    drawable->flushed = 1;
 
     if (surface)
 	glitz_surface_pop_current (surface);
@@ -365,18 +368,30 @@
 void
 glitz_drawable_flush (glitz_drawable_t *drawable)
 {
-    drawable->backend->push_current (drawable, NULL, GLITZ_DRAWABLE_CURRENT);
+    if (drawable->flushed)
+	return;
+
+    drawable->backend->push_current (drawable, NULL, GLITZ_DRAWABLE_CURRENT,
+				     NULL);
     drawable->backend->gl->flush ();
     drawable->backend->pop_current (drawable);
+
+    drawable->flushed = 1;
 }
 slim_hidden_def(glitz_drawable_flush);
 
 void
 glitz_drawable_finish (glitz_drawable_t *drawable)
 {
-    drawable->backend->push_current (drawable, NULL, GLITZ_DRAWABLE_CURRENT);
+    if (drawable->finished)
+	return;
+
+    drawable->backend->push_current (drawable, NULL, GLITZ_DRAWABLE_CURRENT,
+				     NULL);
     drawable->backend->gl->finish ();
     drawable->backend->pop_current (drawable);
+
+    drawable->finished = drawable->flushed = 1;
 }
 slim_hidden_def(glitz_drawable_finish);
 

Index: glitz_framebuffer.c
===================================================================
RCS file: /cvs/cairo/glitz/src/glitz_framebuffer.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- glitz_framebuffer.c	13 Mar 2006 13:42:46 -0000	1.5
+++ glitz_framebuffer.c	13 Mar 2006 14:23:44 -0000	1.6
@@ -201,7 +201,8 @@
     if (!TEXTURE_ALLOCATED (texture))
     {
 	drawable->other->backend->push_current (drawable->other, NULL,
-						GLITZ_ANY_CONTEXT_CURRENT);
+						GLITZ_ANY_CONTEXT_CURRENT,
+						NULL);
 	glitz_texture_allocate (gl, texture);
 	drawable->other->backend->pop_current (drawable->other);
 
@@ -225,7 +226,8 @@
 	GLITZ_GL_DRAWABLE (drawable->other);
 
 	drawable->other->backend->push_current (drawable->other, NULL,
-						GLITZ_ANY_CONTEXT_CURRENT);
+						GLITZ_ANY_CONTEXT_CURRENT,
+						NULL);
 
 	gl->bind_framebuffer (GLITZ_GL_FRAMEBUFFER, drawable->fb);
 
@@ -258,13 +260,14 @@
 static glitz_bool_t
 _glitz_fbo_push_current (void               *abstract_drawable,
 			 glitz_surface_t    *surface,
-			 glitz_constraint_t constraint)
+			 glitz_constraint_t constraint,
+			 glitz_bool_t       *restore_state)
 {
     glitz_fbo_drawable_t *drawable = (glitz_fbo_drawable_t *)
 	abstract_drawable;
 
     drawable->other->backend->push_current (drawable->other, surface,
-					    constraint);
+					    constraint, restore_state);
 
     if (constraint == GLITZ_DRAWABLE_CURRENT)
     {
@@ -350,7 +353,8 @@
 	GLITZ_GL_DRAWABLE (drawable->other);
 
 	drawable->other->backend->push_current (drawable->other, NULL,
-						GLITZ_ANY_CONTEXT_CURRENT);
+						GLITZ_ANY_CONTEXT_CURRENT,
+						NULL);
 
 	gl->delete_framebuffers (1, &drawable->fb);
 

Index: glitz_gl.h
===================================================================
RCS file: /cvs/cairo/glitz/src/glitz_gl.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- glitz_gl.h	23 Feb 2006 01:21:11 -0000	1.19
+++ glitz_gl.h	13 Mar 2006 14:23:44 -0000	1.20
@@ -116,6 +116,9 @@
 #define GLITZ_GL_TEXTURE_HEIGHT       0x1001
 #define GLITZ_GL_TEXTURE_BORDER_COLOR 0x1004
 
+#define GLITZ_GL_TEXTURE_BINDING_2D        0x8069
+#define GLITZ_GL_TEXTURE_BINDING_RECTANGLE 0x84F6
+
 #define GLITZ_GL_TEXTURE_ENV            0x2300
 #define GLITZ_GL_TEXTURE_ENV_MODE       0x2200
 #define GLITZ_GL_TEXTURE_2D             0x0DE1

Index: glitz_pixel.c
===================================================================
RCS file: /cvs/cairo/glitz/src/glitz_pixel.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- glitz_pixel.c	16 Feb 2006 01:20:44 -0000	1.27
+++ glitz_pixel.c	13 Mar 2006 14:23:44 -0000	1.28
@@ -901,6 +901,11 @@
     glitz_image_t           src_image, dst_image;
     unsigned long           color_mask;
     glitz_box_t             box;
+    glitz_surface_t         *surface;
+    glitz_bool_t            restore_state;
+    glitz_gl_int_t          unpackrowlength, unpackalignment;
+    glitz_gl_int_t          unpackskiprows, unpackskippixels;
+    glitz_gl_int_t          t2d, tbind2d, trect, tbindrect;
 
     GLITZ_GL_SURFACE (dst);
 
@@ -1041,12 +1046,49 @@
 					      feature_mask);
     }
 
-    glitz_surface_push_current (dst, GLITZ_ANY_CONTEXT_CURRENT);
+    /* avoid context switch in this case */
+    if (!dst->attached &&
+	TEXTURE_ALLOCATED (&dst->texture) &&
+	!REGION_NOTEMPTY (&dst->texture_damage))
+    {
+	dst->drawable->backend->push_current (dst->drawable, dst,
+					      GLITZ_ANY_CONTEXT_CURRENT,
+					      &restore_state);
+	texture = &dst->texture;
 
-    texture = glitz_surface_get_texture (dst, 1);
-    if (!texture) {
-	glitz_surface_pop_current (dst);
-	return;
+	/* we are using a foreign context so we must restore all state when we
+	   are done */
+	if (restore_state)
+	{
+	    /* get pixel store state */
+	    gl->get_integer_v (GLITZ_GL_UNPACK_ROW_LENGTH,  &unpackrowlength);
+	    gl->get_integer_v (GLITZ_GL_UNPACK_ALIGNMENT,   &unpackalignment);
+	    gl->get_integer_v (GLITZ_GL_UNPACK_SKIP_ROWS,   &unpackskiprows);
+	    gl->get_integer_v (GLITZ_GL_UNPACK_SKIP_PIXELS, &unpackskippixels);
+
+	    /* get texture bindings */
+	    gl->get_integer_v (GLITZ_GL_TEXTURE_2D,                &t2d);
+	    gl->get_integer_v (GLITZ_GL_TEXTURE_BINDING_2D,        &tbind2d);
+	    gl->get_integer_v (GLITZ_GL_TEXTURE_RECTANGLE,         &trect);
+	    gl->get_integer_v (GLITZ_GL_TEXTURE_BINDING_RECTANGLE, &tbindrect);
+
+	    /* TODO: save PBO state */
+	}
+
+	surface = NULL;
+    }
+    else
+    {
+	glitz_surface_push_current (dst, GLITZ_ANY_CONTEXT_CURRENT);
+
+	texture = glitz_surface_get_texture (dst, 1);
+	if (!texture) {
+	    glitz_surface_pop_current (dst);
+	    return;
+	}
+
+	restore_state = 0;
+	surface = dst;
     }
 
     if (height > 1) {
@@ -1247,7 +1289,39 @@
 
 BAIL:
     glitz_texture_unbind (gl, texture);
-    glitz_surface_pop_current (dst);
+
+    if (surface)
+    {
+	glitz_surface_pop_current (surface);
+    }
+    else
+    {
+	dst->drawable->backend->pop_current (dst->drawable);
+    }
+
+    if (restore_state)
+    {
+	/* pixel store state */
+	gl->pixel_store_i (GLITZ_GL_UNPACK_ROW_LENGTH,  unpackrowlength);
+	gl->pixel_store_i (GLITZ_GL_UNPACK_ALIGNMENT,   unpackalignment);
+	gl->pixel_store_i (GLITZ_GL_UNPACK_SKIP_ROWS,   unpackskiprows);
+	gl->pixel_store_i (GLITZ_GL_UNPACK_SKIP_PIXELS, unpackskippixels);
+
+	/* get texture bindings */
+	if (t2d)
+	    gl->enable (GLITZ_GL_TEXTURE_2D);
+	else
+	    gl->disable (GLITZ_GL_TEXTURE_2D);
+
+	gl->bind_texture (GLITZ_GL_TEXTURE_2D, tbind2d);
+
+	if (trect)
+	    gl->enable (GLITZ_GL_TEXTURE_RECTANGLE);
+	else
+	    gl->disable (GLITZ_GL_TEXTURE_RECTANGLE);
+
+	gl->bind_texture (GLITZ_GL_TEXTURE_RECTANGLE, tbindrect);
+    }
 }
 
 void

Index: glitz_surface.c
===================================================================
RCS file: /cvs/cairo/glitz/src/glitz_surface.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- glitz_surface.c	21 Dec 2005 16:19:51 -0000	1.33
+++ glitz_surface.c	13 Mar 2006 14:23:44 -0000	1.34
@@ -601,7 +601,7 @@
     {
 	drawable = surface->attached;
 	if (drawable->backend->push_current (drawable, surface,
-					     constraint))
+					     constraint, NULL))
 	{
 	    if (constraint == GLITZ_DRAWABLE_CURRENT)
 	    {
@@ -641,12 +641,12 @@
 	if (constraint == GLITZ_DRAWABLE_CURRENT)
 	{
 	    drawable->backend->push_current (drawable, surface,
-					     GLITZ_ANY_CONTEXT_CURRENT);
+					     GLITZ_ANY_CONTEXT_CURRENT, NULL);
 	}
 	else
 	{
 	    return drawable->backend->push_current (drawable, surface,
-						    constraint);
+						    constraint, NULL);
 	}
     }
 

Index: glitzint.h
===================================================================
RCS file: /cvs/cairo/glitz/src/glitzint.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- glitzint.h	13 Mar 2006 13:42:46 -0000	1.40
+++ glitzint.h	13 Mar 2006 14:23:44 -0000	1.41
@@ -374,7 +374,8 @@
   glitz_bool_t
   (*push_current)              (void               *drawable,
 				glitz_surface_t    *surface,
-				glitz_constraint_t constraint);
+				glitz_constraint_t constraint,
+				glitz_bool_t       *restore_state);
 
   glitz_surface_t *
   (*pop_current)               (void *drawable);
@@ -450,6 +451,8 @@
   int                         width, height;
   glitz_rectangle_t           viewport;
   glitz_bool_t                update_all;
+  glitz_bool_t                flushed;
+  glitz_bool_t                finished;
   glitz_surface_t             *front;
   glitz_surface_t             *back;
 };



More information about the cairo-commit mailing list