1 From 16898ba11b4d6e9e2e64bb2d02d0fb5adbe266e2 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?=
3 =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <lrn1986@gmail.com>
4 Date: Thu, 26 Mar 2015 19:33:43 +0000
5 Subject: win32: Add cairo API to set up a Win32 surface for an HDC with an
8 Content-Type: text/plain; charset=UTF-8
9 Content-Transfer-Encoding: 8bit
11 Signed-off-by: Руслан Ижбулатов <lrn1986@gmail.com>
12 Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
14 diff --git a/src/cairo-win32.h b/src/cairo-win32.h
15 index 3d2e1c6..db4cac6 100644
16 --- a/src/cairo-win32.h
17 +++ b/src/cairo-win32.h
18 @@ -49,6 +49,10 @@ cairo_public cairo_surface_t *
19 cairo_win32_surface_create (HDC hdc);
21 cairo_public cairo_surface_t *
22 +cairo_win32_surface_create_with_format (HDC hdc,
23 + cairo_format_t format);
25 +cairo_public cairo_surface_t *
26 cairo_win32_printing_surface_create (HDC hdc);
28 cairo_public cairo_surface_t *
29 diff --git a/src/win32/cairo-win32-display-surface.c b/src/win32/cairo-win32-display-surface.c
30 index 965f2c4..1571480 100644
31 --- a/src/win32/cairo-win32-display-surface.c
32 +++ b/src/win32/cairo-win32-display-surface.c
33 @@ -917,31 +917,41 @@ static const cairo_surface_backend_t cairo_win32_display_surface_backend = {
37 - * cairo_win32_surface_create:
38 + * cairo_win32_surface_create_with_format:
39 * @hdc: the DC to create a surface for
40 + * @format: format of pixels in the surface to create
42 * Creates a cairo surface that targets the given DC. The DC will be
43 * queried for its initial clip extents, and this will be used as the
44 - * size of the cairo surface. The resulting surface will always be of
45 - * format %CAIRO_FORMAT_RGB24; should you need another surface format,
46 - * you will need to create one through
47 - * cairo_win32_surface_create_with_dib().
48 + * size of the cairo surface.
50 - * Return value: the newly created surface
51 + * Supported formats are:
52 + * %CAIRO_FORMAT_ARGB32
53 + * %CAIRO_FORMAT_RGB24
56 + * Note: @format only tells cairo how to draw on the surface, not what
57 + * the format of the surface is. Namely, cairo does not (and cannot)
58 + * check that @hdc actually supports alpha-transparency.
60 + * Return value: the newly created surface, NULL on failure
65 -cairo_win32_surface_create (HDC hdc)
66 +cairo_win32_surface_create_with_format (HDC hdc, cairo_format_t format)
68 cairo_win32_display_surface_t *surface;
70 - cairo_format_t format;
71 cairo_status_t status;
72 cairo_device_t *device;
74 - /* Assume that everything coming in as a HDC is RGB24 */
75 - format = CAIRO_FORMAT_RGB24;
78 + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
79 + case CAIRO_FORMAT_ARGB32:
80 + case CAIRO_FORMAT_RGB24:
84 surface = malloc (sizeof (*surface));
86 @@ -977,6 +987,28 @@ cairo_win32_surface_create (HDC hdc)
90 + * cairo_win32_surface_create:
91 + * @hdc: the DC to create a surface for
93 + * Creates a cairo surface that targets the given DC. The DC will be
94 + * queried for its initial clip extents, and this will be used as the
95 + * size of the cairo surface. The resulting surface will always be of
96 + * format %CAIRO_FORMAT_RGB24; should you need another surface format,
97 + * you will need to create one through
98 + * cairo_win32_surface_create_with_format() or
99 + * cairo_win32_surface_create_with_dib().
101 + * Return value: the newly created surface, NULL on failure
106 +cairo_win32_surface_create (HDC hdc)
108 + return cairo_win32_surface_create_with_format (hdc, CAIRO_FORMAT_RGB24);
112 * cairo_win32_surface_create_with_dib:
113 * @format: format of pixels in the surface to create
114 * @width: width of the surface, in pixels
115 @@ -1027,12 +1059,16 @@ cairo_win32_surface_create_with_ddb (HDC hdc,
116 HDC screen_dc, ddb_dc;
117 HBITMAP saved_dc_bitmap;
119 - if (format != CAIRO_FORMAT_RGB24)
122 +/* XXX handle these eventually */
123 + case CAIRO_FORMAT_A8:
124 + case CAIRO_FORMAT_A1:
125 return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
126 -/* XXX handle these eventually
127 - format != CAIRO_FORMAT_A8 ||
128 - format != CAIRO_FORMAT_A1)
130 + case CAIRO_FORMAT_ARGB32:
131 + case CAIRO_FORMAT_RGB24:
136 screen_dc = GetDC (NULL);