OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "gpu/command_buffer/service/texture_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "gpu/command_buffer/service/error_state_mock.h" | 8 #include "gpu/command_buffer/service/error_state_mock.h" |
9 #include "gpu/command_buffer/service/feature_info.h" | 9 #include "gpu/command_buffer/service/feature_info.h" |
10 #include "gpu/command_buffer/service/framebuffer_manager.h" | 10 #include "gpu/command_buffer/service/framebuffer_manager.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 class TextureManagerTest : public testing::Test { | 42 class TextureManagerTest : public testing::Test { |
43 public: | 43 public: |
44 static const GLint kMaxTextureSize = 16; | 44 static const GLint kMaxTextureSize = 16; |
45 static const GLint kMaxCubeMapTextureSize = 8; | 45 static const GLint kMaxCubeMapTextureSize = 8; |
46 static const GLint kMaxExternalTextureSize = 16; | 46 static const GLint kMaxExternalTextureSize = 16; |
47 static const GLint kMax2dLevels = 5; | 47 static const GLint kMax2dLevels = 5; |
48 static const GLint kMaxCubeMapLevels = 4; | 48 static const GLint kMaxCubeMapLevels = 4; |
49 static const GLint kMaxExternalLevels = 1; | 49 static const GLint kMaxExternalLevels = 1; |
50 | 50 |
51 TextureManagerTest() | 51 TextureManagerTest() |
52 : feature_info_(new FeatureInfo()) { | 52 : feature_info_(new FeatureInfo()), use_default_textures_(false) {} |
53 } | |
54 | 53 |
55 virtual ~TextureManagerTest() { | 54 virtual ~TextureManagerTest() { |
56 } | 55 } |
57 | 56 |
58 protected: | 57 protected: |
59 virtual void SetUp() { | 58 virtual void SetUp() { |
60 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 59 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
61 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); | 60 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); |
62 | 61 |
63 manager_.reset(new TextureManager( | 62 manager_.reset(new TextureManager( |
64 NULL, feature_info_.get(), | 63 NULL, feature_info_.get(), |
65 kMaxTextureSize, kMaxCubeMapTextureSize)); | 64 kMaxTextureSize, kMaxCubeMapTextureSize)); |
66 TestHelper::SetupTextureManagerInitExpectations(gl_.get(), ""); | 65 TestHelper::SetupTextureManagerInitExpectations( |
66 gl_.get(), "", use_default_textures_); | |
67 manager_->set_use_default_textures(use_default_textures_); | |
67 manager_->Initialize(); | 68 manager_->Initialize(); |
68 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>()); | 69 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>()); |
69 } | 70 } |
70 | 71 |
71 virtual void TearDown() { | 72 virtual void TearDown() { |
72 manager_->Destroy(false); | 73 manager_->Destroy(false); |
73 manager_.reset(); | 74 manager_.reset(); |
74 ::gfx::MockGLInterface::SetGLInterface(NULL); | 75 ::gfx::MockGLInterface::SetGLInterface(NULL); |
75 gl_.reset(); | 76 gl_.reset(); |
76 } | 77 } |
77 | 78 |
78 void SetParameter( | 79 void SetParameter( |
79 TextureRef* texture_ref, GLenum pname, GLint value, GLenum error) { | 80 TextureRef* texture_ref, GLenum pname, GLint value, GLenum error) { |
80 TestHelper::SetTexParameteriWithExpectations( | 81 TestHelper::SetTexParameteriWithExpectations( |
81 gl_.get(), error_state_.get(), manager_.get(), | 82 gl_.get(), error_state_.get(), manager_.get(), |
82 texture_ref, pname, value, error); | 83 texture_ref, pname, value, error); |
83 } | 84 } |
84 | 85 |
85 // Use StrictMock to make 100% sure we know how GL will be called. | 86 // Use StrictMock to make 100% sure we know how GL will be called. |
86 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | 87 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
87 scoped_refptr<FeatureInfo> feature_info_; | 88 scoped_refptr<FeatureInfo> feature_info_; |
88 scoped_ptr<TextureManager> manager_; | 89 scoped_ptr<TextureManager> manager_; |
89 scoped_ptr<MockErrorState> error_state_; | 90 scoped_ptr<MockErrorState> error_state_; |
91 bool use_default_textures_; | |
piman
2014/04/04 02:50:28
Same here, is there anything that sets this?
vmiura
2014/04/04 18:32:57
Changed to kUseDefaultTextures.
| |
90 }; | 92 }; |
91 | 93 |
92 // GCC requires these declarations, but MSVC requires they not be present | 94 // GCC requires these declarations, but MSVC requires they not be present |
93 #ifndef COMPILER_MSVC | 95 #ifndef COMPILER_MSVC |
94 const GLint TextureManagerTest::kMaxTextureSize; | 96 const GLint TextureManagerTest::kMaxTextureSize; |
95 const GLint TextureManagerTest::kMaxCubeMapTextureSize; | 97 const GLint TextureManagerTest::kMaxCubeMapTextureSize; |
96 const GLint TextureManagerTest::kMaxExternalTextureSize; | 98 const GLint TextureManagerTest::kMaxExternalTextureSize; |
97 const GLint TextureManagerTest::kMax2dLevels; | 99 const GLint TextureManagerTest::kMax2dLevels; |
98 const GLint TextureManagerTest::kMaxCubeMapLevels; | 100 const GLint TextureManagerTest::kMaxCubeMapLevels; |
99 const GLint TextureManagerTest::kMaxExternalLevels; | 101 const GLint TextureManagerTest::kMaxExternalLevels; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 texture_ref, GL_TEXTURE_MAG_FILTER, GL_CLAMP_TO_EDGE, GL_INVALID_ENUM); | 158 texture_ref, GL_TEXTURE_MAG_FILTER, GL_CLAMP_TO_EDGE, GL_INVALID_ENUM); |
157 EXPECT_EQ(static_cast<GLenum>(GL_NEAREST), texture->min_filter()); | 159 EXPECT_EQ(static_cast<GLenum>(GL_NEAREST), texture->min_filter()); |
158 SetParameter(texture_ref, GL_TEXTURE_WRAP_S, GL_NEAREST, GL_INVALID_ENUM); | 160 SetParameter(texture_ref, GL_TEXTURE_WRAP_S, GL_NEAREST, GL_INVALID_ENUM); |
159 EXPECT_EQ(static_cast<GLenum>(GL_CLAMP_TO_EDGE), texture->wrap_s()); | 161 EXPECT_EQ(static_cast<GLenum>(GL_CLAMP_TO_EDGE), texture->wrap_s()); |
160 SetParameter(texture_ref, GL_TEXTURE_WRAP_T, GL_NEAREST, GL_INVALID_ENUM); | 162 SetParameter(texture_ref, GL_TEXTURE_WRAP_T, GL_NEAREST, GL_INVALID_ENUM); |
161 EXPECT_EQ(static_cast<GLenum>(GL_CLAMP_TO_EDGE), texture->wrap_t()); | 163 EXPECT_EQ(static_cast<GLenum>(GL_CLAMP_TO_EDGE), texture->wrap_t()); |
162 SetParameter(texture_ref, GL_TEXTURE_MAX_ANISOTROPY_EXT, 0, GL_INVALID_VALUE); | 164 SetParameter(texture_ref, GL_TEXTURE_MAX_ANISOTROPY_EXT, 0, GL_INVALID_VALUE); |
163 } | 165 } |
164 | 166 |
165 TEST_F(TextureManagerTest, TextureUsageExt) { | 167 TEST_F(TextureManagerTest, TextureUsageExt) { |
166 TestHelper::SetupTextureManagerInitExpectations(gl_.get(), | 168 bool use_default_textures = false; |
167 "GL_ANGLE_texture_usage"); | 169 TestHelper::SetupTextureManagerInitExpectations( |
170 gl_.get(), "GL_ANGLE_texture_usage", use_default_textures); | |
168 TextureManager manager( | 171 TextureManager manager( |
169 NULL, feature_info_.get(), kMaxTextureSize, kMaxCubeMapTextureSize); | 172 NULL, feature_info_.get(), kMaxTextureSize, kMaxCubeMapTextureSize); |
170 manager.Initialize(); | 173 manager.Initialize(); |
171 const GLuint kClient1Id = 1; | 174 const GLuint kClient1Id = 1; |
172 const GLuint kService1Id = 11; | 175 const GLuint kService1Id = 11; |
173 // Check we can create texture. | 176 // Check we can create texture. |
174 manager.CreateTexture(kClient1Id, kService1Id); | 177 manager.CreateTexture(kClient1Id, kService1Id); |
175 // Check texture got created. | 178 // Check texture got created. |
176 TextureRef* texture_ref = manager.GetTexture(kClient1Id); | 179 TextureRef* texture_ref = manager.GetTexture(kClient1Id); |
177 ASSERT_TRUE(texture_ref != NULL); | 180 ASSERT_TRUE(texture_ref != NULL); |
178 TestHelper::SetTexParameteriWithExpectations( | 181 TestHelper::SetTexParameteriWithExpectations( |
179 gl_.get(), error_state_.get(), &manager, texture_ref, | 182 gl_.get(), error_state_.get(), &manager, texture_ref, |
180 GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE,GL_NO_ERROR); | 183 GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE,GL_NO_ERROR); |
181 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_ATTACHMENT_ANGLE), | 184 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_ATTACHMENT_ANGLE), |
182 texture_ref->texture()->usage()); | 185 texture_ref->texture()->usage()); |
183 manager.Destroy(false); | 186 manager.Destroy(false); |
184 } | 187 } |
185 | 188 |
186 TEST_F(TextureManagerTest, Destroy) { | 189 TEST_F(TextureManagerTest, Destroy) { |
187 const GLuint kClient1Id = 1; | 190 const GLuint kClient1Id = 1; |
188 const GLuint kService1Id = 11; | 191 const GLuint kService1Id = 11; |
189 TestHelper::SetupTextureManagerInitExpectations(gl_.get(), ""); | 192 bool use_default_textures = false; |
193 TestHelper::SetupTextureManagerInitExpectations( | |
194 gl_.get(), "", use_default_textures); | |
190 TextureManager manager( | 195 TextureManager manager( |
191 NULL, feature_info_.get(), kMaxTextureSize, kMaxCubeMapTextureSize); | 196 NULL, feature_info_.get(), kMaxTextureSize, kMaxCubeMapTextureSize); |
192 manager.Initialize(); | 197 manager.Initialize(); |
193 // Check we can create texture. | 198 // Check we can create texture. |
194 manager.CreateTexture(kClient1Id, kService1Id); | 199 manager.CreateTexture(kClient1Id, kService1Id); |
195 // Check texture got created. | 200 // Check texture got created. |
196 TextureRef* texture = manager.GetTexture(kClient1Id); | 201 TextureRef* texture = manager.GetTexture(kClient1Id); |
197 ASSERT_TRUE(texture != NULL); | 202 ASSERT_TRUE(texture != NULL); |
198 EXPECT_CALL(*gl_, DeleteTextures(1, ::testing::Pointee(kService1Id))) | 203 EXPECT_CALL(*gl_, DeleteTextures(1, ::testing::Pointee(kService1Id))) |
199 .Times(1) | 204 .Times(1) |
200 .RetiresOnSaturation(); | 205 .RetiresOnSaturation(); |
201 TestHelper::SetupTextureManagerDestructionExpectations(gl_.get(), ""); | 206 TestHelper::SetupTextureManagerDestructionExpectations( |
207 gl_.get(), "", use_default_textures); | |
202 manager.Destroy(true); | 208 manager.Destroy(true); |
203 // Check that resources got freed. | 209 // Check that resources got freed. |
204 texture = manager.GetTexture(kClient1Id); | 210 texture = manager.GetTexture(kClient1Id); |
205 ASSERT_TRUE(texture == NULL); | 211 ASSERT_TRUE(texture == NULL); |
206 } | 212 } |
207 | 213 |
208 TEST_F(TextureManagerTest, MaxValues) { | 214 TEST_F(TextureManagerTest, MaxValues) { |
209 // Check we get the right values for the max sizes. | 215 // Check we get the right values for the max sizes. |
210 EXPECT_EQ(kMax2dLevels, manager_->MaxLevelsForTarget(GL_TEXTURE_2D)); | 216 EXPECT_EQ(kMax2dLevels, manager_->MaxLevelsForTarget(GL_TEXTURE_2D)); |
211 EXPECT_EQ(kMaxCubeMapLevels, | 217 EXPECT_EQ(kMaxCubeMapLevels, |
(...skipping 1908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2120 private: | 2126 private: |
2121 virtual ~CountingMemoryTracker() {} | 2127 virtual ~CountingMemoryTracker() {} |
2122 | 2128 |
2123 size_t current_size_[2]; | 2129 size_t current_size_[2]; |
2124 DISALLOW_COPY_AND_ASSIGN(CountingMemoryTracker); | 2130 DISALLOW_COPY_AND_ASSIGN(CountingMemoryTracker); |
2125 }; | 2131 }; |
2126 | 2132 |
2127 class SharedTextureTest : public testing::Test { | 2133 class SharedTextureTest : public testing::Test { |
2128 public: | 2134 public: |
2129 SharedTextureTest() | 2135 SharedTextureTest() |
2130 : feature_info_(new FeatureInfo()) { | 2136 : feature_info_(new FeatureInfo()), use_default_textures_(false) {} |
2131 } | |
2132 | 2137 |
2133 virtual ~SharedTextureTest() { | 2138 virtual ~SharedTextureTest() { |
2134 } | 2139 } |
2135 | 2140 |
2136 virtual void SetUp() { | 2141 virtual void SetUp() { |
2137 gl_.reset(new ::gfx::MockGLInterface()); | 2142 gl_.reset(new ::gfx::MockGLInterface()); |
2138 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); | 2143 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); |
2139 | 2144 |
2140 memory_tracker1_ = new CountingMemoryTracker; | 2145 memory_tracker1_ = new CountingMemoryTracker; |
2141 texture_manager1_.reset( | 2146 texture_manager1_.reset( |
2142 new TextureManager(memory_tracker1_.get(), | 2147 new TextureManager(memory_tracker1_.get(), |
2143 feature_info_.get(), | 2148 feature_info_.get(), |
2144 TextureManagerTest::kMaxTextureSize, | 2149 TextureManagerTest::kMaxTextureSize, |
2145 TextureManagerTest::kMaxCubeMapTextureSize)); | 2150 TextureManagerTest::kMaxCubeMapTextureSize)); |
2146 memory_tracker2_ = new CountingMemoryTracker; | 2151 memory_tracker2_ = new CountingMemoryTracker; |
2147 texture_manager2_.reset( | 2152 texture_manager2_.reset( |
2148 new TextureManager(memory_tracker2_.get(), | 2153 new TextureManager(memory_tracker2_.get(), |
2149 feature_info_.get(), | 2154 feature_info_.get(), |
2150 TextureManagerTest::kMaxTextureSize, | 2155 TextureManagerTest::kMaxTextureSize, |
2151 TextureManagerTest::kMaxCubeMapTextureSize)); | 2156 TextureManagerTest::kMaxCubeMapTextureSize)); |
2152 TestHelper::SetupTextureManagerInitExpectations(gl_.get(), ""); | 2157 TestHelper::SetupTextureManagerInitExpectations( |
2158 gl_.get(), "", use_default_textures_); | |
2159 texture_manager1_->set_use_default_textures(use_default_textures_); | |
2153 texture_manager1_->Initialize(); | 2160 texture_manager1_->Initialize(); |
2154 TestHelper::SetupTextureManagerInitExpectations(gl_.get(), ""); | 2161 TestHelper::SetupTextureManagerInitExpectations( |
2162 gl_.get(), "", use_default_textures_); | |
2163 texture_manager2_->set_use_default_textures(use_default_textures_); | |
2155 texture_manager2_->Initialize(); | 2164 texture_manager2_->Initialize(); |
2156 } | 2165 } |
2157 | 2166 |
2158 virtual void TearDown() { | 2167 virtual void TearDown() { |
2159 texture_manager2_->Destroy(false); | 2168 texture_manager2_->Destroy(false); |
2160 texture_manager2_.reset(); | 2169 texture_manager2_.reset(); |
2161 texture_manager1_->Destroy(false); | 2170 texture_manager1_->Destroy(false); |
2162 texture_manager1_.reset(); | 2171 texture_manager1_.reset(); |
2163 ::gfx::MockGLInterface::SetGLInterface(NULL); | 2172 ::gfx::MockGLInterface::SetGLInterface(NULL); |
2164 gl_.reset(); | 2173 gl_.reset(); |
2165 } | 2174 } |
2166 | 2175 |
2167 protected: | 2176 protected: |
2168 scoped_ptr< ::gfx::MockGLInterface > gl_; | 2177 scoped_ptr< ::gfx::MockGLInterface > gl_; |
2169 scoped_refptr<FeatureInfo> feature_info_; | 2178 scoped_refptr<FeatureInfo> feature_info_; |
2170 scoped_refptr<CountingMemoryTracker> memory_tracker1_; | 2179 scoped_refptr<CountingMemoryTracker> memory_tracker1_; |
2171 scoped_ptr<TextureManager> texture_manager1_; | 2180 scoped_ptr<TextureManager> texture_manager1_; |
2172 scoped_refptr<CountingMemoryTracker> memory_tracker2_; | 2181 scoped_refptr<CountingMemoryTracker> memory_tracker2_; |
2173 scoped_ptr<TextureManager> texture_manager2_; | 2182 scoped_ptr<TextureManager> texture_manager2_; |
2183 bool use_default_textures_; | |
2174 }; | 2184 }; |
2175 | 2185 |
2176 TEST_F(SharedTextureTest, DeleteTextures) { | 2186 TEST_F(SharedTextureTest, DeleteTextures) { |
2177 scoped_refptr<TextureRef> ref1 = texture_manager1_->CreateTexture(10, 10); | 2187 scoped_refptr<TextureRef> ref1 = texture_manager1_->CreateTexture(10, 10); |
2178 scoped_refptr<TextureRef> ref2 = | 2188 scoped_refptr<TextureRef> ref2 = |
2179 texture_manager2_->Consume(20, ref1->texture()); | 2189 texture_manager2_->Consume(20, ref1->texture()); |
2180 EXPECT_CALL(*gl_, DeleteTextures(1, _)) | 2190 EXPECT_CALL(*gl_, DeleteTextures(1, _)) |
2181 .Times(0); | 2191 .Times(0); |
2182 ref1 = NULL; | 2192 ref1 = NULL; |
2183 texture_manager1_->RemoveTexture(10); | 2193 texture_manager1_->RemoveTexture(10); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2438 | 2448 |
2439 EXPECT_CALL(*gl_, DeleteTextures(1, _)) | 2449 EXPECT_CALL(*gl_, DeleteTextures(1, _)) |
2440 .Times(1) | 2450 .Times(1) |
2441 .RetiresOnSaturation(); | 2451 .RetiresOnSaturation(); |
2442 texture_manager1_->RemoveTexture(10); | 2452 texture_manager1_->RemoveTexture(10); |
2443 texture_manager2_->RemoveTexture(20); | 2453 texture_manager2_->RemoveTexture(20); |
2444 } | 2454 } |
2445 | 2455 |
2446 } // namespace gles2 | 2456 } // namespace gles2 |
2447 } // namespace gpu | 2457 } // namespace gpu |
OLD | NEW |