[cairo] win32 surface create/destroy

Theo Veenker T.J.G.Veenker at uu.nl
Fri Apr 17 12:47:11 PDT 2009


Hi all,

I'm porting a Linux XLib application to Windows. Now I have run into
two problems.

1)

I've created a test program (attached) to demonstrate. The program creates
a window and draws a cirle in it using a cairo win32 surface. The window
gets drawn on WM_PAINT and on WM_WINDOWPOSCHANGED using this code (see
attachment for full code):

     case WM_PAINT:
	dc = BeginPaint(win, &ps);
	GetClientRect(win, &rect);

	surface = cairo_win32_surface_create(dc);
	draw(surface, rect.right, rect.bottom);
	cairo_surface_destroy(surface);

	EndPaint(win, &ps);
	break;

     case WM_WINDOWPOSCHANGED:
	dc = GetDC(win);
	GetClientRect(win, &rect);

	surface = cairo_win32_surface_create(dc);
	draw(surface, rect.right, rect.bottom);
	cairo_surface_destroy(surface);

	ReleaseDC(win, dc);
	break;

So this gets the DC from the window, creates a surface, draws on it,
destroys the surface and releases the DC. This sequence doesn't work
properly if the style of the window class has the CS_OWNDC flag set.
Resizing the window sometimes leaves unpainted areas, as if the wrong
parts where clipped. It gets a lot worse if the CS_HREDRAW and CS_VREDRAW
flags are also added to the window class. What's wrong here?


2)

I also wonder if this is the proper way to draw under win32. In my
unix code I simply keep the xlib surface during the lifetime of the
window. I tried to use the same approach with the win32 backend
(only recreate the surface on resize) but that doesn't work at all.
It seems the the surface create/destroy calls have to be guarded by
GetDC()/ReleaseDC(), or maybe the window must stay the same size during
the lifetime of the window? Don't know. Anyway, how can I avoid creating
and destroying a win32 surface on each redraw?


Thanks.
Theo

-------------- next part --------------
A non-text attachment was scrubbed...
Name: win32-test.cpp
Type: text/x-c++src
Size: 3426 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20090417/6ea5ff9f/attachment.cpp 


More information about the cairo mailing list