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

Unified Diff: cc/resources/display_item_list.cc

Issue 1077033004: cc: Make DisplayItemList::Append replay into an SkPicture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 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
Index: cc/resources/display_item_list.cc
diff --git a/cc/resources/display_item_list.cc b/cc/resources/display_item_list.cc
index b541c5f34d9a066bf4dfd7fdcbedeca6568850b6..e9112076b0f0cf3b75a66c9dce10ee41da22cb8d 100644
--- a/cc/resources/display_item_list.cc
+++ b/cc/resources/display_item_list.cc
@@ -20,12 +20,30 @@
namespace cc {
-DisplayItemList::DisplayItemList()
- : is_suitable_for_gpu_rasterization_(true), approximate_op_count_(0) {
+DisplayItemList::DisplayItemList(gfx::Rect layer_rect)
+ : recorder_(new SkPictureRecorder()),
+ retain_individual_display_items_(false),
+ layer_rect_(layer_rect),
+ is_suitable_for_gpu_rasterization_(true),
+ approximate_op_count_(0) {
+ SkRTreeFactory factory;
+ recorder_.reset(new SkPictureRecorder());
+ canvas_ = skia::SharePtr(recorder_->beginRecording(
+ layer_rect_.width(), layer_rect_.height(), &factory));
+ canvas_->translate(-layer_rect_.x(), -layer_rect_.y());
+ canvas_->clipRect(gfx::RectToSkRect(layer_rect_));
+
+ bool tracing_enabled;
+ TRACE_EVENT_CATEGORY_GROUP_ENABLED(
+ TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") ","
+ TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"),
+ &tracing_enabled);
ajuma 2015/04/14 18:02:32 If tracing is enabled after the DisplayItemList is
+ if (tracing_enabled)
+ retain_individual_display_items_ = true;
}
-scoped_refptr<DisplayItemList> DisplayItemList::Create() {
- return make_scoped_refptr(new DisplayItemList());
+scoped_refptr<DisplayItemList> DisplayItemList::Create(gfx::Rect layer_rect) {
+ return make_scoped_refptr(new DisplayItemList(layer_rect));
}
DisplayItemList::~DisplayItemList() {
@@ -34,53 +52,42 @@ DisplayItemList::~DisplayItemList() {
void DisplayItemList::Raster(SkCanvas* canvas,
SkDrawPictureCallback* callback,
float contents_scale) const {
- if (!picture_) {
- canvas->save();
- canvas->scale(contents_scale, contents_scale);
- for (size_t i = 0; i < items_.size(); ++i) {
- items_[i]->Raster(canvas, callback);
- }
- canvas->restore();
+ DCHECK(picture_);
+
+ canvas->save();
+ canvas->scale(contents_scale, contents_scale);
+ canvas->translate(layer_rect_.x(), layer_rect_.y());
+ if (callback) {
+ // If we have a callback, we need to call |draw()|, |drawPicture()|
+ // doesn't take a callback. This is used by |AnalysisCanvas| to early
+ // out.
+ picture_->playback(canvas, callback);
} else {
- DCHECK(picture_);
-
- canvas->save();
- canvas->scale(contents_scale, contents_scale);
- canvas->translate(layer_rect_.x(), layer_rect_.y());
- if (callback) {
- // If we have a callback, we need to call |draw()|, |drawPicture()|
- // doesn't take a callback. This is used by |AnalysisCanvas| to early
- // out.
- picture_->playback(canvas, callback);
- } else {
- // Prefer to call |drawPicture()| on the canvas since it could place the
- // entire picture on the canvas instead of parsing the skia operations.
- canvas->drawPicture(picture_.get());
- }
- canvas->restore();
+ // Prefer to call |drawPicture()| on the canvas since it could place the
+ // entire picture on the canvas instead of parsing the skia operations.
+ canvas->drawPicture(picture_.get());
}
+ canvas->restore();
}
void DisplayItemList::CreateAndCacheSkPicture() {
- // Convert to an SkPicture for faster rasterization. Code is identical to
- // that in Picture::Record.
- SkRTreeFactory factory;
- SkPictureRecorder recorder;
- skia::RefPtr<SkCanvas> canvas;
- canvas = skia::SharePtr(recorder.beginRecording(
- layer_rect_.width(), layer_rect_.height(), &factory));
- canvas->translate(-layer_rect_.x(), -layer_rect_.y());
- canvas->clipRect(gfx::RectToSkRect(layer_rect_));
- for (size_t i = 0; i < items_.size(); ++i)
- items_[i]->Raster(canvas.get(), NULL);
- picture_ = skia::AdoptRef(recorder.endRecordingAsPicture());
+ // Convert to an SkPicture for faster rasterization.
+ picture_ = skia::AdoptRef(recorder_->endRecordingAsPicture());
DCHECK(picture_);
+ recorder_.reset();
+ canvas_.clear();
}
void DisplayItemList::AppendItem(scoped_ptr<DisplayItem> item) {
+ DCHECK(canvas_);
+
is_suitable_for_gpu_rasterization_ &= item->IsSuitableForGpuRasterization();
approximate_op_count_ += item->ApproximateOpCount();
- items_.push_back(item.Pass());
+
+ item->Raster(canvas_.get(), NULL);
+
+ if (retain_individual_display_items_)
+ items_.push_back(item.Pass());
}
bool DisplayItemList::IsSuitableForGpuRasterization() const {
@@ -121,18 +128,9 @@ DisplayItemList::AsValue() const {
state->SetValue("params.layer_rect",
MathUtil::AsValue(layer_rect_).release());
- SkPictureRecorder recorder;
- SkCanvas* canvas =
- recorder.beginRecording(layer_rect_.width(), layer_rect_.height());
- canvas->translate(-layer_rect_.x(), -layer_rect_.y());
- canvas->clipRect(gfx::RectToSkRect(layer_rect_));
- for (size_t i = 0; i < items_.size(); ++i)
- items_[i]->RasterForTracing(canvas);
- skia::RefPtr<SkPicture> picture =
- skia::AdoptRef(recorder.endRecordingAsPicture());
-
std::string b64_picture;
- PictureDebugUtil::SerializeAsBase64(picture.get(), &b64_picture);
+ DCHECK(picture_);
+ PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture);
state->SetString("skp64", b64_picture);
return state;

Powered by Google App Engine
This is Rietveld 408576698