diff options
Diffstat (limited to 'cc')
-rw-r--r-- | cc/BUILD.gn | 7 | ||||
-rw-r--r-- | cc/cc.gyp | 6 | ||||
-rw-r--r-- | cc/cc_tests.gyp | 1 | ||||
-rw-r--r-- | cc/debug/micro_benchmark_controller.cc | 3 | ||||
-rw-r--r-- | cc/debug/picture_record_benchmark.cc | 119 | ||||
-rw-r--r-- | cc/debug/picture_record_benchmark.h | 37 | ||||
-rw-r--r-- | cc/debug/rasterize_and_record_benchmark.h | 3 | ||||
-rw-r--r-- | cc/debug/traced_picture.cc | 56 | ||||
-rw-r--r-- | cc/debug/traced_picture.h | 42 | ||||
-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 | ||||
-rw-r--r-- | cc/test/fake_display_list_recording_source.h | 5 | ||||
-rw-r--r-- | cc/test/skia_common.cc | 15 | ||||
-rw-r--r-- | cc/test/skia_common.h | 5 |
20 files changed, 60 insertions, 980 deletions
diff --git a/cc/BUILD.gn b/cc/BUILD.gn index 8fcf7fc..96fc142 100644 --- a/cc/BUILD.gn +++ b/cc/BUILD.gn @@ -77,8 +77,6 @@ component("cc") { "debug/micro_benchmark_impl.h", "debug/picture_debug_util.cc", "debug/picture_debug_util.h", - "debug/picture_record_benchmark.cc", - "debug/picture_record_benchmark.h", "debug/rasterize_and_record_benchmark.cc", "debug/rasterize_and_record_benchmark.h", "debug/rasterize_and_record_benchmark_impl.cc", @@ -90,8 +88,6 @@ component("cc") { "debug/ring_buffer.h", "debug/traced_display_item_list.cc", "debug/traced_display_item_list.h", - "debug/traced_picture.cc", - "debug/traced_picture.h", "debug/traced_value.cc", "debug/traced_value.h", "debug/unittest_only_benchmark.cc", @@ -308,8 +304,6 @@ component("cc") { "playback/float_clip_display_item.h", "playback/largest_display_item.cc", "playback/largest_display_item.h", - "playback/picture.cc", - "playback/picture.h", "playback/raster_source.h", "playback/raster_source_helper.cc", "playback/raster_source_helper.h", @@ -781,7 +775,6 @@ test("cc_unittests") { "playback/display_item_list_unittest.cc", "playback/display_list_raster_source_unittest.cc", "playback/display_list_recording_source_unittest.cc", - "playback/picture_unittest.cc", "quads/draw_polygon_unittest.cc", "quads/draw_quad_unittest.cc", "quads/render_pass_unittest.cc", @@ -137,8 +137,6 @@ 'debug/micro_benchmark_impl.h', 'debug/picture_debug_util.cc', 'debug/picture_debug_util.h', - 'debug/picture_record_benchmark.cc', - 'debug/picture_record_benchmark.h', 'debug/rasterize_and_record_benchmark.cc', 'debug/rasterize_and_record_benchmark.h', 'debug/rasterize_and_record_benchmark_impl.cc', @@ -150,8 +148,6 @@ 'debug/ring_buffer.h', 'debug/traced_display_item_list.cc', 'debug/traced_display_item_list.h', - 'debug/traced_picture.cc', - 'debug/traced_picture.h', 'debug/traced_value.cc', 'debug/traced_value.h', 'debug/unittest_only_benchmark.cc', @@ -368,8 +364,6 @@ 'playback/float_clip_display_item.h', 'playback/largest_display_item.cc', 'playback/largest_display_item.h', - 'playback/picture.cc', - 'playback/picture.h', 'playback/raster_source.h', 'playback/raster_source_helper.cc', 'playback/raster_source_helper.h', diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp index e85d590..419f68c 100644 --- a/cc/cc_tests.gyp +++ b/cc/cc_tests.gyp @@ -84,7 +84,6 @@ 'playback/display_item_list_unittest.cc', 'playback/display_list_raster_source_unittest.cc', 'playback/display_list_recording_source_unittest.cc', - 'playback/picture_unittest.cc', 'quads/draw_polygon_unittest.cc', 'quads/draw_quad_unittest.cc', 'quads/render_pass_unittest.cc', diff --git a/cc/debug/micro_benchmark_controller.cc b/cc/debug/micro_benchmark_controller.cc index a38e5ad..a0dc306 100644 --- a/cc/debug/micro_benchmark_controller.cc +++ b/cc/debug/micro_benchmark_controller.cc @@ -11,7 +11,6 @@ #include "base/thread_task_runner_handle.h" #include "base/values.h" #include "cc/debug/invalidation_benchmark.h" -#include "cc/debug/picture_record_benchmark.h" #include "cc/debug/rasterize_and_record_benchmark.h" #include "cc/debug/unittest_only_benchmark.h" #include "cc/trees/layer_tree_host.h" @@ -29,8 +28,6 @@ scoped_ptr<MicroBenchmark> CreateBenchmark( const MicroBenchmark::DoneCallback& callback) { if (name == "invalidation_benchmark") { return make_scoped_ptr(new InvalidationBenchmark(value.Pass(), callback)); - } else if (name == "picture_record_benchmark") { - return make_scoped_ptr(new PictureRecordBenchmark(value.Pass(), callback)); } else if (name == "rasterize_and_record_benchmark") { return make_scoped_ptr( new RasterizeAndRecordBenchmark(value.Pass(), callback)); diff --git a/cc/debug/picture_record_benchmark.cc b/cc/debug/picture_record_benchmark.cc deleted file mode 100644 index 0f093ce..0000000 --- a/cc/debug/picture_record_benchmark.cc +++ /dev/null @@ -1,119 +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/debug/picture_record_benchmark.h" - -#include <algorithm> - -#include "base/basictypes.h" -#include "base/values.h" -#include "cc/layers/layer.h" -#include "cc/layers/picture_layer.h" -#include "cc/playback/picture.h" -#include "cc/trees/layer_tree_host.h" -#include "cc/trees/layer_tree_host_common.h" -#include "ui/gfx/geometry/rect.h" - -namespace cc { - -namespace { - -const int kPositionIncrement = 100; -const int kTileGridSize = 512; - -} // namespace - -PictureRecordBenchmark::PictureRecordBenchmark( - scoped_ptr<base::Value> value, - const MicroBenchmark::DoneCallback& callback) - : MicroBenchmark(callback) { - if (!value) - return; - - base::ListValue* list = nullptr; - value->GetAsList(&list); - if (!list) - return; - - for (base::ListValue::iterator it = list->begin(); it != list->end(); ++it) { - base::DictionaryValue* dictionary = nullptr; - (*it)->GetAsDictionary(&dictionary); - if (!dictionary || - !dictionary->HasKey("width") || - !dictionary->HasKey("height")) - continue; - - int width, height; - dictionary->GetInteger("width", &width); - dictionary->GetInteger("height", &height); - - dimensions_.push_back(std::make_pair(width, height)); - } -} - -PictureRecordBenchmark::~PictureRecordBenchmark() {} - -void PictureRecordBenchmark::DidUpdateLayers(LayerTreeHost* host) { - LayerTreeHostCommon::CallFunctionForSubtree( - host->root_layer(), - [this](Layer* layer) { layer->RunMicroBenchmark(this); }); - - scoped_ptr<base::ListValue> results(new base::ListValue()); - for (std::map<std::pair<int, int>, TotalTime>::iterator it = times_.begin(); - it != times_.end(); - ++it) { - std::pair<int, int> dimensions = it->first; - base::TimeDelta total_time = it->second.first; - unsigned total_count = it->second.second; - - double average_time = 0.0; - if (total_count > 0) - average_time = total_time.InMillisecondsF() / total_count; - - scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); - result->SetInteger("width", dimensions.first); - result->SetInteger("height", dimensions.second); - result->SetInteger("samples_count", total_count); - result->SetDouble("time_ms", average_time); - - results->Append(result.release()); - } - - NotifyDone(results.Pass()); -} - -void PictureRecordBenchmark::RunOnLayer(PictureLayer* layer) { - ContentLayerClient* painter = layer->client(); - gfx::Size bounds = layer->bounds(); - - gfx::Size tile_grid_size(kTileGridSize, kTileGridSize); - - for (size_t i = 0; i < dimensions_.size(); ++i) { - std::pair<int, int> dimensions = dimensions_[i]; - int width = dimensions.first; - int height = dimensions.second; - - int y_limit = std::max(1, bounds.height() - height); - int x_limit = std::max(1, bounds.width() - width); - for (int y = 0; y < y_limit; y += kPositionIncrement) { - for (int x = 0; x < x_limit; x += kPositionIncrement) { - gfx::Rect rect = gfx::Rect(x, y, width, height); - - base::TimeTicks start = base::TimeTicks::Now(); - - scoped_refptr<Picture> picture = - Picture::Create(rect, painter, tile_grid_size, false, - RecordingSource::RECORD_NORMALLY); - - base::TimeTicks end = base::TimeTicks::Now(); - base::TimeDelta duration = end - start; - TotalTime& total_time = times_[dimensions]; - total_time.first += duration; - total_time.second++; - } - } - } -} - -} // namespace cc diff --git a/cc/debug/picture_record_benchmark.h b/cc/debug/picture_record_benchmark.h deleted file mode 100644 index 3710d83..0000000 --- a/cc/debug/picture_record_benchmark.h +++ /dev/null @@ -1,37 +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. - -#ifndef CC_DEBUG_PICTURE_RECORD_BENCHMARK_H_ -#define CC_DEBUG_PICTURE_RECORD_BENCHMARK_H_ - -#include <map> -#include <utility> -#include <vector> - -#include "base/time/time.h" -#include "cc/debug/micro_benchmark_controller.h" - -namespace cc { - -class LayerTreeHost; -class Layer; -class CC_EXPORT PictureRecordBenchmark : public MicroBenchmark { - public: - explicit PictureRecordBenchmark(scoped_ptr<base::Value> value, - const MicroBenchmark::DoneCallback& callback); - ~PictureRecordBenchmark() override; - - // Implements MicroBenchmark interface. - void DidUpdateLayers(LayerTreeHost* host) override; - void RunOnLayer(PictureLayer* layer) override; - - private: - typedef std::pair<base::TimeDelta, unsigned> TotalTime; - std::map<std::pair<int, int>, TotalTime> times_; - std::vector<std::pair<int, int>> dimensions_; -}; - -} // namespace cc - -#endif // CC_DEBUG_PICTURE_RECORD_BENCHMARK_H_ diff --git a/cc/debug/rasterize_and_record_benchmark.h b/cc/debug/rasterize_and_record_benchmark.h index 3e873ce..97cecb1 100644 --- a/cc/debug/rasterize_and_record_benchmark.h +++ b/cc/debug/rasterize_and_record_benchmark.h @@ -13,7 +13,8 @@ #include "base/single_thread_task_runner.h" #include "base/time/time.h" #include "cc/debug/micro_benchmark_controller.h" -#include "cc/playback/picture.h" +#include "cc/playback/recording_source.h" +#include "ui/gfx/geometry/rect.h" namespace base { class DictionaryValue; diff --git a/cc/debug/traced_picture.cc b/cc/debug/traced_picture.cc deleted file mode 100644 index 3241871..0000000 --- a/cc/debug/traced_picture.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 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/debug/traced_picture.h" - -#include "base/json/json_writer.h" -#include "base/strings/stringprintf.h" -#include "base/values.h" - -namespace cc { - -TracedPicture::TracedPicture(scoped_refptr<const Picture> picture) - : picture_(picture), is_alias_(false) {} - -TracedPicture::~TracedPicture() { -} - -scoped_refptr<base::trace_event::ConvertableToTraceFormat> -TracedPicture::AsTraceablePicture(const Picture* picture) { - return scoped_refptr<base::trace_event::ConvertableToTraceFormat>( - new TracedPicture(picture)); -} - -scoped_refptr<base::trace_event::ConvertableToTraceFormat> -TracedPicture::AsTraceablePictureAlias(const Picture* original) { - scoped_refptr<TracedPicture> ptr = new TracedPicture(original); - ptr->is_alias_ = true; - return scoped_refptr<base::trace_event::ConvertableToTraceFormat>(ptr); -} - -void TracedPicture::AppendAsTraceFormat(std::string* out) const { - if (is_alias_) - AppendPictureAlias(out); - else - AppendPicture(out); -} - -void TracedPicture::AppendPictureAlias(std::string* out) const { - scoped_ptr<base::DictionaryValue> alias(new base::DictionaryValue()); - alias->SetString("id_ref", base::StringPrintf("%p", picture_.get())); - - base::DictionaryValue res; - res.Set("alias", alias.release()); - std::string tmp; - base::JSONWriter::Write(res, &tmp); - out->append(tmp); -} - -void TracedPicture::AppendPicture(std::string* out) const { - std::string tmp; - base::JSONWriter::Write(*picture_->AsValue(), &tmp); - out->append(tmp); -} - -} // namespace cc diff --git a/cc/debug/traced_picture.h b/cc/debug/traced_picture.h deleted file mode 100644 index 0cb044e..0000000 --- a/cc/debug/traced_picture.h +++ /dev/null @@ -1,42 +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. - -#ifndef CC_DEBUG_TRACED_PICTURE_H_ -#define CC_DEBUG_TRACED_PICTURE_H_ - -#include <string> - -#include "base/memory/scoped_ptr.h" -#include "base/trace_event/trace_event.h" -#include "cc/playback/picture.h" - -namespace cc { - -class TracedPicture : public base::trace_event::ConvertableToTraceFormat { - public: - explicit TracedPicture(scoped_refptr<const Picture>); - - static scoped_refptr<base::trace_event::ConvertableToTraceFormat> - AsTraceablePicture(const Picture* picture); - - static scoped_refptr<base::trace_event::ConvertableToTraceFormat> - AsTraceablePictureAlias(const Picture* original); - - void AppendAsTraceFormat(std::string* out) const override; - - private: - ~TracedPicture() override; - - void AppendPicture(std::string* out) const; - void AppendPictureAlias(std::string* out) const; - - scoped_refptr<const Picture> picture_; - bool is_alias_; - - DISALLOW_COPY_AND_ASSIGN(TracedPicture); -}; - -} // namespace cc - -#endif // CC_DEBUG_TRACED_PICTURE_H_ 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 { diff --git a/cc/test/fake_display_list_recording_source.h b/cc/test/fake_display_list_recording_source.h index 3d400b6..5729812 100644 --- a/cc/test/fake_display_list_recording_source.h +++ b/cc/test/fake_display_list_recording_source.h @@ -120,6 +120,11 @@ class FakeDisplayListRecordingSource : public DisplayListRecordingSource { playback_allowed_event_ = event; } + DisplayItemList* display_list() const { return display_list_.get(); } + void set_pixel_record_distance(int distance) { + pixel_record_distance_ = distance; + } + private: FakeContentLayerClient client_; SkPaint default_paint_; diff --git a/cc/test/skia_common.cc b/cc/test/skia_common.cc index bcb5f1a..22d546c 100644 --- a/cc/test/skia_common.cc +++ b/cc/test/skia_common.cc @@ -5,7 +5,6 @@ #include "cc/test/skia_common.h" #include "cc/playback/display_item_list.h" -#include "cc/playback/picture.h" #include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkImageGenerator.h" @@ -24,20 +23,6 @@ class TestImageGenerator : public SkImageGenerator { } // anonymous namespace -void DrawPicture(unsigned char* buffer, - const gfx::Rect& layer_rect, - scoped_refptr<Picture> picture) { - SkImageInfo info = - SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); - SkBitmap bitmap; - bitmap.installPixels(info, buffer, info.minRowBytes()); - SkCanvas canvas(bitmap); - canvas.clipRect(gfx::RectToSkRect(layer_rect)); - // We're drawing the entire canvas, so the negated content region is empty. - gfx::Rect negated_content_region; - picture->Raster(&canvas, NULL, negated_content_region, 1.0f); -} - void DrawDisplayList(unsigned char* buffer, const gfx::Rect& layer_rect, scoped_refptr<DisplayItemList> list) { diff --git a/cc/test/skia_common.h b/cc/test/skia_common.h index 8603e10..2351e27 100644 --- a/cc/test/skia_common.h +++ b/cc/test/skia_common.h @@ -17,13 +17,8 @@ class Size; } namespace cc { -class Picture; class DisplayItemList; -void DrawPicture(unsigned char* buffer, - const gfx::Rect& layer_rect, - scoped_refptr<Picture> picture); - void DrawDisplayList(unsigned char* buffer, const gfx::Rect& layer_rect, scoped_refptr<DisplayItemList> list); |