Chromium Code Reviews| Index: cc/resources/picture.cc |
| diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc |
| index 93b59aea7435532456ab03b9248113b8e5c8d46c..4bb3bca1a26cbe5e2f50c965337801dca1d790ec 100644 |
| --- a/cc/resources/picture.cc |
| +++ b/cc/resources/picture.cc |
| @@ -9,6 +9,7 @@ |
| #include <set> |
| #include "base/base64.h" |
| +#include "base/command_line.h" |
| #include "base/debug/trace_event.h" |
| #include "base/values.h" |
| #include "cc/base/math_util.h" |
| @@ -191,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_.get() != NULL) { |
| + 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); |
| @@ -213,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_.get() != NULL) { |
| + return; |
| + } |
| + |
| DCHECK(picture_); |
| DCHECK(clones_.empty()); |
| @@ -240,6 +251,13 @@ void Picture::CloneForDrawing(int num_threads) { |
| void Picture::Record(ContentLayerClient* painter, |
| const SkTileGridPicture::TileGridInfo& tile_grid_info, |
| RecordingMode recording_mode) { |
| + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| + // HACK HACK HACK HACK: checkdeps won't let me look at this flag here. :( |
|
enne (OOO)
2014/04/17 17:09:49
If you want to make this patch more real, I'd sugg
mtklein
2014/04/17 17:32:04
Ah, thanks, figuring this out was actually my hang
|
| + if (command_line.HasSwitch("enable-bleeding-edge-rendering-fast-paths")) { |
| + recording_mode = RECORD_WITH_SKRECORD; |
| + } |
| + recording_mode = RECORD_WITH_SKRECORD; |
| + |
| TRACE_EVENT2("cc", |
| "Picture::Record", |
| "data", |
| @@ -252,22 +270,33 @@ void Picture::Record(ContentLayerClient* painter, |
| picture_ = skia::AdoptRef(new SkTileGridPicture( |
| layer_rect_.width(), layer_rect_.height(), tile_grid_info)); |
| - skia::RefPtr<SkCanvas> canvas; |
| + skia::RefPtr<SkCanvas> ownedCanvas; |
| + SkCanvas* canvas = NULL; |
|
tomhudson
2014/04/17 16:44:03
cc/ dogma considers any naked SkCanvas pointer to
enne (OOO)
2014/04/17 17:09:49
And, on the third day, the clouds opened and Peevi
mtklein
2014/04/17 17:32:04
Do you guys have an UnownedPtr? Or a MaybeOwnedPt
danakj
2014/04/17 17:36:56
You can always ref something that's refcounted. If
enne (OOO)
2014/04/17 17:41:44
More seriously, raw Skia objects do have some code
|
| + EXPERIMENTAL::SkRecording* recording = NULL; |
| + |
| switch (recording_mode) { |
| case RECORD_NORMALLY: |
| - canvas = skia::SharePtr(picture_->beginRecording( |
| + ownedCanvas = skia::SharePtr(picture_->beginRecording( |
| layer_rect_.width(), |
| layer_rect_.height(), |
| SkPicture::kUsePathBoundsForClip_RecordingFlag | |
| SkPicture::kOptimizeForClippedPlayback_RecordingFlag)); |
| + canvas = ownedCanvas.get(); |
| break; |
| case RECORD_WITH_SK_NULL_CANVAS: |
| - canvas = skia::AdoptRef(SkCreateNullCanvas()); |
| + ownedCanvas = skia::AdoptRef(SkCreateNullCanvas()); |
| + canvas = ownedCanvas.get(); |
| break; |
| case RECORD_WITH_PAINTING_DISABLED: |
| // Blink's GraphicsContext will disable painting when given a NULL |
| // canvas. |
| break; |
| + case RECORD_WITH_SKRECORD: { |
| + recording = EXPERIMENTAL::SkRecording::Create(layer_rect_.width(), |
| + layer_rect_.height()); |
| + canvas = recording->canvas(); |
| + break; |
| + } |
| default: |
| NOTREACHED(); |
| } |
| @@ -285,13 +314,17 @@ void Picture::Record(ContentLayerClient* painter, |
| } |
| gfx::RectF opaque_layer_rect; |
| - painter->PaintContents(canvas.get(), layer_rect_, &opaque_layer_rect); |
| + painter->PaintContents(canvas, layer_rect_, &opaque_layer_rect); |
| if (canvas) |
| canvas->restore(); |
| if (picture_->getRecordingCanvas()) |
| picture_->endRecording(); |
| + if (recording != NULL) { |
| + playback_.reset(EXPERIMENTAL::SkRecording::Delete(recording)); |
| + } |
| + |
| opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); |
| EmitTraceSnapshot(); |
| @@ -374,7 +407,11 @@ int Picture::Raster( |
| canvas->scale(contents_scale, contents_scale); |
| canvas->translate(layer_rect_.x(), layer_rect_.y()); |
| - picture_->draw(canvas, callback); |
| + if (playback_.get() != NULL) { |
| + playback_->draw(canvas); |
| + } else { |
| + picture_->draw(canvas, callback); |
| + } |
| SkIRect bounds; |
| canvas->getClipDeviceBounds(&bounds); |
| canvas->restore(); |
| @@ -389,7 +426,11 @@ void Picture::Replay(SkCanvas* canvas) { |
| TRACE_EVENT_BEGIN0("cc", "Picture::Replay"); |
| DCHECK(picture_); |
| - picture_->draw(canvas); |
| + if (playback_.get() != NULL) { |
| + playback_->draw(canvas); |
| + } else { |
| + picture_->draw(canvas); |
| + } |
| SkIRect bounds; |
| canvas->getClipDeviceBounds(&bounds); |
| TRACE_EVENT_END1("cc", "Picture::Replay", |