| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 FakeOutputSurfaceClient output_surface_client; | 38 FakeOutputSurfaceClient output_surface_client; |
| 39 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 39 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 40 CHECK(output_surface->BindToClient(&output_surface_client)); | 40 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 41 | 41 |
| 42 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 42 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 43 new TestSharedBitmapManager()); | 43 new TestSharedBitmapManager()); |
| 44 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 44 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 45 output_surface.get(), shared_bitmap_manager.get(), 0, false, 1, false)); | 45 output_surface.get(), shared_bitmap_manager.get(), 0, false, 1, false)); |
| 46 scoped_ptr<ScopedResource> texture = | 46 scoped_ptr<ScopedResource> texture = |
| 47 ScopedResource::Create(resource_provider.get()); | 47 ScopedResource::Create(resource_provider.get()); |
| 48 texture->Allocate(gfx::Size(30, 30), | 48 texture->Allocate( |
| 49 ResourceProvider::TextureUsageAny, | 49 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); |
| 50 RGBA_8888); | |
| 51 | 50 |
| 52 // The texture has an allocated byte-size now. | 51 // The texture has an allocated byte-size now. |
| 53 size_t expected_bytes = 30 * 30 * 4; | 52 size_t expected_bytes = 30 * 30 * 4; |
| 54 EXPECT_EQ(expected_bytes, texture->bytes()); | 53 EXPECT_EQ(expected_bytes, texture->bytes()); |
| 55 | 54 |
| 56 EXPECT_LT(0u, texture->id()); | 55 EXPECT_LT(0u, texture->id()); |
| 57 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); | 56 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); |
| 58 EXPECT_EQ(gfx::Size(30, 30), texture->size()); | 57 EXPECT_EQ(gfx::Size(30, 30), texture->size()); |
| 59 } | 58 } |
| 60 | 59 |
| 61 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { | 60 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { |
| 62 FakeOutputSurfaceClient output_surface_client; | 61 FakeOutputSurfaceClient output_surface_client; |
| 63 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 62 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 64 CHECK(output_surface->BindToClient(&output_surface_client)); | 63 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 65 | 64 |
| 66 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 65 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 67 new TestSharedBitmapManager()); | 66 new TestSharedBitmapManager()); |
| 68 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 67 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 69 output_surface.get(), shared_bitmap_manager.get(), 0, false, 1, false)); | 68 output_surface.get(), shared_bitmap_manager.get(), 0, false, 1, false)); |
| 70 { | 69 { |
| 71 scoped_ptr<ScopedResource> texture = | 70 scoped_ptr<ScopedResource> texture = |
| 72 ScopedResource::Create(resource_provider.get()); | 71 ScopedResource::Create(resource_provider.get()); |
| 73 | 72 |
| 74 EXPECT_EQ(0u, resource_provider->num_resources()); | 73 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 75 texture->Allocate(gfx::Size(30, 30), | 74 texture->Allocate( |
| 76 ResourceProvider::TextureUsageAny, | 75 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); |
| 77 RGBA_8888); | |
| 78 EXPECT_LT(0u, texture->id()); | 76 EXPECT_LT(0u, texture->id()); |
| 79 EXPECT_EQ(1u, resource_provider->num_resources()); | 77 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 80 } | 78 } |
| 81 | 79 |
| 82 EXPECT_EQ(0u, resource_provider->num_resources()); | 80 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 83 { | 81 { |
| 84 scoped_ptr<ScopedResource> texture = | 82 scoped_ptr<ScopedResource> texture = |
| 85 ScopedResource::Create(resource_provider.get()); | 83 ScopedResource::Create(resource_provider.get()); |
| 86 EXPECT_EQ(0u, resource_provider->num_resources()); | 84 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 87 texture->Allocate(gfx::Size(30, 30), | 85 texture->Allocate( |
| 88 ResourceProvider::TextureUsageAny, | 86 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); |
| 89 RGBA_8888); | |
| 90 EXPECT_LT(0u, texture->id()); | 87 EXPECT_LT(0u, texture->id()); |
| 91 EXPECT_EQ(1u, resource_provider->num_resources()); | 88 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 92 texture->Free(); | 89 texture->Free(); |
| 93 EXPECT_EQ(0u, resource_provider->num_resources()); | 90 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 94 } | 91 } |
| 95 } | 92 } |
| 96 | 93 |
| 97 TEST(ScopedResourceTest, LeakScopedResource) { | 94 TEST(ScopedResourceTest, LeakScopedResource) { |
| 98 FakeOutputSurfaceClient output_surface_client; | 95 FakeOutputSurfaceClient output_surface_client; |
| 99 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 96 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 100 CHECK(output_surface->BindToClient(&output_surface_client)); | 97 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 101 | 98 |
| 102 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 99 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 103 new TestSharedBitmapManager()); | 100 new TestSharedBitmapManager()); |
| 104 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 101 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 105 output_surface.get(), shared_bitmap_manager.get(), 0, false, 1, false)); | 102 output_surface.get(), shared_bitmap_manager.get(), 0, false, 1, false)); |
| 106 { | 103 { |
| 107 scoped_ptr<ScopedResource> texture = | 104 scoped_ptr<ScopedResource> texture = |
| 108 ScopedResource::Create(resource_provider.get()); | 105 ScopedResource::Create(resource_provider.get()); |
| 109 | 106 |
| 110 EXPECT_EQ(0u, resource_provider->num_resources()); | 107 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 111 texture->Allocate(gfx::Size(30, 30), | 108 texture->Allocate( |
| 112 ResourceProvider::TextureUsageAny, | 109 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); |
| 113 RGBA_8888); | |
| 114 EXPECT_LT(0u, texture->id()); | 110 EXPECT_LT(0u, texture->id()); |
| 115 EXPECT_EQ(1u, resource_provider->num_resources()); | 111 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 116 | 112 |
| 117 texture->Leak(); | 113 texture->Leak(); |
| 118 EXPECT_EQ(0u, texture->id()); | 114 EXPECT_EQ(0u, texture->id()); |
| 119 EXPECT_EQ(1u, resource_provider->num_resources()); | 115 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 120 | 116 |
| 121 texture->Free(); | 117 texture->Free(); |
| 122 EXPECT_EQ(0u, texture->id()); | 118 EXPECT_EQ(0u, texture->id()); |
| 123 EXPECT_EQ(1u, resource_provider->num_resources()); | 119 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 124 } | 120 } |
| 125 | 121 |
| 126 EXPECT_EQ(1u, resource_provider->num_resources()); | 122 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 127 } | 123 } |
| 128 | 124 |
| 129 } // namespace | 125 } // namespace |
| 130 } // namespace cc | 126 } // namespace cc |
| OLD | NEW |