summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Vukicevic <vladimir@pobox.com>2006-02-17 23:34:51 -0800
committerBehdad Esfahbod <behdad@home.(none)>2006-03-15 11:53:30 -0500
commitec4b006c162292ea3b2719dc18a4a3bd40a971ab (patch)
tree8a193add1b3d0a1be9ca904027873b7b1313f7a5
parentd7b280a3add4ec84670e56a85b2a256225b21d0d (diff)
downloadcairo-ec4b006c162292ea3b2719dc18a4a3bd40a971ab.tar.gz
Win32: Set surface format based on device caps
If the DC is a display DC, inspect its depth and set out local format appropriately. If it's not a display DC, assume RGB24. (cherry picked from 6dd0a70d271f93df95f4bcaff5073b9bf90cecb6 commit) (cherry picked from 2d784815ffac1ca8c10dac12525f2e8d0b412c1a commit)
-rw-r--r--src/cairo-win32-surface.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
index 66fc1c48d..84105e53b 100644
--- a/src/cairo-win32-surface.c
+++ b/src/cairo-win32-surface.c
@@ -31,6 +31,8 @@
*
* Contributor(s):
* Owen Taylor <otaylor@redhat.com>
+ * Stuart Parmenter <stuart@mozilla.com>
+ * Vladimir Vukicevic <vladimir@pobox.com>
*/
#include <stdio.h>
@@ -973,6 +975,8 @@ cairo_win32_surface_create (HDC hdc)
{
cairo_win32_surface_t *surface;
RECT rect;
+ int depth;
+ cairo_format_t format;
/* Try to figure out the drawing bounds for the Device context
*/
@@ -982,7 +986,26 @@ cairo_win32_surface_create (HDC hdc)
_cairo_error (CAIRO_STATUS_NO_MEMORY);
return &_cairo_surface_nil;
}
-
+
+ if (GetDeviceCaps(hdc, TECHNOLOGY) == DT_RASDISPLAY) {
+ depth = GetDeviceCaps(hdc, BITSPIXEL);
+ if (depth == 32)
+ format = CAIRO_FORMAT_ARGB32;
+ else if (depth == 24)
+ format = CAIRO_FORMAT_RGB24;
+ else if (depth == 8)
+ format = CAIRO_FORMAT_A8;
+ else if (depth == 1)
+ format = CAIRO_FORMAT_A1;
+ else {
+ _cairo_win32_print_gdi_error("cairo_win32_surface_create(bad BITSPIXEL)");
+ _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ return &_cairo_surface_nil;
+ }
+ } else {
+ format = CAIRO_FORMAT_RGB24;
+ }
+
surface = malloc (sizeof (cairo_win32_surface_t));
if (surface == NULL) {
_cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -990,7 +1013,7 @@ cairo_win32_surface_create (HDC hdc)
}
surface->image = NULL;
- surface->format = CAIRO_FORMAT_RGB24;
+ surface->format = format;
surface->dc = hdc;
surface->bitmap = NULL;