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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 if (!extensions.empty()) { | 376 if (!extensions.empty()) { |
376 TestHelper::SetupFeatureInfoInitExpectations(gl_.get(), | 377 TestHelper::SetupFeatureInfoInitExpectations(gl_.get(), |
377 extensions.c_str()); | 378 extensions.c_str()); |
378 feature_info_->Initialize(NULL); | 379 feature_info_->Initialize(NULL); |
379 } | 380 } |
380 | 381 |
381 manager_.reset(new TextureManager( | 382 manager_.reset(new TextureManager( |
382 memory_tracker, feature_info_.get(), | 383 memory_tracker, feature_info_.get(), |
383 kMaxTextureSize, kMaxCubeMapTextureSize)); | 384 kMaxTextureSize, kMaxCubeMapTextureSize)); |
384 decoder_.reset(new ::testing::StrictMock<gles2::MockGLES2Decoder>()); | 385 decoder_.reset(new ::testing::StrictMock<gles2::MockGLES2Decoder>()); |
| 386 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>()); |
385 manager_->CreateTexture(kClient1Id, kService1Id); | 387 manager_->CreateTexture(kClient1Id, kService1Id); |
386 texture_ = manager_->GetTexture(kClient1Id); | 388 texture_ = manager_->GetTexture(kClient1Id); |
387 ASSERT_TRUE(texture_.get() != NULL); | 389 ASSERT_TRUE(texture_.get() != NULL); |
388 } | 390 } |
389 | 391 |
390 virtual void TearDown() { | 392 virtual void TearDown() { |
391 if (texture_.get()) { | 393 if (texture_.get()) { |
392 GLuint client_id = 0; | 394 GLuint client_id = 0; |
393 // If it's not in the manager then setting texture_ to NULL will | 395 // If it's not in the manager then setting texture_ to NULL will |
394 // delete the texture. | 396 // delete the texture. |
395 if (!manager_->GetClientId(texture_->service_id(), &client_id)) { | 397 if (!manager_->GetClientId(texture_->service_id(), &client_id)) { |
396 // Check that it gets deleted when the last reference is released. | 398 // Check that it gets deleted when the last reference is released. |
397 EXPECT_CALL(*gl_, | 399 EXPECT_CALL(*gl_, |
398 DeleteTextures(1, ::testing::Pointee(texture_->service_id()))) | 400 DeleteTextures(1, ::testing::Pointee(texture_->service_id()))) |
399 .Times(1) | 401 .Times(1) |
400 .RetiresOnSaturation(); | 402 .RetiresOnSaturation(); |
401 } | 403 } |
402 texture_ = NULL; | 404 texture_ = NULL; |
403 } | 405 } |
404 manager_->Destroy(false); | 406 manager_->Destroy(false); |
405 manager_.reset(); | 407 manager_.reset(); |
406 ::gfx::GLInterface::SetGLInterface(NULL); | 408 ::gfx::GLInterface::SetGLInterface(NULL); |
407 gl_.reset(); | 409 gl_.reset(); |
408 } | 410 } |
409 | 411 |
410 void SetParameter( | 412 void SetParameter( |
411 Texture* texture, GLenum pname, GLint value, GLenum error) { | 413 Texture* texture, GLenum pname, GLint value, GLenum error) { |
412 TestHelper::SetTexParameterWithExpectations( | 414 TestHelper::SetTexParameterWithExpectations( |
413 gl_.get(), decoder_.get(), manager_.get(), | 415 gl_.get(), error_state_.get(), manager_.get(), |
414 texture, pname, value, error); | 416 texture, pname, value, error); |
415 } | 417 } |
416 | 418 |
| 419 scoped_ptr<MockGLES2Decoder> decoder_; |
| 420 scoped_ptr<MockErrorState> error_state_; |
417 // Use StrictMock to make 100% sure we know how GL will be called. | 421 // Use StrictMock to make 100% sure we know how GL will be called. |
418 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | 422 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
419 scoped_refptr<FeatureInfo> feature_info_; | 423 scoped_refptr<FeatureInfo> feature_info_; |
420 scoped_ptr<TextureManager> manager_; | 424 scoped_ptr<TextureManager> manager_; |
421 scoped_ptr<MockGLES2Decoder> decoder_; | |
422 scoped_refptr<Texture> texture_; | 425 scoped_refptr<Texture> texture_; |
423 }; | 426 }; |
424 | 427 |
425 class TextureTest : public TextureTestBase { | 428 class TextureTest : public TextureTestBase { |
426 protected: | 429 protected: |
427 virtual void SetUp() { | 430 virtual void SetUp() { |
428 SetUpBase(NULL, std::string()); | 431 SetUpBase(NULL, std::string()); |
429 } | 432 } |
430 }; | 433 }; |
431 | 434 |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 NULL, feature_info.get(), kMaxTextureSize, kMaxCubeMapTextureSize); | 848 NULL, feature_info.get(), kMaxTextureSize, kMaxCubeMapTextureSize); |
846 manager.CreateTexture(kClient1Id, kService1Id); | 849 manager.CreateTexture(kClient1Id, kService1Id); |
847 Texture* texture = manager.GetTexture(kClient1Id); | 850 Texture* texture = manager.GetTexture(kClient1Id); |
848 ASSERT_TRUE(texture != NULL); | 851 ASSERT_TRUE(texture != NULL); |
849 manager.SetTarget(texture, GL_TEXTURE_2D); | 852 manager.SetTarget(texture, GL_TEXTURE_2D); |
850 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target()); | 853 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target()); |
851 manager.SetLevelInfo(texture, | 854 manager.SetLevelInfo(texture, |
852 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_FLOAT, true); | 855 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_FLOAT, true); |
853 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); | 856 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); |
854 TestHelper::SetTexParameterWithExpectations( | 857 TestHelper::SetTexParameterWithExpectations( |
855 gl_.get(), decoder_.get(), &manager, | 858 gl_.get(), error_state_.get(), &manager, |
856 texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR); | 859 texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR); |
857 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); | 860 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); |
858 TestHelper::SetTexParameterWithExpectations( | 861 TestHelper::SetTexParameterWithExpectations( |
859 gl_.get(), decoder_.get(), &manager, | 862 gl_.get(), error_state_.get(), &manager, |
860 texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST, GL_NO_ERROR); | 863 texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST, GL_NO_ERROR); |
861 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture)); | 864 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture)); |
862 manager.Destroy(false); | 865 manager.Destroy(false); |
863 } | 866 } |
864 | 867 |
865 TEST_F(TextureTest, FloatLinear) { | 868 TEST_F(TextureTest, FloatLinear) { |
866 TestHelper::SetupFeatureInfoInitExpectations( | 869 TestHelper::SetupFeatureInfoInitExpectations( |
867 gl_.get(), "GL_OES_texture_float GL_OES_texture_float_linear"); | 870 gl_.get(), "GL_OES_texture_float GL_OES_texture_float_linear"); |
868 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo()); | 871 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo()); |
869 feature_info->Initialize(NULL); | 872 feature_info->Initialize(NULL); |
(...skipping 19 matching lines...) Expand all Loading... |
889 NULL, feature_info.get(), kMaxTextureSize, kMaxCubeMapTextureSize); | 892 NULL, feature_info.get(), kMaxTextureSize, kMaxCubeMapTextureSize); |
890 manager.CreateTexture(kClient1Id, kService1Id); | 893 manager.CreateTexture(kClient1Id, kService1Id); |
891 Texture* texture = manager.GetTexture(kClient1Id); | 894 Texture* texture = manager.GetTexture(kClient1Id); |
892 ASSERT_TRUE(texture != NULL); | 895 ASSERT_TRUE(texture != NULL); |
893 manager.SetTarget(texture, GL_TEXTURE_2D); | 896 manager.SetTarget(texture, GL_TEXTURE_2D); |
894 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target()); | 897 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target()); |
895 manager.SetLevelInfo(texture, | 898 manager.SetLevelInfo(texture, |
896 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_HALF_FLOAT_OES, true); | 899 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_HALF_FLOAT_OES, true); |
897 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); | 900 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); |
898 TestHelper::SetTexParameterWithExpectations( | 901 TestHelper::SetTexParameterWithExpectations( |
899 gl_.get(), decoder_.get(), &manager, | 902 gl_.get(), error_state_.get(), &manager, |
900 texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR); | 903 texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR); |
901 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); | 904 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture)); |
902 TestHelper::SetTexParameterWithExpectations( | 905 TestHelper::SetTexParameterWithExpectations( |
903 gl_.get(), decoder_.get(), &manager, | 906 gl_.get(), error_state_.get(), &manager, |
904 texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST, GL_NO_ERROR); | 907 texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST, GL_NO_ERROR); |
905 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture)); | 908 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture)); |
906 manager.Destroy(false); | 909 manager.Destroy(false); |
907 } | 910 } |
908 | 911 |
909 TEST_F(TextureTest, HalfFloatLinear) { | 912 TEST_F(TextureTest, HalfFloatLinear) { |
910 TestHelper::SetupFeatureInfoInitExpectations( | 913 TestHelper::SetupFeatureInfoInitExpectations( |
911 gl_.get(), "GL_OES_texture_half_float GL_OES_texture_half_float_linear"); | 914 gl_.get(), "GL_OES_texture_half_float GL_OES_texture_half_float_linear"); |
912 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo()); | 915 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo()); |
913 feature_info->Initialize(NULL); | 916 feature_info->Initialize(NULL); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 // Check the set was acutally getting different signatures. | 1289 // Check the set was acutally getting different signatures. |
1287 EXPECT_EQ(11u, string_set.size()); | 1290 EXPECT_EQ(11u, string_set.size()); |
1288 } | 1291 } |
1289 | 1292 |
1290 class SaveRestoreTextureTest : public TextureTest { | 1293 class SaveRestoreTextureTest : public TextureTest { |
1291 public: | 1294 public: |
1292 virtual void SetUp() { | 1295 virtual void SetUp() { |
1293 TextureTest::SetUpBase(NULL, "GL_OES_EGL_image_external"); | 1296 TextureTest::SetUpBase(NULL, "GL_OES_EGL_image_external"); |
1294 manager_->CreateTexture(kClient2Id, kService2Id); | 1297 manager_->CreateTexture(kClient2Id, kService2Id); |
1295 texture2_ = manager_->GetTexture(kClient2Id); | 1298 texture2_ = manager_->GetTexture(kClient2Id); |
| 1299 |
| 1300 EXPECT_CALL(*decoder_.get(), GetErrorState()) |
| 1301 .WillRepeatedly(Return(error_state_.get())); |
1296 } | 1302 } |
1297 | 1303 |
1298 virtual void TearDown() { | 1304 virtual void TearDown() { |
1299 if (texture2_.get()) { | 1305 if (texture2_.get()) { |
1300 GLuint client_id = 0; | 1306 GLuint client_id = 0; |
1301 // If it's not in the manager then setting texture2_ to NULL will | 1307 // If it's not in the manager then setting texture2_ to NULL will |
1302 // delete the texture. | 1308 // delete the texture. |
1303 if (!manager_->GetClientId(texture2_->service_id(), &client_id)) { | 1309 if (!manager_->GetClientId(texture2_->service_id(), &client_id)) { |
1304 // Check that it gets deleted when the last reference is released. | 1310 // Check that it gets deleted when the last reference is released. |
1305 EXPECT_CALL( | 1311 EXPECT_CALL( |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 EXPECT_EQ(face0, | 1527 EXPECT_EQ(face0, |
1522 GetLevelInfo(texture2_.get(), GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)); | 1528 GetLevelInfo(texture2_.get(), GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)); |
1523 EXPECT_EQ(face5, | 1529 EXPECT_EQ(face5, |
1524 GetLevelInfo(texture2_.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0)); | 1530 GetLevelInfo(texture2_.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0)); |
1525 } | 1531 } |
1526 | 1532 |
1527 } // namespace gles2 | 1533 } // namespace gles2 |
1528 } // namespace gpu | 1534 } // namespace gpu |
1529 | 1535 |
1530 | 1536 |
OLD | NEW |