| 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/test_shared_bitmap_manager.h" | 10 #include "cc/test/test_shared_bitmap_manager.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 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 TEST(ScopedResourceTest, NewScopedResource) { | 17 TEST(ScopedResourceTest, NewScopedResource) { |
| 18 FakeOutputSurfaceClient output_surface_client; | 18 FakeOutputSurfaceClient output_surface_client; |
| 19 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 19 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 20 CHECK(output_surface->BindToClient(&output_surface_client)); | 20 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 21 | 21 |
| 22 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 22 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 23 new TestSharedBitmapManager()); | 23 new TestSharedBitmapManager()); |
| 24 scoped_ptr<ResourceProvider> resource_provider( | 24 scoped_ptr<ResourceProvider> resource_provider( |
| 25 ResourceProvider::Create(output_surface.get(), | 25 ResourceProvider::Create(output_surface.get(), |
| 26 shared_bitmap_manager.get(), | 26 shared_bitmap_manager.get(), |
| 27 NULL, | 27 nullptr, |
| 28 0, | 28 0, |
| 29 false, | 29 false, |
| 30 1, | 30 1, |
| 31 false)); | 31 false)); |
| 32 scoped_ptr<ScopedResource> texture = | 32 scoped_ptr<ScopedResource> texture = |
| 33 ScopedResource::Create(resource_provider.get()); | 33 ScopedResource::Create(resource_provider.get()); |
| 34 | 34 |
| 35 // New scoped textures do not hold a texture yet. | 35 // New scoped textures do not hold a texture yet. |
| 36 EXPECT_EQ(0u, texture->id()); | 36 EXPECT_EQ(0u, texture->id()); |
| 37 | 37 |
| 38 // New scoped textures do not have a size yet. | 38 // New scoped textures do not have a size yet. |
| 39 EXPECT_EQ(gfx::Size(), texture->size()); | 39 EXPECT_EQ(gfx::Size(), texture->size()); |
| 40 EXPECT_EQ(0u, texture->bytes()); | 40 EXPECT_EQ(0u, texture->bytes()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 TEST(ScopedResourceTest, CreateScopedResource) { | 43 TEST(ScopedResourceTest, CreateScopedResource) { |
| 44 FakeOutputSurfaceClient output_surface_client; | 44 FakeOutputSurfaceClient output_surface_client; |
| 45 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 45 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 46 CHECK(output_surface->BindToClient(&output_surface_client)); | 46 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 47 | 47 |
| 48 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 48 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 49 new TestSharedBitmapManager()); | 49 new TestSharedBitmapManager()); |
| 50 scoped_ptr<ResourceProvider> resource_provider( | 50 scoped_ptr<ResourceProvider> resource_provider( |
| 51 ResourceProvider::Create(output_surface.get(), | 51 ResourceProvider::Create(output_surface.get(), |
| 52 shared_bitmap_manager.get(), | 52 shared_bitmap_manager.get(), |
| 53 NULL, | 53 nullptr, |
| 54 0, | 54 0, |
| 55 false, | 55 false, |
| 56 1, | 56 1, |
| 57 false)); | 57 false)); |
| 58 scoped_ptr<ScopedResource> texture = | 58 scoped_ptr<ScopedResource> texture = |
| 59 ScopedResource::Create(resource_provider.get()); | 59 ScopedResource::Create(resource_provider.get()); |
| 60 texture->Allocate( | 60 texture->Allocate( |
| 61 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); | 61 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); |
| 62 | 62 |
| 63 // The texture has an allocated byte-size now. | 63 // The texture has an allocated byte-size now. |
| 64 size_t expected_bytes = 30 * 30 * 4; | 64 size_t expected_bytes = 30 * 30 * 4; |
| 65 EXPECT_EQ(expected_bytes, texture->bytes()); | 65 EXPECT_EQ(expected_bytes, texture->bytes()); |
| 66 | 66 |
| 67 EXPECT_LT(0u, texture->id()); | 67 EXPECT_LT(0u, texture->id()); |
| 68 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); | 68 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); |
| 69 EXPECT_EQ(gfx::Size(30, 30), texture->size()); | 69 EXPECT_EQ(gfx::Size(30, 30), texture->size()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { | 72 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { |
| 73 FakeOutputSurfaceClient output_surface_client; | 73 FakeOutputSurfaceClient output_surface_client; |
| 74 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 74 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 75 CHECK(output_surface->BindToClient(&output_surface_client)); | 75 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 76 | 76 |
| 77 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 77 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 78 new TestSharedBitmapManager()); | 78 new TestSharedBitmapManager()); |
| 79 scoped_ptr<ResourceProvider> resource_provider( | 79 scoped_ptr<ResourceProvider> resource_provider( |
| 80 ResourceProvider::Create(output_surface.get(), | 80 ResourceProvider::Create(output_surface.get(), |
| 81 shared_bitmap_manager.get(), | 81 shared_bitmap_manager.get(), |
| 82 NULL, | 82 nullptr, |
| 83 0, | 83 0, |
| 84 false, | 84 false, |
| 85 1, | 85 1, |
| 86 false)); | 86 false)); |
| 87 { | 87 { |
| 88 scoped_ptr<ScopedResource> texture = | 88 scoped_ptr<ScopedResource> texture = |
| 89 ScopedResource::Create(resource_provider.get()); | 89 ScopedResource::Create(resource_provider.get()); |
| 90 | 90 |
| 91 EXPECT_EQ(0u, resource_provider->num_resources()); | 91 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 92 texture->Allocate( | 92 texture->Allocate( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 112 TEST(ScopedResourceTest, LeakScopedResource) { | 112 TEST(ScopedResourceTest, LeakScopedResource) { |
| 113 FakeOutputSurfaceClient output_surface_client; | 113 FakeOutputSurfaceClient output_surface_client; |
| 114 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 114 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 115 CHECK(output_surface->BindToClient(&output_surface_client)); | 115 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 116 | 116 |
| 117 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 117 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 118 new TestSharedBitmapManager()); | 118 new TestSharedBitmapManager()); |
| 119 scoped_ptr<ResourceProvider> resource_provider( | 119 scoped_ptr<ResourceProvider> resource_provider( |
| 120 ResourceProvider::Create(output_surface.get(), | 120 ResourceProvider::Create(output_surface.get(), |
| 121 shared_bitmap_manager.get(), | 121 shared_bitmap_manager.get(), |
| 122 NULL, | 122 nullptr, |
| 123 0, | 123 0, |
| 124 false, | 124 false, |
| 125 1, | 125 1, |
| 126 false)); | 126 false)); |
| 127 { | 127 { |
| 128 scoped_ptr<ScopedResource> texture = | 128 scoped_ptr<ScopedResource> texture = |
| 129 ScopedResource::Create(resource_provider.get()); | 129 ScopedResource::Create(resource_provider.get()); |
| 130 | 130 |
| 131 EXPECT_EQ(0u, resource_provider->num_resources()); | 131 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 132 texture->Allocate( | 132 texture->Allocate( |
| 133 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); | 133 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); |
| 134 EXPECT_LT(0u, texture->id()); | 134 EXPECT_LT(0u, texture->id()); |
| 135 EXPECT_EQ(1u, resource_provider->num_resources()); | 135 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 136 | 136 |
| 137 texture->Leak(); | 137 texture->Leak(); |
| 138 EXPECT_EQ(0u, texture->id()); | 138 EXPECT_EQ(0u, texture->id()); |
| 139 EXPECT_EQ(1u, resource_provider->num_resources()); | 139 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 140 | 140 |
| 141 texture->Free(); | 141 texture->Free(); |
| 142 EXPECT_EQ(0u, texture->id()); | 142 EXPECT_EQ(0u, texture->id()); |
| 143 EXPECT_EQ(1u, resource_provider->num_resources()); | 143 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 EXPECT_EQ(1u, resource_provider->num_resources()); | 146 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 147 } | 147 } |
| 148 | 148 |
| 149 } // namespace | 149 } // namespace |
| 150 } // namespace cc | 150 } // namespace cc |
| OLD | NEW |