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/feature_info.h" | 9 #include "gpu/command_buffer/service/feature_info.h" |
9 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" | 10 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" |
10 #include "gpu/command_buffer/service/memory_tracking.h" | 11 #include "gpu/command_buffer/service/memory_tracking.h" |
11 #include "gpu/command_buffer/service/mocks.h" | 12 #include "gpu/command_buffer/service/mocks.h" |
12 #include "gpu/command_buffer/service/test_helper.h" | 13 #include "gpu/command_buffer/service/test_helper.h" |
13 #include "gpu/command_buffer/service/texture_definition.h" | 14 #include "gpu/command_buffer/service/texture_definition.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "ui/gl/gl_mock.h" | 16 #include "ui/gl/gl_mock.h" |
16 | 17 |
17 using ::testing::AtLeast; | 18 using ::testing::AtLeast; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 protected: | 57 protected: |
57 virtual void SetUp() { | 58 virtual void SetUp() { |
58 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 59 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
59 ::gfx::GLInterface::SetGLInterface(gl_.get()); | 60 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
60 | 61 |
61 manager_.reset(new TextureManager( | 62 manager_.reset(new TextureManager( |
62 NULL, feature_info_.get(), | 63 NULL, feature_info_.get(), |
63 kMaxTextureSize, kMaxCubeMapTextureSize)); | 64 kMaxTextureSize, kMaxCubeMapTextureSize)); |
64 TestHelper::SetupTextureManagerInitExpectations(gl_.get(), ""); | 65 TestHelper::SetupTextureManagerInitExpectations(gl_.get(), ""); |
65 manager_->Initialize(); | 66 manager_->Initialize(); |
66 decoder_.reset(new ::testing::StrictMock<gles2::MockGLES2Decoder>()); | 67 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>()); |
67 } | 68 } |
68 | 69 |
69 virtual void TearDown() { | 70 virtual void TearDown() { |
70 manager_->Destroy(false); | 71 manager_->Destroy(false); |
71 manager_.reset(); | 72 manager_.reset(); |
72 ::gfx::GLInterface::SetGLInterface(NULL); | 73 ::gfx::GLInterface::SetGLInterface(NULL); |
73 gl_.reset(); | 74 gl_.reset(); |
74 } | 75 } |
75 | 76 |
76 void SetParameter( | 77 void SetParameter( |
77 Texture* texture, GLenum pname, GLint value, GLenum error) { | 78 Texture* texture, GLenum pname, GLint value, GLenum error) { |
78 TestHelper::SetTexParameterWithExpectations( | 79 TestHelper::SetTexParameterWithExpectations( |
79 gl_.get(), decoder_.get(), manager_.get(), | 80 gl_.get(), error_state_.get(), manager_.get(), |
80 texture, pname, value, error); | 81 texture, pname, value, error); |
81 } | 82 } |
82 | 83 |
83 // Use StrictMock to make 100% sure we know how GL will be called. | 84 // Use StrictMock to make 100% sure we know how GL will be called. |
84 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | 85 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
85 scoped_refptr<FeatureInfo> feature_info_; | 86 scoped_refptr<FeatureInfo> feature_info_; |
86 scoped_ptr<TextureManager> manager_; | 87 scoped_ptr<TextureManager> manager_; |
87 scoped_ptr<MockGLES2Decoder> decoder_; | 88 scoped_ptr<MockErrorState> error_state_; |
88 }; | 89 }; |
89 | 90 |
90 // GCC requires these declarations, but MSVC requires they not be present | 91 // GCC requires these declarations, but MSVC requires they not be present |
91 #ifndef COMPILER_MSVC | 92 #ifndef COMPILER_MSVC |
92 const GLint TextureManagerTest::kMaxTextureSize; | 93 const GLint TextureManagerTest::kMaxTextureSize; |
93 const GLint TextureManagerTest::kMaxCubeMapTextureSize; | 94 const GLint TextureManagerTest::kMaxCubeMapTextureSize; |
94 const GLint TextureManagerTest::kMaxExternalTextureSize; | 95 const GLint TextureManagerTest::kMaxExternalTextureSize; |
95 const GLint TextureManagerTest::kMax2dLevels; | 96 const GLint TextureManagerTest::kMax2dLevels; |
96 const GLint TextureManagerTest::kMaxCubeMapLevels; | 97 const GLint TextureManagerTest::kMaxCubeMapLevels; |
97 const GLint TextureManagerTest::kMaxExternalLevels; | 98 const GLint TextureManagerTest::kMaxExternalLevels; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 NULL, feature_info_.get(), kMaxTextureSize, kMaxCubeMapTextureSize); | 166 NULL, feature_info_.get(), kMaxTextureSize, kMaxCubeMapTextureSize); |
166 manager.Initialize(); | 167 manager.Initialize(); |
167 const GLuint kClient1Id = 1; | 168 const GLuint kClient1Id = 1; |
168 const GLuint kService1Id = 11; | 169 const GLuint kService1Id = 11; |
169 // Check we can create texture. | 170 // Check we can create texture. |
170 manager.CreateTexture(kClient1Id, kService1Id); | 171 manager.CreateTexture(kClient1Id, kService1Id); |
171 // Check texture got created. | 172 // Check texture got created. |
172 Texture* texture = manager.GetTexture(kClient1Id); | 173 Texture* texture = manager.GetTexture(kClient1Id); |
173 ASSERT_TRUE(texture != NULL); | 174 ASSERT_TRUE(texture != NULL); |
174 TestHelper::SetTexParameterWithExpectations( | 175 TestHelper::SetTexParameterWithExpectations( |
175 gl_.get(), decoder_.get(), &manager, texture, | 176 gl_.get(), error_state_.get(), &manager, texture, |
176 GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE,GL_NO_ERROR); | 177 GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE,GL_NO_ERROR); |
177 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_ATTACHMENT_ANGLE), | 178 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_ATTACHMENT_ANGLE), |
178 texture->usage()); | 179 texture->usage()); |
179 manager.Destroy(false); | 180 manager.Destroy(false); |
180 } | 181 } |
181 | 182 |
182 TEST_F(TextureManagerTest, Destroy) { | 183 TEST_F(TextureManagerTest, Destroy) { |
183 const GLuint kClient1Id = 1; | 184 const GLuint kClient1Id = 1; |
184 const GLuint kService1Id = 11; | 185 const GLuint kService1Id = 11; |
185 TestHelper::SetupTextureManagerInitExpectations(gl_.get(), ""); | 186 TestHelper::SetupTextureManagerInitExpectations(gl_.get(), ""); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 } | 369 } |
369 | 370 |
370 protected: | 371 protected: |
371 void SetUpBase(MemoryTracker* memory_tracker) { | 372 void SetUpBase(MemoryTracker* memory_tracker) { |
372 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 373 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
373 ::gfx::GLInterface::SetGLInterface(gl_.get()); | 374 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
374 manager_.reset(new TextureManager( | 375 manager_.reset(new TextureManager( |
375 memory_tracker, feature_info_.get(), | 376 memory_tracker, feature_info_.get(), |
376 kMaxTextureSize, kMaxCubeMapTextureSize)); | 377 kMaxTextureSize, kMaxCubeMapTextureSize)); |
377 decoder_.reset(new ::testing::StrictMock<gles2::MockGLES2Decoder>()); | 378 decoder_.reset(new ::testing::StrictMock<gles2::MockGLES2Decoder>()); |
| 379 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>()); |
378 manager_->CreateTexture(kClient1Id, kService1Id); | 380 manager_->CreateTexture(kClient1Id, kService1Id); |
379 texture_ = manager_->GetTexture(kClient1Id); | 381 texture_ = manager_->GetTexture(kClient1Id); |
380 ASSERT_TRUE(texture_.get() != NULL); | 382 ASSERT_TRUE(texture_.get() != NULL); |
381 } | 383 } |
382 | 384 |
383 virtual void TearDown() { | 385 virtual void TearDown() { |
384 if (texture_.get()) { | 386 if (texture_.get()) { |
385 GLuint client_id = 0; | 387 GLuint client_id = 0; |
386 // If it's not in the manager then setting texture_ to NULL will | 388 // If it's not in the manager then setting texture_ to NULL will |
387 // delete the texture. | 389 // delete the texture. |
388 if (!manager_->GetClientId(texture_->service_id(), &client_id)) { | 390 if (!manager_->GetClientId(texture_->service_id(), &client_id)) { |
389 // Check that it gets deleted when the last reference is released. | 391 // Check that it gets deleted when the last reference is released. |
390 EXPECT_CALL(*gl_, | 392 EXPECT_CALL(*gl_, |
391 DeleteTextures(1, ::testing::Pointee(texture_->service_id()))) | 393 DeleteTextures(1, ::testing::Pointee(texture_->service_id()))) |
392 .Times(1) | 394 .Times(1) |
393 .RetiresOnSaturation(); | 395 .RetiresOnSaturation(); |
394 } | 396 } |
395 texture_ = NULL; | 397 texture_ = NULL; |
396 } | 398 } |
397 manager_->Destroy(false); | 399 manager_->Destroy(false); |
398 manager_.reset(); | 400 manager_.reset(); |
399 ::gfx::GLInterface::SetGLInterface(NULL); | 401 ::gfx::GLInterface::SetGLInterface(NULL); |
400 gl_.reset(); | 402 gl_.reset(); |
401 } | 403 } |
402 | 404 |
403 void SetParameter( | 405 void SetParameter( |
404 Texture* texture, GLenum pname, GLint value, GLenum error) { | 406 Texture* texture, GLenum pname, GLint value, GLenum error) { |
405 TestHelper::SetTexParameterWithExpectations( | 407 TestHelper::SetTexParameterWithExpectations( |
406 gl_.get(), decoder_.get(), manager_.get(), | 408 gl_.get(), error_state_.get(), manager_.get(), |
407 texture, pname, value, error); | 409 texture, pname, value, error); |
408 } | 410 } |
409 | 411 |
| 412 scoped_ptr<MockGLES2Decoder> decoder_; |
| 413 scoped_ptr<MockErrorState> error_state_; |
410 // Use StrictMock to make 100% sure we know how GL will be called. | 414 // Use StrictMock to make 100% sure we know how GL will be called. |
411 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | 415 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
412 scoped_refptr<FeatureInfo> feature_info_; | 416 scoped_refptr<FeatureInfo> feature_info_; |
413 scoped_ptr<TextureManager> manager_; | 417 scoped_ptr<TextureManager> manager_; |
414 scoped_ptr<MockGLES2Decoder> decoder_; | |
415 scoped_refptr<Texture> texture_; | 418 scoped_refptr<Texture> texture_; |
416 }; | 419 }; |
417 | 420 |
418 class TextureTest : public TextureTestBase { | 421 class TextureTest : public TextureTestBase { |
419 protected: | 422 protected: |
420 virtual void SetUp() { | 423 virtual void SetUp() { |
421 SetUpBase(NULL); | 424 SetUpBase(NULL); |
422 } | 425 } |
423 }; | 426 }; |
424 | 427 |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 NULL, feature_info.get(), kMaxTextureSize, kMaxCubeMapTextureSize); | 841 NULL, feature_info.get(), kMaxTextureSize, kMaxCubeMapTextureSize); |
839 manager.CreateTexture(kClient1Id, kService1Id); | 842 manager.CreateTexture(kClient1Id, kService1Id); |
840 Texture* texture = manager.GetTexture(kClient1Id); | 843 Texture* texture = manager.GetTexture(kClient1Id); |
841 ASSERT_TRUE(texture != NULL); | 844 ASSERT_TRUE(texture != NULL); |
842 manager.SetTarget(texture, GL_TEXTURE_2D); | 845 manager.SetTarget(texture, GL_TEXTURE_2D); |
843 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target()); | 846 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target()); |
844 manager.SetLevelInfo(texture, | 847 manager.SetLevelInfo(texture, |
845 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_FLOAT, true); | 848 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_FLOAT, true); |
846 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); | 849 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); |
847 TestHelper::SetTexParameterWithExpectations( | 850 TestHelper::SetTexParameterWithExpectations( |
848 gl_.get(), decoder_.get(), &manager, | 851 gl_.get(), error_state_.get(), &manager, |
849 texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR); | 852 texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR); |
850 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); | 853 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); |
851 TestHelper::SetTexParameterWithExpectations( | 854 TestHelper::SetTexParameterWithExpectations( |
852 gl_.get(), decoder_.get(), &manager, | 855 gl_.get(), error_state_.get(), &manager, |
853 texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST, GL_NO_ERROR); | 856 texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST, GL_NO_ERROR); |
854 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture)); | 857 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture)); |
855 manager.Destroy(false); | 858 manager.Destroy(false); |
856 } | 859 } |
857 | 860 |
858 TEST_F(TextureTest, FloatLinear) { | 861 TEST_F(TextureTest, FloatLinear) { |
859 TestHelper::SetupFeatureInfoInitExpectations( | 862 TestHelper::SetupFeatureInfoInitExpectations( |
860 gl_.get(), "GL_OES_texture_float GL_OES_texture_float_linear"); | 863 gl_.get(), "GL_OES_texture_float GL_OES_texture_float_linear"); |
861 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo()); | 864 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo()); |
862 feature_info->Initialize(NULL); | 865 feature_info->Initialize(NULL); |
(...skipping 19 matching lines...) Expand all Loading... |
882 NULL, feature_info.get(), kMaxTextureSize, kMaxCubeMapTextureSize); | 885 NULL, feature_info.get(), kMaxTextureSize, kMaxCubeMapTextureSize); |
883 manager.CreateTexture(kClient1Id, kService1Id); | 886 manager.CreateTexture(kClient1Id, kService1Id); |
884 Texture* texture = manager.GetTexture(kClient1Id); | 887 Texture* texture = manager.GetTexture(kClient1Id); |
885 ASSERT_TRUE(texture != NULL); | 888 ASSERT_TRUE(texture != NULL); |
886 manager.SetTarget(texture, GL_TEXTURE_2D); | 889 manager.SetTarget(texture, GL_TEXTURE_2D); |
887 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target()); | 890 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target()); |
888 manager.SetLevelInfo(texture, | 891 manager.SetLevelInfo(texture, |
889 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_HALF_FLOAT_OES, true); | 892 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_HALF_FLOAT_OES, true); |
890 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); | 893 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); |
891 TestHelper::SetTexParameterWithExpectations( | 894 TestHelper::SetTexParameterWithExpectations( |
892 gl_.get(), decoder_.get(), &manager, | 895 gl_.get(), error_state_.get(), &manager, |
893 texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR); | 896 texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR); |
894 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); | 897 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); |
895 TestHelper::SetTexParameterWithExpectations( | 898 TestHelper::SetTexParameterWithExpectations( |
896 gl_.get(), decoder_.get(), &manager, | 899 gl_.get(), error_state_.get(), &manager, |
897 texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST, GL_NO_ERROR); | 900 texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST, GL_NO_ERROR); |
898 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture)); | 901 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture)); |
899 manager.Destroy(false); | 902 manager.Destroy(false); |
900 } | 903 } |
901 | 904 |
902 TEST_F(TextureTest, HalfFloatLinear) { | 905 TEST_F(TextureTest, HalfFloatLinear) { |
903 TestHelper::SetupFeatureInfoInitExpectations( | 906 TestHelper::SetupFeatureInfoInitExpectations( |
904 gl_.get(), "GL_OES_texture_half_float GL_OES_texture_half_float_linear"); | 907 gl_.get(), "GL_OES_texture_half_float GL_OES_texture_half_float_linear"); |
905 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo()); | 908 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo()); |
906 feature_info->Initialize(NULL); | 909 feature_info->Initialize(NULL); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 // Check the set was acutally getting different signatures. | 1282 // Check the set was acutally getting different signatures. |
1280 EXPECT_EQ(11u, string_set.size()); | 1283 EXPECT_EQ(11u, string_set.size()); |
1281 } | 1284 } |
1282 | 1285 |
1283 class SaveRestoreTextureTest : public TextureTest { | 1286 class SaveRestoreTextureTest : public TextureTest { |
1284 public: | 1287 public: |
1285 virtual void SetUp() { | 1288 virtual void SetUp() { |
1286 TextureTest::SetUp(); | 1289 TextureTest::SetUp(); |
1287 manager_->CreateTexture(kClient2Id, kService2Id); | 1290 manager_->CreateTexture(kClient2Id, kService2Id); |
1288 texture2_ = manager_->GetTexture(kClient2Id); | 1291 texture2_ = manager_->GetTexture(kClient2Id); |
| 1292 |
| 1293 EXPECT_CALL(*decoder_.get(), GetErrorState()) |
| 1294 .WillRepeatedly(Return(error_state_.get())); |
1289 } | 1295 } |
1290 | 1296 |
1291 virtual void TearDown() { | 1297 virtual void TearDown() { |
1292 if (texture2_.get()) { | 1298 if (texture2_.get()) { |
1293 GLuint client_id = 0; | 1299 GLuint client_id = 0; |
1294 // If it's not in the manager then setting texture2_ to NULL will | 1300 // If it's not in the manager then setting texture2_ to NULL will |
1295 // delete the texture. | 1301 // delete the texture. |
1296 if (!manager_->GetClientId(texture2_->service_id(), &client_id)) { | 1302 if (!manager_->GetClientId(texture2_->service_id(), &client_id)) { |
1297 // Check that it gets deleted when the last reference is released. | 1303 // Check that it gets deleted when the last reference is released. |
1298 EXPECT_CALL( | 1304 EXPECT_CALL( |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 EXPECT_EQ(face0, | 1506 EXPECT_EQ(face0, |
1501 GetLevelInfo(texture2_.get(), GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)); | 1507 GetLevelInfo(texture2_.get(), GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)); |
1502 EXPECT_EQ(face5, | 1508 EXPECT_EQ(face5, |
1503 GetLevelInfo(texture2_.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0)); | 1509 GetLevelInfo(texture2_.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0)); |
1504 } | 1510 } |
1505 | 1511 |
1506 } // namespace gles2 | 1512 } // namespace gles2 |
1507 } // namespace gpu | 1513 } // namespace gpu |
1508 | 1514 |
1509 | 1515 |
OLD | NEW |