| 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(ResourceProvider::Create( |
| 25 ResourceProvider::Create(output_surface.get(), | 25 output_surface.get(), shared_bitmap_manager.get(), NULL, NULL, 0, false, |
| 26 shared_bitmap_manager.get(), | 26 false, 1)); |
| 27 NULL, | |
| 28 NULL, | |
| 29 0, | |
| 30 false, | |
| 31 1)); | |
| 32 scoped_ptr<ScopedResource> texture = | 27 scoped_ptr<ScopedResource> texture = |
| 33 ScopedResource::Create(resource_provider.get()); | 28 ScopedResource::Create(resource_provider.get()); |
| 34 | 29 |
| 35 // New scoped textures do not hold a texture yet. | 30 // New scoped textures do not hold a texture yet. |
| 36 EXPECT_EQ(0u, texture->id()); | 31 EXPECT_EQ(0u, texture->id()); |
| 37 | 32 |
| 38 // New scoped textures do not have a size yet. | 33 // New scoped textures do not have a size yet. |
| 39 EXPECT_EQ(gfx::Size(), texture->size()); | 34 EXPECT_EQ(gfx::Size(), texture->size()); |
| 40 EXPECT_EQ(0u, texture->bytes()); | 35 EXPECT_EQ(0u, texture->bytes()); |
| 41 } | 36 } |
| 42 | 37 |
| 43 TEST(ScopedResourceTest, CreateScopedResource) { | 38 TEST(ScopedResourceTest, CreateScopedResource) { |
| 44 FakeOutputSurfaceClient output_surface_client; | 39 FakeOutputSurfaceClient output_surface_client; |
| 45 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 40 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 46 CHECK(output_surface->BindToClient(&output_surface_client)); | 41 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 47 | 42 |
| 48 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 43 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 49 new TestSharedBitmapManager()); | 44 new TestSharedBitmapManager()); |
| 50 scoped_ptr<ResourceProvider> resource_provider( | 45 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 51 ResourceProvider::Create(output_surface.get(), | 46 output_surface.get(), shared_bitmap_manager.get(), NULL, NULL, 0, false, |
| 52 shared_bitmap_manager.get(), | 47 false, 1)); |
| 53 NULL, | |
| 54 NULL, | |
| 55 0, | |
| 56 false, | |
| 57 1)); | |
| 58 scoped_ptr<ScopedResource> texture = | 48 scoped_ptr<ScopedResource> texture = |
| 59 ScopedResource::Create(resource_provider.get()); | 49 ScopedResource::Create(resource_provider.get()); |
| 60 texture->Allocate( | 50 texture->Allocate( |
| 61 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); | 51 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); |
| 62 | 52 |
| 63 // The texture has an allocated byte-size now. | 53 // The texture has an allocated byte-size now. |
| 64 size_t expected_bytes = 30 * 30 * 4; | 54 size_t expected_bytes = 30 * 30 * 4; |
| 65 EXPECT_EQ(expected_bytes, texture->bytes()); | 55 EXPECT_EQ(expected_bytes, texture->bytes()); |
| 66 | 56 |
| 67 EXPECT_LT(0u, texture->id()); | 57 EXPECT_LT(0u, texture->id()); |
| 68 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); | 58 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); |
| 69 EXPECT_EQ(gfx::Size(30, 30), texture->size()); | 59 EXPECT_EQ(gfx::Size(30, 30), texture->size()); |
| 70 } | 60 } |
| 71 | 61 |
| 72 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { | 62 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { |
| 73 FakeOutputSurfaceClient output_surface_client; | 63 FakeOutputSurfaceClient output_surface_client; |
| 74 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 64 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 75 CHECK(output_surface->BindToClient(&output_surface_client)); | 65 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 76 | 66 |
| 77 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 67 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 78 new TestSharedBitmapManager()); | 68 new TestSharedBitmapManager()); |
| 79 scoped_ptr<ResourceProvider> resource_provider( | 69 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 80 ResourceProvider::Create(output_surface.get(), | 70 output_surface.get(), shared_bitmap_manager.get(), NULL, NULL, 0, false, |
| 81 shared_bitmap_manager.get(), | 71 false, 1)); |
| 82 NULL, | |
| 83 NULL, | |
| 84 0, | |
| 85 false, | |
| 86 1)); | |
| 87 { | 72 { |
| 88 scoped_ptr<ScopedResource> texture = | 73 scoped_ptr<ScopedResource> texture = |
| 89 ScopedResource::Create(resource_provider.get()); | 74 ScopedResource::Create(resource_provider.get()); |
| 90 | 75 |
| 91 EXPECT_EQ(0u, resource_provider->num_resources()); | 76 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 92 texture->Allocate( | 77 texture->Allocate( |
| 93 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); | 78 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); |
| 94 EXPECT_LT(0u, texture->id()); | 79 EXPECT_LT(0u, texture->id()); |
| 95 EXPECT_EQ(1u, resource_provider->num_resources()); | 80 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 96 } | 81 } |
| 97 | 82 |
| 98 EXPECT_EQ(0u, resource_provider->num_resources()); | 83 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 99 { | 84 { |
| 100 scoped_ptr<ScopedResource> texture = | 85 scoped_ptr<ScopedResource> texture = |
| 101 ScopedResource::Create(resource_provider.get()); | 86 ScopedResource::Create(resource_provider.get()); |
| 102 EXPECT_EQ(0u, resource_provider->num_resources()); | 87 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 103 texture->Allocate( | 88 texture->Allocate( |
| 104 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); | 89 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); |
| 105 EXPECT_LT(0u, texture->id()); | 90 EXPECT_LT(0u, texture->id()); |
| 106 EXPECT_EQ(1u, resource_provider->num_resources()); | 91 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 107 texture->Free(); | 92 texture->Free(); |
| 108 EXPECT_EQ(0u, resource_provider->num_resources()); | 93 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 109 } | 94 } |
| 110 } | 95 } |
| 111 | 96 |
| 112 } // namespace | 97 } // namespace |
| 113 } // namespace cc | 98 } // namespace cc |
| OLD | NEW |