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

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

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

Powered by Google App Engine
This is Rietveld 408576698