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