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

Side by Side Diff: cc/picture_pile_impl.cc

Issue 12316084: cc: Consolidate the analysis_canvas operations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bugfix Created 7 years, 10 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 | « cc/picture_pile_impl.h ('k') | cc/switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/debug/trace_event.h" 5 #include "base/debug/trace_event.h"
6 #include "cc/debug_colors.h" 6 #include "cc/debug_colors.h"
7 #include "cc/picture_pile_impl.h" 7 #include "cc/picture_pile_impl.h"
8 #include "cc/region.h" 8 #include "cc/region.h"
9 #include "cc/rendering_stats.h" 9 #include "cc/rendering_stats.h"
10 #include "skia/ext/analysis_canvas.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 11 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkSize.h" 12 #include "third_party/skia/include/core/SkSize.h"
12 #include "ui/gfx/rect_conversions.h" 13 #include "ui/gfx/rect_conversions.h"
13 #include "ui/gfx/skia_util.h" 14 #include "ui/gfx/skia_util.h"
14 15
15 namespace cc { 16 namespace cc {
16 17
17 scoped_refptr<PicturePileImpl> PicturePileImpl::Create() { 18 scoped_refptr<PicturePileImpl> PicturePileImpl::Create() {
18 return make_scoped_refptr(new PicturePileImpl()); 19 return make_scoped_refptr(new PicturePileImpl());
19 } 20 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 layer_rect.height(), 181 layer_rect.height(),
181 SkPicture::kUsePathBoundsForClip_RecordingFlag); 182 SkPicture::kUsePathBoundsForClip_RecordingFlag);
182 183
183 int64 total_pixels_rasterized = 0; 184 int64 total_pixels_rasterized = 0;
184 Raster(canvas, layer_rect, 1.0, &total_pixels_rasterized); 185 Raster(canvas, layer_rect, 1.0, &total_pixels_rasterized);
185 picture->endRecording(); 186 picture->endRecording();
186 187
187 return picture; 188 return picture;
188 } 189 }
189 190
190 bool PicturePileImpl::IsCheapInRect( 191 void PicturePileImpl::AnalyzeInRect(const gfx::Rect& content_rect,
191 gfx::Rect content_rect, float contents_scale) const { 192 float contents_scale) {
193 TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect");
194
195 if (analysis_.is_analyzed_ &&
196 content_rect == analysis_.analyzed_content_rect_ &&
197 contents_scale == analysis_.analyzed_contents_scale_) {
198 return;
199 }
200
192 gfx::Rect layer_rect = gfx::ToEnclosingRect( 201 gfx::Rect layer_rect = gfx::ToEnclosingRect(
193 gfx::ScaleRect(content_rect, 1.f / contents_scale)); 202 gfx::ScaleRect(content_rect, 1.f / contents_scale));
194 203
204 SkBitmap emptyBitmap;
205 emptyBitmap.setConfig(SkBitmap::kNo_Config, content_rect.width(),
206 content_rect.height());
207 skia::AnalysisDevice device(emptyBitmap);
208 skia::AnalysisCanvas canvas(&device);
209
210 canvas.translate(-content_rect.x(), -content_rect.y());
211 canvas.clipRect(gfx::RectToSkRect(content_rect));
212
213 Region unclipped(content_rect);
214 bool determined_if_solid = false;
215 bool determined_if_transparent = false;
216 bool is_transparent_guess = false;
217 bool cheap = true;
195 for (TilingData::Iterator tile_iter(&tiling_, layer_rect); 218 for (TilingData::Iterator tile_iter(&tiling_, layer_rect);
196 tile_iter; ++tile_iter) { 219 tile_iter; ++tile_iter) {
197 PictureListMap::const_iterator map_iter = 220 PictureListMap::iterator map_iter =
198 picture_list_map_.find(tile_iter.index()); 221 picture_list_map_.find(tile_iter.index());
199 if (map_iter == picture_list_map_.end()) 222 if (map_iter == picture_list_map_.end())
200 continue; 223 continue;
224 PictureList& pic_list= map_iter->second;
225 if (pic_list.empty())
226 continue;
201 227
202 const PictureList& pic_list = map_iter->second; 228 for (PictureList::reverse_iterator i = pic_list.rbegin();
203 for (PictureList::const_iterator i = pic_list.begin(); 229 i != pic_list.rend(); ++i) {
204 i != pic_list.end(); ++i) { 230 gfx::Rect content_clip = gfx::ToEnclosedRect(
205 if (!(*i)->LayerRect().Intersects(layer_rect) || !(*i)->HasRecording()) 231 gfx::ScaleRect((*i)->LayerRect(), contents_scale));
232 if (!unclipped.Intersects(content_clip))
206 continue; 233 continue;
207 if (!(*i)->IsCheapInRect(layer_rect)) 234
208 return false; 235 bool is_picture_solid;
236 SkColor solid_color;
237 bool is_picture_transparent;
238 bool is_picture_cheap;
239 (*i)->AnalyzeInRect(&canvas,
240 content_clip,
241 contents_scale,
242 &is_picture_solid,
243 &solid_color,
244 &is_picture_transparent,
245 &is_picture_cheap);
246 if (!determined_if_solid) {
247 determined_if_solid = true;
248 analysis_.is_solid_color_ = is_picture_solid;
249 analysis_.solid_color_ = solid_color;
250 }
251 else {
252 analysis_.is_solid_color_ = false;
Tom Hudson 2013/02/27 14:49:36 Does this mean that if there's more than one pictu
253 }
254
255 if (is_picture_transparent)
256 is_transparent_guess = true;
257 else {
258 analysis_.is_transparent_ = false;
259 determined_if_transparent = true;
260 }
261
262 if (cheap)
263 cheap = is_picture_cheap;
264
265 // Don't allow pictures underneath to draw where this picture did.
266 canvas.clipRect(
267 gfx::RectToSkRect(content_clip),
268 SkRegion::kDifference_Op);
269 unclipped.Subtract(content_clip);
209 } 270 }
210 } 271 }
211 return true; 272
273 if (!determined_if_solid)
274 analysis_.is_solid_color_ = false;
275 if (!determined_if_transparent)
276 analysis_.is_transparent_ = is_transparent_guess;
277 analysis_.is_cheap_ = cheap;
278 analysis_.is_analyzed_ = true;
279 analysis_.analyzed_content_rect_ = content_rect;
280 analysis_.analyzed_contents_scale_ = contents_scale;
212 } 281 }
213 282
283 bool PicturePileImpl::GetColorIfSolidInRect(const gfx::Rect& content_rect,
284 float contents_scale,
285 SkColor* color) {
286 AnalyzeInRect(content_rect, contents_scale);
287 DCHECK(analysis_.is_analyzed_);
288 *color = analysis_.solid_color_;
289 return analysis_.is_solid_color_;
290 }
291
292 bool PicturePileImpl::IsCheapInRect(const gfx::Rect& content_rect,
293 float contents_scale) {
294 AnalyzeInRect(content_rect, contents_scale);
295 DCHECK(analysis_.is_analyzed_);
296 return analysis_.is_cheap_;
297 }
298
299 bool PicturePileImpl::IsTransparentInRect(const gfx::Rect& content_rect,
300 float contents_scale) {
301 AnalyzeInRect(content_rect, contents_scale);
302 DCHECK(analysis_.is_analyzed_);
303 return analysis_.is_transparent_;
304 }
305
306 PicturePileImpl::Analysis::Analysis()
307 : is_analyzed_(false) {}
308
214 } // namespace cc 309 } // namespace cc
OLDNEW
« no previous file with comments | « cc/picture_pile_impl.h ('k') | cc/switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698