GNOME Bugzilla – Bug 668552
iagno, gnomine, mahjongg, glchess: use a similar surface for the tile cache
Last modified: 2012-02-22 20:09:32 UTC
The current drawing code is somewhat suboptimal. See patch for a fix.
Created attachment 205939 [details] [review] iagno: use a similar surface for the tile cache This stores the cached tiles in the X server (probably in video memory) which makes rendering them quite a lot faster. We were currently storing them locally and sending them to the X server for each frame. This should solve any problems with poor animation performance.
I did some tests by doing the drawing code 1000 times in a loop. This change increases performance by a factor of 2 on the initial board, working up to more like a 100 times improvement with a full board and a lot going on (like two computer players against each other).
Review of attachment 205939 [details] [review]: Oh, nice. I thought ImageSurface was going to do that for us.
Note this same fix should be done in gnomine, mahjongg, glchess too.
Created attachment 206054 [details] [review] Mahjongg: Cairo.Surface.similar Following the example of the iagno fix, this hopefully fixes mahjongg.
Created attachment 206055 [details] [review] Gnomine: Cairo.Surface.similar ...and Gnomine
Created attachment 206056 [details] [review] GlChess: Cairo.Surface.similar ...and GlChess
Review of attachment 206054 [details] [review]: ::: mahjongg/src/game-view.vala @@ -72,3 @@ var height = image_height * 2; - var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height); it's slightly odd that you changed ARGB for COLOR (instead of COLOR_ALPHA), but if it works it's probably okay (ie: the images have no transparent content)
Review of attachment 206056 [details] [review]: ::: glchess/src/chess-view-2d.vala @@ +212,3 @@ c.rotate (Math.PI); + var size = ((Cairo.ImageSurface) surface).get_height (); this cast is almost certainly unsafe...
Review of attachment 206055 [details] [review]: looks good
Created attachment 206138 [details] [review] no more unsafe cast.
Review of attachment 206054 [details] [review]: Worked for me!
Review of attachment 206055 [details] [review]: Worked for me.
Review of attachment 206138 [details] [review]: ::: glchess/src/chess-view-2d.vala @@ +214,3 @@ + var size = 0; + + if (surface == model_surface) This is a bit unsafe - if we ever added a third surface it wouldn't be clear this method should be updated. Instead change this to a method parameter and this patch is good to go.
Just to clarify, you want me to pass the 'size' in is as a parameter?
yes
done. http://git.gnome.org/browse/gnome-games/commit/?id=a0268dd86ee92895f085ef05c5fc73df9c1bd48d