diff options
author | mtklein@chromium.org <mtklein@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-30 14:53:44 +0000 |
---|---|---|
committer | mtklein@chromium.org <mtklein@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-30 14:53:44 +0000 |
commit | bc912d62c56a24662004cc46461d04609fd2c162 (patch) | |
tree | f6a31b407be813f540fa98914518d5425913dcc9 /cc/resources | |
parent | 2031f930f895d1a308e85036139abc2fb5a98c61 (diff) | |
download | chromium_src-bc912d62c56a24662004cc46461d04609fd2c162.zip chromium_src-bc912d62c56a24662004cc46461d04609fd2c162.tar.gz chromium_src-bc912d62c56a24662004cc46461d04609fd2c162.tar.bz2 |
Hack SkRecord in as an alternate recording mode in cc/resources/picture.
BUG=skia:2378
Review URL: https://codereview.chromium.org/225023031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267209 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/resources')
-rw-r--r-- | cc/resources/picture.cc | 36 | ||||
-rw-r--r-- | cc/resources/picture.h | 3 | ||||
-rw-r--r-- | cc/resources/picture_unittest.cc | 11 |
3 files changed, 47 insertions, 3 deletions
diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc index 48f03e0..de6ff93 100644 --- a/cc/resources/picture.cc +++ b/cc/resources/picture.cc @@ -192,6 +192,11 @@ Picture::~Picture() { } Picture* Picture::GetCloneForDrawingOnThread(unsigned thread_index) { + // We don't need clones to draw from multiple threads with SkRecord. + if (playback_) { + return this; + } + // SkPicture is not thread-safe to rasterize with, this returns a clone // to rasterize with on a specific thread. CHECK_GE(clones_.size(), thread_index); @@ -214,6 +219,11 @@ bool Picture::IsSuitableForGpuRasterization() const { void Picture::CloneForDrawing(int num_threads) { TRACE_EVENT1("cc", "Picture::CloneForDrawing", "num_threads", num_threads); + // We don't need clones to draw from multiple threads with SkRecord. + if (playback_) { + return; + } + DCHECK(picture_); DCHECK(clones_.empty()); @@ -254,6 +264,8 @@ void Picture::Record(ContentLayerClient* painter, SkTileGridFactory factory(tile_grid_info); SkPictureRecorder recorder; + scoped_ptr<EXPERIMENTAL::SkRecording> recording; + skia::RefPtr<SkCanvas> canvas; canvas = skia::SharePtr( recorder.beginRecording(layer_rect_.width(), @@ -273,6 +285,11 @@ void Picture::Record(ContentLayerClient* painter, // canvas. canvas.clear(); break; + case RECORD_WITH_SKRECORD: + recording.reset(new EXPERIMENTAL::SkRecording(layer_rect_.width(), + layer_rect_.height())); + canvas = skia::SharePtr(recording->canvas()); + break; default: NOTREACHED(); } @@ -297,6 +314,13 @@ void Picture::Record(ContentLayerClient* painter, picture_ = skia::AdoptRef(recorder.endRecording()); DCHECK(picture_); + if (recording) { + // SkRecording requires it's the only one holding onto canvas before we + // may call releasePlayback(). (This helps enforce thread-safety.) + canvas.clear(); + playback_.reset(recording->releasePlayback()); + } + opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); EmitTraceSnapshot(); @@ -379,7 +403,11 @@ int Picture::Raster( canvas->scale(contents_scale, contents_scale); canvas->translate(layer_rect_.x(), layer_rect_.y()); - picture_->draw(canvas, callback); + if (playback_) { + playback_->draw(canvas); + } else { + picture_->draw(canvas, callback); + } SkIRect bounds; canvas->getClipDeviceBounds(&bounds); canvas->restore(); @@ -394,7 +422,11 @@ void Picture::Replay(SkCanvas* canvas) { TRACE_EVENT_BEGIN0("cc", "Picture::Replay"); DCHECK(picture_); - picture_->draw(canvas); + if (playback_) { + playback_->draw(canvas); + } else { + picture_->draw(canvas); + } SkIRect bounds; canvas->getClipDeviceBounds(&bounds); TRACE_EVENT_END1("cc", "Picture::Replay", diff --git a/cc/resources/picture.h b/cc/resources/picture.h index 26d106b..4761ca6 100644 --- a/cc/resources/picture.h +++ b/cc/resources/picture.h @@ -22,6 +22,7 @@ #include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkBBHFactory.h" #include "third_party/skia/include/core/SkPicture.h" +#include "third_party/skia/include/record/SkRecording.h" #include "ui/gfx/rect.h" class SkPixelRef; @@ -49,6 +50,7 @@ class CC_EXPORT Picture RECORD_NORMALLY, RECORD_WITH_SK_NULL_CANVAS, RECORD_WITH_PAINTING_DISABLED, + RECORD_WITH_SKRECORD, RECORDING_MODE_COUNT, // Must be the last entry. }; @@ -156,6 +158,7 @@ class CC_EXPORT Picture gfx::Rect layer_rect_; gfx::Rect opaque_rect_; skia::RefPtr<SkPicture> picture_; + scoped_ptr<const EXPERIMENTAL::SkPlayback> playback_; typedef std::vector<scoped_refptr<Picture> > PictureVector; PictureVector clones_; diff --git a/cc/resources/picture_unittest.cc b/cc/resources/picture_unittest.cc index 8a36743..a3910c6 100644 --- a/cc/resources/picture_unittest.cc +++ b/cc/resources/picture_unittest.cc @@ -483,7 +483,16 @@ TEST(PictureTest, RecordingModes) { EXPECT_EQ(NULL, content_layer_client.last_canvas()); EXPECT_TRUE(picture); - EXPECT_EQ(3, Picture::RECORDING_MODE_COUNT); + picture = Picture::Create(layer_rect, + &content_layer_client, + tile_grid_info, + false, + 0, + Picture::RECORD_WITH_SKRECORD); + EXPECT_TRUE(content_layer_client.last_canvas() != NULL); + EXPECT_TRUE(picture); + + EXPECT_EQ(4, Picture::RECORDING_MODE_COUNT); } } // namespace |