Bug 291818 - make cairo conditionally use AlphaBlend(). r=paper, a=asa.

This commit is contained in:
tor%cs.brown.edu 2005-04-25 23:55:56 +00:00
parent 4d5cd7b2b1
commit e833055374
4 changed files with 163 additions and 9 deletions

View File

@ -23,3 +23,5 @@ PATCHES:
dash-dos.diff - prevent DOS attack with dasharray.
icformat.diff - upstream patch to select appropriate depth
alphablend.diff - check for AlphaBlend usability at runtime (win32)

110
gfx/cairo/alphablend.diff Normal file
View File

@ -0,0 +1,110 @@
Index: cairo_win32_surface.c
===================================================================
RCS file: /cvsroot/mozilla/gfx/cairo/cairo/src/cairo_win32_surface.c,v
retrieving revision 1.1
diff -u -8 -p -r1.1 cairo_win32_surface.c
--- cairo_win32_surface.c 23 Mar 2005 19:53:39 -0000 1.1
+++ cairo_win32_surface.c 25 Apr 2005 16:38:22 -0000
@@ -547,16 +547,48 @@ _cairo_win32_surface_release_dest_image
static cairo_status_t
_cairo_win32_surface_clone_similar (void *surface,
cairo_surface_t *src,
cairo_surface_t **clone_out)
{
return CAIRO_INT_STATUS_UNSUPPORTED;
}
+// AlphaBlend is not available or useable on older versions of Win32
+
+/* for compatibility with VC++ 5 */
+#if !defined(AC_SRC_OVER)
+#define AC_SRC_OVER 0x00
+#define AC_SRC_ALPHA 0x01
+#pragma pack(1)
+typedef struct {
+ BYTE BlendOp;
+ BYTE BlendFlags;
+ BYTE SourceConstantAlpha;
+ BYTE AlphaFormat;
+}BLENDFUNCTION;
+#pragma pack()
+#endif
+
+typedef BOOL (WINAPI *ALPHABLENDPROC)(
+ HDC hdcDest,
+ int nXOriginDest,
+ int nYOriginDest,
+ int nWidthDest,
+ int hHeightDest,
+ HDC hdcSrc,
+ int nXOriginSrc,
+ int nYOriginSrc,
+ int nWidthSrc,
+ int nHeightSrc,
+ BLENDFUNCTION blendFunction);
+
+static unsigned gAlphaBlendChecked = FALSE;
+static ALPHABLENDPROC gAlphaBlend;
+
static cairo_int_status_t
_cairo_win32_surface_composite (cairo_operator_t operator,
cairo_pattern_t *pattern,
cairo_pattern_t *mask_pattern,
void *abstract_dst,
int src_x,
int src_y,
int mask_x,
@@ -568,16 +600,31 @@ _cairo_win32_surface_composite (cairo_op
{
cairo_win32_surface_t *dst = abstract_dst;
cairo_win32_surface_t *src;
cairo_surface_pattern_t *src_surface_pattern;
int alpha;
int integer_transform;
int itx, ity;
+ if (!gAlphaBlendChecked) {
+ 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) {
+ gAlphaBlend = (ALPHABLENDPROC)GetProcAddress(LoadLibrary("msimg32"),
+ "AlphaBlend");
+ }
+ gAlphaBlendChecked = PR_TRUE;
+ }
+
if (pattern->type != CAIRO_PATTERN_SURFACE ||
pattern->extend != CAIRO_EXTEND_NONE)
return CAIRO_INT_STATUS_UNSUPPORTED;
if (mask_pattern) {
/* FIXME: When we fully support RENDER style 4-channel
* masks we need to check r/g/b != 1.0.
*/
@@ -622,17 +669,20 @@ _cairo_win32_surface_composite (cairo_op
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,
+ if (!gAlphaBlend)
+ return CAIRO_INT_STATUS_UNSUPPORTED;
+
+ if (!gAlphaBlend(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");

View File

@ -552,6 +552,38 @@ _cairo_win32_surface_clone_similar (void *surface,
return CAIRO_INT_STATUS_UNSUPPORTED;
}
// AlphaBlend is not available or useable on older versions of Win32
/* for compatibility with VC++ 5 */
#if !defined(AC_SRC_OVER)
#define AC_SRC_OVER 0x00
#define AC_SRC_ALPHA 0x01
#pragma pack(1)
typedef struct {
BYTE BlendOp;
BYTE BlendFlags;
BYTE SourceConstantAlpha;
BYTE AlphaFormat;
}BLENDFUNCTION;
#pragma pack()
#endif
typedef BOOL (WINAPI *ALPHABLENDPROC)(
HDC hdcDest,
int nXOriginDest,
int nYOriginDest,
int nWidthDest,
int hHeightDest,
HDC hdcSrc,
int nXOriginSrc,
int nYOriginSrc,
int nWidthSrc,
int nHeightSrc,
BLENDFUNCTION blendFunction);
static unsigned gAlphaBlendChecked = FALSE;
static ALPHABLENDPROC gAlphaBlend;
static cairo_int_status_t
_cairo_win32_surface_composite (cairo_operator_t operator,
cairo_pattern_t *pattern,
@ -573,6 +605,21 @@ _cairo_win32_surface_composite (cairo_operator_t operator,
int integer_transform;
int itx, ity;
if (!gAlphaBlendChecked) {
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) {
gAlphaBlend = (ALPHABLENDPROC)GetProcAddress(LoadLibrary("msimg32"),
"AlphaBlend");
}
gAlphaBlendChecked = PR_TRUE;
}
if (pattern->type != CAIRO_PATTERN_SURFACE ||
pattern->extend != CAIRO_EXTEND_NONE)
return CAIRO_INT_STATUS_UNSUPPORTED;
@ -627,7 +674,10 @@ _cairo_win32_surface_composite (cairo_operator_t operator,
blend_function.SourceConstantAlpha = alpha;
blend_function.AlphaFormat = src->format == CAIRO_FORMAT_ARGB32 ? AC_SRC_ALPHA : 0;
if (!AlphaBlend (dst->dc,
if (!gAlphaBlend)
return CAIRO_INT_STATUS_UNSUPPORTED;
if (!gAlphaBlend(dst->dc,
dst_x, dst_y,
width, height,
src->dc,

View File

@ -274,11 +274,3 @@ $(BUILD_DATE_TS): FORCE
$(BUILD_DATE):: gbdate.pl $(BUILD_DATE_TS)
$(RM) $@
$(PERL) $(srcdir)/gbdate.pl > $@
ifdef MOZ_ENABLE_CAIRO
ifndef MOZ_SVG_RENDERER_CAIRO
ifeq ($(MOZ_WIDGET_TOOLKIT), windows)
EXTRA_DSO_LDOPTS += msimg32.lib
endif
endif
endif