OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include "base/synchronization/lock.h" | 7 #include "base/synchronization/lock.h" |
8 #include "cc/animation/timing_function.h" | 8 #include "cc/animation/timing_function.h" |
9 #include "cc/layers/content_layer.h" | 9 #include "cc/layers/content_layer.h" |
10 #include "cc/layers/content_layer_client.h" | 10 #include "cc/layers/content_layer_client.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 { | 135 { |
136 } | 136 } |
137 | 137 |
138 virtual void BeginTest() OVERRIDE | 138 virtual void BeginTest() OVERRIDE |
139 { | 139 { |
140 PostSetNeedsCommitToMainThread(); | 140 PostSetNeedsCommitToMainThread(); |
141 } | 141 } |
142 | 142 |
143 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 143 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE |
144 { | 144 { |
| 145 ++m_numDraws; |
| 146 } |
| 147 |
| 148 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 149 { |
| 150 m_numCommits++; |
| 151 |
145 if (impl->active_tree()->source_frame_number() == 0) | 152 if (impl->active_tree()->source_frame_number() == 0) |
146 PostSetNeedsCommitToMainThread(); | 153 PostSetNeedsCommitToMainThread(); |
147 else if (impl->active_tree()->source_frame_number() == 1) | 154 else if (impl->active_tree()->source_frame_number() == 1) |
148 EndTest(); | 155 EndTest(); |
149 } | 156 } |
150 | 157 |
151 virtual void CommitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | |
152 { | |
153 m_numCommits++; | |
154 } | |
155 | |
156 virtual void AfterTest() OVERRIDE | 158 virtual void AfterTest() OVERRIDE |
157 { | 159 { |
158 EXPECT_EQ(2, m_numCommits); | 160 EXPECT_EQ(2, m_numCommits); |
159 EXPECT_GE(2, m_numDraws); | 161 EXPECT_EQ(1, m_numDraws); |
160 } | 162 } |
161 | 163 |
162 private: | 164 private: |
163 int m_numCommits; | 165 int m_numCommits; |
164 int m_numDraws; | 166 int m_numDraws; |
165 }; | 167 }; |
166 | 168 |
167 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2) | 169 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2) |
168 | 170 |
169 // 1 setNeedsRedraw after the first commit has completed should lead to 1 | 171 // 1 setNeedsRedraw after the first commit has completed should lead to 1 |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 | 835 |
834 LayerImpl* root = impl->active_tree()->root_layer(); | 836 LayerImpl* root = impl->active_tree()->root_layer(); |
835 LayerImpl* child = impl->active_tree()->root_layer()->children()[0]; | 837 LayerImpl* child = impl->active_tree()->root_layer()->children()[0]; |
836 | 838 |
837 // Positions remain in layout pixels. | 839 // Positions remain in layout pixels. |
838 EXPECT_EQ(gfx::Point(0, 0), root->position()); | 840 EXPECT_EQ(gfx::Point(0, 0), root->position()); |
839 EXPECT_EQ(gfx::Point(2, 2), child->position()); | 841 EXPECT_EQ(gfx::Point(2, 2), child->position()); |
840 | 842 |
841 // Compute all the layer transforms for the frame. | 843 // Compute all the layer transforms for the frame. |
842 LayerTreeHostImpl::FrameData frameData; | 844 LayerTreeHostImpl::FrameData frameData; |
843 impl->PrepareToDraw(&frameData); | 845 impl->PrepareToDraw(&frameData, gfx::Rect()); |
844 impl->DidDrawAllLayers(frameData); | 846 impl->DidDrawAllLayers(frameData); |
845 | 847 |
846 const LayerTreeHostImpl::LayerList& renderSurfaceLayerList = | 848 const LayerTreeHostImpl::LayerList& renderSurfaceLayerList = |
847 *frameData.render_surface_layer_list; | 849 *frameData.render_surface_layer_list; |
848 | 850 |
849 // Both layers should be drawing into the root render surface. | 851 // Both layers should be drawing into the root render surface. |
850 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | 852 ASSERT_EQ(1u, renderSurfaceLayerList.size()); |
851 ASSERT_EQ(root->render_surface(), renderSurfaceLayerList[0]->render_surf
ace()); | 853 ASSERT_EQ(root->render_surface(), renderSurfaceLayerList[0]->render_surf
ace()); |
852 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); | 854 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
853 | 855 |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 virtual void AfterTest() OVERRIDE | 1283 virtual void AfterTest() OVERRIDE |
1282 { | 1284 { |
1283 } | 1285 } |
1284 }; | 1286 }; |
1285 | 1287 |
1286 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackCleanup) | 1288 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackCleanup) |
1287 | 1289 |
1288 class LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit : public L
ayerTreeHostTest { | 1290 class LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit : public L
ayerTreeHostTest { |
1289 public: | 1291 public: |
1290 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit() | 1292 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit() |
1291 : m_rootLayer(ContentLayerWithUpdateTracking::Create(&m_fakeDelegate)) | 1293 : m_rootLayer(FakeContentLayer::Create(&m_client)) |
1292 , m_surfaceLayer1(ContentLayerWithUpdateTracking::Create(&m_fakeDelegate
)) | 1294 , m_surfaceLayer1(FakeContentLayer::Create(&m_client)) |
1293 , m_replicaLayer1(ContentLayerWithUpdateTracking::Create(&m_fakeDelegate
)) | 1295 , m_replicaLayer1(FakeContentLayer::Create(&m_client)) |
1294 , m_surfaceLayer2(ContentLayerWithUpdateTracking::Create(&m_fakeDelegate
)) | 1296 , m_surfaceLayer2(FakeContentLayer::Create(&m_client)) |
1295 , m_replicaLayer2(ContentLayerWithUpdateTracking::Create(&m_fakeDelegate
)) | 1297 , m_replicaLayer2(FakeContentLayer::Create(&m_client)) |
1296 { | 1298 { |
1297 } | 1299 } |
1298 | 1300 |
1299 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE | 1301 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE |
1300 { | 1302 { |
1301 settings->cache_render_pass_contents = true; | 1303 settings->cache_render_pass_contents = true; |
1302 } | 1304 } |
1303 | 1305 |
1304 virtual void BeginTest() OVERRIDE | 1306 virtual void BeginTest() OVERRIDE |
1305 { | 1307 { |
1306 layer_tree_host()->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 1
00)); | 1308 layer_tree_host()->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 1
00)); |
1307 | 1309 |
1308 m_rootLayer->SetBounds(gfx::Size(100, 100)); | 1310 m_rootLayer->SetBounds(gfx::Size(100, 100)); |
| 1311 m_rootLayer->SetIsDrawable(true); |
1309 m_surfaceLayer1->SetBounds(gfx::Size(100, 100)); | 1312 m_surfaceLayer1->SetBounds(gfx::Size(100, 100)); |
1310 m_surfaceLayer1->SetForceRenderSurface(true); | 1313 m_surfaceLayer1->SetForceRenderSurface(true); |
1311 m_surfaceLayer1->SetOpacity(0.5); | 1314 m_surfaceLayer1->SetOpacity(0.5); |
| 1315 m_surfaceLayer1->SetIsDrawable(true); |
1312 m_surfaceLayer2->SetBounds(gfx::Size(100, 100)); | 1316 m_surfaceLayer2->SetBounds(gfx::Size(100, 100)); |
1313 m_surfaceLayer2->SetForceRenderSurface(true); | 1317 m_surfaceLayer2->SetForceRenderSurface(true); |
1314 m_surfaceLayer2->SetOpacity(0.5); | 1318 m_surfaceLayer2->SetOpacity(0.5); |
| 1319 m_surfaceLayer2->SetIsDrawable(true); |
1315 | 1320 |
1316 m_surfaceLayer1->SetReplicaLayer(m_replicaLayer1.get()); | 1321 m_surfaceLayer1->SetReplicaLayer(m_replicaLayer1.get()); |
1317 m_surfaceLayer2->SetReplicaLayer(m_replicaLayer2.get()); | 1322 m_surfaceLayer2->SetReplicaLayer(m_replicaLayer2.get()); |
1318 | 1323 |
1319 m_rootLayer->AddChild(m_surfaceLayer1); | 1324 m_rootLayer->AddChild(m_surfaceLayer1); |
1320 m_surfaceLayer1->AddChild(m_surfaceLayer2); | 1325 m_surfaceLayer1->AddChild(m_surfaceLayer2); |
1321 layer_tree_host()->SetRootLayer(m_rootLayer); | 1326 layer_tree_host()->SetRootLayer(m_rootLayer); |
1322 | 1327 |
1323 PostSetNeedsCommitToMainThread(); | 1328 PostSetNeedsCommitToMainThread(); |
1324 } | 1329 } |
1325 | 1330 |
1326 virtual void DrawLayersOnThread(LayerTreeHostImpl* hostImpl) OVERRIDE | 1331 virtual void DrawLayersOnThread(LayerTreeHostImpl* hostImpl) OVERRIDE |
1327 { | 1332 { |
1328 Renderer* renderer = hostImpl->renderer(); | 1333 Renderer* renderer = hostImpl->renderer(); |
1329 RenderPass::Id surface1RenderPassId = hostImpl->active_tree()->root_laye
r()->children()[0]->render_surface()->RenderPassId(); | 1334 RenderPass::Id surface1RenderPassId = hostImpl->active_tree()->root_laye
r()->children()[0]->render_surface()->RenderPassId(); |
1330 RenderPass::Id surface2RenderPassId = hostImpl->active_tree()->root_laye
r()->children()[0]->children()[0]->render_surface()->RenderPassId(); | 1335 RenderPass::Id surface2RenderPassId = hostImpl->active_tree()->root_laye
r()->children()[0]->children()[0]->render_surface()->RenderPassId(); |
1331 | 1336 |
1332 switch (hostImpl->active_tree()->source_frame_number()) { | 1337 int source_frame = hostImpl->active_tree()->source_frame_number(); |
| 1338 switch (source_frame) { |
1333 case 0: | 1339 case 0: |
1334 EXPECT_TRUE(renderer->HaveCachedResourcesForRenderPassId(surface1Ren
derPassId)); | 1340 EXPECT_TRUE(renderer->HaveCachedResourcesForRenderPassId(surface1Ren
derPassId)); |
1335 EXPECT_TRUE(renderer->HaveCachedResourcesForRenderPassId(surface2Ren
derPassId)); | 1341 EXPECT_TRUE(renderer->HaveCachedResourcesForRenderPassId(surface2Ren
derPassId)); |
1336 | 1342 |
1337 // Reduce the memory limit to only fit the root layer and one render
surface. This | 1343 // Reduce the memory limit to only fit the root layer and one render
surface. This |
1338 // prevents any contents drawing into surfaces from being allocated. | 1344 // prevents any contents drawing into surfaces from being allocated. |
1339 hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy(100 * 100 * 4 *
2)); | 1345 hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy(100 * 100 * 4 *
2)); |
1340 break; | 1346 break; |
1341 case 1: | 1347 case 1: |
1342 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId(surface1Re
nderPassId)); | 1348 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId(surface1Re
nderPassId)); |
1343 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId(surface2Re
nderPassId)); | 1349 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId(surface2Re
nderPassId)); |
1344 | 1350 |
1345 EndTest(); | 1351 EndTest(); |
1346 break; | 1352 break; |
1347 } | 1353 } |
1348 } | 1354 } |
1349 | 1355 |
| 1356 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1357 if (!TestEnded()) |
| 1358 m_rootLayer->SetNeedsDisplay(); |
| 1359 } |
| 1360 |
1350 virtual void AfterTest() OVERRIDE | 1361 virtual void AfterTest() OVERRIDE |
1351 { | 1362 { |
1352 EXPECT_EQ(2, m_rootLayer->paintContentsCount()); | 1363 EXPECT_EQ(3, m_rootLayer->update_count()); |
1353 EXPECT_EQ(2, m_surfaceLayer1->paintContentsCount()); | 1364 EXPECT_EQ(3, m_surfaceLayer1->update_count()); |
1354 EXPECT_EQ(2, m_surfaceLayer2->paintContentsCount()); | 1365 EXPECT_EQ(3, m_surfaceLayer2->update_count()); |
1355 | |
1356 // Clear layer references so LayerTreeHost dies. | |
1357 m_rootLayer = NULL; | |
1358 m_surfaceLayer1 = NULL; | |
1359 m_replicaLayer1 = NULL; | |
1360 m_surfaceLayer2 = NULL; | |
1361 m_replicaLayer2 = NULL; | |
1362 } | 1366 } |
1363 | 1367 |
1364 private: | 1368 private: |
1365 FakeContentLayerClient m_fakeDelegate; | 1369 FakeContentLayerClient m_client; |
1366 scoped_refptr<ContentLayerWithUpdateTracking> m_rootLayer; | 1370 scoped_refptr<FakeContentLayer> m_rootLayer; |
1367 scoped_refptr<ContentLayerWithUpdateTracking> m_surfaceLayer1; | 1371 scoped_refptr<FakeContentLayer> m_surfaceLayer1; |
1368 scoped_refptr<ContentLayerWithUpdateTracking> m_replicaLayer1; | 1372 scoped_refptr<FakeContentLayer> m_replicaLayer1; |
1369 scoped_refptr<ContentLayerWithUpdateTracking> m_surfaceLayer2; | 1373 scoped_refptr<FakeContentLayer> m_surfaceLayer2; |
1370 scoped_refptr<ContentLayerWithUpdateTracking> m_replicaLayer2; | 1374 scoped_refptr<FakeContentLayer> m_replicaLayer2; |
1371 }; | 1375 }; |
1372 | 1376 |
1373 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSurfaceNotAllocatedForLayersOuts
ideMemoryLimit) | 1377 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSurfaceNotAllocatedForLayersOuts
ideMemoryLimit) |
1374 | 1378 |
1375 class EvictionTestLayer : public Layer { | 1379 class EvictionTestLayer : public Layer { |
1376 public: | 1380 public: |
1377 static scoped_refptr<EvictionTestLayer> Create() { return make_scoped_refptr
(new EvictionTestLayer()); } | 1381 static scoped_refptr<EvictionTestLayer> Create() { return make_scoped_refptr
(new EvictionTestLayer()); } |
1378 | 1382 |
1379 virtual void Update(ResourceUpdateQueue*, const OcclusionTracker*, Rendering
Stats*) OVERRIDE; | 1383 virtual void Update(ResourceUpdateQueue*, const OcclusionTracker*, Rendering
Stats*) OVERRIDE; |
1380 virtual bool DrawsContent() const OVERRIDE { return true; } | 1384 virtual bool DrawsContent() const OVERRIDE { return true; } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 // Commit 6: Triggered by the eviction, post an eviction task in | 1512 // Commit 6: Triggered by the eviction, post an eviction task in |
1509 // Layout(), which will be a noop, letting the commit (which recreates the | 1513 // Layout(), which will be a noop, letting the commit (which recreates the |
1510 // textures) go through and draw a frame, then end the test. | 1514 // textures) go through and draw a frame, then end the test. |
1511 // | 1515 // |
1512 // Commits 1+2 test the eviction recovery path where eviction happens outsid
e | 1516 // Commits 1+2 test the eviction recovery path where eviction happens outsid
e |
1513 // of the beginFrame/commit pair. | 1517 // of the beginFrame/commit pair. |
1514 // Commits 3+4 test the eviction recovery path where eviction happens inside | 1518 // Commits 3+4 test the eviction recovery path where eviction happens inside |
1515 // the beginFrame/commit pair. | 1519 // the beginFrame/commit pair. |
1516 // Commits 5+6 test the path where an eviction happens during the eviction | 1520 // Commits 5+6 test the path where an eviction happens during the eviction |
1517 // recovery path. | 1521 // recovery path. |
1518 virtual void DidCommitAndDrawFrame() OVERRIDE | 1522 virtual void DidCommit() OVERRIDE |
1519 { | 1523 { |
1520 switch (m_numCommits) { | 1524 switch (m_numCommits) { |
1521 case 1: | 1525 case 1: |
1522 EXPECT_TRUE(m_layer->haveBackingTexture()); | 1526 EXPECT_TRUE(m_layer->haveBackingTexture()); |
1523 postEvictTextures(); | 1527 postEvictTextures(); |
1524 break; | 1528 break; |
1525 case 2: | 1529 case 2: |
1526 EXPECT_TRUE(m_layer->haveBackingTexture()); | 1530 EXPECT_TRUE(m_layer->haveBackingTexture()); |
1527 layer_tree_host()->SetNeedsCommit(); | 1531 layer_tree_host()->SetNeedsCommit(); |
1528 break; | 1532 break; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10))
; | 1607 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10))
; |
1604 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); | 1608 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); |
1605 | 1609 |
1606 PostSetNeedsCommitToMainThread(); | 1610 PostSetNeedsCommitToMainThread(); |
1607 } | 1611 } |
1608 | 1612 |
1609 virtual void DidCommit() OVERRIDE | 1613 virtual void DidCommit() OVERRIDE |
1610 { | 1614 { |
1611 if (m_numDrawLayers == 2) | 1615 if (m_numDrawLayers == 2) |
1612 return; | 1616 return; |
1613 PostSetNeedsCommitToMainThread(); | 1617 layer_tree_host()->root_layer()->SetNeedsDisplay(); |
1614 } | 1618 } |
1615 | 1619 |
1616 virtual void CommitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | 1620 virtual void CommitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE |
1617 { | 1621 { |
1618 if (m_numDrawLayers == 1) | 1622 if (m_numDrawLayers == 1) |
1619 m_numCommitComplete++; | 1623 m_numCommitComplete++; |
1620 } | 1624 } |
1621 | 1625 |
1622 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 1626 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE |
1623 { | 1627 { |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2344 } | 2348 } |
2345 | 2349 |
2346 private: | 2350 private: |
2347 NotificationClient client_; | 2351 NotificationClient client_; |
2348 }; | 2352 }; |
2349 | 2353 |
2350 SINGLE_THREAD_TEST_F(LayerTreeHostTestLCDNotification) | 2354 SINGLE_THREAD_TEST_F(LayerTreeHostTestLCDNotification) |
2351 | 2355 |
2352 } // namespace | 2356 } // namespace |
2353 } // namespace cc | 2357 } // namespace cc |
OLD | NEW |