Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Unified Diff: cc/layers/picture_layer_unittest.cc

Issue 1527863002: Serialize PictureLayer properties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed tests Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/layers/picture_layer_unittest.cc
diff --git a/cc/layers/picture_layer_unittest.cc b/cc/layers/picture_layer_unittest.cc
index 97751fde77ac5f869a835ff6044348c928f1b378..4b46f46e9dbe4de35374e21a75949639c663cf9e 100644
--- a/cc/layers/picture_layer_unittest.cc
+++ b/cc/layers/picture_layer_unittest.cc
@@ -6,9 +6,11 @@
#include "base/thread_task_runner_handle.h"
#include "cc/layers/content_layer_client.h"
+#include "cc/layers/empty_content_layer_client.h"
#include "cc/layers/layer_settings.h"
#include "cc/layers/picture_layer_impl.h"
#include "cc/playback/display_item_list_settings.h"
+#include "cc/proto/layer.pb.h"
#include "cc/test/fake_display_list_recording_source.h"
#include "cc/test/fake_layer_tree_host.h"
#include "cc/test/fake_picture_layer.h"
@@ -21,23 +23,139 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
-namespace {
-class MockContentLayerClient : public ContentLayerClient {
+class TestSerializationPictureLayer : public PictureLayer {
public:
- gfx::Rect PaintableRegion() override { return gfx::Rect(); }
- scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
- PaintingControlSetting picture_control) override {
- return DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings());
+ static scoped_refptr<TestSerializationPictureLayer> Create(
+ const gfx::Size& recording_source_viewport) {
+ return make_scoped_refptr(new TestSerializationPictureLayer(
+ LayerSettings(), EmptyContentLayerClient::GetInstance(),
+ FakeDisplayListRecordingSource::CreateFilledRecordingSource(
+ recording_source_viewport),
+ recording_source_viewport));
+ }
+
+ FakeDisplayListRecordingSource* recording_source() {
+ return static_cast<FakeDisplayListRecordingSource*>(
+ recording_source_.get());
+ }
+
+ void set_invalidation(const Region& invalidation) {
+ *invalidation_.region() = invalidation;
+ }
+
+ void set_last_updated_visible_layer_rect(const gfx::Rect& rect) {
+ last_updated_visible_layer_rect_ = rect;
+ }
+
+ void set_update_source_frame_number(int number) {
+ update_source_frame_number_ = number;
+ }
+
+ void set_is_mask(bool is_mask) { is_mask_ = is_mask; }
+
+ void set_nearest_neighbor(bool nearest_neighbor) {
+ nearest_neighbor_ = nearest_neighbor;
}
- bool FillsBoundsCompletely() const override { return false; };
- size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
+
+ void ValidateSerialization() {
+ proto::LayerProperties proto;
+ LayerSpecificPropertiesToProto(&proto);
+
+ scoped_refptr<TestSerializationPictureLayer> layer =
+ TestSerializationPictureLayer::Create(recording_source_viewport_);
+ layer->FromLayerSpecificPropertiesProto(proto);
+
+ // Validate that the PictureLayer specific fields are properly set.
+ EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source()));
+ EXPECT_EQ(last_updated_visible_layer_rect_,
+ layer->last_updated_visible_layer_rect_);
+ EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_);
+ EXPECT_EQ(is_mask_, layer->is_mask_);
+ EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_);
+ }
+
+ private:
+ TestSerializationPictureLayer(const LayerSettings& settings,
+ ContentLayerClient* client,
+ scoped_ptr<DisplayListRecordingSource> source,
+ const gfx::Size& recording_source_viewport)
+ : PictureLayer(settings, client, std::move(source)),
+ recording_source_viewport_(recording_source_viewport) {}
+ ~TestSerializationPictureLayer() override {}
+
+ gfx::Size recording_source_viewport_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestSerializationPictureLayer);
};
+namespace {
+
+TEST(PictureLayerTest, TestSetAllPropsSerializationDeserialization) {
+ FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
+ TestTaskGraphRunner task_graph_runner;
+ scoped_ptr<FakeLayerTreeHost> host =
+ FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
+
+ gfx::Size recording_source_viewport(256, 256);
+ scoped_refptr<TestSerializationPictureLayer> layer =
+ TestSerializationPictureLayer::Create(recording_source_viewport);
+ host->SetRootLayer(layer);
+
+ Region region(gfx::Rect(14, 15, 16, 17));
+ layer->set_invalidation(region);
+ layer->set_last_updated_visible_layer_rect(gfx::Rect(5, 6, 7, 8));
+ layer->set_is_mask(true);
+ layer->set_nearest_neighbor(true);
+
+ layer->SetBounds(recording_source_viewport);
+ layer->set_update_source_frame_number(0);
+ layer->recording_source()->SetDisplayListUsesCachedPicture(false);
+ layer->recording_source()->add_draw_rect(
+ gfx::Rect(recording_source_viewport));
+ layer->recording_source()->SetGenerateDiscardableImagesMetadata(true);
+ layer->recording_source()->Rerecord();
+ layer->ValidateSerialization();
+}
+
+TEST(PictureLayerTest, TestSerializationDeserialization) {
+ FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
+ TestTaskGraphRunner task_graph_runner;
+ scoped_ptr<FakeLayerTreeHost> host =
+ FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
+
+ gfx::Size recording_source_viewport(256, 256);
+ scoped_refptr<TestSerializationPictureLayer> layer =
+ TestSerializationPictureLayer::Create(recording_source_viewport);
+ host->SetRootLayer(layer);
+
+ layer->SetBounds(recording_source_viewport);
+ layer->set_update_source_frame_number(0);
+ layer->recording_source()->SetDisplayListUsesCachedPicture(false);
+ layer->recording_source()->add_draw_rect(
+ gfx::Rect(recording_source_viewport));
+ layer->recording_source()->SetGenerateDiscardableImagesMetadata(true);
+ layer->recording_source()->Rerecord();
+ layer->ValidateSerialization();
+}
+
+TEST(PictureLayerTest, TestEmptySerializationDeserialization) {
+ FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
+ TestTaskGraphRunner task_graph_runner;
+ scoped_ptr<FakeLayerTreeHost> host =
+ FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
+
+ gfx::Size recording_source_viewport(256, 256);
+ scoped_refptr<TestSerializationPictureLayer> layer =
+ TestSerializationPictureLayer::Create(recording_source_viewport);
+ host->SetRootLayer(layer);
+ layer->ValidateSerialization();
+}
+
TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
- MockContentLayerClient client;
+ ContentLayerClient* client = EmptyContentLayerClient::GetInstance();
scoped_refptr<PictureLayer> layer =
- PictureLayer::Create(LayerSettings(), &client);
+ PictureLayer::Create(LayerSettings(), client);
layer->SetBounds(gfx::Size(10, 10));
FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
@@ -81,10 +199,10 @@ TEST(PictureLayerTest, SuitableForGpuRasterization) {
FakeDisplayListRecordingSource* recording_source =
recording_source_owned.get();
- MockContentLayerClient client;
+ ContentLayerClient* client = EmptyContentLayerClient::GetInstance();
scoped_refptr<FakePictureLayer> layer =
FakePictureLayer::CreateWithRecordingSource(
- LayerSettings(), &client, std::move(recording_source_owned));
+ LayerSettings(), client, std::move(recording_source_owned));
FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
TestTaskGraphRunner task_graph_runner;
@@ -97,7 +215,7 @@ TEST(PictureLayerTest, SuitableForGpuRasterization) {
gfx::Rect layer_rect(layer_bounds);
Region invalidation(layer_rect);
recording_source->UpdateAndExpandInvalidation(
- &client, &invalidation, layer_bounds, layer_rect, 1,
+ client, &invalidation, layer_bounds, layer_rect, 1,
DisplayListRecordingSource::RECORD_NORMALLY);
// Layer is suitable for gpu rasterization by default.
@@ -124,9 +242,9 @@ TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) {
TestSharedBitmapManager shared_bitmap_manager;
TestTaskGraphRunner task_graph_runner;
- MockContentLayerClient client;
+ ContentLayerClient* client = EmptyContentLayerClient::GetInstance();
scoped_refptr<FakePictureLayer> layer =
- FakePictureLayer::Create(LayerSettings(), &client);
+ FakePictureLayer::Create(LayerSettings(), client);
LayerTreeHost::InitParams params;
params.client = &host_client1;

Powered by Google App Engine
This is Rietveld 408576698