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