GNOME Bugzilla – Bug 608715
StWidget: Don't redraw gradient when size doesn't change
Last modified: 2010-02-01 23:19:14 UTC
If we are animating a widget with a gradient moving around the screen, the widget will constantly be reallocated, but with the same size every time. This happens when entering and leaving the overview. In this case, we should avoid recreating and redrawing the gradient. (The biggest expense I'm seeing isn't recreating the gradient but uploading it as a texture, though I'm not quite sure why that is noticeably slow, since copying *into* video ram should be pretty fast.)
Created attachment 152772 [details] [review] [StWidget] Limit gradient redraws to size changes When moving a widget with a gradient, its allocation changes continuously, resulting in constant redraws. Checking for actual size changes before the operation avoids unnecessary redraws.
Review of attachment 152772 [details] [review]: Heh, came up with almost exactly the same patch, but then my computer crashed when I went to test it, and I got drawn off into a meeting. Patch looks good, just one comment based on comparison with my patch. If that makes sense to you and works out in testing, you can go ahead and commit with the change. ::: src/st/st-widget.c @@ +336,3 @@ + + if (width > 0 && height > 0 && + (old_width != (guint)width || old_height != (guint)height)) Though this patch doesn't make it worse, and should work, in general, I think the truncating cast from float width/height to integers isn't a great idea. I'd rather see something like: - float width, height; + guint width, height; - frame_box.x2 = width; - frame_box.y2 = height; + frame_box.x2 = box->x2 - box->x1; + frame_box.y2 = box->y2 - box->y1; + + width = (guint)(0.5 + frame_box.x2); + height = (guint)(0.5 + frame_box.y2); Then you can just compare with old_width, old_height directly.
Created attachment 152783 [details] [review] [StWidget] Limit gradient redraws to size changes Updated patch according to Owen's suggestions. Owen: Yeah, casting float to integer is kinda nasty - originally I considered something along the lines of (fabs(width - old_width) > 0.1), but your suggestion seems much more reasonable to me.
Attachment 152783 [details] pushed as 3e19f41 - [StWidget] Limit gradient redraws to size changes