[D3D] Add fast-past for color-keyed Blt

Lionel Ulmer lionel.ulmer at free.fr
Thu Jul 10 15:12:39 CDT 2003


Changelog:
 - added fast-path for color-keyed Blts
 - fix 565 colour-keying conversion
 - properly handles Pitch in colour conversion
 - easier and less buggy UNPACK_WIDTH support

-- 
		 Lionel Ulmer - http://www.bbrox.org/
-------------- next part --------------
--- dlls/ddraw_CVS/d3ddevice/mesa.c	Sat Jul  5 14:24:44 2003
+++ dlls/ddraw/d3ddevice/mesa.c	Thu Jul 10 22:09:47 2003
@@ -2946,12 +2946,6 @@
 		int x, y;
 		double x_stretch, y_stretch;
 		
-		if (dwFlags & DDBLT_KEYSRC) {
-		    /* As I have no game using this, did not bother to do it yet as I cannot test it anyway */
-		    FIXME(" Blt overide with color-keying not supported yet.\n");
-		    return DDERR_INVALIDPARAMS;
-		}
-
 		if (rsrc) {
 		    src_rect.u1.x1 = rsrc->left;
 		    src_rect.u2.y1 = rsrc->top;
@@ -2974,10 +2968,10 @@
 
 		ENTER_GL();
 
-		opt_bitmap = d3ddevice_set_state_for_flush(This->d3ddevice, (LPCRECT) &rect, FALSE, &initial);
+		opt_bitmap = d3ddevice_set_state_for_flush(This->d3ddevice, (LPCRECT) &rect, ((dwFlags & DDBLT_KEYSRC) != 0), &initial);
 		
 		if (upload_surface_to_tex_memory_init(src_impl, 0, &gl_d3d_dev->current_internal_format,
-						      initial, FALSE, UNLOCK_TEX_SIZE, UNLOCK_TEX_SIZE) != DD_OK) {
+						      initial, ((dwFlags & DDBLT_KEYSRC) != 0), UNLOCK_TEX_SIZE, UNLOCK_TEX_SIZE) != DD_OK) {
 		    ERR(" unsupported pixel format at memory to buffer Blt overide.\n");
 		    LEAVE_GL();
 		    return DDERR_INVALIDPARAMS;
@@ -3029,7 +3023,7 @@
 		}
 		
 		upload_surface_to_tex_memory_release();
-		d3ddevice_restore_state_after_flush(This->d3ddevice, opt_bitmap, FALSE);
+		d3ddevice_restore_state_after_flush(This->d3ddevice, opt_bitmap, ((dwFlags & DDBLT_KEYSRC) != 0));
 		
 		if (((buffer_type == WINE_GL_BUFFER_FRONT) && (prev_draw == GL_BACK)) ||
 		    ((buffer_type == WINE_GL_BUFFER_BACK)  && (prev_draw == GL_FRONT)))
--- dlls/ddraw_CVS/mesa.c	Sat Jul  5 14:24:44 2003
+++ dlls/ddraw/mesa.c	Thu Jul 10 21:56:51 2003
@@ -622,7 +622,7 @@
 static GLuint current_level;
 static DWORD current_tex_width;
 static DWORD current_tex_height;
-static BOOLEAN need_alignement_restore;
+static GLuint current_alignement_constraints;
 static int current_storage_width;
 
 HRESULT upload_surface_to_tex_memory_init(IDirectDrawSurfaceImpl *surf_ptr, GLuint level, GLenum *current_internal_format,
@@ -635,14 +635,18 @@
     BYTE bpp = GET_BPP(surf_ptr->surface_desc);
     BOOL sub_texture = TRUE;
 
-    need_alignement_restore = FALSE;
-    
     current_surface = surf_ptr;
     current_level = level;
 
     /* First, do some sanity checks ... */
     if ((surf_ptr->surface_desc.u1.lPitch % bpp) != 0) {
 	FIXME("Warning : pitch is not a multiple of BPP - not supported yet !\n");
+    } else {
+	/* In that case, no need to have any alignement constraints... */
+	if (current_alignement_constraints != 1) {
+	    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+	    current_alignement_constraints = 1;
+	}
     }
 
     /* Note: we only check width here as you cannot have width non-zero while height is set to zero */
@@ -911,7 +915,7 @@
     height = rect->bottom - rect->top;
 
     /* Used when converting stuff */
-    line_increase = src_d->dwWidth - width;
+    line_increase = src_d->u1.lPitch - (width * bpp);
     
     switch (convert_type) {
         case CONVERT_PALETTED: {
@@ -982,13 +986,13 @@
 	    for (y = 0; y < height; y++) {
 		for (x = 0; x < width; x++) {
 		    WORD color = *src++;
-		    *dst = ((color & 0xFFC0) | ((color & 0x1F) << 1));
+		    *dst = ((color & 0xFFD0) | ((color & 0x1F) << 1));
 		    if ((color < src_d->ddckCKSrcBlt.dwColorSpaceLowValue) ||
 			(color > src_d->ddckCKSrcBlt.dwColorSpaceHighValue))
 			*dst |= 0x0001;
 		    dst++;
 		}
-		src += line_increase;
+		src = (WORD *) (((BYTE *) src) + line_increase);
 	    }
 	} break;
 	
@@ -1011,7 +1015,7 @@
 			*dst |= color & 0x0001;
 		    dst++;
 		}
-		src += line_increase;
+		src = (WORD *) (((BYTE *) src) + line_increase);
 	    }
 	} break;
 	
