| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/output/texture_mailbox_deleter.h" | 5 #include "cc/output/texture_mailbox_deleter.h" |
| 6 | 6 |
| 7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "cc/resources/single_release_callback.h" | 9 #include "cc/resources/single_release_callback.h" |
| 10 #include "cc/test/test_context_provider.h" | 10 #include "cc/test/test_context_provider.h" |
| 11 #include "cc/test/test_web_graphics_context_3d.h" | 11 #include "cc/test/test_web_graphics_context_3d.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 TEST(TextureMailboxDeleterTest, Destroy) { | 17 TEST(TextureMailboxDeleterTest, Destroy) { |
| 18 std::unique_ptr<TextureMailboxDeleter> deleter( | 18 std::unique_ptr<TextureMailboxDeleter> deleter( |
| 19 new TextureMailboxDeleter(base::ThreadTaskRunnerHandle::Get())); | 19 new TextureMailboxDeleter(base::ThreadTaskRunnerHandle::Get())); |
| 20 | 20 |
| 21 scoped_refptr<TestContextProvider> context_provider = | 21 scoped_refptr<TestContextProvider> context_provider = |
| 22 TestContextProvider::Create(); | 22 TestContextProvider::Create(); |
| 23 context_provider->BindToCurrentThread(); | |
| 24 | 23 |
| 25 GLuint texture_id = 0u; | 24 GLuint texture_id = 0u; |
| 26 context_provider->ContextGL()->GenTextures(1, &texture_id); | 25 context_provider->ContextGL()->GenTextures(1, &texture_id); |
| 27 | 26 |
| 28 EXPECT_TRUE(context_provider->HasOneRef()); | 27 EXPECT_TRUE(context_provider->HasOneRef()); |
| 29 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); | 28 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); |
| 30 | 29 |
| 31 std::unique_ptr<SingleReleaseCallback> cb = | 30 std::unique_ptr<SingleReleaseCallback> cb = |
| 32 deleter->GetReleaseCallback(context_provider, texture_id); | 31 deleter->GetReleaseCallback(context_provider, texture_id); |
| 33 EXPECT_FALSE(context_provider->HasOneRef()); | 32 EXPECT_FALSE(context_provider->HasOneRef()); |
| 34 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); | 33 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); |
| 35 | 34 |
| 36 // When the deleter is destroyed, it immediately drops its ref on the | 35 // When the deleter is destroyed, it immediately drops its ref on the |
| 37 // ContextProvider, and deletes the texture. | 36 // ContextProvider, and deletes the texture. |
| 38 deleter = nullptr; | 37 deleter = nullptr; |
| 39 EXPECT_TRUE(context_provider->HasOneRef()); | 38 EXPECT_TRUE(context_provider->HasOneRef()); |
| 40 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); | 39 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); |
| 41 | 40 |
| 42 // Run the scoped release callback before destroying it, but it won't do | 41 // Run the scoped release callback before destroying it, but it won't do |
| 43 // anything. | 42 // anything. |
| 44 cb->Run(gpu::SyncToken(), false); | 43 cb->Run(gpu::SyncToken(), false); |
| 45 } | 44 } |
| 46 | 45 |
| 47 TEST(TextureMailboxDeleterTest, NullTaskRunner) { | 46 TEST(TextureMailboxDeleterTest, NullTaskRunner) { |
| 48 std::unique_ptr<TextureMailboxDeleter> deleter( | 47 std::unique_ptr<TextureMailboxDeleter> deleter( |
| 49 new TextureMailboxDeleter(nullptr)); | 48 new TextureMailboxDeleter(nullptr)); |
| 50 | 49 |
| 51 scoped_refptr<TestContextProvider> context_provider = | 50 scoped_refptr<TestContextProvider> context_provider = |
| 52 TestContextProvider::Create(); | 51 TestContextProvider::Create(); |
| 53 context_provider->BindToCurrentThread(); | |
| 54 | 52 |
| 55 GLuint texture_id = 0u; | 53 GLuint texture_id = 0u; |
| 56 context_provider->ContextGL()->GenTextures(1, &texture_id); | 54 context_provider->ContextGL()->GenTextures(1, &texture_id); |
| 57 | 55 |
| 58 EXPECT_TRUE(context_provider->HasOneRef()); | 56 EXPECT_TRUE(context_provider->HasOneRef()); |
| 59 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); | 57 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); |
| 60 | 58 |
| 61 std::unique_ptr<SingleReleaseCallback> cb = | 59 std::unique_ptr<SingleReleaseCallback> cb = |
| 62 deleter->GetReleaseCallback(context_provider, texture_id); | 60 deleter->GetReleaseCallback(context_provider, texture_id); |
| 63 EXPECT_FALSE(context_provider->HasOneRef()); | 61 EXPECT_FALSE(context_provider->HasOneRef()); |
| 64 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); | 62 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); |
| 65 | 63 |
| 66 cb->Run(gpu::SyncToken(), false); | 64 cb->Run(gpu::SyncToken(), false); |
| 67 | 65 |
| 68 // With no task runner the callback will immediately drops its ref on the | 66 // With no task runner the callback will immediately drops its ref on the |
| 69 // ContextProvider and delete the texture. | 67 // ContextProvider and delete the texture. |
| 70 EXPECT_TRUE(context_provider->HasOneRef()); | 68 EXPECT_TRUE(context_provider->HasOneRef()); |
| 71 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); | 69 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); |
| 72 } | 70 } |
| 73 | 71 |
| 74 } // namespace | 72 } // namespace |
| 75 } // namespace cc | 73 } // namespace cc |
| OLD | NEW |