[PATCH 2/3] Support a different pixel format for HDC

LRN <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Add cairo API to set up a Win32 surface for an HDC with an alpha channel.

Signed-off-by: Bas Schouten <[email protected]>
---
 src/cairo-win32.h                       |  3 ++
 src/win32/cairo-win32-display-surface.c | 64 ++++++++++++++++++++++-----------
 2 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/src/cairo-win32.h b/src/cairo-win32.h
index 3d2e1c6..2dd8934 100644
--- a/src/cairo-win32.h
+++ b/src/cairo-win32.h
@@ -49,6 +49,9 @@ cairo_public cairo_surface_t *
 cairo_win32_surface_create (HDC hdc);

 cairo_public cairo_surface_t *
+cairo_win32_surface_create_with_alpha (HDC hdc);
+
+cairo_public cairo_surface_t *
 cairo_win32_printing_surface_create (HDC hdc);

 cairo_public cairo_surface_t *
diff --git a/src/win32/cairo-win32-display-surface.c b/src/win32/cairo-win32-display-surface.c
index 965f2c4..d002ce2 100644
--- a/src/win32/cairo-win32-display-surface.c
+++ b/src/win32/cairo-win32-display-surface.c
@@ -916,33 +916,14 @@ static const cairo_surface_backend_t cairo_win32_display_surface_backend = {
  *              multiplied by all the src components.
  */

-/**
- * cairo_win32_surface_create:
- * @hdc: the DC to create a surface for
- *
- * Creates a cairo surface that targets the given DC.  The DC will be
- * queried for its initial clip extents, and this will be used as the
- * size of the cairo surface.  The resulting surface will always be of
- * format %CAIRO_FORMAT_RGB24; should you need another surface format,
- * you will need to create one through
- * cairo_win32_surface_create_with_dib().
- *
- * Return value: the newly created surface
- *
- * Since: 1.0
- **/
-cairo_surface_t *
-cairo_win32_surface_create (HDC hdc)
+static cairo_surface_t *
+cairo_win32_surface_create_internal (HDC hdc, cairo_format_t format)
 {
     cairo_win32_display_surface_t *surface;

-    cairo_format_t format;
     cairo_status_t status;
     cairo_device_t *device;

-    /* Assume that everything coming in as a HDC is RGB24 */
-    format = CAIRO_FORMAT_RGB24;
-
     surface = malloc (sizeof (*surface));
     if (surface == NULL)
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
@@ -977,6 +958,48 @@ cairo_win32_surface_create (HDC hdc)
 }

 /**
+ * cairo_win32_surface_create:
+ * @hdc: the DC to create a surface for
+ *
+ * Creates a cairo surface that targets the given DC.  The DC will be
+ * queried for its initial clip extents, and this will be used as the
+ * size of the cairo surface.  The resulting surface will always be of
+ * format %CAIRO_FORMAT_RGB24; should you need another surface format,
+ * you will need to create one through
+ * cairo_win32_surface_create_with_dib() or call
+ * cairo_win32_surface_create_with_alpha().
+ *
+ * Return value: the newly created surface
+ *
+ * Since: 1.0
+ **/
+cairo_surface_t *
+cairo_win32_surface_create (HDC hdc)
+{
+    return cairo_win32_surface_create_internal(hdc, CAIRO_FORMAT_RGB24);
+}
+
+/**
+ * cairo_win32_surface_create_with_alpha:
+ * @hdc: the DC to create a surface for
+ *
+ * Creates a cairo surface that targets the given DC.  The DC will be
+ * queried for its initial clip extents, and this will be used as the
+ * size of the cairo surface.  The resulting surface will always be of
+ * format %CAIRO_FORMAT_ARGB32 (as supported for transparent windows with
+ * Windows Vista and up).
+ *
+ * Return value: the newly created surface
+ *
+ * Since: 1.12
+ **/
+cairo_surface_t *
+cairo_win32_surface_create_with_alpha (HDC hdc)
+{
+    return cairo_win32_surface_create_internal(hdc, CAIRO_FORMAT_ARGB32);
+}
+
+/**
  * cairo_win32_surface_create_with_dib:
  * @format: format of pixels in the surface to create
  * @width: width of the surface, in pixels
-- 
1.8.5.3

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.