[D3D] Small optimization in the Lock / Unlock code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Changelog:
 - no need to flush the surface back if last lock was a RO lock
 
-- 
		 Lionel Ulmer - http://www.bbrox.org/
--- dlls/ddraw_CVS/d3ddevice/mesa.c	Mon May 19 17:33:09 2003
+++ dlls/ddraw/d3ddevice/mesa.c	Mon May 19 17:32:24 2003
@@ -112,7 +112,7 @@
 
     TRACE("(%p, %ld)\n", gl_d3d_dev->display,(Drawable)drawable);
     ENTER_GL();
-    if (gl_d3d_dev->state == SURFACE_MEMORY) {
+    if (gl_d3d_dev->state == SURFACE_MEMORY_DIRTY) {
         d3d_dev->flush_to_framebuffer(d3d_dev, NULL);
     }
     gl_d3d_dev->state = SURFACE_GL;
@@ -1100,7 +1100,7 @@
     int num_active_stages = 0;
 
     ENTER_GL();
-    if (glThis->state == SURFACE_MEMORY) {
+    if (glThis->state == SURFACE_MEMORY_DIRTY) {
         This->flush_to_framebuffer(This, NULL);
     }
     LEAVE_GL();
@@ -2404,6 +2404,7 @@
 			       D3DVALUE dvZ,
 			       DWORD dwStencil)
 {
+    IDirect3DDeviceGLImpl *glThis = (IDirect3DDeviceGLImpl *) This;
     GLboolean ztest;
     GLfloat old_z_clear_value;
     GLbitfield bitfield = 0;
@@ -2435,6 +2436,13 @@
     
     /* Clears the screen */
     ENTER_GL();
+
+    if (glThis->state == SURFACE_MEMORY_DIRTY) {
+        /* TODO: optimize here the case where Clear changes all the screen... */
+        This->flush_to_framebuffer(This, NULL);
+    }
+    glThis->state = SURFACE_GL;
+
     if (dwFlags & D3DCLEAR_ZBUFFER) {
 	bitfield |= GL_DEPTH_BUFFER_BIT;
         glGetBooleanv(GL_DEPTH_WRITEMASK, &ztest);
@@ -2713,8 +2721,8 @@
     /* Try to acquire the device critical section */
     EnterCriticalSection(&(d3d_dev->crit));
     
-    if (((is_front == TRUE)  && (gl_d3d_dev->front_state != SURFACE_MEMORY)) ||
-	((is_front == FALSE) && (gl_d3d_dev->state       != SURFACE_MEMORY))) {
+    if (((is_front == TRUE)  && (gl_d3d_dev->front_state == SURFACE_GL)) ||
+	((is_front == FALSE) && (gl_d3d_dev->state       == SURFACE_GL))) {
         /* If the surface is already in memory, no need to do anything here... */
         GLenum buffer_type;
 	GLenum buffer_color;
@@ -2964,6 +2972,7 @@
 {
     BOOLEAN is_front;
     IDirect3DDeviceImpl *d3d_dev = This->d3ddevice;
+    IDirect3DDeviceGLImpl* gl_d3d_dev = (IDirect3DDeviceGLImpl*) d3d_dev;
   
     if ((This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER|DDSCAPS_PRIMARYSURFACE)) != 0) {
         is_front = TRUE;
@@ -2974,15 +2983,18 @@
 	return;
     }
     /* First, check if we need to do anything. For the backbuffer, flushing is done at the next 3D activity. */
-    if (((This->lastlocktype & DDLOCK_READONLY) == 0) &&
-	(is_front == TRUE)) {
-        GLenum prev_draw;
-	ENTER_GL();
-	glGetIntegerv(GL_DRAW_BUFFER, &prev_draw);
-	glDrawBuffer(GL_FRONT);
-        d3d_dev->flush_to_framebuffer(d3d_dev, pRect);
-	glDrawBuffer(prev_draw);
-	LEAVE_GL();
+    if ((This->lastlocktype & DDLOCK_READONLY) == 0) {
+        if (is_front == TRUE) {
+	    GLenum prev_draw;
+	    ENTER_GL();
+	    glGetIntegerv(GL_DRAW_BUFFER, &prev_draw);
+	    glDrawBuffer(GL_FRONT);
+	    d3d_dev->flush_to_framebuffer(d3d_dev, pRect);
+	    glDrawBuffer(prev_draw);
+	    LEAVE_GL();
+	} else {
+	    gl_d3d_dev->state = SURFACE_MEMORY_DIRTY;
+	}
     }
 
     /* And 'frees' the device critical section */
--- dlls/ddraw_CVS/d3dexecutebuffer.c	Mon May 19 17:33:09 2003
+++ dlls/ddraw/d3dexecutebuffer.c	Mon May 19 17:04:55 2003
@@ -207,7 +207,7 @@
 
     ENTER_GL();
     
-    if (((IDirect3DDeviceGLImpl *) lpDevice)->state == SURFACE_MEMORY) {
+    if (((IDirect3DDeviceGLImpl *) lpDevice)->state == SURFACE_MEMORY_DIRTY) {
         lpDevice->flush_to_framebuffer(lpDevice, NULL);
     }
     ((IDirect3DDeviceGLImpl *) lpDevice)->state = SURFACE_GL;
--- dlls/ddraw_CVS/mesa_private.h	Mon May 19 17:33:09 2003
+++ dlls/ddraw/mesa_private.h	Mon May 19 17:03:01 2003
@@ -100,7 +100,8 @@
 
 typedef enum {
     SURFACE_GL,
-    SURFACE_MEMORY
+    SURFACE_MEMORY,
+    SURFACE_MEMORY_DIRTY
 } SURFACE_STATE;
 
 typedef struct IDirect3DDeviceGLImpl

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux