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( |
(...skipping 11 matching lines...) Expand all Loading... |
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)); |
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 ResourceProvider::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>(ResourceProvider::RGBA_8888), |
| 53 texture->format()); |
53 EXPECT_EQ(gfx::Size(30, 30), texture->size()); | 54 EXPECT_EQ(gfx::Size(30, 30), texture->size()); |
54 } | 55 } |
55 | 56 |
56 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { | 57 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { |
57 FakeOutputSurfaceClient output_surface_client; | 58 FakeOutputSurfaceClient output_surface_client; |
58 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 59 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
59 CHECK(output_surface->BindToClient(&output_surface_client)); | 60 CHECK(output_surface->BindToClient(&output_surface_client)); |
60 | 61 |
61 scoped_ptr<ResourceProvider> resource_provider( | 62 scoped_ptr<ResourceProvider> resource_provider( |
62 ResourceProvider::Create(output_surface.get(), 0)); | 63 ResourceProvider::Create(output_surface.get(), 0)); |
63 { | 64 { |
64 scoped_ptr<ScopedResource> texture = | 65 scoped_ptr<ScopedResource> texture = |
65 ScopedResource::create(resource_provider.get()); | 66 ScopedResource::create(resource_provider.get()); |
66 | 67 |
67 EXPECT_EQ(0u, resource_provider->num_resources()); | 68 EXPECT_EQ(0u, resource_provider->num_resources()); |
68 texture->Allocate( | 69 texture->Allocate(gfx::Size(30, 30), |
69 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); | 70 ResourceProvider::TextureUsageAny, |
| 71 ResourceProvider::RGBA_8888); |
70 EXPECT_LT(0u, texture->id()); | 72 EXPECT_LT(0u, texture->id()); |
71 EXPECT_EQ(1u, resource_provider->num_resources()); | 73 EXPECT_EQ(1u, resource_provider->num_resources()); |
72 } | 74 } |
73 | 75 |
74 EXPECT_EQ(0u, resource_provider->num_resources()); | 76 EXPECT_EQ(0u, resource_provider->num_resources()); |
75 { | 77 { |
76 scoped_ptr<ScopedResource> texture = | 78 scoped_ptr<ScopedResource> texture = |
77 ScopedResource::create(resource_provider.get()); | 79 ScopedResource::create(resource_provider.get()); |
78 EXPECT_EQ(0u, resource_provider->num_resources()); | 80 EXPECT_EQ(0u, resource_provider->num_resources()); |
79 texture->Allocate( | 81 texture->Allocate(gfx::Size(30, 30), |
80 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); | 82 ResourceProvider::TextureUsageAny, |
| 83 ResourceProvider::RGBA_8888); |
81 EXPECT_LT(0u, texture->id()); | 84 EXPECT_LT(0u, texture->id()); |
82 EXPECT_EQ(1u, resource_provider->num_resources()); | 85 EXPECT_EQ(1u, resource_provider->num_resources()); |
83 texture->Free(); | 86 texture->Free(); |
84 EXPECT_EQ(0u, resource_provider->num_resources()); | 87 EXPECT_EQ(0u, resource_provider->num_resources()); |
85 } | 88 } |
86 } | 89 } |
87 | 90 |
88 TEST(ScopedResourceTest, LeakScopedResource) { | 91 TEST(ScopedResourceTest, LeakScopedResource) { |
89 FakeOutputSurfaceClient output_surface_client; | 92 FakeOutputSurfaceClient output_surface_client; |
90 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 93 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
91 CHECK(output_surface->BindToClient(&output_surface_client)); | 94 CHECK(output_surface->BindToClient(&output_surface_client)); |
92 | 95 |
93 scoped_ptr<ResourceProvider> resource_provider( | 96 scoped_ptr<ResourceProvider> resource_provider( |
94 ResourceProvider::Create(output_surface.get(), 0)); | 97 ResourceProvider::Create(output_surface.get(), 0)); |
95 { | 98 { |
96 scoped_ptr<ScopedResource> texture = | 99 scoped_ptr<ScopedResource> texture = |
97 ScopedResource::create(resource_provider.get()); | 100 ScopedResource::create(resource_provider.get()); |
98 | 101 |
99 EXPECT_EQ(0u, resource_provider->num_resources()); | 102 EXPECT_EQ(0u, resource_provider->num_resources()); |
100 texture->Allocate( | 103 texture->Allocate(gfx::Size(30, 30), |
101 gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); | 104 ResourceProvider::TextureUsageAny, |
| 105 ResourceProvider::RGBA_8888); |
102 EXPECT_LT(0u, texture->id()); | 106 EXPECT_LT(0u, texture->id()); |
103 EXPECT_EQ(1u, resource_provider->num_resources()); | 107 EXPECT_EQ(1u, resource_provider->num_resources()); |
104 | 108 |
105 texture->Leak(); | 109 texture->Leak(); |
106 EXPECT_EQ(0u, texture->id()); | 110 EXPECT_EQ(0u, texture->id()); |
107 EXPECT_EQ(1u, resource_provider->num_resources()); | 111 EXPECT_EQ(1u, resource_provider->num_resources()); |
108 | 112 |
109 texture->Free(); | 113 texture->Free(); |
110 EXPECT_EQ(0u, texture->id()); | 114 EXPECT_EQ(0u, texture->id()); |
111 EXPECT_EQ(1u, resource_provider->num_resources()); | 115 EXPECT_EQ(1u, resource_provider->num_resources()); |
112 } | 116 } |
113 | 117 |
114 EXPECT_EQ(1u, resource_provider->num_resources()); | 118 EXPECT_EQ(1u, resource_provider->num_resources()); |
115 } | 119 } |
116 | 120 |
117 } // namespace | 121 } // namespace |
118 } // namespace cc | 122 } // namespace cc |
OLD | NEW |