Chromium Code Reviews| Index: cc/resources/picture.cc |
| diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc |
| index 2b6eca8777fbc0c3d7d280170d3f7008ce85d990..1052f1f3419cb87641f7f42574e902609ec31cd2 100644 |
| --- a/cc/resources/picture.cc |
| +++ b/cc/resources/picture.cc |
| @@ -2,10 +2,14 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "cc/resources/picture.h" |
| + |
| +#include <algorithm> |
| +#include <set> |
| + |
| #include "base/debug/trace_event.h" |
| #include "cc/debug/rendering_stats.h" |
| #include "cc/layers/content_layer_client.h" |
| -#include "cc/resources/picture.h" |
| #include "skia/ext/analysis_canvas.h" |
| #include "third_party/skia/include/core/SkCanvas.h" |
| #include "third_party/skia/include/core/SkData.h" |
| @@ -18,6 +22,8 @@ |
| namespace { |
| // URI label for a lazily decoded SkPixelRef. |
| const char kLabelLazyDecoded[] = "lazy"; |
| +// Size of each of the grid cells for storing lazy pixel refs. |
| +const gfx::Size kRegionSize(512, 512); |
|
reveman
2013/04/17 00:42:57
only POD is allowed for objects with static storag
|
| class DisableLCDTextFilter : public SkDrawFilter { |
| public: |
| @@ -44,10 +50,12 @@ Picture::Picture(gfx::Rect layer_rect) |
| Picture::Picture(const skia::RefPtr<SkPicture>& picture, |
| gfx::Rect layer_rect, |
| - gfx::Rect opaque_rect) : |
| + gfx::Rect opaque_rect, |
| + const PixelRefsMap& lazy_pixel_refs) : |
| layer_rect_(layer_rect), |
| opaque_rect_(opaque_rect), |
| - picture_(picture) { |
| + picture_(picture), |
| + lazy_pixel_refs_(lazy_pixel_refs) { |
| } |
| Picture::~Picture() { |
| @@ -73,7 +81,8 @@ void Picture::CloneForDrawing(int num_threads) { |
| scoped_refptr<Picture> clone = make_scoped_refptr( |
| new Picture(skia::AdoptRef(new SkPicture(clones[i])), |
| layer_rect_, |
| - opaque_rect_)); |
| + opaque_rect_, |
| + lazy_pixel_refs_)); |
| clones_.push_back(clone); |
| } |
| } |
| @@ -125,6 +134,8 @@ void Picture::Record(ContentLayerClient* painter, |
| picture_->endRecording(); |
| opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); |
| + |
| + GatherAllPixelRefs(); |
| } |
| void Picture::Raster( |
| @@ -152,6 +163,38 @@ void Picture::Raster( |
| void Picture::GatherPixelRefs(const gfx::Rect& layer_rect, |
| std::list<skia::LazyPixelRef*>& pixel_ref_list) { |
|
reveman
2013/04/17 00:42:57
How about adding a Picture::PixelRefIterator inste
|
| + std::list<skia::LazyPixelRef*> pixel_refs; |
| + // The min/max point calculation assumes that layer_rect |
| + // origin's coordinates are non-negative. |
| + DCHECK(layer_rect.x() >= 0 && layer_rect.y() >= 0); |
| + gfx::Point min_point( |
| + (layer_rect.x() / kRegionSize.width()) * kRegionSize.width(), |
| + (layer_rect.y() / kRegionSize.height()) * kRegionSize.height()); |
| + gfx::Point max_point( |
| + (layer_rect.right() / kRegionSize.width()) * kRegionSize.width(), |
| + (layer_rect.bottom() / kRegionSize.height()) * kRegionSize.height()); |
| + |
| + for (int y = min_point.y(); y <= max_point.y(); y += kRegionSize.height()) { |
| + for (int x = min_point.x(); x <= max_point.x(); x += kRegionSize.width()) { |
| + PixelRefsMap::const_iterator iter = |
| + lazy_pixel_refs_.find(std::make_pair(x, y)); |
| + if (iter != lazy_pixel_refs_.end()) { |
| + pixel_refs.insert(pixel_refs.end(), |
| + iter->second.begin(), |
| + iter->second.end()); |
| + } |
| + } |
| + } |
| + std::set<skia::LazyPixelRef*> unique_pixel_refs(pixel_refs.begin(), |
| + pixel_refs.end()); |
| + pixel_ref_list.insert(pixel_ref_list.end(), |
| + unique_pixel_refs.begin(), |
| + unique_pixel_refs.end()); |
| +} |
| + |
| +void Picture::GatherPixelRefsFromSkia( |
| + const gfx::Rect& layer_rect, |
| + std::list<skia::LazyPixelRef*>& pixel_ref_list) { |
| DCHECK(picture_); |
| SkData* pixel_refs = SkPictureUtils::GatherPixelRefs( |
| picture_.get(), SkRect::MakeXYWH(layer_rect.x(), |
| @@ -178,4 +221,28 @@ void Picture::GatherPixelRefs(const gfx::Rect& layer_rect, |
| pixel_refs->unref(); |
| } |
| +void Picture::GatherAllPixelRefs() { |
| + // Capture pixel refs for this picture in a grid |
| + // with kRegionSize sized cells. |
| + for (int y = layer_rect_.y(); |
| + y < layer_rect_.bottom(); |
| + y += kRegionSize.height()) { |
| + for (int x = layer_rect_.x(); |
| + x < layer_rect_.right(); |
| + x += kRegionSize.width()) { |
| + gfx::Size extent( |
| + std::min(kRegionSize.width(), layer_rect_.right() - x), |
| + std::min(kRegionSize.height(), layer_rect_.bottom() - y)); |
| + gfx::Rect rect(x, y, extent.width(), extent.height()); |
| + |
| + std::list<skia::LazyPixelRef*> lazy_pixel_refs; |
| + GatherPixelRefsFromSkia(rect, lazy_pixel_refs); |
| + |
| + // Only capture non-empty cells. |
| + if (!lazy_pixel_refs.empty()) |
| + lazy_pixel_refs_[std::make_pair(x, y)].swap(lazy_pixel_refs); |
| + } |
| + } |
| +} |
| + |
| } // namespace cc |