Chromium Code Reviews| Index: cc/picture_pile_impl.cc |
| diff --git a/cc/picture_pile_impl.cc b/cc/picture_pile_impl.cc |
| index 4bb01a397dad325a0cfb138827b7fd0e70aea991..9d6469ea93eca48819b38d7857bb217d0f5ded4c 100644 |
| --- a/cc/picture_pile_impl.cc |
| +++ b/cc/picture_pile_impl.cc |
| @@ -7,6 +7,7 @@ |
| #include "cc/picture_pile_impl.h" |
| #include "cc/region.h" |
| #include "cc/rendering_stats.h" |
| +#include "skia/ext/analysis_canvas.h" |
| #include "third_party/skia/include/core/SkCanvas.h" |
| #include "third_party/skia/include/core/SkSize.h" |
| #include "ui/gfx/rect_conversions.h" |
| @@ -188,28 +189,71 @@ skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() { |
| return picture; |
| } |
| -bool PicturePileImpl::IsCheapInRect( |
| - gfx::Rect content_rect, float contents_scale) const { |
| +void PicturePileImpl::AnalyzeInRect(const gfx::Rect& content_rect, |
| + float contents_scale, |
| + PicturePileImpl::Analysis* analysis) { |
| + DCHECK(analysis); |
| + |
| + TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect"); |
| + |
| gfx::Rect layer_rect = gfx::ToEnclosingRect( |
| gfx::ScaleRect(content_rect, 1.f / contents_scale)); |
| + SkBitmap emptyBitmap; |
| + emptyBitmap.setConfig(SkBitmap::kNo_Config, content_rect.width(), |
| + content_rect.height()); |
| + skia::AnalysisDevice device(emptyBitmap); |
| + skia::AnalysisCanvas canvas(&device); |
| + |
| + canvas.translate(-content_rect.x(), -content_rect.y()); |
| + canvas.clipRect(gfx::RectToSkRect(content_rect)); |
|
Justin Novosad
2013/03/05 22:14:02
I think this call to clip rect is redundant. It is
|
| + |
| + bool determined_if_transparent = false; |
| + bool is_transparent_guess = false; |
| + bool cheap = true; |
|
Sami
2013/03/05 20:18:31
Nit: is_cheap for consistency.
|
| + |
| + // The loop here is similar to the raster loop. |
| + Region unclipped(content_rect); |
| for (TilingData::Iterator tile_iter(&tiling_, layer_rect); |
| tile_iter; ++tile_iter) { |
| - PictureListMap::const_iterator map_iter = |
| + PictureListMap::iterator map_iter = |
| picture_list_map_.find(tile_iter.index()); |
| if (map_iter == picture_list_map_.end()) |
| continue; |
| + PictureList& pic_list= map_iter->second; |
|
Sami
2013/03/05 20:18:31
Nit: space missing before =.
|
| + if (pic_list.empty()) |
| + continue; |
| - const PictureList& pic_list = map_iter->second; |
| - for (PictureList::const_iterator i = pic_list.begin(); |
| - i != pic_list.end(); ++i) { |
| - if (!(*i)->LayerRect().Intersects(layer_rect) || !(*i)->HasRecording()) |
| + for (PictureList::reverse_iterator i = pic_list.rbegin(); |
| + i != pic_list.rend(); ++i) { |
| + gfx::Rect content_clip = gfx::ToEnclosedRect( |
| + gfx::ScaleRect((*i)->LayerRect(), contents_scale)); |
| + DCHECK(!content_clip.IsEmpty()); |
| + if (!unclipped.Intersects(content_clip)) |
| continue; |
| - if (!(*i)->IsCheapInRect(layer_rect)) |
| - return false; |
| + |
| + // Do the analysis on the canvas. |
|
Sami
2013/03/05 20:18:31
Nit: doesn't seem like a very useful comment.
|
| + (*i)->AnalyzeInRect(&canvas, |
| + content_rect, |
| + contents_scale); |
| + |
| + canvas.clipRect( |
| + gfx::RectToSkRect(content_clip), |
| + SkRegion::kDifference_Op); |
| + unclipped.Subtract(content_clip); |
| + |
| } |
| } |
| - return true; |
| + |
| + analysis->is_transparent = canvas.isTransparent(); |
| + analysis->is_solid_color = canvas.getColorIfSolid(&analysis->solid_color); |
| + analysis->is_cheap_to_raster = canvas.isCheap(); |
| +} |
| + |
| +PicturePileImpl::Analysis::Analysis() : |
| + is_solid_color(false), |
| + is_transparent(false), |
| + is_cheap_to_raster(false) { |
| } |
| } // namespace cc |