[cairo] Question concerning Win32 surfaces.

Andrew S Katz (tb) akatz712 at gmail.com
Sat Jun 6 05:00:27 PDT 2009

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 ()


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], 

    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


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);

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]);

DLLIMPORT void end_cairo_screen()

More information about the cairo mailing list