| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "cc/output/renderer.h" | 9 #include "cc/output/renderer.h" |
| 10 #include "cc/test/fake_output_surface.h" | 10 #include "cc/test/fake_output_surface.h" |
| 11 #include "cc/test/fake_output_surface_client.h" | 11 #include "cc/test/fake_output_surface_client.h" |
| 12 #include "cc/test/fake_resource_provider.h" | 12 #include "cc/test/fake_resource_provider.h" |
| 13 #include "cc/test/test_shared_bitmap_manager.h" | 13 #include "cc/test/test_shared_bitmap_manager.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 TEST(ScopedResourceTest, NewScopedResource) { | 19 TEST(ScopedResourceTest, NewScopedResource) { |
| 20 FakeOutputSurfaceClient output_surface_client; | 20 FakeOutputSurfaceClient output_surface_client; |
| 21 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 21 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 22 CHECK(output_surface->BindToClient(&output_surface_client)); | 22 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 23 | 23 |
| 24 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 24 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 25 new TestSharedBitmapManager()); | 25 new TestSharedBitmapManager()); |
| 26 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create( | 26 std::unique_ptr<ResourceProvider> resource_provider = |
| 27 output_surface.get(), shared_bitmap_manager.get()); | 27 FakeResourceProvider::Create(output_surface.get(), |
| 28 scoped_ptr<ScopedResource> texture = | 28 shared_bitmap_manager.get()); |
| 29 std::unique_ptr<ScopedResource> texture = |
| 29 ScopedResource::Create(resource_provider.get()); | 30 ScopedResource::Create(resource_provider.get()); |
| 30 | 31 |
| 31 // New scoped textures do not hold a texture yet. | 32 // New scoped textures do not hold a texture yet. |
| 32 EXPECT_EQ(0u, texture->id()); | 33 EXPECT_EQ(0u, texture->id()); |
| 33 | 34 |
| 34 // New scoped textures do not have a size yet. | 35 // New scoped textures do not have a size yet. |
| 35 EXPECT_EQ(gfx::Size(), texture->size()); | 36 EXPECT_EQ(gfx::Size(), texture->size()); |
| 36 EXPECT_EQ(0u, ResourceUtil::UncheckedSizeInBytes<size_t>(texture->size(), | 37 EXPECT_EQ(0u, ResourceUtil::UncheckedSizeInBytes<size_t>(texture->size(), |
| 37 texture->format())); | 38 texture->format())); |
| 38 } | 39 } |
| 39 | 40 |
| 40 TEST(ScopedResourceTest, CreateScopedResource) { | 41 TEST(ScopedResourceTest, CreateScopedResource) { |
| 41 FakeOutputSurfaceClient output_surface_client; | 42 FakeOutputSurfaceClient output_surface_client; |
| 42 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 43 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 43 CHECK(output_surface->BindToClient(&output_surface_client)); | 44 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 44 | 45 |
| 45 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 46 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 46 new TestSharedBitmapManager()); | 47 new TestSharedBitmapManager()); |
| 47 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create( | 48 std::unique_ptr<ResourceProvider> resource_provider = |
| 48 output_surface.get(), shared_bitmap_manager.get()); | 49 FakeResourceProvider::Create(output_surface.get(), |
| 49 scoped_ptr<ScopedResource> texture = | 50 shared_bitmap_manager.get()); |
| 51 std::unique_ptr<ScopedResource> texture = |
| 50 ScopedResource::Create(resource_provider.get()); | 52 ScopedResource::Create(resource_provider.get()); |
| 51 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 53 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 52 RGBA_8888); | 54 RGBA_8888); |
| 53 | 55 |
| 54 // The texture has an allocated byte-size now. | 56 // The texture has an allocated byte-size now. |
| 55 size_t expected_bytes = 30 * 30 * 4; | 57 size_t expected_bytes = 30 * 30 * 4; |
| 56 EXPECT_EQ(expected_bytes, ResourceUtil::UncheckedSizeInBytes<size_t>( | 58 EXPECT_EQ(expected_bytes, ResourceUtil::UncheckedSizeInBytes<size_t>( |
| 57 texture->size(), texture->format())); | 59 texture->size(), texture->format())); |
| 58 | 60 |
| 59 EXPECT_LT(0u, texture->id()); | 61 EXPECT_LT(0u, texture->id()); |
| 60 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); | 62 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); |
| 61 EXPECT_EQ(gfx::Size(30, 30), texture->size()); | 63 EXPECT_EQ(gfx::Size(30, 30), texture->size()); |
| 62 } | 64 } |
| 63 | 65 |
| 64 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { | 66 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { |
| 65 FakeOutputSurfaceClient output_surface_client; | 67 FakeOutputSurfaceClient output_surface_client; |
| 66 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 68 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 67 CHECK(output_surface->BindToClient(&output_surface_client)); | 69 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 68 | 70 |
| 69 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 71 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 70 new TestSharedBitmapManager()); | 72 new TestSharedBitmapManager()); |
| 71 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create( | 73 std::unique_ptr<ResourceProvider> resource_provider = |
| 72 output_surface.get(), shared_bitmap_manager.get()); | 74 FakeResourceProvider::Create(output_surface.get(), |
| 75 shared_bitmap_manager.get()); |
| 73 { | 76 { |
| 74 scoped_ptr<ScopedResource> texture = | 77 std::unique_ptr<ScopedResource> texture = |
| 75 ScopedResource::Create(resource_provider.get()); | 78 ScopedResource::Create(resource_provider.get()); |
| 76 | 79 |
| 77 EXPECT_EQ(0u, resource_provider->num_resources()); | 80 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 78 texture->Allocate(gfx::Size(30, 30), | 81 texture->Allocate(gfx::Size(30, 30), |
| 79 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888); | 82 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888); |
| 80 EXPECT_LT(0u, texture->id()); | 83 EXPECT_LT(0u, texture->id()); |
| 81 EXPECT_EQ(1u, resource_provider->num_resources()); | 84 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 82 } | 85 } |
| 83 | 86 |
| 84 EXPECT_EQ(0u, resource_provider->num_resources()); | 87 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 85 { | 88 { |
| 86 scoped_ptr<ScopedResource> texture = | 89 std::unique_ptr<ScopedResource> texture = |
| 87 ScopedResource::Create(resource_provider.get()); | 90 ScopedResource::Create(resource_provider.get()); |
| 88 EXPECT_EQ(0u, resource_provider->num_resources()); | 91 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 89 texture->Allocate(gfx::Size(30, 30), | 92 texture->Allocate(gfx::Size(30, 30), |
| 90 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888); | 93 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888); |
| 91 EXPECT_LT(0u, texture->id()); | 94 EXPECT_LT(0u, texture->id()); |
| 92 EXPECT_EQ(1u, resource_provider->num_resources()); | 95 EXPECT_EQ(1u, resource_provider->num_resources()); |
| 93 texture->Free(); | 96 texture->Free(); |
| 94 EXPECT_EQ(0u, resource_provider->num_resources()); | 97 EXPECT_EQ(0u, resource_provider->num_resources()); |
| 95 } | 98 } |
| 96 } | 99 } |
| 97 | 100 |
| 98 } // namespace | 101 } // namespace |
| 99 } // namespace cc | 102 } // namespace cc |
| OLD | NEW |