[cairo] win32 surface create/destroy
Gerdus van Zyl
gerdusvanzyl at gmail.com
Fri Apr 17 14:39:12 PDT 2009
Firstly this is off topic, you might be better served by using a
windows api group,etc.
1) The only flags I use is style = win32con.WS_THICKFRAME |
win32con.WS_MAXIMIZEBOX | win32con.WS_MINIMIZEBOX |
win32con.WS_SYSMENU (no CS_ flags); CS_HREDRAW and CS_VREDRAW also
caused problems for me so I left them out and you can use
InvalidateRect on resize message.
Also I don't think you can draw in WM_WINDOWPOSCHANGED or is at least
bad form. The window should get the correct redraw areas, but using
InvalidateRect you can control/add a redraw which is then handled by
paint.
Also CS_OWNDC is bad - see
http://blogs.msdn.com/oldnewthing/archive/2006/06/01/612970.aspx
2) Don't avoid creating and destroying a surface on paint, it's the
generally accepted way and is recommended. If you have to use an
ofscreen buffer,etc use cairo_create_similar or if you want double
buffering push_group_with_content(cairo.CONTENT_COLOR) and
cairo_pop_group
~Gerdus
On Fri, Apr 17, 2009 at 9:47 PM, Theo Veenker <T.J.G.Veenker at uu.nl> wrote:
> 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
>
>
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>
More information about the cairo
mailing list