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

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: Added test 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 was 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 delete_texture_on_next_commit_(0) {}
489
490 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE {
491 scoped_ptr<WebKit::WebGraphicsContext3D> context(
492 TestWebGraphicsContext3D::Create());
493 context_ = context.get();
494 texture_ = context->createTexture();
495 return FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>();
496 }
497
498 virtual unsigned PrepareTexture(ResourceUpdateQueue* queue) {
499 return texture_;
500 }
501
502 virtual WebKit::WebGraphicsContext3D* Context3d() {
503 return context_;
504 }
505
506 virtual void SetupTree() OVERRIDE {
507 scoped_refptr<Layer> root = Layer::Create();
508 root->SetBounds(gfx::Size(10, 10));
509 root->SetAnchorPoint(gfx::PointF());
510 root->SetIsDrawable(true);
511
512 texture_layer_ = TextureLayer::Create(this);
513 texture_layer_->SetBounds(gfx::Size(10, 10));
514 texture_layer_->SetAnchorPoint(gfx::PointF());
515 texture_layer_->SetIsDrawable(true);
516 root->AddChild(texture_layer_);
517
518 layer_tree_host()->SetRootLayer(root);
519 LayerTreeTest::SetupTree();
520 }
521
522 virtual void BeginTest() OVERRIDE {
523 PostSetNeedsCommitToMainThread();
524 }
525
526 virtual void DidCommitAndDrawFrame() OVERRIDE {
527 ++commit_count_;
528 switch (commit_count_) {
529 case 1:
530 texture_layer_->ClearClient();
531 {
532 // We want to delete the texture, so that if the layer still uses it
danakj 2013/03/28 01:44:44 The test looks good, but would it be more straight
piman 2013/03/28 03:11:35 Fair enough, I tried it on the new patch. It requi
533 // we'll trigger the assert in TestWebGraphicsContext3D.
534 // However at this point, we can only safely access the context on the
535 // thread, so we'll do that on the next commit.
536 base::AutoLock lock(lock_);
537 delete_texture_on_next_commit_ = texture_;
538 }
539 texture_ = 0;
540 break;
541 case 2:
542 EndTest();
543 break;
544 default:
545 NOTREACHED();
546 break;
547 }
548 }
549
550 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) {
551 base::AutoLock lock(lock_);
552 if (delete_texture_on_next_commit_) {
553 context_->deleteTexture(delete_texture_on_next_commit_);
554 delete_texture_on_next_commit_ = 0;
555 }
556 }
557
558 virtual void AfterTest() OVERRIDE {}
559
560 private:
561 scoped_refptr<TextureLayer> texture_layer_;
562 WebKit::WebGraphicsContext3D* context_;
563 unsigned texture_;
564 int commit_count_;
565
566 base::Lock lock_;
567 unsigned delete_texture_on_next_commit_;
568 };
569
570 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerClientTest);
571
477 } // namespace 572 } // namespace
478 } // namespace cc 573 } // 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