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

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