@@ -1034,7 +1038,7 @@
 			*dst |= color & 0x000F;
 		    dst++;
 		}
-		src += line_increase;
+		src = (WORD *) (((BYTE *) src) + line_increase);
 	    }
 	} break;
 	
@@ -1057,7 +1061,7 @@
 			*dst |= (color & 0xF000) >> 12;
 		    dst++;
 		}
-		src += line_increase;
+		src = (WORD *) (((BYTE *) src) + line_increase);
 	    }
 	} break;
 	
@@ -1079,7 +1083,7 @@
 			*dst |= (color & 0x8000) >> 15;
 		    dst++;
 		}
-		src += line_increase;
+		src = (WORD *) (((BYTE *) src) + line_increase);
 	    }
 	} break;
 	
@@ -1103,7 +1107,7 @@
 			    *dst |= 0x0001;
 			dst++;
 		    }
-		    src += line_increase;
+		    src = (WORD *) (((BYTE *) src) + line_increase);
 		}
 	    } else {
 		for (y = 0; y < height; y++) {
@@ -1111,7 +1115,7 @@
 			WORD color = *src++;
 			*dst++ = ((color & 0x7FFF) << 1) | 0x0001;
 		    }
-		    src += line_increase;
+		    src = (WORD *) (((BYTE *) src) + line_increase);
 		}
 	    }
 	    
@@ -1138,7 +1142,7 @@
 			*dst |= 0xFF;
 		    dst++;
 		}
-		src += 3 * line_increase;
+		src += line_increase;
 	    }
 	} break;
 
@@ -1161,7 +1165,7 @@
 			*dst |= color & 0x000000FF;
 		    dst++;
 		}
-		src += line_increase;
+		src = (DWORD *) (((BYTE *) src) + line_increase);
 	    }
 	} break;
 	
@@ -1183,7 +1187,7 @@
 			*dst |= (color & 0xFF000000) >> 24;
 		    dst++;
 		}
-		src += line_increase;
+		src = (DWORD *) (((BYTE *) src) + line_increase);
 	    }
 	} break;
 	
@@ -1207,14 +1211,14 @@
 			    *dst |= 0xFF;
 			dst++;
 		    }
-		    src += line_increase;
+		    src = (DWORD *) (((BYTE *) src) + line_increase);
 		}
 	    } else {
 		for (y = 0; y < height; y++) {
 		    for (x = 0; x < width; x++) {
 			*dst++ = (*src++ << 8) | 0xFF;
 		    }
-		    src += line_increase;
+		    src = (DWORD *) (((BYTE *) src) + line_increase);
 		}
 	    }
 	} break;
@@ -1226,31 +1230,13 @@
     }
 
     if (convert_type != NO_CONVERSION) {
-	int storage_width;
-	
+	/* When doing conversion, the storage is always of width 'width' as there will never
+	   be any Pitch issue... For now :-)
+	*/
 	surf_buffer = *temp_buffer;
-	if (width != current_tex_width) {
-	    /* Overide the default PixelStore parameter if only using part of the actual texture */
-	    storage_width = width;
-	    /* This is needed when locking with a rectangle with 'odd' width */
-	    if (need_alignement_restore == FALSE) {
-		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-		need_alignement_restore = TRUE;
-	    }
-	} else {
-	    if (current_surface->surface_desc.u1.lPitch == (current_surface->surface_desc.dwWidth * bpp)) {
-		storage_width = 0;
-	    } else {
-		storage_width = current_surface->surface_desc.u1.lPitch / bpp;
-	    }
-	    if (need_alignement_restore == TRUE) {
-		glPixelStorei(GL_UNPACK_ALIGNMENT, 0);
-		need_alignement_restore = FALSE;
-	    }
-	}
-	if (storage_width != current_storage_width) {
-	    glPixelStorei(GL_UNPACK_ROW_LENGTH, storage_width);
-	    current_storage_width = storage_width;
+	if (width != current_storage_width) {
+	    glPixelStorei(GL_UNPACK_ROW_LENGTH, width);
+	    current_storage_width = width;
 	}
     }
     
@@ -1269,9 +1255,5 @@
 {
     current_surface = NULL;
 
-    if (need_alignement_restore == TRUE) {
-	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
-    }
-    
     return DD_OK;
 }


More information about the wine-patches mailing list