diff options
author | vmpstr <vmpstr@chromium.org> | 2015-09-24 13:57:54 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-24 21:09:54 +0000 |
commit | e22c50891decd8dd2456244645eec3d90b87a453 (patch) | |
tree | d6f1985dbe705082abd1070df9d0ef4fe2e98004 /cc/playback | |
parent | 59aae2ac2535dd7c1ac1634c771a7638d52030aa (diff) | |
download | chromium_src-e22c50891decd8dd2456244645eec3d90b87a453.zip chromium_src-e22c50891decd8dd2456244645eec3d90b87a453.tar.gz chromium_src-e22c50891decd8dd2456244645eec3d90b87a453.tar.bz2 |
cc: Remove Picture.
This patch removes the cc::Picture class, since the display list
approach is the only one supported now.
Depends on https://codereview.chromium.org/1362663002/
BUG=533151
R=danakj, enne
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1365673004
Cr-Commit-Position: refs/heads/master@{#350661}
Diffstat (limited to 'cc/playback')
-rw-r--r-- | cc/playback/discardable_image_map.cc | 11 | ||||
-rw-r--r-- | cc/playback/discardable_image_map.h | 7 | ||||
-rw-r--r-- | cc/playback/discardable_image_map_unittest.cc | 79 | ||||
-rw-r--r-- | cc/playback/display_item_list.cc | 1 | ||||
-rw-r--r-- | cc/playback/picture.cc | 342 | ||||
-rw-r--r-- | cc/playback/picture.h | 118 | ||||
-rw-r--r-- | cc/playback/picture_unittest.cc | 181 | ||||
-rw-r--r-- | cc/playback/raster_source.h | 2 |
8 files changed, 53 insertions, 688 deletions
diff --git a/cc/playback/discardable_image_map.cc b/cc/playback/discardable_image_map.cc index e115277..8fd7f44 100644 --- a/cc/playback/discardable_image_map.cc +++ b/cc/playback/discardable_image_map.cc @@ -9,9 +9,9 @@ #include "cc/base/math_util.h" #include "cc/playback/display_item_list.h" -#include "cc/playback/picture.h" #include "skia/ext/discardable_image_utils.h" #include "ui/gfx/geometry/rect_conversions.h" +#include "ui/gfx/skia_util.h" namespace cc { @@ -91,15 +91,6 @@ DiscardableImageMap::Iterator::Iterator() current_y_(0) {} DiscardableImageMap::Iterator::Iterator(const gfx::Rect& rect, - const Picture* picture) - : target_image_map_(&(picture->images_)), - current_images_(empty_images_.Pointer()), - current_index_(0) { - map_layer_rect_ = picture->layer_rect_; - PointToFirstImage(rect); -} - -DiscardableImageMap::Iterator::Iterator(const gfx::Rect& rect, const DisplayItemList* display_list) : target_image_map_(display_list->images_.get()), current_images_(empty_images_.Pointer()), diff --git a/cc/playback/discardable_image_map.h b/cc/playback/discardable_image_map.h index 68b8ac1..1e53011 100644 --- a/cc/playback/discardable_image_map.h +++ b/cc/playback/discardable_image_map.h @@ -21,16 +21,14 @@ class SkImage; namespace cc { -class Picture; class DisplayItemList; typedef std::pair<int, int> ImageMapKey; typedef std::vector<skia::PositionImage> Images; typedef base::hash_map<ImageMapKey, Images> ImageHashmap; -// This class is used and owned by cc Picture class. It is used to gather images -// which would happen after record. It takes in |cell_size| to decide how -// big each grid cell should be. +// This class is used to gather images which would happen after record. It takes +// in |cell_size| to decide how big each grid cell should be. class CC_EXPORT DiscardableImageMap { public: explicit DiscardableImageMap(const gfx::Size& cell_size); @@ -48,7 +46,6 @@ class CC_EXPORT DiscardableImageMap { // Default iterator constructor that is used as place holder for invalid // Iterator. Iterator(); - Iterator(const gfx::Rect& layer_rect, const Picture* picture); Iterator(const gfx::Rect& layer_rect, const DisplayItemList* picture); ~Iterator(); diff --git a/cc/playback/discardable_image_map_unittest.cc b/cc/playback/discardable_image_map_unittest.cc index 70061ea..3384987 100644 --- a/cc/playback/discardable_image_map_unittest.cc +++ b/cc/playback/discardable_image_map_unittest.cc @@ -7,8 +7,10 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/values.h" -#include "cc/playback/picture.h" +#include "cc/base/region.h" +#include "cc/playback/raster_source.h" #include "cc/test/fake_content_layer_client.h" +#include "cc/test/fake_display_list_recording_source.h" #include "cc/test/skia_common.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkGraphics.h" @@ -33,7 +35,7 @@ skia::RefPtr<SkImage> CreateDiscardableImage(const gfx::Size& size) { } TEST(DiscardableImageMapTest, DiscardableImageMapIterator) { - gfx::Rect layer_rect(2048, 2048); + gfx::Rect visible_rect(2048, 2048); gfx::Size tile_grid_size(512, 512); @@ -62,9 +64,13 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIterator) { } } - scoped_refptr<Picture> picture = - Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, - RecordingSource::RECORD_NORMALLY); + FakeDisplayListRecordingSource recording_source(tile_grid_size); + Region invalidation(visible_rect); + recording_source.SetGatherDiscardableImages(true); + recording_source.UpdateAndExpandInvalidation( + &content_layer_client, &invalidation, visible_rect.size(), visible_rect, + 1, RecordingSource::RECORD_NORMALLY); + DisplayItemList* display_list = recording_source.display_list(); // Default iterator does not have any pixel refs. { @@ -75,7 +81,7 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIterator) { for (int y = 0; y < 4; ++y) { for (int x = 0; x < 4; ++x) { DiscardableImageMap::Iterator iterator( - gfx::Rect(x * 512, y * 512, 500, 500), picture.get()); + gfx::Rect(x * 512, y * 512, 500, 500), display_list); if ((x + y) & 1) { EXPECT_TRUE(iterator) << x << " " << y; EXPECT_TRUE(iterator->image == discardable_image[y][x].get()) @@ -92,7 +98,7 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIterator) { // Capture 4 pixel refs. { DiscardableImageMap::Iterator iterator(gfx::Rect(512, 512, 2048, 2048), - picture.get()); + display_list); EXPECT_TRUE(iterator); EXPECT_TRUE(iterator->image == discardable_image[1][2].get()); EXPECT_EQ(gfx::RectF(2 * 512 + 6, 512 + 6, 500, 500).ToString(), @@ -115,7 +121,7 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIterator) { { // Copy test. DiscardableImageMap::Iterator iterator(gfx::Rect(512, 512, 2048, 2048), - picture.get()); + display_list); EXPECT_TRUE(iterator); EXPECT_TRUE(iterator->image == discardable_image[1][2].get()); EXPECT_EQ(gfx::RectF(2 * 512 + 6, 512 + 6, 500, 500).ToString(), @@ -155,7 +161,9 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIterator) { } TEST(DiscardableImageMapTest, DiscardableImageMapIteratorNonZeroLayer) { - gfx::Rect layer_rect(1024, 0, 2048, 2048); + gfx::Rect visible_rect(1024, 0, 2048, 2048); + // Make sure visible rect fits into the layer size. + gfx::Size layer_size(visible_rect.right(), visible_rect.bottom()); gfx::Size tile_grid_size(512, 512); @@ -184,9 +192,14 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIteratorNonZeroLayer) { } } - scoped_refptr<Picture> picture = - Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, - RecordingSource::RECORD_NORMALLY); + FakeDisplayListRecordingSource recording_source(tile_grid_size); + Region invalidation(visible_rect); + recording_source.set_pixel_record_distance(0); + recording_source.SetGatherDiscardableImages(true); + recording_source.UpdateAndExpandInvalidation( + &content_layer_client, &invalidation, layer_size, visible_rect, 1, + RecordingSource::RECORD_NORMALLY); + DisplayItemList* display_list = recording_source.display_list(); // Default iterator does not have any pixel refs. { @@ -197,7 +210,7 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIteratorNonZeroLayer) { for (int y = 0; y < 4; ++y) { for (int x = 0; x < 4; ++x) { DiscardableImageMap::Iterator iterator( - gfx::Rect(1024 + x * 512, y * 512, 500, 500), picture.get()); + gfx::Rect(1024 + x * 512, y * 512, 500, 500), display_list); if ((x + y) & 1) { EXPECT_TRUE(iterator) << x << " " << y; EXPECT_TRUE(iterator->image == discardable_image[y][x].get()); @@ -213,7 +226,7 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIteratorNonZeroLayer) { // Capture 4 pixel refs. { DiscardableImageMap::Iterator iterator( - gfx::Rect(1024 + 512, 512, 2048, 2048), picture.get()); + gfx::Rect(1024 + 512, 512, 2048, 2048), display_list); EXPECT_TRUE(iterator); EXPECT_TRUE(iterator->image == discardable_image[1][2].get()); EXPECT_EQ(gfx::RectF(1024 + 2 * 512 + 6, 512 + 6, 500, 500).ToString(), @@ -236,7 +249,7 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIteratorNonZeroLayer) { // Copy test. { DiscardableImageMap::Iterator iterator( - gfx::Rect(1024 + 512, 512, 2048, 2048), picture.get()); + gfx::Rect(1024 + 512, 512, 2048, 2048), display_list); EXPECT_TRUE(iterator); EXPECT_TRUE(iterator->image == discardable_image[1][2].get()); EXPECT_EQ(gfx::RectF(1024 + 2 * 512 + 6, 512 + 6, 500, 500).ToString(), @@ -277,28 +290,28 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIteratorNonZeroLayer) { // Non intersecting rects { DiscardableImageMap::Iterator iterator(gfx::Rect(0, 0, 1000, 1000), - picture.get()); + display_list); EXPECT_FALSE(iterator); } { DiscardableImageMap::Iterator iterator(gfx::Rect(3500, 0, 1000, 1000), - picture.get()); + display_list); EXPECT_FALSE(iterator); } { DiscardableImageMap::Iterator iterator(gfx::Rect(0, 1100, 1000, 1000), - picture.get()); + display_list); EXPECT_FALSE(iterator); } { DiscardableImageMap::Iterator iterator(gfx::Rect(3500, 1100, 1000, 1000), - picture.get()); + display_list); EXPECT_FALSE(iterator); } } TEST(DiscardableImageMapTest, DiscardableImageMapIteratorOnePixelQuery) { - gfx::Rect layer_rect(2048, 2048); + gfx::Rect visible_rect(2048, 2048); gfx::Size tile_grid_size(512, 512); @@ -327,9 +340,13 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIteratorOnePixelQuery) { } } - scoped_refptr<Picture> picture = - Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, - RecordingSource::RECORD_NORMALLY); + FakeDisplayListRecordingSource recording_source(tile_grid_size); + Region invalidation(visible_rect); + recording_source.SetGatherDiscardableImages(true); + recording_source.UpdateAndExpandInvalidation( + &content_layer_client, &invalidation, visible_rect.size(), visible_rect, + 1, RecordingSource::RECORD_NORMALLY); + DisplayItemList* display_list = recording_source.display_list(); // Default iterator does not have any pixel refs. { @@ -340,7 +357,7 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIteratorOnePixelQuery) { for (int y = 0; y < 4; ++y) { for (int x = 0; x < 4; ++x) { DiscardableImageMap::Iterator iterator( - gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); + gfx::Rect(x * 512, y * 512 + 256, 1, 1), display_list); if ((x + y) & 1) { EXPECT_TRUE(iterator) << x << " " << y; EXPECT_TRUE(iterator->image == discardable_image[y][x].get()); @@ -355,7 +372,7 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIteratorOnePixelQuery) { } TEST(DiscardableImageMapTest, DiscardableImageMapIteratorMassiveImage) { - gfx::Rect layer_rect(2048, 2048); + gfx::Rect visible_rect(2048, 2048); gfx::Size tile_grid_size(512, 512); FakeContentLayerClient content_layer_client; @@ -365,11 +382,15 @@ TEST(DiscardableImageMapTest, DiscardableImageMapIteratorMassiveImage) { content_layer_client.add_draw_image(discardable_image.get(), gfx::Point(0, 0), paint); - scoped_refptr<Picture> picture = - Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, - RecordingSource::RECORD_NORMALLY); + FakeDisplayListRecordingSource recording_source(tile_grid_size); + Region invalidation(visible_rect); + recording_source.SetGatherDiscardableImages(true); + recording_source.UpdateAndExpandInvalidation( + &content_layer_client, &invalidation, visible_rect.size(), visible_rect, + 1, RecordingSource::RECORD_NORMALLY); + DisplayItemList* display_list = recording_source.display_list(); - DiscardableImageMap::Iterator iterator(gfx::Rect(0, 0, 1, 1), picture.get()); + DiscardableImageMap::Iterator iterator(gfx::Rect(0, 0, 1, 1), display_list); EXPECT_TRUE(iterator); EXPECT_TRUE(iterator->image == discardable_image.get()); EXPECT_EQ(gfx::RectF(0, 0, 1 << 25, 1 << 25).ToString(), diff --git a/cc/playback/display_item_list.cc b/cc/playback/display_item_list.cc index 88f4909..ce6b324 100644 --- a/cc/playback/display_item_list.cc +++ b/cc/playback/display_item_list.cc @@ -12,7 +12,6 @@ #include "cc/base/math_util.h" #include "cc/debug/picture_debug_util.h" #include "cc/debug/traced_display_item_list.h" -#include "cc/debug/traced_picture.h" #include "cc/debug/traced_value.h" #include "cc/playback/display_item_list_settings.h" #include "cc/playback/largest_display_item.h" diff --git a/cc/playback/picture.cc b/cc/playback/picture.cc deleted file mode 100644 index 102e076..0000000 --- a/cc/playback/picture.cc +++ /dev/null @@ -1,342 +0,0 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "cc/playback/picture.h" - -#include <set> -#include <string> - -#include "base/base64.h" -#include "base/trace_event/trace_event.h" -#include "base/trace_event/trace_event_argument.h" -#include "base/values.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 "cc/layers/content_layer_client.h" -#include "skia/ext/discardable_image_utils.h" -#include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/core/SkPaint.h" -#include "third_party/skia/include/core/SkPictureRecorder.h" -#include "third_party/skia/include/core/SkStream.h" -#include "third_party/skia/include/utils/SkNullCanvas.h" -#include "third_party/skia/include/utils/SkPictureUtils.h" -#include "ui/gfx/codec/jpeg_codec.h" -#include "ui/gfx/codec/png_codec.h" -#include "ui/gfx/geometry/rect_conversions.h" -#include "ui/gfx/skia_util.h" - -namespace cc { - -namespace { - -// We don't perform per-layer solid color analysis when there are too many skia -// operations. -const int kOpCountThatIsOkToAnalyze = 10; - -bool DecodeBitmap(const void* buffer, size_t size, SkBitmap* bm) { - const unsigned char* data = static_cast<const unsigned char *>(buffer); - - // Try PNG first. - if (gfx::PNGCodec::Decode(data, size, bm)) - return true; - - // Try JPEG. - scoped_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodec::Decode(data, size)); - if (decoded_jpeg) { - *bm = *decoded_jpeg; - return true; - } - return false; -} - -} // namespace - -scoped_refptr<Picture> Picture::Create( - const gfx::Rect& layer_rect, - ContentLayerClient* client, - const gfx::Size& tile_grid_size, - bool gather_discardable_images, - RecordingSource::RecordingMode recording_mode) { - scoped_refptr<Picture> picture = - make_scoped_refptr(new Picture(layer_rect, tile_grid_size)); - - picture->Record(client, recording_mode); - if (gather_discardable_images) - picture->GatherDiscardableImages(); - - return picture; -} - -Picture::Picture(const gfx::Rect& layer_rect, const gfx::Size& tile_grid_size) - : layer_rect_(layer_rect), images_(tile_grid_size) { - // Instead of recording a trace event for object creation here, we wait for - // the picture to be recorded in Picture::Record. -} - -scoped_refptr<Picture> Picture::CreateFromSkpValue(const base::Value* value) { - // Decode the picture from base64. - std::string encoded; - if (!value->GetAsString(&encoded)) - return NULL; - - std::string decoded; - base::Base64Decode(encoded, &decoded); - SkMemoryStream stream(decoded.data(), decoded.size()); - - // Read the picture. This creates an empty picture on failure. - SkPicture* skpicture = SkPicture::CreateFromStream(&stream, &DecodeBitmap); - if (skpicture == NULL) - return NULL; - - gfx::Rect layer_rect(gfx::SkIRectToRect(skpicture->cullRect().roundOut())); - return make_scoped_refptr(new Picture(skpicture, layer_rect)); -} - -scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* raw_value) { - const base::DictionaryValue* value = NULL; - if (!raw_value->GetAsDictionary(&value)) - return NULL; - - // Decode the picture from base64. - std::string encoded; - if (!value->GetString("skp64", &encoded)) - return NULL; - - std::string decoded; - base::Base64Decode(encoded, &decoded); - SkMemoryStream stream(decoded.data(), decoded.size()); - - const base::Value* layer_rect_value = NULL; - if (!value->Get("params.layer_rect", &layer_rect_value)) - return NULL; - - gfx::Rect layer_rect; - if (!MathUtil::FromValue(layer_rect_value, &layer_rect)) - return NULL; - - // Read the picture. This creates an empty picture on failure. - SkPicture* skpicture = SkPicture::CreateFromStream(&stream, &DecodeBitmap); - if (skpicture == NULL) - return NULL; - - return make_scoped_refptr(new Picture(skpicture, layer_rect)); -} - -Picture::Picture(SkPicture* picture, const gfx::Rect& layer_rect) - : layer_rect_(layer_rect), - picture_(skia::AdoptRef(picture)), - images_(layer_rect.size()) {} - -Picture::Picture(const skia::RefPtr<SkPicture>& picture, - const gfx::Rect& layer_rect, - const DiscardableImageMap& images) - : layer_rect_(layer_rect), picture_(picture), images_(images) {} - -Picture::~Picture() { - TRACE_EVENT_OBJECT_DELETED_WITH_ID( - TRACE_DISABLED_BY_DEFAULT("cc.debug.picture"), "cc::Picture", this); -} - -bool Picture::IsSuitableForGpuRasterization(const char** reason) const { - DCHECK(picture_); - - // TODO(hendrikw): SkPicture::suitableForGpuRasterization takes a GrContext. - // Currently the GrContext isn't used, and should probably be removed from - // skia. - return picture_->suitableForGpuRasterization(nullptr, reason); -} - -int Picture::ApproximateOpCount() const { - DCHECK(picture_); - return picture_->approximateOpCount(); -} - -size_t Picture::ApproximateMemoryUsage() const { - DCHECK(picture_); - return SkPictureUtils::ApproximateBytesUsed(picture_.get()); -} - -bool Picture::ShouldBeAnalyzedForSolidColor() const { - return ApproximateOpCount() <= kOpCountThatIsOkToAnalyze; -} - -bool Picture::HasText() const { - DCHECK(picture_); - return picture_->hasText(); -} - -void Picture::Record(ContentLayerClient* painter, - RecordingSource::RecordingMode recording_mode) { - TRACE_EVENT2("cc", - "Picture::Record", - "data", - AsTraceableRecordData(), - "recording_mode", - recording_mode); - - DCHECK(!picture_); - - SkRTreeFactory factory; - SkPictureRecorder recorder; - - skia::RefPtr<SkCanvas> canvas; - canvas = skia::SharePtr(recorder.beginRecording( - layer_rect_.width(), layer_rect_.height(), &factory, - SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); - - ContentLayerClient::PaintingControlSetting painting_control = - ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; - - switch (recording_mode) { - case RecordingSource::RECORD_NORMALLY: - // Already setup for normal recording. - break; - case RecordingSource::RECORD_WITH_SK_NULL_CANVAS: - canvas = skia::AdoptRef(SkCreateNullCanvas()); - break; - case RecordingSource::RECORD_WITH_PAINTING_DISABLED: - // We pass a disable flag through the paint calls when perfromance - // testing (the only time this case should ever arise) when we want to - // prevent the Blink GraphicsContext object from consuming any compute - // time. - canvas = skia::AdoptRef(SkCreateNullCanvas()); - painting_control = ContentLayerClient::DISPLAY_LIST_PAINTING_DISABLED; - break; - case RecordingSource::RECORD_WITH_CACHING_DISABLED: - // This mode should give the same results as RECORD_NORMALLY. - painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED; - break; - default: - // case RecordingSource::RECORD_WITH_CONSTRUCTION_DISABLED should - // not be reached - NOTREACHED(); - } - - canvas->save(); - canvas->translate(SkFloatToScalar(-layer_rect_.x()), - SkFloatToScalar(-layer_rect_.y())); - - canvas->clipRect(gfx::RectToSkRect(layer_rect_)); - - painter->PaintContents(canvas.get(), layer_rect_, painting_control); - - canvas->restore(); - picture_ = skia::AdoptRef(recorder.endRecordingAsPicture()); - DCHECK(picture_); - - EmitTraceSnapshot(); -} - -void Picture::GatherDiscardableImages() { - TRACE_EVENT2("cc", "Picture::GatherDiscardableImages", "width", - layer_rect_.width(), "height", layer_rect_.height()); - - DCHECK(picture_); - DCHECK(images_.empty()); - if (!WillPlayBackBitmaps()) - return; - - images_.GatherImagesFromPicture(picture_.get(), layer_rect_); -} - -int Picture::Raster(SkCanvas* canvas, - SkPicture::AbortCallback* callback, - const Region& negated_content_region, - float contents_scale) const { - TRACE_EVENT_BEGIN1( - "cc", - "Picture::Raster", - "data", - AsTraceableRasterData(contents_scale)); - - DCHECK(picture_); - - canvas->save(); - - for (Region::Iterator it(negated_content_region); it.has_rect(); it.next()) - canvas->clipRect(gfx::RectToSkRect(it.rect()), SkRegion::kDifference_Op); - - 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()); - } - SkIRect bounds; - canvas->getClipDeviceBounds(&bounds); - canvas->restore(); - TRACE_EVENT_END1("cc", "Picture::Raster", "num_pixels_rasterized", - bounds.width() * bounds.height()); - return bounds.width() * bounds.height(); -} - -void Picture::Replay(SkCanvas* canvas, SkPicture::AbortCallback* callback) { - TRACE_EVENT_BEGIN0("cc", "Picture::Replay"); - DCHECK(picture_); - picture_->playback(canvas, callback); - SkIRect bounds; - canvas->getClipDeviceBounds(&bounds); - TRACE_EVENT_END1("cc", "Picture::Replay", "num_pixels_replayed", - bounds.width() * bounds.height()); -} - -scoped_ptr<base::Value> Picture::AsValue() const { - // Encode the picture as base64. - scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); - res->Set("params.layer_rect", MathUtil::AsValue(layer_rect_).release()); - std::string b64_picture; - PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); - res->SetString("skp64", b64_picture); - return res.Pass(); -} - -void Picture::EmitTraceSnapshot() const { - TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( - TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") "," - TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"), - "cc::Picture", - this, - TracedPicture::AsTraceablePicture(this)); -} - -void Picture::EmitTraceSnapshotAlias(Picture* original) const { - TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( - TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") "," - TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"), - "cc::Picture", - this, - TracedPicture::AsTraceablePictureAlias(original)); -} - -DiscardableImageMap::Iterator Picture::GetDiscardableImageMapIterator( - const gfx::Rect& layer_rect) const { - return DiscardableImageMap::Iterator(layer_rect, this); -} - -scoped_refptr<base::trace_event::ConvertableToTraceFormat> - Picture::AsTraceableRasterData(float scale) const { - scoped_refptr<base::trace_event::TracedValue> raster_data = - new base::trace_event::TracedValue(); - TracedValue::SetIDRef(this, raster_data.get(), "picture_id"); - raster_data->SetDouble("scale", scale); - return raster_data; -} - -scoped_refptr<base::trace_event::ConvertableToTraceFormat> - Picture::AsTraceableRecordData() const { - scoped_refptr<base::trace_event::TracedValue> record_data = - new base::trace_event::TracedValue(); - TracedValue::SetIDRef(this, record_data.get(), "picture_id"); - MathUtil::AddToTracedValue("layer_rect", layer_rect_, record_data.get()); - return record_data; -} - -} // namespace cc diff --git a/cc/playback/picture.h b/cc/playback/picture.h deleted file mode 100644 index 4cb3367..0000000 --- a/cc/playback/picture.h +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CC_PLAYBACK_PICTURE_H_ -#define CC_PLAYBACK_PICTURE_H_ - -#include "base/basictypes.h" -#include "base/containers/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/logging.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/trace_event/trace_event.h" -#include "cc/base/cc_export.h" -#include "cc/base/region.h" -#include "cc/playback/discardable_image_map.h" -#include "cc/playback/recording_source.h" -#include "skia/ext/refptr.h" -#include "third_party/skia/include/core/SkPicture.h" -#include "ui/gfx/geometry/rect.h" - -namespace base { -class Value; -} - -namespace skia { -class AnalysisCanvas; -} - -namespace cc { - -class ContentLayerClient; - -class CC_EXPORT Picture - : public base::RefCountedThreadSafe<Picture> { - public: - static scoped_refptr<Picture> Create( - const gfx::Rect& layer_rect, - ContentLayerClient* client, - const gfx::Size& tile_grid_size, - bool gather_discardable_images, - RecordingSource::RecordingMode recording_mode); - static scoped_refptr<Picture> CreateFromValue(const base::Value* value); - static scoped_refptr<Picture> CreateFromSkpValue(const base::Value* value); - - gfx::Rect LayerRect() const { return layer_rect_; } - - // Has Record() been called yet? - bool HasRecording() const { return picture_.get() != NULL; } - - bool IsSuitableForGpuRasterization(const char** reason) const; - int ApproximateOpCount() const; - size_t ApproximateMemoryUsage() const; - bool ShouldBeAnalyzedForSolidColor() const; - - bool HasText() const; - - // 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, - SkPicture::AbortCallback* callback, - const Region& negated_content_region, - float contents_scale) const; - - // Draw the picture directly into the given canvas, without applying any - // clip/scale/layer transformations. - void Replay(SkCanvas* canvas, SkPicture::AbortCallback* callback = NULL); - - scoped_ptr<base::Value> AsValue() const; - - void EmitTraceSnapshot() const; - void EmitTraceSnapshotAlias(Picture* original) const; - - bool WillPlayBackBitmaps() const { return picture_->willPlayBackBitmaps(); } - - DiscardableImageMap::Iterator GetDiscardableImageMapIterator( - const gfx::Rect& layer_rect) const; - - private: - Picture(const gfx::Rect& layer_rect, const gfx::Size& tile_grid_size); - // This constructor assumes SkPicture is already ref'd and transfers - // ownership to this picture. - Picture(const skia::RefPtr<SkPicture>&, - const gfx::Rect& layer_rect, - const DiscardableImageMap& images); - // This constructor will call AdoptRef on the SkPicture. - Picture(SkPicture*, const gfx::Rect& layer_rect); - ~Picture(); - - // Record a paint operation. To be able to safely use this SkPicture for - // playback on a different thread this can only be called once. - void Record(ContentLayerClient* client, - RecordingSource::RecordingMode recording_mode); - - // Gather discardable images from recording. - void GatherDiscardableImages(); - - gfx::Rect layer_rect_; - skia::RefPtr<SkPicture> picture_; - - DiscardableImageMap images_; - - scoped_refptr<base::trace_event::ConvertableToTraceFormat> - AsTraceableRasterData(float scale) const; - scoped_refptr<base::trace_event::ConvertableToTraceFormat> - AsTraceableRecordData() const; - - friend class base::RefCountedThreadSafe<Picture>; - friend class DiscardableImageMap::Iterator; - DISALLOW_COPY_AND_ASSIGN(Picture); -}; - -} // namespace cc - -#endif // CC_PLAYBACK_PICTURE_H_ diff --git a/cc/playback/picture_unittest.cc b/cc/playback/picture_unittest.cc deleted file mode 100644 index 53310e3..0000000 --- a/cc/playback/picture_unittest.cc +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "cc/playback/picture.h" - -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/values.h" -#include "cc/test/fake_content_layer_client.h" -#include "cc/test/skia_common.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/skia/include/core/SkGraphics.h" -#include "ui/gfx/geometry/rect.h" -#include "ui/gfx/skia_util.h" - -namespace cc { -namespace { - -TEST(PictureTest, AsBase64String) { - SkGraphics::Init(); - - gfx::Rect layer_rect(100, 100); - - gfx::Size tile_grid_size(100, 100); - - FakeContentLayerClient content_layer_client; - - scoped_ptr<base::Value> tmp; - - SkPaint red_paint; - red_paint.setColor(SkColorSetARGB(255, 255, 0, 0)); - SkPaint green_paint; - green_paint.setColor(SkColorSetARGB(255, 0, 255, 0)); - - // Invalid picture (not a dict). - tmp.reset(new base::StringValue("abc!@#$%")); - scoped_refptr<Picture> invalid_picture = - Picture::CreateFromValue(tmp.get()); - EXPECT_FALSE(invalid_picture.get()); - - // 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_size, false, - RecordingSource::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); - - // 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(0, memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100)); - - // 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_size, false, - RecordingSource::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); - - // 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(0, memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100)); -} - -TEST(PictureTest, CreateFromSkpValue) { - SkGraphics::Init(); - - gfx::Rect layer_rect(100, 200); - - gfx::Size tile_grid_size(100, 200); - - FakeContentLayerClient content_layer_client; - - scoped_ptr<base::Value> tmp; - - SkPaint red_paint; - red_paint.setColor(SkColorSetARGB(255, 255, 0, 0)); - SkPaint green_paint; - green_paint.setColor(SkColorSetARGB(255, 0, 255, 0)); - - // Invalid picture (not a dict). - tmp.reset(new base::StringValue("abc!@#$%")); - scoped_refptr<Picture> invalid_picture = - Picture::CreateFromSkpValue(tmp.get()); - EXPECT_TRUE(!invalid_picture.get()); - - // 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_size, false, - RecordingSource::RECORD_NORMALLY); - scoped_ptr<base::Value> serialized_one_rect( - one_rect_picture->AsValue()); - - const base::DictionaryValue* value = NULL; - EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value)); - - // Decode the picture from base64. - const base::Value* skp_value; - EXPECT_TRUE(value->Get("skp64", &skp_value)); - - // Reconstruct the picture. - scoped_refptr<Picture> one_rect_picture_check = - Picture::CreateFromSkpValue(skp_value); - EXPECT_TRUE(one_rect_picture_check); - - EXPECT_EQ(100, one_rect_picture_check->LayerRect().width()); - EXPECT_EQ(200, one_rect_picture_check->LayerRect().height()); -} - -TEST(PictureTest, RecordingModes) { - SkGraphics::Init(); - - gfx::Rect layer_rect(100, 200); - - gfx::Size tile_grid_size(100, 200); - - FakeContentLayerClient content_layer_client; - EXPECT_EQ(NULL, content_layer_client.last_canvas()); - - scoped_refptr<Picture> picture = - Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, - RecordingSource::RECORD_NORMALLY); - EXPECT_TRUE(content_layer_client.last_canvas() != NULL); - EXPECT_EQ(ContentLayerClient::PAINTING_BEHAVIOR_NORMAL, - content_layer_client.last_painting_control()); - EXPECT_TRUE(picture.get()); - - picture = Picture::Create(layer_rect, &content_layer_client, tile_grid_size, - false, RecordingSource::RECORD_WITH_SK_NULL_CANVAS); - EXPECT_TRUE(content_layer_client.last_canvas() != NULL); - EXPECT_EQ(ContentLayerClient::PAINTING_BEHAVIOR_NORMAL, - content_layer_client.last_painting_control()); - EXPECT_TRUE(picture.get()); - - picture = - Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, - RecordingSource::RECORD_WITH_PAINTING_DISABLED); - EXPECT_TRUE(content_layer_client.last_canvas() != NULL); - EXPECT_EQ(ContentLayerClient::DISPLAY_LIST_PAINTING_DISABLED, - content_layer_client.last_painting_control()); - EXPECT_TRUE(picture.get()); - - picture = - Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, - RecordingSource::RECORD_WITH_CACHING_DISABLED); - EXPECT_TRUE(content_layer_client.last_canvas() != NULL); - EXPECT_EQ(ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED, - content_layer_client.last_painting_control()); - EXPECT_TRUE(picture.get()); - - // RECORD_WITH_CONSTRUCTION_DISABLED is not supported for Picture. - - EXPECT_EQ(5, RecordingSource::RECORDING_MODE_COUNT); -} - -} // namespace -} // namespace cc diff --git a/cc/playback/raster_source.h b/cc/playback/raster_source.h index a9bbcf1..e34f064 100644 --- a/cc/playback/raster_source.h +++ b/cc/playback/raster_source.h @@ -21,8 +21,6 @@ class SkPicture; namespace cc { -class Picture; - class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> { public: struct CC_EXPORT SolidColorAnalysis { |