Blame SOURCES/0001-win32-Add-cairo-API-to-set-up-a-Win32-surface-for-an.patch

79d03b
From 16898ba11b4d6e9e2e64bb2d02d0fb5adbe266e2 Mon Sep 17 00:00:00 2001
79d03b
From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?=
79d03b
 =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <lrn1986@gmail.com>
79d03b
Date: Thu, 26 Mar 2015 19:33:43 +0000
79d03b
Subject: [PATCH 1/2] win32: Add cairo API to set up a Win32 surface for an HDC
79d03b
 with an alpha channel.
79d03b
MIME-Version: 1.0
79d03b
Content-Type: text/plain; charset=UTF-8
79d03b
Content-Transfer-Encoding: 8bit
79d03b
79d03b
Signed-off-by: Руслан Ижбулатов <lrn1986@gmail.com>
79d03b
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
79d03b
---
79d03b
 src/cairo-win32.h                       |  4 ++
79d03b
 src/win32/cairo-win32-display-surface.c | 68 +++++++++++++++++++++++++--------
79d03b
 2 files changed, 56 insertions(+), 16 deletions(-)
79d03b
79d03b
diff --git a/src/cairo-win32.h b/src/cairo-win32.h
79d03b
index 3d2e1c6..db4cac6 100644
79d03b
--- a/src/cairo-win32.h
79d03b
+++ b/src/cairo-win32.h
79d03b
@@ -49,6 +49,10 @@ cairo_public cairo_surface_t *
79d03b
 cairo_win32_surface_create (HDC hdc);
79d03b
 
79d03b
 cairo_public cairo_surface_t *
79d03b
+cairo_win32_surface_create_with_format (HDC hdc,
79d03b
+                                        cairo_format_t format);
79d03b
+
79d03b
+cairo_public cairo_surface_t *
79d03b
 cairo_win32_printing_surface_create (HDC hdc);
79d03b
 
79d03b
 cairo_public cairo_surface_t *
79d03b
diff --git a/src/win32/cairo-win32-display-surface.c b/src/win32/cairo-win32-display-surface.c
79d03b
index 965f2c4..1571480 100644
79d03b
--- a/src/win32/cairo-win32-display-surface.c
79d03b
+++ b/src/win32/cairo-win32-display-surface.c
79d03b
@@ -917,31 +917,41 @@ static const cairo_surface_backend_t cairo_win32_display_surface_backend = {
79d03b
  */
79d03b
 
79d03b
 /**
79d03b
- * cairo_win32_surface_create:
79d03b
+ * cairo_win32_surface_create_with_format:
79d03b
  * @hdc: the DC to create a surface for
79d03b
+ * @format: format of pixels in the surface to create
79d03b
  *
79d03b
  * Creates a cairo surface that targets the given DC.  The DC will be
79d03b
  * queried for its initial clip extents, and this will be used as the
79d03b
- * size of the cairo surface.  The resulting surface will always be of
79d03b
- * format %CAIRO_FORMAT_RGB24; should you need another surface format,
79d03b
- * you will need to create one through
79d03b
- * cairo_win32_surface_create_with_dib().
79d03b
+ * size of the cairo surface.
79d03b
  *
79d03b
- * Return value: the newly created surface
79d03b
+ * Supported formats are:
79d03b
+ * %CAIRO_FORMAT_ARGB32
79d03b
+ * %CAIRO_FORMAT_RGB24
79d03b
  *
79d03b
- * Since: 1.0
79d03b
+ * Note: @format only tells cairo how to draw on the surface, not what
79d03b
+ * the format of the surface is. Namely, cairo does not (and cannot)
79d03b
+ * check that @hdc actually supports alpha-transparency.
79d03b
+ *
79d03b
+ * Return value: the newly created surface, NULL on failure
79d03b
+ *
79d03b
+ * Since: 1.14.3
79d03b
  **/
79d03b
 cairo_surface_t *
79d03b
-cairo_win32_surface_create (HDC hdc)
79d03b
+cairo_win32_surface_create_with_format (HDC hdc, cairo_format_t format)
79d03b
 {
79d03b
     cairo_win32_display_surface_t *surface;
79d03b
 
79d03b
-    cairo_format_t format;
79d03b
     cairo_status_t status;
79d03b
     cairo_device_t *device;
79d03b
 
79d03b
-    /* Assume that everything coming in as a HDC is RGB24 */
79d03b
-    format = CAIRO_FORMAT_RGB24;
79d03b
+    switch (format) {
79d03b
+    default:
79d03b
+	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
79d03b
+    case CAIRO_FORMAT_ARGB32:
79d03b
+    case CAIRO_FORMAT_RGB24:
79d03b
+	break;
79d03b
+    }
79d03b
 
79d03b
     surface = malloc (sizeof (*surface));
79d03b
     if (surface == NULL)
79d03b
@@ -977,6 +987,28 @@ cairo_win32_surface_create (HDC hdc)
79d03b
 }
79d03b
 
79d03b
 /**
79d03b
+ * cairo_win32_surface_create:
79d03b
+ * @hdc: the DC to create a surface for
79d03b
+ *
79d03b
+ * Creates a cairo surface that targets the given DC.  The DC will be
79d03b
+ * queried for its initial clip extents, and this will be used as the
79d03b
+ * size of the cairo surface.  The resulting surface will always be of
79d03b
+ * format %CAIRO_FORMAT_RGB24; should you need another surface format,
79d03b
+ * you will need to create one through
79d03b
+ * cairo_win32_surface_create_with_format() or
79d03b
+ * cairo_win32_surface_create_with_dib().
79d03b
+ *
79d03b
+ * Return value: the newly created surface, NULL on failure
79d03b
+ *
79d03b
+ * Since: 1.0
79d03b
+ **/
79d03b
+cairo_surface_t *
79d03b
+cairo_win32_surface_create (HDC hdc)
79d03b
+{
79d03b
+    return cairo_win32_surface_create_with_format (hdc, CAIRO_FORMAT_RGB24);
79d03b
+}
79d03b
+
79d03b
+/**
79d03b
  * cairo_win32_surface_create_with_dib:
79d03b
  * @format: format of pixels in the surface to create
79d03b
  * @width: width of the surface, in pixels
79d03b
@@ -1027,12 +1059,16 @@ cairo_win32_surface_create_with_ddb (HDC hdc,
79d03b
     HDC screen_dc, ddb_dc;
79d03b
     HBITMAP saved_dc_bitmap;
79d03b
 
79d03b
-    if (format != CAIRO_FORMAT_RGB24)
79d03b
+    switch (format) {
79d03b
+    default:
79d03b
+/* XXX handle these eventually */
79d03b
+    case CAIRO_FORMAT_A8:
79d03b
+    case CAIRO_FORMAT_A1:
79d03b
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
79d03b
-/* XXX handle these eventually
79d03b
-	format != CAIRO_FORMAT_A8 ||
79d03b
-	format != CAIRO_FORMAT_A1)
79d03b
-*/
79d03b
+    case CAIRO_FORMAT_ARGB32:
79d03b
+    case CAIRO_FORMAT_RGB24:
79d03b
+	break;
79d03b
+    }
79d03b
 
79d03b
     if (!hdc) {
79d03b
 	screen_dc = GetDC (NULL);
79d03b
-- 
79d03b
2.4.3
79d03b