[cairo-commit] cairo/src cairo-win32-surface.c,1.33,1.34

Owen Taylor commit at pdx.freedesktop.org
Tue Aug 23 14:30:54 PDT 2005


Committed by: otaylor

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv6042/src

Modified Files:
	cairo-win32-surface.c 
Log Message:
2005-08-23  Owen Taylor  <otaylor at redhat.com>

        * src/cairo-win32-font.c (_cairo_win32_scaled_font_show_glyphs):
        Check for AlphaBlend() with GetProcAddress() to support older
        compilation environments like MSVC 6. (Also fixes this portion
        of the code to run on Win98 and Win95, but much of the rest
        of cairo-win32-* won't work in that environment)
        (#3926, Hans Breuer, Christian Biesinger, based on code
        originally from Mozilla)

        * src/cairo-win32-private.h: Remove WINVER define, since it
        was (hopefully) there only for AlphaBlend().


Index: cairo-win32-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-win32-surface.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- cairo-win32-surface.c	1 Aug 2005 18:45:42 -0000	1.33
+++ cairo-win32-surface.c	23 Aug 2005 21:30:52 -0000	1.34
@@ -524,6 +524,95 @@
     cairo_surface_destroy ((cairo_surface_t *)local);
 }
 
+#if !defined(AC_SRC_OVER)
+#define AC_SRC_OVER                 0x00
+#pragma pack(1)
+typedef struct {
+    BYTE   BlendOp;
+    BYTE   BlendFlags;
+    BYTE   SourceConstantAlpha;
+    BYTE   AlphaFormat;
+}BLENDFUNCTION;
+#pragma pack()
+#endif
+
+/* for compatibility with VC++ 6 */
+#ifndef AC_SRC_ALPHA
+#define AC_SRC_ALPHA                0x01
+#endif
+
+typedef BOOL (WINAPI *cairo_alpha_blend_func_t) (HDC hdcDest,
+						 int nXOriginDest,
+						 int nYOriginDest,
+						 int nWidthDest,
+						 int hHeightDest,
+						 HDC hdcSrc,
+						 int nXOriginSrc,
+						 int nYOriginSrc,
+						 int nWidthSrc,
+						 int nHeightSrc,
+						 BLENDFUNCTION blendFunction);
+
+static cairo_int_status_t
+_composite_alpha_blend (cairo_win32_surface_t *dst,
+			cairo_win32_surface_t *src,
+			int                    alpha,
+			int                    src_x,
+			int                    src_y,
+			int                    dst_x,
+			int                    dst_y,
+			int                    width,
+			int                    height)
+{
+    static unsigned alpha_blend_checked = FALSE;
+    static cairo_alpha_blend_func_t alpha_blend = NULL;
+
+    BLENDFUNCTION blend_function;
+
+    /* Check for AlphaBlend dynamically to allow compiling on
+     * MSVC 6 and use on older windows versions
+     */
+    if (!alpha_blend_checked) {
+	OSVERSIONINFO os;
+    
+	os.dwOSVersionInfoSize = sizeof (os);
+	GetVersionEx (&os);
+	
+	/* If running on Win98, disable using AlphaBlend()
+	 * to avoid Win98 AlphaBlend() bug */
+	if (VER_PLATFORM_WIN32_WINDOWS != os.dwPlatformId ||
+	    os.dwMajorVersion != 4 || os.dwMinorVersion != 10)
+	{
+	    HMODULE msimg32_dll = LoadLibrary ("msimg32");
+	    
+	    if (msimg32_dll != NULL)
+		alpha_blend = (cairo_alpha_blend_func_t)GetProcAddress (msimg32_dll,
+									"AlphaBlend");
+	}
+	    
+	alpha_blend_checked = TRUE;
+    }
+
+    if (alpha_blend == NULL)
+	return CAIRO_INT_STATUS_UNSUPPORTED;
+    
+    blend_function.BlendOp = AC_SRC_OVER;
+    blend_function.BlendFlags = 0;
+    blend_function.SourceConstantAlpha = alpha;
+    blend_function.AlphaFormat = src->format == CAIRO_FORMAT_ARGB32 ? AC_SRC_ALPHA : 0;
+
+    if (!alpha_blend (dst->dc,
+		      dst_x, dst_y,
+		      width, height,
+		      src->dc,
+		      src_x, src_y,
+		      width, height,
+		      blend_function))
+	return _cairo_win32_print_gdi_error ("_cairo_win32_surface_composite");
+    
+    return CAIRO_STATUS_SUCCESS;
+}
+
 static cairo_int_status_t
 _cairo_win32_surface_composite (cairo_operator_t	operator,
 				cairo_pattern_t       	*pattern,
@@ -591,23 +680,9 @@
 	       dst->format == CAIRO_FORMAT_RGB24 &&
 	       operator == CAIRO_OPERATOR_OVER) {
 
-	BLENDFUNCTION blend_function;
-
-	blend_function.BlendOp = AC_SRC_OVER;
-	blend_function.BlendFlags = 0;
-	blend_function.SourceConstantAlpha = alpha;
-	blend_function.AlphaFormat = src->format == CAIRO_FORMAT_ARGB32 ? AC_SRC_ALPHA : 0;
-
-	if (!AlphaBlend (dst->dc,
-			 dst_x, dst_y,
-			 width, height,
-			 src->dc,
-			 src_x + itx, src_y + ity,
-			 width, height,
-			 blend_function))
-	    return _cairo_win32_print_gdi_error ("_cairo_win32_surface_composite");
-
-	return CAIRO_STATUS_SUCCESS;
+	return _composite_alpha_blend (dst, src, alpha,
+				       src_x + itx, src_y + ity,
+				       dst_x, dst_y, width, height);
     }
     
     return CAIRO_INT_STATUS_UNSUPPORTED;



More information about the cairo-commit mailing list