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/tiled_layer_test_common.h" | 10 #include "cc/test/tiled_layer_test_common.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "third_party/khronos/GLES2/gl2.h" | |
13 | 12 |
14 namespace cc { | 13 namespace cc { |
15 namespace { | 14 namespace { |
16 | 15 |
17 TEST(ScopedResourceTest, NewScopedResource) { | 16 TEST(ScopedResourceTest, NewScopedResource) { |
18 FakeOutputSurfaceClient output_surface_client; | 17 FakeOutputSurfaceClient output_surface_client; |
19 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 18 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
20 CHECK(output_surface->BindToClient(&output_surface_client)); | 19 CHECK(output_surface->BindToClient(&output_surface_client)); |
21 | 20 |
22 scoped_ptr<ResourceProvider> resource_provider( | 21 scoped_ptr<ResourceProvider> resource_provider( |
23 ResourceProvider::Create(output_surface.get(), 0)); | 22 ResourceProvider::Create(output_surface.get(), 0, false)); |
24 scoped_ptr<ScopedResource> texture = | 23 scoped_ptr<ScopedResource> texture = |
25 ScopedResource::create(resource_provider.get()); | 24 ScopedResource::create(resource_provider.get()); |
26 | 25 |
27 // New scoped textures do not hold a texture yet. | 26 // New scoped textures do not hold a texture yet. |
28 EXPECT_EQ(0u, texture->id()); | 27 EXPECT_EQ(0u, texture->id()); |
29 | 28 |
30 // New scoped textures do not have a size yet. | 29 // New scoped textures do not have a size yet. |
31 EXPECT_EQ(gfx::Size(), texture->size()); | 30 EXPECT_EQ(gfx::Size(), texture->size()); |
32 EXPECT_EQ(0u, texture->bytes()); | 31 EXPECT_EQ(0u, texture->bytes()); |
33 } | 32 } |
34 | 33 |
35 TEST(ScopedResourceTest, CreateScopedResource) { | 34 TEST(ScopedResourceTest, CreateScopedResource) { |
36 FakeOutputSurfaceClient output_surface_client; | 35 FakeOutputSurfaceClient output_surface_client; |
37 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 36 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
38 CHECK(output_surface->BindToClient(&output_surface_client)); | 37 CHECK(output_surface->BindToClient(&output_surface_client)); |
39 | 38 |
40 scoped_ptr<ResourceProvider> resource_provider( | 39 scoped_ptr<ResourceProvider> resource_provider( |
41 ResourceProvider::Create(output_surface.get(), 0)); | 40 ResourceProvider::Create(output_surface.get(), 0, false)); |
42 scoped_ptr<ScopedResource> texture = | 41 scoped_ptr<ScopedResource> texture = |
43 ScopedResource::create(resource_provider.get()); | 42 ScopedResource::create(resource_provider.get()); |
44 texture->Allocate( | 43 texture->Allocate(gfx::Size(30, 30), |
45 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); | 44 ResourceProvider::TextureUsageAny, |
| 45 RGBA_8888); |
46 | 46 |
47 // The texture has an allocated byte-size now. | 47 // The texture has an allocated byte-size now. |
48 size_t expected_bytes = 30 * 30 * 4; | 48 size_t expected_bytes = 30 * 30 * 4; |
49 EXPECT_EQ(expected_bytes, texture->bytes()); | 49 EXPECT_EQ(expected_bytes, texture->bytes()); |
50 | 50 |
51 EXPECT_LT(0u, texture->id()); | 51 EXPECT_LT(0u, texture->id()); |
52 EXPECT_EQ(static_cast<unsigned>(GL_RGBA), texture->format()); | 52 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); |
53 EXPECT_EQ(gfx::Size(30, 30), texture->size()); | 53 EXPECT_EQ(gfx::Size(30, 30), texture->size()); |
54 } | 54 } |
55 | 55 |
56 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { | 56 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { |
57 FakeOutputSurfaceClient output_surface_client; | 57 FakeOutputSurfaceClient output_surface_client; |
58 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 58 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
59 CHECK(output_surface->BindToClient(&output_surface_client)); | 59 CHECK(output_surface->BindToClient(&output_surface_client)); |
60 | 60 |
61 scoped_ptr<ResourceProvider> resource_provider( | 61 scoped_ptr<ResourceProvider> resource_provider( |
62 ResourceProvider::Create(output_surface.get(), 0)); | 62 ResourceProvider::Create(output_surface.get(), 0, false)); |
63 { | 63 { |
64 scoped_ptr<ScopedResource> texture = | 64 scoped_ptr<ScopedResource> texture = |
65 ScopedResource::create(resource_provider.get()); | 65 ScopedResource::create(resource_provider.get()); |
66 | 66 |
67 EXPECT_EQ(0u, resource_provider->num_resources()); | 67 EXPECT_EQ(0u, resource_provider->num_resources()); |
68 texture->Allocate( | 68 texture->Allocate(gfx::Size(30, 30), |
69 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); | 69 ResourceProvider::TextureUsageAny, |
| 70 RGBA_8888); |
70 EXPECT_LT(0u, texture->id()); | 71 EXPECT_LT(0u, texture->id()); |
71 EXPECT_EQ(1u, resource_provider->num_resources()); | 72 EXPECT_EQ(1u, resource_provider->num_resources()); |
72 } | 73 } |
73 | 74 |
74 EXPECT_EQ(0u, resource_provider->num_resources()); | 75 EXPECT_EQ(0u, resource_provider->num_resources()); |
75 { | 76 { |
76 scoped_ptr<ScopedResource> texture = | 77 scoped_ptr<ScopedResource> texture = |
77 ScopedResource::create(resource_provider.get()); | 78 ScopedResource::create(resource_provider.get()); |
78 EXPECT_EQ(0u, resource_provider->num_resources()); | 79 EXPECT_EQ(0u, resource_provider->num_resources()); |
79 texture->Allocate( | 80 texture->Allocate(gfx::Size(30, 30), |
80 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); | 81 ResourceProvider::TextureUsageAny, |
| 82 RGBA_8888); |
81 EXPECT_LT(0u, texture->id()); | 83 EXPECT_LT(0u, texture->id()); |
82 EXPECT_EQ(1u, resource_provider->num_resources()); | 84 EXPECT_EQ(1u, resource_provider->num_resources()); |
83 texture->Free(); | 85 texture->Free(); |
84 EXPECT_EQ(0u, resource_provider->num_resources()); | 86 EXPECT_EQ(0u, resource_provider->num_resources()); |
85 } | 87 } |
86 } | 88 } |
87 | 89 |
88 TEST(ScopedResourceTest, LeakScopedResource) { | 90 TEST(ScopedResourceTest, LeakScopedResource) { |
89 FakeOutputSurfaceClient output_surface_client; | 91 FakeOutputSurfaceClient output_surface_client; |
90 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 92 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
91 CHECK(output_surface->BindToClient(&output_surface_client)); | 93 CHECK(output_surface->BindToClient(&output_surface_client)); |
92 | 94 |
93 scoped_ptr<ResourceProvider> resource_provider( | 95 scoped_ptr<ResourceProvider> resource_provider( |
94 ResourceProvider::Create(output_surface.get(), 0)); | 96 ResourceProvider::Create(output_surface.get(), 0, false)); |
95 { | 97 { |
96 scoped_ptr<ScopedResource> texture = | 98 scoped_ptr<ScopedResource> texture = |
97 ScopedResource::create(resource_provider.get()); | 99 ScopedResource::create(resource_provider.get()); |
98 | 100 |
99 EXPECT_EQ(0u, resource_provider->num_resources()); | 101 EXPECT_EQ(0u, resource_provider->num_resources()); |
100 texture->Allocate( | 102 texture->Allocate(gfx::Size(30, 30), |
101 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); | 103 ResourceProvider::TextureUsageAny, |
| 104 RGBA_8888); |
102 EXPECT_LT(0u, texture->id()); | 105 EXPECT_LT(0u, texture->id()); |
103 EXPECT_EQ(1u, resource_provider->num_resources()); | 106 EXPECT_EQ(1u, resource_provider->num_resources()); |
104 | 107 |
105 texture->Leak(); | 108 texture->Leak(); |
106 EXPECT_EQ(0u, texture->id()); | 109 EXPECT_EQ(0u, texture->id()); |
107 EXPECT_EQ(1u, resource_provider->num_resources()); | 110 EXPECT_EQ(1u, resource_provider->num_resources()); |
108 | 111 |
109 texture->Free(); | 112 texture->Free(); |
110 EXPECT_EQ(0u, texture->id()); | 113 EXPECT_EQ(0u, texture->id()); |
111 EXPECT_EQ(1u, resource_provider->num_resources()); | 114 EXPECT_EQ(1u, resource_provider->num_resources()); |
112 } | 115 } |
113 | 116 |
114 EXPECT_EQ(1u, resource_provider->num_resources()); | 117 EXPECT_EQ(1u, resource_provider->num_resources()); |
115 } | 118 } |
116 | 119 |
117 } // namespace | 120 } // namespace |
118 } // namespace cc | 121 } // namespace cc |
OLD | NEW |