Re: [PATCH 3/3] W32: Add a win32 boilerplate that uses a real window
LRN <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <[email protected]> |
On 08.04.2015 0:07, Bryce Harrington wrote:
> On Sat, Apr 04, 2015 at 07:21:20PM +0300, LRN wrote:
>> See the discussion in "[PATCH 2/3] Support a different pixel format for HDC"
>> for background information and the previous 2 patches.
>>
>> This patch adds a boilerplate code for win32 that uses a real window (instead
>> of a device-independent bitmap) as a backend for the surface.
>>
>> There is a summary of testsuite results in the commit message (obtained by
>> counting the number of '*.fail.png' and '*.pass.png' for a particular target.
>
> Thanks for checking that.
>
>> + format = ChoosePixelFormat (win32tc->dc, &pfd);
>
> Check if format == 0; then GetLastError()
>
>> + SetPixelFormat (win32tc->dc, format, &pfd);
>
> Returns FALSE on error
>
Removed both (further digging suggested that pixel format choosing is only
needed for OpenGL and i've copied it from the wgl boilerplate by mistake).
>> + ShowWindow (win32tc->wnd, SW_SHOWNOACTIVATE);
>
> Safe to ignore return value here.
OK, but i've changed the call to ensure that the window will not show up on the
desktop, giving it the lowest Z order and shoving it as far off the screen as
possible.
>
>> + win32tc->surface = surface;
>> +
>> + if (cairo_surface_status (surface)) {
>> + _cairo_boilerplate_win32_cleanup (win32tc);
>> + return NULL;
>> + }
>> +
>> + return surface;
>> +}
>> +
>
>> +static cairo_status_t
>> +_cairo_boilerplate_win32_finish_window (cairo_surface_t *surface)
>> +{
>
> Would probably be a good idea to document this routine, and mention that
> the surface parameter can get changed.
>
>> + win32_target_closure_t *win32tc = cairo_surface_get_user_data (surface,
>> + &win32_closure_key);
>> +
>> + if (win32tc != NULL && win32tc->surface != NULL) {
>> + cairo_t *cr;
>> +
>> + cr = cairo_create (win32tc->surface);
>> + cairo_set_source_surface (cr, surface, 0, 0);
>> + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
>> + cairo_paint (cr);
>> + cairo_destroy (cr);
>
> Error checks needed in some of the above...
There was no cairo_surface_set_user_data() call in the first place, so this
function was a big no-op. After i've added it, function started to work
normally, but completely blanked the window (not unexpected), which caused all
tests to fail.
wgl does some buffer swapping here too, i have no idea what the GDI equivalent
for that is. xcb implementation also finishes the surface here. Tried that,
also gives negative results.
Eventually i've just removed this function completely.
I'm attaching the new version of the patch. Does it really need to use tabs for
indentation? Because they look messed up in a diff.
--
O< ascii ribbon - stop html email! - www.asciiribbon.org
--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
0002-W32-Add-a-win32-boilerplate-that-uses-a-real-window.patch
(text/plain, 8.5 KB)
From dc052bfe4e3683b8996392a56a95f94622f129e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <[email protected]> Date: Sat, 4 Apr 2015 15:58:53 +0000 Subject: [PATCH 2/2] W32: Add a win32 boilerplate that uses a real window This way it uses the codepath for cairo_win32_surface_create_with_format(), instead of the cairo_win32_surface_create_with_dib(). Without the recording tests (which terminate the testsuite) the testsuite results for win32 are: 284 Passed, 167 Failed [1 crashed, 9 expected], 23 Skipped win32 (rgb24): 1 crashed! win32 (rgb24): 17 error win32 (rgb24): 155 failed win32 (argb32): 1 crashed! win32 (argb32): 17 error win32 (argb32): 68 failed win32-window-color (rgb24): 1 crashed! win32-window-color (rgb24): 17 error win32-window-color (rgb24): 148 failed win32-window-coloralpha (argb32): 1 crashed! win32-window-coloralpha (argb32): 17 error win32-window-coloralpha (argb32): 66 failed --- boilerplate/cairo-boilerplate-win32.c | 242 ++++++++++++++++++++++++++++++++-- 1 file changed, 228 insertions(+), 14 deletions(-) diff --git a/boilerplate/cairo-boilerplate-win32.c b/boilerplate/cairo-boilerplate-win32.c index 7469cc7..4fd0a10 100644 --- a/boilerplate/cairo-boilerplate-win32.c +++ b/boilerplate/cairo-boilerplate-win32.c @@ -28,15 +28,191 @@ #include <cairo-win32.h> +static const cairo_user_data_key_t win32_closure_key; + +typedef struct _win32_target_closure { + HWND wnd; + HDC dc; + ATOM bpl_atom; + cairo_surface_t *surface; +} win32_target_closure_t; + +static void +_cairo_boilerplate_win32_cleanup_window_surface (void *closure) +{ + win32_target_closure_t *win32tc = closure; + + if (win32tc != NULL) + { + if (win32tc->wnd != NULL && + ReleaseDC (win32tc->wnd, win32tc->dc) != 1) + fprintf (stderr, + "Failed to release DC of a test window when cleaning up.\n"); + if (win32tc->wnd != NULL && + DestroyWindow (win32tc->wnd) == 0) + fprintf (stderr, + "Failed to destroy a test window when cleaning up, GLE is %lu.\n", + GetLastError ()); + if (win32tc->bpl_atom != 0 && + UnregisterClassA ((LPCSTR) MAKELPARAM (win32tc->bpl_atom, 0), GetModuleHandle (NULL)) == 0 && + GetLastError () != ERROR_CLASS_DOES_NOT_EXIST) + fprintf (stderr, + "Failed to unregister boilerplate window class, GLE is %lu.\n", + GetLastError ()); + + free (win32tc); + } +} + +static win32_target_closure_t * +_cairo_boilerplate_win32_create_window (int width, + int height) +{ + WNDCLASSEXA wincl; + win32_target_closure_t *win32tc; + LPCSTR window_class_name; + + ZeroMemory (&wincl, sizeof (WNDCLASSEXA)); + wincl.cbSize = sizeof (WNDCLASSEXA); + wincl.hInstance = GetModuleHandle (0); + wincl.lpszClassName = "cairo_boilerplate_win32_dummy"; + wincl.lpfnWndProc = DefWindowProcA; + wincl.style = CS_OWNDC; + + win32tc = calloc (1, sizeof (win32_target_closure_t)); + + if (win32tc == NULL) + { + int error = errno; + fprintf (stderr, "Ran out of memory: %d.\n", error); + return NULL; + } + + ZeroMemory (win32tc, sizeof (win32_target_closure_t)); + + win32tc->bpl_atom = RegisterClassExA (&wincl); + + if (win32tc->bpl_atom == 0 && GetLastError () != ERROR_CLASS_ALREADY_EXISTS) + { + fprintf (stderr, + "Failed to register a boilerplate window class, GLE is %lu.\n", + GetLastError ()); + _cairo_boilerplate_win32_cleanup_window_surface (win32tc); + return NULL; + } + + if (win32tc->bpl_atom == 0) + window_class_name = wincl.lpszClassName; + else + window_class_name = (LPCSTR) MAKELPARAM (win32tc->bpl_atom, 0); + + win32tc->wnd = CreateWindowExA (WS_EX_TOOLWINDOW, + window_class_name, + 0, + WS_POPUP, + 0, + 0, + width, + height, + 0, + 0, + 0, + 0); + + if (win32tc->wnd == NULL) + { + fprintf (stderr, + "Failed to create a test window, GLE is %lu.\n", + GetLastError ()); + _cairo_boilerplate_win32_cleanup_window_surface (win32tc); + return NULL; + } + + win32tc->dc = GetDC (win32tc->wnd); + + if (win32tc->dc == NULL) + { + fprintf (stderr, "Failed to get test window DC.\n"); + _cairo_boilerplate_win32_cleanup_window_surface (win32tc); + return NULL; + } + + SetWindowPos (win32tc->wnd, + HWND_BOTTOM, + INT_MIN, + INT_MIN, + width, + height, + SWP_NOACTIVATE | SWP_SHOWWINDOW); + + return win32tc; +} + static cairo_surface_t * -_cairo_boilerplate_win32_create_surface (const char *name, - cairo_content_t content, - double width, - double height, - double max_width, - double max_height, - cairo_boilerplate_mode_t mode, - void **closure) +_cairo_boilerplate_win32_create_window_surface (const char *name, + cairo_content_t content, + double width, + double height, + double max_width, + double max_height, + cairo_boilerplate_mode_t mode, + void **closure) +{ + win32_target_closure_t *win32tc; + cairo_surface_t *surface; + cairo_format_t format; + cairo_status_t status; + + win32tc = _cairo_boilerplate_win32_create_window (width, height); + + if (win32tc == NULL) + return NULL; + + format = cairo_boilerplate_format_from_content (content); + + surface = cairo_win32_surface_create_with_format (win32tc->dc, format); + + win32tc->surface = surface; + + status = cairo_surface_status (surface); + + if (status != CAIRO_STATUS_SUCCESS) + { + fprintf (stderr, + "Failed to create the test surface: %s [%d].\n", + cairo_status_to_string (status), status); + _cairo_boilerplate_win32_cleanup_window_surface (win32tc); + return NULL; + } + + status = cairo_surface_set_user_data (surface, &win32_closure_key, win32tc, NULL); + + if (status != CAIRO_STATUS_SUCCESS) + { + fprintf (stderr, + "Failed to set surface userdata: %s [%d].\n", + cairo_status_to_string (status), status); + + cairo_surface_destroy (surface); + _cairo_boilerplate_win32_cleanup_window_surface (win32tc); + + return NULL; + } + + *closure = win32tc; + + return surface; +} + +static cairo_surface_t * +_cairo_boilerplate_win32_create_dib_surface (const char *name, + cairo_content_t content, + double width, + double height, + double max_width, + double max_height, + cairo_boilerplate_mode_t mode, + void **closure) { cairo_format_t format; @@ -52,12 +228,16 @@ static const cairo_boilerplate_target_t targets[] = { "win32", "win32", NULL, NULL, CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR, 0, "cairo_win32_surface_create_with_dib", - _cairo_boilerplate_win32_create_surface, + _cairo_boilerplate_win32_create_dib_surface, cairo_surface_create_similar, - NULL, NULL, + NULL, + NULL, _cairo_boilerplate_get_image_surface, cairo_surface_write_to_png, - NULL, NULL, NULL, TRUE, FALSE, FALSE + NULL, + NULL, + NULL, + TRUE, FALSE, FALSE }, /* Testing the win32 surface isn't interesting, since for * ARGB images it just chains to the image backend @@ -66,12 +246,46 @@ static const cairo_boilerplate_target_t targets[] = { "win32", "win32", NULL, NULL, CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR_ALPHA, 0, "cairo_win32_surface_create_with_dib", - _cairo_boilerplate_win32_create_surface, + _cairo_boilerplate_win32_create_dib_surface, + cairo_surface_create_similar, + NULL, + NULL, + _cairo_boilerplate_get_image_surface, + cairo_surface_write_to_png, + NULL, + NULL, + NULL, + FALSE, FALSE, FALSE + }, + { + "win32-window-color", "win32", NULL, NULL, + CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR, 1, + "cairo_win32_surface_create", + _cairo_boilerplate_win32_create_window_surface, + cairo_surface_create_similar, + NULL, + NULL, + _cairo_boilerplate_get_image_surface, + cairo_surface_write_to_png, + _cairo_boilerplate_win32_cleanup_window_surface, + NULL, + NULL, + FALSE, FALSE, FALSE + }, + { + "win32-window-coloralpha", "win32", NULL, NULL, + CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR_ALPHA, 1, + "cairo_win32_surface_create_with_format", + _cairo_boilerplate_win32_create_window_surface, cairo_surface_create_similar, - NULL, NULL, + NULL, + NULL, _cairo_boilerplate_get_image_surface, cairo_surface_write_to_png, - NULL, NULL, NULL, FALSE, FALSE, FALSE + _cairo_boilerplate_win32_cleanup_window_surface, + NULL, + NULL, + FALSE, FALSE, FALSE }, }; CAIRO_BOILERPLATE (win32, targets) -- 1.8.5.3
0x922360B0.asc
(application/pgp-keys, 1.7 KB)
-----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.4.11 (MingW32) mQENBE48DHkBCADjAv/EeFMN+i5XDN2WjSBU/yHbJlIG93/Hpj7Hee65qr82O9us n3t4W1bk2+YwGBrFdfVlesHF4DObckXveayC+IulVvTJwZhR8igVENvWjIo6oF1N 1B3GV/c8zVCnHdkF0+vYJ9akX6DZf8KvBqKZapK1kc3tll0o+kS9lwNfpWRarUpQ SBTw2uq+FUEsO3pwVAyvwom4b7AB6fz1tpyl28dOaNDKr2W55ZDPC8aM5PPe/kiH n3ylOwpgXYqZLhIyJStqL/KcZ76y8o/gDXnilFRLwXu9CbXjapo7MARXByuSVMfb PHa3XNj5JCzlv4GhEF4HOp4qoVRk8YASTqf/ABEBAAG0F0xSTiA8bHJuMTk4NkBn bWFpbC5jb20+iQE9BBMBAgAnAhsjBQkJZgGAAh4BAheABQJT5qxpBQsJCAcDBRUK CQgLBRYCAwEAAAoJEOs4Jb6SI2CwBNMIAKu3L9CGoTlJHZ/0G5AbbcP9zeiIkKkN yvi1XszHiDz1kaESQYjpDsEWeHQutEhmnK5DNRyA6VV7Tcc49+1luq5Uf1kb8gGr 2mbF+eLG0Rv/WGoi/Aa4eH7K9dH2BSOUn+eX3Ft/HbBp9ZWCBRnABuO4oKmS+zfd O9wMaQJkRRnwo151TNVMpWIO/kE7t4YeJyV/fUdYsMzlH53hzXnCM5DQ3ovje7NI 0prrSaqrthS0W5ELKZnb7PDY7pII0xh5/+u+f9Vs0mdMjvYZT42DiJnHvtfLEo1h 7KwLkC1lltZ/eaQOKFAszDzi2KoilSY/29mK7wLCd1TFJjklJNQqyxu5AQ0ETjwM eQEIAKpvqHog2hpurRnsF6IKQtqR7JXYie9mvNoPW7XWmN3TtkHp5zrUG4SkR4dU CTXxO82kMlwC94s79YJNTr30fahW6BVe72aZ+1D5qJcHk0CeHj56lri2kPOxyZXo 19Rhw43YtGZNvkNOg5xmMIzxUbMnxRTSppEFi0YQ+cCjnQksHiQPcCsb5bow53Ii M9pICELT0d3nB5iDFCQb3oiXdRitDJJtZ97vOUE+xpUeYTcHXZyLmXYyMA7cFa/b wRwj/5xofXYE0WlnHDn+0QOTf1BOGaWH1eZqYYBVKegKXW65Y7UOU4f0pZQUQ+FQ wbwnSDlFuJPKA5MDgDczqtAVtNsAEQEAAYkBJQQYAQIADwUCTjwMeQIbDAUJCWYB gAAKCRDrOCW+kiNgsJ2FCACaycPmmvwar2FwTbT+/OFM9rt9KQ6JCldNSePGNzHE k0WBu5HyzgGcuOqoQSIwPHGnu2zkZl0PMW/WW9648a4OBuK08zNmypHXQw3fG0nG KNsO6j86tOLINS6p/P4vMcF8Fz6ZdIwSj8oXnuku0C0nkLB/ja/VZk1wcI30ulJF A2EhgLWIXZaTBlWR4KitGiGL7yzpUzBarPE8YFZLF+rfqu7NlxeG3NbBA/5UmH6r FL5Cva/ajOJW2CtGyuROTYhqBfolxZtfSHHj1wOAlc+dA0utIW4NDbIyZxCoxDTF /lUIjgj/Xu0IRIsX5m6TbBl40LH81JI0g1750FJfP4de =aWCf -----END PGP PUBLIC KEY BLOCK-----
signature.asc
(application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) iQEcBAEBAgAGBQJVJTM1AAoJEOs4Jb6SI2CwUs8H/iyiiEz01VQ9Jy+d1aywaRRm RvfM6Tzqxd/EAOf4MOThMNSv+xlCUXK3wtTfk5LDsQp/reeBnktRPTI7ETjpS1t1 7lFusZkL7/E9GpK4kL93UOdEfXYesPKX65k3Ppxi5Vpth176+BQhDC6n3dAWXPgh g34z24WoRtWwJ3hYDJXLBoOHb3dKHNi+ANh6kBzO4U9GQbwoPQsGmVJyCeqW7YUO WnWWSsTzdljImoNfwK0raRNNYL3k+nt6G7Oj73cSPif43Y5zrddcL/hacsAR/xSq dvx3NaVGWaebtlSN6wZoTOGu0PEFwFXUIkqoen9u2vF687MStFz7VA8FlbL3+zE= =TRPS -----END PGP SIGNATURE-----