OLD | NEW |
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 <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 layer->VisibleContentOpaqueRegion().ToString()); | 238 layer->VisibleContentOpaqueRegion().ToString()); |
239 | 239 |
240 // Transparent background. | 240 // Transparent background. |
241 layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255)); | 241 layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255)); |
242 EXPECT_EQ(Region().ToString(), | 242 EXPECT_EQ(Region().ToString(), |
243 layer->VisibleContentOpaqueRegion().ToString()); | 243 layer->VisibleContentOpaqueRegion().ToString()); |
244 } | 244 } |
245 | 245 |
246 class FakeTextureLayerClient : public TextureLayerClient { | 246 class FakeTextureLayerClient : public TextureLayerClient { |
247 public: | 247 public: |
248 FakeTextureLayerClient() : context_(TestWebGraphicsContext3D::Create()) {} | 248 FakeTextureLayerClient() {} |
249 | 249 |
250 virtual unsigned PrepareTexture() OVERRIDE { | 250 virtual unsigned PrepareTexture() OVERRIDE { |
251 return 0; | 251 return 0; |
252 } | 252 } |
253 | 253 |
254 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
255 return context_.get(); | |
256 } | |
257 | |
258 virtual bool PrepareTextureMailbox( | 254 virtual bool PrepareTextureMailbox( |
259 TextureMailbox* mailbox, | 255 TextureMailbox* mailbox, |
260 scoped_ptr<SingleReleaseCallback>* release_callback, | 256 scoped_ptr<SingleReleaseCallback>* release_callback, |
261 bool use_shared_memory) OVERRIDE { | 257 bool use_shared_memory) OVERRIDE { |
262 *mailbox = TextureMailbox(); | 258 *mailbox = TextureMailbox(); |
263 *release_callback = scoped_ptr<SingleReleaseCallback>(); | 259 *release_callback = scoped_ptr<SingleReleaseCallback>(); |
264 return true; | 260 return true; |
265 } | 261 } |
266 | 262 |
267 private: | 263 private: |
268 scoped_ptr<TestWebGraphicsContext3D> context_; | |
269 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); | 264 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); |
270 }; | 265 }; |
271 | 266 |
272 TEST_F(TextureLayerTest, RateLimiter) { | 267 TEST_F(TextureLayerTest, RateLimiter) { |
273 FakeTextureLayerClient client; | 268 FakeTextureLayerClient client; |
274 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox( | 269 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox( |
275 &client); | 270 &client); |
276 test_layer->SetIsDrawable(true); | 271 test_layer->SetIsDrawable(true); |
277 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 272 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
278 layer_tree_host_->SetRootLayer(test_layer); | 273 layer_tree_host_->SetRootLayer(test_layer); |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 881 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
887 TextureLayerImplWithMailboxThreadedCallback); | 882 TextureLayerImplWithMailboxThreadedCallback); |
888 | 883 |
889 | 884 |
890 class TextureLayerNoMailboxIsActivatedDuringCommit : public LayerTreeTest, | 885 class TextureLayerNoMailboxIsActivatedDuringCommit : public LayerTreeTest, |
891 public TextureLayerClient { | 886 public TextureLayerClient { |
892 protected: | 887 protected: |
893 TextureLayerNoMailboxIsActivatedDuringCommit() | 888 TextureLayerNoMailboxIsActivatedDuringCommit() |
894 : wait_thread_("WAIT"), | 889 : wait_thread_("WAIT"), |
895 wait_event_(false, false), | 890 wait_event_(false, false), |
896 context_(TestWebGraphicsContext3D::Create()) { | 891 texture_(0u) { |
897 wait_thread_.Start(); | 892 wait_thread_.Start(); |
898 } | 893 } |
899 | 894 |
900 virtual void BeginTest() OVERRIDE { | 895 virtual void BeginTest() OVERRIDE { |
901 activate_count_ = 0; | 896 activate_count_ = 0; |
902 | 897 |
903 gfx::Size bounds(100, 100); | 898 gfx::Size bounds(100, 100); |
904 root_ = Layer::Create(); | 899 root_ = Layer::Create(); |
905 root_->SetAnchorPoint(gfx::PointF()); | 900 root_->SetAnchorPoint(gfx::PointF()); |
906 root_->SetBounds(bounds); | 901 root_->SetBounds(bounds); |
907 | 902 |
908 layer_ = TextureLayer::Create(this); | 903 layer_ = TextureLayer::Create(this); |
909 layer_->SetIsDrawable(true); | 904 layer_->SetIsDrawable(true); |
910 layer_->SetAnchorPoint(gfx::PointF()); | 905 layer_->SetAnchorPoint(gfx::PointF()); |
911 layer_->SetBounds(bounds); | 906 layer_->SetBounds(bounds); |
912 | 907 |
913 root_->AddChild(layer_); | 908 root_->AddChild(layer_); |
914 layer_tree_host()->SetRootLayer(root_); | 909 layer_tree_host()->SetRootLayer(root_); |
915 layer_tree_host()->SetViewportSize(bounds); | 910 layer_tree_host()->SetViewportSize(bounds); |
916 | 911 |
917 PostSetNeedsCommitToMainThread(); | 912 PostSetNeedsCommitToMainThread(); |
918 } | 913 } |
919 | 914 |
| 915 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
| 916 OVERRIDE { |
| 917 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
| 918 texture_ = provider->UnboundTestContext3d()->createExternalTexture(); |
| 919 return FakeOutputSurface::Create3d(provider).PassAs<OutputSurface>(); |
| 920 } |
| 921 |
920 // TextureLayerClient implementation. | 922 // TextureLayerClient implementation. |
921 virtual unsigned PrepareTexture() OVERRIDE { | 923 virtual unsigned PrepareTexture() OVERRIDE { |
922 context_->makeContextCurrent(); | 924 return texture_; |
923 return context_->createTexture(); | |
924 } | |
925 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
926 return context_.get(); | |
927 } | 925 } |
928 virtual bool PrepareTextureMailbox( | 926 virtual bool PrepareTextureMailbox( |
929 TextureMailbox* mailbox, | 927 TextureMailbox* mailbox, |
930 scoped_ptr<SingleReleaseCallback>* release_callback, | 928 scoped_ptr<SingleReleaseCallback>* release_callback, |
931 bool use_shared_memory) OVERRIDE { | 929 bool use_shared_memory) OVERRIDE { |
932 return false; | 930 return false; |
933 } | 931 } |
934 | 932 |
935 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 933 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
936 // Slow down activation so the main thread DidCommit() will run if | 934 // Slow down activation so the main thread DidCommit() will run if |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 } | 993 } |
996 } | 994 } |
997 } | 995 } |
998 | 996 |
999 | 997 |
1000 virtual void AfterTest() OVERRIDE {} | 998 virtual void AfterTest() OVERRIDE {} |
1001 | 999 |
1002 base::Thread wait_thread_; | 1000 base::Thread wait_thread_; |
1003 base::WaitableEvent wait_event_; | 1001 base::WaitableEvent wait_event_; |
1004 base::Lock activate_lock_; | 1002 base::Lock activate_lock_; |
| 1003 unsigned texture_; |
1005 int activate_count_; | 1004 int activate_count_; |
1006 int activate_commit_; | |
1007 scoped_refptr<Layer> root_; | 1005 scoped_refptr<Layer> root_; |
1008 scoped_refptr<TextureLayer> layer_; | 1006 scoped_refptr<TextureLayer> layer_; |
1009 scoped_ptr<TestWebGraphicsContext3D> context_; | |
1010 }; | 1007 }; |
1011 | 1008 |
1012 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1009 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
1013 TextureLayerNoMailboxIsActivatedDuringCommit); | 1010 TextureLayerNoMailboxIsActivatedDuringCommit); |
1014 | 1011 |
1015 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { | 1012 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { |
1016 protected: | 1013 protected: |
1017 TextureLayerMailboxIsActivatedDuringCommit() | 1014 TextureLayerMailboxIsActivatedDuringCommit() |
1018 : wait_thread_("WAIT"), | 1015 : wait_thread_("WAIT"), |
1019 wait_event_(false, false) { | 1016 wait_event_(false, false) { |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 provider->ReceiveReturnsFromParent(returned); | 1396 provider->ReceiveReturnsFromParent(returned); |
1400 } | 1397 } |
1401 | 1398 |
1402 // Check that ClearClient correctly clears the state so that the impl side | 1399 // Check that ClearClient correctly clears the state so that the impl side |
1403 // doesn't try to use a texture that could have been destroyed. | 1400 // doesn't try to use a texture that could have been destroyed. |
1404 class TextureLayerClientTest | 1401 class TextureLayerClientTest |
1405 : public LayerTreeTest, | 1402 : public LayerTreeTest, |
1406 public TextureLayerClient { | 1403 public TextureLayerClient { |
1407 public: | 1404 public: |
1408 TextureLayerClientTest() | 1405 TextureLayerClientTest() |
1409 : context_(NULL), | 1406 : texture_(0), |
1410 texture_(0), | |
1411 commit_count_(0), | 1407 commit_count_(0), |
1412 expected_used_textures_on_draw_(0), | 1408 expected_used_textures_on_draw_(0), |
1413 expected_used_textures_on_commit_(0) {} | 1409 expected_used_textures_on_commit_(0) {} |
1414 | 1410 |
1415 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) | 1411 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
1416 OVERRIDE { | 1412 OVERRIDE { |
1417 scoped_ptr<TestWebGraphicsContext3D> context( | 1413 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
1418 TestWebGraphicsContext3D::Create()); | 1414 texture_ = provider->UnboundTestContext3d()->createExternalTexture(); |
1419 context_ = context.get(); | 1415 return FakeOutputSurface::Create3d(provider).PassAs<OutputSurface>(); |
1420 texture_ = context->createTexture(); | |
1421 return FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>(); | |
1422 } | 1416 } |
1423 | 1417 |
1424 virtual unsigned PrepareTexture() OVERRIDE { | 1418 virtual unsigned PrepareTexture() OVERRIDE { return texture_; } |
1425 return texture_; | |
1426 } | |
1427 | |
1428 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
1429 return context_; | |
1430 } | |
1431 | 1419 |
1432 virtual bool PrepareTextureMailbox( | 1420 virtual bool PrepareTextureMailbox( |
1433 TextureMailbox* mailbox, | 1421 TextureMailbox* mailbox, |
1434 scoped_ptr<SingleReleaseCallback>* release_callback, | 1422 scoped_ptr<SingleReleaseCallback>* release_callback, |
1435 bool use_shared_memory) OVERRIDE { | 1423 bool use_shared_memory) OVERRIDE { |
1436 return false; | 1424 return false; |
1437 } | 1425 } |
1438 | 1426 |
1439 virtual void SetupTree() OVERRIDE { | 1427 virtual void SetupTree() OVERRIDE { |
1440 scoped_refptr<Layer> root = Layer::Create(); | 1428 scoped_refptr<Layer> root = Layer::Create(); |
(...skipping 22 matching lines...) Expand all Loading... |
1463 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1451 virtual void DidCommitAndDrawFrame() OVERRIDE { |
1464 ++commit_count_; | 1452 ++commit_count_; |
1465 switch (commit_count_) { | 1453 switch (commit_count_) { |
1466 case 1: | 1454 case 1: |
1467 texture_layer_->ClearClient(); | 1455 texture_layer_->ClearClient(); |
1468 texture_layer_->SetNeedsDisplay(); | 1456 texture_layer_->SetNeedsDisplay(); |
1469 { | 1457 { |
1470 base::AutoLock lock(lock_); | 1458 base::AutoLock lock(lock_); |
1471 expected_used_textures_on_commit_ = 0; | 1459 expected_used_textures_on_commit_ = 0; |
1472 } | 1460 } |
1473 texture_ = 0; | |
1474 break; | 1461 break; |
1475 case 2: | 1462 case 2: |
1476 EndTest(); | 1463 EndTest(); |
1477 break; | 1464 break; |
1478 default: | 1465 default: |
1479 NOTREACHED(); | 1466 NOTREACHED(); |
1480 break; | 1467 break; |
1481 } | 1468 } |
1482 } | 1469 } |
1483 | 1470 |
1484 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1471 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
1485 base::AutoLock lock(lock_); | 1472 base::AutoLock lock(lock_); |
1486 expected_used_textures_on_draw_ = expected_used_textures_on_commit_; | 1473 expected_used_textures_on_draw_ = expected_used_textures_on_commit_; |
1487 } | 1474 } |
1488 | 1475 |
1489 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 1476 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
1490 LayerTreeHostImpl::FrameData* frame_data, | 1477 LayerTreeHostImpl::FrameData* frame_data, |
1491 bool result) OVERRIDE { | 1478 bool result) OVERRIDE { |
1492 context_->ResetUsedTextures(); | 1479 ContextForImplThread(host_impl)->ResetUsedTextures(); |
1493 return true; | 1480 return true; |
1494 } | 1481 } |
1495 | 1482 |
1496 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | 1483 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
1497 bool result) OVERRIDE { | 1484 bool result) OVERRIDE { |
1498 ASSERT_TRUE(result); | 1485 ASSERT_TRUE(result); |
1499 EXPECT_EQ(expected_used_textures_on_draw_, context_->NumUsedTextures()); | 1486 EXPECT_EQ(expected_used_textures_on_draw_, |
| 1487 ContextForImplThread(host_impl)->NumUsedTextures()); |
1500 } | 1488 } |
1501 | 1489 |
1502 virtual void AfterTest() OVERRIDE {} | 1490 virtual void AfterTest() OVERRIDE {} |
1503 | 1491 |
1504 private: | 1492 private: |
| 1493 TestWebGraphicsContext3D* ContextForImplThread(LayerTreeHostImpl* host_impl) { |
| 1494 return static_cast<TestWebGraphicsContext3D*>( |
| 1495 host_impl->output_surface()->context_provider()->Context3d()); |
| 1496 } |
| 1497 |
1505 scoped_refptr<TextureLayer> texture_layer_; | 1498 scoped_refptr<TextureLayer> texture_layer_; |
1506 TestWebGraphicsContext3D* context_; | |
1507 unsigned texture_; | 1499 unsigned texture_; |
1508 int commit_count_; | 1500 int commit_count_; |
1509 | 1501 |
1510 // Used only on thread. | 1502 // Used only on thread. |
1511 unsigned expected_used_textures_on_draw_; | 1503 unsigned expected_used_textures_on_draw_; |
1512 | 1504 |
1513 // Used on either thread, protected by lock_. | 1505 // Used on either thread, protected by lock_. |
1514 base::Lock lock_; | 1506 base::Lock lock_; |
1515 unsigned expected_used_textures_on_commit_; | 1507 unsigned expected_used_textures_on_commit_; |
1516 }; | 1508 }; |
1517 | 1509 |
1518 // The TextureLayerClient does not use mailboxes, so can't use a delegating | 1510 // The TextureLayerClient does not use mailboxes, so can't use a delegating |
1519 // renderer. | 1511 // renderer. |
1520 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerClientTest); | 1512 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerClientTest); |
1521 | 1513 |
1522 | 1514 |
1523 // Checks that changing a texture in the client for a TextureLayer that's | 1515 // Checks that changing a texture in the client for a TextureLayer that's |
1524 // invisible correctly works without drawing a deleted texture. See | 1516 // invisible correctly works without drawing a deleted texture. See |
1525 // crbug.com/266628 | 1517 // crbug.com/266628 |
1526 class TextureLayerChangeInvisibleTest | 1518 class TextureLayerChangeInvisibleTest |
1527 : public LayerTreeTest, | 1519 : public LayerTreeTest, |
1528 public TextureLayerClient { | 1520 public TextureLayerClient { |
1529 public: | 1521 public: |
1530 TextureLayerChangeInvisibleTest() | 1522 TextureLayerChangeInvisibleTest() |
1531 : client_context_(TestWebGraphicsContext3D::Create()), | 1523 : texture_(0u), |
1532 texture_(client_context_->createTexture()), | |
1533 texture_to_delete_on_next_commit_(0), | |
1534 prepare_called_(0), | 1524 prepare_called_(0), |
1535 commit_count_(0), | 1525 commit_count_(0), |
1536 expected_texture_on_draw_(0) {} | 1526 expected_texture_on_draw_(0) {} |
1537 | 1527 |
| 1528 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
| 1529 OVERRIDE { |
| 1530 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
| 1531 texture_ = provider->UnboundTestContext3d()->createExternalTexture(); |
| 1532 return FakeOutputSurface::Create3d(provider).PassAs<OutputSurface>(); |
| 1533 } |
| 1534 |
1538 // TextureLayerClient implementation. | 1535 // TextureLayerClient implementation. |
1539 virtual unsigned PrepareTexture() OVERRIDE { | 1536 virtual unsigned PrepareTexture() OVERRIDE { |
1540 ++prepare_called_; | 1537 ++prepare_called_; |
1541 return texture_; | 1538 return texture_; |
1542 } | 1539 } |
1543 | |
1544 // TextureLayerClient implementation. | |
1545 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
1546 return client_context_.get(); | |
1547 } | |
1548 | |
1549 // TextureLayerClient implementation. | |
1550 virtual bool PrepareTextureMailbox( | 1540 virtual bool PrepareTextureMailbox( |
1551 cc::TextureMailbox* mailbox, | 1541 cc::TextureMailbox* mailbox, |
1552 scoped_ptr<SingleReleaseCallback>* release_callback, | 1542 scoped_ptr<SingleReleaseCallback>* release_callback, |
1553 bool use_shared_memory) OVERRIDE { | 1543 bool use_shared_memory) OVERRIDE { |
1554 return false; | 1544 return false; |
1555 } | 1545 } |
1556 | 1546 |
1557 virtual void SetupTree() OVERRIDE { | 1547 virtual void SetupTree() OVERRIDE { |
1558 scoped_refptr<Layer> root = Layer::Create(); | 1548 scoped_refptr<Layer> root = Layer::Create(); |
1559 root->SetBounds(gfx::Size(10, 10)); | 1549 root->SetBounds(gfx::Size(10, 10)); |
(...skipping 30 matching lines...) Expand all Loading... |
1590 switch (commit_count_) { | 1580 switch (commit_count_) { |
1591 case 1: | 1581 case 1: |
1592 // We should have updated the layer, committing the texture. | 1582 // We should have updated the layer, committing the texture. |
1593 EXPECT_EQ(1, prepare_called_); | 1583 EXPECT_EQ(1, prepare_called_); |
1594 // Make layer invisible. | 1584 // Make layer invisible. |
1595 parent_layer_->SetOpacity(0.f); | 1585 parent_layer_->SetOpacity(0.f); |
1596 break; | 1586 break; |
1597 case 2: { | 1587 case 2: { |
1598 // Layer shouldn't have been updated. | 1588 // Layer shouldn't have been updated. |
1599 EXPECT_EQ(1, prepare_called_); | 1589 EXPECT_EQ(1, prepare_called_); |
1600 // Change the texture. | |
1601 texture_to_delete_on_next_commit_ = texture_; | |
1602 texture_ = client_context_->createTexture(); | |
1603 texture_layer_->SetNeedsDisplay(); | 1590 texture_layer_->SetNeedsDisplay(); |
1604 // Force a change to make sure we draw a frame. | 1591 // Force a change to make sure we draw a frame. |
1605 solid_layer_->SetBackgroundColor(SK_ColorGRAY); | 1592 solid_layer_->SetBackgroundColor(SK_ColorGRAY); |
1606 break; | 1593 break; |
1607 } | 1594 } |
1608 case 3: | 1595 case 3: |
1609 EXPECT_EQ(1, prepare_called_); | 1596 EXPECT_EQ(1, prepare_called_); |
1610 client_context_->deleteTexture(texture_to_delete_on_next_commit_); | |
1611 texture_to_delete_on_next_commit_ = 0; | |
1612 // Make layer visible again. | 1597 // Make layer visible again. |
1613 parent_layer_->SetOpacity(1.f); | 1598 parent_layer_->SetOpacity(1.f); |
1614 break; | 1599 break; |
1615 case 4: { | 1600 case 4: { |
1616 // Layer should have been updated. | 1601 // Layer should have been updated. |
1617 EXPECT_EQ(2, prepare_called_); | 1602 EXPECT_EQ(2, prepare_called_); |
1618 texture_layer_->ClearClient(); | 1603 texture_layer_->ClearClient(); |
1619 client_context_->deleteTexture(texture_); | |
1620 texture_ = 0; | 1604 texture_ = 0; |
1621 break; | 1605 break; |
1622 } | 1606 } |
1623 case 5: | 1607 case 5: |
1624 EndTest(); | 1608 EndTest(); |
1625 break; | 1609 break; |
1626 default: | 1610 default: |
1627 NOTREACHED(); | 1611 NOTREACHED(); |
1628 break; | 1612 break; |
1629 } | 1613 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1669 | 1653 |
1670 private: | 1654 private: |
1671 TestWebGraphicsContext3D* ContextForImplThread(LayerTreeHostImpl* host_impl) { | 1655 TestWebGraphicsContext3D* ContextForImplThread(LayerTreeHostImpl* host_impl) { |
1672 return static_cast<TestWebGraphicsContext3D*>( | 1656 return static_cast<TestWebGraphicsContext3D*>( |
1673 host_impl->output_surface()->context_provider()->Context3d()); | 1657 host_impl->output_surface()->context_provider()->Context3d()); |
1674 } | 1658 } |
1675 | 1659 |
1676 scoped_refptr<SolidColorLayer> solid_layer_; | 1660 scoped_refptr<SolidColorLayer> solid_layer_; |
1677 scoped_refptr<Layer> parent_layer_; | 1661 scoped_refptr<Layer> parent_layer_; |
1678 scoped_refptr<TextureLayer> texture_layer_; | 1662 scoped_refptr<TextureLayer> texture_layer_; |
1679 scoped_ptr<TestWebGraphicsContext3D> client_context_; | |
1680 | 1663 |
1681 // Used on the main thread, and on the impl thread while the main thread is | 1664 // Used on the main thread, and on the impl thread while the main thread is |
1682 // blocked. | 1665 // blocked. |
1683 unsigned texture_; | 1666 unsigned texture_; |
1684 | 1667 |
1685 // Used on the main thread. | 1668 // Used on the main thread. |
1686 unsigned texture_to_delete_on_next_commit_; | |
1687 int prepare_called_; | 1669 int prepare_called_; |
1688 int commit_count_; | 1670 int commit_count_; |
1689 | 1671 |
1690 // Used on the compositor thread. | 1672 // Used on the compositor thread. |
1691 unsigned expected_texture_on_draw_; | 1673 unsigned expected_texture_on_draw_; |
1692 }; | 1674 }; |
1693 | 1675 |
1694 // The TextureLayerChangeInvisibleTest does not use mailboxes, so can't use a | 1676 // The TextureLayerChangeInvisibleTest does not use mailboxes, so can't use a |
1695 // delegating renderer. | 1677 // delegating renderer. |
1696 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerChangeInvisibleTest); | 1678 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerChangeInvisibleTest); |
1697 | 1679 |
1698 // Checks that TextureLayer::Update does not cause an extra commit when setting | 1680 // Checks that TextureLayer::Update does not cause an extra commit when setting |
1699 // the texture mailbox. | 1681 // the texture mailbox. |
1700 class TextureLayerNoExtraCommitForMailboxTest | 1682 class TextureLayerNoExtraCommitForMailboxTest |
1701 : public LayerTreeTest, | 1683 : public LayerTreeTest, |
1702 public TextureLayerClient { | 1684 public TextureLayerClient { |
1703 public: | 1685 public: |
1704 TextureLayerNoExtraCommitForMailboxTest() | 1686 TextureLayerNoExtraCommitForMailboxTest() |
1705 : prepare_mailbox_count_(0) {} | 1687 : prepare_mailbox_count_(0) {} |
1706 | 1688 |
1707 // TextureLayerClient implementation. | 1689 // TextureLayerClient implementation. |
1708 virtual unsigned PrepareTexture() OVERRIDE { | 1690 virtual unsigned PrepareTexture() OVERRIDE { |
1709 NOTREACHED(); | 1691 NOTREACHED(); |
1710 return 0; | 1692 return 0; |
1711 } | 1693 } |
1712 | 1694 |
1713 // TextureLayerClient implementation. | |
1714 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
1715 NOTREACHED(); | |
1716 return NULL; | |
1717 } | |
1718 | |
1719 virtual bool PrepareTextureMailbox( | 1695 virtual bool PrepareTextureMailbox( |
1720 cc::TextureMailbox* mailbox, | 1696 cc::TextureMailbox* mailbox, |
1721 scoped_ptr<SingleReleaseCallback>* release_callback, | 1697 scoped_ptr<SingleReleaseCallback>* release_callback, |
1722 bool use_shared_memory) OVERRIDE { | 1698 bool use_shared_memory) OVERRIDE { |
1723 prepare_mailbox_count_++; | 1699 prepare_mailbox_count_++; |
1724 // Alternate between two mailboxes to ensure that the TextureLayer updates | 1700 // Alternate between two mailboxes to ensure that the TextureLayer updates |
1725 // and commits. | 1701 // and commits. |
1726 if (prepare_mailbox_count_ % 2 == 0) | 1702 if (prepare_mailbox_count_ % 2 == 0) |
1727 *mailbox = MakeMailbox('1'); | 1703 *mailbox = MakeMailbox('1'); |
1728 else | 1704 else |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1812 commit_count_(0) { | 1788 commit_count_(0) { |
1813 mailbox_ = MakeMailbox('1'); | 1789 mailbox_ = MakeMailbox('1'); |
1814 } | 1790 } |
1815 | 1791 |
1816 // TextureLayerClient implementation. | 1792 // TextureLayerClient implementation. |
1817 virtual unsigned PrepareTexture() OVERRIDE { | 1793 virtual unsigned PrepareTexture() OVERRIDE { |
1818 NOTREACHED(); | 1794 NOTREACHED(); |
1819 return 0; | 1795 return 0; |
1820 } | 1796 } |
1821 | 1797 |
1822 // TextureLayerClient implementation. | |
1823 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
1824 NOTREACHED(); | |
1825 return NULL; | |
1826 } | |
1827 | |
1828 // TextureLayerClient implementation. | |
1829 virtual bool PrepareTextureMailbox( | 1798 virtual bool PrepareTextureMailbox( |
1830 cc::TextureMailbox* mailbox, | 1799 cc::TextureMailbox* mailbox, |
1831 scoped_ptr<SingleReleaseCallback>* release_callback, | 1800 scoped_ptr<SingleReleaseCallback>* release_callback, |
1832 bool use_shared_memory) OVERRIDE { | 1801 bool use_shared_memory) OVERRIDE { |
1833 ++prepare_called_; | 1802 ++prepare_called_; |
1834 if (!mailbox_changed_) | 1803 if (!mailbox_changed_) |
1835 return false; | 1804 return false; |
1836 *mailbox = mailbox_; | 1805 *mailbox = mailbox_; |
1837 *release_callback = SingleReleaseCallback::Create( | 1806 *release_callback = SingleReleaseCallback::Create( |
1838 base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased, | 1807 base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 }; | 1927 }; |
1959 | 1928 |
1960 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest); | 1929 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest); |
1961 | 1930 |
1962 // Test recovering from a lost context. | 1931 // Test recovering from a lost context. |
1963 class TextureLayerLostContextTest | 1932 class TextureLayerLostContextTest |
1964 : public LayerTreeTest, | 1933 : public LayerTreeTest, |
1965 public TextureLayerClient { | 1934 public TextureLayerClient { |
1966 public: | 1935 public: |
1967 TextureLayerLostContextTest() | 1936 TextureLayerLostContextTest() |
1968 : texture_(0), | 1937 : context_lost_(false), |
1969 draw_count_(0) {} | 1938 draw_count_(0) {} |
1970 | 1939 |
1971 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) | 1940 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
1972 OVERRIDE { | 1941 OVERRIDE { |
1973 texture_context_ = TestWebGraphicsContext3D::Create(); | |
1974 texture_ = texture_context_->createTexture(); | |
1975 return CreateFakeOutputSurface(); | 1942 return CreateFakeOutputSurface(); |
1976 } | 1943 } |
1977 | 1944 |
1978 virtual unsigned PrepareTexture() OVERRIDE { | 1945 virtual unsigned PrepareTexture() OVERRIDE { |
1979 if (draw_count_ == 0) { | 1946 if (draw_count_ == 0) |
1980 texture_context_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 1947 context_lost_ = true; |
1981 GL_INNOCENT_CONTEXT_RESET_ARB); | 1948 if (context_lost_) |
1982 } | 1949 return 0u; |
1983 return texture_; | 1950 return 1u; |
1984 } | |
1985 | |
1986 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
1987 return texture_context_.get(); | |
1988 } | 1951 } |
1989 | 1952 |
1990 virtual bool PrepareTextureMailbox( | 1953 virtual bool PrepareTextureMailbox( |
1991 TextureMailbox* mailbox, | 1954 TextureMailbox* mailbox, |
1992 scoped_ptr<SingleReleaseCallback>* release_callback, | 1955 scoped_ptr<SingleReleaseCallback>* release_callback, |
1993 bool use_shared_memory) OVERRIDE { | 1956 bool use_shared_memory) OVERRIDE { |
1994 return false; | 1957 return false; |
1995 } | 1958 } |
1996 | 1959 |
1997 virtual void SetupTree() OVERRIDE { | 1960 virtual void SetupTree() OVERRIDE { |
(...skipping 16 matching lines...) Expand all Loading... |
2014 | 1977 |
2015 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 1978 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
2016 LayerTreeHostImpl::FrameData* frame_data, | 1979 LayerTreeHostImpl::FrameData* frame_data, |
2017 bool result) OVERRIDE { | 1980 bool result) OVERRIDE { |
2018 LayerImpl* root = host_impl->RootLayer(); | 1981 LayerImpl* root = host_impl->RootLayer(); |
2019 TextureLayerImpl* texture_layer = | 1982 TextureLayerImpl* texture_layer = |
2020 static_cast<TextureLayerImpl*>(root->children()[0]); | 1983 static_cast<TextureLayerImpl*>(root->children()[0]); |
2021 if (++draw_count_ == 1) | 1984 if (++draw_count_ == 1) |
2022 EXPECT_EQ(0u, texture_layer->texture_id()); | 1985 EXPECT_EQ(0u, texture_layer->texture_id()); |
2023 else | 1986 else |
2024 EXPECT_EQ(texture_, texture_layer->texture_id()); | 1987 EXPECT_EQ(1u, texture_layer->texture_id()); |
2025 return true; | 1988 return true; |
2026 } | 1989 } |
2027 | 1990 |
2028 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1991 virtual void DidCommitAndDrawFrame() OVERRIDE { |
2029 EndTest(); | 1992 EndTest(); |
2030 } | 1993 } |
2031 | 1994 |
2032 virtual void AfterTest() OVERRIDE {} | 1995 virtual void AfterTest() OVERRIDE {} |
2033 | 1996 |
2034 private: | 1997 private: |
2035 scoped_refptr<TextureLayer> texture_layer_; | 1998 scoped_refptr<TextureLayer> texture_layer_; |
2036 scoped_ptr<TestWebGraphicsContext3D> texture_context_; | 1999 bool context_lost_; |
2037 unsigned texture_; | |
2038 int draw_count_; | 2000 int draw_count_; |
2039 }; | 2001 }; |
2040 | 2002 |
2041 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerLostContextTest); | 2003 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerLostContextTest); |
2042 | 2004 |
2043 class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest { | 2005 class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest { |
2044 public: | 2006 public: |
2045 void ReleaseCallback(unsigned sync_point, bool lost_resource) { | 2007 void ReleaseCallback(unsigned sync_point, bool lost_resource) { |
2046 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 2008 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
2047 EXPECT_FALSE(lost_resource); | 2009 EXPECT_FALSE(lost_resource); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2182 int callback_count_; | 2144 int callback_count_; |
2183 scoped_refptr<Layer> root_; | 2145 scoped_refptr<Layer> root_; |
2184 scoped_refptr<TextureLayer> layer_; | 2146 scoped_refptr<TextureLayer> layer_; |
2185 }; | 2147 }; |
2186 | 2148 |
2187 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 2149 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
2188 TextureLayerWithMailboxImplThreadDeleted); | 2150 TextureLayerWithMailboxImplThreadDeleted); |
2189 | 2151 |
2190 } // namespace | 2152 } // namespace |
2191 } // namespace cc | 2153 } // namespace cc |
OLD | NEW |