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

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

Issue 6320002: O2D: Several (unrelated) improvements:... (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 2010, 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.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 DLOG(INFO) << "To Destroy"; 65 DLOG(INFO) << "To Destroy";
66 66
67 if (main_surface_ != NULL) { 67 if (main_surface_ != NULL) {
68 cairo_surface_destroy(main_surface_); 68 cairo_surface_destroy(main_surface_);
69 main_surface_= NULL; 69 main_surface_= NULL;
70 } 70 }
71 71
72 display_ = NULL; 72 display_ = NULL;
73 } 73 }
74 74
75 // Comparison predicate for STL sort.
76 bool LayerZValueLessThan(const Layer* first, const Layer* second) {
77 return first->z() < second->z();
78 }
79
75 void RendererCairo::Paint() { 80 void RendererCairo::Paint() {
81 // TODO(tschmelcher): Don't keep creating and destroying the drawing context.
76 cairo_t* current_drawing = cairo_create(main_surface_); 82 cairo_t* current_drawing = cairo_create(main_surface_);
77 83
84 // Redirect drawing to an off-screen surface (holding only colour information,
85 // without an alpha channel).
86 cairo_push_group_with_content(current_drawing, CAIRO_CONTENT_COLOR);
87
88 // Sort layers by z value.
89 // TODO(tschmelcher): Only sort when changes are made.
90 layer_list_.sort(LayerZValueLessThan);
91
78 // Paint the background. 92 // Paint the background.
79 PaintBackground(current_drawing); 93 PaintBackground(current_drawing);
80 94
81 // Core process of painting. 95 // Core process of painting.
82 for (LayerRefList::iterator i = layer_list_.begin(); 96 for (LayerList::iterator i = layer_list_.begin();
83 i != layer_list_.end(); i++) { 97 i != layer_list_.end(); i++) {
84 // Put the state with no mask to the stack. 98 // Put the state with no mask to the stack.
85 cairo_save(current_drawing); 99 cairo_save(current_drawing);
86 100
87 // Preparing and updating the Layer. 101 // Preparing and updating the Layer.
88 Layer* cur = *i; 102 Layer* cur = *i;
89 Pattern* pattern = cur->pattern(); 103 Pattern* pattern = cur->pattern();
90 if (!pattern) { 104 if (!pattern) {
91 // Skip layers with no pattern assigned. 105 // Skip layers with no pattern assigned.
92 continue; 106 continue;
93 } 107 }
94 108
95 // Masking areas for other scene. 109 // Masking areas for other scene.
96 LayerRefList::iterator start_mask_it = i; 110 LayerList::iterator start_mask_it = i;
97 start_mask_it++; 111 start_mask_it++;
98 MaskArea(current_drawing, start_mask_it); 112 MaskArea(current_drawing, start_mask_it);
99 113
100 cairo_translate(current_drawing, cur->x(), cur->y()); 114 cairo_translate(current_drawing, cur->x(), cur->y());
101 115
102 cairo_scale(current_drawing, cur->scale_x(), cur->scale_y()); 116 cairo_scale(current_drawing, cur->scale_x(), cur->scale_y());
103 117
104 // Painting the image to the surface. 118 // Painting the image to the surface.
105 cairo_set_source(current_drawing, pattern->pattern()); 119 cairo_set_source(current_drawing, pattern->pattern());
106 120
107 cairo_paint_with_alpha(current_drawing, cur->alpha()); 121 cairo_paint_with_alpha(current_drawing, cur->alpha());
108 122
109 // Restore to the state with no mask. 123 // Restore to the state with no mask.
110 cairo_restore(current_drawing); 124 cairo_restore(current_drawing);
111 } 125 }
126
127 // Finish off-screen drawing and make the off-screen surface the source for
128 // paints to the screen.
129 cairo_pop_group_to_source(current_drawing);
130
131 // Paint the off-screen surface to the screen.
132 cairo_paint(current_drawing);
133
112 cairo_destroy(current_drawing); 134 cairo_destroy(current_drawing);
113 } 135 }
114 136
115 void RendererCairo::PaintBackground(cairo_t* cr) { 137 void RendererCairo::PaintBackground(cairo_t* cr) {
116 cairo_save(cr); 138 cairo_save(cr);
117 MaskArea(cr, layer_list_.begin()); 139 MaskArea(cr, layer_list_.begin());
118 140
119 cairo_rectangle(cr, 0, 0, display_width(), display_height()); 141 cairo_rectangle(cr, 0, 0, display_width(), display_height());
120 cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); 142 cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
121 cairo_fill(cr); 143 cairo_fill(cr);
122 cairo_restore(cr); 144 cairo_restore(cr);
123 } 145 }
124 146
125 void RendererCairo::MaskArea(cairo_t* cr, LayerRefList::iterator it) { 147 void RendererCairo::MaskArea(cairo_t* cr, LayerList::iterator it) {
126 cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); 148 cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
127 149
128 for (LayerRefList::iterator i = it; i != layer_list_.end(); i++) { 150 for (LayerList::iterator i = it; i != layer_list_.end(); i++) {
129 // Preparing and updating the Layer. 151 // Preparing and updating the Layer.
130 Layer* cur_mask = *i; 152 Layer* cur_mask = *i;
131 153
132 cairo_rectangle(cr, 0, 0, display_width(), display_height()); 154 cairo_rectangle(cr, 0, 0, display_width(), display_height());
133 cairo_rectangle(cr, 155 cairo_rectangle(cr,
134 cur_mask->x(), 156 cur_mask->x(),
135 cur_mask->y(), 157 cur_mask->y(),
136 cur_mask->width(), 158 cur_mask->width(),
137 cur_mask->height()); 159 cur_mask->height());
138 cairo_clip(cr); 160 cairo_clip(cr);
139 } 161 }
140 } 162 }
141 163
142 void RendererCairo::AddLayer(Layer* image) { 164 void RendererCairo::AddLayer(Layer* image) {
143 layer_list_.push_front(Layer::Ref(image)); 165 layer_list_.push_front(image);
166 }
167
168 void RendererCairo::RemoveLayer(Layer* image) {
169 layer_list_.remove(image);
144 } 170 }
145 171
146 void RendererCairo::InitCommon() { 172 void RendererCairo::InitCommon() {
147 main_surface_ = cairo_xlib_surface_create(display_, window_, 173 main_surface_ = cairo_xlib_surface_create(display_, window_,
148 XDefaultVisual(display_, 0), 174 XDefaultVisual(display_, 0),
149 display_width(), display_height()); 175 display_width(), display_height());
150 } 176 }
151 177
152 void RendererCairo::UninitCommon() { 178 void RendererCairo::UninitCommon() {
153 // Don't need to do anything. 179 // Don't need to do anything.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 void RendererCairo::PlatformSpecificFinishRendering() { 233 void RendererCairo::PlatformSpecificFinishRendering() {
208 Paint(); 234 Paint();
209 } 235 }
210 236
211 // The platform specific part of Present. 237 // The platform specific part of Present.
212 void RendererCairo::PlatformSpecificPresent() { 238 void RendererCairo::PlatformSpecificPresent() {
213 // Don't need to do anything. 239 // Don't need to do anything.
214 } 240 }
215 241
216 // TODO(fransiskusx): DO need to implement before shipped. 242 // TODO(fransiskusx): DO need to implement before shipped.
217 // Removes the Layer from the array.
218 void RendererCairo::RemoveLayer(Layer* image) {
219 NOTIMPLEMENTED();
220 }
221
222 // TODO(fransiskusx): DO need to implement before shipped.
223 // Get a single fullscreen display mode by id. 243 // Get a single fullscreen display mode by id.
224 // Returns true on success, false on error. 244 // Returns true on success, false on error.
225 bool RendererCairo::GetDisplayMode(int id, DisplayMode* mode) { 245 bool RendererCairo::GetDisplayMode(int id, DisplayMode* mode) {
226 NOTIMPLEMENTED(); 246 NOTIMPLEMENTED();
227 return true; 247 return true;
228 } 248 }
229 249
230 // TODO(fransiskusx): DO need to implement before shipped. 250 // TODO(fransiskusx): DO need to implement before shipped.
231 // Get a vector of the available fullscreen display modes. 251 // Get a vector of the available fullscreen display modes.
232 // Clears *modes on error. 252 // Clears *modes on error.
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 NOTIMPLEMENTED(); 432 NOTIMPLEMENTED();
413 } 433 }
414 434
415 void RendererCairo::PopRenderStates() { 435 void RendererCairo::PopRenderStates() {
416 NOTIMPLEMENTED(); 436 NOTIMPLEMENTED();
417 } 437 }
418 438
419 } // namespace o2d 439 } // namespace o2d
420 440
421 } // namespace o3d 441 } // 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