[cairo] Question concerning Win32 surfaces.

Gerdus van Zyl gerdusvanzyl at gmail.com
Sun Jun 7 13:13:09 PDT 2009


I have never used create_with_dib/ddb so I can't comment on that
(other than the generic: it's used when you already have a dib/ddb
bitmap you want to work with).

But if you have a delay on painting you might need to call the win32
api call InvalidateRect which tell the control to queue a redraw. It
was useful  to me when starting out to remove cairo completely from my
rendering to see if I had the basics right. Another thing you might
check is it is not necesary or required to draw into a windows bitmap
but you can draw directly to the window/control, thus simpler.

~Gerdus

On Sat, Jun 6, 2009 at 2:00 PM, Andrew S Katz (tb)<akatz712 at gmail.com> wrote:
> I am looking for the fastest way to get my designs drawn to my Windows
> application. I noticed that Firefox uses Cairo for Canvas, and I can
> draw many designs and it shows up instantaneously. So, why is there a
> delay for me. I have written my user interface in a language called
> Euphoria with its Windows library, and it calls a DLL I wrote in C with
> Cairo calls. I had an idea that one of these calls would be faster, but
> they do not work, so please explain how and why they are used:
> cairo_win32_surface_create_with_dib ()
> cairo_win32_surface_create_with_ddb ()
>
> Thanks,
> Andy
>
> Here is my code:
>
> -- this is what Cairo draws to
> snapshotx = createEx(Pixmap,"",0,0,0,cx,cy,0,0)
>
> setCtlSize( DRAWIN, cx, cy ) -- assume this triggers paint
>
> hDC = getDC (snapshotx)
> DRAWINsize = getCtlSize(DRAWIN)
> c_proc (start_cairo_screen_C, {hDC, backcolor, DRAWINsize[ptx],
> DRAWINsize[pty]})
>
>    for i=1 to length(mgs) do -- loop for designs
>        c_proc (redraw_C, {mgs[i][mgcolor], mgs[i][penwidth],
> mgdivs[i][2], mgdivs[i][1]}) -- contains the points for bezier curves
>    end for
>
> c_proc (end_cairo_screen_C, {})
> releaseDC (snapshotx)
>
> -- do repaint now
> bitBlt(DRAWIN,0,0,snapshotx,0,0,DRAWINsize[ptx],DRAWINsize[pty],SrcCopy)
>
> ------------------------------------------------------------------------------------------------------------------------------------------
>
> DLLIMPORT void start_cairo_screen(HDC hDC, COLORREF backcolor, int
> iwidth, int iheight)
> {
>    surface = cairo_win32_surface_create(hDC);
>    cr = cairo_create(surface);
>    cairo_set_source_rgb(cr, (backcolor&0xFF)/255.0,
> ((backcolor>>8)&0xFF)/255.0, ((backcolor>>16)&0xFF)/255.0);
>    cairo_rectangle(cr, 0.0, 0.0, (double)iwidth, (double)iheight);
>    cairo_fill(cr);
> }
>
> DLLIMPORT void redraw_xxxx(COLORREF color, int stroke, DIV *div, int
> segments) // redraw_C
> {
>    int i,j;
>
>    if (segments == 0) return;
>
>    cairo_set_source_rgb(cr, (color&0xFF)/255.0,
> ((color>>8)&0xFF)/255.0, ((color>>16)&0xFF)/255.0);
>    cairo_set_line_width(cr, (double)stroke);
>
>    for (i=0; i<segments; i+=4)
>    {
>        for (j=0; j<4; j++)
>        {
>            bezierx[j] = div[i+j].x;
>            beziery[j] = div[i+j].y;
>        }
>        cairo_move_to( cr, bezierx[0], beziery[0] );
>        cairo_curve_to( cr, bezierx[1], beziery[1],    bezierx[2],
> beziery[2],    bezierx[3], beziery[3]);
>    }
>    cairo_stroke(cr);
> }
>
> DLLIMPORT void end_cairo_screen()
> {
>    cairo_destroy(cr);
>    cairo_surface_destroy(surface);
> }
>
>
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>


More information about the cairo mailing list