OLD | NEW |
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 | 10 #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread |
(...skipping 12 matching lines...) Expand all Loading... |
23 { | 23 { |
24 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); | 24 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); |
25 DebugScopedSetImplThread implThread; | 25 DebugScopedSetImplThread implThread; |
26 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); | 26 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); |
27 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvider.g
et()); | 27 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvider.g
et()); |
28 | 28 |
29 // New scoped textures do not hold a texture yet. | 29 // New scoped textures do not hold a texture yet. |
30 EXPECT_EQ(0u, texture->id()); | 30 EXPECT_EQ(0u, texture->id()); |
31 | 31 |
32 // New scoped textures do not have a size yet. | 32 // New scoped textures do not have a size yet. |
33 EXPECT_EQ(IntSize(), texture->size()); | 33 EXPECT_EQ(gfx::Size(), texture->size()); |
34 EXPECT_EQ(0u, texture->bytes()); | 34 EXPECT_EQ(0u, texture->bytes()); |
35 } | 35 } |
36 | 36 |
37 TEST(ScopedTextureTest, CreateScopedTexture) | 37 TEST(ScopedTextureTest, CreateScopedTexture) |
38 { | 38 { |
39 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); | 39 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); |
40 DebugScopedSetImplThread implThread; | 40 DebugScopedSetImplThread implThread; |
41 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); | 41 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); |
42 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvider.g
et()); | 42 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvider.g
et()); |
43 texture->allocate(Renderer::ImplPool, IntSize(30, 30), GL_RGBA, ResourceProv
ider::TextureUsageAny); | 43 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, ResourcePr
ovider::TextureUsageAny); |
44 | 44 |
45 // The texture has an allocated byte-size now. | 45 // The texture has an allocated byte-size now. |
46 size_t expectedBytes = 30 * 30 * 4; | 46 size_t expectedBytes = 30 * 30 * 4; |
47 EXPECT_EQ(expectedBytes, texture->bytes()); | 47 EXPECT_EQ(expectedBytes, texture->bytes()); |
48 | 48 |
49 EXPECT_LT(0u, texture->id()); | 49 EXPECT_LT(0u, texture->id()); |
50 EXPECT_EQ(GL_RGBA, texture->format()); | 50 EXPECT_EQ(GL_RGBA, texture->format()); |
51 EXPECT_EQ(IntSize(30, 30), texture->size()); | 51 EXPECT_EQ(gfx::Size(30, 30), texture->size()); |
52 } | 52 } |
53 | 53 |
54 TEST(ScopedTextureTest, ScopedTextureIsDeleted) | 54 TEST(ScopedTextureTest, ScopedTextureIsDeleted) |
55 { | 55 { |
56 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); | 56 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); |
57 DebugScopedSetImplThread implThread; | 57 DebugScopedSetImplThread implThread; |
58 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); | 58 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); |
59 | 59 |
60 { | 60 { |
61 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid
er.get()); | 61 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid
er.get()); |
62 | 62 |
63 EXPECT_EQ(0u, resourceProvider->numResources()); | 63 EXPECT_EQ(0u, resourceProvider->numResources()); |
64 texture->allocate(Renderer::ImplPool, IntSize(30, 30), GL_RGBA, Resource
Provider::TextureUsageAny); | 64 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, Resour
ceProvider::TextureUsageAny); |
65 EXPECT_LT(0u, texture->id()); | 65 EXPECT_LT(0u, texture->id()); |
66 EXPECT_EQ(1u, resourceProvider->numResources()); | 66 EXPECT_EQ(1u, resourceProvider->numResources()); |
67 } | 67 } |
68 | 68 |
69 EXPECT_EQ(0u, resourceProvider->numResources()); | 69 EXPECT_EQ(0u, resourceProvider->numResources()); |
70 | 70 |
71 { | 71 { |
72 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid
er.get()); | 72 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid
er.get()); |
73 EXPECT_EQ(0u, resourceProvider->numResources()); | 73 EXPECT_EQ(0u, resourceProvider->numResources()); |
74 texture->allocate(Renderer::ImplPool, IntSize(30, 30), GL_RGBA, Resource
Provider::TextureUsageAny); | 74 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, Resour
ceProvider::TextureUsageAny); |
75 EXPECT_LT(0u, texture->id()); | 75 EXPECT_LT(0u, texture->id()); |
76 EXPECT_EQ(1u, resourceProvider->numResources()); | 76 EXPECT_EQ(1u, resourceProvider->numResources()); |
77 texture->free(); | 77 texture->free(); |
78 EXPECT_EQ(0u, resourceProvider->numResources()); | 78 EXPECT_EQ(0u, resourceProvider->numResources()); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 TEST(ScopedTextureTest, LeakScopedTexture) | 82 TEST(ScopedTextureTest, LeakScopedTexture) |
83 { | 83 { |
84 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); | 84 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); |
85 DebugScopedSetImplThread implThread; | 85 DebugScopedSetImplThread implThread; |
86 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); | 86 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); |
87 | 87 |
88 { | 88 { |
89 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid
er.get()); | 89 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid
er.get()); |
90 | 90 |
91 EXPECT_EQ(0u, resourceProvider->numResources()); | 91 EXPECT_EQ(0u, resourceProvider->numResources()); |
92 texture->allocate(Renderer::ImplPool, IntSize(30, 30), GL_RGBA, Resource
Provider::TextureUsageAny); | 92 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, Resour
ceProvider::TextureUsageAny); |
93 EXPECT_LT(0u, texture->id()); | 93 EXPECT_LT(0u, texture->id()); |
94 EXPECT_EQ(1u, resourceProvider->numResources()); | 94 EXPECT_EQ(1u, resourceProvider->numResources()); |
95 | 95 |
96 texture->leak(); | 96 texture->leak(); |
97 EXPECT_EQ(0u, texture->id()); | 97 EXPECT_EQ(0u, texture->id()); |
98 EXPECT_EQ(1u, resourceProvider->numResources()); | 98 EXPECT_EQ(1u, resourceProvider->numResources()); |
99 | 99 |
100 texture->free(); | 100 texture->free(); |
101 EXPECT_EQ(0u, texture->id()); | 101 EXPECT_EQ(0u, texture->id()); |
102 EXPECT_EQ(1u, resourceProvider->numResources()); | 102 EXPECT_EQ(1u, resourceProvider->numResources()); |
103 } | 103 } |
104 | 104 |
105 EXPECT_EQ(1u, resourceProvider->numResources()); | 105 EXPECT_EQ(1u, resourceProvider->numResources()); |
106 } | 106 } |
107 | 107 |
108 } | 108 } |
OLD | NEW |