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