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/test_helper.h" | 5 #include "gpu/command_buffer/service/test_helper.h" |
6 | 6 |
7 #include "base/string_tokenizer.h" | 7 #include "base/string_tokenizer.h" |
8 #include "gpu/command_buffer/common/gl_mock.h" | 8 #include "gpu/command_buffer/common/gl_mock.h" |
9 #include "gpu/command_buffer/common/types.h" | 9 #include "gpu/command_buffer/common/types.h" |
10 #include "gpu/command_buffer/service/gl_utils.h" | 10 #include "gpu/command_buffer/service/gl_utils.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 using ::testing::SetArgumentPointee; | 22 using ::testing::SetArgumentPointee; |
23 using ::testing::StrEq; | 23 using ::testing::StrEq; |
24 using ::testing::StrictMock; | 24 using ::testing::StrictMock; |
25 | 25 |
26 namespace gpu { | 26 namespace gpu { |
27 namespace gles2 { | 27 namespace gles2 { |
28 | 28 |
29 // GCC requires these declarations, but MSVC requires they not be present | 29 // GCC requires these declarations, but MSVC requires they not be present |
30 #ifndef COMPILER_MSVC | 30 #ifndef COMPILER_MSVC |
31 const GLuint TestHelper::kServiceBlackTexture2dId; | 31 const GLuint TestHelper::kServiceBlackTexture2dId; |
| 32 const GLuint TestHelper::kServiceDefaultTexture2dId; |
32 const GLuint TestHelper::kServiceBlackTextureCubemapId; | 33 const GLuint TestHelper::kServiceBlackTextureCubemapId; |
33 const GLuint TestHelper::kServiceDefaultTexture2dId; | |
34 const GLuint TestHelper::kServiceDefaultTextureCubemapId; | 34 const GLuint TestHelper::kServiceDefaultTextureCubemapId; |
| 35 const GLuint TestHelper::kServiceBlackExternalTextureId; |
35 const GLuint TestHelper::kServiceDefaultExternalTextureId; | 36 const GLuint TestHelper::kServiceDefaultExternalTextureId; |
36 const GLuint TestHelper::kServiceBlackExternalTextureId; | 37 const GLuint TestHelper::kServiceBlackRectangleTextureId; |
| 38 const GLuint TestHelper::kServiceDefaultRectangleTextureId; |
37 | 39 |
38 const GLint TestHelper::kMaxSamples; | 40 const GLint TestHelper::kMaxSamples; |
39 const GLint TestHelper::kMaxRenderbufferSize; | 41 const GLint TestHelper::kMaxRenderbufferSize; |
40 const GLint TestHelper::kMaxTextureSize; | 42 const GLint TestHelper::kMaxTextureSize; |
41 const GLint TestHelper::kMaxCubeMapTextureSize; | 43 const GLint TestHelper::kMaxCubeMapTextureSize; |
42 const GLint TestHelper::kNumVertexAttribs; | 44 const GLint TestHelper::kNumVertexAttribs; |
43 const GLint TestHelper::kNumTextureUnits; | 45 const GLint TestHelper::kNumTextureUnits; |
44 const GLint TestHelper::kMaxTextureImageUnits; | 46 const GLint TestHelper::kMaxTextureImageUnits; |
45 const GLint TestHelper::kMaxVertexTextureImageUnits; | 47 const GLint TestHelper::kMaxVertexTextureImageUnits; |
46 const GLint TestHelper::kMaxFragmentUniformVectors; | 48 const GLint TestHelper::kMaxFragmentUniformVectors; |
47 const GLint TestHelper::kMaxFragmentUniformComponents; | 49 const GLint TestHelper::kMaxFragmentUniformComponents; |
48 const GLint TestHelper::kMaxVaryingVectors; | 50 const GLint TestHelper::kMaxVaryingVectors; |
49 const GLint TestHelper::kMaxVaryingFloats; | 51 const GLint TestHelper::kMaxVaryingFloats; |
50 const GLint TestHelper::kMaxVertexUniformVectors; | 52 const GLint TestHelper::kMaxVertexUniformVectors; |
51 const GLint TestHelper::kMaxVertexUniformComponents; | 53 const GLint TestHelper::kMaxVertexUniformComponents; |
52 #endif | 54 #endif |
53 | 55 |
| 56 void TestHelper::SetupTextureInitializationExpectations( |
| 57 ::gfx::MockGLInterface* gl, GLenum target) { |
| 58 InSequence sequence; |
| 59 |
| 60 bool needs_initialization = (target != GL_TEXTURE_EXTERNAL_OES); |
| 61 bool needs_faces = (target == GL_TEXTURE_CUBE_MAP); |
| 62 |
| 63 static GLuint texture_2d_ids[] = { |
| 64 kServiceBlackTexture2dId, |
| 65 kServiceDefaultTexture2dId }; |
| 66 static GLuint texture_cube_map_ids[] = { |
| 67 kServiceBlackTextureCubemapId, |
| 68 kServiceDefaultTextureCubemapId }; |
| 69 static GLuint texture_external_oes_ids[] = { |
| 70 kServiceBlackExternalTextureId, |
| 71 kServiceDefaultExternalTextureId }; |
| 72 static GLuint texture_rectangle_arb_ids[] = { |
| 73 kServiceBlackRectangleTextureId, |
| 74 kServiceDefaultRectangleTextureId }; |
| 75 |
| 76 const GLuint* texture_ids = NULL; |
| 77 switch (target) { |
| 78 case GL_TEXTURE_2D: |
| 79 texture_ids = &texture_2d_ids[0]; |
| 80 break; |
| 81 case GL_TEXTURE_CUBE_MAP: |
| 82 texture_ids = &texture_cube_map_ids[0]; |
| 83 break; |
| 84 case GL_TEXTURE_EXTERNAL_OES: |
| 85 texture_ids = &texture_external_oes_ids[0]; |
| 86 break; |
| 87 case GL_TEXTURE_RECTANGLE_ARB: |
| 88 texture_ids = &texture_rectangle_arb_ids[0]; |
| 89 break; |
| 90 default: |
| 91 NOTREACHED(); |
| 92 } |
| 93 |
| 94 int array_size = 2; |
| 95 |
| 96 EXPECT_CALL(*gl, GenTextures(array_size, _)) |
| 97 .WillOnce(SetArrayArgument<1>(texture_ids, |
| 98 texture_ids + array_size)) |
| 99 .RetiresOnSaturation(); |
| 100 for (int ii = 0; ii < array_size; ++ii) { |
| 101 EXPECT_CALL(*gl, BindTexture(target, texture_ids[ii])) |
| 102 .Times(1) |
| 103 .RetiresOnSaturation(); |
| 104 if (needs_initialization) { |
| 105 if (needs_faces) { |
| 106 static GLenum faces[] = { |
| 107 GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
| 108 GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
| 109 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
| 110 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, |
| 111 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, |
| 112 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, |
| 113 }; |
| 114 for (size_t ii = 0; ii < arraysize(faces); ++ii) { |
| 115 EXPECT_CALL(*gl, TexImage2D(faces[ii], 0, GL_RGBA, 1, 1, 0, GL_RGBA, |
| 116 GL_UNSIGNED_BYTE, _)) |
| 117 .Times(1) |
| 118 .RetiresOnSaturation(); |
| 119 } |
| 120 } else { |
| 121 EXPECT_CALL(*gl, TexImage2D(target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, |
| 122 GL_UNSIGNED_BYTE, _)) |
| 123 .Times(1) |
| 124 .RetiresOnSaturation(); |
| 125 } |
| 126 } |
| 127 } |
| 128 EXPECT_CALL(*gl, BindTexture(target, 0)) |
| 129 .Times(1) |
| 130 .RetiresOnSaturation(); |
| 131 } |
| 132 |
54 void TestHelper::SetupTextureManagerInitExpectations( | 133 void TestHelper::SetupTextureManagerInitExpectations( |
55 ::gfx::MockGLInterface* gl, | 134 ::gfx::MockGLInterface* gl, |
56 const char* extensions) { | 135 const char* extensions) { |
57 static GLuint texture_ids[] = { | 136 InSequence sequence; |
58 kServiceBlackTexture2dId, | 137 |
59 kServiceDefaultTexture2dId, | 138 SetupTextureInitializationExpectations(gl, GL_TEXTURE_2D); |
60 kServiceBlackTextureCubemapId, | 139 SetupTextureInitializationExpectations(gl, GL_TEXTURE_CUBE_MAP); |
61 kServiceDefaultTextureCubemapId, | |
62 }; | |
63 EXPECT_CALL(*gl, GenTextures(arraysize(texture_ids), _)) | |
64 .WillOnce(SetArrayArgument<1>(texture_ids, | |
65 texture_ids + arraysize(texture_ids))) | |
66 .RetiresOnSaturation(); | |
67 for (int ii = 0; ii < 2; ++ii) { | |
68 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_2D, texture_ids[ii])) | |
69 .Times(1) | |
70 .RetiresOnSaturation(); | |
71 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, | |
72 GL_UNSIGNED_BYTE, _)) | |
73 .Times(1) | |
74 .RetiresOnSaturation(); | |
75 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_CUBE_MAP, texture_ids[2 + ii])) | |
76 .Times(1) | |
77 .RetiresOnSaturation(); | |
78 static GLenum faces[] = { | |
79 GL_TEXTURE_CUBE_MAP_POSITIVE_X, | |
80 GL_TEXTURE_CUBE_MAP_NEGATIVE_X, | |
81 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, | |
82 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, | |
83 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, | |
84 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, | |
85 }; | |
86 for (size_t ii = 0; ii < arraysize(faces); ++ii) { | |
87 EXPECT_CALL(*gl, TexImage2D(faces[ii], 0, GL_RGBA, 1, 1, 0, GL_RGBA, | |
88 GL_UNSIGNED_BYTE, _)) | |
89 .Times(1) | |
90 .RetiresOnSaturation(); | |
91 } | |
92 } | |
93 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_2D, 0)) | |
94 .Times(1) | |
95 .RetiresOnSaturation(); | |
96 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_CUBE_MAP, 0)) | |
97 .Times(1) | |
98 .RetiresOnSaturation(); | |
99 | 140 |
100 bool ext_image_external = false; | 141 bool ext_image_external = false; |
| 142 bool arb_texture_rectangle = false; |
101 CStringTokenizer t(extensions, extensions + strlen(extensions), " "); | 143 CStringTokenizer t(extensions, extensions + strlen(extensions), " "); |
102 while (t.GetNext()) { | 144 while (t.GetNext()) { |
103 if (t.token() == "GL_OES_EGL_image_external") { | 145 if (t.token() == "GL_OES_EGL_image_external") { |
104 ext_image_external = true; | 146 ext_image_external = true; |
105 break; | 147 break; |
106 } | 148 } |
| 149 if (t.token() == "GL_ARB_texture_rectangle") { |
| 150 arb_texture_rectangle = true; |
| 151 break; |
| 152 } |
107 } | 153 } |
108 | 154 |
109 if (ext_image_external) { | 155 if (ext_image_external) { |
110 static GLuint external_texture_ids[] = { | 156 SetupTextureInitializationExpectations(gl, GL_TEXTURE_EXTERNAL_OES); |
111 kServiceDefaultExternalTextureId, | 157 } |
112 kServiceBlackExternalTextureId, | 158 if (arb_texture_rectangle) { |
113 }; | 159 SetupTextureInitializationExpectations(gl, GL_TEXTURE_RECTANGLE_ARB); |
114 EXPECT_CALL(*gl, GenTextures(arraysize(external_texture_ids), _)) | |
115 .WillOnce(SetArrayArgument<1>( | |
116 external_texture_ids, | |
117 external_texture_ids + arraysize(external_texture_ids))) | |
118 .RetiresOnSaturation(); | |
119 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_EXTERNAL_OES, 0)) | |
120 .Times(1) | |
121 .RetiresOnSaturation(); | |
122 } | 160 } |
123 } | 161 } |
124 | 162 |
125 void TestHelper::SetupContextGroupInitExpectations( | 163 void TestHelper::SetupContextGroupInitExpectations( |
126 ::gfx::MockGLInterface* gl, | 164 ::gfx::MockGLInterface* gl, |
127 const DisallowedFeatures& disallowed_features, | 165 const DisallowedFeatures& disallowed_features, |
128 const char* extensions) { | 166 const char* extensions) { |
129 InSequence sequence; | 167 InSequence sequence; |
130 | 168 |
131 SetupFeatureInfoInitExpectations(gl, extensions); | 169 SetupFeatureInfoInitExpectations(gl, extensions); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 InSequence sequence; | 219 InSequence sequence; |
182 | 220 |
183 EXPECT_CALL(*gl, GetString(GL_EXTENSIONS)) | 221 EXPECT_CALL(*gl, GetString(GL_EXTENSIONS)) |
184 .WillOnce(Return(reinterpret_cast<const uint8*>(extensions))) | 222 .WillOnce(Return(reinterpret_cast<const uint8*>(extensions))) |
185 .RetiresOnSaturation(); | 223 .RetiresOnSaturation(); |
186 } | 224 } |
187 | 225 |
188 } // namespace gles2 | 226 } // namespace gles2 |
189 } // namespace gpu | 227 } // namespace gpu |
190 | 228 |
OLD | NEW |