From: <hez...@us...> - 2009-08-25 17:05:28
|
Revision: 10329 http://plplot.svn.sourceforge.net/plplot/?rev=10329&view=rev Author: hezekiahcarty Date: 2009-08-25 17:05:16 +0000 (Tue, 25 Aug 2009) Log Message: ----------- Off-screen rendering for xcairo. This provides a large speed increase. A possibly negative side effect of this patch is that the plot is not displayed in the plot window until either plflush is called or we reach the end of the page. A positive side effect of this patch is that xcairo no longer flickers repeatedly due to replots on expose events (when the window has to be redrawn). Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2009-08-25 14:36:42 UTC (rev 10328) +++ trunk/drivers/cairo.c 2009-08-25 17:05:16 UTC (rev 10329) @@ -96,6 +96,8 @@ short upDown; float fontSize; #if defined(PLD_xcairo) + cairo_surface_t *cairoSurface_X; + cairo_t *cairoContext_X; short exit_event_loop; Display *XDisplay; Window XWindow; @@ -1405,7 +1407,11 @@ /* Create an cairo surface & context that are associated with the X window. */ defaultVisual = DefaultVisual(aStream->XDisplay, 0); /* Dimension units are pixels from cairo documentation. */ - aStream->cairoSurface = cairo_xlib_surface_create(aStream->XDisplay, aStream->XWindow, defaultVisual, pls->xlength, pls->ylength); + /* This is the X window Cairo surface. */ + aStream->cairoSurface_X = cairo_xlib_surface_create(aStream->XDisplay, aStream->XWindow, defaultVisual, pls->xlength, pls->ylength); + aStream->cairoContext_X = cairo_create(aStream->cairoSurface_X); + /* This is the Cairo surface PLplot will actually plot to. */ + aStream->cairoSurface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, pls->xlength, pls->ylength); aStream->cairoContext = cairo_create(aStream->cairoSurface); /* Invert the surface so that the graphs are drawn right side up. */ @@ -1466,6 +1472,18 @@ } +/*--------------------------------------------------------------------- + blit_to_x() + + Blit the offscreen image to the X window. + ---------------------------------------------------------------------*/ + +void blit_to_x(PLCairo *aStream) +{ + cairo_set_source_surface(aStream->cairoContext_X, aStream->cairoSurface, 0.0, 0.0); + cairo_paint(aStream->cairoContext_X); +} + /*---------------------------------------------------------------------- plD_bop_xcairo() @@ -1510,6 +1528,9 @@ if (aStream->xdrawable_mode) return; + /* Blit the offscreen image to the X window. */ + blit_to_x(aStream); + XFlush(aStream->XDisplay); /* Only pause if nopause is unset. */ @@ -1536,8 +1557,8 @@ aStream->exit_event_loop = 1; break; case Expose: - plD_bop_cairo(pls); - plRemakePlot(pls); + /* Blit the image again after an expose event. */ + blit_to_x(aStream); XFlush(aStream->XDisplay); break; } @@ -1560,6 +1581,10 @@ plD_tidy_cairo(pls); + /* Also free up the Cairo X surface and context */ + cairo_destroy(aStream->cairoContext_X); + cairo_surface_destroy(aStream->cairoSurface_X); + if (aStream->xdrawable_mode) return; @@ -1586,6 +1611,7 @@ switch(op) { case PLESC_FLUSH: /* forced update of the window */ + blit_to_x(aStream); XFlush(aStream->XDisplay); break; case PLESC_GETC: /* get cursor position */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |