OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/GLES2/gles2_command_buffer.h" | 8 #include "gpu/GLES2/gles2_command_buffer.h" |
9 #include "gpu/command_buffer/common/gl_mock.h" | 9 #include "gpu/command_buffer/common/gl_mock.h" |
10 #include "gpu/command_buffer/service/feature_info.h" | 10 #include "gpu/command_buffer/service/feature_info.h" |
11 #include "gpu/command_buffer/service/test_helper.h" | 11 #include "gpu/command_buffer/service/test_helper.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 using ::testing::Pointee; | 14 using ::testing::Pointee; |
15 using ::testing::_; | 15 using ::testing::_; |
16 | 16 |
17 namespace gpu { | 17 namespace gpu { |
18 namespace gles2 { | 18 namespace gles2 { |
19 | 19 |
20 class TextureManagerTest : public testing::Test { | 20 class TextureManagerTest : public testing::Test { |
21 public: | 21 public: |
22 static const GLint kMaxTextureSize = 16; | 22 static const GLint kMaxTextureSize = 16; |
23 static const GLint kMaxCubeMapTextureSize = 8; | 23 static const GLint kMaxCubeMapTextureSize = 8; |
| 24 static const GLint kMaxExternalTextureSize = 16; |
24 static const GLint kMax2dLevels = 5; | 25 static const GLint kMax2dLevels = 5; |
25 static const GLint kMaxCubeMapLevels = 4; | 26 static const GLint kMaxCubeMapLevels = 4; |
| 27 static const GLint kMaxExternalLevels = 1; |
26 | 28 |
27 static const GLuint kServiceBlackTexture2dId = 701; | 29 static const GLuint kServiceBlackTexture2dId = 701; |
28 static const GLuint kServiceBlackTextureCubemapId = 702; | 30 static const GLuint kServiceBlackTextureCubemapId = 702; |
29 static const GLuint kServiceDefaultTexture2dId = 703; | 31 static const GLuint kServiceDefaultTexture2dId = 703; |
30 static const GLuint kServiceDefaultTextureCubemapId = 704; | 32 static const GLuint kServiceDefaultTextureCubemapId = 704; |
31 | 33 |
32 | 34 |
33 TextureManagerTest() | 35 TextureManagerTest() |
34 : manager_(kMaxTextureSize, kMaxCubeMapTextureSize) { | 36 : manager_(kMaxTextureSize, kMaxCubeMapTextureSize) { |
35 } | 37 } |
36 | 38 |
37 ~TextureManagerTest() { | 39 ~TextureManagerTest() { |
38 manager_.Destroy(false); | 40 manager_.Destroy(false); |
39 } | 41 } |
40 | 42 |
41 protected: | 43 protected: |
42 virtual void SetUp() { | 44 virtual void SetUp() { |
43 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 45 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
44 ::gfx::GLInterface::SetGLInterface(gl_.get()); | 46 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
45 | 47 |
46 TestHelper::SetupTextureManagerInitExpectations(gl_.get()); | 48 TestHelper::SetupTextureManagerInitExpectations(gl_.get(), ""); |
47 manager_.Initialize(); | 49 manager_.Initialize(&feature_info_); |
48 } | 50 } |
49 | 51 |
50 virtual void TearDown() { | 52 virtual void TearDown() { |
51 ::gfx::GLInterface::SetGLInterface(NULL); | 53 ::gfx::GLInterface::SetGLInterface(NULL); |
52 gl_.reset(); | 54 gl_.reset(); |
53 } | 55 } |
54 | 56 |
55 // Use StrictMock to make 100% sure we know how GL will be called. | 57 // Use StrictMock to make 100% sure we know how GL will be called. |
56 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | 58 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
57 TextureManager manager_; | 59 TextureManager manager_; |
58 FeatureInfo feature_info_; | 60 FeatureInfo feature_info_; |
59 }; | 61 }; |
60 | 62 |
61 // GCC requires these declarations, but MSVC requires they not be present | 63 // GCC requires these declarations, but MSVC requires they not be present |
62 #ifndef COMPILER_MSVC | 64 #ifndef COMPILER_MSVC |
63 const GLint TextureManagerTest::kMaxTextureSize; | 65 const GLint TextureManagerTest::kMaxTextureSize; |
64 const GLint TextureManagerTest::kMaxCubeMapTextureSize; | 66 const GLint TextureManagerTest::kMaxCubeMapTextureSize; |
| 67 const GLint TextureManagerTest::kMaxExternalTextureSize; |
65 const GLint TextureManagerTest::kMax2dLevels; | 68 const GLint TextureManagerTest::kMax2dLevels; |
66 const GLint TextureManagerTest::kMaxCubeMapLevels; | 69 const GLint TextureManagerTest::kMaxCubeMapLevels; |
| 70 const GLint TextureManagerTest::kMaxExternalLevels; |
67 const GLuint TextureManagerTest::kServiceBlackTexture2dId; | 71 const GLuint TextureManagerTest::kServiceBlackTexture2dId; |
68 const GLuint TextureManagerTest::kServiceBlackTextureCubemapId; | 72 const GLuint TextureManagerTest::kServiceBlackTextureCubemapId; |
69 const GLuint TextureManagerTest::kServiceDefaultTexture2dId; | 73 const GLuint TextureManagerTest::kServiceDefaultTexture2dId; |
70 const GLuint TextureManagerTest::kServiceDefaultTextureCubemapId; | 74 const GLuint TextureManagerTest::kServiceDefaultTextureCubemapId; |
71 #endif | 75 #endif |
72 | 76 |
73 TEST_F(TextureManagerTest, Basic) { | 77 TEST_F(TextureManagerTest, Basic) { |
74 const GLuint kClient1Id = 1; | 78 const GLuint kClient1Id = 1; |
75 const GLuint kService1Id = 11; | 79 const GLuint kService1Id = 11; |
76 const GLuint kClient2Id = 2; | 80 const GLuint kClient2Id = 2; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 manager_.Destroy(true); | 173 manager_.Destroy(true); |
170 info1 = manager_.GetTextureInfo(kClient1Id); | 174 info1 = manager_.GetTextureInfo(kClient1Id); |
171 ASSERT_TRUE(info1 == NULL); | 175 ASSERT_TRUE(info1 == NULL); |
172 } | 176 } |
173 | 177 |
174 TEST_F(TextureManagerTest, MaxValues) { | 178 TEST_F(TextureManagerTest, MaxValues) { |
175 // Check we get the right values for the max sizes. | 179 // Check we get the right values for the max sizes. |
176 EXPECT_EQ(kMax2dLevels, manager_.MaxLevelsForTarget(GL_TEXTURE_2D)); | 180 EXPECT_EQ(kMax2dLevels, manager_.MaxLevelsForTarget(GL_TEXTURE_2D)); |
177 EXPECT_EQ(kMaxCubeMapLevels, | 181 EXPECT_EQ(kMaxCubeMapLevels, |
178 manager_.MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP)); | 182 manager_.MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP)); |
| 183 EXPECT_EQ(kMaxCubeMapLevels, |
| 184 manager_.MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_X)); |
| 185 EXPECT_EQ(kMaxCubeMapLevels, |
| 186 manager_.MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_X)); |
| 187 EXPECT_EQ(kMaxCubeMapLevels, |
| 188 manager_.MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_Y)); |
| 189 EXPECT_EQ(kMaxCubeMapLevels, |
| 190 manager_.MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y)); |
| 191 EXPECT_EQ(kMaxCubeMapLevels, |
| 192 manager_.MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_Z)); |
| 193 EXPECT_EQ(kMaxCubeMapLevels, |
| 194 manager_.MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)); |
| 195 EXPECT_EQ(kMaxExternalLevels, |
| 196 manager_.MaxLevelsForTarget(GL_TEXTURE_EXTERNAL_OES)); |
179 EXPECT_EQ(kMaxTextureSize, manager_.MaxSizeForTarget(GL_TEXTURE_2D)); | 197 EXPECT_EQ(kMaxTextureSize, manager_.MaxSizeForTarget(GL_TEXTURE_2D)); |
180 EXPECT_EQ(kMaxCubeMapTextureSize, | 198 EXPECT_EQ(kMaxCubeMapTextureSize, |
181 manager_.MaxSizeForTarget(GL_TEXTURE_CUBE_MAP)); | 199 manager_.MaxSizeForTarget(GL_TEXTURE_CUBE_MAP)); |
| 200 EXPECT_EQ(kMaxCubeMapTextureSize, |
| 201 manager_.MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_X)); |
| 202 EXPECT_EQ(kMaxCubeMapTextureSize, |
| 203 manager_.MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_X)); |
| 204 EXPECT_EQ(kMaxCubeMapTextureSize, |
| 205 manager_.MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_Y)); |
| 206 EXPECT_EQ(kMaxCubeMapTextureSize, |
| 207 manager_.MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y)); |
| 208 EXPECT_EQ(kMaxCubeMapTextureSize, |
| 209 manager_.MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_Z)); |
| 210 EXPECT_EQ(kMaxCubeMapTextureSize, |
| 211 manager_.MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)); |
| 212 EXPECT_EQ(kMaxExternalTextureSize, |
| 213 manager_.MaxSizeForTarget(GL_TEXTURE_EXTERNAL_OES)); |
182 } | 214 } |
183 | 215 |
184 TEST_F(TextureManagerTest, ValidForTarget) { | 216 TEST_F(TextureManagerTest, ValidForTarget) { |
185 // check 2d | 217 // check 2d |
186 EXPECT_TRUE(manager_.ValidForTarget( | 218 EXPECT_TRUE(manager_.ValidForTarget( |
187 &feature_info_, GL_TEXTURE_2D, 0, | 219 &feature_info_, GL_TEXTURE_2D, 0, |
188 kMaxTextureSize, kMaxTextureSize, 1)); | 220 kMaxTextureSize, kMaxTextureSize, 1)); |
189 EXPECT_TRUE(manager_.ValidForTarget( | 221 EXPECT_TRUE(manager_.ValidForTarget( |
190 &feature_info_, GL_TEXTURE_2D, kMax2dLevels - 1, | 222 &feature_info_, GL_TEXTURE_2D, kMax2dLevels - 1, |
191 kMaxTextureSize, kMaxTextureSize, 1)); | 223 kMaxTextureSize, kMaxTextureSize, 1)); |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 TextureManager::TextureInfo* info = manager_.GetTextureInfo(kClient1Id); | 675 TextureManager::TextureInfo* info = manager_.GetTextureInfo(kClient1Id); |
644 ASSERT_TRUE(info != NULL); | 676 ASSERT_TRUE(info != NULL); |
645 manager.SetInfoTarget(info, GL_TEXTURE_2D); | 677 manager.SetInfoTarget(info, GL_TEXTURE_2D); |
646 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), info->target()); | 678 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), info->target()); |
647 manager.SetLevelInfo(&feature_info, info, | 679 manager.SetLevelInfo(&feature_info, info, |
648 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_HALF_FLOAT_OES); | 680 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_HALF_FLOAT_OES); |
649 EXPECT_TRUE(info->texture_complete()); | 681 EXPECT_TRUE(info->texture_complete()); |
650 manager.Destroy(false); | 682 manager.Destroy(false); |
651 } | 683 } |
652 | 684 |
| 685 TEST_F(TextureInfoTest, EGLImageExternal) { |
| 686 TextureManager manager(kMaxTextureSize, kMaxCubeMapTextureSize); |
| 687 TestHelper::SetupFeatureInfoInitExpectations( |
| 688 gl_.get(), "GL_OES_EGL_image_external"); |
| 689 FeatureInfo feature_info; |
| 690 feature_info.Initialize(NULL); |
| 691 manager.CreateTextureInfo(&feature_info, kClient1Id, kService1Id); |
| 692 TextureManager::TextureInfo* info = manager_.GetTextureInfo(kClient1Id); |
| 693 ASSERT_TRUE(info != NULL); |
| 694 manager.SetInfoTarget(info, GL_TEXTURE_EXTERNAL_OES); |
| 695 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), info->target()); |
| 696 EXPECT_FALSE(info->CanGenerateMipmaps(&feature_info)); |
| 697 manager.Destroy(false); |
| 698 } |
| 699 |
653 } // namespace gles2 | 700 } // namespace gles2 |
654 } // namespace gpu | 701 } // namespace gpu |
655 | 702 |
656 | 703 |
OLD | NEW |