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/fake_resource_provider.h" | 10 #include "cc/test/fake_resource_provider.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create( | 24 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create( |
25 output_surface.get(), shared_bitmap_manager.get()); | 25 output_surface.get(), shared_bitmap_manager.get()); |
26 scoped_ptr<ScopedResource> texture = | 26 scoped_ptr<ScopedResource> texture = |
27 ScopedResource::Create(resource_provider.get()); | 27 ScopedResource::Create(resource_provider.get()); |
28 | 28 |
29 // New scoped textures do not hold a texture yet. | 29 // New scoped textures do not hold a texture yet. |
30 EXPECT_EQ(0u, texture->id()); | 30 EXPECT_EQ(0u, texture->id()); |
31 | 31 |
32 // New scoped textures do not have a size yet. | 32 // New scoped textures do not have a size yet. |
33 EXPECT_EQ(gfx::Size(), texture->size()); | 33 EXPECT_EQ(gfx::Size(), texture->size()); |
34 EXPECT_EQ(0u, Resource::UncheckedMemorySizeBytes(texture->size(), | 34 EXPECT_EQ(0u, ResourceUtil::SizeInBytes(texture->size(), texture->format())); |
35 texture->format())); | |
36 } | 35 } |
37 | 36 |
38 TEST(ScopedResourceTest, CreateScopedResource) { | 37 TEST(ScopedResourceTest, CreateScopedResource) { |
39 FakeOutputSurfaceClient output_surface_client; | 38 FakeOutputSurfaceClient output_surface_client; |
40 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 39 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
41 CHECK(output_surface->BindToClient(&output_surface_client)); | 40 CHECK(output_surface->BindToClient(&output_surface_client)); |
42 | 41 |
43 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 42 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
44 new TestSharedBitmapManager()); | 43 new TestSharedBitmapManager()); |
45 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create( | 44 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create( |
46 output_surface.get(), shared_bitmap_manager.get()); | 45 output_surface.get(), shared_bitmap_manager.get()); |
47 scoped_ptr<ScopedResource> texture = | 46 scoped_ptr<ScopedResource> texture = |
48 ScopedResource::Create(resource_provider.get()); | 47 ScopedResource::Create(resource_provider.get()); |
49 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 48 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
50 RGBA_8888); | 49 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, Resource::UncheckedMemorySizeBytes( | 53 EXPECT_EQ(expected_bytes, |
55 texture->size(), texture->format())); | 54 ResourceUtil::SizeInBytes(texture->size(), texture->format())); |
56 | 55 |
57 EXPECT_LT(0u, texture->id()); | 56 EXPECT_LT(0u, texture->id()); |
58 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); | 57 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); |
59 EXPECT_EQ(gfx::Size(30, 30), texture->size()); | 58 EXPECT_EQ(gfx::Size(30, 30), texture->size()); |
60 } | 59 } |
61 | 60 |
62 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { | 61 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { |
63 FakeOutputSurfaceClient output_surface_client; | 62 FakeOutputSurfaceClient output_surface_client; |
64 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 63 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
65 CHECK(output_surface->BindToClient(&output_surface_client)); | 64 CHECK(output_surface->BindToClient(&output_surface_client)); |
(...skipping 22 matching lines...) Expand all Loading... |
88 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888); | 87 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888); |
89 EXPECT_LT(0u, texture->id()); | 88 EXPECT_LT(0u, texture->id()); |
90 EXPECT_EQ(1u, resource_provider->num_resources()); | 89 EXPECT_EQ(1u, resource_provider->num_resources()); |
91 texture->Free(); | 90 texture->Free(); |
92 EXPECT_EQ(0u, resource_provider->num_resources()); | 91 EXPECT_EQ(0u, resource_provider->num_resources()); |
93 } | 92 } |
94 } | 93 } |
95 | 94 |
96 } // namespace | 95 } // namespace |
97 } // namespace cc | 96 } // namespace cc |
OLD | NEW |