[cairo] drawing on and reusing an off-screen image surface
Matt Hoosier
matt.hoosier at gmail.com
Mon Dec 3 08:51:50 PST 2007
On Dec 3, 2007 1:31 AM, Peter Groves <pdgroves at gmail.com> wrote:
> ##at my application startup, draw the background and save it as
> ##a cairo_pattern
> startup() {
> background_surface = cairo_image_surface_create(...)
> background_ctx = cairo_create(background_surface)
>
> #do all the cairo drawings for the background
> my_draw_the_background_method(background_ctx)
>
> #this global variable will hopefully be a fully rendered version of
> #the rasterized background image
> _background_pattern = cairo_pattern_create_for_surface(background_surface)
> }
>
> ##now, inside my main re-paint function for a gtk drawing area
> ##named 'widg', which will be called on expose_event and some other
> ##events
> repaint(widg){
>
> #get the cairo_t for the gtk widget
> gtk_widget_ctx = gdk_cairo_create(widg)
>
> #tell cairo to use the cached rasterized image as the "paint"
> cairo_set_source(gtk_widget_ctx, _background_pattern)
>
> #(**)paint the whole gtk_widget_ctx canvas with the image.
> cairo_paint(gtk_widget_ctx)
>
> #do any additional drawings that occur each re-paint on top
> my_draw_the_foreground_method(gtk_widget_ctx)
> }
You might want to consider allocating an offscreen GdkPixmap and pass
that to the gdk_cairo_create() call. Then you can repeatedly do very
cheap area copies from the GdkPixmap onto your on-screen GdkWindow.
More information about the cairo
mailing list