blob: 33f6a859f95c9375fb765d1369bb431fb1841cbc [file] [log] [blame]
Avi Drissman05dfbc822022-09-13 21:25:341// Copyright 2012 The Chromium Authors
gman@chromium.org00f893d2010-08-24 18:55:492// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "gpu/command_buffer/service/test_helper.h"
thakis@chromium.orga36c7b412010-10-14 21:17:066
avif15d60a2015-12-21 17:06:337#include <stddef.h>
8#include <stdint.h>
9
dmurph@chromium.org65dfc602012-07-23 20:39:3910#include <algorithm>
brettw@chromium.orgf4ebe772013-02-02 00:21:3911#include <string>
dmurph@chromium.org65dfc602012-07-23 20:39:3912
zmo@chromium.org185de2a2013-04-04 22:57:1113#include "base/strings/string_number_conversions.h"
Sunny Sachanandanieb4c2a92021-06-04 23:00:3814#include "build/build_config.h"
gman@chromium.org17cfbe0e2013-03-07 01:26:0815#include "gpu/command_buffer/service/buffer_manager.h"
kloveless@chromium.orgd3eba342013-04-18 21:11:5016#include "gpu/command_buffer/service/error_state_mock.h"
kkinnunenc8b449e1582015-11-02 07:57:5117#include "gpu/command_buffer/service/feature_info.h"
bulach@chromium.org61eeb33f2011-07-26 15:30:3118#include "gpu/command_buffer/service/gl_utils.h"
zmo@chromium.org185de2a2013-04-04 22:57:1119#include "gpu/command_buffer/service/gpu_switches.h"
zmo576a0492014-09-13 01:12:3220#include "gpu/command_buffer/service/mocks.h"
gman@chromium.org0abf43e32012-05-10 23:36:2321#include "gpu/command_buffer/service/program_manager.h"
gman@chromium.org02965c22013-03-09 02:40:0722#include "gpu/command_buffer/service/texture_manager.h"
gman@chromium.org00f893d2010-08-24 18:55:4923#include "testing/gtest/include/gtest/gtest.h"
gman@chromium.orge16b0252012-12-07 09:07:4924#include "ui/gl/gl_mock.h"
kbrc9f0e10c2015-03-31 19:49:1225#include "ui/gl/gl_version_info.h"
gman@chromium.org00f893d2010-08-24 18:55:4926
27using ::testing::_;
28using ::testing::DoAll;
29using ::testing::InSequence;
30using ::testing::MatcherCast;
31using ::testing::Pointee;
zmo576a0492014-09-13 01:12:3232using ::testing::NotNull;
gman@chromium.org00f893d2010-08-24 18:55:4933using ::testing::Return;
34using ::testing::SetArrayArgument;
thestige147d682017-05-05 07:31:3135using ::testing::SetArgPointee;
kainino803bcd7b2016-08-31 02:52:2936using ::testing::SetArgPointee;
gman@chromium.org00f893d2010-08-24 18:55:4937using ::testing::StrEq;
38using ::testing::StrictMock;
39
40namespace gpu {
41namespace gles2 {
42
zmo88043c082014-10-09 20:38:5543namespace {
44
45template<typename T>
46T ConstructShaderVariable(
47 GLenum type, GLint array_size, GLenum precision,
48 bool static_use, const std::string& name) {
49 T var;
50 var.type = type;
Olli Etuaho263298eb2017-10-19 20:06:1851 var.setArraySize(array_size);
zmo88043c082014-10-09 20:38:5552 var.precision = precision;
53 var.staticUse = static_use;
54 var.name = name;
55 var.mappedName = name; // No name hashing.
56 return var;
57}
58
59} // namespace anonymous
60
gman@chromium.org00f893d2010-08-24 18:55:4961// GCC requires these declarations, but MSVC requires they not be present
62#ifndef COMPILER_MSVC
63const GLuint TestHelper::kServiceBlackTexture2dId;
gman@chromium.org00f893d2010-08-24 18:55:4964const GLuint TestHelper::kServiceDefaultTexture2dId;
qiankun.miao4e2f0d02015-09-18 03:34:4865const GLuint TestHelper::kServiceBlackTexture3dId;
66const GLuint TestHelper::kServiceDefaultTexture3dId;
67const GLuint TestHelper::kServiceBlackTexture2dArrayId;
68const GLuint TestHelper::kServiceDefaultTexture2dArrayId;
kbr@chromium.orge51bdf32011-11-23 22:21:4669const GLuint TestHelper::kServiceBlackTextureCubemapId;
gman@chromium.org00f893d2010-08-24 18:55:4970const GLuint TestHelper::kServiceDefaultTextureCubemapId;
bulach@chromium.org61eeb33f2011-07-26 15:30:3171const GLuint TestHelper::kServiceBlackExternalTextureId;
kbr@chromium.orge51bdf32011-11-23 22:21:4672const GLuint TestHelper::kServiceDefaultExternalTextureId;
73const GLuint TestHelper::kServiceBlackRectangleTextureId;
74const GLuint TestHelper::kServiceDefaultRectangleTextureId;
gman@chromium.org00f893d2010-08-24 18:55:4975
gman@chromium.org84afefa2011-10-19 21:45:5376const GLint TestHelper::kMaxSamples;
gman@chromium.org5094b0f2010-11-09 19:45:2477const GLint TestHelper::kMaxRenderbufferSize;
gman@chromium.org00f893d2010-08-24 18:55:4978const GLint TestHelper::kMaxTextureSize;
79const GLint TestHelper::kMaxCubeMapTextureSize;
sandersd9d0bb832014-12-17 01:24:5580const GLint TestHelper::kMaxRectangleTextureSize;
zmoea06a6f2015-04-30 01:15:4681const GLint TestHelper::kMax3DTextureSize;
zmo9bdab5d2016-05-05 04:35:2782const GLint TestHelper::kMaxArrayTextureLayers;
gman@chromium.org00f893d2010-08-24 18:55:4983const GLint TestHelper::kNumVertexAttribs;
84const GLint TestHelper::kNumTextureUnits;
85const GLint TestHelper::kMaxTextureImageUnits;
86const GLint TestHelper::kMaxVertexTextureImageUnits;
87const GLint TestHelper::kMaxFragmentUniformVectors;
gman@chromium.org915a59a12010-09-30 21:29:1188const GLint TestHelper::kMaxFragmentUniformComponents;
gman@chromium.org00f893d2010-08-24 18:55:4989const GLint TestHelper::kMaxVaryingVectors;
gman@chromium.org915a59a12010-09-30 21:29:1190const GLint TestHelper::kMaxVaryingFloats;
gman@chromium.org00f893d2010-08-24 18:55:4991const GLint TestHelper::kMaxVertexUniformVectors;
gman@chromium.org915a59a12010-09-30 21:29:1192const GLint TestHelper::kMaxVertexUniformComponents;
cwalleze96e24b2016-03-15 00:18:4893const GLint TestHelper::kMaxVertexOutputComponents;
94const GLint TestHelper::kMaxFragmentInputComponents;
95const GLint TestHelper::kMaxProgramTexelOffset;
96const GLint TestHelper::kMinProgramTexelOffset;
zmo706399be2016-04-21 00:01:0897const GLint TestHelper::kMaxTransformFeedbackSeparateAttribs;
98const GLint TestHelper::kMaxUniformBufferBindings;
99const GLint TestHelper::kUniformBufferOffsetAlignment;
gman@chromium.org00f893d2010-08-24 18:55:49100#endif
101
kbrc9f0e10c2015-03-31 19:49:12102std::vector<std::string> TestHelper::split_extensions_;
103
kbr@chromium.orge51bdf32011-11-23 22:21:46104void TestHelper::SetupTextureInitializationExpectations(
kylechar7a463842016-05-26 14:46:12105 ::gl::MockGLInterface* gl,
vmiura@chromium.org5ebf59f2014-04-08 03:51:57106 GLenum target,
107 bool use_default_textures) {
kbr@chromium.orge51bdf32011-11-23 22:21:46108 InSequence sequence;
109
110 bool needs_initialization = (target != GL_TEXTURE_EXTERNAL_OES);
111 bool needs_faces = (target == GL_TEXTURE_CUBE_MAP);
qiankun.miao4e2f0d02015-09-18 03:34:48112 bool is_3d_or_2d_array_target = (target == GL_TEXTURE_3D ||
113 target == GL_TEXTURE_2D_ARRAY);
kbr@chromium.orge51bdf32011-11-23 22:21:46114
115 static GLuint texture_2d_ids[] = {
116 kServiceBlackTexture2dId,
117 kServiceDefaultTexture2dId };
qiankun.miao4e2f0d02015-09-18 03:34:48118 static GLuint texture_3d_ids[] = {
119 kServiceBlackTexture3dId,
120 kServiceDefaultTexture3dId };
121 static GLuint texture_2d_array_ids[] = {
122 kServiceBlackTexture2dArrayId,
123 kServiceDefaultTexture2dArrayId };
kbr@chromium.orge51bdf32011-11-23 22:21:46124 static GLuint texture_cube_map_ids[] = {
125 kServiceBlackTextureCubemapId,
126 kServiceDefaultTextureCubemapId };
127 static GLuint texture_external_oes_ids[] = {
128 kServiceBlackExternalTextureId,
129 kServiceDefaultExternalTextureId };
130 static GLuint texture_rectangle_arb_ids[] = {
131 kServiceBlackRectangleTextureId,
132 kServiceDefaultRectangleTextureId };
133
tzikddef02182018-08-14 07:08:33134 const GLuint* texture_ids = nullptr;
kbr@chromium.orge51bdf32011-11-23 22:21:46135 switch (target) {
136 case GL_TEXTURE_2D:
137 texture_ids = &texture_2d_ids[0];
138 break;
qiankun.miao4e2f0d02015-09-18 03:34:48139 case GL_TEXTURE_3D:
140 texture_ids = &texture_3d_ids[0];
141 break;
142 case GL_TEXTURE_2D_ARRAY:
143 texture_ids = &texture_2d_array_ids[0];
144 break;
kbr@chromium.orge51bdf32011-11-23 22:21:46145 case GL_TEXTURE_CUBE_MAP:
146 texture_ids = &texture_cube_map_ids[0];
147 break;
148 case GL_TEXTURE_EXTERNAL_OES:
149 texture_ids = &texture_external_oes_ids[0];
150 break;
151 case GL_TEXTURE_RECTANGLE_ARB:
152 texture_ids = &texture_rectangle_arb_ids[0];
153 break;
154 default:
155 NOTREACHED();
156 }
157
vmiura@chromium.org5ebf59f2014-04-08 03:51:57158 int array_size = use_default_textures ? 2 : 1;
kbr@chromium.orge51bdf32011-11-23 22:21:46159
160 EXPECT_CALL(*gl, GenTextures(array_size, _))
161 .WillOnce(SetArrayArgument<1>(texture_ids,
162 texture_ids + array_size))
163 .RetiresOnSaturation();
164 for (int ii = 0; ii < array_size; ++ii) {
165 EXPECT_CALL(*gl, BindTexture(target, texture_ids[ii]))
166 .Times(1)
167 .RetiresOnSaturation();
168 if (needs_initialization) {
169 if (needs_faces) {
170 static GLenum faces[] = {
171 GL_TEXTURE_CUBE_MAP_POSITIVE_X,
172 GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
173 GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
174 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
175 GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
176 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
177 };
Daniel Chengadafb3a2022-02-28 07:38:22178 for (size_t face = 0; face < std::size(faces); ++face) {
Peter Kasting905a2a92021-08-24 21:53:34179 EXPECT_CALL(*gl, TexImage2D(faces[face], 0, GL_RGBA, 1, 1, 0, GL_RGBA,
kbr@chromium.orge51bdf32011-11-23 22:21:46180 GL_UNSIGNED_BYTE, _))
181 .Times(1)
182 .RetiresOnSaturation();
183 }
184 } else {
qiankun.miao4e2f0d02015-09-18 03:34:48185 if (is_3d_or_2d_array_target) {
186 EXPECT_CALL(*gl, TexImage3D(target, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA,
187 GL_UNSIGNED_BYTE, _))
188 .Times(1)
189 .RetiresOnSaturation();
190 } else {
191 EXPECT_CALL(*gl, TexImage2D(target, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
192 GL_UNSIGNED_BYTE, _))
193 .Times(1)
194 .RetiresOnSaturation();
195 }
kbr@chromium.orge51bdf32011-11-23 22:21:46196 }
197 }
198 }
199 EXPECT_CALL(*gl, BindTexture(target, 0))
200 .Times(1)
201 .RetiresOnSaturation();
202}
203
gman@chromium.org00f893d2010-08-24 18:55:49204void TestHelper::SetupTextureManagerInitExpectations(
kylechar7a463842016-05-26 14:46:12205 ::gl::MockGLInterface* gl,
qiankun.miao4e2f0d02015-09-18 03:34:48206 bool is_es3_enabled,
qiankun.miao17ad0f1c2016-09-09 20:14:05207 bool is_es3_capable,
bajones2c9d7182016-03-11 18:16:28208 bool is_desktop_core_profile,
Michael Spangbe9d9eb2018-06-21 20:02:04209 const gfx::ExtensionSet& extensions,
vmiura@chromium.org5ebf59f2014-04-08 03:51:57210 bool use_default_textures) {
kbr@chromium.orge51bdf32011-11-23 22:21:46211 InSequence sequence;
212
qiankun.miao17ad0f1c2016-09-09 20:14:05213 if (is_es3_capable) {
214 EXPECT_CALL(*gl, BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0))
215 .Times(1)
216 .RetiresOnSaturation();
217 }
218
vmiura@chromium.org5ebf59f2014-04-08 03:51:57219 SetupTextureInitializationExpectations(
220 gl, GL_TEXTURE_2D, use_default_textures);
221 SetupTextureInitializationExpectations(
222 gl, GL_TEXTURE_CUBE_MAP, use_default_textures);
bulach@chromium.org61eeb33f2011-07-26 15:30:31223
qiankun.miao4e2f0d02015-09-18 03:34:48224 if (is_es3_enabled) {
225 SetupTextureInitializationExpectations(
226 gl, GL_TEXTURE_3D, use_default_textures);
227 SetupTextureInitializationExpectations(
228 gl, GL_TEXTURE_2D_ARRAY, use_default_textures);
229 }
230
Antoine Labour20d16202017-09-05 23:05:29231 bool ext_image_external =
Michael Spangbe9d9eb2018-06-21 20:02:04232 gfx::HasExtension(extensions, "GL_OES_EGL_image_external");
Antoine Labour20d16202017-09-05 23:05:29233 bool arb_texture_rectangle =
234 is_desktop_core_profile ||
Michael Spangbe9d9eb2018-06-21 20:02:04235 gfx::HasExtension(extensions, "GL_ARB_texture_rectangle");
bulach@chromium.org61eeb33f2011-07-26 15:30:31236
237 if (ext_image_external) {
vmiura@chromium.org5ebf59f2014-04-08 03:51:57238 SetupTextureInitializationExpectations(
239 gl, GL_TEXTURE_EXTERNAL_OES, use_default_textures);
kbr@chromium.orge51bdf32011-11-23 22:21:46240 }
241 if (arb_texture_rectangle) {
vmiura@chromium.org5ebf59f2014-04-08 03:51:57242 SetupTextureInitializationExpectations(
243 gl, GL_TEXTURE_RECTANGLE_ARB, use_default_textures);
bulach@chromium.org61eeb33f2011-07-26 15:30:31244 }
gman@chromium.org00f893d2010-08-24 18:55:49245}
246
gman@chromium.org1075a532012-06-13 00:52:33247void TestHelper::SetupTextureDestructionExpectations(
kylechar7a463842016-05-26 14:46:12248 ::gl::MockGLInterface* gl,
vmiura@chromium.org5ebf59f2014-04-08 03:51:57249 GLenum target,
250 bool use_default_textures) {
251 if (!use_default_textures)
252 return;
253
gman@chromium.org1075a532012-06-13 00:52:33254 GLuint texture_id = 0;
255 switch (target) {
256 case GL_TEXTURE_2D:
257 texture_id = kServiceDefaultTexture2dId;
258 break;
qiankun.miao4e2f0d02015-09-18 03:34:48259 case GL_TEXTURE_3D:
260 texture_id = kServiceDefaultTexture3dId;
261 break;
262 case GL_TEXTURE_2D_ARRAY:
263 texture_id = kServiceDefaultTexture2dArrayId;
264 break;
gman@chromium.org1075a532012-06-13 00:52:33265 case GL_TEXTURE_CUBE_MAP:
266 texture_id = kServiceDefaultTextureCubemapId;
267 break;
268 case GL_TEXTURE_EXTERNAL_OES:
269 texture_id = kServiceDefaultExternalTextureId;
270 break;
271 case GL_TEXTURE_RECTANGLE_ARB:
272 texture_id = kServiceDefaultRectangleTextureId;
273 break;
274 default:
275 NOTREACHED();
276 }
277
278 EXPECT_CALL(*gl, DeleteTextures(1, Pointee(texture_id)))
279 .Times(1)
280 .RetiresOnSaturation();
281}
282
283void TestHelper::SetupTextureManagerDestructionExpectations(
kylechar7a463842016-05-26 14:46:12284 ::gl::MockGLInterface* gl,
qiankun.miao4e2f0d02015-09-18 03:34:48285 bool is_es3_enabled,
bajones2c9d7182016-03-11 18:16:28286 bool is_desktop_core_profile,
Michael Spangbe9d9eb2018-06-21 20:02:04287 const gfx::ExtensionSet& extensions,
vmiura@chromium.org5ebf59f2014-04-08 03:51:57288 bool use_default_textures) {
289 SetupTextureDestructionExpectations(gl, GL_TEXTURE_2D, use_default_textures);
290 SetupTextureDestructionExpectations(
291 gl, GL_TEXTURE_CUBE_MAP, use_default_textures);
gman@chromium.org1075a532012-06-13 00:52:33292
qiankun.miao4e2f0d02015-09-18 03:34:48293 if (is_es3_enabled) {
294 SetupTextureDestructionExpectations(
295 gl, GL_TEXTURE_3D, use_default_textures);
296 SetupTextureDestructionExpectations(
297 gl, GL_TEXTURE_2D_ARRAY,use_default_textures);
298 }
299
Antoine Labour20d16202017-09-05 23:05:29300 bool ext_image_external =
Michael Spangbe9d9eb2018-06-21 20:02:04301 gfx::HasExtension(extensions, "GL_OES_EGL_image_external");
Antoine Labour20d16202017-09-05 23:05:29302 bool arb_texture_rectangle =
303 is_desktop_core_profile ||
Michael Spangbe9d9eb2018-06-21 20:02:04304 gfx::HasExtension(extensions, "GL_ARB_texture_rectangle");
gman@chromium.org1075a532012-06-13 00:52:33305
306 if (ext_image_external) {
vmiura@chromium.org5ebf59f2014-04-08 03:51:57307 SetupTextureDestructionExpectations(
308 gl, GL_TEXTURE_EXTERNAL_OES, use_default_textures);
gman@chromium.org1075a532012-06-13 00:52:33309 }
bajones2c9d7182016-03-11 18:16:28310 if (arb_texture_rectangle || is_desktop_core_profile) {
vmiura@chromium.org5ebf59f2014-04-08 03:51:57311 SetupTextureDestructionExpectations(
312 gl, GL_TEXTURE_RECTANGLE_ARB, use_default_textures);
gman@chromium.org1075a532012-06-13 00:52:33313 }
314
qiankun.miao4e2f0d02015-09-18 03:34:48315 EXPECT_CALL(*gl, DeleteTextures(TextureManager::kNumDefaultTextures, _))
gman@chromium.org1075a532012-06-13 00:52:33316 .Times(1)
317 .RetiresOnSaturation();
318}
319
gman@chromium.org00f893d2010-08-24 18:55:49320void TestHelper::SetupContextGroupInitExpectations(
kylechar7a463842016-05-26 14:46:12321 ::gl::MockGLInterface* gl,
vmiura@chromium.org5ebf59f2014-04-08 03:51:57322 const DisallowedFeatures& disallowed_features,
323 const char* extensions,
324 const char* gl_version,
kainino803bcd7b2016-08-31 02:52:29325 ContextType context_type,
vmiura@chromium.org5ebf59f2014-04-08 03:51:57326 bool bind_generates_resource) {
gman@chromium.org00f893d2010-08-24 18:55:49327 InSequence sequence;
328
kaininoe20d23ac2016-11-03 01:03:45329 bool enable_es3 = !(context_type == CONTEXT_TYPE_OPENGLES2 ||
330 context_type == CONTEXT_TYPE_WEBGL1);
331
Michael Spangbe9d9eb2018-06-21 20:02:04332 gfx::ExtensionSet extension_set(gfx::MakeExtensionSet(extensions));
Antoine Labour20d16202017-09-05 23:05:29333 gl::GLVersionInfo gl_info(gl_version, "", extension_set);
gman@chromium.org915a59a12010-09-30 21:29:11334
kainino803bcd7b2016-08-31 02:52:29335 SetupFeatureInfoInitExpectationsWithGLVersion(gl, extensions, "", gl_version,
kaininoe20d23ac2016-11-03 01:03:45336 context_type);
gman@chromium.org5094b0f2010-11-09 19:45:24337 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_RENDERBUFFER_SIZE, _))
thestige147d682017-05-05 07:31:31338 .WillOnce(SetArgPointee<1>(kMaxRenderbufferSize))
gman@chromium.org5094b0f2010-11-09 19:45:24339 .RetiresOnSaturation();
Michael Spangbe9d9eb2018-06-21 20:02:04340 if (gfx::HasExtension(extension_set, "GL_ARB_framebuffer_object") ||
341 gfx::HasExtension(extension_set, "GL_EXT_framebuffer_multisample") ||
342 gfx::HasExtension(extension_set,
343 "GL_EXT_multisampled_render_to_texture") ||
cwallezdc1c9eb2016-05-26 03:11:56344 gl_info.is_es3 || gl_info.is_desktop_core_profile) {
gman@chromium.org84afefa2011-10-19 21:45:53345 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_SAMPLES, _))
thestige147d682017-05-05 07:31:31346 .WillOnce(SetArgPointee<1>(kMaxSamples))
gman@chromium.org84afefa2011-10-19 21:45:53347 .RetiresOnSaturation();
Michael Spangbe9d9eb2018-06-21 20:02:04348 } else if (gfx::HasExtension(extension_set,
349 "GL_IMG_multisampled_render_to_texture")) {
sievers@chromium.org49cabed2013-11-13 18:15:18350 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_SAMPLES_IMG, _))
thestige147d682017-05-05 07:31:31351 .WillOnce(SetArgPointee<1>(kMaxSamples))
sievers@chromium.org49cabed2013-11-13 18:15:18352 .RetiresOnSaturation();
gman@chromium.org84afefa2011-10-19 21:45:53353 }
kkinnunen8cefb232015-12-04 09:36:31354
kainino313016a2017-02-17 19:55:22355 if (enable_es3 ||
356 (!enable_es3 &&
357 (gl_info.is_desktop_core_profile ||
Michael Spangbe9d9eb2018-06-21 20:02:04358 gfx::HasExtension(extension_set, "GL_EXT_draw_buffers") ||
359 gfx::HasExtension(extension_set, "GL_ARB_draw_buffers") ||
Antoine Labour20d16202017-09-05 23:05:29360 (gl_info.is_es3 &&
Michael Spangbe9d9eb2018-06-21 20:02:04361 gfx::HasExtension(extension_set, "GL_NV_draw_buffers"))))) {
cwallezdc1c9eb2016-05-26 03:11:56362 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, _))
thestige147d682017-05-05 07:31:31363 .WillOnce(SetArgPointee<1>(8))
cwallezdc1c9eb2016-05-26 03:11:56364 .RetiresOnSaturation();
365 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, _))
thestige147d682017-05-05 07:31:31366 .WillOnce(SetArgPointee<1>(8))
cwallezdc1c9eb2016-05-26 03:11:56367 .RetiresOnSaturation();
368 }
369
kkinnunen8cefb232015-12-04 09:36:31370 if (gl_info.IsAtLeastGL(3, 3) ||
371 (gl_info.IsAtLeastGL(3, 2) &&
Michael Spangbe9d9eb2018-06-21 20:02:04372 gfx::HasExtension(extension_set, "GL_ARB_blend_func_extended")) ||
Antoine Labour20d16202017-09-05 23:05:29373 (gl_info.is_es &&
Michael Spangbe9d9eb2018-06-21 20:02:04374 gfx::HasExtension(extension_set, "GL_EXT_blend_func_extended"))) {
kkinnunen8cefb232015-12-04 09:36:31375 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT, _))
thestige147d682017-05-05 07:31:31376 .WillOnce(SetArgPointee<1>(8))
kkinnunen8cefb232015-12-04 09:36:31377 .RetiresOnSaturation();
378 }
379
cwallez3b2dfed2016-06-27 20:03:27380 if (gl_info.is_es3_capable) {
zmo706399be2016-04-21 00:01:08381 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, _))
thestige147d682017-05-05 07:31:31382 .WillOnce(SetArgPointee<1>(kMaxTransformFeedbackSeparateAttribs))
zmo706399be2016-04-21 00:01:08383 .RetiresOnSaturation();
384 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, _))
thestige147d682017-05-05 07:31:31385 .WillOnce(SetArgPointee<1>(kMaxUniformBufferBindings))
zmo706399be2016-04-21 00:01:08386 .RetiresOnSaturation();
387 EXPECT_CALL(*gl, GetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, _))
thestige147d682017-05-05 07:31:31388 .WillOnce(SetArgPointee<1>(kUniformBufferOffsetAlignment))
zmo706399be2016-04-21 00:01:08389 .RetiresOnSaturation();
390 }
391
gman@chromium.org00f893d2010-08-24 18:55:49392 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_VERTEX_ATTRIBS, _))
thestige147d682017-05-05 07:31:31393 .WillOnce(SetArgPointee<1>(kNumVertexAttribs))
gman@chromium.org00f893d2010-08-24 18:55:49394 .RetiresOnSaturation();
395 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, _))
thestige147d682017-05-05 07:31:31396 .WillOnce(SetArgPointee<1>(kNumTextureUnits))
gman@chromium.org00f893d2010-08-24 18:55:49397 .RetiresOnSaturation();
398 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_TEXTURE_SIZE, _))
thestige147d682017-05-05 07:31:31399 .WillOnce(SetArgPointee<1>(kMaxTextureSize))
gman@chromium.org00f893d2010-08-24 18:55:49400 .RetiresOnSaturation();
401 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, _))
thestige147d682017-05-05 07:31:31402 .WillOnce(SetArgPointee<1>(kMaxCubeMapTextureSize))
gman@chromium.org00f893d2010-08-24 18:55:49403 .RetiresOnSaturation();
cwallez3b2dfed2016-06-27 20:03:27404 if (gl_info.is_es3_capable) {
zmoea06a6f2015-04-30 01:15:46405 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_3D_TEXTURE_SIZE, _))
thestige147d682017-05-05 07:31:31406 .WillOnce(SetArgPointee<1>(kMax3DTextureSize))
zmoea06a6f2015-04-30 01:15:46407 .RetiresOnSaturation();
408 }
cwallez3b2dfed2016-06-27 20:03:27409 if (gl_info.is_es3_capable) {
zmo9bdab5d2016-05-05 04:35:27410 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, _))
thestige147d682017-05-05 07:31:31411 .WillOnce(SetArgPointee<1>(kMaxArrayTextureLayers))
zmo9bdab5d2016-05-05 04:35:27412 .RetiresOnSaturation();
413 }
Michael Spangbe9d9eb2018-06-21 20:02:04414 if (gfx::HasExtension(extension_set, "GL_ARB_texture_rectangle") ||
cwallezdc1c9eb2016-05-26 03:11:56415 gl_info.is_desktop_core_profile) {
sandersd9d0bb832014-12-17 01:24:55416 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE, _))
thestige147d682017-05-05 07:31:31417 .WillOnce(SetArgPointee<1>(kMaxRectangleTextureSize))
sandersd9d0bb832014-12-17 01:24:55418 .RetiresOnSaturation();
419 }
gman@chromium.org00f893d2010-08-24 18:55:49420 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, _))
thestige147d682017-05-05 07:31:31421 .WillOnce(SetArgPointee<1>(kMaxTextureImageUnits))
gman@chromium.org00f893d2010-08-24 18:55:49422 .RetiresOnSaturation();
423 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, _))
thestige147d682017-05-05 07:31:31424 .WillOnce(SetArgPointee<1>(kMaxVertexTextureImageUnits))
gman@chromium.org00f893d2010-08-24 18:55:49425 .RetiresOnSaturation();
kbrc9f0e10c2015-03-31 19:49:12426
cwallezdc1c9eb2016-05-26 03:11:56427 if (gl_info.is_es || gl_info.is_desktop_core_profile) {
kbrc9f0e10c2015-03-31 19:49:12428 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, _))
thestige147d682017-05-05 07:31:31429 .WillOnce(SetArgPointee<1>(kMaxFragmentUniformVectors))
kbrc9f0e10c2015-03-31 19:49:12430 .RetiresOnSaturation();
431 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_VARYING_VECTORS, _))
thestige147d682017-05-05 07:31:31432 .WillOnce(SetArgPointee<1>(kMaxVaryingVectors))
kbrc9f0e10c2015-03-31 19:49:12433 .RetiresOnSaturation();
434 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, _))
thestige147d682017-05-05 07:31:31435 .WillOnce(SetArgPointee<1>(kMaxVertexUniformVectors))
kbrc9f0e10c2015-03-31 19:49:12436 .RetiresOnSaturation();
437 } else {
438 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, _))
thestige147d682017-05-05 07:31:31439 .WillOnce(SetArgPointee<1>(kMaxFragmentUniformComponents))
kbrc9f0e10c2015-03-31 19:49:12440 .RetiresOnSaturation();
441 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_VARYING_FLOATS, _))
thestige147d682017-05-05 07:31:31442 .WillOnce(SetArgPointee<1>(kMaxVaryingFloats))
kbrc9f0e10c2015-03-31 19:49:12443 .RetiresOnSaturation();
444 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, _))
thestige147d682017-05-05 07:31:31445 .WillOnce(SetArgPointee<1>(kMaxVertexUniformComponents))
kbrc9f0e10c2015-03-31 19:49:12446 .RetiresOnSaturation();
447 }
gman@chromium.org00f893d2010-08-24 18:55:49448
cwalleze96e24b2016-03-15 00:18:48449 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_VERTEX_OUTPUT_COMPONENTS, _))
450 .Times(testing::Between(0, 1))
thestige147d682017-05-05 07:31:31451 .WillRepeatedly(SetArgPointee<1>(kMaxVertexOutputComponents))
cwalleze96e24b2016-03-15 00:18:48452 .RetiresOnSaturation();
453 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_FRAGMENT_INPUT_COMPONENTS, _))
454 .Times(testing::Between(0, 1))
thestige147d682017-05-05 07:31:31455 .WillRepeatedly(SetArgPointee<1>(kMaxFragmentInputComponents))
cwalleze96e24b2016-03-15 00:18:48456 .RetiresOnSaturation();
457 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_PROGRAM_TEXEL_OFFSET, _))
458 .Times(testing::Between(0, 1))
thestige147d682017-05-05 07:31:31459 .WillRepeatedly(SetArgPointee<1>(kMaxProgramTexelOffset))
cwalleze96e24b2016-03-15 00:18:48460 .RetiresOnSaturation();
461 EXPECT_CALL(*gl, GetIntegerv(GL_MIN_PROGRAM_TEXEL_OFFSET, _))
462 .Times(testing::Between(0, 1))
thestige147d682017-05-05 07:31:31463 .WillRepeatedly(SetArgPointee<1>(kMinProgramTexelOffset))
cwalleze96e24b2016-03-15 00:18:48464 .RetiresOnSaturation();
465
vmiura@chromium.org5ebf59f2014-04-08 03:51:57466 bool use_default_textures = bind_generates_resource;
Antoine Labour20d16202017-09-05 23:05:29467 SetupTextureManagerInitExpectations(gl, enable_es3, gl_info.is_es3_capable,
468 gl_info.is_desktop_core_profile,
469 extension_set, use_default_textures);
gman@chromium.org00f893d2010-08-24 18:55:49470}
471
kylechar7a463842016-05-26 14:46:12472void TestHelper::SetupFeatureInfoInitExpectations(::gl::MockGLInterface* gl,
473 const char* extensions) {
kainino803bcd7b2016-08-31 02:52:29474 SetupFeatureInfoInitExpectationsWithGLVersion(gl, extensions, "", "",
475 CONTEXT_TYPE_OPENGLES2);
gman@chromium.org5c67c7032012-05-15 18:21:22476}
477
zmo@chromium.org185de2a2013-04-04 22:57:11478void TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion(
kylechar7a463842016-05-26 14:46:12479 ::gl::MockGLInterface* gl,
480 const char* extensions,
481 const char* gl_renderer,
482 const char* gl_version,
kaininoe20d23ac2016-11-03 01:03:45483 ContextType context_type) {
gman@chromium.org915a59a12010-09-30 21:29:11484 InSequence sequence;
485
kaininoe20d23ac2016-11-03 01:03:45486 bool enable_es3 = context_type == CONTEXT_TYPE_WEBGL2 ||
487 context_type == CONTEXT_TYPE_OPENGLES3;
488
dsinclair@chromium.org7832f3f2013-03-14 08:15:05489 EXPECT_CALL(*gl, GetString(GL_VERSION))
avif15d60a2015-12-21 17:06:33490 .WillOnce(Return(reinterpret_cast<const uint8_t*>(gl_version)))
dsinclair@chromium.org7832f3f2013-03-14 08:15:05491 .RetiresOnSaturation();
oetuaho@nvidia.com17a961192014-02-14 15:20:52492
Jonah Ryan-Davisc4d099f3f2021-01-27 20:49:31493 EXPECT_CALL(*gl, GetString(GL_RENDERER))
494 .WillOnce(Return(reinterpret_cast<const uint8_t*>(gl_renderer)))
495 .RetiresOnSaturation();
496
Michael Spangbe9d9eb2018-06-21 20:02:04497 gfx::ExtensionSet extension_set(gfx::MakeExtensionSet(extensions));
kbrc9f0e10c2015-03-31 19:49:12498 // Persistent storage is needed for the split extension string.
Antoine Labour20d16202017-09-05 23:05:29499 split_extensions_ =
500 std::vector<std::string>(extension_set.begin(), extension_set.end());
501 gl::GLVersionInfo gl_info(gl_version, gl_renderer, extension_set);
kbrc9f0e10c2015-03-31 19:49:12502 if (!gl_info.is_es && gl_info.major_version >= 3) {
503 EXPECT_CALL(*gl, GetIntegerv(GL_NUM_EXTENSIONS, _))
thestige147d682017-05-05 07:31:31504 .WillOnce(SetArgPointee<1>(split_extensions_.size()))
kbrc9f0e10c2015-03-31 19:49:12505 .RetiresOnSaturation();
506 for (size_t ii = 0; ii < split_extensions_.size(); ++ii) {
507 EXPECT_CALL(*gl, GetStringi(GL_EXTENSIONS, ii))
avif15d60a2015-12-21 17:06:33508 .WillOnce(Return(
509 reinterpret_cast<const uint8_t*>(split_extensions_[ii].c_str())))
kbrc9f0e10c2015-03-31 19:49:12510 .RetiresOnSaturation();
511 }
512 } else {
513 EXPECT_CALL(*gl, GetString(GL_EXTENSIONS))
avif15d60a2015-12-21 17:06:33514 .WillOnce(Return(reinterpret_cast<const uint8_t*>(extensions)))
kbrc9f0e10c2015-03-31 19:49:12515 .RetiresOnSaturation();
516 }
517
kbr53edb992015-08-06 01:16:29518 EXPECT_CALL(*gl, GetString(GL_VERSION))
avif15d60a2015-12-21 17:06:33519 .WillOnce(Return(reinterpret_cast<const uint8_t*>(gl_version)))
kbr53edb992015-08-06 01:16:29520 .RetiresOnSaturation();
kbrc9f0e10c2015-03-31 19:49:12521 EXPECT_CALL(*gl, GetString(GL_RENDERER))
avif15d60a2015-12-21 17:06:33522 .WillOnce(Return(reinterpret_cast<const uint8_t*>(gl_renderer)))
kbrc9f0e10c2015-03-31 19:49:12523 .RetiresOnSaturation();
oetuaho@nvidia.com17a961192014-02-14 15:20:52524
Antoine Labourae9d975a2018-11-17 00:47:45525 if (gl_info.is_es3 || gl_info.is_desktop_core_profile ||
526 gfx::HasExtension(extension_set, "GL_ARB_pixel_buffer_object") ||
Michael Spangbe9d9eb2018-06-21 20:02:04527 gfx::HasExtension(extension_set, "GL_NV_pixel_buffer_object")) {
kainino803bcd7b2016-08-31 02:52:29528 EXPECT_CALL(*gl, GetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, _))
529 .WillOnce(SetArgPointee<1>(0))
530 .RetiresOnSaturation();
531 }
532
Michael Spangbe9d9eb2018-06-21 20:02:04533 if ((gfx::HasExtension(extension_set, "GL_ARB_texture_float") ||
kkinnunenc8b449e1582015-11-02 07:57:51534 gl_info.is_desktop_core_profile) ||
Antoine Labour20d16202017-09-05 23:05:29535 (gl_info.is_es3 &&
Michael Spangbe9d9eb2018-06-21 20:02:04536 gfx::HasExtension(extension_set, "GL_OES_texture_float") &&
537 gfx::HasExtension(extension_set, "GL_EXT_color_buffer_float"))) {
hendrikw83f2fb52014-12-02 03:30:40538 static const GLuint tx_ids[] = {101, 102};
539 static const GLuint fb_ids[] = {103, 104};
oetuaho@nvidia.com17a961192014-02-14 15:20:52540 const GLsizei width = 16;
541 EXPECT_CALL(*gl, GetIntegerv(GL_FRAMEBUFFER_BINDING, _))
thestige147d682017-05-05 07:31:31542 .WillOnce(SetArgPointee<1>(fb_ids[0]))
oetuaho@nvidia.com17a961192014-02-14 15:20:52543 .RetiresOnSaturation();
544 EXPECT_CALL(*gl, GetIntegerv(GL_TEXTURE_BINDING_2D, _))
thestige147d682017-05-05 07:31:31545 .WillOnce(SetArgPointee<1>(tx_ids[0]))
oetuaho@nvidia.com17a961192014-02-14 15:20:52546 .RetiresOnSaturation();
547 EXPECT_CALL(*gl, GenTextures(1, _))
hendrikw83f2fb52014-12-02 03:30:40548 .WillOnce(SetArrayArgument<1>(tx_ids + 1, tx_ids + 2))
oetuaho@nvidia.com17a961192014-02-14 15:20:52549 .RetiresOnSaturation();
550 EXPECT_CALL(*gl, GenFramebuffersEXT(1, _))
hendrikw83f2fb52014-12-02 03:30:40551 .WillOnce(SetArrayArgument<1>(fb_ids + 1, fb_ids + 2))
oetuaho@nvidia.com17a961192014-02-14 15:20:52552 .RetiresOnSaturation();
hendrikw83f2fb52014-12-02 03:30:40553 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_2D, tx_ids[1]))
oetuaho@nvidia.com17a961192014-02-14 15:20:52554 .Times(1)
555 .RetiresOnSaturation();
556 EXPECT_CALL(*gl, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
557 GL_NEAREST))
558 .Times(1)
559 .RetiresOnSaturation();
560 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, width, 0,
561 GL_RGBA, GL_FLOAT, _))
562 .Times(1)
563 .RetiresOnSaturation();
hendrikw83f2fb52014-12-02 03:30:40564 EXPECT_CALL(*gl, BindFramebufferEXT(GL_FRAMEBUFFER, fb_ids[1]))
oetuaho@nvidia.com17a961192014-02-14 15:20:52565 .Times(1)
566 .RetiresOnSaturation();
567 EXPECT_CALL(*gl, FramebufferTexture2DEXT(GL_FRAMEBUFFER,
hendrikw83f2fb52014-12-02 03:30:40568 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tx_ids[1], 0))
oetuaho@nvidia.com17a961192014-02-14 15:20:52569 .Times(1)
570 .RetiresOnSaturation();
571 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
572 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
573 .RetiresOnSaturation();
qiankun.miaobd9c6582016-11-03 15:26:55574 GLenum status_rgba = GL_FRAMEBUFFER_COMPLETE;
oetuaho@nvidia.com17a961192014-02-14 15:20:52575 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, width, 0,
576 GL_RGB, GL_FLOAT, _))
577 .Times(1)
578 .RetiresOnSaturation();
kbrc9f0e10c2015-03-31 19:49:12579 if (gl_info.is_es3) {
oetuaho@nvidia.com17a961192014-02-14 15:20:52580 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
581 .WillOnce(Return(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT))
582 .RetiresOnSaturation();
583 } else {
584 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
585 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
586 .RetiresOnSaturation();
kaininoe20d23ac2016-11-03 01:03:45587 }
bajones2c9d7182016-03-11 18:16:28588
kbr75c64262017-02-05 00:34:11589 if (status_rgba == GL_FRAMEBUFFER_COMPLETE && enable_es3) {
kaininoe20d23ac2016-11-03 01:03:45590 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_R16F, width, width,
591 0, GL_RED, GL_FLOAT, _))
592 .Times(1)
593 .RetiresOnSaturation();
594 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
595 .Times(1)
596 .RetiresOnSaturation();
597 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, width, width,
598 0, GL_RG, GL_FLOAT, _))
599 .Times(1)
600 .RetiresOnSaturation();
601 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
602 .Times(1)
603 .RetiresOnSaturation();
604 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, width,
605 0, GL_RGBA, GL_FLOAT, _))
606 .Times(1)
607 .RetiresOnSaturation();
608 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
609 .Times(1)
610 .RetiresOnSaturation();
611 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_R32F, width, width,
612 0, GL_RED, GL_FLOAT, _))
613 .Times(1)
614 .RetiresOnSaturation();
615 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
616 .Times(1)
617 .RetiresOnSaturation();
618 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, width, width,
619 0, GL_RG, GL_FLOAT, _))
620 .Times(1)
621 .RetiresOnSaturation();
622 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
623 .Times(1)
624 .RetiresOnSaturation();
625 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_R11F_G11F_B10F,
626 width, width, 0, GL_RGB, GL_FLOAT, _))
627 .Times(1)
628 .RetiresOnSaturation();
629 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
630 .Times(1)
631 .RetiresOnSaturation();
oetuaho@nvidia.com17a961192014-02-14 15:20:52632 }
Antoine Labour20d16202017-09-05 23:05:29633 if (!enable_es3 &&
Michael Spangbe9d9eb2018-06-21 20:02:04634 !gfx::HasExtension(extension_set, "GL_EXT_color_buffer_half_float") &&
Zhenyao Moc82b9b9a2017-09-26 01:27:03635 (gl_info.IsAtLeastGLES(3, 0) || gl_info.IsAtLeastGL(3, 0))) {
636 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, width, 0,
637 GL_RGBA, GL_HALF_FLOAT, nullptr))
ccameron85072152017-02-24 19:53:23638 .Times(1)
639 .RetiresOnSaturation();
640 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
641 .Times(1)
642 .RetiresOnSaturation();
643 }
bajones2c9d7182016-03-11 18:16:28644
oetuaho@nvidia.com17a961192014-02-14 15:20:52645 EXPECT_CALL(*gl, DeleteFramebuffersEXT(1, _))
646 .Times(1)
647 .RetiresOnSaturation();
648 EXPECT_CALL(*gl, DeleteTextures(1, _))
649 .Times(1)
650 .RetiresOnSaturation();
hendrikw83f2fb52014-12-02 03:30:40651 EXPECT_CALL(*gl, BindFramebufferEXT(GL_FRAMEBUFFER, fb_ids[0]))
oetuaho@nvidia.com17a961192014-02-14 15:20:52652 .Times(1)
653 .RetiresOnSaturation();
hendrikw83f2fb52014-12-02 03:30:40654 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_2D, tx_ids[0]))
oetuaho@nvidia.com17a961192014-02-14 15:20:52655 .Times(1)
656 .RetiresOnSaturation();
danakje649f572015-01-08 23:35:58657#if DCHECK_IS_ON()
wangxianzhu@chromium.orgc02cb8012014-03-14 18:39:53658 EXPECT_CALL(*gl, GetError())
659 .WillOnce(Return(GL_NO_ERROR))
660 .RetiresOnSaturation();
661#endif
oetuaho@nvidia.com17a961192014-02-14 15:20:52662 }
oetuaho0decd442014-10-13 08:40:46663
kainino313016a2017-02-17 19:55:22664 if (enable_es3 ||
665 (!enable_es3 &&
666 (gl_info.is_desktop_core_profile ||
Michael Spangbe9d9eb2018-06-21 20:02:04667 gfx::HasExtension(extension_set, "GL_EXT_draw_buffers") ||
668 gfx::HasExtension(extension_set, "GL_ARB_draw_buffers") ||
Antoine Labour20d16202017-09-05 23:05:29669 (gl_info.is_es3 &&
Michael Spangbe9d9eb2018-06-21 20:02:04670 gfx::HasExtension(extension_set, "GL_NV_draw_buffers"))))) {
oetuaho0decd442014-10-13 08:40:46671 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, _))
thestige147d682017-05-05 07:31:31672 .WillOnce(SetArgPointee<1>(8))
oetuaho0decd442014-10-13 08:40:46673 .RetiresOnSaturation();
674 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, _))
thestige147d682017-05-05 07:31:31675 .WillOnce(SetArgPointee<1>(8))
oetuaho0decd442014-10-13 08:40:46676 .RetiresOnSaturation();
677 }
hendrikw83f2fb52014-12-02 03:30:40678
Xiaohan Wangfa22d3e2022-01-15 02:02:43679#if !BUILDFLAG(IS_MAC)
kkinnunenc8b449e1582015-11-02 07:57:51680 if (gl_info.is_es3 || gl_info.is_desktop_core_profile ||
Michael Spangbe9d9eb2018-06-21 20:02:04681 gfx::HasExtension(extension_set, "GL_EXT_texture_rg") ||
682 (gfx::HasExtension(extension_set, "GL_ARB_texture_rg"))) {
Antoine Labour5e48f902017-11-06 21:46:21683#if DCHECK_IS_ON()
684 EXPECT_CALL(*gl, GetError())
685 .WillOnce(Return(GL_NO_ERROR))
686 .RetiresOnSaturation();
687#endif
hendrikw83f2fb52014-12-02 03:30:40688 static const GLuint tx_ids[] = {101, 102};
689 static const GLuint fb_ids[] = {103, 104};
Kenneth Russell734c5f12023-01-22 19:42:51690 const GLsizei width = 8;
hendrikw83f2fb52014-12-02 03:30:40691 EXPECT_CALL(*gl, GetIntegerv(GL_FRAMEBUFFER_BINDING, _))
thestige147d682017-05-05 07:31:31692 .WillOnce(SetArgPointee<1>(fb_ids[0]))
hendrikw83f2fb52014-12-02 03:30:40693 .RetiresOnSaturation();
694 EXPECT_CALL(*gl, GetIntegerv(GL_TEXTURE_BINDING_2D, _))
thestige147d682017-05-05 07:31:31695 .WillOnce(SetArgPointee<1>(tx_ids[0]))
hendrikw83f2fb52014-12-02 03:30:40696 .RetiresOnSaturation();
697 EXPECT_CALL(*gl, GenTextures(1, _))
698 .WillOnce(SetArrayArgument<1>(tx_ids + 1, tx_ids + 2))
699 .RetiresOnSaturation();
700 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_2D, tx_ids[1]))
701 .Times(1)
702 .RetiresOnSaturation();
hendrikwbef24f5c2014-12-05 01:01:42703 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, _, width, width, 0,
hendrikw83f2fb52014-12-02 03:30:40704 GL_RED_EXT, GL_UNSIGNED_BYTE, _))
705 .Times(1)
706 .RetiresOnSaturation();
707 EXPECT_CALL(*gl, GenFramebuffersEXT(1, _))
708 .WillOnce(SetArrayArgument<1>(fb_ids + 1, fb_ids + 2))
709 .RetiresOnSaturation();
710 EXPECT_CALL(*gl, BindFramebufferEXT(GL_FRAMEBUFFER, fb_ids[1]))
711 .Times(1)
712 .RetiresOnSaturation();
713 EXPECT_CALL(*gl, FramebufferTexture2DEXT(GL_FRAMEBUFFER,
714 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tx_ids[1], 0))
715 .Times(1)
716 .RetiresOnSaturation();
717 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
718 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
719 .RetiresOnSaturation();
720 EXPECT_CALL(*gl, DeleteFramebuffersEXT(1, _))
721 .Times(1)
722 .RetiresOnSaturation();
723 EXPECT_CALL(*gl, DeleteTextures(1, _))
724 .Times(1)
725 .RetiresOnSaturation();
726 EXPECT_CALL(*gl, BindFramebufferEXT(GL_FRAMEBUFFER, fb_ids[0]))
727 .Times(1)
728 .RetiresOnSaturation();
729 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_2D, tx_ids[0]))
730 .Times(1)
731 .RetiresOnSaturation();
danakje649f572015-01-08 23:35:58732#if DCHECK_IS_ON()
hendrikw83f2fb52014-12-02 03:30:40733 EXPECT_CALL(*gl, GetError())
734 .WillOnce(Return(GL_NO_ERROR))
735 .RetiresOnSaturation();
736#endif
737 }
Xiaohan Wangfa22d3e2022-01-15 02:02:43738#endif // !BUILDFLAG(IS_MAC)
gman@chromium.org915a59a12010-09-30 21:29:11739}
740
kylechar7a463842016-05-26 14:46:12741void TestHelper::SetupExpectationsForClearingUniforms(::gl::MockGLInterface* gl,
742 UniformInfo* uniforms,
743 size_t num_uniforms) {
gman@chromium.org0abf43e32012-05-10 23:36:23744 for (size_t ii = 0; ii < num_uniforms; ++ii) {
745 const UniformInfo& info = uniforms[ii];
746 switch (info.type) {
747 case GL_FLOAT:
748 EXPECT_CALL(*gl, Uniform1fv(info.real_location, info.size, _))
749 .Times(1)
750 .RetiresOnSaturation();
751 break;
752 case GL_FLOAT_VEC2:
753 EXPECT_CALL(*gl, Uniform2fv(info.real_location, info.size, _))
754 .Times(1)
755 .RetiresOnSaturation();
756 break;
757 case GL_FLOAT_VEC3:
758 EXPECT_CALL(*gl, Uniform3fv(info.real_location, info.size, _))
759 .Times(1)
760 .RetiresOnSaturation();
761 break;
762 case GL_FLOAT_VEC4:
763 EXPECT_CALL(*gl, Uniform4fv(info.real_location, info.size, _))
764 .Times(1)
765 .RetiresOnSaturation();
766 break;
767 case GL_INT:
768 case GL_BOOL:
769 case GL_SAMPLER_2D:
770 case GL_SAMPLER_CUBE:
771 case GL_SAMPLER_EXTERNAL_OES:
772 case GL_SAMPLER_3D_OES:
773 case GL_SAMPLER_2D_RECT_ARB:
zmo791482592015-09-14 20:42:13774 case GL_SAMPLER_2D_ARRAY:
gman@chromium.org0abf43e32012-05-10 23:36:23775 EXPECT_CALL(*gl, Uniform1iv(info.real_location, info.size, _))
776 .Times(1)
777 .RetiresOnSaturation();
778 break;
zmo791482592015-09-14 20:42:13779 case GL_UNSIGNED_INT:
780 EXPECT_CALL(*gl, Uniform1uiv(info.real_location, info.size, _))
781 .Times(1)
782 .RetiresOnSaturation();
783 break;
gman@chromium.org0abf43e32012-05-10 23:36:23784 case GL_INT_VEC2:
785 case GL_BOOL_VEC2:
786 EXPECT_CALL(*gl, Uniform2iv(info.real_location, info.size, _))
787 .Times(1)
788 .RetiresOnSaturation();
789 break;
zmo791482592015-09-14 20:42:13790 case GL_UNSIGNED_INT_VEC2:
791 EXPECT_CALL(*gl, Uniform2uiv(info.real_location, info.size, _))
792 .Times(1)
793 .RetiresOnSaturation();
794 break;
gman@chromium.org0abf43e32012-05-10 23:36:23795 case GL_INT_VEC3:
796 case GL_BOOL_VEC3:
797 EXPECT_CALL(*gl, Uniform3iv(info.real_location, info.size, _))
798 .Times(1)
799 .RetiresOnSaturation();
800 break;
zmo791482592015-09-14 20:42:13801 case GL_UNSIGNED_INT_VEC3:
802 EXPECT_CALL(*gl, Uniform3uiv(info.real_location, info.size, _))
803 .Times(1)
804 .RetiresOnSaturation();
805 break;
gman@chromium.org0abf43e32012-05-10 23:36:23806 case GL_INT_VEC4:
807 case GL_BOOL_VEC4:
808 EXPECT_CALL(*gl, Uniform4iv(info.real_location, info.size, _))
809 .Times(1)
810 .RetiresOnSaturation();
811 break;
zmo791482592015-09-14 20:42:13812 case GL_UNSIGNED_INT_VEC4:
813 EXPECT_CALL(*gl, Uniform4uiv(info.real_location, info.size, _))
814 .Times(1)
815 .RetiresOnSaturation();
816 break;
gman@chromium.org0abf43e32012-05-10 23:36:23817 case GL_FLOAT_MAT2:
818 EXPECT_CALL(*gl, UniformMatrix2fv(
819 info.real_location, info.size, false, _))
820 .Times(1)
821 .RetiresOnSaturation();
822 break;
823 case GL_FLOAT_MAT3:
824 EXPECT_CALL(*gl, UniformMatrix3fv(
825 info.real_location, info.size, false, _))
826 .Times(1)
827 .RetiresOnSaturation();
828 break;
829 case GL_FLOAT_MAT4:
830 EXPECT_CALL(*gl, UniformMatrix4fv(
831 info.real_location, info.size, false, _))
832 .Times(1)
833 .RetiresOnSaturation();
834 break;
835 default:
836 NOTREACHED();
837 break;
838 }
839 }
840}
841
dmurph@chromium.org65dfc602012-07-23 20:39:39842void TestHelper::SetupProgramSuccessExpectations(
kylechar7a463842016-05-26 14:46:12843 ::gl::MockGLInterface* gl,
kkinnunenc8b449e1582015-11-02 07:57:51844 const FeatureInfo* feature_info,
845 AttribInfo* attribs,
846 size_t num_attribs,
847 UniformInfo* uniforms,
848 size_t num_uniforms,
849 VaryingInfo* varyings,
850 size_t num_varyings,
kkinnunen8cefb232015-12-04 09:36:31851 ProgramOutputInfo* program_outputs,
852 size_t num_program_outputs,
gman@chromium.org0abf43e32012-05-10 23:36:23853 GLuint service_id) {
thestige147d682017-05-05 07:31:31854 EXPECT_CALL(*gl, GetProgramiv(service_id, GL_LINK_STATUS, _))
855 .WillOnce(SetArgPointee<2>(1))
gman@chromium.org0abf43e32012-05-10 23:36:23856 .RetiresOnSaturation();
thestige147d682017-05-05 07:31:31857 EXPECT_CALL(*gl, GetProgramiv(service_id, GL_INFO_LOG_LENGTH, _))
858 .WillOnce(SetArgPointee<2>(0))
gman@chromium.org0abf43e32012-05-10 23:36:23859 .RetiresOnSaturation();
thestige147d682017-05-05 07:31:31860 EXPECT_CALL(*gl, GetProgramiv(service_id, GL_ACTIVE_ATTRIBUTES, _))
861 .WillOnce(SetArgPointee<2>(num_attribs))
gman@chromium.org0abf43e32012-05-10 23:36:23862 .RetiresOnSaturation();
863 size_t max_attrib_len = 0;
864 for (size_t ii = 0; ii < num_attribs; ++ii) {
865 size_t len = strlen(attribs[ii].name) + 1;
866 max_attrib_len = std::max(max_attrib_len, len);
867 }
thestige147d682017-05-05 07:31:31868 EXPECT_CALL(*gl, GetProgramiv(service_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _))
869 .WillOnce(SetArgPointee<2>(max_attrib_len))
gman@chromium.org0abf43e32012-05-10 23:36:23870 .RetiresOnSaturation();
gman@chromium.org3f00df92012-06-19 00:44:58871
gman@chromium.org0abf43e32012-05-10 23:36:23872 for (size_t ii = 0; ii < num_attribs; ++ii) {
873 const AttribInfo& info = attribs[ii];
874 EXPECT_CALL(*gl,
thestige147d682017-05-05 07:31:31875 GetActiveAttrib(service_id, ii, max_attrib_len, _, _, _, _))
gman@chromium.org0abf43e32012-05-10 23:36:23876 .WillOnce(DoAll(
thestige147d682017-05-05 07:31:31877 SetArgPointee<3>(strlen(info.name)), SetArgPointee<4>(info.size),
878 SetArgPointee<5>(info.type),
879 SetArrayArgument<6>(info.name, info.name + strlen(info.name) + 1)))
gman@chromium.org0abf43e32012-05-10 23:36:23880 .RetiresOnSaturation();
kkinnunen8cefb232015-12-04 09:36:31881 if (!ProgramManager::HasBuiltInPrefix(info.name)) {
gman@chromium.org0abf43e32012-05-10 23:36:23882 EXPECT_CALL(*gl, GetAttribLocation(service_id, StrEq(info.name)))
883 .WillOnce(Return(info.location))
884 .RetiresOnSaturation();
885 }
886 }
thestige147d682017-05-05 07:31:31887 EXPECT_CALL(*gl, GetProgramiv(service_id, GL_ACTIVE_UNIFORMS, _))
888 .WillOnce(SetArgPointee<2>(num_uniforms))
gman@chromium.org0abf43e32012-05-10 23:36:23889 .RetiresOnSaturation();
gman@chromium.org3f00df92012-06-19 00:44:58890
kkinnunen8fbcba142015-11-23 08:25:25891 if (num_uniforms > 0) {
892 size_t max_uniform_len = 0;
893 for (size_t ii = 0; ii < num_uniforms; ++ii) {
894 size_t len = strlen(uniforms[ii].name) + 1;
895 max_uniform_len = std::max(max_uniform_len, len);
896 }
897 EXPECT_CALL(*gl, GetProgramiv(service_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, _))
thestige147d682017-05-05 07:31:31898 .WillOnce(SetArgPointee<2>(max_uniform_len))
gman@chromium.org0abf43e32012-05-10 23:36:23899 .RetiresOnSaturation();
gman@chromium.org2be6abf32012-06-26 00:28:33900 for (size_t ii = 0; ii < num_uniforms; ++ii) {
901 const UniformInfo& info = uniforms[ii];
kkinnunen8fbcba142015-11-23 08:25:25902 EXPECT_CALL(*gl,
903 GetActiveUniform(service_id, ii, max_uniform_len, _, _, _, _))
thestige147d682017-05-05 07:31:31904 .WillOnce(DoAll(SetArgPointee<3>(strlen(info.name)),
905 SetArgPointee<4>(info.size),
906 SetArgPointee<5>(info.type),
kkinnunen8fbcba142015-11-23 08:25:25907 SetArrayArgument<6>(
908 info.name, info.name + strlen(info.name) + 1)))
909 .RetiresOnSaturation();
910
Bo Liu3d66a60a2017-06-26 22:26:35911 // Corresponds to early out in Program::UpdateUniforms
912 if (!info.size)
913 return;
914
kkinnunen8fbcba142015-11-23 08:25:25915 if (info.real_location != -1) {
gman@chromium.org2be6abf32012-06-26 00:28:33916 EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(info.name)))
917 .WillOnce(Return(info.real_location))
gman@chromium.org3f00df92012-06-19 00:44:58918 .RetiresOnSaturation();
gman@chromium.org0abf43e32012-05-10 23:36:23919 }
kkinnunen8fbcba142015-11-23 08:25:25920 if (info.size > 1) {
921 std::string base_name = info.name;
922 size_t array_pos = base_name.rfind("[0]");
923 if (base_name.size() > 3 && array_pos == base_name.size() - 3) {
924 base_name = base_name.substr(0, base_name.size() - 3);
925 }
926 for (GLsizei jj = 1; jj < info.size; ++jj) {
927 std::string element_name(std::string(base_name) + "[" +
Raul Tambre36584542019-02-07 23:42:08928 base::NumberToString(jj) + "]");
kkinnunen8fbcba142015-11-23 08:25:25929 EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(element_name)))
930 .WillOnce(Return(info.real_location + jj * 2))
931 .RetiresOnSaturation();
gman@chromium.org2be6abf32012-06-26 00:28:33932 }
933 }
gman@chromium.org0abf43e32012-05-10 23:36:23934 }
935 }
kkinnunenc8b449e1582015-11-02 07:57:51936
cwallez3b2dfed2016-06-27 20:03:27937 if (feature_info->gl_version_info().is_es3_capable &&
kkinnunen8cefb232015-12-04 09:36:31938 !feature_info->disable_shader_translator()) {
939 for (size_t ii = 0; ii < num_program_outputs; ++ii) {
940 ProgramOutputInfo& info = program_outputs[ii];
941 if (ProgramManager::HasBuiltInPrefix(info.name))
942 continue;
943
944 EXPECT_CALL(*gl, GetFragDataLocation(service_id, StrEq(info.name)))
945 .WillOnce(Return(info.color_name))
946 .RetiresOnSaturation();
947 if (feature_info->feature_flags().ext_blend_func_extended) {
948 EXPECT_CALL(*gl, GetFragDataIndex(service_id, StrEq(info.name)))
949 .WillOnce(Return(info.index))
950 .RetiresOnSaturation();
951 } else {
952 // Test case must not use indices, or the context of the testcase has to
953 // support the dual source blending.
954 DCHECK(info.index == 0);
955 }
kkinnunenc8b449e1582015-11-02 07:57:51956 }
957 }
gman@chromium.org0abf43e32012-05-10 23:36:23958}
959
kylechar7a463842016-05-26 14:46:12960void TestHelper::SetupShaderExpectations(::gl::MockGLInterface* gl,
kkinnunenc8b449e1582015-11-02 07:57:51961 const FeatureInfo* feature_info,
962 AttribInfo* attribs,
963 size_t num_attribs,
964 UniformInfo* uniforms,
965 size_t num_uniforms,
966 GLuint service_id) {
967 InSequence s;
968
969 EXPECT_CALL(*gl, LinkProgram(service_id)).Times(1).RetiresOnSaturation();
970
971 SetupProgramSuccessExpectations(gl, feature_info, attribs, num_attribs,
kkinnunen8cefb232015-12-04 09:36:31972 uniforms, num_uniforms, nullptr, 0, nullptr,
973 0, service_id);
kkinnunenc8b449e1582015-11-02 07:57:51974}
975
976void TestHelper::SetupShaderExpectationsWithVaryings(
kylechar7a463842016-05-26 14:46:12977 ::gl::MockGLInterface* gl,
kkinnunenc8b449e1582015-11-02 07:57:51978 const FeatureInfo* feature_info,
979 AttribInfo* attribs,
980 size_t num_attribs,
981 UniformInfo* uniforms,
982 size_t num_uniforms,
983 VaryingInfo* varyings,
984 size_t num_varyings,
kkinnunen8cefb232015-12-04 09:36:31985 ProgramOutputInfo* program_outputs,
986 size_t num_program_outputs,
dmurph@chromium.org65dfc602012-07-23 20:39:39987 GLuint service_id) {
988 InSequence s;
989
990 EXPECT_CALL(*gl,
991 LinkProgram(service_id))
992 .Times(1)
993 .RetiresOnSaturation();
994
kkinnunen8cefb232015-12-04 09:36:31995 SetupProgramSuccessExpectations(
996 gl, feature_info, attribs, num_attribs, uniforms, num_uniforms, varyings,
997 num_varyings, program_outputs, num_program_outputs, service_id);
dmurph@chromium.org65dfc602012-07-23 20:39:39998}
999
kylechar7a463842016-05-26 14:46:121000void TestHelper::DoBufferData(::gl::MockGLInterface* gl,
1001 MockErrorState* error_state,
1002 BufferManager* manager,
1003 Buffer* buffer,
1004 GLenum target,
1005 GLsizeiptr size,
1006 GLenum usage,
1007 const GLvoid* data,
1008 GLenum error) {
kloveless@chromium.orgd3eba342013-04-18 21:11:501009 EXPECT_CALL(*error_state, CopyRealGLErrorsToWrapper(_, _, _))
gman@chromium.org17cfbe0e2013-03-07 01:26:081010 .Times(1)
1011 .RetiresOnSaturation();
1012 if (manager->IsUsageClientSideArray(usage)) {
zmo4c0c3532015-05-22 20:04:481013 EXPECT_CALL(*gl, BufferData(target, 0, _, usage))
gman@chromium.org17cfbe0e2013-03-07 01:26:081014 .Times(1)
1015 .RetiresOnSaturation();
1016 } else {
zmo4c0c3532015-05-22 20:04:481017 EXPECT_CALL(*gl, BufferData(target, size, _, usage))
gman@chromium.org17cfbe0e2013-03-07 01:26:081018 .Times(1)
1019 .RetiresOnSaturation();
1020 }
kloveless@chromium.orgd3eba342013-04-18 21:11:501021 EXPECT_CALL(*error_state, PeekGLError(_, _, _))
gman@chromium.org17cfbe0e2013-03-07 01:26:081022 .WillOnce(Return(error))
1023 .RetiresOnSaturation();
zmo4c0c3532015-05-22 20:04:481024 manager->DoBufferData(error_state, buffer, target, size, usage, data);
gman@chromium.org17cfbe0e2013-03-07 01:26:081025}
1026
kylechar7a463842016-05-26 14:46:121027void TestHelper::SetTexParameteriWithExpectations(::gl::MockGLInterface* gl,
1028 MockErrorState* error_state,
1029 TextureManager* manager,
1030 TextureRef* texture_ref,
1031 GLenum pname,
1032 GLint value,
1033 GLenum error) {
gman@chromium.org02965c22013-03-09 02:40:071034 if (error == GL_NO_ERROR) {
ccamerondfb2f202015-10-09 23:17:591035 EXPECT_CALL(*gl, TexParameteri(texture_ref->texture()->target(),
1036 pname, value))
1037 .Times(1)
1038 .RetiresOnSaturation();
gman@chromium.org02965c22013-03-09 02:40:071039 } else if (error == GL_INVALID_ENUM) {
kloveless@chromium.orgd3eba342013-04-18 21:11:501040 EXPECT_CALL(*error_state, SetGLErrorInvalidEnum(_, _, _, value, _))
gman@chromium.org02965c22013-03-09 02:40:071041 .Times(1)
1042 .RetiresOnSaturation();
1043 } else {
zmo@chromium.org737191ee72014-03-09 08:02:421044 EXPECT_CALL(*error_state, SetGLErrorInvalidParami(_, _, error, _, _, _))
gman@chromium.org02965c22013-03-09 02:40:071045 .Times(1)
1046 .RetiresOnSaturation();
1047 }
zmo@chromium.org737191ee72014-03-09 08:02:421048 manager->SetParameteri("", error_state, texture_ref, pname, value);
gman@chromium.org02965c22013-03-09 02:40:071049}
1050
zmo576a0492014-09-13 01:12:321051// static
1052void TestHelper::SetShaderStates(
kylechar7a463842016-05-26 14:46:121053 ::gl::MockGLInterface* gl,
kkinnunen8cefb232015-12-04 09:36:311054 Shader* shader,
1055 bool expected_valid,
1056 const std::string* const expected_log_info,
1057 const std::string* const expected_translated_source,
1058 const int* const expected_shader_version,
1059 const AttributeMap* const expected_attrib_map,
1060 const UniformMap* const expected_uniform_map,
1061 const VaryingMap* const expected_varying_map,
1062 const InterfaceBlockMap* const expected_interface_block_map,
Geoff Lang30efb7b2017-08-09 14:59:231063 const OutputVariableList* const expected_output_variable_list,
1064 OptionsAffectingCompilationString* options_affecting_compilation) {
zmo576a0492014-09-13 01:12:321065 const std::string empty_log_info;
1066 const std::string* log_info = (expected_log_info && !expected_valid) ?
1067 expected_log_info : &empty_log_info;
1068 const std::string empty_translated_source;
1069 const std::string* translated_source =
1070 (expected_translated_source && expected_valid) ?
1071 expected_translated_source : &empty_translated_source;
oetuahoe6bdcf32015-05-07 16:45:251072 int default_shader_version = 100;
1073 const int* shader_version = (expected_shader_version && expected_valid) ?
1074 expected_shader_version : &default_shader_version;
zmo88043c082014-10-09 20:38:551075 const AttributeMap empty_attrib_map;
1076 const AttributeMap* attrib_map = (expected_attrib_map && expected_valid) ?
1077 expected_attrib_map : &empty_attrib_map;
1078 const UniformMap empty_uniform_map;
1079 const UniformMap* uniform_map = (expected_uniform_map && expected_valid) ?
1080 expected_uniform_map : &empty_uniform_map;
1081 const VaryingMap empty_varying_map;
1082 const VaryingMap* varying_map = (expected_varying_map && expected_valid) ?
1083 expected_varying_map : &empty_varying_map;
yunchao.hee4edccd2015-11-06 00:45:181084 const InterfaceBlockMap empty_interface_block_map;
1085 const InterfaceBlockMap* interface_block_map =
1086 (expected_interface_block_map && expected_valid) ?
1087 expected_interface_block_map : &empty_interface_block_map;
kkinnunen8cefb232015-12-04 09:36:311088 const OutputVariableList empty_output_variable_list;
1089 const OutputVariableList* output_variable_list =
1090 (expected_output_variable_list && expected_valid)
1091 ? expected_output_variable_list
1092 : &empty_output_variable_list;
zmo576a0492014-09-13 01:12:321093
dyen0ff9e4402015-02-12 22:27:431094 MockShaderTranslator* mock_translator = new MockShaderTranslator;
1095 scoped_refptr<ShaderTranslatorInterface> translator(mock_translator);
1096 EXPECT_CALL(*mock_translator, Translate(_,
kkinnunen8cefb232015-12-04 09:36:311097 NotNull(), // log_info
1098 NotNull(), // translated_source
1099 NotNull(), // shader_version
1100 NotNull(), // attrib_map
1101 NotNull(), // uniform_map
1102 NotNull(), // varying_map
1103 NotNull(), // interface_block_map
kainino78c79d22017-05-04 18:45:301104 NotNull())) // output_variable_list
thestige147d682017-05-05 07:31:311105 .WillOnce(DoAll(
1106 SetArgPointee<1>(*log_info), SetArgPointee<2>(*translated_source),
1107 SetArgPointee<3>(*shader_version), SetArgPointee<4>(*attrib_map),
1108 SetArgPointee<5>(*uniform_map), SetArgPointee<6>(*varying_map),
1109 SetArgPointee<7>(*interface_block_map),
1110 SetArgPointee<8>(*output_variable_list), Return(expected_valid)))
zmo576a0492014-09-13 01:12:321111 .RetiresOnSaturation();
Geoff Lang30efb7b2017-08-09 14:59:231112 EXPECT_CALL(*mock_translator, GetStringForOptionsThatWouldAffectCompilation())
1113 .WillOnce(Return(options_affecting_compilation))
1114 .RetiresOnSaturation();
zmo576a0492014-09-13 01:12:321115 if (expected_valid) {
tzikddef02182018-08-14 07:08:331116 EXPECT_CALL(*gl, ShaderSource(shader->service_id(), 1, _, nullptr))
zmo576a0492014-09-13 01:12:321117 .Times(1)
1118 .RetiresOnSaturation();
1119 EXPECT_CALL(*gl, CompileShader(shader->service_id()))
1120 .Times(1)
1121 .RetiresOnSaturation();
thestige147d682017-05-05 07:31:311122 EXPECT_CALL(*gl, GetShaderiv(shader->service_id(), GL_COMPILE_STATUS,
zmo576a0492014-09-13 01:12:321123 NotNull())) // status
thestige147d682017-05-05 07:31:311124 .WillOnce(SetArgPointee<2>(GL_TRUE))
zmo576a0492014-09-13 01:12:321125 .RetiresOnSaturation();
1126 }
dyen0ff9e4402015-02-12 22:27:431127 shader->RequestCompile(translator, Shader::kGL);
1128 shader->DoCompile();
zmo576a0492014-09-13 01:12:321129}
1130
1131// static
kylechar7a463842016-05-26 14:46:121132void TestHelper::SetShaderStates(::gl::MockGLInterface* gl,
1133 Shader* shader,
1134 bool valid) {
kkinnunen8cefb232015-12-04 09:36:311135 SetShaderStates(gl, shader, valid, nullptr, nullptr, nullptr, nullptr,
Geoff Lang30efb7b2017-08-09 14:59:231136 nullptr, nullptr, nullptr, nullptr, nullptr);
1137}
1138
1139// static
1140void TestHelper::SetShaderStates(
1141 ::gl::MockGLInterface* gl,
1142 Shader* shader,
1143 bool valid,
1144 const std::string& options_affecting_compilation) {
1145 scoped_refptr<OptionsAffectingCompilationString> options =
1146 base::MakeRefCounted<OptionsAffectingCompilationString>(
1147 options_affecting_compilation);
1148 SetShaderStates(gl, shader, valid, nullptr, nullptr, nullptr, nullptr,
1149 nullptr, nullptr, nullptr, nullptr, options.get());
zmo576a0492014-09-13 01:12:321150}
1151
zmo88043c082014-10-09 20:38:551152// static
1153sh::Attribute TestHelper::ConstructAttribute(
1154 GLenum type, GLint array_size, GLenum precision,
1155 bool static_use, const std::string& name) {
1156 return ConstructShaderVariable<sh::Attribute>(
1157 type, array_size, precision, static_use, name);
1158}
1159
1160// static
1161sh::Uniform TestHelper::ConstructUniform(
1162 GLenum type, GLint array_size, GLenum precision,
1163 bool static_use, const std::string& name) {
1164 return ConstructShaderVariable<sh::Uniform>(
1165 type, array_size, precision, static_use, name);
1166}
1167
1168// static
1169sh::Varying TestHelper::ConstructVarying(
1170 GLenum type, GLint array_size, GLenum precision,
1171 bool static_use, const std::string& name) {
1172 return ConstructShaderVariable<sh::Varying>(
1173 type, array_size, precision, static_use, name);
1174}
1175
Kai Ninomiyae9cc6302017-05-19 21:49:131176// static
1177sh::InterfaceBlockField TestHelper::ConstructInterfaceBlockField(
1178 GLenum type,
1179 GLint array_size,
1180 GLenum precision,
1181 bool static_use,
1182 const std::string& name) {
1183 return ConstructShaderVariable<sh::InterfaceBlockField>(
1184 type, array_size, precision, static_use, name);
1185}
1186
1187// static
1188sh::InterfaceBlock TestHelper::ConstructInterfaceBlock(
1189 GLint array_size,
1190 sh::BlockLayoutType layout,
1191 bool is_row_major_layout,
1192 bool static_use,
1193 const std::string& name,
1194 const std::string& instance_name,
1195 const std::vector<sh::InterfaceBlockField>& fields) {
1196 sh::InterfaceBlock var;
1197 var.arraySize = array_size;
1198 var.layout = layout;
1199 var.isRowMajorLayout = is_row_major_layout;
1200 var.staticUse = static_use;
1201 var.name = name;
1202 var.mappedName = name; // No name hashing.
1203 var.instanceName = instance_name;
1204 var.fields = fields;
1205 return var;
1206}
1207
kkinnunen8cefb232015-12-04 09:36:311208sh::OutputVariable TestHelper::ConstructOutputVariable(
1209 GLenum type,
1210 GLint array_size,
1211 GLenum precision,
1212 bool static_use,
1213 const std::string& name) {
1214 return ConstructShaderVariable<sh::OutputVariable>(
1215 type, array_size, precision, static_use, name);
1216}
1217
gman@chromium.org00f893d2010-08-24 18:55:491218} // namespace gles2
1219} // namespace gpu