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

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

Issue 2661523003: cc: Merge LayerTree into the LayerTreeHost. (Closed)
Patch Set: auto Created 3 years, 10 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
« no previous file with comments | « cc/layers/surface_layer_unittest.cc ('k') | cc/layers/ui_resource_layer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 : compositor_frame_sink_(FakeCompositorFrameSink::Create3d()), 211 : compositor_frame_sink_(FakeCompositorFrameSink::Create3d()),
212 host_impl_(&task_runner_provider_, 212 host_impl_(&task_runner_provider_,
213 &task_graph_runner_), 213 &task_graph_runner_),
214 test_data_(&shared_bitmap_manager_) {} 214 test_data_(&shared_bitmap_manager_) {}
215 215
216 protected: 216 protected:
217 void SetUp() override { 217 void SetUp() override {
218 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN); 218 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
219 layer_tree_host_ = MockLayerTreeHost::Create( 219 layer_tree_host_ = MockLayerTreeHost::Create(
220 &fake_client_, &task_graph_runner_, animation_host_.get()); 220 &fake_client_, &task_graph_runner_, animation_host_.get());
221 layer_tree_ = layer_tree_host_->GetLayerTree();
222 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 221 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
223 layer_tree_->SetViewportSize(gfx::Size(10, 10)); 222 layer_tree_host_->SetViewportSize(gfx::Size(10, 10));
224 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 223 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
225 } 224 }
226 225
227 void TearDown() override { 226 void TearDown() override {
228 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 227 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
229 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 228 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
230 229
231 animation_host_->SetMutatorHostClient(nullptr); 230 animation_host_->SetMutatorHostClient(nullptr);
232 layer_tree_->SetRootLayer(nullptr); 231 layer_tree_host_->SetRootLayer(nullptr);
233 layer_tree_host_ = nullptr; 232 layer_tree_host_ = nullptr;
234 animation_host_ = nullptr; 233 animation_host_ = nullptr;
235 } 234 }
236 235
237 std::unique_ptr<MockLayerTreeHost> layer_tree_host_; 236 std::unique_ptr<MockLayerTreeHost> layer_tree_host_;
238 std::unique_ptr<AnimationHost> animation_host_; 237 std::unique_ptr<AnimationHost> animation_host_;
239 LayerTree* layer_tree_;
240 FakeImplTaskRunnerProvider task_runner_provider_; 238 FakeImplTaskRunnerProvider task_runner_provider_;
241 FakeLayerTreeHostClient fake_client_; 239 FakeLayerTreeHostClient fake_client_;
242 TestSharedBitmapManager shared_bitmap_manager_; 240 TestSharedBitmapManager shared_bitmap_manager_;
243 TestTaskGraphRunner task_graph_runner_; 241 TestTaskGraphRunner task_graph_runner_;
244 std::unique_ptr<CompositorFrameSink> compositor_frame_sink_; 242 std::unique_ptr<CompositorFrameSink> compositor_frame_sink_;
245 FakeLayerTreeHostImpl host_impl_; 243 FakeLayerTreeHostImpl host_impl_;
246 CommonMailboxObjects test_data_; 244 CommonMailboxObjects test_data_;
247 }; 245 };
248 246
249 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { 247 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) {
250 scoped_refptr<TextureLayer> test_layer = 248 scoped_refptr<TextureLayer> test_layer =
251 TextureLayer::CreateForMailbox(nullptr); 249 TextureLayer::CreateForMailbox(nullptr);
252 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_->SetRootLayer(test_layer)); 250 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer));
253 251
254 // Test properties that should call SetNeedsCommit. All properties need to 252 // Test properties that should call SetNeedsCommit. All properties need to
255 // be set to new values in order for SetNeedsCommit to be called. 253 // be set to new values in order for SetNeedsCommit to be called.
256 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); 254 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false));
257 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNearestNeighbor(true)); 255 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNearestNeighbor(true));
258 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( 256 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV(
259 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); 257 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f)));
260 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( 258 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity(
261 0.5f, 0.5f, 0.5f, 0.5f)); 259 0.5f, 0.5f, 0.5f, 0.5f));
262 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); 260 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false));
(...skipping 19 matching lines...) Expand all
282 TextureLayerTest::TearDown(); 280 TextureLayerTest::TearDown();
283 } 281 }
284 }; 282 };
285 283
286 TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { 284 TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) {
287 scoped_refptr<TextureLayer> test_layer = 285 scoped_refptr<TextureLayer> test_layer =
288 TextureLayer::CreateForMailbox(nullptr); 286 TextureLayer::CreateForMailbox(nullptr);
289 ASSERT_TRUE(test_layer.get()); 287 ASSERT_TRUE(test_layer.get());
290 288
291 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 289 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
292 layer_tree_->SetRootLayer(test_layer); 290 layer_tree_host_->SetRootLayer(test_layer);
293 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 291 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
294 292
295 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 293 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
296 test_layer->SetTextureMailbox( 294 test_layer->SetTextureMailbox(
297 test_data_.mailbox1_, 295 test_data_.mailbox1_,
298 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); 296 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
299 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 297 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
300 298
301 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 299 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
302 EXPECT_CALL( 300 EXPECT_CALL(
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 749
752 gfx::Size bounds(100, 100); 750 gfx::Size bounds(100, 100);
753 root_ = Layer::Create(); 751 root_ = Layer::Create();
754 root_->SetBounds(bounds); 752 root_->SetBounds(bounds);
755 753
756 layer_ = TextureLayer::CreateForMailbox(nullptr); 754 layer_ = TextureLayer::CreateForMailbox(nullptr);
757 layer_->SetIsDrawable(true); 755 layer_->SetIsDrawable(true);
758 layer_->SetBounds(bounds); 756 layer_->SetBounds(bounds);
759 757
760 root_->AddChild(layer_); 758 root_->AddChild(layer_);
761 layer_tree()->SetRootLayer(root_); 759 layer_tree_host()->SetRootLayer(root_);
762 layer_tree()->SetViewportSize(bounds); 760 layer_tree_host()->SetViewportSize(bounds);
763 SetMailbox('1'); 761 SetMailbox('1');
764 EXPECT_EQ(0, callback_count_); 762 EXPECT_EQ(0, callback_count_);
765 763
766 // Setup is complete - advance to test case 1. 764 // Setup is complete - advance to test case 1.
767 AdvanceTestCase(); 765 AdvanceTestCase();
768 } 766 }
769 767
770 void DidCommit() override { 768 void DidCommit() override {
771 // If we are not waiting on a callback, advance now. 769 // If we are not waiting on a callback, advance now.
772 if (!pending_callback_) 770 if (!pending_callback_)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 void BeginTest() override { 808 void BeginTest() override {
811 gfx::Size bounds(100, 100); 809 gfx::Size bounds(100, 100);
812 root_ = Layer::Create(); 810 root_ = Layer::Create();
813 root_->SetBounds(bounds); 811 root_->SetBounds(bounds);
814 812
815 layer_ = TextureLayer::CreateForMailbox(nullptr); 813 layer_ = TextureLayer::CreateForMailbox(nullptr);
816 layer_->SetIsDrawable(true); 814 layer_->SetIsDrawable(true);
817 layer_->SetBounds(bounds); 815 layer_->SetBounds(bounds);
818 816
819 root_->AddChild(layer_); 817 root_->AddChild(layer_);
820 layer_tree()->SetRootLayer(root_); 818 layer_tree_host()->SetRootLayer(root_);
821 layer_tree()->SetViewportSize(bounds); 819 layer_tree_host()->SetViewportSize(bounds);
822 SetMailbox('1'); 820 SetMailbox('1');
823 821
824 PostSetNeedsCommitToMainThread(); 822 PostSetNeedsCommitToMainThread();
825 } 823 }
826 824
827 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { 825 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
828 base::AutoLock lock(activate_count_lock_); 826 base::AutoLock lock(activate_count_lock_);
829 ++activate_count_; 827 ++activate_count_;
830 } 828 }
831 829
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 #if !defined(OS_WIN) && !defined(OS_LINUX) 872 #if !defined(OS_WIN) && !defined(OS_LINUX)
875 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerMailboxIsActivatedDuringCommit); 873 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerMailboxIsActivatedDuringCommit);
876 #endif 874 #endif
877 875
878 class TextureLayerImplWithMailboxTest : public TextureLayerTest { 876 class TextureLayerImplWithMailboxTest : public TextureLayerTest {
879 protected: 877 protected:
880 void SetUp() override { 878 void SetUp() override {
881 TextureLayerTest::SetUp(); 879 TextureLayerTest::SetUp();
882 layer_tree_host_ = MockLayerTreeHost::Create( 880 layer_tree_host_ = MockLayerTreeHost::Create(
883 &fake_client_, &task_graph_runner_, animation_host_.get()); 881 &fake_client_, &task_graph_runner_, animation_host_.get());
884 layer_tree_ = layer_tree_host_->GetLayerTree();
885 host_impl_.SetVisible(true); 882 host_impl_.SetVisible(true);
886 EXPECT_TRUE(host_impl_.InitializeRenderer(compositor_frame_sink_.get())); 883 EXPECT_TRUE(host_impl_.InitializeRenderer(compositor_frame_sink_.get()));
887 } 884 }
888 885
889 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) { 886 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) {
890 bool will_draw = layer->WillDraw( 887 bool will_draw = layer->WillDraw(
891 mode, host_impl_.active_tree()->resource_provider()); 888 mode, host_impl_.active_tree()->resource_provider());
892 if (will_draw) 889 if (will_draw)
893 layer->DidDraw(host_impl_.active_tree()->resource_provider()); 890 layer->DidDraw(host_impl_.active_tree()->resource_provider());
894 return will_draw; 891 return will_draw;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 void SetupTree() override { 1101 void SetupTree() override {
1105 scoped_refptr<Layer> root = Layer::Create(); 1102 scoped_refptr<Layer> root = Layer::Create();
1106 root->SetBounds(gfx::Size(10, 10)); 1103 root->SetBounds(gfx::Size(10, 10));
1107 root->SetIsDrawable(true); 1104 root->SetIsDrawable(true);
1108 1105
1109 texture_layer_ = TextureLayer::CreateForMailbox(this); 1106 texture_layer_ = TextureLayer::CreateForMailbox(this);
1110 texture_layer_->SetBounds(gfx::Size(10, 10)); 1107 texture_layer_->SetBounds(gfx::Size(10, 10));
1111 texture_layer_->SetIsDrawable(true); 1108 texture_layer_->SetIsDrawable(true);
1112 root->AddChild(texture_layer_); 1109 root->AddChild(texture_layer_);
1113 1110
1114 layer_tree()->SetRootLayer(root); 1111 layer_tree_host()->SetRootLayer(root);
1115 LayerTreeTest::SetupTree(); 1112 LayerTreeTest::SetupTree();
1116 } 1113 }
1117 1114
1118 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1115 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1119 1116
1120 void DidCommitAndDrawFrame() override { 1117 void DidCommitAndDrawFrame() override {
1121 switch (layer_tree_host()->SourceFrameNumber()) { 1118 switch (layer_tree_host()->SourceFrameNumber()) {
1122 case 1: 1119 case 1:
1123 EXPECT_FALSE(proxy()->MainFrameWillHappenForTesting()); 1120 EXPECT_FALSE(proxy()->MainFrameWillHappenForTesting());
1124 // Invalidate the texture layer to clear the mailbox before 1121 // Invalidate the texture layer to clear the mailbox before
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 parent_layer_ = Layer::Create(); 1192 parent_layer_ = Layer::Create();
1196 parent_layer_->SetBounds(gfx::Size(10, 10)); 1193 parent_layer_->SetBounds(gfx::Size(10, 10));
1197 parent_layer_->SetIsDrawable(true); 1194 parent_layer_->SetIsDrawable(true);
1198 root->AddChild(parent_layer_); 1195 root->AddChild(parent_layer_);
1199 1196
1200 texture_layer_ = TextureLayer::CreateForMailbox(this); 1197 texture_layer_ = TextureLayer::CreateForMailbox(this);
1201 texture_layer_->SetBounds(gfx::Size(10, 10)); 1198 texture_layer_->SetBounds(gfx::Size(10, 10));
1202 texture_layer_->SetIsDrawable(true); 1199 texture_layer_->SetIsDrawable(true);
1203 parent_layer_->AddChild(texture_layer_); 1200 parent_layer_->AddChild(texture_layer_);
1204 1201
1205 layer_tree()->SetRootLayer(root); 1202 layer_tree_host()->SetRootLayer(root);
1206 LayerTreeTest::SetupTree(); 1203 LayerTreeTest::SetupTree();
1207 } 1204 }
1208 1205
1209 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1206 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1210 1207
1211 void DidCommitAndDrawFrame() override { 1208 void DidCommitAndDrawFrame() override {
1212 ++commit_count_; 1209 ++commit_count_;
1213 switch (commit_count_) { 1210 switch (commit_count_) {
1214 case 1: 1211 case 1:
1215 // We should have updated the layer, committing the texture. 1212 // We should have updated the layer, committing the texture.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 } 1289 }
1293 1290
1294 void SetupTree() override { 1291 void SetupTree() override {
1295 LayerTreeTest::SetupTree(); 1292 LayerTreeTest::SetupTree();
1296 1293
1297 scoped_refptr<TextureLayer> texture_layer = 1294 scoped_refptr<TextureLayer> texture_layer =
1298 TextureLayer::CreateForMailbox(this); 1295 TextureLayer::CreateForMailbox(this);
1299 texture_layer->SetBounds(gfx::Size(10, 10)); 1296 texture_layer->SetBounds(gfx::Size(10, 10));
1300 texture_layer->SetIsDrawable(true); 1297 texture_layer->SetIsDrawable(true);
1301 1298
1302 layer_tree()->root_layer()->AddChild(texture_layer); 1299 layer_tree_host()->root_layer()->AddChild(texture_layer);
1303 texture_layer_id_ = texture_layer->id(); 1300 texture_layer_id_ = texture_layer->id();
1304 } 1301 }
1305 1302
1306 void BeginTest() override { 1303 void BeginTest() override {
1307 mailbox_released_ = false; 1304 mailbox_released_ = false;
1308 PostSetNeedsCommitToMainThread(); 1305 PostSetNeedsCommitToMainThread();
1309 } 1306 }
1310 1307
1311 void DidCommitAndDrawFrame() override { EndTest(); } 1308 void DidCommitAndDrawFrame() override { EndTest(); }
1312 1309
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 void SetupTree() override { 1363 void SetupTree() override {
1367 gfx::Size bounds(100, 100); 1364 gfx::Size bounds(100, 100);
1368 root_ = Layer::Create(); 1365 root_ = Layer::Create();
1369 root_->SetBounds(bounds); 1366 root_->SetBounds(bounds);
1370 1367
1371 layer_ = TextureLayer::CreateForMailbox(nullptr); 1368 layer_ = TextureLayer::CreateForMailbox(nullptr);
1372 layer_->SetIsDrawable(true); 1369 layer_->SetIsDrawable(true);
1373 layer_->SetBounds(bounds); 1370 layer_->SetBounds(bounds);
1374 1371
1375 root_->AddChild(layer_); 1372 root_->AddChild(layer_);
1376 layer_tree()->SetRootLayer(root_); 1373 layer_tree_host()->SetRootLayer(root_);
1377 layer_tree()->SetViewportSize(bounds); 1374 layer_tree_host()->SetViewportSize(bounds);
1378 } 1375 }
1379 1376
1380 void BeginTest() override { 1377 void BeginTest() override {
1381 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); 1378 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1382 1379
1383 callback_count_ = 0; 1380 callback_count_ = 0;
1384 1381
1385 // Set the mailbox on the main thread. 1382 // Set the mailbox on the main thread.
1386 SetMailbox('1'); 1383 SetMailbox('1');
1387 EXPECT_EQ(0, callback_count_); 1384 EXPECT_EQ(0, callback_count_);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 void SetupTree() override { 1433 void SetupTree() override {
1437 gfx::Size bounds(100, 100); 1434 gfx::Size bounds(100, 100);
1438 root_ = Layer::Create(); 1435 root_ = Layer::Create();
1439 root_->SetBounds(bounds); 1436 root_->SetBounds(bounds);
1440 1437
1441 layer_ = TextureLayer::CreateForMailbox(nullptr); 1438 layer_ = TextureLayer::CreateForMailbox(nullptr);
1442 layer_->SetIsDrawable(true); 1439 layer_->SetIsDrawable(true);
1443 layer_->SetBounds(bounds); 1440 layer_->SetBounds(bounds);
1444 1441
1445 root_->AddChild(layer_); 1442 root_->AddChild(layer_);
1446 layer_tree()->SetRootLayer(root_); 1443 layer_tree_host()->SetRootLayer(root_);
1447 layer_tree()->SetViewportSize(bounds); 1444 layer_tree_host()->SetViewportSize(bounds);
1448 } 1445 }
1449 1446
1450 void BeginTest() override { 1447 void BeginTest() override {
1451 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); 1448 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1452 1449
1453 callback_count_ = 0; 1450 callback_count_ = 0;
1454 1451
1455 // Set the mailbox on the main thread. 1452 // Set the mailbox on the main thread.
1456 SetMailbox('1'); 1453 SetMailbox('1');
1457 EXPECT_EQ(0, callback_count_); 1454 EXPECT_EQ(0, callback_count_);
(...skipping 21 matching lines...) Expand all
1479 base::ThreadChecker main_thread_; 1476 base::ThreadChecker main_thread_;
1480 int callback_count_; 1477 int callback_count_;
1481 scoped_refptr<Layer> root_; 1478 scoped_refptr<Layer> root_;
1482 scoped_refptr<TextureLayer> layer_; 1479 scoped_refptr<TextureLayer> layer_;
1483 }; 1480 };
1484 1481
1485 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); 1482 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted);
1486 1483
1487 } // namespace 1484 } // namespace
1488 } // namespace cc 1485 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/surface_layer_unittest.cc ('k') | cc/layers/ui_resource_layer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698