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