diff options
author | skyostil@chromium.org <skyostil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-06 13:49:46 +0000 |
---|---|---|
committer | skyostil@chromium.org <skyostil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-06 13:49:46 +0000 |
commit | 8b023d82648f11c12293aaa572c89ac63fbbe5e0 (patch) | |
tree | 46eed9a334da31d389625bd195a6454f5830d5db /cc/resources | |
parent | d049ddba0524b0a9bb380542d956c916cebd9034 (diff) | |
download | chromium_src-8b023d82648f11c12293aaa572c89ac63fbbe5e0.zip chromium_src-8b023d82648f11c12293aaa572c89ac63fbbe5e0.tar.gz chromium_src-8b023d82648f11c12293aaa572c89ac63fbbe5e0.tar.bz2 |
cc: Use SkRecord recording back-end in bleeding edge rendering mode
Start using Skia's experimental SkRecord recording back-end in the
bleeding edge rendering mode (--enable-bleeding-edge-rendering-fast-paths).
This allows us to measure the rasterization speed of this back-end in
benchmarks such as rasterize_and_record_micro.
Note that once SkRecord replaces SkPicture's internal recording back-end
this patch becomes obsolete. It is only needed during the transition
phase.
Review URL: https://codereview.chromium.org/253813002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268507 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/resources')
-rw-r--r-- | cc/resources/picture.cc | 23 | ||||
-rw-r--r-- | cc/resources/picture.h | 6 | ||||
-rw-r--r-- | cc/resources/picture_pile.cc | 3 | ||||
-rw-r--r-- | cc/resources/picture_pile.h | 1 | ||||
-rw-r--r-- | cc/resources/picture_pile_unittest.cc | 1 | ||||
-rw-r--r-- | cc/resources/picture_unittest.cc | 115 |
6 files changed, 88 insertions, 61 deletions
diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc index d9b45df..7147a15 100644 --- a/cc/resources/picture.cc +++ b/cc/resources/picture.cc @@ -391,7 +391,8 @@ int Picture::Raster( SkDrawPictureCallback* callback, const Region& negated_content_region, float contents_scale) { - DCHECK(raster_thread_checker_.CalledOnValidThread()); + if (!playback_) + DCHECK(raster_thread_checker_.CalledOnValidThread()); TRACE_EVENT_BEGIN1( "cc", "Picture::Raster", @@ -422,7 +423,8 @@ int Picture::Raster( } void Picture::Replay(SkCanvas* canvas) { - DCHECK(raster_thread_checker_.CalledOnValidThread()); + if (!playback_) + DCHECK(raster_thread_checker_.CalledOnValidThread()); TRACE_EVENT_BEGIN0("cc", "Picture::Replay"); DCHECK(picture_); @@ -440,8 +442,21 @@ void Picture::Replay(SkCanvas* canvas) { scoped_ptr<base::Value> Picture::AsValue() const { SkDynamicMemoryWStream stream; - // Serialize the picture. - picture_->serialize(&stream, &EncodeBitmap); + if (playback_) { + // SkPlayback can't serialize itself, so re-record into an SkPicture. + SkPictureRecorder recorder; + skia::RefPtr<SkCanvas> canvas(skia::SharePtr(recorder.beginRecording( + layer_rect_.width(), + layer_rect_.height(), + NULL, // Default (no) bounding-box hierarchy is fastest. + SkPicture::kUsePathBoundsForClip_RecordingFlag))); + playback_->draw(canvas.get()); + skia::RefPtr<SkPicture> picture(skia::AdoptRef(recorder.endRecording())); + picture->serialize(&stream, &EncodeBitmap); + } else { + // Serialize the picture. + picture_->serialize(&stream, &EncodeBitmap); + } // Encode the picture as base64. scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); diff --git a/cc/resources/picture.h b/cc/resources/picture.h index 4761ca6..78833d1 100644 --- a/cc/resources/picture.h +++ b/cc/resources/picture.h @@ -75,8 +75,10 @@ class CC_EXPORT Picture bool IsSuitableForGpuRasterization() const; - // Apply this scale and raster the negated region into the canvas. See comment - // in PicturePileImpl::RasterCommon for explanation on negated content region. + // Apply this scale and raster the negated region into the canvas. + // |negated_content_region| specifies the region to be clipped out of the + // raster operation, i.e., the parts of the canvas which will not get drawn + // to. int Raster(SkCanvas* canvas, SkDrawPictureCallback* callback, const Region& negated_content_region, diff --git a/cc/resources/picture_pile.cc b/cc/resources/picture_pile.cc index 6637e4d..27c58a1 100644 --- a/cc/resources/picture_pile.cc +++ b/cc/resources/picture_pile.cc @@ -153,6 +153,7 @@ bool PicturePile::Update(ContentLayerClient* painter, const Region& invalidation, const gfx::Rect& visible_layer_rect, int frame_number, + Picture::RecordingMode recording_mode, RenderingStatsInstrumentation* stats_instrumentation) { background_color_ = background_color; contents_opaque_ = contents_opaque; @@ -243,7 +244,7 @@ bool PicturePile::Update(ContentLayerClient* painter, tile_grid_info_, gather_pixel_refs, num_raster_threads, - Picture::RECORD_NORMALLY); + recording_mode); // Note the '&&' with previous is-suitable state. // This means that once a picture-pile becomes unsuitable for gpu // rasterization due to some content, it will continue to be unsuitable diff --git a/cc/resources/picture_pile.h b/cc/resources/picture_pile.h index dbc3966..415bbdfe 100644 --- a/cc/resources/picture_pile.h +++ b/cc/resources/picture_pile.h @@ -27,6 +27,7 @@ class CC_EXPORT PicturePile : public PicturePileBase { const Region& invalidation, const gfx::Rect& visible_layer_rect, int frame_number, + Picture::RecordingMode recording_mode, RenderingStatsInstrumentation* stats_instrumentation); void set_slow_down_raster_scale_factor(int factor) { diff --git a/cc/resources/picture_pile_unittest.cc b/cc/resources/picture_pile_unittest.cc index 04b4c33..0387863 100644 --- a/cc/resources/picture_pile_unittest.cc +++ b/cc/resources/picture_pile_unittest.cc @@ -60,6 +60,7 @@ class PicturePileTest : public testing::Test { invalidation, visible_layer_rect, frame_number_, + Picture::RECORD_NORMALLY, &stats_instrumentation_); } diff --git a/cc/resources/picture_unittest.cc b/cc/resources/picture_unittest.cc index 61b048a..1367c5f 100644 --- a/cc/resources/picture_unittest.cc +++ b/cc/resources/picture_unittest.cc @@ -43,68 +43,75 @@ TEST(PictureTest, AsBase64String) { tmp.reset(new base::StringValue("abc!@#$%")); scoped_refptr<Picture> invalid_picture = Picture::CreateFromValue(tmp.get()); - EXPECT_TRUE(!invalid_picture.get()); + EXPECT_FALSE(invalid_picture.get()); + + Picture::RecordingMode kRecordingModes[] = {Picture::RECORD_NORMALLY, + Picture::RECORD_WITH_SKRECORD}; // Single full-size rect picture. content_layer_client.add_draw_rect(layer_rect, red_paint); - scoped_refptr<Picture> one_rect_picture = - Picture::Create(layer_rect, - &content_layer_client, - tile_grid_info, - false, - 0, - Picture::RECORD_NORMALLY); - scoped_ptr<base::Value> serialized_one_rect( - one_rect_picture->AsValue()); - - // Reconstruct the picture. - scoped_refptr<Picture> one_rect_picture_check = - Picture::CreateFromValue(serialized_one_rect.get()); - EXPECT_TRUE(!!one_rect_picture_check.get()); - // Check for equivalence. - unsigned char one_rect_buffer[4 * 100 * 100] = {0}; - DrawPicture(one_rect_buffer, layer_rect, one_rect_picture); - unsigned char one_rect_buffer_check[4 * 100 * 100] = {0}; - DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check); - - EXPECT_EQ(one_rect_picture->LayerRect(), - one_rect_picture_check->LayerRect()); - EXPECT_EQ(one_rect_picture->OpaqueRect(), - one_rect_picture_check->OpaqueRect()); - EXPECT_TRUE( - memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100) == 0); + for (size_t i = 0; i < arraysize(kRecordingModes); ++i) { + scoped_refptr<Picture> one_rect_picture = + Picture::Create(layer_rect, + &content_layer_client, + tile_grid_info, + false, + 0, + kRecordingModes[i]); + scoped_ptr<base::Value> serialized_one_rect(one_rect_picture->AsValue()); + + // Reconstruct the picture. + scoped_refptr<Picture> one_rect_picture_check = + Picture::CreateFromValue(serialized_one_rect.get()); + EXPECT_TRUE(!!one_rect_picture_check.get()); + + // Check for equivalence. + unsigned char one_rect_buffer[4 * 100 * 100] = {0}; + DrawPicture(one_rect_buffer, layer_rect, one_rect_picture); + unsigned char one_rect_buffer_check[4 * 100 * 100] = {0}; + DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check); + + EXPECT_EQ(one_rect_picture->LayerRect(), + one_rect_picture_check->LayerRect()); + EXPECT_EQ(one_rect_picture->OpaqueRect(), + one_rect_picture_check->OpaqueRect()); + EXPECT_TRUE(memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100) == + 0); + } // Two rect picture. content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint); - scoped_refptr<Picture> two_rect_picture = - Picture::Create(layer_rect, - &content_layer_client, - tile_grid_info, - false, - 0, - Picture::RECORD_NORMALLY); - scoped_ptr<base::Value> serialized_two_rect( - two_rect_picture->AsValue()); - - // Reconstruct the picture. - scoped_refptr<Picture> two_rect_picture_check = - Picture::CreateFromValue(serialized_two_rect.get()); - EXPECT_TRUE(!!two_rect_picture_check.get()); - - // Check for equivalence. - unsigned char two_rect_buffer[4 * 100 * 100] = {0}; - DrawPicture(two_rect_buffer, layer_rect, two_rect_picture); - unsigned char two_rect_buffer_check[4 * 100 * 100] = {0}; - DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check); - - EXPECT_EQ(two_rect_picture->LayerRect(), - two_rect_picture_check->LayerRect()); - EXPECT_EQ(two_rect_picture->OpaqueRect(), - two_rect_picture_check->OpaqueRect()); - EXPECT_TRUE( - memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100) == 0); + for (size_t i = 0; i < arraysize(kRecordingModes); ++i) { + scoped_refptr<Picture> two_rect_picture = + Picture::Create(layer_rect, + &content_layer_client, + tile_grid_info, + false, + 0, + Picture::RECORD_NORMALLY); + + scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue()); + + // Reconstruct the picture. + scoped_refptr<Picture> two_rect_picture_check = + Picture::CreateFromValue(serialized_two_rect.get()); + EXPECT_TRUE(!!two_rect_picture_check.get()); + + // Check for equivalence. + unsigned char two_rect_buffer[4 * 100 * 100] = {0}; + DrawPicture(two_rect_buffer, layer_rect, two_rect_picture); + unsigned char two_rect_buffer_check[4 * 100 * 100] = {0}; + DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check); + + EXPECT_EQ(two_rect_picture->LayerRect(), + two_rect_picture_check->LayerRect()); + EXPECT_EQ(two_rect_picture->OpaqueRect(), + two_rect_picture_check->OpaqueRect()); + EXPECT_TRUE(memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100) == + 0); + } } TEST(PictureTest, PixelRefIterator) { |