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