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

Unified Diff: cc/resources/picture.cc

Issue 14230007: cc: Do GatherPixelRefs from skia at record time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« cc/resources/picture.h ('K') | « cc/resources/picture.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/picture.cc
diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc
index 2b6eca8777fbc0c3d7d280170d3f7008ce85d990..2fc4fee798c27cf83f03bc1c26d5ed323e02cbd1 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"
@@ -44,10 +48,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 PositionPixelRefsVector& 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 +79,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 +132,8 @@ void Picture::Record(ContentLayerClient* painter,
picture_->endRecording();
opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect);
+
+ GatherAllPixelRefs();
}
void Picture::Raster(
@@ -152,6 +161,26 @@ void Picture::Raster(
void Picture::GatherPixelRefs(const gfx::Rect& layer_rect,
std::list<skia::LazyPixelRef*>& pixel_ref_list) {
+ std::list<skia::LazyPixelRef*> pixel_refs;
+ for (PositionPixelRefsVector::iterator iter = lazy_pixel_refs_.begin();
+ iter != lazy_pixel_refs_.end();
+ ++iter) {
+ if (iter->rect.Intersects(layer_rect)) {
+ pixel_refs.insert(pixel_refs.end(),
+ iter->pixel_refs.begin(),
+ iter->pixel_refs.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 +207,33 @@ void Picture::GatherPixelRefs(const gfx::Rect& layer_rect,
pixel_refs->unref();
}
+void Picture::GatherAllPixelRefs() {
+ const gfx::Size kRegionSize(512, 512);
+ // 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());
enne (OOO) 2013/04/16 22:03:36 Can we get this information from Skia, rather than
reveman 2013/04/17 00:25:28 this is not related to the image size. it's the gr
+
+ std::list<skia::LazyPixelRef*> lazy_pixel_refs;
+ GatherPixelRefsFromSkia(rect, lazy_pixel_refs);
+
+ // Only capture non-empty cells.
+ if (!lazy_pixel_refs.empty()) {
+ PositionPixelRefs position_pixel_refs;
+ position_pixel_refs.rect = rect;
+ position_pixel_refs.pixel_refs.swap(lazy_pixel_refs);
+ lazy_pixel_refs_.push_back(position_pixel_refs);
+ }
+ }
+ }
+}
+
} // namespace cc
« cc/resources/picture.h ('K') | « cc/resources/picture.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698