| 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/resources/scoped_resource.h" | 5 #include "cc/resources/scoped_resource.h" |
| 6 | 6 |
| 7 #include "cc/output/renderer.h" | 7 #include "cc/output/renderer.h" |
| 8 #include "cc/test/fake_output_surface.h" | 8 #include "cc/test/fake_output_surface.h" |
| 9 #include "cc/test/fake_output_surface_client.h" |
| 9 #include "cc/test/tiled_layer_test_common.h" | 10 #include "cc/test/tiled_layer_test_common.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "third_party/khronos/GLES2/gl2.h" | 12 #include "third_party/khronos/GLES2/gl2.h" |
| 12 | 13 |
| 13 namespace cc { | 14 namespace cc { |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 TEST(ScopedResourceTest, NewScopedResource) { | 17 TEST(ScopedResourceTest, NewScopedResource) { |
| 17 scoped_ptr<OutputSurface> context(CreateFakeOutputSurface()); | 18 FakeOutputSurfaceClient output_surface_client; |
| 19 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 20 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 21 |
| 18 scoped_ptr<ResourceProvider> resource_provider( | 22 scoped_ptr<ResourceProvider> resource_provider( |
| 19 ResourceProvider::Create(context.get(), 0)); | 23 ResourceProvider::Create(output_surface.get(), 0)); |
| 20 scoped_ptr<ScopedResource> texture = | 24 scoped_ptr<ScopedResource> texture = |
| 21 ScopedResource::create(resource_provider.get()); | 25 ScopedResource::create(resource_provider.get()); |
| 22 | 26 |
| 23 // New scoped textures do not hold a texture yet. | 27 // New scoped textures do not hold a texture yet. |
| 24 EXPECT_EQ(0u, texture->id()); | 28 EXPECT_EQ(0u, texture->id()); |
| 25 | 29 |
| 26 // New scoped textures do not have a size yet. | 30 // New scoped textures do not have a size yet. |
| 27 EXPECT_EQ(gfx::Size(), texture->size()); | 31 EXPECT_EQ(gfx::Size(), texture->size()); |
| 28 EXPECT_EQ(0u, texture->bytes()); | 32 EXPECT_EQ(0u, texture->bytes()); |
| 29 } | 33 } |
| 30 | 34 |
| 31 TEST(ScopedResourceTest, CreateScopedResource) { | 35 TEST(ScopedResourceTest, CreateScopedResource) { |
| 32 scoped_ptr<OutputSurface> context(CreateFakeOutputSurface()); | 36 FakeOutputSurfaceClient output_surface_client; |
| 37 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 38 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 39 |
| 33 scoped_ptr<ResourceProvider> resource_provider( | 40 scoped_ptr<ResourceProvider> resource_provider( |
| 34 ResourceProvider::Create(context.get(), 0)); | 41 ResourceProvider::Create(output_surface.get(), 0)); |
| 35 scoped_ptr<ScopedResource> texture = | 42 scoped_ptr<ScopedResource> texture = |
| 36 ScopedResource::create(resource_provider.get()); | 43 ScopedResource::create(resource_provider.get()); |
| 37 texture->Allocate( | 44 texture->Allocate( |
| 38 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); | 45 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); |
| 39 | 46 |
| 40 // The texture has an allocated byte-size now. | 47 // The texture has an allocated byte-size now. |
| 41 size_t expected_bytes = 30 * 30 * 4; | 48 size_t expected_bytes = 30 * 30 * 4; |
| 42 EXPECT_EQ(expected_bytes, texture->bytes()); | 49 EXPECT_EQ(expected_bytes, texture->bytes()); |
| 43 | 50 |
| 44 EXPECT_LT(0u, texture->id()); | 51 EXPECT_LT(0u, texture->id()); |
| 45 EXPECT_EQ(static_cast<unsigned>(GL_RGBA), texture->format()); | 52 EXPECT_EQ(static_cast<unsigned>(GL_RGBA), texture->format()); |
| 46 EXPECT_EQ(gfx::Size(30, 30), texture->size()); | 53 EXPECT_EQ(gfx::Size(30, 30), texture->size()); |
| 47 } | 54 } |
| 48 | 55 |
| 49 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { | 56 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { |
| 50 scoped_ptr<OutputSurface> context(CreateFakeOutputSurface()); | 57 FakeOutputSurfaceClient output_surface_client; |
| 58 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 59 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 60 |
| 51 scoped_ptr<ResourceProvider> resource_provider( | 61 scoped_ptr<ResourceProvider> resource_provider( |
| 52 ResourceProvider::Create(context.get(), 0)); | 62 ResourceProvider::Create(output_surface.get(), 0)); |
| 53 { | 63 { |
| 54 scoped_ptr<ScopedResource> texture = | 64 scoped_ptr<ScopedResource> texture = |
| 55 ScopedResource::create(resource_provider.get()); | 65 ScopedResource::create(resource_provider.get()); |
| 56 | 66 |
| 57 EXPECT_EQ(0u, resource_provider->num_resources()); | 67 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 58 texture->Allocate( | 68 texture->Allocate( |
| 59 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); | 69 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); |
| 60 EXPECT_LT(0u, texture->id()); | 70 EXPECT_LT(0u, texture->id()); |
| 61 EXPECT_EQ(1u, resource_provider->num_resources()); | 71 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 62 } | 72 } |
| 63 | 73 |
| 64 EXPECT_EQ(0u, resource_provider->num_resources()); | 74 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 65 { | 75 { |
| 66 scoped_ptr<ScopedResource> texture = | 76 scoped_ptr<ScopedResource> texture = |
| 67 ScopedResource::create(resource_provider.get()); | 77 ScopedResource::create(resource_provider.get()); |
| 68 EXPECT_EQ(0u, resource_provider->num_resources()); | 78 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 69 texture->Allocate( | 79 texture->Allocate( |
| 70 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); | 80 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); |
| 71 EXPECT_LT(0u, texture->id()); | 81 EXPECT_LT(0u, texture->id()); |
| 72 EXPECT_EQ(1u, resource_provider->num_resources()); | 82 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 73 texture->Free(); | 83 texture->Free(); |
| 74 EXPECT_EQ(0u, resource_provider->num_resources()); | 84 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 75 } | 85 } |
| 76 } | 86 } |
| 77 | 87 |
| 78 TEST(ScopedResourceTest, LeakScopedResource) { | 88 TEST(ScopedResourceTest, LeakScopedResource) { |
| 79 scoped_ptr<OutputSurface> context(CreateFakeOutputSurface()); | 89 FakeOutputSurfaceClient output_surface_client; |
| 90 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 91 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 92 |
| 80 scoped_ptr<ResourceProvider> resource_provider( | 93 scoped_ptr<ResourceProvider> resource_provider( |
| 81 ResourceProvider::Create(context.get(), 0)); | 94 ResourceProvider::Create(output_surface.get(), 0)); |
| 82 { | 95 { |
| 83 scoped_ptr<ScopedResource> texture = | 96 scoped_ptr<ScopedResource> texture = |
| 84 ScopedResource::create(resource_provider.get()); | 97 ScopedResource::create(resource_provider.get()); |
| 85 | 98 |
| 86 EXPECT_EQ(0u, resource_provider->num_resources()); | 99 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 87 texture->Allocate( | 100 texture->Allocate( |
| 88 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); | 101 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); |
| 89 EXPECT_LT(0u, texture->id()); | 102 EXPECT_LT(0u, texture->id()); |
| 90 EXPECT_EQ(1u, resource_provider->num_resources()); | 103 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 91 | 104 |
| 92 texture->Leak(); | 105 texture->Leak(); |
| 93 EXPECT_EQ(0u, texture->id()); | 106 EXPECT_EQ(0u, texture->id()); |
| 94 EXPECT_EQ(1u, resource_provider->num_resources()); | 107 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 95 | 108 |
| 96 texture->Free(); | 109 texture->Free(); |
| 97 EXPECT_EQ(0u, texture->id()); | 110 EXPECT_EQ(0u, texture->id()); |
| 98 EXPECT_EQ(1u, resource_provider->num_resources()); | 111 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 99 } | 112 } |
| 100 | 113 |
| 101 EXPECT_EQ(1u, resource_provider->num_resources()); | 114 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 102 } | 115 } |
| 103 | 116 |
| 104 } // namespace | 117 } // namespace |
| 105 } // namespace cc | 118 } // namespace cc |
| OLD | NEW |