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