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

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

Issue 331293005: Revert of gpu: Add base class for gpu service tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
OLDNEW
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"
11 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" 11 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
12 #include "gpu/command_buffer/service/gpu_service_test.h"
13 #include "gpu/command_buffer/service/mailbox_manager.h" 12 #include "gpu/command_buffer/service/mailbox_manager.h"
14 #include "gpu/command_buffer/service/memory_tracking.h" 13 #include "gpu/command_buffer/service/memory_tracking.h"
15 #include "gpu/command_buffer/service/mocks.h" 14 #include "gpu/command_buffer/service/mocks.h"
16 #include "gpu/command_buffer/service/test_helper.h" 15 #include "gpu/command_buffer/service/test_helper.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gl/gl_mock.h" 17 #include "ui/gl/gl_mock.h"
19 18
20 using ::testing::AtLeast; 19 using ::testing::AtLeast;
21 using ::testing::Pointee; 20 using ::testing::Pointee;
22 using ::testing::Return; 21 using ::testing::Return;
(...skipping 10 matching lines...) Expand all
33 return texture->npot(); 32 return texture->npot();
34 } 33 }
35 static bool IsTextureComplete(const Texture* texture) { 34 static bool IsTextureComplete(const Texture* texture) {
36 return texture->texture_complete(); 35 return texture->texture_complete();
37 } 36 }
38 static bool IsCubeComplete(const Texture* texture) { 37 static bool IsCubeComplete(const Texture* texture) {
39 return texture->cube_complete(); 38 return texture->cube_complete();
40 } 39 }
41 }; 40 };
42 41
43 class TextureManagerTest : public GpuServiceTest { 42 class TextureManagerTest : public testing::Test {
44 public: 43 public:
45 static const GLint kMaxTextureSize = 16; 44 static const GLint kMaxTextureSize = 16;
46 static const GLint kMaxCubeMapTextureSize = 8; 45 static const GLint kMaxCubeMapTextureSize = 8;
47 static const GLint kMaxExternalTextureSize = 16; 46 static const GLint kMaxExternalTextureSize = 16;
48 static const GLint kMax2dLevels = 5; 47 static const GLint kMax2dLevels = 5;
49 static const GLint kMaxCubeMapLevels = 4; 48 static const GLint kMaxCubeMapLevels = 4;
50 static const GLint kMaxExternalLevels = 1; 49 static const GLint kMaxExternalLevels = 1;
51 static const bool kUseDefaultTextures = false; 50 static const bool kUseDefaultTextures = false;
52 51
53 TextureManagerTest() : feature_info_(new FeatureInfo()) {} 52 TextureManagerTest() : feature_info_(new FeatureInfo()) {}
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 GpuServiceTest::SetUp(); 59 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
60 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
61
61 manager_.reset(new TextureManager(NULL, 62 manager_.reset(new TextureManager(NULL,
62 feature_info_.get(), 63 feature_info_.get(),
63 kMaxTextureSize, 64 kMaxTextureSize,
64 kMaxCubeMapTextureSize, 65 kMaxCubeMapTextureSize,
65 kUseDefaultTextures)); 66 kUseDefaultTextures));
66 TestHelper::SetupTextureManagerInitExpectations( 67 TestHelper::SetupTextureManagerInitExpectations(
67 gl_.get(), "", kUseDefaultTextures); 68 gl_.get(), "", kUseDefaultTextures);
68 manager_->Initialize(); 69 manager_->Initialize();
69 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>()); 70 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>());
70 } 71 }
71 72
72 virtual void TearDown() { 73 virtual void TearDown() {
73 manager_->Destroy(false); 74 manager_->Destroy(false);
74 manager_.reset(); 75 manager_.reset();
75 GpuServiceTest::TearDown(); 76 ::gfx::MockGLInterface::SetGLInterface(NULL);
77 gl_.reset();
76 } 78 }
77 79
78 void SetParameter( 80 void SetParameter(
79 TextureRef* texture_ref, GLenum pname, GLint value, GLenum error) { 81 TextureRef* texture_ref, GLenum pname, GLint value, GLenum error) {
80 TestHelper::SetTexParameteriWithExpectations( 82 TestHelper::SetTexParameteriWithExpectations(
81 gl_.get(), error_state_.get(), manager_.get(), 83 gl_.get(), error_state_.get(), manager_.get(),
82 texture_ref, pname, value, error); 84 texture_ref, pname, value, error);
83 } 85 }
84 86
87 // Use StrictMock to make 100% sure we know how GL will be called.
88 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
85 scoped_refptr<FeatureInfo> feature_info_; 89 scoped_refptr<FeatureInfo> feature_info_;
86 scoped_ptr<TextureManager> manager_; 90 scoped_ptr<TextureManager> manager_;
87 scoped_ptr<MockErrorState> error_state_; 91 scoped_ptr<MockErrorState> error_state_;
88 }; 92 };
89 93
90 // GCC requires these declarations, but MSVC requires they not be present 94 // GCC requires these declarations, but MSVC requires they not be present
91 #ifndef COMPILER_MSVC 95 #ifndef COMPILER_MSVC
92 const GLint TextureManagerTest::kMaxTextureSize; 96 const GLint TextureManagerTest::kMaxTextureSize;
93 const GLint TextureManagerTest::kMaxCubeMapTextureSize; 97 const GLint TextureManagerTest::kMaxCubeMapTextureSize;
94 const GLint TextureManagerTest::kMaxExternalTextureSize; 98 const GLint TextureManagerTest::kMaxExternalTextureSize;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 EXPECT_TRUE(manager.ValidForTarget(GL_TEXTURE_2D, 0, 5, 2, 1)); 378 EXPECT_TRUE(manager.ValidForTarget(GL_TEXTURE_2D, 0, 5, 2, 1));
375 // Check NPOT height on level 0 379 // Check NPOT height on level 0
376 EXPECT_TRUE(manager.ValidForTarget(GL_TEXTURE_2D, 0, 2, 5, 1)); 380 EXPECT_TRUE(manager.ValidForTarget(GL_TEXTURE_2D, 0, 2, 5, 1));
377 // Check NPOT width on level 1 381 // Check NPOT width on level 1
378 EXPECT_TRUE(manager.ValidForTarget(GL_TEXTURE_2D, 1, 5, 2, 1)); 382 EXPECT_TRUE(manager.ValidForTarget(GL_TEXTURE_2D, 1, 5, 2, 1));
379 // Check NPOT height on level 1 383 // Check NPOT height on level 1
380 EXPECT_TRUE(manager.ValidForTarget(GL_TEXTURE_2D, 1, 2, 5, 1)); 384 EXPECT_TRUE(manager.ValidForTarget(GL_TEXTURE_2D, 1, 2, 5, 1));
381 manager.Destroy(false); 385 manager.Destroy(false);
382 } 386 }
383 387
384 class TextureTestBase : public GpuServiceTest { 388 class TextureTestBase : public testing::Test {
385 public: 389 public:
386 static const GLint kMaxTextureSize = 16; 390 static const GLint kMaxTextureSize = 16;
387 static const GLint kMaxCubeMapTextureSize = 8; 391 static const GLint kMaxCubeMapTextureSize = 8;
388 static const GLint kMax2dLevels = 5; 392 static const GLint kMax2dLevels = 5;
389 static const GLint kMaxCubeMapLevels = 4; 393 static const GLint kMaxCubeMapLevels = 4;
390 static const GLuint kClient1Id = 1; 394 static const GLuint kClient1Id = 1;
391 static const GLuint kService1Id = 11; 395 static const GLuint kService1Id = 11;
392 static const bool kUseDefaultTextures = false; 396 static const bool kUseDefaultTextures = false;
393 397
394 TextureTestBase() 398 TextureTestBase()
395 : feature_info_(new FeatureInfo()) { 399 : feature_info_(new FeatureInfo()) {
396 } 400 }
397 virtual ~TextureTestBase() { 401 virtual ~TextureTestBase() {
398 texture_ref_ = NULL; 402 texture_ref_ = NULL;
399 } 403 }
400 404
401 protected: 405 protected:
402 void SetUpBase(MemoryTracker* memory_tracker, std::string extensions) { 406 void SetUpBase(MemoryTracker* memory_tracker, std::string extensions) {
403 GpuServiceTest::SetUp(); 407 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
408 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
409
404 if (!extensions.empty()) { 410 if (!extensions.empty()) {
405 TestHelper::SetupFeatureInfoInitExpectations(gl_.get(), 411 TestHelper::SetupFeatureInfoInitExpectations(gl_.get(),
406 extensions.c_str()); 412 extensions.c_str());
407 feature_info_->Initialize(); 413 feature_info_->Initialize();
408 } 414 }
409 415
410 manager_.reset(new TextureManager(memory_tracker, 416 manager_.reset(new TextureManager(memory_tracker,
411 feature_info_.get(), 417 feature_info_.get(),
412 kMaxTextureSize, 418 kMaxTextureSize,
413 kMaxCubeMapTextureSize, 419 kMaxCubeMapTextureSize,
(...skipping 13 matching lines...) Expand all
427 // Check that it gets deleted when the last reference is released. 433 // Check that it gets deleted when the last reference is released.
428 EXPECT_CALL(*gl_, 434 EXPECT_CALL(*gl_,
429 DeleteTextures(1, ::testing::Pointee(texture_ref_->service_id()))) 435 DeleteTextures(1, ::testing::Pointee(texture_ref_->service_id())))
430 .Times(1) 436 .Times(1)
431 .RetiresOnSaturation(); 437 .RetiresOnSaturation();
432 } 438 }
433 texture_ref_ = NULL; 439 texture_ref_ = NULL;
434 } 440 }
435 manager_->Destroy(false); 441 manager_->Destroy(false);
436 manager_.reset(); 442 manager_.reset();
437 GpuServiceTest::TearDown(); 443 ::gfx::MockGLInterface::SetGLInterface(NULL);
444 gl_.reset();
438 } 445 }
439 446
440 void SetParameter( 447 void SetParameter(
441 TextureRef* texture_ref, GLenum pname, GLint value, GLenum error) { 448 TextureRef* texture_ref, GLenum pname, GLint value, GLenum error) {
442 TestHelper::SetTexParameteriWithExpectations( 449 TestHelper::SetTexParameteriWithExpectations(
443 gl_.get(), error_state_.get(), manager_.get(), 450 gl_.get(), error_state_.get(), manager_.get(),
444 texture_ref, pname, value, error); 451 texture_ref, pname, value, error);
445 } 452 }
446 453
447 scoped_ptr<MockGLES2Decoder> decoder_; 454 scoped_ptr<MockGLES2Decoder> decoder_;
448 scoped_ptr<MockErrorState> error_state_; 455 scoped_ptr<MockErrorState> error_state_;
456 // Use StrictMock to make 100% sure we know how GL will be called.
457 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
449 scoped_refptr<FeatureInfo> feature_info_; 458 scoped_refptr<FeatureInfo> feature_info_;
450 scoped_ptr<TextureManager> manager_; 459 scoped_ptr<TextureManager> manager_;
451 scoped_refptr<TextureRef> texture_ref_; 460 scoped_refptr<TextureRef> texture_ref_;
452 }; 461 };
453 462
454 class TextureTest : public TextureTestBase { 463 class TextureTest : public TextureTestBase {
455 protected: 464 protected:
456 virtual void SetUp() { 465 virtual void SetUp() {
457 SetUpBase(NULL, std::string()); 466 SetUpBase(NULL, std::string());
458 } 467 }
(...skipping 1726 matching lines...) Expand 10 before | Expand all | Expand 10 after
2185 return current_size_[pool]; 2194 return current_size_[pool];
2186 } 2195 }
2187 2196
2188 private: 2197 private:
2189 virtual ~CountingMemoryTracker() {} 2198 virtual ~CountingMemoryTracker() {}
2190 2199
2191 size_t current_size_[2]; 2200 size_t current_size_[2];
2192 DISALLOW_COPY_AND_ASSIGN(CountingMemoryTracker); 2201 DISALLOW_COPY_AND_ASSIGN(CountingMemoryTracker);
2193 }; 2202 };
2194 2203
2195 class SharedTextureTest : public GpuServiceTest { 2204 class SharedTextureTest : public testing::Test {
2196 public: 2205 public:
2197 static const bool kUseDefaultTextures = false; 2206 static const bool kUseDefaultTextures = false;
2198 2207
2199 SharedTextureTest() : feature_info_(new FeatureInfo()) {} 2208 SharedTextureTest() : feature_info_(new FeatureInfo()) {}
2200 2209
2201 virtual ~SharedTextureTest() { 2210 virtual ~SharedTextureTest() {
2202 } 2211 }
2203 2212
2204 virtual void SetUp() { 2213 virtual void SetUp() {
2205 GpuServiceTest::SetUp(); 2214 gl_.reset(new ::gfx::MockGLInterface());
2215 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
2216
2206 memory_tracker1_ = new CountingMemoryTracker; 2217 memory_tracker1_ = new CountingMemoryTracker;
2207 texture_manager1_.reset( 2218 texture_manager1_.reset(
2208 new TextureManager(memory_tracker1_.get(), 2219 new TextureManager(memory_tracker1_.get(),
2209 feature_info_.get(), 2220 feature_info_.get(),
2210 TextureManagerTest::kMaxTextureSize, 2221 TextureManagerTest::kMaxTextureSize,
2211 TextureManagerTest::kMaxCubeMapTextureSize, 2222 TextureManagerTest::kMaxCubeMapTextureSize,
2212 kUseDefaultTextures)); 2223 kUseDefaultTextures));
2213 memory_tracker2_ = new CountingMemoryTracker; 2224 memory_tracker2_ = new CountingMemoryTracker;
2214 texture_manager2_.reset( 2225 texture_manager2_.reset(
2215 new TextureManager(memory_tracker2_.get(), 2226 new TextureManager(memory_tracker2_.get(),
2216 feature_info_.get(), 2227 feature_info_.get(),
2217 TextureManagerTest::kMaxTextureSize, 2228 TextureManagerTest::kMaxTextureSize,
2218 TextureManagerTest::kMaxCubeMapTextureSize, 2229 TextureManagerTest::kMaxCubeMapTextureSize,
2219 kUseDefaultTextures)); 2230 kUseDefaultTextures));
2220 TestHelper::SetupTextureManagerInitExpectations( 2231 TestHelper::SetupTextureManagerInitExpectations(
2221 gl_.get(), "", kUseDefaultTextures); 2232 gl_.get(), "", kUseDefaultTextures);
2222 texture_manager1_->Initialize(); 2233 texture_manager1_->Initialize();
2223 TestHelper::SetupTextureManagerInitExpectations( 2234 TestHelper::SetupTextureManagerInitExpectations(
2224 gl_.get(), "", kUseDefaultTextures); 2235 gl_.get(), "", kUseDefaultTextures);
2225 texture_manager2_->Initialize(); 2236 texture_manager2_->Initialize();
2226 } 2237 }
2227 2238
2228 virtual void TearDown() { 2239 virtual void TearDown() {
2229 texture_manager2_->Destroy(false); 2240 texture_manager2_->Destroy(false);
2230 texture_manager2_.reset(); 2241 texture_manager2_.reset();
2231 texture_manager1_->Destroy(false); 2242 texture_manager1_->Destroy(false);
2232 texture_manager1_.reset(); 2243 texture_manager1_.reset();
2233 GpuServiceTest::TearDown(); 2244 ::gfx::MockGLInterface::SetGLInterface(NULL);
2245 gl_.reset();
2234 } 2246 }
2235 2247
2236 protected: 2248 protected:
2249 scoped_ptr< ::gfx::MockGLInterface > gl_;
2237 scoped_refptr<FeatureInfo> feature_info_; 2250 scoped_refptr<FeatureInfo> feature_info_;
2238 scoped_refptr<CountingMemoryTracker> memory_tracker1_; 2251 scoped_refptr<CountingMemoryTracker> memory_tracker1_;
2239 scoped_ptr<TextureManager> texture_manager1_; 2252 scoped_ptr<TextureManager> texture_manager1_;
2240 scoped_refptr<CountingMemoryTracker> memory_tracker2_; 2253 scoped_refptr<CountingMemoryTracker> memory_tracker2_;
2241 scoped_ptr<TextureManager> texture_manager2_; 2254 scoped_ptr<TextureManager> texture_manager2_;
2242 }; 2255 };
2243 2256
2244 TEST_F(SharedTextureTest, DeleteTextures) { 2257 TEST_F(SharedTextureTest, DeleteTextures) {
2245 scoped_refptr<TextureRef> ref1 = texture_manager1_->CreateTexture(10, 10); 2258 scoped_refptr<TextureRef> ref1 = texture_manager1_->CreateTexture(10, 10);
2246 scoped_refptr<TextureRef> ref2 = 2259 scoped_refptr<TextureRef> ref2 =
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
2506 2519
2507 EXPECT_CALL(*gl_, DeleteTextures(1, _)) 2520 EXPECT_CALL(*gl_, DeleteTextures(1, _))
2508 .Times(1) 2521 .Times(1)
2509 .RetiresOnSaturation(); 2522 .RetiresOnSaturation();
2510 texture_manager1_->RemoveTexture(10); 2523 texture_manager1_->RemoveTexture(10);
2511 texture_manager2_->RemoveTexture(20); 2524 texture_manager2_->RemoveTexture(20);
2512 } 2525 }
2513 2526
2514 } // namespace gles2 2527 } // namespace gles2
2515 } // namespace gpu 2528 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/shader_manager_unittest.cc ('k') | gpu/command_buffer/service/vertex_array_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698