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

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

Issue 2251143002: cc: Reland Move data to LayerTree from LayerTreeHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better fix? Created 4 years, 4 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/texture_layer.h" 5 #include "cc/layers/texture_layer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 : output_surface_(FakeOutputSurface::CreateDelegating3d()), 213 : output_surface_(FakeOutputSurface::CreateDelegating3d()),
214 host_impl_(&task_runner_provider_, 214 host_impl_(&task_runner_provider_,
215 &shared_bitmap_manager_, 215 &shared_bitmap_manager_,
216 &task_graph_runner_), 216 &task_graph_runner_),
217 test_data_(&shared_bitmap_manager_) {} 217 test_data_(&shared_bitmap_manager_) {}
218 218
219 protected: 219 protected:
220 void SetUp() override { 220 void SetUp() override {
221 layer_tree_host_ = 221 layer_tree_host_ =
222 MockLayerTreeHost::Create(&fake_client_, &task_graph_runner_); 222 MockLayerTreeHost::Create(&fake_client_, &task_graph_runner_);
223 layer_tree_ = layer_tree_host_->GetLayerTree();
223 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 224 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
224 layer_tree_host_->SetViewportSize(gfx::Size(10, 10)); 225 layer_tree_->SetViewportSize(gfx::Size(10, 10));
225 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 226 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
226 } 227 }
227 228
228 void TearDown() override { 229 void TearDown() override {
229 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 230 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
230 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 231 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
231 232
232 layer_tree_host_->SetRootLayer(nullptr); 233 layer_tree_->SetRootLayer(nullptr);
233 layer_tree_host_ = nullptr; 234 layer_tree_host_ = nullptr;
234 } 235 }
235 236
236 std::unique_ptr<MockLayerTreeHost> layer_tree_host_; 237 std::unique_ptr<MockLayerTreeHost> layer_tree_host_;
238 LayerTree* layer_tree_;
237 FakeImplTaskRunnerProvider task_runner_provider_; 239 FakeImplTaskRunnerProvider task_runner_provider_;
238 FakeLayerTreeHostClient fake_client_; 240 FakeLayerTreeHostClient fake_client_;
239 TestSharedBitmapManager shared_bitmap_manager_; 241 TestSharedBitmapManager shared_bitmap_manager_;
240 TestTaskGraphRunner task_graph_runner_; 242 TestTaskGraphRunner task_graph_runner_;
241 std::unique_ptr<OutputSurface> output_surface_; 243 std::unique_ptr<OutputSurface> output_surface_;
242 FakeLayerTreeHostImpl host_impl_; 244 FakeLayerTreeHostImpl host_impl_;
243 CommonMailboxObjects test_data_; 245 CommonMailboxObjects test_data_;
244 }; 246 };
245 247
246 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { 248 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) {
247 scoped_refptr<TextureLayer> test_layer = 249 scoped_refptr<TextureLayer> test_layer =
248 TextureLayer::CreateForMailbox(nullptr); 250 TextureLayer::CreateForMailbox(nullptr);
249 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); 251 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_->SetRootLayer(test_layer));
250 252
251 // Test properties that should call SetNeedsCommit. All properties need to 253 // Test properties that should call SetNeedsCommit. All properties need to
252 // be set to new values in order for SetNeedsCommit to be called. 254 // be set to new values in order for SetNeedsCommit to be called.
253 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); 255 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false));
254 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNearestNeighbor(true)); 256 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNearestNeighbor(true));
255 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( 257 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV(
256 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); 258 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f)));
257 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( 259 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity(
258 0.5f, 0.5f, 0.5f, 0.5f)); 260 0.5f, 0.5f, 0.5f, 0.5f));
259 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); 261 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false));
(...skipping 19 matching lines...) Expand all
279 TextureLayerTest::TearDown(); 281 TextureLayerTest::TearDown();
280 } 282 }
281 }; 283 };
282 284
283 TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { 285 TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) {
284 scoped_refptr<TextureLayer> test_layer = 286 scoped_refptr<TextureLayer> test_layer =
285 TextureLayer::CreateForMailbox(nullptr); 287 TextureLayer::CreateForMailbox(nullptr);
286 ASSERT_TRUE(test_layer.get()); 288 ASSERT_TRUE(test_layer.get());
287 289
288 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 290 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
289 layer_tree_host_->SetRootLayer(test_layer); 291 layer_tree_->SetRootLayer(test_layer);
290 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 292 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
291 293
292 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 294 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
293 test_layer->SetTextureMailbox( 295 test_layer->SetTextureMailbox(
294 test_data_.mailbox1_, 296 test_data_.mailbox1_,
295 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); 297 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
296 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 298 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
297 299
298 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 300 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
299 EXPECT_CALL( 301 EXPECT_CALL(
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 683
682 gfx::Size bounds(100, 100); 684 gfx::Size bounds(100, 100);
683 root_ = Layer::Create(); 685 root_ = Layer::Create();
684 root_->SetBounds(bounds); 686 root_->SetBounds(bounds);
685 687
686 layer_ = TextureLayer::CreateForMailbox(nullptr); 688 layer_ = TextureLayer::CreateForMailbox(nullptr);
687 layer_->SetIsDrawable(true); 689 layer_->SetIsDrawable(true);
688 layer_->SetBounds(bounds); 690 layer_->SetBounds(bounds);
689 691
690 root_->AddChild(layer_); 692 root_->AddChild(layer_);
691 layer_tree_host()->SetRootLayer(root_); 693 layer_tree()->SetRootLayer(root_);
692 layer_tree_host()->SetViewportSize(bounds); 694 layer_tree()->SetViewportSize(bounds);
693 SetMailbox('1'); 695 SetMailbox('1');
694 EXPECT_EQ(0, callback_count_); 696 EXPECT_EQ(0, callback_count_);
695 697
696 // Case #1: change mailbox before the commit. The old mailbox should be 698 // Case #1: change mailbox before the commit. The old mailbox should be
697 // released immediately. 699 // released immediately.
698 SetMailbox('2'); 700 SetMailbox('2');
699 EXPECT_EQ(1, callback_count_); 701 EXPECT_EQ(1, callback_count_);
700 PostSetNeedsCommitToMainThread(); 702 PostSetNeedsCommitToMainThread();
701 } 703 }
702 704
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 void BeginTest() override { 784 void BeginTest() override {
783 gfx::Size bounds(100, 100); 785 gfx::Size bounds(100, 100);
784 root_ = Layer::Create(); 786 root_ = Layer::Create();
785 root_->SetBounds(bounds); 787 root_->SetBounds(bounds);
786 788
787 layer_ = TextureLayer::CreateForMailbox(nullptr); 789 layer_ = TextureLayer::CreateForMailbox(nullptr);
788 layer_->SetIsDrawable(true); 790 layer_->SetIsDrawable(true);
789 layer_->SetBounds(bounds); 791 layer_->SetBounds(bounds);
790 792
791 root_->AddChild(layer_); 793 root_->AddChild(layer_);
792 layer_tree_host()->SetRootLayer(root_); 794 layer_tree()->SetRootLayer(root_);
793 layer_tree_host()->SetViewportSize(bounds); 795 layer_tree()->SetViewportSize(bounds);
794 SetMailbox('1'); 796 SetMailbox('1');
795 797
796 PostSetNeedsCommitToMainThread(); 798 PostSetNeedsCommitToMainThread();
797 } 799 }
798 800
799 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { 801 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
800 base::AutoLock lock(activate_count_lock_); 802 base::AutoLock lock(activate_count_lock_);
801 ++activate_count_; 803 ++activate_count_;
802 } 804 }
803 805
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 }; 845 };
844 846
845 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerMailboxIsActivatedDuringCommit); 847 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerMailboxIsActivatedDuringCommit);
846 848
847 class TextureLayerImplWithMailboxTest : public TextureLayerTest { 849 class TextureLayerImplWithMailboxTest : public TextureLayerTest {
848 protected: 850 protected:
849 void SetUp() override { 851 void SetUp() override {
850 TextureLayerTest::SetUp(); 852 TextureLayerTest::SetUp();
851 layer_tree_host_ = 853 layer_tree_host_ =
852 MockLayerTreeHost::Create(&fake_client_, &task_graph_runner_); 854 MockLayerTreeHost::Create(&fake_client_, &task_graph_runner_);
855 layer_tree_ = layer_tree_host_->GetLayerTree();
853 host_impl_.SetVisible(true); 856 host_impl_.SetVisible(true);
854 EXPECT_TRUE(host_impl_.InitializeRenderer(output_surface_.get())); 857 EXPECT_TRUE(host_impl_.InitializeRenderer(output_surface_.get()));
855 } 858 }
856 859
857 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) { 860 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) {
858 bool will_draw = layer->WillDraw( 861 bool will_draw = layer->WillDraw(
859 mode, host_impl_.active_tree()->resource_provider()); 862 mode, host_impl_.active_tree()->resource_provider());
860 if (will_draw) 863 if (will_draw)
861 layer->DidDraw(host_impl_.active_tree()->resource_provider()); 864 layer->DidDraw(host_impl_.active_tree()->resource_provider());
862 return will_draw; 865 return will_draw;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 void SetupTree() override { 1076 void SetupTree() override {
1074 scoped_refptr<Layer> root = Layer::Create(); 1077 scoped_refptr<Layer> root = Layer::Create();
1075 root->SetBounds(gfx::Size(10, 10)); 1078 root->SetBounds(gfx::Size(10, 10));
1076 root->SetIsDrawable(true); 1079 root->SetIsDrawable(true);
1077 1080
1078 texture_layer_ = TextureLayer::CreateForMailbox(this); 1081 texture_layer_ = TextureLayer::CreateForMailbox(this);
1079 texture_layer_->SetBounds(gfx::Size(10, 10)); 1082 texture_layer_->SetBounds(gfx::Size(10, 10));
1080 texture_layer_->SetIsDrawable(true); 1083 texture_layer_->SetIsDrawable(true);
1081 root->AddChild(texture_layer_); 1084 root->AddChild(texture_layer_);
1082 1085
1083 layer_tree_host()->SetRootLayer(root); 1086 layer_tree()->SetRootLayer(root);
1084 LayerTreeTest::SetupTree(); 1087 LayerTreeTest::SetupTree();
1085 } 1088 }
1086 1089
1087 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1090 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1088 1091
1089 void DidCommitAndDrawFrame() override { 1092 void DidCommitAndDrawFrame() override {
1090 switch (layer_tree_host()->source_frame_number()) { 1093 switch (layer_tree_host()->source_frame_number()) {
1091 case 1: 1094 case 1:
1092 EXPECT_FALSE(proxy()->MainFrameWillHappenForTesting()); 1095 EXPECT_FALSE(proxy()->MainFrameWillHappenForTesting());
1093 // Invalidate the texture layer to clear the mailbox before 1096 // Invalidate the texture layer to clear the mailbox before
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 parent_layer_ = Layer::Create(); 1168 parent_layer_ = Layer::Create();
1166 parent_layer_->SetBounds(gfx::Size(10, 10)); 1169 parent_layer_->SetBounds(gfx::Size(10, 10));
1167 parent_layer_->SetIsDrawable(true); 1170 parent_layer_->SetIsDrawable(true);
1168 root->AddChild(parent_layer_); 1171 root->AddChild(parent_layer_);
1169 1172
1170 texture_layer_ = TextureLayer::CreateForMailbox(this); 1173 texture_layer_ = TextureLayer::CreateForMailbox(this);
1171 texture_layer_->SetBounds(gfx::Size(10, 10)); 1174 texture_layer_->SetBounds(gfx::Size(10, 10));
1172 texture_layer_->SetIsDrawable(true); 1175 texture_layer_->SetIsDrawable(true);
1173 parent_layer_->AddChild(texture_layer_); 1176 parent_layer_->AddChild(texture_layer_);
1174 1177
1175 layer_tree_host()->SetRootLayer(root); 1178 layer_tree()->SetRootLayer(root);
1176 LayerTreeTest::SetupTree(); 1179 LayerTreeTest::SetupTree();
1177 } 1180 }
1178 1181
1179 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1182 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1180 1183
1181 void DidCommitAndDrawFrame() override { 1184 void DidCommitAndDrawFrame() override {
1182 ++commit_count_; 1185 ++commit_count_;
1183 switch (commit_count_) { 1186 switch (commit_count_) {
1184 case 1: 1187 case 1:
1185 // We should have updated the layer, committing the texture. 1188 // We should have updated the layer, committing the texture.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 } 1266 }
1264 1267
1265 void SetupTree() override { 1268 void SetupTree() override {
1266 LayerTreeTest::SetupTree(); 1269 LayerTreeTest::SetupTree();
1267 1270
1268 scoped_refptr<TextureLayer> texture_layer = 1271 scoped_refptr<TextureLayer> texture_layer =
1269 TextureLayer::CreateForMailbox(this); 1272 TextureLayer::CreateForMailbox(this);
1270 texture_layer->SetBounds(gfx::Size(10, 10)); 1273 texture_layer->SetBounds(gfx::Size(10, 10));
1271 texture_layer->SetIsDrawable(true); 1274 texture_layer->SetIsDrawable(true);
1272 1275
1273 layer_tree_host()->root_layer()->AddChild(texture_layer); 1276 layer_tree()->root_layer()->AddChild(texture_layer);
1274 texture_layer_id_ = texture_layer->id(); 1277 texture_layer_id_ = texture_layer->id();
1275 } 1278 }
1276 1279
1277 void BeginTest() override { 1280 void BeginTest() override {
1278 mailbox_released_ = false; 1281 mailbox_released_ = false;
1279 PostSetNeedsCommitToMainThread(); 1282 PostSetNeedsCommitToMainThread();
1280 } 1283 }
1281 1284
1282 void DidCommitAndDrawFrame() override { EndTest(); } 1285 void DidCommitAndDrawFrame() override { EndTest(); }
1283 1286
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 void SetupTree() override { 1340 void SetupTree() override {
1338 gfx::Size bounds(100, 100); 1341 gfx::Size bounds(100, 100);
1339 root_ = Layer::Create(); 1342 root_ = Layer::Create();
1340 root_->SetBounds(bounds); 1343 root_->SetBounds(bounds);
1341 1344
1342 layer_ = TextureLayer::CreateForMailbox(nullptr); 1345 layer_ = TextureLayer::CreateForMailbox(nullptr);
1343 layer_->SetIsDrawable(true); 1346 layer_->SetIsDrawable(true);
1344 layer_->SetBounds(bounds); 1347 layer_->SetBounds(bounds);
1345 1348
1346 root_->AddChild(layer_); 1349 root_->AddChild(layer_);
1347 layer_tree_host()->SetRootLayer(root_); 1350 layer_tree()->SetRootLayer(root_);
1348 layer_tree_host()->SetViewportSize(bounds); 1351 layer_tree()->SetViewportSize(bounds);
1349 } 1352 }
1350 1353
1351 void BeginTest() override { 1354 void BeginTest() override {
1352 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); 1355 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1353 1356
1354 callback_count_ = 0; 1357 callback_count_ = 0;
1355 1358
1356 // Set the mailbox on the main thread. 1359 // Set the mailbox on the main thread.
1357 SetMailbox('1'); 1360 SetMailbox('1');
1358 EXPECT_EQ(0, callback_count_); 1361 EXPECT_EQ(0, callback_count_);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 void SetupTree() override { 1410 void SetupTree() override {
1408 gfx::Size bounds(100, 100); 1411 gfx::Size bounds(100, 100);
1409 root_ = Layer::Create(); 1412 root_ = Layer::Create();
1410 root_->SetBounds(bounds); 1413 root_->SetBounds(bounds);
1411 1414
1412 layer_ = TextureLayer::CreateForMailbox(nullptr); 1415 layer_ = TextureLayer::CreateForMailbox(nullptr);
1413 layer_->SetIsDrawable(true); 1416 layer_->SetIsDrawable(true);
1414 layer_->SetBounds(bounds); 1417 layer_->SetBounds(bounds);
1415 1418
1416 root_->AddChild(layer_); 1419 root_->AddChild(layer_);
1417 layer_tree_host()->SetRootLayer(root_); 1420 layer_tree()->SetRootLayer(root_);
1418 layer_tree_host()->SetViewportSize(bounds); 1421 layer_tree()->SetViewportSize(bounds);
1419 } 1422 }
1420 1423
1421 void BeginTest() override { 1424 void BeginTest() override {
1422 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); 1425 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1423 1426
1424 callback_count_ = 0; 1427 callback_count_ = 0;
1425 1428
1426 // Set the mailbox on the main thread. 1429 // Set the mailbox on the main thread.
1427 SetMailbox('1'); 1430 SetMailbox('1');
1428 EXPECT_EQ(0, callback_count_); 1431 EXPECT_EQ(0, callback_count_);
(...skipping 21 matching lines...) Expand all
1450 base::ThreadChecker main_thread_; 1453 base::ThreadChecker main_thread_;
1451 int callback_count_; 1454 int callback_count_;
1452 scoped_refptr<Layer> root_; 1455 scoped_refptr<Layer> root_;
1453 scoped_refptr<TextureLayer> layer_; 1456 scoped_refptr<TextureLayer> layer_;
1454 }; 1457 };
1455 1458
1456 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); 1459 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted);
1457 1460
1458 } // namespace 1461 } // namespace
1459 } // namespace cc 1462 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698