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

Side by Side Diff: cc/layers/picture_layer_unittest.cc

Issue 1982893002: [blimp] Add SkPicture caching support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git merge origin/master Created 4 years, 6 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/picture_layer.h" 5 #include "cc/layers/picture_layer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 void set_update_source_frame_number(int number) { 53 void set_update_source_frame_number(int number) {
54 update_source_frame_number_ = number; 54 update_source_frame_number_ = number;
55 } 55 }
56 56
57 void set_is_mask(bool is_mask) { is_mask_ = is_mask; } 57 void set_is_mask(bool is_mask) { is_mask_ = is_mask; }
58 58
59 void set_nearest_neighbor(bool nearest_neighbor) { 59 void set_nearest_neighbor(bool nearest_neighbor) {
60 nearest_neighbor_ = nearest_neighbor; 60 nearest_neighbor_ = nearest_neighbor;
61 } 61 }
62 62
63 void ValidateSerialization() { 63 void ValidateSerialization(
64 proto::LayerProperties proto; 64 ImageSerializationProcessor* image_serialization_processor) {
65 LayerSpecificPropertiesToProto(&proto);
66
67 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 65 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
68 TestTaskGraphRunner task_graph_runner; 66 TestTaskGraphRunner task_graph_runner;
69 LayerTreeSettings settings; 67 LayerTreeSettings settings;
70 std::unique_ptr<FakeImageSerializationProcessor> 68 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(
71 fake_image_serialization_processor = 69 &host_client, &task_graph_runner, settings,
72 base::WrapUnique(new FakeImageSerializationProcessor); 70 CompositorMode::SINGLE_THREADED, image_serialization_processor);
73 std::unique_ptr<FakeLayerTreeHost> host = 71 host->InitializePictureCacheForTesting();
74 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings,
75 CompositorMode::SINGLE_THREADED,
76 fake_image_serialization_processor.get());
77 scoped_refptr<TestSerializationPictureLayer> layer = 72 scoped_refptr<TestSerializationPictureLayer> layer =
78 TestSerializationPictureLayer::Create(recording_source_viewport_); 73 TestSerializationPictureLayer::Create(recording_source_viewport_);
79 host->SetRootLayer(layer); 74 host->SetRootLayer(layer);
75
76 recording_source()->set_engine_picture_cache(host->engine_picture_cache());
77 recording_source()->MarkForRegistration();
78
79 proto::LayerProperties proto;
80 LayerSpecificPropertiesToProto(&proto);
81 // The EnginePictureCache will be invalid after this method ends, so ensure
82 // the recording source does not use it when the layer under test is
83 // destructed.
84 recording_source()->set_engine_picture_cache(nullptr);
85
86 // The client must have the ClientPictureCache available during
87 // deserialization.
88 layer->recording_source()->set_client_picture_cache(
89 host->client_picture_cache());
90
80 layer->FromLayerSpecificPropertiesProto(proto); 91 layer->FromLayerSpecificPropertiesProto(proto);
81 92
82 // Validate that the PictureLayer specific fields are properly set. 93 // Validate that the PictureLayer specific fields are properly set.
83 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source())); 94 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source()));
84 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_); 95 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_);
85 EXPECT_EQ(is_mask_, layer->is_mask_); 96 EXPECT_EQ(is_mask_, layer->is_mask_);
86 EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_); 97 EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_);
87 } 98 }
88 99
89 private: 100 private:
(...skipping 15 matching lines...) Expand all
105 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 116 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
106 TestTaskGraphRunner task_graph_runner; 117 TestTaskGraphRunner task_graph_runner;
107 LayerTreeSettings settings; 118 LayerTreeSettings settings;
108 std::unique_ptr<FakeImageSerializationProcessor> 119 std::unique_ptr<FakeImageSerializationProcessor>
109 fake_image_serialization_processor = 120 fake_image_serialization_processor =
110 base::WrapUnique(new FakeImageSerializationProcessor); 121 base::WrapUnique(new FakeImageSerializationProcessor);
111 std::unique_ptr<FakeLayerTreeHost> host = 122 std::unique_ptr<FakeLayerTreeHost> host =
112 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, 123 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings,
113 CompositorMode::SINGLE_THREADED, 124 CompositorMode::SINGLE_THREADED,
114 fake_image_serialization_processor.get()); 125 fake_image_serialization_processor.get());
126 host->InitializePictureCacheForTesting();
115 127
116 gfx::Size recording_source_viewport(256, 256); 128 gfx::Size recording_source_viewport(256, 256);
117 scoped_refptr<TestSerializationPictureLayer> layer = 129 scoped_refptr<TestSerializationPictureLayer> layer =
118 TestSerializationPictureLayer::Create(recording_source_viewport); 130 TestSerializationPictureLayer::Create(recording_source_viewport);
119 host->SetRootLayer(layer); 131 host->SetRootLayer(layer);
120 132
121 Region region(gfx::Rect(14, 15, 16, 17)); 133 Region region(gfx::Rect(14, 15, 16, 17));
122 layer->set_invalidation(region); 134 layer->set_invalidation(region);
123 layer->set_is_mask(true); 135 layer->set_is_mask(true);
124 layer->set_nearest_neighbor(true); 136 layer->set_nearest_neighbor(true);
125 137
126 layer->SetBounds(recording_source_viewport); 138 layer->SetBounds(recording_source_viewport);
127 layer->set_update_source_frame_number(0); 139 layer->set_update_source_frame_number(0);
128 layer->recording_source()->SetDisplayListUsesCachedPicture(false); 140 layer->recording_source()->SetDisplayListUsesCachedPicture(false);
129 layer->recording_source()->add_draw_rect( 141 layer->recording_source()->add_draw_rect(
130 gfx::Rect(recording_source_viewport)); 142 gfx::Rect(recording_source_viewport));
131 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); 143 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true);
132 layer->recording_source()->Rerecord(); 144 layer->recording_source()->Rerecord();
133 layer->ValidateSerialization(); 145 layer->ValidateSerialization(fake_image_serialization_processor.get());
134 } 146 }
135 147
136 TEST(PictureLayerTest, TestSerializationDeserialization) { 148 TEST(PictureLayerTest, TestSerializationDeserialization) {
137 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 149 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
138 TestTaskGraphRunner task_graph_runner; 150 TestTaskGraphRunner task_graph_runner;
139 std::unique_ptr<FakeImageSerializationProcessor> 151 std::unique_ptr<FakeImageSerializationProcessor>
140 fake_image_serialization_processor = 152 fake_image_serialization_processor =
141 base::WrapUnique(new FakeImageSerializationProcessor); 153 base::WrapUnique(new FakeImageSerializationProcessor);
142 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( 154 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(
143 &host_client, &task_graph_runner, LayerTreeSettings(), 155 &host_client, &task_graph_runner, LayerTreeSettings(),
144 CompositorMode::SINGLE_THREADED, 156 CompositorMode::SINGLE_THREADED,
145 fake_image_serialization_processor.get()); 157 fake_image_serialization_processor.get());
158 host->InitializePictureCacheForTesting();
159
146 gfx::Size recording_source_viewport(256, 256); 160 gfx::Size recording_source_viewport(256, 256);
147 scoped_refptr<TestSerializationPictureLayer> layer = 161 scoped_refptr<TestSerializationPictureLayer> layer =
148 TestSerializationPictureLayer::Create(recording_source_viewport); 162 TestSerializationPictureLayer::Create(recording_source_viewport);
149 host->SetRootLayer(layer); 163 host->SetRootLayer(layer);
150 164
151 layer->SetBounds(recording_source_viewport); 165 layer->SetBounds(recording_source_viewport);
152 layer->set_update_source_frame_number(0); 166 layer->set_update_source_frame_number(0);
153 layer->recording_source()->SetDisplayListUsesCachedPicture(false); 167 layer->recording_source()->SetDisplayListUsesCachedPicture(false);
154 layer->recording_source()->add_draw_rect( 168 layer->recording_source()->add_draw_rect(
155 gfx::Rect(recording_source_viewport)); 169 gfx::Rect(recording_source_viewport));
156 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); 170 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true);
157 layer->recording_source()->Rerecord(); 171 layer->recording_source()->Rerecord();
158 layer->ValidateSerialization(); 172 layer->ValidateSerialization(fake_image_serialization_processor.get());
159 } 173 }
160 174
161 TEST(PictureLayerTest, TestEmptySerializationDeserialization) { 175 TEST(PictureLayerTest, TestEmptySerializationDeserialization) {
176 std::unique_ptr<FakeImageSerializationProcessor>
177 fake_image_serialization_processor =
178 base::WrapUnique(new FakeImageSerializationProcessor);
162 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 179 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
163 TestTaskGraphRunner task_graph_runner; 180 TestTaskGraphRunner task_graph_runner;
164 std::unique_ptr<FakeLayerTreeHost> host = 181 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(
165 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); 182 &host_client, &task_graph_runner, LayerTreeSettings(),
183 CompositorMode::SINGLE_THREADED,
184 fake_image_serialization_processor.get());
166 185
167 gfx::Size recording_source_viewport(256, 256); 186 gfx::Size recording_source_viewport(256, 256);
168 scoped_refptr<TestSerializationPictureLayer> layer = 187 scoped_refptr<TestSerializationPictureLayer> layer =
169 TestSerializationPictureLayer::Create(recording_source_viewport); 188 TestSerializationPictureLayer::Create(recording_source_viewport);
170 host->SetRootLayer(layer); 189 host->SetRootLayer(layer);
171 layer->ValidateSerialization(); 190 layer->ValidateSerialization(fake_image_serialization_processor.get());
172 } 191 }
173 192
174 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { 193 TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
175 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); 194 ContentLayerClient* client = EmptyContentLayerClient::GetInstance();
176 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); 195 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client);
177 layer->SetBounds(gfx::Size(10, 10)); 196 layer->SetBounds(gfx::Size(10, 10));
178 197
179 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 198 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
180 TestTaskGraphRunner task_graph_runner; 199 TestTaskGraphRunner task_graph_runner;
181 std::unique_ptr<FakeLayerTreeHost> host = 200 std::unique_ptr<FakeLayerTreeHost> host =
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 // Do a main frame, record the picture layers. The frame number has changed 486 // Do a main frame, record the picture layers. The frame number has changed
468 // non-monotonically. 487 // non-monotonically.
469 layer->SetNeedsDisplay(); 488 layer->SetNeedsDisplay();
470 host2->Composite(base::TimeTicks::Now()); 489 host2->Composite(base::TimeTicks::Now());
471 EXPECT_EQ(3, layer->update_count()); 490 EXPECT_EQ(3, layer->update_count());
472 EXPECT_EQ(1, host2->source_frame_number()); 491 EXPECT_EQ(1, host2->source_frame_number());
473 } 492 }
474 493
475 } // namespace 494 } // namespace
476 } // namespace cc 495 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698