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

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

Issue 13126002: TextureLayer: clear texture id when clearing client (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add SetNeedsDisplay Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layers/texture_layer.cc ('k') | webkit/plugins/ppapi/ppapi_plugin_instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/texture_layer.h" 5 #include "cc/layers/texture_layer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "cc/base/thread.h" 10 #include "cc/base/thread.h"
11 #include "cc/layers/texture_layer_client.h"
11 #include "cc/layers/texture_layer_impl.h" 12 #include "cc/layers/texture_layer_impl.h"
12 #include "cc/test/fake_impl_proxy.h" 13 #include "cc/test/fake_impl_proxy.h"
13 #include "cc/test/fake_layer_tree_host_client.h" 14 #include "cc/test/fake_layer_tree_host_client.h"
14 #include "cc/test/fake_layer_tree_host_impl.h" 15 #include "cc/test/fake_layer_tree_host_impl.h"
15 #include "cc/test/layer_tree_test.h" 16 #include "cc/test/layer_tree_test.h"
16 #include "cc/trees/layer_tree_host.h" 17 #include "cc/trees/layer_tree_host.h"
17 #include "cc/trees/layer_tree_impl.h" 18 #include "cc/trees/layer_tree_impl.h"
18 #include "cc/trees/single_thread_proxy.h" 19 #include "cc/trees/single_thread_proxy.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 provider->PrepareSendToParent(resource_ids_to_transfer, &list); 468 provider->PrepareSendToParent(resource_ids_to_transfer, &list);
468 EXPECT_TRUE(provider->InUseByConsumer(id)); 469 EXPECT_TRUE(provider->InUseByConsumer(id));
469 EXPECT_CALL(test_data_.mock_callback_, Release(_, _)).Times(0); 470 EXPECT_CALL(test_data_.mock_callback_, Release(_, _)).Times(0);
470 provider->DeleteResource(id); 471 provider->DeleteResource(id);
471 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); 472 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
472 EXPECT_CALL(test_data_.mock_callback_, Release(test_data_.mailbox_name1_, _)) 473 EXPECT_CALL(test_data_.mock_callback_, Release(test_data_.mailbox_name1_, _))
473 .Times(1); 474 .Times(1);
474 provider->ReceiveFromParent(list); 475 provider->ReceiveFromParent(list);
475 } 476 }
476 477
478 // Check that ClearClient correctly clears the state so that the impl side
479 // doesn't try to use a texture that could have been destroyed.
480 class TextureLayerClientTest :
481 public LayerTreeTest,
482 public TextureLayerClient {
483 public:
484 TextureLayerClientTest()
485 : context_(NULL),
486 texture_(0),
487 commit_count_(0),
488 expected_used_textures_on_draw_(0),
489 expected_used_textures_on_commit_(0) {}
490
491 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE {
492 scoped_ptr<TestWebGraphicsContext3D> context(
493 TestWebGraphicsContext3D::Create());
494 context_ = context.get();
495 texture_ = context->createTexture();
496 return FakeOutputSurface::Create3d(
497 context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>();
498 }
499
500 virtual unsigned PrepareTexture(ResourceUpdateQueue* queue) {
501 return texture_;
502 }
503
504 virtual WebKit::WebGraphicsContext3D* Context3d() {
505 return context_;
506 }
507
508 virtual void SetupTree() OVERRIDE {
509 scoped_refptr<Layer> root = Layer::Create();
510 root->SetBounds(gfx::Size(10, 10));
511 root->SetAnchorPoint(gfx::PointF());
512 root->SetIsDrawable(true);
513
514 texture_layer_ = TextureLayer::Create(this);
515 texture_layer_->SetBounds(gfx::Size(10, 10));
516 texture_layer_->SetAnchorPoint(gfx::PointF());
517 texture_layer_->SetIsDrawable(true);
518 root->AddChild(texture_layer_);
519
520 layer_tree_host()->SetRootLayer(root);
521 LayerTreeTest::SetupTree();
522 {
523 base::AutoLock lock(lock_);
524 expected_used_textures_on_commit_ = 1;
525 }
526 }
527
528 virtual void BeginTest() OVERRIDE {
529 PostSetNeedsCommitToMainThread();
530 }
531
532 virtual void DidCommitAndDrawFrame() OVERRIDE {
533 ++commit_count_;
534 switch (commit_count_) {
535 case 1:
536 texture_layer_->ClearClient();
537 texture_layer_->SetNeedsDisplay();
538 {
539 base::AutoLock lock(lock_);
540 expected_used_textures_on_commit_ = 0;
541 }
542 texture_ = 0;
543 break;
544 case 2:
545 EndTest();
546 break;
547 default:
548 NOTREACHED();
549 break;
550 }
551 }
552
553 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
554 base::AutoLock lock(lock_);
555 expected_used_textures_on_draw_ = expected_used_textures_on_commit_;
556 }
557
558 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
559 LayerTreeHostImpl::FrameData* frame_data,
560 bool result) OVERRIDE {
561 context_->ResetUsedTextures();
562 return true;
563 }
564
565 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
566 bool result) OVERRIDE {
567 ASSERT_TRUE(result);
568 EXPECT_EQ(expected_used_textures_on_draw_, context_->NumUsedTextures());
569 }
570
571 virtual void AfterTest() OVERRIDE {}
572
573 private:
574 scoped_refptr<TextureLayer> texture_layer_;
575 TestWebGraphicsContext3D* context_;
576 unsigned texture_;
577 int commit_count_;
578
579 // Used only on thread.
580 unsigned expected_used_textures_on_draw_;
581
582 // Used on either thread, protected by lock_.
583 base::Lock lock_;
584 unsigned expected_used_textures_on_commit_;
585 };
586
587 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerClientTest);
588
477 } // namespace 589 } // namespace
478 } // namespace cc 590 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/texture_layer.cc ('k') | webkit/plugins/ppapi/ppapi_plugin_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698