Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: gpu/command_buffer/service/texture_manager_unittest.cc

Issue 2880013: Free the resources used by a context group. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gpu/command_buffer/service/texture_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "gpu/command_buffer/service/texture_manager.h" 5 #include "gpu/command_buffer/service/texture_manager.h"
6 #include "base/scoped_ptr.h"
7 #include "app/gfx/gl/gl_mock.h"
6 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
7 9
10 using ::testing::Pointee;
11
8 namespace gpu { 12 namespace gpu {
9 namespace gles2 { 13 namespace gles2 {
10 14
11 class TextureManagerTest : public testing::Test { 15 class TextureManagerTest : public testing::Test {
12 public: 16 public:
13 static const GLint kMaxTextureSize = 16; 17 static const GLint kMaxTextureSize = 16;
14 static const GLint kMaxCubeMapTextureSize = 8; 18 static const GLint kMaxCubeMapTextureSize = 8;
15 static const GLint kMax2dLevels = 5; 19 static const GLint kMax2dLevels = 5;
16 static const GLint kMaxCubeMapLevels = 4; 20 static const GLint kMaxCubeMapLevels = 4;
17 21
18 TextureManagerTest() 22 TextureManagerTest()
19 : manager_(kMaxTextureSize, kMaxCubeMapTextureSize) { 23 : manager_(kMaxTextureSize, kMaxCubeMapTextureSize) {
20 } 24 }
21 25
26 ~TextureManagerTest() {
27 manager_.Destroy(false);
28 }
29
22 protected: 30 protected:
23 virtual void SetUp() { 31 virtual void SetUp() {
32 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
33 ::gfx::GLInterface::SetGLInterface(gl_.get());
24 } 34 }
25 35
26 virtual void TearDown() { 36 virtual void TearDown() {
37 ::gfx::GLInterface::SetGLInterface(NULL);
38 gl_.reset();
27 } 39 }
28 40
41 // Use StrictMock to make 100% sure we know how GL will be called.
42 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
29 TextureManager manager_; 43 TextureManager manager_;
30 }; 44 };
31 45
32 // GCC requires these declarations, but MSVC requires they not be present 46 // GCC requires these declarations, but MSVC requires they not be present
33 #ifndef COMPILER_MSVC 47 #ifndef COMPILER_MSVC
34 const GLint TextureManagerTest::kMaxTextureSize; 48 const GLint TextureManagerTest::kMaxTextureSize;
35 const GLint TextureManagerTest::kMaxCubeMapTextureSize; 49 const GLint TextureManagerTest::kMaxCubeMapTextureSize;
36 const GLint TextureManagerTest::kMax2dLevels; 50 const GLint TextureManagerTest::kMax2dLevels;
37 const GLint TextureManagerTest::kMaxCubeMapLevels; 51 const GLint TextureManagerTest::kMaxCubeMapLevels;
38 #endif 52 #endif
(...skipping 14 matching lines...) Expand all
53 EXPECT_EQ(kClient1Id, client_id); 67 EXPECT_EQ(kClient1Id, client_id);
54 // Check we get nothing for a non-existent texture. 68 // Check we get nothing for a non-existent texture.
55 EXPECT_TRUE(manager_.GetTextureInfo(kClient2Id) == NULL); 69 EXPECT_TRUE(manager_.GetTextureInfo(kClient2Id) == NULL);
56 // Check trying to a remove non-existent textures does not crash. 70 // Check trying to a remove non-existent textures does not crash.
57 manager_.RemoveTextureInfo(kClient2Id); 71 manager_.RemoveTextureInfo(kClient2Id);
58 // Check we can't get the texture after we remove it. 72 // Check we can't get the texture after we remove it.
59 manager_.RemoveTextureInfo(kClient1Id); 73 manager_.RemoveTextureInfo(kClient1Id);
60 EXPECT_TRUE(manager_.GetTextureInfo(kClient1Id) == NULL); 74 EXPECT_TRUE(manager_.GetTextureInfo(kClient1Id) == NULL);
61 } 75 }
62 76
77 TEST_F(TextureManagerTest, Destroy) {
78 const GLuint kClient1Id = 1;
79 const GLuint kService1Id = 11;
80 EXPECT_FALSE(manager_.HaveUnrenderableTextures());
81 // Check we can create texture.
82 manager_.CreateTextureInfo(kClient1Id, kService1Id);
83 // Check texture got created.
84 TextureManager::TextureInfo* info1 = manager_.GetTextureInfo(kClient1Id);
85 ASSERT_TRUE(info1 != NULL);
86 EXPECT_CALL(*gl_, DeleteTextures(1, ::testing::Pointee(kService1Id)))
87 .Times(1)
88 .RetiresOnSaturation();
89 manager_.Destroy(true);
90 // Check that resources got freed.
91 info1 = manager_.GetTextureInfo(kClient1Id);
92 ASSERT_TRUE(info1 == NULL);
93 }
94
63 TEST_F(TextureManagerTest, MaxValues) { 95 TEST_F(TextureManagerTest, MaxValues) {
64 // Check we get the right values for the max sizes. 96 // Check we get the right values for the max sizes.
65 EXPECT_EQ(kMax2dLevels, manager_.MaxLevelsForTarget(GL_TEXTURE_2D)); 97 EXPECT_EQ(kMax2dLevels, manager_.MaxLevelsForTarget(GL_TEXTURE_2D));
66 EXPECT_EQ(kMaxCubeMapLevels, 98 EXPECT_EQ(kMaxCubeMapLevels,
67 manager_.MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP)); 99 manager_.MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP));
68 EXPECT_EQ(kMaxTextureSize, manager_.MaxSizeForTarget(GL_TEXTURE_2D)); 100 EXPECT_EQ(kMaxTextureSize, manager_.MaxSizeForTarget(GL_TEXTURE_2D));
69 EXPECT_EQ(kMaxCubeMapTextureSize, 101 EXPECT_EQ(kMaxCubeMapTextureSize,
70 manager_.MaxSizeForTarget(GL_TEXTURE_CUBE_MAP)); 102 manager_.MaxSizeForTarget(GL_TEXTURE_CUBE_MAP));
71 } 103 }
72 104
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 static const GLint kMaxTextureSize = 16; 151 static const GLint kMaxTextureSize = 16;
120 static const GLint kMaxCubeMapTextureSize = 8; 152 static const GLint kMaxCubeMapTextureSize = 8;
121 static const GLint kMax2dLevels = 5; 153 static const GLint kMax2dLevels = 5;
122 static const GLint kMaxCubeMapLevels = 4; 154 static const GLint kMaxCubeMapLevels = 4;
123 static const GLuint kClient1Id = 1; 155 static const GLuint kClient1Id = 1;
124 static const GLuint kService1Id = 11; 156 static const GLuint kService1Id = 11;
125 157
126 TextureInfoTest() 158 TextureInfoTest()
127 : manager_(kMaxTextureSize, kMaxCubeMapTextureSize) { 159 : manager_(kMaxTextureSize, kMaxCubeMapTextureSize) {
128 } 160 }
161 ~TextureInfoTest() {
162 manager_.Destroy(false);
163 }
129 164
130 protected: 165 protected:
131 virtual void SetUp() { 166 virtual void SetUp() {
167 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
168 ::gfx::GLInterface::SetGLInterface(gl_.get());
132 manager_.CreateTextureInfo(kClient1Id, kService1Id); 169 manager_.CreateTextureInfo(kClient1Id, kService1Id);
133 info_ = manager_.GetTextureInfo(kClient1Id); 170 info_ = manager_.GetTextureInfo(kClient1Id);
134 ASSERT_TRUE(info_ != NULL); 171 ASSERT_TRUE(info_ != NULL);
135 } 172 }
136 173
137 virtual void TearDown() { 174 virtual void TearDown() {
175 ::gfx::GLInterface::SetGLInterface(NULL);
176 gl_.reset();
138 } 177 }
139 178
179 // Use StrictMock to make 100% sure we know how GL will be called.
180 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
140 TextureManager manager_; 181 TextureManager manager_;
141 TextureManager::TextureInfo* info_; 182 TextureManager::TextureInfo* info_;
142 }; 183 };
143 184
144 TEST_F(TextureInfoTest, Basic) { 185 TEST_F(TextureInfoTest, Basic) {
145 EXPECT_EQ(0u, info_->target()); 186 EXPECT_EQ(0u, info_->target());
146 EXPECT_FALSE(info_->texture_complete()); 187 EXPECT_FALSE(info_->texture_complete());
147 EXPECT_FALSE(info_->cube_complete()); 188 EXPECT_FALSE(info_->cube_complete());
148 EXPECT_FALSE(info_->CanGenerateMipmaps()); 189 EXPECT_FALSE(info_->CanGenerateMipmaps());
149 EXPECT_FALSE(info_->npot()); 190 EXPECT_FALSE(info_->npot());
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 EXPECT_EQ(4, width); 364 EXPECT_EQ(4, width);
324 EXPECT_EQ(5, height); 365 EXPECT_EQ(5, height);
325 manager_.RemoveTextureInfo(kClient1Id); 366 manager_.RemoveTextureInfo(kClient1Id);
326 EXPECT_FALSE(info_->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height)); 367 EXPECT_FALSE(info_->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
327 } 368 }
328 369
329 } // namespace gles2 370 } // namespace gles2
330 } // namespace gpu 371 } // namespace gpu
331 372
332 373
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/texture_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698