| 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/layer_tree_host.h" | 5 #include "cc/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "base/synchronization/lock.h" | 7 #include "base/synchronization/lock.h" |
| 8 #include "cc/content_layer.h" | 8 #include "cc/content_layer.h" |
| 9 #include "cc/content_layer_client.h" | 9 #include "cc/content_layer_client.h" |
| 10 #include "cc/layer_impl.h" | 10 #include "cc/layer_impl.h" |
| 11 #include "cc/layer_tree_host_impl.h" | 11 #include "cc/layer_tree_host_impl.h" |
| 12 #include "cc/layer_tree_impl.h" | 12 #include "cc/layer_tree_impl.h" |
| 13 #include "cc/output_surface.h" | 13 #include "cc/output_surface.h" |
| 14 #include "cc/scrollbar_layer.h" |
| 14 #include "cc/single_thread_proxy.h" | 15 #include "cc/single_thread_proxy.h" |
| 15 #include "cc/test/fake_content_layer_client.h" | 16 #include "cc/test/fake_content_layer_client.h" |
| 16 #include "cc/test/fake_layer_tree_host_client.h" | 17 #include "cc/test/fake_layer_tree_host_client.h" |
| 17 #include "cc/test/fake_output_surface.h" | 18 #include "cc/test/fake_output_surface.h" |
| 18 #include "cc/test/fake_proxy.h" | 19 #include "cc/test/fake_proxy.h" |
| 20 #include "cc/test/fake_scrollbar_theme_painter.h" |
| 21 #include "cc/test/fake_web_scrollbar.h" |
| 22 #include "cc/test/fake_web_scrollbar_theme_geometry.h" |
| 19 #include "cc/test/geometry_test_utils.h" | 23 #include "cc/test/geometry_test_utils.h" |
| 20 #include "cc/test/layer_tree_test_common.h" | 24 #include "cc/test/layer_tree_test_common.h" |
| 21 #include "cc/test/occlusion_tracker_test_common.h" | 25 #include "cc/test/occlusion_tracker_test_common.h" |
| 22 #include "cc/resource_update_queue.h" | 26 #include "cc/resource_update_queue.h" |
| 23 #include "cc/timing_function.h" | 27 #include "cc/timing_function.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "third_party/khronos/GLES2/gl2.h" | 29 #include "third_party/khronos/GLES2/gl2.h" |
| 26 #include "third_party/khronos/GLES2/gl2ext.h" | 30 #include "third_party/khronos/GLES2/gl2ext.h" |
| 27 #include "ui/gfx/point_conversions.h" | 31 #include "ui/gfx/point_conversions.h" |
| 28 #include "ui/gfx/size_conversions.h" | 32 #include "ui/gfx/size_conversions.h" |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 setBounds(gfx::Size(10, 10)); | 1169 setBounds(gfx::Size(10, 10)); |
| 1166 setIsDrawable(true); | 1170 setIsDrawable(true); |
| 1167 } | 1171 } |
| 1168 virtual ~ContentLayerWithUpdateTracking() | 1172 virtual ~ContentLayerWithUpdateTracking() |
| 1169 { | 1173 { |
| 1170 } | 1174 } |
| 1171 | 1175 |
| 1172 int m_paintContentsCount; | 1176 int m_paintContentsCount; |
| 1173 }; | 1177 }; |
| 1174 | 1178 |
| 1179 class ScrollbarLayerWithUpdateTracking : public ScrollbarLayer { |
| 1180 public: |
| 1181 static scoped_refptr<ScrollbarLayerWithUpdateTracking> create(int scrollLaye
rId, bool paintContentsDuringUpdate) |
| 1182 { |
| 1183 return make_scoped_refptr(new ScrollbarLayerWithUpdateTracking(scrollLay
erId, paintContentsDuringUpdate)); |
| 1184 } |
| 1185 |
| 1186 int updateCount() { return m_updateCount; } |
| 1187 void resetUpdateCount() { m_updateCount = 0; } |
| 1188 |
| 1189 virtual void update(ResourceUpdateQueue& queue, const OcclusionTracker* occl
usion, RenderingStats& stats) OVERRIDE |
| 1190 { |
| 1191 ScrollbarLayer::update(queue, occlusion, stats); |
| 1192 m_updateCount++; |
| 1193 } |
| 1194 |
| 1195 private: |
| 1196 explicit ScrollbarLayerWithUpdateTracking(int scrollLayerId, bool paintConte
ntsDuringUpdate) |
| 1197 : ScrollbarLayer( |
| 1198 FakeWebScrollbar::create().PassAs<WebKit::WebScrollbar>(), |
| 1199 FakeScrollbarThemePainter::Create(paintContentsDuringUpdate).PassAs<
ScrollbarThemePainter>(), |
| 1200 FakeWebScrollbarThemeGeometry::create().PassAs<WebKit::WebScrollbarT
hemeGeometry>(), |
| 1201 scrollLayerId) |
| 1202 , m_updateCount(0) |
| 1203 { |
| 1204 setAnchorPoint(gfx::PointF(0, 0)); |
| 1205 setBounds(gfx::Size(10, 10)); |
| 1206 setIsDrawable(true); |
| 1207 } |
| 1208 virtual ~ScrollbarLayerWithUpdateTracking() |
| 1209 { |
| 1210 } |
| 1211 |
| 1212 int m_updateCount; |
| 1213 }; |
| 1214 |
| 1175 // Layer opacity change during paint should not prevent compositor resources fro
m being updated during commit. | 1215 // Layer opacity change during paint should not prevent compositor resources fro
m being updated during commit. |
| 1176 class LayerTreeHostTestOpacityChange : public LayerTreeHostTest { | 1216 class LayerTreeHostTestOpacityChange : public LayerTreeHostTest { |
| 1177 public: | 1217 public: |
| 1178 LayerTreeHostTestOpacityChange() | 1218 LayerTreeHostTestOpacityChange() |
| 1179 : m_testOpacityChangeDelegate() | 1219 : m_testOpacityChangeDelegate() |
| 1180 , m_updateCheckLayer(ContentLayerWithUpdateTracking::create(&m_testOpaci
tyChangeDelegate)) | 1220 , m_updateCheckLayer(ContentLayerWithUpdateTracking::create(&m_testOpaci
tyChangeDelegate)) |
| 1181 { | 1221 { |
| 1182 m_testOpacityChangeDelegate.setTestLayer(m_updateCheckLayer.get()); | 1222 m_testOpacityChangeDelegate.setTestLayer(m_updateCheckLayer.get()); |
| 1183 } | 1223 } |
| 1184 | 1224 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1391 TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers, FLAKY_runMulti
Thread) | 1431 TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers, FLAKY_runMulti
Thread) |
| 1392 { | 1432 { |
| 1393 runTest(true); | 1433 runTest(true); |
| 1394 } | 1434 } |
| 1395 | 1435 |
| 1396 // Verify atomicity of commits and reuse of textures. | 1436 // Verify atomicity of commits and reuse of textures. |
| 1397 class LayerTreeHostTestAtomicCommit : public LayerTreeHostTest { | 1437 class LayerTreeHostTestAtomicCommit : public LayerTreeHostTest { |
| 1398 public: | 1438 public: |
| 1399 LayerTreeHostTestAtomicCommit() | 1439 LayerTreeHostTestAtomicCommit() |
| 1400 : m_layer(ContentLayerWithUpdateTracking::create(&m_client)) | 1440 : m_layer(ContentLayerWithUpdateTracking::create(&m_client)) |
| 1441 , m_scrollbar(ScrollbarLayerWithUpdateTracking::create(m_layer->id(), tr
ue)) |
| 1401 { | 1442 { |
| 1402 // Make sure partial texture updates are turned off. | 1443 // Make sure partial texture updates are turned off. |
| 1403 m_settings.maxPartialTextureUpdates = 0; | 1444 m_settings.maxPartialTextureUpdates = 0; |
| 1404 } | 1445 } |
| 1405 | 1446 |
| 1406 virtual void beginTest() OVERRIDE | 1447 virtual void beginTest() OVERRIDE |
| 1407 { | 1448 { |
| 1449 m_layer->addChild(m_scrollbar); |
| 1408 m_layerTreeHost->setRootLayer(m_layer); | 1450 m_layerTreeHost->setRootLayer(m_layer); |
| 1409 m_layerTreeHost->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); | 1451 m_layerTreeHost->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); |
| 1410 | 1452 |
| 1411 ASSERT_TRUE(m_layerTreeHost->initializeRendererIfNeeded()); | 1453 ASSERT_TRUE(m_layerTreeHost->initializeRendererIfNeeded()); |
| 1412 ResourceUpdateQueue queue; | 1454 ResourceUpdateQueue queue; |
| 1413 m_layerTreeHost->updateLayers(queue, std::numeric_limits<size_t>::max())
; | 1455 m_layerTreeHost->updateLayers(queue, std::numeric_limits<size_t>::max())
; |
| 1414 postSetNeedsCommitToMainThread(); | 1456 postSetNeedsCommitToMainThread(); |
| 1415 postSetNeedsRedrawToMainThread(); | 1457 postSetNeedsRedrawToMainThread(); |
| 1416 } | 1458 } |
| 1417 | 1459 |
| 1418 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 1460 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 1419 { | 1461 { |
| 1420 CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_
cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(impl->outputSurface
()->Context3D()); | 1462 CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_
cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(impl->outputSurface
()->Context3D()); |
| 1421 | 1463 |
| 1422 switch (impl->activeTree()->source_frame_number()) { | 1464 switch (impl->activeTree()->source_frame_number()) { |
| 1423 case 0: | 1465 case 0: |
| 1424 // Number of textures should be one. | 1466 // Number of textures should be one for each layer |
| 1425 ASSERT_EQ(1, context->numTextures()); | 1467 ASSERT_EQ(2, context->numTextures()); |
| 1426 // Number of textures used for commit should be one. | 1468 // Number of textures used for commit should be one for each layer. |
| 1427 EXPECT_EQ(1, context->numUsedTextures()); | 1469 EXPECT_EQ(2, context->numUsedTextures()); |
| 1428 // Verify that used texture is correct. | 1470 // Verify that used texture is correct. |
| 1429 EXPECT_TRUE(context->usedTexture(context->texture(0))); | 1471 EXPECT_TRUE(context->usedTexture(context->texture(0))); |
| 1472 EXPECT_TRUE(context->usedTexture(context->texture(1))); |
| 1430 | 1473 |
| 1431 context->resetUsedTextures(); | 1474 context->resetUsedTextures(); |
| 1432 break; | 1475 break; |
| 1433 case 1: | 1476 case 1: |
| 1434 // Number of textures should be two as the first texture | 1477 // Number of textures should be doubled as the first textures |
| 1435 // is used by impl thread and cannot by used for update. | 1478 // are used by impl thread and cannot by used for update. |
| 1436 ASSERT_EQ(2, context->numTextures()); | 1479 ASSERT_EQ(4, context->numTextures()); |
| 1437 // Number of textures used for commit should still be one. | 1480 // Number of textures used for commit should still be one for each l
ayer. |
| 1438 EXPECT_EQ(1, context->numUsedTextures()); | 1481 EXPECT_EQ(2, context->numUsedTextures()); |
| 1439 // First texture should not have been used. | 1482 // First textures should not have been used. |
| 1440 EXPECT_FALSE(context->usedTexture(context->texture(0))); | 1483 EXPECT_FALSE(context->usedTexture(context->texture(0))); |
| 1441 // New texture should have been used. | 1484 EXPECT_FALSE(context->usedTexture(context->texture(1))); |
| 1442 EXPECT_TRUE(context->usedTexture(context->texture(1))); | 1485 // New textures should have been used. |
| 1486 EXPECT_TRUE(context->usedTexture(context->texture(2))); |
| 1487 EXPECT_TRUE(context->usedTexture(context->texture(3))); |
| 1443 | 1488 |
| 1444 context->resetUsedTextures(); | 1489 context->resetUsedTextures(); |
| 1445 break; | 1490 break; |
| 1446 default: | 1491 default: |
| 1447 NOTREACHED(); | 1492 NOTREACHED(); |
| 1448 break; | 1493 break; |
| 1449 } | 1494 } |
| 1450 } | 1495 } |
| 1451 | 1496 |
| 1452 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 1497 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 1453 { | 1498 { |
| 1454 CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_
cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(impl->outputSurface
()->Context3D()); | 1499 CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_
cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(impl->outputSurface
()->Context3D()); |
| 1455 | 1500 |
| 1456 // Number of textures used for draw should always be one. | 1501 // Number of textures used for draw should always be one for each layer. |
| 1457 EXPECT_EQ(1, context->numUsedTextures()); | 1502 EXPECT_EQ(2, context->numUsedTextures()); |
| 1458 | 1503 |
| 1459 if (impl->activeTree()->source_frame_number() < 1) { | 1504 if (impl->activeTree()->source_frame_number() < 1) { |
| 1460 context->resetUsedTextures(); | 1505 context->resetUsedTextures(); |
| 1461 postSetNeedsCommitToMainThread(); | 1506 postSetNeedsCommitToMainThread(); |
| 1462 postSetNeedsRedrawToMainThread(); | 1507 postSetNeedsRedrawToMainThread(); |
| 1463 } else | 1508 } else |
| 1464 endTest(); | 1509 endTest(); |
| 1465 } | 1510 } |
| 1466 | 1511 |
| 1467 virtual void layout() OVERRIDE | 1512 virtual void layout() OVERRIDE |
| 1468 { | 1513 { |
| 1469 m_layer->setNeedsDisplay(); | 1514 m_layer->setNeedsDisplay(); |
| 1515 m_scrollbar->setNeedsDisplay(); |
| 1470 } | 1516 } |
| 1471 | 1517 |
| 1472 virtual void afterTest() OVERRIDE | 1518 virtual void afterTest() OVERRIDE |
| 1473 { | 1519 { |
| 1474 } | 1520 } |
| 1475 | 1521 |
| 1476 private: | 1522 private: |
| 1477 FakeContentLayerClient m_client; | 1523 FakeContentLayerClient m_client; |
| 1478 scoped_refptr<ContentLayerWithUpdateTracking> m_layer; | 1524 scoped_refptr<ContentLayerWithUpdateTracking> m_layer; |
| 1525 scoped_refptr<ScrollbarLayerWithUpdateTracking> m_scrollbar; |
| 1479 }; | 1526 }; |
| 1480 | 1527 |
| 1481 TEST_F(LayerTreeHostTestAtomicCommit, runMultiThread) | 1528 TEST_F(LayerTreeHostTestAtomicCommit, runMultiThread) |
| 1482 { | 1529 { |
| 1483 runTest(true); | 1530 runTest(true); |
| 1484 } | 1531 } |
| 1485 | 1532 |
| 1486 static void setLayerPropertiesForTesting(Layer* layer, Layer* parent, const gfx:
:Transform& transform, const gfx::PointF& anchor, const gfx::PointF& position, c
onst gfx::Size& bounds, bool opaque) | 1533 static void setLayerPropertiesForTesting(Layer* layer, Layer* parent, const gfx:
:Transform& transform, const gfx::PointF& anchor, const gfx::PointF& position, c
onst gfx::Size& bounds, bool opaque) |
| 1487 { | 1534 { |
| 1488 layer->removeAllChildren(); | 1535 layer->removeAllChildren(); |
| 1489 if (parent) | 1536 if (parent) |
| 1490 parent->addChild(layer); | 1537 parent->addChild(layer); |
| 1491 layer->setTransform(transform); | 1538 layer->setTransform(transform); |
| 1492 layer->setAnchorPoint(anchor); | 1539 layer->setAnchorPoint(anchor); |
| 1493 layer->setPosition(position); | 1540 layer->setPosition(position); |
| 1494 layer->setBounds(bounds); | 1541 layer->setBounds(bounds); |
| 1495 layer->setContentsOpaque(opaque); | 1542 layer->setContentsOpaque(opaque); |
| 1496 } | 1543 } |
| 1497 | 1544 |
| 1498 class LayerTreeHostTestAtomicCommitWithPartialUpdate : public LayerTreeHostTest
{ | 1545 class LayerTreeHostTestAtomicCommitWithPartialUpdate : public LayerTreeHostTest
{ |
| 1499 public: | 1546 public: |
| 1500 LayerTreeHostTestAtomicCommitWithPartialUpdate() | 1547 LayerTreeHostTestAtomicCommitWithPartialUpdate() |
| 1501 : m_parent(ContentLayerWithUpdateTracking::create(&m_client)) | 1548 : m_parent(ContentLayerWithUpdateTracking::create(&m_client)) |
| 1502 , m_child(ContentLayerWithUpdateTracking::create(&m_client)) | 1549 , m_child(ContentLayerWithUpdateTracking::create(&m_client)) |
| 1550 , m_scrollbarWithPaints(ScrollbarLayerWithUpdateTracking::create(m_paren
t->id(), true)) |
| 1551 , m_scrollbarWithoutPaints(ScrollbarLayerWithUpdateTracking::create(m_pa
rent->id(), false)) |
| 1503 , m_numCommits(0) | 1552 , m_numCommits(0) |
| 1504 { | 1553 { |
| 1505 // Allow one partial texture update. | 1554 // Allow one partial texture update. |
| 1506 m_settings.maxPartialTextureUpdates = 1; | 1555 m_settings.maxPartialTextureUpdates = 1; |
| 1507 } | 1556 } |
| 1508 | 1557 |
| 1509 virtual void beginTest() OVERRIDE | 1558 virtual void beginTest() OVERRIDE |
| 1510 { | 1559 { |
| 1511 m_layerTreeHost->setRootLayer(m_parent); | 1560 m_layerTreeHost->setRootLayer(m_parent); |
| 1512 m_layerTreeHost->setViewportSize(gfx::Size(10, 20), gfx::Size(10, 20)); | 1561 m_layerTreeHost->setViewportSize(gfx::Size(10, 20), gfx::Size(10, 20)); |
| 1513 | 1562 |
| 1514 gfx::Transform identityMatrix; | 1563 gfx::Transform identityMatrix; |
| 1515 setLayerPropertiesForTesting(m_parent.get(), 0, identityMatrix, gfx::Poi
ntF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 20), true); | 1564 setLayerPropertiesForTesting(m_parent.get(), 0, identityMatrix, gfx::Poi
ntF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 20), true); |
| 1516 setLayerPropertiesForTesting(m_child.get(), m_parent.get(), identityMatr
ix, gfx::PointF(0, 0), gfx::PointF(0, 10), gfx::Size(10, 10), false); | 1565 setLayerPropertiesForTesting(m_child.get(), m_parent.get(), identityMatr
ix, gfx::PointF(0, 0), gfx::PointF(0, 10), gfx::Size(10, 10), false); |
| 1566 setLayerPropertiesForTesting(m_scrollbarWithPaints.get(), m_parent.get()
, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 10), gfx::Size(10, 10), fals
e); |
| 1567 setLayerPropertiesForTesting(m_scrollbarWithoutPaints.get(), m_parent.ge
t(), identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 10), gfx::Size(10, 10), f
alse); |
| 1517 | 1568 |
| 1518 ASSERT_TRUE(m_layerTreeHost->initializeRendererIfNeeded()); | 1569 ASSERT_TRUE(m_layerTreeHost->initializeRendererIfNeeded()); |
| 1519 ResourceUpdateQueue queue; | 1570 ResourceUpdateQueue queue; |
| 1520 m_layerTreeHost->updateLayers(queue, std::numeric_limits<size_t>::max())
; | 1571 m_layerTreeHost->updateLayers(queue, std::numeric_limits<size_t>::max())
; |
| 1521 postSetNeedsCommitToMainThread(); | 1572 postSetNeedsCommitToMainThread(); |
| 1522 postSetNeedsRedrawToMainThread(); | 1573 postSetNeedsRedrawToMainThread(); |
| 1523 } | 1574 } |
| 1524 | 1575 |
| 1525 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 1576 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 1526 { | 1577 { |
| 1527 CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_
cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(impl->outputSurface
()->Context3D()); | 1578 CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_
cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(impl->outputSurface
()->Context3D()); |
| 1528 | 1579 |
| 1529 switch (impl->activeTree()->source_frame_number()) { | 1580 switch (impl->activeTree()->source_frame_number()) { |
| 1530 case 0: | 1581 case 0: |
| 1531 // Number of textures should be two. | 1582 // Number of textures should be one for each layer. |
| 1532 ASSERT_EQ(2, context->numTextures()); | 1583 ASSERT_EQ(4, context->numTextures()); |
| 1533 // Number of textures used for commit should be two. | 1584 // Number of textures used for commit should be one for each layer. |
| 1534 EXPECT_EQ(2, context->numUsedTextures()); | 1585 EXPECT_EQ(4, context->numUsedTextures()); |
| 1535 // Verify that used textures are correct. | 1586 // Verify that used textures are correct. |
| 1536 EXPECT_TRUE(context->usedTexture(context->texture(0))); | 1587 EXPECT_TRUE(context->usedTexture(context->texture(0))); |
| 1537 EXPECT_TRUE(context->usedTexture(context->texture(1))); | 1588 EXPECT_TRUE(context->usedTexture(context->texture(1))); |
| 1538 | |
| 1539 context->resetUsedTextures(); | |
| 1540 break; | |
| 1541 case 1: | |
| 1542 // Number of textures used for commit should still be two. | |
| 1543 EXPECT_EQ(2, context->numUsedTextures()); | |
| 1544 // First two textures should not have been used. | |
| 1545 EXPECT_FALSE(context->usedTexture(context->texture(0))); | |
| 1546 EXPECT_FALSE(context->usedTexture(context->texture(1))); | |
| 1547 // New textures should have been used. | |
| 1548 EXPECT_TRUE(context->usedTexture(context->texture(2))); | 1589 EXPECT_TRUE(context->usedTexture(context->texture(2))); |
| 1549 EXPECT_TRUE(context->usedTexture(context->texture(3))); | 1590 EXPECT_TRUE(context->usedTexture(context->texture(3))); |
| 1550 | 1591 |
| 1551 context->resetUsedTextures(); | 1592 context->resetUsedTextures(); |
| 1552 break; | 1593 break; |
| 1553 case 2: | 1594 case 1: |
| 1554 // Number of textures used for commit should still be two. | 1595 // Number of textures should be two for each content layer and one |
| 1555 EXPECT_EQ(2, context->numUsedTextures()); | 1596 // for each scrollbar, since they always do a partial update. |
| 1597 ASSERT_EQ(6, context->numTextures()); |
| 1598 // Number of textures used for commit should be one for each content |
| 1599 // layer, and one for the scrollbar layer that paints. |
| 1600 EXPECT_EQ(3, context->numUsedTextures()); |
| 1601 |
| 1602 // First content textures should not have been used. |
| 1603 EXPECT_FALSE(context->usedTexture(context->texture(0))); |
| 1604 EXPECT_FALSE(context->usedTexture(context->texture(1))); |
| 1605 // The non-painting scrollbar's texture wasn't updated. |
| 1606 EXPECT_FALSE(context->usedTexture(context->texture(2))); |
| 1607 // The painting scrollbar's partial update texture was used. |
| 1608 EXPECT_TRUE(context->usedTexture(context->texture(3))); |
| 1609 // New textures should have been used. |
| 1610 EXPECT_TRUE(context->usedTexture(context->texture(4))); |
| 1611 EXPECT_TRUE(context->usedTexture(context->texture(5))); |
| 1556 | 1612 |
| 1557 context->resetUsedTextures(); | 1613 context->resetUsedTextures(); |
| 1558 break; | 1614 break; |
| 1615 case 2: |
| 1616 // Number of textures should be two for each content layer and one |
| 1617 // for each scrollbar, since they always do a partial update. |
| 1618 ASSERT_EQ(6, context->numTextures()); |
| 1619 // Number of textures used for commit should be one for each content |
| 1620 // layer, and one for the scrollbar layer that paints. |
| 1621 EXPECT_EQ(3, context->numUsedTextures()); |
| 1622 |
| 1623 // The non-painting scrollbar's texture wasn't updated. |
| 1624 EXPECT_FALSE(context->usedTexture(context->texture(2))); |
| 1625 // The painting scrollbar does a partial update. |
| 1626 EXPECT_TRUE(context->usedTexture(context->texture(3))); |
| 1627 // One content layer does a partial update also. |
| 1628 EXPECT_TRUE(context->usedTexture(context->texture(4))); |
| 1629 EXPECT_FALSE(context->usedTexture(context->texture(5))); |
| 1630 |
| 1631 context->resetUsedTextures(); |
| 1632 break; |
| 1559 case 3: | 1633 case 3: |
| 1560 // No textures should be used for commit. | 1634 // No textures should be used for commit. |
| 1561 EXPECT_EQ(0, context->numUsedTextures()); | 1635 EXPECT_EQ(0, context->numUsedTextures()); |
| 1562 | 1636 |
| 1563 context->resetUsedTextures(); | 1637 context->resetUsedTextures(); |
| 1564 break; | 1638 break; |
| 1565 case 4: | 1639 case 4: |
| 1566 // Number of textures used for commit should be one. | 1640 // Number of textures used for commit should be two. One for the |
| 1567 EXPECT_EQ(1, context->numUsedTextures()); | 1641 // content layer, and one for the painting scrollbar. The |
| 1642 // non-painting scrollbar doesn't update its texture. |
| 1643 EXPECT_EQ(2, context->numUsedTextures()); |
| 1568 | 1644 |
| 1569 context->resetUsedTextures(); | 1645 context->resetUsedTextures(); |
| 1570 break; | 1646 break; |
| 1571 default: | 1647 default: |
| 1572 NOTREACHED(); | 1648 NOTREACHED(); |
| 1573 break; | 1649 break; |
| 1574 } | 1650 } |
| 1575 } | 1651 } |
| 1576 | 1652 |
| 1577 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 1653 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 1578 { | 1654 { |
| 1579 CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_
cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(impl->outputSurface
()->Context3D()); | 1655 CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_
cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(impl->outputSurface
()->Context3D()); |
| 1580 | 1656 |
| 1581 // Number of textures used for drawing should two except for frame 4 | 1657 // Number of textures used for drawing should one per layer except for |
| 1582 // where the viewport only contains one layer. | 1658 // frame 3 where the viewport only contains one layer. |
| 1583 if (impl->activeTree()->source_frame_number() == 3) | 1659 if (impl->activeTree()->source_frame_number() == 3) |
| 1584 EXPECT_EQ(1, context->numUsedTextures()); | 1660 EXPECT_EQ(1, context->numUsedTextures()); |
| 1585 else | 1661 else |
| 1586 EXPECT_EQ(2, context->numUsedTextures()); | 1662 EXPECT_EQ(4, context->numUsedTextures()); |
| 1587 | 1663 |
| 1588 if (impl->activeTree()->source_frame_number() < 4) { | 1664 if (impl->activeTree()->source_frame_number() < 4) { |
| 1589 context->resetUsedTextures(); | 1665 context->resetUsedTextures(); |
| 1590 postSetNeedsCommitToMainThread(); | 1666 postSetNeedsCommitToMainThread(); |
| 1591 postSetNeedsRedrawToMainThread(); | 1667 postSetNeedsRedrawToMainThread(); |
| 1592 } else | 1668 } else |
| 1593 endTest(); | 1669 endTest(); |
| 1594 } | 1670 } |
| 1595 | 1671 |
| 1596 virtual void layout() OVERRIDE | 1672 virtual void layout() OVERRIDE |
| 1597 { | 1673 { |
| 1598 switch (m_numCommits++) { | 1674 switch (m_numCommits++) { |
| 1599 case 0: | 1675 case 0: |
| 1600 case 1: | 1676 case 1: |
| 1601 m_parent->setNeedsDisplay(); | 1677 m_parent->setNeedsDisplay(); |
| 1602 m_child->setNeedsDisplay(); | 1678 m_child->setNeedsDisplay(); |
| 1679 m_scrollbarWithPaints->setNeedsDisplay(); |
| 1680 m_scrollbarWithoutPaints->setNeedsDisplay(); |
| 1603 break; | 1681 break; |
| 1604 case 2: | 1682 case 2: |
| 1605 // Damage part of layers. | 1683 // Damage part of layers. |
| 1606 m_parent->setNeedsDisplayRect(gfx::RectF(0, 0, 5, 5)); | 1684 m_parent->setNeedsDisplayRect(gfx::RectF(0, 0, 5, 5)); |
| 1607 m_child->setNeedsDisplayRect(gfx::RectF(0, 0, 5, 5)); | 1685 m_child->setNeedsDisplayRect(gfx::RectF(0, 0, 5, 5)); |
| 1686 m_scrollbarWithPaints->setNeedsDisplayRect(gfx::RectF(0, 0, 5, 5)); |
| 1687 m_scrollbarWithoutPaints->setNeedsDisplayRect(gfx::RectF(0, 0, 5, 5)
); |
| 1608 break; | 1688 break; |
| 1609 case 3: | 1689 case 3: |
| 1610 m_child->setNeedsDisplay(); | 1690 m_child->setNeedsDisplay(); |
| 1691 m_scrollbarWithPaints->setNeedsDisplay(); |
| 1692 m_scrollbarWithoutPaints->setNeedsDisplay(); |
| 1611 m_layerTreeHost->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10
)); | 1693 m_layerTreeHost->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10
)); |
| 1612 break; | 1694 break; |
| 1613 case 4: | 1695 case 4: |
| 1614 m_layerTreeHost->setViewportSize(gfx::Size(10, 20), gfx::Size(10, 20
)); | 1696 m_layerTreeHost->setViewportSize(gfx::Size(10, 20), gfx::Size(10, 20
)); |
| 1615 break; | 1697 break; |
| 1616 default: | 1698 default: |
| 1617 NOTREACHED(); | 1699 NOTREACHED(); |
| 1618 break; | 1700 break; |
| 1619 } | 1701 } |
| 1620 } | 1702 } |
| 1621 | 1703 |
| 1622 virtual void afterTest() OVERRIDE | 1704 virtual void afterTest() OVERRIDE |
| 1623 { | 1705 { |
| 1624 } | 1706 } |
| 1625 | 1707 |
| 1626 private: | 1708 private: |
| 1627 FakeContentLayerClient m_client; | 1709 FakeContentLayerClient m_client; |
| 1628 scoped_refptr<ContentLayerWithUpdateTracking> m_parent; | 1710 scoped_refptr<ContentLayerWithUpdateTracking> m_parent; |
| 1629 scoped_refptr<ContentLayerWithUpdateTracking> m_child; | 1711 scoped_refptr<ContentLayerWithUpdateTracking> m_child; |
| 1712 scoped_refptr<ScrollbarLayerWithUpdateTracking> m_scrollbarWithPaints; |
| 1713 scoped_refptr<ScrollbarLayerWithUpdateTracking> m_scrollbarWithoutPaints; |
| 1630 int m_numCommits; | 1714 int m_numCommits; |
| 1631 }; | 1715 }; |
| 1632 | 1716 |
| 1633 TEST_F(LayerTreeHostTestAtomicCommitWithPartialUpdate, runMultiThread) | 1717 TEST_F(LayerTreeHostTestAtomicCommitWithPartialUpdate, runMultiThread) |
| 1634 { | 1718 { |
| 1635 runTest(true); | 1719 runTest(true); |
| 1636 } | 1720 } |
| 1637 | 1721 |
| 1638 class TestLayer : public Layer { | 1722 class TestLayer : public Layer { |
| 1639 public: | 1723 public: |
| (...skipping 1740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3380 LayerTreeSettings settings; | 3464 LayerTreeSettings settings; |
| 3381 settings.maxPartialTextureUpdates = 4; | 3465 settings.maxPartialTextureUpdates = 4; |
| 3382 | 3466 |
| 3383 scoped_ptr<LayerTreeHost> host = LayerTreeHost::create(&client, settings, sc
oped_ptr<Thread>()); | 3467 scoped_ptr<LayerTreeHost> host = LayerTreeHost::create(&client, settings, sc
oped_ptr<Thread>()); |
| 3384 EXPECT_TRUE(host->initializeRendererIfNeeded()); | 3468 EXPECT_TRUE(host->initializeRendererIfNeeded()); |
| 3385 EXPECT_EQ(0u, host->settings().maxPartialTextureUpdates); | 3469 EXPECT_EQ(0u, host->settings().maxPartialTextureUpdates); |
| 3386 } | 3470 } |
| 3387 | 3471 |
| 3388 } // namespace | 3472 } // namespace |
| 3389 } // namespace cc | 3473 } // namespace cc |
| OLD | NEW |