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

Side by Side Diff: cc/output/texture_mailbox_deleter_unittest.cc

Issue 1866203004: Convert //cc from scoped_ptr to std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptrcc: rebase Created 4 years, 8 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
« no previous file with comments | « cc/output/texture_mailbox_deleter.cc ('k') | cc/output/vulkan_in_process_context_provider.h » ('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 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/thread_task_runner_handle.h" 8 #include "base/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 scoped_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(); 23 context_provider->BindToCurrentThread();
24 24
25 GLuint texture_id = 0u; 25 GLuint texture_id = 0u;
26 context_provider->ContextGL()->GenTextures(1, &texture_id); 26 context_provider->ContextGL()->GenTextures(1, &texture_id);
27 27
28 EXPECT_TRUE(context_provider->HasOneRef()); 28 EXPECT_TRUE(context_provider->HasOneRef());
29 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); 29 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures());
30 30
31 scoped_ptr<SingleReleaseCallback> cb = 31 std::unique_ptr<SingleReleaseCallback> cb =
32 deleter->GetReleaseCallback(context_provider, texture_id); 32 deleter->GetReleaseCallback(context_provider, texture_id);
33 EXPECT_FALSE(context_provider->HasOneRef()); 33 EXPECT_FALSE(context_provider->HasOneRef());
34 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); 34 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures());
35 35
36 // When the deleter is destroyed, it immediately drops its ref on the 36 // When the deleter is destroyed, it immediately drops its ref on the
37 // ContextProvider, and deletes the texture. 37 // ContextProvider, and deletes the texture.
38 deleter = nullptr; 38 deleter = nullptr;
39 EXPECT_TRUE(context_provider->HasOneRef()); 39 EXPECT_TRUE(context_provider->HasOneRef());
40 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); 40 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures());
41 41
42 // Run the scoped release callback before destroying it, but it won't do 42 // Run the scoped release callback before destroying it, but it won't do
43 // anything. 43 // anything.
44 cb->Run(gpu::SyncToken(), false); 44 cb->Run(gpu::SyncToken(), false);
45 } 45 }
46 46
47 TEST(TextureMailboxDeleterTest, NullTaskRunner) { 47 TEST(TextureMailboxDeleterTest, NullTaskRunner) {
48 scoped_ptr<TextureMailboxDeleter> deleter(new TextureMailboxDeleter(nullptr)); 48 std::unique_ptr<TextureMailboxDeleter> deleter(
49 new TextureMailboxDeleter(nullptr));
49 50
50 scoped_refptr<TestContextProvider> context_provider = 51 scoped_refptr<TestContextProvider> context_provider =
51 TestContextProvider::Create(); 52 TestContextProvider::Create();
52 context_provider->BindToCurrentThread(); 53 context_provider->BindToCurrentThread();
53 54
54 GLuint texture_id = 0u; 55 GLuint texture_id = 0u;
55 context_provider->ContextGL()->GenTextures(1, &texture_id); 56 context_provider->ContextGL()->GenTextures(1, &texture_id);
56 57
57 EXPECT_TRUE(context_provider->HasOneRef()); 58 EXPECT_TRUE(context_provider->HasOneRef());
58 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); 59 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures());
59 60
60 scoped_ptr<SingleReleaseCallback> cb = 61 std::unique_ptr<SingleReleaseCallback> cb =
61 deleter->GetReleaseCallback(context_provider, texture_id); 62 deleter->GetReleaseCallback(context_provider, texture_id);
62 EXPECT_FALSE(context_provider->HasOneRef()); 63 EXPECT_FALSE(context_provider->HasOneRef());
63 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); 64 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures());
64 65
65 cb->Run(gpu::SyncToken(), false); 66 cb->Run(gpu::SyncToken(), false);
66 67
67 // With no task runner the callback will immediately drops its ref on the 68 // With no task runner the callback will immediately drops its ref on the
68 // ContextProvider and delete the texture. 69 // ContextProvider and delete the texture.
69 EXPECT_TRUE(context_provider->HasOneRef()); 70 EXPECT_TRUE(context_provider->HasOneRef());
70 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); 71 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures());
71 } 72 }
72 73
73 } // namespace 74 } // namespace
74 } // namespace cc 75 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/texture_mailbox_deleter.cc ('k') | cc/output/vulkan_in_process_context_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698