Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: core/cross/cairo/renderer_cairo.cc

Issue 6255003: O2D:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « core/cross/cairo/renderer_cairo.h ('k') | plugin/idl/layer.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010, Google Inc. 2 * Copyright 2011, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above 11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer 12 * copyright notice, this list of conditions and the following disclaimer
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // Sort layers by z value. 88 // Sort layers by z value.
89 // TODO(tschmelcher): Only sort when changes are made. 89 // TODO(tschmelcher): Only sort when changes are made.
90 layer_list_.sort(LayerZValueLessThan); 90 layer_list_.sort(LayerZValueLessThan);
91 91
92 // Paint the background. 92 // Paint the background.
93 PaintBackground(current_drawing); 93 PaintBackground(current_drawing);
94 94
95 // Core process of painting. 95 // Core process of painting.
96 for (LayerList::iterator i = layer_list_.begin(); 96 for (LayerList::iterator i = layer_list_.begin();
97 i != layer_list_.end(); i++) { 97 i != layer_list_.end(); i++) {
98 // Put the state with no mask to the stack. 98 Layer* cur = *i;
99 if (!cur->ShouldPaint()) continue;
100
101 Pattern* pattern = cur->pattern();
102
103 // Save the current drawing state.
99 cairo_save(current_drawing); 104 cairo_save(current_drawing);
100 105
101 // Preparing and updating the Layer. 106 // Clip areas that will be obscured anyway.
102 Layer* cur = *i; 107 LayerList::iterator start_mask_it = i;
103 Pattern* pattern = cur->pattern(); 108 start_mask_it++;
104 if (!pattern) { 109 ClipArea(current_drawing, start_mask_it);
105 // Skip layers with no pattern assigned. 110
106 continue; 111 // Define the region to fill.
112 cairo_rectangle(current_drawing,
113 cur->x(),
114 cur->y(),
115 cur->width(),
116 cur->height());
117
118 // Transform the pattern to fit into the fill region.
119 cairo_translate(current_drawing, cur->x(), cur->y());
120 cairo_scale(current_drawing, cur->scale_x(), cur->scale_y());
121
122 // Set source pattern.
123 cairo_set_source(current_drawing, pattern->pattern());
124
125 // Paint the pattern to the off-screen surface.
126 switch (cur->paint_operator()) {
127 case Layer::BLEND:
128 cairo_fill(current_drawing);
129 break;
130
131 case Layer::BLEND_WITH_TRANSPARENCY:
132 {
133 cairo_pattern_t* mask = cairo_pattern_create_rgba(0.0,
134 0.0,
135 0.0,
136 cur->alpha());
137 cairo_mask(current_drawing, mask);
138 cairo_pattern_destroy(mask);
139 }
140 break;
141
142 // TODO(tschmelcher): COPY_WITH_FADING is not implemented yet. For now
143 // we treat it the same as COPY.
144 case Layer::COPY_WITH_FADING:
145 case Layer::COPY:
146 // Set Cairo to copy the pattern's alpha content instead of blending.
147 cairo_set_operator(current_drawing, CAIRO_OPERATOR_SOURCE);
148 cairo_fill(current_drawing);
149 break;
150
151 default:
152 DCHECK(false);
107 } 153 }
108 154
109 // Masking areas for other scene. 155 // Restore to a clean state.
110 LayerList::iterator start_mask_it = i;
111 start_mask_it++;
112 MaskArea(current_drawing, start_mask_it);
113
114 cairo_translate(current_drawing, cur->x(), cur->y());
115
116 cairo_scale(current_drawing, cur->scale_x(), cur->scale_y());
117
118 // Painting the image to the surface.
119 cairo_set_source(current_drawing, pattern->pattern());
120
121 cairo_paint_with_alpha(current_drawing, cur->alpha());
122
123 // Restore to the state with no mask.
124 cairo_restore(current_drawing); 156 cairo_restore(current_drawing);
125 } 157 }
126 158
127 // Finish off-screen drawing and make the off-screen surface the source for 159 // Finish off-screen drawing and make the off-screen surface the source for
128 // paints to the screen. 160 // paints to the screen.
129 cairo_pop_group_to_source(current_drawing); 161 cairo_pop_group_to_source(current_drawing);
130 162
131 // Paint the off-screen surface to the screen. 163 // Paint the off-screen surface to the screen.
132 cairo_paint(current_drawing); 164 cairo_paint(current_drawing);
133 165
134 cairo_destroy(current_drawing); 166 cairo_destroy(current_drawing);
135 } 167 }
136 168
137 void RendererCairo::PaintBackground(cairo_t* cr) { 169 void RendererCairo::PaintBackground(cairo_t* cr) {
138 cairo_save(cr); 170 cairo_save(cr);
139 MaskArea(cr, layer_list_.begin()); 171 ClipArea(cr, layer_list_.begin());
140 172
141 cairo_rectangle(cr, 0, 0, display_width(), display_height()); 173 cairo_rectangle(cr, 0, 0, display_width(), display_height());
142 cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); 174 cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
143 cairo_fill(cr); 175 cairo_fill(cr);
144 cairo_restore(cr); 176 cairo_restore(cr);
145 } 177 }
146 178
147 void RendererCairo::MaskArea(cairo_t* cr, LayerList::iterator it) { 179 void RendererCairo::ClipArea(cairo_t* cr, LayerList::iterator it) {
148 cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); 180 cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
149 181
150 for (LayerList::iterator i = it; i != layer_list_.end(); i++) { 182 for (LayerList::iterator i = it; i != layer_list_.end(); i++) {
151 // Preparing and updating the Layer. 183 // Preparing and updating the Layer.
152 Layer* cur_mask = *i; 184 Layer* cur = *i;
185 if (!cur->ShouldClip()) continue;
153 186
154 cairo_rectangle(cr, 0, 0, display_width(), display_height()); 187 cairo_rectangle(cr, 0, 0, display_width(), display_height());
155 cairo_rectangle(cr, 188 cairo_rectangle(cr,
156 cur_mask->x(), 189 cur->x(),
157 cur_mask->y(), 190 cur->y(),
158 cur_mask->width(), 191 cur->width(),
159 cur_mask->height()); 192 cur->height());
160 cairo_clip(cr); 193 cairo_clip(cr);
161 } 194 }
162 } 195 }
163 196
164 void RendererCairo::AddLayer(Layer* image) { 197 void RendererCairo::AddLayer(Layer* image) {
165 layer_list_.push_front(image); 198 layer_list_.push_front(image);
166 } 199 }
167 200
168 void RendererCairo::RemoveLayer(Layer* image) { 201 void RendererCairo::RemoveLayer(Layer* image) {
169 layer_list_.remove(image); 202 layer_list_.remove(image);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 NOTIMPLEMENTED(); 465 NOTIMPLEMENTED();
433 } 466 }
434 467
435 void RendererCairo::PopRenderStates() { 468 void RendererCairo::PopRenderStates() {
436 NOTIMPLEMENTED(); 469 NOTIMPLEMENTED();
437 } 470 }
438 471
439 } // namespace o2d 472 } // namespace o2d
440 473
441 } // namespace o3d 474 } // namespace o3d
OLDNEW
« no previous file with comments | « core/cross/cairo/renderer_cairo.h ('k') | plugin/idl/layer.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698