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

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

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