summaryrefslogtreecommitdiffstats
path: root/o3d/core
diff options
context:
space:
mode:
authortschmelcher@chromium.org <tschmelcher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-21 21:31:32 +0000
committertschmelcher@chromium.org <tschmelcher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-21 21:31:32 +0000
commite64ec2e60f5412c189638b9f1f36c78b4832a059 (patch)
tree3e02ea703c32dd4477858f125513dd0f26f59c01 /o3d/core
parent663d62c23fbfdab3e9c30c627ec4adf29f4c8c5d (diff)
downloadchromium_src-e64ec2e60f5412c189638b9f1f36c78b4832a059.zip
chromium_src-e64ec2e60f5412c189638b9f1f36c78b4832a059.tar.gz
chromium_src-e64ec2e60f5412c189638b9f1f36c78b4832a059.tar.bz2
O2D: Implement the COPY_WITH_FADING paint operator, and change some of the other code to be simpler.
TEST=loaded O2D and verified COPY_WITH_FADING works BUG=none Review URL: http://codereview.chromium.org/6298011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72194 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core')
-rw-r--r--o3d/core/cross/cairo/renderer_cairo.cc50
1 files changed, 28 insertions, 22 deletions
diff --git a/o3d/core/cross/cairo/renderer_cairo.cc b/o3d/core/cross/cairo/renderer_cairo.cc
index dabf61b..2846d5d 100644
--- a/o3d/core/cross/cairo/renderer_cairo.cc
+++ b/o3d/core/cross/cairo/renderer_cairo.cc
@@ -85,6 +85,9 @@ void RendererCairo::Paint() {
// without an alpha channel).
cairo_push_group_with_content(current_drawing, CAIRO_CONTENT_COLOR);
+ // Set fill (and clip) rule.
+ cairo_set_fill_rule(current_drawing, CAIRO_FILL_RULE_EVEN_ODD);
+
// Sort layers by z value.
// TODO(tschmelcher): Only sort when changes are made.
layer_list_.sort(LayerZValueLessThan);
@@ -103,19 +106,20 @@ void RendererCairo::Paint() {
// Save the current drawing state.
cairo_save(current_drawing);
- // Clip areas that will be obscured anyway.
- LayerList::iterator start_mask_it = i;
- start_mask_it++;
- ClipArea(current_drawing, start_mask_it);
-
- // Define the region to fill.
+ // Clip the region outside the current Layer.
cairo_rectangle(current_drawing,
cur->x(),
cur->y(),
cur->width(),
cur->height());
+ cairo_clip(current_drawing);
+
+ // Clip the regions within other Layers that will obscure this one.
+ LayerList::iterator start_mask_it = i;
+ start_mask_it++;
+ ClipArea(current_drawing, start_mask_it);
- // Transform the pattern to fit into the fill region.
+ // Transform the pattern to fit into the Layer's region.
cairo_translate(current_drawing, cur->x(), cur->y());
cairo_scale(current_drawing, cur->scale_x(), cur->scale_y());
@@ -125,27 +129,31 @@ void RendererCairo::Paint() {
// Paint the pattern to the off-screen surface.
switch (cur->paint_operator()) {
case Layer::BLEND:
- cairo_fill(current_drawing);
+ cairo_paint(current_drawing);
break;
case Layer::BLEND_WITH_TRANSPARENCY:
- {
- cairo_pattern_t* mask = cairo_pattern_create_rgba(0.0,
- 0.0,
- 0.0,
- cur->alpha());
- cairo_mask(current_drawing, mask);
- cairo_pattern_destroy(mask);
- }
+ cairo_paint_with_alpha(current_drawing, cur->alpha());
break;
- // TODO(tschmelcher): COPY_WITH_FADING is not implemented yet. For now
- // we treat it the same as COPY.
- case Layer::COPY_WITH_FADING:
case Layer::COPY:
// Set Cairo to copy the pattern's alpha content instead of blending.
cairo_set_operator(current_drawing, CAIRO_OPERATOR_SOURCE);
- cairo_fill(current_drawing);
+ cairo_paint(current_drawing);
+ break;
+
+ case Layer::COPY_WITH_FADING:
+ // TODO(tschmelcher): This can also be done in a single operation with:
+ //
+ // cairo_set_operator(current_drawing, CAIRO_OPERATOR_IN);
+ // cairo_paint_with_alpha(current_drawing, cur->alpha());
+ //
+ // but surprisingly that is slightly slower for me. We should figure out
+ // why.
+ cairo_set_operator(current_drawing, CAIRO_OPERATOR_CLEAR);
+ cairo_paint(current_drawing);
+ cairo_set_operator(current_drawing, CAIRO_OPERATOR_OVER);
+ cairo_paint_with_alpha(current_drawing, cur->alpha());
break;
default:
@@ -177,8 +185,6 @@ void RendererCairo::PaintBackground(cairo_t* cr) {
}
void RendererCairo::ClipArea(cairo_t* cr, LayerList::iterator it) {
- cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
-
for (LayerList::iterator i = it; i != layer_list_.end(); i++) {
// Preparing and updating the Layer.
Layer* cur = *i;