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