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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "gpu/command_buffer/service/error_state_mock.h" | 10 #include "gpu/command_buffer/service/error_state_mock.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 static const GLint kMaxTextureSize = 16; | 48 static const GLint kMaxTextureSize = 16; |
49 static const GLint kMaxCubeMapTextureSize = 8; | 49 static const GLint kMaxCubeMapTextureSize = 8; |
50 static const GLint kMaxExternalTextureSize = 16; | 50 static const GLint kMaxExternalTextureSize = 16; |
51 static const GLint kMax2dLevels = 5; | 51 static const GLint kMax2dLevels = 5; |
52 static const GLint kMaxCubeMapLevels = 4; | 52 static const GLint kMaxCubeMapLevels = 4; |
53 static const GLint kMaxExternalLevels = 1; | 53 static const GLint kMaxExternalLevels = 1; |
54 static const bool kUseDefaultTextures = false; | 54 static const bool kUseDefaultTextures = false; |
55 | 55 |
56 TextureManagerTest() : feature_info_(new FeatureInfo()) {} | 56 TextureManagerTest() : feature_info_(new FeatureInfo()) {} |
57 | 57 |
58 virtual ~TextureManagerTest() { | 58 ~TextureManagerTest() override {} |
59 } | |
60 | 59 |
61 protected: | 60 protected: |
62 virtual void SetUp() { | 61 void SetUp() override { |
63 GpuServiceTest::SetUp(); | 62 GpuServiceTest::SetUp(); |
64 manager_.reset(new TextureManager(NULL, | 63 manager_.reset(new TextureManager(NULL, |
65 feature_info_.get(), | 64 feature_info_.get(), |
66 kMaxTextureSize, | 65 kMaxTextureSize, |
67 kMaxCubeMapTextureSize, | 66 kMaxCubeMapTextureSize, |
68 kUseDefaultTextures)); | 67 kUseDefaultTextures)); |
69 TestHelper::SetupTextureManagerInitExpectations( | 68 TestHelper::SetupTextureManagerInitExpectations( |
70 gl_.get(), "", kUseDefaultTextures); | 69 gl_.get(), "", kUseDefaultTextures); |
71 manager_->Initialize(); | 70 manager_->Initialize(); |
72 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>()); | 71 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>()); |
73 } | 72 } |
74 | 73 |
75 virtual void TearDown() { | 74 void TearDown() override { |
76 manager_->Destroy(false); | 75 manager_->Destroy(false); |
77 manager_.reset(); | 76 manager_.reset(); |
78 GpuServiceTest::TearDown(); | 77 GpuServiceTest::TearDown(); |
79 } | 78 } |
80 | 79 |
81 void SetParameter( | 80 void SetParameter( |
82 TextureRef* texture_ref, GLenum pname, GLint value, GLenum error) { | 81 TextureRef* texture_ref, GLenum pname, GLint value, GLenum error) { |
83 TestHelper::SetTexParameteriWithExpectations( | 82 TestHelper::SetTexParameteriWithExpectations( |
84 gl_.get(), error_state_.get(), manager_.get(), | 83 gl_.get(), error_state_.get(), manager_.get(), |
85 texture_ref, pname, value, error); | 84 texture_ref, pname, value, error); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 static const GLint kMaxCubeMapTextureSize = 8; | 389 static const GLint kMaxCubeMapTextureSize = 8; |
391 static const GLint kMax2dLevels = 5; | 390 static const GLint kMax2dLevels = 5; |
392 static const GLint kMaxCubeMapLevels = 4; | 391 static const GLint kMaxCubeMapLevels = 4; |
393 static const GLuint kClient1Id = 1; | 392 static const GLuint kClient1Id = 1; |
394 static const GLuint kService1Id = 11; | 393 static const GLuint kService1Id = 11; |
395 static const bool kUseDefaultTextures = false; | 394 static const bool kUseDefaultTextures = false; |
396 | 395 |
397 TextureTestBase() | 396 TextureTestBase() |
398 : feature_info_(new FeatureInfo()) { | 397 : feature_info_(new FeatureInfo()) { |
399 } | 398 } |
400 virtual ~TextureTestBase() { | 399 ~TextureTestBase() override { texture_ref_ = NULL; } |
401 texture_ref_ = NULL; | |
402 } | |
403 | 400 |
404 protected: | 401 protected: |
405 void SetUpBase(MemoryTracker* memory_tracker, std::string extensions) { | 402 void SetUpBase(MemoryTracker* memory_tracker, std::string extensions) { |
406 GpuServiceTest::SetUp(); | 403 GpuServiceTest::SetUp(); |
407 if (!extensions.empty()) { | 404 if (!extensions.empty()) { |
408 TestHelper::SetupFeatureInfoInitExpectations(gl_.get(), | 405 TestHelper::SetupFeatureInfoInitExpectations(gl_.get(), |
409 extensions.c_str()); | 406 extensions.c_str()); |
410 feature_info_->Initialize(); | 407 feature_info_->Initialize(); |
411 } | 408 } |
412 | 409 |
413 manager_.reset(new TextureManager(memory_tracker, | 410 manager_.reset(new TextureManager(memory_tracker, |
414 feature_info_.get(), | 411 feature_info_.get(), |
415 kMaxTextureSize, | 412 kMaxTextureSize, |
416 kMaxCubeMapTextureSize, | 413 kMaxCubeMapTextureSize, |
417 kUseDefaultTextures)); | 414 kUseDefaultTextures)); |
418 decoder_.reset(new ::testing::StrictMock<gles2::MockGLES2Decoder>()); | 415 decoder_.reset(new ::testing::StrictMock<gles2::MockGLES2Decoder>()); |
419 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>()); | 416 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>()); |
420 manager_->CreateTexture(kClient1Id, kService1Id); | 417 manager_->CreateTexture(kClient1Id, kService1Id); |
421 texture_ref_ = manager_->GetTexture(kClient1Id); | 418 texture_ref_ = manager_->GetTexture(kClient1Id); |
422 ASSERT_TRUE(texture_ref_.get() != NULL); | 419 ASSERT_TRUE(texture_ref_.get() != NULL); |
423 } | 420 } |
424 | 421 |
425 virtual void TearDown() { | 422 void TearDown() override { |
426 if (texture_ref_.get()) { | 423 if (texture_ref_.get()) { |
427 // If it's not in the manager then setting texture_ref_ to NULL will | 424 // If it's not in the manager then setting texture_ref_ to NULL will |
428 // delete the texture. | 425 // delete the texture. |
429 if (!texture_ref_->client_id()) { | 426 if (!texture_ref_->client_id()) { |
430 // Check that it gets deleted when the last reference is released. | 427 // Check that it gets deleted when the last reference is released. |
431 EXPECT_CALL(*gl_, | 428 EXPECT_CALL(*gl_, |
432 DeleteTextures(1, ::testing::Pointee(texture_ref_->service_id()))) | 429 DeleteTextures(1, ::testing::Pointee(texture_ref_->service_id()))) |
433 .Times(1) | 430 .Times(1) |
434 .RetiresOnSaturation(); | 431 .RetiresOnSaturation(); |
435 } | 432 } |
(...skipping 13 matching lines...) Expand all Loading... |
449 | 446 |
450 scoped_ptr<MockGLES2Decoder> decoder_; | 447 scoped_ptr<MockGLES2Decoder> decoder_; |
451 scoped_ptr<MockErrorState> error_state_; | 448 scoped_ptr<MockErrorState> error_state_; |
452 scoped_refptr<FeatureInfo> feature_info_; | 449 scoped_refptr<FeatureInfo> feature_info_; |
453 scoped_ptr<TextureManager> manager_; | 450 scoped_ptr<TextureManager> manager_; |
454 scoped_refptr<TextureRef> texture_ref_; | 451 scoped_refptr<TextureRef> texture_ref_; |
455 }; | 452 }; |
456 | 453 |
457 class TextureTest : public TextureTestBase { | 454 class TextureTest : public TextureTestBase { |
458 protected: | 455 protected: |
459 virtual void SetUp() { | 456 void SetUp() override { SetUpBase(NULL, std::string()); } |
460 SetUpBase(NULL, std::string()); | |
461 } | |
462 }; | 457 }; |
463 | 458 |
464 class TextureMemoryTrackerTest : public TextureTestBase { | 459 class TextureMemoryTrackerTest : public TextureTestBase { |
465 protected: | 460 protected: |
466 virtual void SetUp() { | 461 void SetUp() override { |
467 mock_memory_tracker_ = new StrictMock<MockMemoryTracker>(); | 462 mock_memory_tracker_ = new StrictMock<MockMemoryTracker>(); |
468 SetUpBase(mock_memory_tracker_.get(), std::string()); | 463 SetUpBase(mock_memory_tracker_.get(), std::string()); |
469 } | 464 } |
470 | 465 |
471 scoped_refptr<MockMemoryTracker> mock_memory_tracker_; | 466 scoped_refptr<MockMemoryTracker> mock_memory_tracker_; |
472 }; | 467 }; |
473 | 468 |
474 #define EXPECT_MEMORY_ALLOCATION_CHANGE(old_size, new_size, pool) \ | 469 #define EXPECT_MEMORY_ALLOCATION_CHANGE(old_size, new_size, pool) \ |
475 EXPECT_CALL(*mock_memory_tracker_.get(), \ | 470 EXPECT_CALL(*mock_memory_tracker_.get(), \ |
476 TrackMemoryAllocatedChange(old_size, new_size, pool)) \ | 471 TrackMemoryAllocatedChange(old_size, new_size, pool)) \ |
(...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1864 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2); | 1859 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2); |
1865 EXPECT_EQ(signature1, signature2); | 1860 EXPECT_EQ(signature1, signature2); |
1866 | 1861 |
1867 // Check the set was acutally getting different signatures. | 1862 // Check the set was acutally getting different signatures. |
1868 EXPECT_EQ(11u, string_set.size()); | 1863 EXPECT_EQ(11u, string_set.size()); |
1869 } | 1864 } |
1870 | 1865 |
1871 class ProduceConsumeTextureTest : public TextureTest, | 1866 class ProduceConsumeTextureTest : public TextureTest, |
1872 public ::testing::WithParamInterface<GLenum> { | 1867 public ::testing::WithParamInterface<GLenum> { |
1873 public: | 1868 public: |
1874 virtual void SetUp() { | 1869 void SetUp() override { |
1875 TextureTest::SetUpBase(NULL, "GL_OES_EGL_image_external"); | 1870 TextureTest::SetUpBase(NULL, "GL_OES_EGL_image_external"); |
1876 manager_->CreateTexture(kClient2Id, kService2Id); | 1871 manager_->CreateTexture(kClient2Id, kService2Id); |
1877 texture2_ = manager_->GetTexture(kClient2Id); | 1872 texture2_ = manager_->GetTexture(kClient2Id); |
1878 | 1873 |
1879 EXPECT_CALL(*decoder_.get(), GetErrorState()) | 1874 EXPECT_CALL(*decoder_.get(), GetErrorState()) |
1880 .WillRepeatedly(Return(error_state_.get())); | 1875 .WillRepeatedly(Return(error_state_.get())); |
1881 } | 1876 } |
1882 | 1877 |
1883 virtual void TearDown() { | 1878 void TearDown() override { |
1884 if (texture2_.get()) { | 1879 if (texture2_.get()) { |
1885 // If it's not in the manager then setting texture2_ to NULL will | 1880 // If it's not in the manager then setting texture2_ to NULL will |
1886 // delete the texture. | 1881 // delete the texture. |
1887 if (!texture2_->client_id()) { | 1882 if (!texture2_->client_id()) { |
1888 // Check that it gets deleted when the last reference is released. | 1883 // Check that it gets deleted when the last reference is released. |
1889 EXPECT_CALL( | 1884 EXPECT_CALL( |
1890 *gl_, | 1885 *gl_, |
1891 DeleteTextures(1, ::testing::Pointee(texture2_->service_id()))) | 1886 DeleteTextures(1, ::testing::Pointee(texture2_->service_id()))) |
1892 .Times(1).RetiresOnSaturation(); | 1887 .Times(1).RetiresOnSaturation(); |
1893 } | 1888 } |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2187 size_t current_size_[2]; | 2182 size_t current_size_[2]; |
2188 DISALLOW_COPY_AND_ASSIGN(CountingMemoryTracker); | 2183 DISALLOW_COPY_AND_ASSIGN(CountingMemoryTracker); |
2189 }; | 2184 }; |
2190 | 2185 |
2191 class SharedTextureTest : public GpuServiceTest { | 2186 class SharedTextureTest : public GpuServiceTest { |
2192 public: | 2187 public: |
2193 static const bool kUseDefaultTextures = false; | 2188 static const bool kUseDefaultTextures = false; |
2194 | 2189 |
2195 SharedTextureTest() : feature_info_(new FeatureInfo()) {} | 2190 SharedTextureTest() : feature_info_(new FeatureInfo()) {} |
2196 | 2191 |
2197 virtual ~SharedTextureTest() { | 2192 ~SharedTextureTest() override {} |
2198 } | |
2199 | 2193 |
2200 virtual void SetUp() { | 2194 void SetUp() override { |
2201 GpuServiceTest::SetUp(); | 2195 GpuServiceTest::SetUp(); |
2202 memory_tracker1_ = new CountingMemoryTracker; | 2196 memory_tracker1_ = new CountingMemoryTracker; |
2203 texture_manager1_.reset( | 2197 texture_manager1_.reset( |
2204 new TextureManager(memory_tracker1_.get(), | 2198 new TextureManager(memory_tracker1_.get(), |
2205 feature_info_.get(), | 2199 feature_info_.get(), |
2206 TextureManagerTest::kMaxTextureSize, | 2200 TextureManagerTest::kMaxTextureSize, |
2207 TextureManagerTest::kMaxCubeMapTextureSize, | 2201 TextureManagerTest::kMaxCubeMapTextureSize, |
2208 kUseDefaultTextures)); | 2202 kUseDefaultTextures)); |
2209 memory_tracker2_ = new CountingMemoryTracker; | 2203 memory_tracker2_ = new CountingMemoryTracker; |
2210 texture_manager2_.reset( | 2204 texture_manager2_.reset( |
2211 new TextureManager(memory_tracker2_.get(), | 2205 new TextureManager(memory_tracker2_.get(), |
2212 feature_info_.get(), | 2206 feature_info_.get(), |
2213 TextureManagerTest::kMaxTextureSize, | 2207 TextureManagerTest::kMaxTextureSize, |
2214 TextureManagerTest::kMaxCubeMapTextureSize, | 2208 TextureManagerTest::kMaxCubeMapTextureSize, |
2215 kUseDefaultTextures)); | 2209 kUseDefaultTextures)); |
2216 TestHelper::SetupTextureManagerInitExpectations( | 2210 TestHelper::SetupTextureManagerInitExpectations( |
2217 gl_.get(), "", kUseDefaultTextures); | 2211 gl_.get(), "", kUseDefaultTextures); |
2218 texture_manager1_->Initialize(); | 2212 texture_manager1_->Initialize(); |
2219 TestHelper::SetupTextureManagerInitExpectations( | 2213 TestHelper::SetupTextureManagerInitExpectations( |
2220 gl_.get(), "", kUseDefaultTextures); | 2214 gl_.get(), "", kUseDefaultTextures); |
2221 texture_manager2_->Initialize(); | 2215 texture_manager2_->Initialize(); |
2222 } | 2216 } |
2223 | 2217 |
2224 virtual void TearDown() { | 2218 void TearDown() override { |
2225 texture_manager2_->Destroy(false); | 2219 texture_manager2_->Destroy(false); |
2226 texture_manager2_.reset(); | 2220 texture_manager2_.reset(); |
2227 texture_manager1_->Destroy(false); | 2221 texture_manager1_->Destroy(false); |
2228 texture_manager1_.reset(); | 2222 texture_manager1_.reset(); |
2229 GpuServiceTest::TearDown(); | 2223 GpuServiceTest::TearDown(); |
2230 } | 2224 } |
2231 | 2225 |
2232 protected: | 2226 protected: |
2233 scoped_refptr<FeatureInfo> feature_info_; | 2227 scoped_refptr<FeatureInfo> feature_info_; |
2234 scoped_refptr<CountingMemoryTracker> memory_tracker1_; | 2228 scoped_refptr<CountingMemoryTracker> memory_tracker1_; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2498 | 2492 |
2499 EXPECT_CALL(*gl_, DeleteTextures(1, _)) | 2493 EXPECT_CALL(*gl_, DeleteTextures(1, _)) |
2500 .Times(1) | 2494 .Times(1) |
2501 .RetiresOnSaturation(); | 2495 .RetiresOnSaturation(); |
2502 texture_manager1_->RemoveTexture(10); | 2496 texture_manager1_->RemoveTexture(10); |
2503 texture_manager2_->RemoveTexture(20); | 2497 texture_manager2_->RemoveTexture(20); |
2504 } | 2498 } |
2505 | 2499 |
2506 } // namespace gles2 | 2500 } // namespace gles2 |
2507 } // namespace gpu | 2501 } // namespace gpu |
OLD | NEW |