| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
| 7 #include "app/gfx/gl/gl_mock.h" | 7 #include "app/gfx/gl/gl_mock.h" |
| 8 #include "gpu/GLES2/gles2_command_buffer.h" | 8 #include "gpu/GLES2/gles2_command_buffer.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "gpu/command_buffer/service/test_helper.h" |
| 10 | 11 |
| 11 using ::testing::Pointee; | 12 using ::testing::Pointee; |
| 13 using ::testing::_; |
| 12 | 14 |
| 13 namespace gpu { | 15 namespace gpu { |
| 14 namespace gles2 { | 16 namespace gles2 { |
| 15 | 17 |
| 16 class TextureManagerTest : public testing::Test { | 18 class TextureManagerTest : public testing::Test { |
| 17 public: | 19 public: |
| 18 static const GLint kMaxTextureSize = 16; | 20 static const GLint kMaxTextureSize = 16; |
| 19 static const GLint kMaxCubeMapTextureSize = 8; | 21 static const GLint kMaxCubeMapTextureSize = 8; |
| 20 static const GLint kMax2dLevels = 5; | 22 static const GLint kMax2dLevels = 5; |
| 21 static const GLint kMaxCubeMapLevels = 4; | 23 static const GLint kMaxCubeMapLevels = 4; |
| 22 | 24 |
| 25 static const GLuint kServiceBlackTexture2dId = 701; |
| 26 static const GLuint kServiceBlackTextureCubemapId = 702; |
| 27 static const GLuint kServiceDefaultTexture2dId = 703; |
| 28 static const GLuint kServiceDefaultTextureCubemapId = 704; |
| 29 |
| 30 |
| 23 TextureManagerTest() | 31 TextureManagerTest() |
| 24 : manager_(false, false, false, kMaxTextureSize, kMaxCubeMapTextureSize) { | 32 : manager_(false, false, false, kMaxTextureSize, kMaxCubeMapTextureSize) { |
| 25 } | 33 } |
| 26 | 34 |
| 27 ~TextureManagerTest() { | 35 ~TextureManagerTest() { |
| 28 manager_.Destroy(false); | 36 manager_.Destroy(false); |
| 29 } | 37 } |
| 30 | 38 |
| 31 protected: | 39 protected: |
| 32 virtual void SetUp() { | 40 virtual void SetUp() { |
| 33 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 41 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
| 34 ::gfx::GLInterface::SetGLInterface(gl_.get()); | 42 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
| 43 |
| 44 TestHelper::SetupTextureManagerInitExpectations(gl_.get()); |
| 45 manager_.Initialize(); |
| 35 } | 46 } |
| 36 | 47 |
| 37 virtual void TearDown() { | 48 virtual void TearDown() { |
| 38 ::gfx::GLInterface::SetGLInterface(NULL); | 49 ::gfx::GLInterface::SetGLInterface(NULL); |
| 39 gl_.reset(); | 50 gl_.reset(); |
| 40 } | 51 } |
| 41 | 52 |
| 42 // Use StrictMock to make 100% sure we know how GL will be called. | 53 // Use StrictMock to make 100% sure we know how GL will be called. |
| 43 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | 54 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
| 44 TextureManager manager_; | 55 TextureManager manager_; |
| 45 }; | 56 }; |
| 46 | 57 |
| 47 // GCC requires these declarations, but MSVC requires they not be present | 58 // GCC requires these declarations, but MSVC requires they not be present |
| 48 #ifndef COMPILER_MSVC | 59 #ifndef COMPILER_MSVC |
| 49 const GLint TextureManagerTest::kMaxTextureSize; | 60 const GLint TextureManagerTest::kMaxTextureSize; |
| 50 const GLint TextureManagerTest::kMaxCubeMapTextureSize; | 61 const GLint TextureManagerTest::kMaxCubeMapTextureSize; |
| 51 const GLint TextureManagerTest::kMax2dLevels; | 62 const GLint TextureManagerTest::kMax2dLevels; |
| 52 const GLint TextureManagerTest::kMaxCubeMapLevels; | 63 const GLint TextureManagerTest::kMaxCubeMapLevels; |
| 64 const GLuint TextureManagerTest::kServiceBlackTexture2dId; |
| 65 const GLuint TextureManagerTest::kServiceBlackTextureCubemapId; |
| 66 const GLuint TextureManagerTest::kServiceDefaultTexture2dId; |
| 67 const GLuint TextureManagerTest::kServiceDefaultTextureCubemapId; |
| 53 #endif | 68 #endif |
| 54 | 69 |
| 55 TEST_F(TextureManagerTest, Basic) { | 70 TEST_F(TextureManagerTest, Basic) { |
| 56 const GLuint kClient1Id = 1; | 71 const GLuint kClient1Id = 1; |
| 57 const GLuint kService1Id = 11; | 72 const GLuint kService1Id = 11; |
| 58 const GLuint kClient2Id = 2; | 73 const GLuint kClient2Id = 2; |
| 59 EXPECT_FALSE(manager_.HaveUnrenderableTextures()); | 74 EXPECT_FALSE(manager_.HaveUnrenderableTextures()); |
| 60 // Check we can create texture. | 75 // Check we can create texture. |
| 61 manager_.CreateTextureInfo(kClient1Id, kService1Id); | 76 manager_.CreateTextureInfo(kClient1Id, kService1Id); |
| 62 // Check texture got created. | 77 // Check texture got created. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 80 const GLuint kService1Id = 11; | 95 const GLuint kService1Id = 11; |
| 81 EXPECT_FALSE(manager_.HaveUnrenderableTextures()); | 96 EXPECT_FALSE(manager_.HaveUnrenderableTextures()); |
| 82 // Check we can create texture. | 97 // Check we can create texture. |
| 83 manager_.CreateTextureInfo(kClient1Id, kService1Id); | 98 manager_.CreateTextureInfo(kClient1Id, kService1Id); |
| 84 // Check texture got created. | 99 // Check texture got created. |
| 85 TextureManager::TextureInfo* info1 = manager_.GetTextureInfo(kClient1Id); | 100 TextureManager::TextureInfo* info1 = manager_.GetTextureInfo(kClient1Id); |
| 86 ASSERT_TRUE(info1 != NULL); | 101 ASSERT_TRUE(info1 != NULL); |
| 87 EXPECT_CALL(*gl_, DeleteTextures(1, ::testing::Pointee(kService1Id))) | 102 EXPECT_CALL(*gl_, DeleteTextures(1, ::testing::Pointee(kService1Id))) |
| 88 .Times(1) | 103 .Times(1) |
| 89 .RetiresOnSaturation(); | 104 .RetiresOnSaturation(); |
| 105 EXPECT_CALL(*gl_, DeleteTextures(4, _)) |
| 106 .Times(1) |
| 107 .RetiresOnSaturation(); |
| 90 manager_.Destroy(true); | 108 manager_.Destroy(true); |
| 91 // Check that resources got freed. | 109 // Check that resources got freed. |
| 92 info1 = manager_.GetTextureInfo(kClient1Id); | 110 info1 = manager_.GetTextureInfo(kClient1Id); |
| 93 ASSERT_TRUE(info1 == NULL); | 111 ASSERT_TRUE(info1 == NULL); |
| 94 } | 112 } |
| 95 | 113 |
| 96 TEST_F(TextureManagerTest, MaxValues) { | 114 TEST_F(TextureManagerTest, MaxValues) { |
| 97 // Check we get the right values for the max sizes. | 115 // Check we get the right values for the max sizes. |
| 98 EXPECT_EQ(kMax2dLevels, manager_.MaxLevelsForTarget(GL_TEXTURE_2D)); | 116 EXPECT_EQ(kMax2dLevels, manager_.MaxLevelsForTarget(GL_TEXTURE_2D)); |
| 99 EXPECT_EQ(kMaxCubeMapLevels, | 117 EXPECT_EQ(kMaxCubeMapLevels, |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 manager.SetLevelInfo(info, | 557 manager.SetLevelInfo(info, |
| 540 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_HALF_FLOAT_OES); | 558 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_HALF_FLOAT_OES); |
| 541 EXPECT_TRUE(info->texture_complete()); | 559 EXPECT_TRUE(info->texture_complete()); |
| 542 manager.Destroy(false); | 560 manager.Destroy(false); |
| 543 } | 561 } |
| 544 | 562 |
| 545 } // namespace gles2 | 563 } // namespace gles2 |
| 546 } // namespace gpu | 564 } // namespace gpu |
| 547 | 565 |
| 548 | 566 |
| OLD | NEW |