Programming Windows D Examples are now Online!
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sat Jul 9 12:09:31 PDT 2011
On 7/9/11, Johannes Pfau <spam at example.com> wrote:
> I'm not sure if cairo's win32 backend uses some kind of
> acceleration? http://cairographics.org/threaded_animation_with_cairo/
> talks about performance & animations, it's quite gtk specific, but
> maybe there's some useful information in there.
I'm already using multithreading. The performance issue I'm having is
related to constantly creating and deleting a cairo surface and the
cairo context.
Here cairo uses a backbuffer, draws to it, and then I do a blit via a
GDI function:
case WM_PAINT:
_buffer = CreateCompatibleDC(hdc);
hBitmap = CreateCompatibleBitmap(hdc, width, height);
hOldBitmap = SelectObject(_buffer, hBitmap);
surf = cairo_win32_surface_create(_buffer);
ctx = cairo_create(surf);
DrawStuff(ctx, rc);
BitBlt(hdc, 0, 0, width, height, _buffer, x, y, SRCCOPY);
SelectObject(_buffer, hOldBitmap);
DeleteObject(hBitmap);
DeleteDC(_buffer);
EndPaint(hwnd, &ps);
I'm trying to remove the calls to create/delete functions, I only
really need them in two cases: when I initialize the window, and when
the window is resized. If I do that I will still get performance
issues when resizing because I get numerous WM_SIZE messages very
rapidly as the window is resized, and just calling Create/Delete takes
about 10% CPU time.
Probably a more clever way to do this is to initially create a big
buffer that can fit the entire screen, and then just limit painting to
the visible rectangle. This way I could avoid calling create/delete.
But that wastes memory.
I'll look around the cairo newsgroups/websites to see how people
handle window resizing.
More information about the Digitalmars-d-announce
mailing list