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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 class MockLayerTreeHost : public LayerTreeHost { | 44 class MockLayerTreeHost : public LayerTreeHost { |
45 public: | 45 public: |
46 explicit MockLayerTreeHost(LayerTreeHostClient* client) | 46 explicit MockLayerTreeHost(LayerTreeHostClient* client) |
47 : LayerTreeHost(client, NULL, LayerTreeSettings()) { | 47 : LayerTreeHost(client, NULL, LayerTreeSettings()) { |
48 Initialize(NULL); | 48 Initialize(NULL); |
49 } | 49 } |
50 | 50 |
51 MOCK_METHOD0(AcquireLayerTextures, void()); | 51 MOCK_METHOD0(AcquireLayerTextures, void()); |
52 MOCK_METHOD0(SetNeedsCommit, void()); | 52 MOCK_METHOD0(SetNeedsCommit, void()); |
53 MOCK_METHOD0(SetNeedsUpdateLayers, void()); | 53 MOCK_METHOD0(SetNeedsUpdateLayers, void()); |
54 MOCK_METHOD1(StartRateLimiter, void(WebKit::WebGraphicsContext3D* context)); | 54 MOCK_METHOD1(StartRateLimiter, void(TextureLayerClient* client)); |
55 MOCK_METHOD1(StopRateLimiter, void(WebKit::WebGraphicsContext3D* context)); | 55 MOCK_METHOD1(StopRateLimiter, void(TextureLayerClient* client)); |
56 }; | 56 }; |
57 | 57 |
58 class TextureLayerTest : public testing::Test { | 58 class TextureLayerTest : public testing::Test { |
59 public: | 59 public: |
60 TextureLayerTest() | 60 TextureLayerTest() |
61 : fake_client_( | 61 : fake_client_( |
62 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), | 62 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), |
63 host_impl_(&proxy_) {} | 63 host_impl_(&proxy_) {} |
64 | 64 |
65 protected: | 65 protected: |
(...skipping 172 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 { | 254 virtual bool IsContextLost() OVERRIDE { |
255 return context_.get(); | 255 return false; |
256 } | 256 } |
257 | 257 |
| 258 virtual void RateLimitContext() OVERRIDE {} |
| 259 |
258 virtual bool PrepareTextureMailbox( | 260 virtual bool PrepareTextureMailbox( |
259 TextureMailbox* mailbox, | 261 TextureMailbox* mailbox, |
260 scoped_ptr<SingleReleaseCallback>* release_callback, | 262 scoped_ptr<SingleReleaseCallback>* release_callback, |
261 bool use_shared_memory) OVERRIDE { | 263 bool use_shared_memory) OVERRIDE { |
262 *mailbox = TextureMailbox(); | 264 *mailbox = TextureMailbox(); |
263 *release_callback = scoped_ptr<SingleReleaseCallback>(); | 265 *release_callback = scoped_ptr<SingleReleaseCallback>(); |
264 return true; | 266 return true; |
265 } | 267 } |
266 | 268 |
267 private: | 269 private: |
268 scoped_ptr<TestWebGraphicsContext3D> context_; | |
269 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); | 270 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); |
270 }; | 271 }; |
271 | 272 |
272 TEST_F(TextureLayerTest, RateLimiter) { | 273 TEST_F(TextureLayerTest, RateLimiter) { |
273 FakeTextureLayerClient client; | 274 FakeTextureLayerClient client; |
274 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox( | 275 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox( |
275 &client); | 276 &client); |
276 test_layer->SetIsDrawable(true); | 277 test_layer->SetIsDrawable(true); |
277 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 278 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
278 layer_tree_host_->SetRootLayer(test_layer); | 279 layer_tree_host_->SetRootLayer(test_layer); |
279 | 280 |
280 // Don't rate limit until we invalidate. | 281 // Don't rate limit until we invalidate. |
281 EXPECT_CALL(*layer_tree_host_, StartRateLimiter(_)).Times(0); | 282 EXPECT_CALL(*layer_tree_host_, StartRateLimiter(_)).Times(0); |
282 test_layer->SetRateLimitContext(true); | 283 test_layer->SetRateLimitContext(true); |
283 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 284 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
284 | 285 |
285 // Do rate limit after we invalidate. | 286 // Do rate limit after we invalidate. |
286 EXPECT_CALL(*layer_tree_host_, StartRateLimiter(client.Context3d())); | 287 EXPECT_CALL(*layer_tree_host_, StartRateLimiter(&client)); |
287 test_layer->SetNeedsDisplay(); | 288 test_layer->SetNeedsDisplay(); |
288 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 289 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
289 | 290 |
290 // Stop rate limiter when we don't want it any more. | 291 // Stop rate limiter when we don't want it any more. |
291 EXPECT_CALL(*layer_tree_host_, StopRateLimiter(client.Context3d())); | 292 EXPECT_CALL(*layer_tree_host_, StopRateLimiter(&client)); |
292 test_layer->SetRateLimitContext(false); | 293 test_layer->SetRateLimitContext(false); |
293 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 294 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
294 | 295 |
295 // Or we clear the client. | 296 // Or we clear the client. |
296 test_layer->SetRateLimitContext(true); | 297 test_layer->SetRateLimitContext(true); |
297 EXPECT_CALL(*layer_tree_host_, StopRateLimiter(client.Context3d())); | 298 EXPECT_CALL(*layer_tree_host_, StopRateLimiter(&client)); |
298 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 299 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
299 test_layer->ClearClient(); | 300 test_layer->ClearClient(); |
300 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 301 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
301 | 302 |
302 // Reset to a layer with a client, that started the rate limiter. | 303 // Reset to a layer with a client, that started the rate limiter. |
303 test_layer = TextureLayer::CreateForMailbox( | 304 test_layer = TextureLayer::CreateForMailbox( |
304 &client); | 305 &client); |
305 test_layer->SetIsDrawable(true); | 306 test_layer->SetIsDrawable(true); |
306 test_layer->SetRateLimitContext(true); | 307 test_layer->SetRateLimitContext(true); |
307 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 308 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
308 layer_tree_host_->SetRootLayer(test_layer); | 309 layer_tree_host_->SetRootLayer(test_layer); |
309 EXPECT_CALL(*layer_tree_host_, StartRateLimiter(_)).Times(0); | 310 EXPECT_CALL(*layer_tree_host_, StartRateLimiter(_)).Times(0); |
310 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 311 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
311 EXPECT_CALL(*layer_tree_host_, StartRateLimiter(client.Context3d())); | 312 EXPECT_CALL(*layer_tree_host_, StartRateLimiter(&client)); |
312 test_layer->SetNeedsDisplay(); | 313 test_layer->SetNeedsDisplay(); |
313 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 314 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
314 | 315 |
315 // Stop rate limiter when we're removed from the tree. | 316 // Stop rate limiter when we're removed from the tree. |
316 EXPECT_CALL(*layer_tree_host_, StopRateLimiter(client.Context3d())); | 317 EXPECT_CALL(*layer_tree_host_, StopRateLimiter(&client)); |
317 layer_tree_host_->SetRootLayer(NULL); | 318 layer_tree_host_->SetRootLayer(NULL); |
318 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 319 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
319 } | 320 } |
320 | 321 |
321 class MockMailboxCallback { | 322 class MockMailboxCallback { |
322 public: | 323 public: |
323 MOCK_METHOD3(Release, void(const std::string& mailbox, | 324 MOCK_METHOD3(Release, void(const std::string& mailbox, |
324 unsigned sync_point, | 325 unsigned sync_point, |
325 bool lost_resource)); | 326 bool lost_resource)); |
326 MOCK_METHOD3(Release2, void(base::SharedMemory* shared_memory, | 327 MOCK_METHOD3(Release2, void(base::SharedMemory* shared_memory, |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 887 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
887 TextureLayerImplWithMailboxThreadedCallback); | 888 TextureLayerImplWithMailboxThreadedCallback); |
888 | 889 |
889 | 890 |
890 class TextureLayerNoMailboxIsActivatedDuringCommit : public LayerTreeTest, | 891 class TextureLayerNoMailboxIsActivatedDuringCommit : public LayerTreeTest, |
891 public TextureLayerClient { | 892 public TextureLayerClient { |
892 protected: | 893 protected: |
893 TextureLayerNoMailboxIsActivatedDuringCommit() | 894 TextureLayerNoMailboxIsActivatedDuringCommit() |
894 : wait_thread_("WAIT"), | 895 : wait_thread_("WAIT"), |
895 wait_event_(false, false), | 896 wait_event_(false, false), |
896 context_(TestWebGraphicsContext3D::Create()) { | 897 texture_(0u) { |
897 wait_thread_.Start(); | 898 wait_thread_.Start(); |
898 } | 899 } |
899 | 900 |
900 virtual void BeginTest() OVERRIDE { | 901 virtual void BeginTest() OVERRIDE { |
901 activate_count_ = 0; | 902 activate_count_ = 0; |
902 | 903 |
903 gfx::Size bounds(100, 100); | 904 gfx::Size bounds(100, 100); |
904 root_ = Layer::Create(); | 905 root_ = Layer::Create(); |
905 root_->SetAnchorPoint(gfx::PointF()); | 906 root_->SetAnchorPoint(gfx::PointF()); |
906 root_->SetBounds(bounds); | 907 root_->SetBounds(bounds); |
907 | 908 |
908 layer_ = TextureLayer::Create(this); | 909 layer_ = TextureLayer::Create(this); |
909 layer_->SetIsDrawable(true); | 910 layer_->SetIsDrawable(true); |
910 layer_->SetAnchorPoint(gfx::PointF()); | 911 layer_->SetAnchorPoint(gfx::PointF()); |
911 layer_->SetBounds(bounds); | 912 layer_->SetBounds(bounds); |
912 | 913 |
913 root_->AddChild(layer_); | 914 root_->AddChild(layer_); |
914 layer_tree_host()->SetRootLayer(root_); | 915 layer_tree_host()->SetRootLayer(root_); |
915 layer_tree_host()->SetViewportSize(bounds); | 916 layer_tree_host()->SetViewportSize(bounds); |
916 | 917 |
917 PostSetNeedsCommitToMainThread(); | 918 PostSetNeedsCommitToMainThread(); |
918 } | 919 } |
919 | 920 |
| 921 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
| 922 OVERRIDE { |
| 923 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
| 924 texture_ = provider->UnboundTestContext3d()->createExternalTexture(); |
| 925 return FakeOutputSurface::Create3d(provider).PassAs<OutputSurface>(); |
| 926 } |
| 927 |
920 // TextureLayerClient implementation. | 928 // TextureLayerClient implementation. |
921 virtual unsigned PrepareTexture() OVERRIDE { | 929 virtual unsigned PrepareTexture() OVERRIDE { |
922 context_->makeContextCurrent(); | 930 return texture_; |
923 return context_->createTexture(); | |
924 } | 931 } |
925 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | 932 virtual bool IsContextLost() OVERRIDE { return false; } |
926 return context_.get(); | 933 virtual void RateLimitContext() OVERRIDE {} |
927 } | |
928 virtual bool PrepareTextureMailbox( | 934 virtual bool PrepareTextureMailbox( |
929 TextureMailbox* mailbox, | 935 TextureMailbox* mailbox, |
930 scoped_ptr<SingleReleaseCallback>* release_callback, | 936 scoped_ptr<SingleReleaseCallback>* release_callback, |
931 bool use_shared_memory) OVERRIDE { | 937 bool use_shared_memory) OVERRIDE { |
932 return false; | 938 return false; |
933 } | 939 } |
934 | 940 |
935 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 941 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
936 // Slow down activation so the main thread DidCommit() will run if | 942 // Slow down activation so the main thread DidCommit() will run if |
937 // not blocked. | 943 // not blocked. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 } | 1001 } |
996 } | 1002 } |
997 } | 1003 } |
998 | 1004 |
999 | 1005 |
1000 virtual void AfterTest() OVERRIDE {} | 1006 virtual void AfterTest() OVERRIDE {} |
1001 | 1007 |
1002 base::Thread wait_thread_; | 1008 base::Thread wait_thread_; |
1003 base::WaitableEvent wait_event_; | 1009 base::WaitableEvent wait_event_; |
1004 base::Lock activate_lock_; | 1010 base::Lock activate_lock_; |
| 1011 unsigned texture_; |
1005 int activate_count_; | 1012 int activate_count_; |
1006 int activate_commit_; | |
1007 scoped_refptr<Layer> root_; | 1013 scoped_refptr<Layer> root_; |
1008 scoped_refptr<TextureLayer> layer_; | 1014 scoped_refptr<TextureLayer> layer_; |
1009 scoped_ptr<TestWebGraphicsContext3D> context_; | |
1010 }; | 1015 }; |
1011 | 1016 |
1012 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1017 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
1013 TextureLayerNoMailboxIsActivatedDuringCommit); | 1018 TextureLayerNoMailboxIsActivatedDuringCommit); |
1014 | 1019 |
1015 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { | 1020 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { |
1016 protected: | 1021 protected: |
1017 TextureLayerMailboxIsActivatedDuringCommit() | 1022 TextureLayerMailboxIsActivatedDuringCommit() |
1018 : wait_thread_("WAIT"), | 1023 : wait_thread_("WAIT"), |
1019 wait_event_(false, false) { | 1024 wait_event_(false, false) { |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 provider->ReceiveReturnsFromParent(returned); | 1404 provider->ReceiveReturnsFromParent(returned); |
1400 } | 1405 } |
1401 | 1406 |
1402 // Check that ClearClient correctly clears the state so that the impl side | 1407 // 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. | 1408 // doesn't try to use a texture that could have been destroyed. |
1404 class TextureLayerClientTest | 1409 class TextureLayerClientTest |
1405 : public LayerTreeTest, | 1410 : public LayerTreeTest, |
1406 public TextureLayerClient { | 1411 public TextureLayerClient { |
1407 public: | 1412 public: |
1408 TextureLayerClientTest() | 1413 TextureLayerClientTest() |
1409 : context_(NULL), | 1414 : texture_(0), |
1410 texture_(0), | |
1411 commit_count_(0), | 1415 commit_count_(0), |
1412 expected_used_textures_on_draw_(0), | 1416 expected_used_textures_on_draw_(0), |
1413 expected_used_textures_on_commit_(0) {} | 1417 expected_used_textures_on_commit_(0) {} |
1414 | 1418 |
1415 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) | 1419 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
1416 OVERRIDE { | 1420 OVERRIDE { |
1417 scoped_ptr<TestWebGraphicsContext3D> context( | 1421 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
1418 TestWebGraphicsContext3D::Create()); | 1422 texture_ = provider->UnboundTestContext3d()->createExternalTexture(); |
1419 context_ = context.get(); | 1423 return FakeOutputSurface::Create3d(provider).PassAs<OutputSurface>(); |
1420 texture_ = context->createTexture(); | |
1421 return FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>(); | |
1422 } | 1424 } |
1423 | 1425 |
1424 virtual unsigned PrepareTexture() OVERRIDE { | 1426 virtual unsigned PrepareTexture() OVERRIDE { return texture_; } |
1425 return texture_; | 1427 virtual bool IsContextLost() OVERRIDE { return false; } |
1426 } | 1428 virtual void RateLimitContext() OVERRIDE { } |
1427 | |
1428 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
1429 return context_; | |
1430 } | |
1431 | 1429 |
1432 virtual bool PrepareTextureMailbox( | 1430 virtual bool PrepareTextureMailbox( |
1433 TextureMailbox* mailbox, | 1431 TextureMailbox* mailbox, |
1434 scoped_ptr<SingleReleaseCallback>* release_callback, | 1432 scoped_ptr<SingleReleaseCallback>* release_callback, |
1435 bool use_shared_memory) OVERRIDE { | 1433 bool use_shared_memory) OVERRIDE { |
1436 return false; | 1434 return false; |
1437 } | 1435 } |
1438 | 1436 |
1439 virtual void SetupTree() OVERRIDE { | 1437 virtual void SetupTree() OVERRIDE { |
1440 scoped_refptr<Layer> root = Layer::Create(); | 1438 scoped_refptr<Layer> root = Layer::Create(); |
(...skipping 22 matching lines...) Expand all Loading... |
1463 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1461 virtual void DidCommitAndDrawFrame() OVERRIDE { |
1464 ++commit_count_; | 1462 ++commit_count_; |
1465 switch (commit_count_) { | 1463 switch (commit_count_) { |
1466 case 1: | 1464 case 1: |
1467 texture_layer_->ClearClient(); | 1465 texture_layer_->ClearClient(); |
1468 texture_layer_->SetNeedsDisplay(); | 1466 texture_layer_->SetNeedsDisplay(); |
1469 { | 1467 { |
1470 base::AutoLock lock(lock_); | 1468 base::AutoLock lock(lock_); |
1471 expected_used_textures_on_commit_ = 0; | 1469 expected_used_textures_on_commit_ = 0; |
1472 } | 1470 } |
1473 texture_ = 0; | |
1474 break; | 1471 break; |
1475 case 2: | 1472 case 2: |
1476 EndTest(); | 1473 EndTest(); |
1477 break; | 1474 break; |
1478 default: | 1475 default: |
1479 NOTREACHED(); | 1476 NOTREACHED(); |
1480 break; | 1477 break; |
1481 } | 1478 } |
1482 } | 1479 } |
1483 | 1480 |
1484 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1481 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
1485 base::AutoLock lock(lock_); | 1482 base::AutoLock lock(lock_); |
1486 expected_used_textures_on_draw_ = expected_used_textures_on_commit_; | 1483 expected_used_textures_on_draw_ = expected_used_textures_on_commit_; |
1487 } | 1484 } |
1488 | 1485 |
1489 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 1486 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
1490 LayerTreeHostImpl::FrameData* frame_data, | 1487 LayerTreeHostImpl::FrameData* frame_data, |
1491 bool result) OVERRIDE { | 1488 bool result) OVERRIDE { |
1492 context_->ResetUsedTextures(); | 1489 ContextForImplThread(host_impl)->ResetUsedTextures(); |
1493 return true; | 1490 return true; |
1494 } | 1491 } |
1495 | 1492 |
1496 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | 1493 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
1497 bool result) OVERRIDE { | 1494 bool result) OVERRIDE { |
1498 ASSERT_TRUE(result); | 1495 ASSERT_TRUE(result); |
1499 EXPECT_EQ(expected_used_textures_on_draw_, context_->NumUsedTextures()); | 1496 EXPECT_EQ(expected_used_textures_on_draw_, |
| 1497 ContextForImplThread(host_impl)->NumUsedTextures()); |
1500 } | 1498 } |
1501 | 1499 |
1502 virtual void AfterTest() OVERRIDE {} | 1500 virtual void AfterTest() OVERRIDE {} |
1503 | 1501 |
1504 private: | 1502 private: |
| 1503 TestWebGraphicsContext3D* ContextForImplThread(LayerTreeHostImpl* host_impl) { |
| 1504 return static_cast<TestWebGraphicsContext3D*>( |
| 1505 host_impl->output_surface()->context_provider()->Context3d()); |
| 1506 } |
| 1507 |
1505 scoped_refptr<TextureLayer> texture_layer_; | 1508 scoped_refptr<TextureLayer> texture_layer_; |
1506 TestWebGraphicsContext3D* context_; | |
1507 unsigned texture_; | 1509 unsigned texture_; |
1508 int commit_count_; | 1510 int commit_count_; |
1509 | 1511 |
1510 // Used only on thread. | 1512 // Used only on thread. |
1511 unsigned expected_used_textures_on_draw_; | 1513 unsigned expected_used_textures_on_draw_; |
1512 | 1514 |
1513 // Used on either thread, protected by lock_. | 1515 // Used on either thread, protected by lock_. |
1514 base::Lock lock_; | 1516 base::Lock lock_; |
1515 unsigned expected_used_textures_on_commit_; | 1517 unsigned expected_used_textures_on_commit_; |
1516 }; | 1518 }; |
1517 | 1519 |
1518 // The TextureLayerClient does not use mailboxes, so can't use a delegating | 1520 // The TextureLayerClient does not use mailboxes, so can't use a delegating |
1519 // renderer. | 1521 // renderer. |
1520 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerClientTest); | 1522 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerClientTest); |
1521 | 1523 |
1522 | 1524 |
1523 // Checks that changing a texture in the client for a TextureLayer that's | 1525 // Checks that changing a texture in the client for a TextureLayer that's |
1524 // invisible correctly works without drawing a deleted texture. See | 1526 // invisible correctly works without drawing a deleted texture. See |
1525 // crbug.com/266628 | 1527 // crbug.com/266628 |
1526 class TextureLayerChangeInvisibleTest | 1528 class TextureLayerChangeInvisibleTest |
1527 : public LayerTreeTest, | 1529 : public LayerTreeTest, |
1528 public TextureLayerClient { | 1530 public TextureLayerClient { |
1529 public: | 1531 public: |
1530 TextureLayerChangeInvisibleTest() | 1532 TextureLayerChangeInvisibleTest() |
1531 : client_context_(TestWebGraphicsContext3D::Create()), | 1533 : texture_(0u), |
1532 texture_(client_context_->createTexture()), | |
1533 texture_to_delete_on_next_commit_(0), | |
1534 prepare_called_(0), | 1534 prepare_called_(0), |
1535 commit_count_(0), | 1535 commit_count_(0), |
1536 expected_texture_on_draw_(0) {} | 1536 expected_texture_on_draw_(0) {} |
1537 | 1537 |
| 1538 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
| 1539 OVERRIDE { |
| 1540 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
| 1541 texture_ = provider->UnboundTestContext3d()->createExternalTexture(); |
| 1542 return FakeOutputSurface::Create3d(provider).PassAs<OutputSurface>(); |
| 1543 } |
| 1544 |
1538 // TextureLayerClient implementation. | 1545 // TextureLayerClient implementation. |
1539 virtual unsigned PrepareTexture() OVERRIDE { | 1546 virtual unsigned PrepareTexture() OVERRIDE { |
1540 ++prepare_called_; | 1547 ++prepare_called_; |
1541 return texture_; | 1548 return texture_; |
1542 } | 1549 } |
1543 | 1550 virtual bool IsContextLost() OVERRIDE { return false; } |
1544 // TextureLayerClient implementation. | 1551 virtual void RateLimitContext() OVERRIDE {} |
1545 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
1546 return client_context_.get(); | |
1547 } | |
1548 | |
1549 // TextureLayerClient implementation. | |
1550 virtual bool PrepareTextureMailbox( | 1552 virtual bool PrepareTextureMailbox( |
1551 cc::TextureMailbox* mailbox, | 1553 cc::TextureMailbox* mailbox, |
1552 scoped_ptr<SingleReleaseCallback>* release_callback, | 1554 scoped_ptr<SingleReleaseCallback>* release_callback, |
1553 bool use_shared_memory) OVERRIDE { | 1555 bool use_shared_memory) OVERRIDE { |
1554 return false; | 1556 return false; |
1555 } | 1557 } |
1556 | 1558 |
1557 virtual void SetupTree() OVERRIDE { | 1559 virtual void SetupTree() OVERRIDE { |
1558 scoped_refptr<Layer> root = Layer::Create(); | 1560 scoped_refptr<Layer> root = Layer::Create(); |
1559 root->SetBounds(gfx::Size(10, 10)); | 1561 root->SetBounds(gfx::Size(10, 10)); |
(...skipping 30 matching lines...) Expand all Loading... |
1590 switch (commit_count_) { | 1592 switch (commit_count_) { |
1591 case 1: | 1593 case 1: |
1592 // We should have updated the layer, committing the texture. | 1594 // We should have updated the layer, committing the texture. |
1593 EXPECT_EQ(1, prepare_called_); | 1595 EXPECT_EQ(1, prepare_called_); |
1594 // Make layer invisible. | 1596 // Make layer invisible. |
1595 parent_layer_->SetOpacity(0.f); | 1597 parent_layer_->SetOpacity(0.f); |
1596 break; | 1598 break; |
1597 case 2: { | 1599 case 2: { |
1598 // Layer shouldn't have been updated. | 1600 // Layer shouldn't have been updated. |
1599 EXPECT_EQ(1, prepare_called_); | 1601 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(); | 1602 texture_layer_->SetNeedsDisplay(); |
1604 // Force a change to make sure we draw a frame. | 1603 // Force a change to make sure we draw a frame. |
1605 solid_layer_->SetBackgroundColor(SK_ColorGRAY); | 1604 solid_layer_->SetBackgroundColor(SK_ColorGRAY); |
1606 break; | 1605 break; |
1607 } | 1606 } |
1608 case 3: | 1607 case 3: |
1609 EXPECT_EQ(1, prepare_called_); | 1608 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. | 1609 // Make layer visible again. |
1613 parent_layer_->SetOpacity(1.f); | 1610 parent_layer_->SetOpacity(1.f); |
1614 break; | 1611 break; |
1615 case 4: { | 1612 case 4: { |
1616 // Layer should have been updated. | 1613 // Layer should have been updated. |
1617 EXPECT_EQ(2, prepare_called_); | 1614 EXPECT_EQ(2, prepare_called_); |
1618 texture_layer_->ClearClient(); | 1615 texture_layer_->ClearClient(); |
1619 client_context_->deleteTexture(texture_); | |
1620 texture_ = 0; | 1616 texture_ = 0; |
1621 break; | 1617 break; |
1622 } | 1618 } |
1623 case 5: | 1619 case 5: |
1624 EndTest(); | 1620 EndTest(); |
1625 break; | 1621 break; |
1626 default: | 1622 default: |
1627 NOTREACHED(); | 1623 NOTREACHED(); |
1628 break; | 1624 break; |
1629 } | 1625 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1669 | 1665 |
1670 private: | 1666 private: |
1671 TestWebGraphicsContext3D* ContextForImplThread(LayerTreeHostImpl* host_impl) { | 1667 TestWebGraphicsContext3D* ContextForImplThread(LayerTreeHostImpl* host_impl) { |
1672 return static_cast<TestWebGraphicsContext3D*>( | 1668 return static_cast<TestWebGraphicsContext3D*>( |
1673 host_impl->output_surface()->context_provider()->Context3d()); | 1669 host_impl->output_surface()->context_provider()->Context3d()); |
1674 } | 1670 } |
1675 | 1671 |
1676 scoped_refptr<SolidColorLayer> solid_layer_; | 1672 scoped_refptr<SolidColorLayer> solid_layer_; |
1677 scoped_refptr<Layer> parent_layer_; | 1673 scoped_refptr<Layer> parent_layer_; |
1678 scoped_refptr<TextureLayer> texture_layer_; | 1674 scoped_refptr<TextureLayer> texture_layer_; |
1679 scoped_ptr<TestWebGraphicsContext3D> client_context_; | |
1680 | 1675 |
1681 // Used on the main thread, and on the impl thread while the main thread is | 1676 // Used on the main thread, and on the impl thread while the main thread is |
1682 // blocked. | 1677 // blocked. |
1683 unsigned texture_; | 1678 unsigned texture_; |
1684 | 1679 |
1685 // Used on the main thread. | 1680 // Used on the main thread. |
1686 unsigned texture_to_delete_on_next_commit_; | |
1687 int prepare_called_; | 1681 int prepare_called_; |
1688 int commit_count_; | 1682 int commit_count_; |
1689 | 1683 |
1690 // Used on the compositor thread. | 1684 // Used on the compositor thread. |
1691 unsigned expected_texture_on_draw_; | 1685 unsigned expected_texture_on_draw_; |
1692 }; | 1686 }; |
1693 | 1687 |
1694 // The TextureLayerChangeInvisibleTest does not use mailboxes, so can't use a | 1688 // The TextureLayerChangeInvisibleTest does not use mailboxes, so can't use a |
1695 // delegating renderer. | 1689 // delegating renderer. |
1696 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerChangeInvisibleTest); | 1690 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerChangeInvisibleTest); |
1697 | 1691 |
1698 // Checks that TextureLayer::Update does not cause an extra commit when setting | 1692 // Checks that TextureLayer::Update does not cause an extra commit when setting |
1699 // the texture mailbox. | 1693 // the texture mailbox. |
1700 class TextureLayerNoExtraCommitForMailboxTest | 1694 class TextureLayerNoExtraCommitForMailboxTest |
1701 : public LayerTreeTest, | 1695 : public LayerTreeTest, |
1702 public TextureLayerClient { | 1696 public TextureLayerClient { |
1703 public: | 1697 public: |
1704 TextureLayerNoExtraCommitForMailboxTest() | 1698 TextureLayerNoExtraCommitForMailboxTest() |
1705 : prepare_mailbox_count_(0) {} | 1699 : prepare_mailbox_count_(0) {} |
1706 | 1700 |
1707 // TextureLayerClient implementation. | 1701 // TextureLayerClient implementation. |
1708 virtual unsigned PrepareTexture() OVERRIDE { | 1702 virtual unsigned PrepareTexture() OVERRIDE { |
1709 NOTREACHED(); | 1703 NOTREACHED(); |
1710 return 0; | 1704 return 0; |
1711 } | 1705 } |
1712 | 1706 virtual bool IsContextLost() OVERRIDE { return false; } |
1713 // TextureLayerClient implementation. | 1707 virtual void RateLimitContext() OVERRIDE {} |
1714 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
1715 NOTREACHED(); | |
1716 return NULL; | |
1717 } | |
1718 | 1708 |
1719 virtual bool PrepareTextureMailbox( | 1709 virtual bool PrepareTextureMailbox( |
1720 cc::TextureMailbox* mailbox, | 1710 cc::TextureMailbox* mailbox, |
1721 scoped_ptr<SingleReleaseCallback>* release_callback, | 1711 scoped_ptr<SingleReleaseCallback>* release_callback, |
1722 bool use_shared_memory) OVERRIDE { | 1712 bool use_shared_memory) OVERRIDE { |
1723 prepare_mailbox_count_++; | 1713 prepare_mailbox_count_++; |
1724 // Alternate between two mailboxes to ensure that the TextureLayer updates | 1714 // Alternate between two mailboxes to ensure that the TextureLayer updates |
1725 // and commits. | 1715 // and commits. |
1726 if (prepare_mailbox_count_ % 2 == 0) | 1716 if (prepare_mailbox_count_ % 2 == 0) |
1727 *mailbox = MakeMailbox('1'); | 1717 *mailbox = MakeMailbox('1'); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1811 prepare_called_(0), | 1801 prepare_called_(0), |
1812 commit_count_(0) { | 1802 commit_count_(0) { |
1813 mailbox_ = MakeMailbox('1'); | 1803 mailbox_ = MakeMailbox('1'); |
1814 } | 1804 } |
1815 | 1805 |
1816 // TextureLayerClient implementation. | 1806 // TextureLayerClient implementation. |
1817 virtual unsigned PrepareTexture() OVERRIDE { | 1807 virtual unsigned PrepareTexture() OVERRIDE { |
1818 NOTREACHED(); | 1808 NOTREACHED(); |
1819 return 0; | 1809 return 0; |
1820 } | 1810 } |
| 1811 virtual bool IsContextLost() OVERRIDE { return false; } |
| 1812 virtual void RateLimitContext() OVERRIDE {} |
1821 | 1813 |
1822 // TextureLayerClient implementation. | |
1823 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
1824 NOTREACHED(); | |
1825 return NULL; | |
1826 } | |
1827 | |
1828 // TextureLayerClient implementation. | |
1829 virtual bool PrepareTextureMailbox( | 1814 virtual bool PrepareTextureMailbox( |
1830 cc::TextureMailbox* mailbox, | 1815 cc::TextureMailbox* mailbox, |
1831 scoped_ptr<SingleReleaseCallback>* release_callback, | 1816 scoped_ptr<SingleReleaseCallback>* release_callback, |
1832 bool use_shared_memory) OVERRIDE { | 1817 bool use_shared_memory) OVERRIDE { |
1833 ++prepare_called_; | 1818 ++prepare_called_; |
1834 if (!mailbox_changed_) | 1819 if (!mailbox_changed_) |
1835 return false; | 1820 return false; |
1836 *mailbox = mailbox_; | 1821 *mailbox = mailbox_; |
1837 *release_callback = SingleReleaseCallback::Create( | 1822 *release_callback = SingleReleaseCallback::Create( |
1838 base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased, | 1823 base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 }; | 1943 }; |
1959 | 1944 |
1960 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest); | 1945 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest); |
1961 | 1946 |
1962 // Test recovering from a lost context. | 1947 // Test recovering from a lost context. |
1963 class TextureLayerLostContextTest | 1948 class TextureLayerLostContextTest |
1964 : public LayerTreeTest, | 1949 : public LayerTreeTest, |
1965 public TextureLayerClient { | 1950 public TextureLayerClient { |
1966 public: | 1951 public: |
1967 TextureLayerLostContextTest() | 1952 TextureLayerLostContextTest() |
1968 : texture_(0), | 1953 : context_lost_(false), |
1969 draw_count_(0) {} | 1954 draw_count_(0) {} |
1970 | 1955 |
1971 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) | 1956 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
1972 OVERRIDE { | 1957 OVERRIDE { |
1973 texture_context_ = TestWebGraphicsContext3D::Create(); | |
1974 texture_ = texture_context_->createTexture(); | |
1975 return CreateFakeOutputSurface(); | 1958 return CreateFakeOutputSurface(); |
1976 } | 1959 } |
1977 | 1960 |
1978 virtual unsigned PrepareTexture() OVERRIDE { | 1961 virtual unsigned PrepareTexture() OVERRIDE { |
1979 if (draw_count_ == 0) { | 1962 if (draw_count_ == 0) { |
1980 texture_context_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 1963 context_lost_ = true; |
1981 GL_INNOCENT_CONTEXT_RESET_ARB); | 1964 return 0u; |
1982 } | 1965 } |
1983 return texture_; | 1966 return 1u; |
1984 } | 1967 } |
1985 | 1968 |
1986 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | 1969 virtual bool IsContextLost() OVERRIDE { |
1987 return texture_context_.get(); | 1970 return context_lost_; |
1988 } | 1971 } |
| 1972 virtual void RateLimitContext() OVERRIDE {} |
1989 | 1973 |
1990 virtual bool PrepareTextureMailbox( | 1974 virtual bool PrepareTextureMailbox( |
1991 TextureMailbox* mailbox, | 1975 TextureMailbox* mailbox, |
1992 scoped_ptr<SingleReleaseCallback>* release_callback, | 1976 scoped_ptr<SingleReleaseCallback>* release_callback, |
1993 bool use_shared_memory) OVERRIDE { | 1977 bool use_shared_memory) OVERRIDE { |
1994 return false; | 1978 return false; |
1995 } | 1979 } |
1996 | 1980 |
1997 virtual void SetupTree() OVERRIDE { | 1981 virtual void SetupTree() OVERRIDE { |
1998 scoped_refptr<Layer> root = Layer::Create(); | 1982 scoped_refptr<Layer> root = Layer::Create(); |
(...skipping 15 matching lines...) Expand all Loading... |
2014 | 1998 |
2015 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 1999 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
2016 LayerTreeHostImpl::FrameData* frame_data, | 2000 LayerTreeHostImpl::FrameData* frame_data, |
2017 bool result) OVERRIDE { | 2001 bool result) OVERRIDE { |
2018 LayerImpl* root = host_impl->RootLayer(); | 2002 LayerImpl* root = host_impl->RootLayer(); |
2019 TextureLayerImpl* texture_layer = | 2003 TextureLayerImpl* texture_layer = |
2020 static_cast<TextureLayerImpl*>(root->children()[0]); | 2004 static_cast<TextureLayerImpl*>(root->children()[0]); |
2021 if (++draw_count_ == 1) | 2005 if (++draw_count_ == 1) |
2022 EXPECT_EQ(0u, texture_layer->texture_id()); | 2006 EXPECT_EQ(0u, texture_layer->texture_id()); |
2023 else | 2007 else |
2024 EXPECT_EQ(texture_, texture_layer->texture_id()); | 2008 EXPECT_EQ(1u, texture_layer->texture_id()); |
2025 return true; | 2009 return true; |
2026 } | 2010 } |
2027 | 2011 |
2028 virtual void DidCommitAndDrawFrame() OVERRIDE { | 2012 virtual void DidCommitAndDrawFrame() OVERRIDE { |
2029 EndTest(); | 2013 EndTest(); |
2030 } | 2014 } |
2031 | 2015 |
2032 virtual void AfterTest() OVERRIDE {} | 2016 virtual void AfterTest() OVERRIDE {} |
2033 | 2017 |
2034 private: | 2018 private: |
2035 scoped_refptr<TextureLayer> texture_layer_; | 2019 scoped_refptr<TextureLayer> texture_layer_; |
2036 scoped_ptr<TestWebGraphicsContext3D> texture_context_; | 2020 bool context_lost_; |
2037 unsigned texture_; | |
2038 int draw_count_; | 2021 int draw_count_; |
2039 }; | 2022 }; |
2040 | 2023 |
2041 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerLostContextTest); | 2024 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerLostContextTest); |
2042 | 2025 |
2043 class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest { | 2026 class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest { |
2044 public: | 2027 public: |
2045 void ReleaseCallback(unsigned sync_point, bool lost_resource) { | 2028 void ReleaseCallback(unsigned sync_point, bool lost_resource) { |
2046 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 2029 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
2047 EXPECT_FALSE(lost_resource); | 2030 EXPECT_FALSE(lost_resource); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2182 int callback_count_; | 2165 int callback_count_; |
2183 scoped_refptr<Layer> root_; | 2166 scoped_refptr<Layer> root_; |
2184 scoped_refptr<TextureLayer> layer_; | 2167 scoped_refptr<TextureLayer> layer_; |
2185 }; | 2168 }; |
2186 | 2169 |
2187 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 2170 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
2188 TextureLayerWithMailboxImplThreadDeleted); | 2171 TextureLayerWithMailboxImplThreadDeleted); |
2189 | 2172 |
2190 } // namespace | 2173 } // namespace |
2191 } // namespace cc | 2174 } // namespace cc |
OLD | NEW |