OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 | |
7 #include "CCScopedTexture.h" | |
8 | |
9 #include "CCRenderer.h" | |
10 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread | |
11 #include "CCTiledLayerTestCommon.h" | |
12 #include "FakeCCGraphicsContext.h" | |
13 #include "GraphicsContext3D.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 using namespace cc; | |
17 using namespace WebKit; | |
18 using namespace WebKitTests; | |
19 | |
20 namespace { | |
21 | |
22 TEST(CCScopedTextureTest, NewScopedTexture) | |
23 { | |
24 scoped_ptr<CCGraphicsContext> context(createFakeCCGraphicsContext()); | |
25 DebugScopedSetImplThread implThread; | |
26 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(conte
xt.get())); | |
27 OwnPtr<CCScopedTexture> texture = CCScopedTexture::create(resourceProvider.g
et()); | |
28 | |
29 // New scoped textures do not hold a texture yet. | |
30 EXPECT_EQ(0u, texture->id()); | |
31 | |
32 // New scoped textures do not have a size yet. | |
33 EXPECT_EQ(IntSize(), texture->size()); | |
34 EXPECT_EQ(0u, texture->bytes()); | |
35 } | |
36 | |
37 TEST(CCScopedTextureTest, CreateScopedTexture) | |
38 { | |
39 scoped_ptr<CCGraphicsContext> context(createFakeCCGraphicsContext()); | |
40 DebugScopedSetImplThread implThread; | |
41 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(conte
xt.get())); | |
42 OwnPtr<CCScopedTexture> texture = CCScopedTexture::create(resourceProvider.g
et()); | |
43 texture->allocate(CCRenderer::ImplPool, IntSize(30, 30), GraphicsContext3D::
RGBA, CCResourceProvider::TextureUsageAny); | |
44 | |
45 // The texture has an allocated byte-size now. | |
46 size_t expectedBytes = 30 * 30 * 4; | |
47 EXPECT_EQ(expectedBytes, texture->bytes()); | |
48 | |
49 EXPECT_LT(0u, texture->id()); | |
50 EXPECT_EQ(GraphicsContext3D::RGBA, texture->format()); | |
51 EXPECT_EQ(IntSize(30, 30), texture->size()); | |
52 } | |
53 | |
54 TEST(CCScopedTextureTest, ScopedTextureIsDeleted) | |
55 { | |
56 scoped_ptr<CCGraphicsContext> context(createFakeCCGraphicsContext()); | |
57 DebugScopedSetImplThread implThread; | |
58 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(conte
xt.get())); | |
59 | |
60 { | |
61 OwnPtr<CCScopedTexture> texture = CCScopedTexture::create(resourceProvid
er.get()); | |
62 | |
63 EXPECT_EQ(0u, resourceProvider->numResources()); | |
64 texture->allocate(CCRenderer::ImplPool, IntSize(30, 30), GraphicsContext
3D::RGBA, CCResourceProvider::TextureUsageAny); | |
65 EXPECT_LT(0u, texture->id()); | |
66 EXPECT_EQ(1u, resourceProvider->numResources()); | |
67 } | |
68 | |
69 EXPECT_EQ(0u, resourceProvider->numResources()); | |
70 | |
71 { | |
72 OwnPtr<CCScopedTexture> texture = CCScopedTexture::create(resourceProvid
er.get()); | |
73 EXPECT_EQ(0u, resourceProvider->numResources()); | |
74 texture->allocate(CCRenderer::ImplPool, IntSize(30, 30), GraphicsContext
3D::RGBA, CCResourceProvider::TextureUsageAny); | |
75 EXPECT_LT(0u, texture->id()); | |
76 EXPECT_EQ(1u, resourceProvider->numResources()); | |
77 texture->free(); | |
78 EXPECT_EQ(0u, resourceProvider->numResources()); | |
79 } | |
80 } | |
81 | |
82 TEST(CCScopedTextureTest, LeakScopedTexture) | |
83 { | |
84 scoped_ptr<CCGraphicsContext> context(createFakeCCGraphicsContext()); | |
85 DebugScopedSetImplThread implThread; | |
86 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(conte
xt.get())); | |
87 | |
88 { | |
89 OwnPtr<CCScopedTexture> texture = CCScopedTexture::create(resourceProvid
er.get()); | |
90 | |
91 EXPECT_EQ(0u, resourceProvider->numResources()); | |
92 texture->allocate(CCRenderer::ImplPool, IntSize(30, 30), GraphicsContext
3D::RGBA, CCResourceProvider::TextureUsageAny); | |
93 EXPECT_LT(0u, texture->id()); | |
94 EXPECT_EQ(1u, resourceProvider->numResources()); | |
95 | |
96 texture->leak(); | |
97 EXPECT_EQ(0u, texture->id()); | |
98 EXPECT_EQ(1u, resourceProvider->numResources()); | |
99 | |
100 texture->free(); | |
101 EXPECT_EQ(0u, texture->id()); | |
102 EXPECT_EQ(1u, resourceProvider->numResources()); | |
103 } | |
104 | |
105 EXPECT_EQ(1u, resourceProvider->numResources()); | |
106 } | |
107 | |
108 } | |
OLD | NEW |