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

Side by Side Diff: cc/scoped_texture_unittest.cc

Issue 11232051: Remove static thread pointers from CC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Apply code review comments Created 8 years, 1 month 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
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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/scoped_texture.h" 7 #include "cc/scoped_texture.h"
8 8
9 #include "cc/renderer.h" 9 #include "cc/renderer.h"
10 #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread
11 #include "cc/test/fake_graphics_context.h" 10 #include "cc/test/fake_graphics_context.h"
12 #include "cc/test/tiled_layer_test_common.h" 11 #include "cc/test/tiled_layer_test_common.h"
13 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/khronos/GLES2/gl2.h" 13 #include "third_party/khronos/GLES2/gl2.h"
15 14
16 using namespace cc; 15 using namespace cc;
17 using namespace WebKit; 16 using namespace WebKit;
18 using namespace WebKitTests; 17 using namespace WebKitTests;
19 18
20 namespace { 19 namespace {
21 20
22 TEST(ScopedTextureTest, NewScopedTexture) 21 TEST(ScopedTextureTest, NewScopedTexture)
23 { 22 {
24 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); 23 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext());
25 DebugScopedSetImplThread implThread;
26 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get())); 24 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
27 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvider.g et()); 25 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvider.g et());
28 26
29 // New scoped textures do not hold a texture yet. 27 // New scoped textures do not hold a texture yet.
30 EXPECT_EQ(0u, texture->id()); 28 EXPECT_EQ(0u, texture->id());
31 29
32 // New scoped textures do not have a size yet. 30 // New scoped textures do not have a size yet.
33 EXPECT_EQ(gfx::Size(), texture->size()); 31 EXPECT_EQ(gfx::Size(), texture->size());
34 EXPECT_EQ(0u, texture->bytes()); 32 EXPECT_EQ(0u, texture->bytes());
35 } 33 }
36 34
37 TEST(ScopedTextureTest, CreateScopedTexture) 35 TEST(ScopedTextureTest, CreateScopedTexture)
38 { 36 {
39 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); 37 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext());
40 DebugScopedSetImplThread implThread;
41 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get())); 38 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
42 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvider.g et()); 39 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvider.g et());
43 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, ResourcePr ovider::TextureUsageAny); 40 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, ResourcePr ovider::TextureUsageAny);
44 41
45 // The texture has an allocated byte-size now. 42 // The texture has an allocated byte-size now.
46 size_t expectedBytes = 30 * 30 * 4; 43 size_t expectedBytes = 30 * 30 * 4;
47 EXPECT_EQ(expectedBytes, texture->bytes()); 44 EXPECT_EQ(expectedBytes, texture->bytes());
48 45
49 EXPECT_LT(0u, texture->id()); 46 EXPECT_LT(0u, texture->id());
50 EXPECT_EQ(GL_RGBA, texture->format()); 47 EXPECT_EQ(GL_RGBA, texture->format());
51 EXPECT_EQ(gfx::Size(30, 30), texture->size()); 48 EXPECT_EQ(gfx::Size(30, 30), texture->size());
52 } 49 }
53 50
54 TEST(ScopedTextureTest, ScopedTextureIsDeleted) 51 TEST(ScopedTextureTest, ScopedTextureIsDeleted)
55 { 52 {
56 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); 53 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext());
57 DebugScopedSetImplThread implThread;
58 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get())); 54 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
59 55
60 { 56 {
61 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid er.get()); 57 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid er.get());
62 58
63 EXPECT_EQ(0u, resourceProvider->numResources()); 59 EXPECT_EQ(0u, resourceProvider->numResources());
64 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, Resour ceProvider::TextureUsageAny); 60 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, Resour ceProvider::TextureUsageAny);
65 EXPECT_LT(0u, texture->id()); 61 EXPECT_LT(0u, texture->id());
66 EXPECT_EQ(1u, resourceProvider->numResources()); 62 EXPECT_EQ(1u, resourceProvider->numResources());
67 } 63 }
68 64
69 EXPECT_EQ(0u, resourceProvider->numResources()); 65 EXPECT_EQ(0u, resourceProvider->numResources());
70 66
71 { 67 {
72 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid er.get()); 68 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid er.get());
73 EXPECT_EQ(0u, resourceProvider->numResources()); 69 EXPECT_EQ(0u, resourceProvider->numResources());
74 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, Resour ceProvider::TextureUsageAny); 70 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, Resour ceProvider::TextureUsageAny);
75 EXPECT_LT(0u, texture->id()); 71 EXPECT_LT(0u, texture->id());
76 EXPECT_EQ(1u, resourceProvider->numResources()); 72 EXPECT_EQ(1u, resourceProvider->numResources());
77 texture->free(); 73 texture->free();
78 EXPECT_EQ(0u, resourceProvider->numResources()); 74 EXPECT_EQ(0u, resourceProvider->numResources());
79 } 75 }
80 } 76 }
81 77
82 TEST(ScopedTextureTest, LeakScopedTexture) 78 TEST(ScopedTextureTest, LeakScopedTexture)
83 { 79 {
84 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); 80 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext());
85 DebugScopedSetImplThread implThread;
86 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get())); 81 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
87 82
88 { 83 {
89 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid er.get()); 84 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid er.get());
90 85
91 EXPECT_EQ(0u, resourceProvider->numResources()); 86 EXPECT_EQ(0u, resourceProvider->numResources());
92 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, Resour ceProvider::TextureUsageAny); 87 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, Resour ceProvider::TextureUsageAny);
93 EXPECT_LT(0u, texture->id()); 88 EXPECT_LT(0u, texture->id());
94 EXPECT_EQ(1u, resourceProvider->numResources()); 89 EXPECT_EQ(1u, resourceProvider->numResources());
95 90
96 texture->leak(); 91 texture->leak();
97 EXPECT_EQ(0u, texture->id()); 92 EXPECT_EQ(0u, texture->id());
98 EXPECT_EQ(1u, resourceProvider->numResources()); 93 EXPECT_EQ(1u, resourceProvider->numResources());
99 94
100 texture->free(); 95 texture->free();
101 EXPECT_EQ(0u, texture->id()); 96 EXPECT_EQ(0u, texture->id());
102 EXPECT_EQ(1u, resourceProvider->numResources()); 97 EXPECT_EQ(1u, resourceProvider->numResources());
103 } 98 }
104 99
105 EXPECT_EQ(1u, resourceProvider->numResources()); 100 EXPECT_EQ(1u, resourceProvider->numResources());
106 } 101 }
107 102
108 } // anonymous namespace 103 } // anonymous namespace
OLDNEW
« no previous file with comments | « cc/resource_update_controller_unittest.cc ('k') | cc/scrollbar_animation_controller_linear_fade_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698