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

Unified Diff: cc/resources/display_item_list.cc

Issue 1001833005: Update from https://crrev.com/320343 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Supress Created 5 years, 9 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
« no previous file with comments | « cc/resources/display_item_list.h ('k') | cc/resources/display_list_recording_source.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/display_item_list.cc
diff --git a/cc/resources/display_item_list.cc b/cc/resources/display_item_list.cc
index ac6ab57d18536cfb15d648f1dd259f1fcca257d6..48f8c66dd32bba9808e4dc7d3ddb5b93685cbd5c 100644
--- a/cc/resources/display_item_list.cc
+++ b/cc/resources/display_item_list.cc
@@ -10,8 +10,12 @@
#include "base/trace_event/trace_event_argument.h"
#include "cc/base/math_util.h"
#include "cc/debug/picture_debug_util.h"
+#include "cc/debug/traced_picture.h"
+#include "cc/debug/traced_value.h"
#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkDrawPictureCallback.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
+#include "third_party/skia/include/utils/SkPictureUtils.h"
#include "ui/gfx/skia_util.h"
namespace cc {
@@ -30,12 +34,46 @@ DisplayItemList::~DisplayItemList() {
void DisplayItemList::Raster(SkCanvas* canvas,
SkDrawPictureCallback* callback,
float contents_scale) const {
- canvas->save();
- canvas->scale(contents_scale, contents_scale);
- for (size_t i = 0; i < items_.size(); ++i) {
- items_[i]->Raster(canvas, callback);
+ 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();
+ } else {
+ DCHECK(picture_);
+
+ canvas->save();
+ canvas->scale(contents_scale, contents_scale);
+ 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();
}
- 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.endRecording());
+ DCHECK(picture_);
}
void DisplayItemList::AppendItem(scoped_ptr<DisplayItem> item) {
@@ -62,6 +100,9 @@ size_t DisplayItemList::PictureMemoryUsage() const {
total_size += item->PictureMemoryUsage();
}
+ if (picture_)
+ total_size += SkPictureUtils::ApproximateBytesUsed(picture_.get());
+
return total_size;
}
« no previous file with comments | « cc/resources/display_item_list.h ('k') | cc/resources/display_list_recording_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698