Skip drawing transparent borders and backgrounds

We were always drawing the border and background of each
StThemeNode, even if they were transparent. The simple
optimization of checking the alpha provides a significant
performance boost (in a quick test, it increased the
overviewFpsSubsequent metric in the core performance test
from 28fps to 35fps).

https://bugzilla.gnome.org/show_bug.cgi?id=634752
This commit is contained in:
Owen W. Taylor 2010-11-13 08:11:03 -05:00
parent c3fb3a98b8
commit 3138b20b11

View File

@ -262,6 +262,11 @@ st_theme_node_lookup_corner (StThemeNode *node,
break;
}
if (corner.color.alpha == 0 &&
corner.border_color_1.alpha == 0 &&
corner.border_color_2.alpha == 0)
return COGL_INVALID_HANDLE;
key = corner_to_string (&corner);
data.node = node;
@ -676,6 +681,7 @@ st_theme_node_paint_borders (StThemeNode *node,
int max_width_radius[4];
int corner_id;
ClutterColor border_color;
guint8 alpha;
width = box->x2 - box->x1;
height = box->y2 - box->y1;
@ -697,11 +703,14 @@ st_theme_node_paint_borders (StThemeNode *node,
float x1, y1, x2, y2;
over (&border_color, &node->background_color, &effective_border);
alpha = paint_opacity * effective_border.alpha / 255;
if (alpha > 0)
{
cogl_set_source_color4ub (effective_border.red,
effective_border.green,
effective_border.blue,
paint_opacity * effective_border.alpha / 255);
alpha);
/* NORTH */
skip_corner_1 = node->border_radius[ST_CORNER_TOPLEFT] > 0;
@ -746,9 +755,10 @@ st_theme_node_paint_borders (StThemeNode *node,
: height - border_width;
cogl_rectangle (x1, y1, x2, y2);
}
}
/* corners */
if (max_border_radius > 0)
if (max_border_radius > 0 && paint_opacity > 0)
{
for (corner_id = 0; corner_id < 4; corner_id++)
{
@ -787,10 +797,13 @@ st_theme_node_paint_borders (StThemeNode *node,
}
/* background color */
alpha = paint_opacity * node->background_color.alpha / 255;
if (alpha > 0)
{
cogl_set_source_color4ub (node->background_color.red,
node->background_color.green,
node->background_color.blue,
paint_opacity * node->background_color.alpha / 255);
alpha);
/* We add padding to each corner, so that all corners end up as if they
* had a border-radius of max_border_radius, which allows us to treat
@ -886,6 +899,7 @@ st_theme_node_paint_borders (StThemeNode *node,
cogl_rectangle (border_width, MAX(border_width, max_border_radius),
width - border_width, height - MAX(border_width, max_border_radius));
}
}
static void