1 //
2 // Copyright 2012 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // ANGLETest:
7 // Implementation of common ANGLE testing fixture.
8 //
9
10 #ifndef ANGLE_TESTS_ANGLE_TEST_H_
11 #define ANGLE_TESTS_ANGLE_TEST_H_
12
13 #include <gtest/gtest.h>
14 #include <algorithm>
15 #include <array>
16
17 #include "angle_test_configs.h"
18 #include "angle_test_platform.h"
19 #include "common/angleutils.h"
20 #include "common/system_utils.h"
21 #include "common/vector_utils.h"
22 #include "platform/PlatformMethods.h"
23 #include "util/EGLWindow.h"
24 #include "util/shader_utils.h"
25 #include "util/util_gl.h"
26
27 namespace angle
28 {
29 struct SystemInfo;
30 class RNG;
31 } // namespace angle
32
33 #define ASSERT_GL_TRUE(a) ASSERT_EQ(static_cast<GLboolean>(GL_TRUE), (a))
34 #define ASSERT_GL_FALSE(a) ASSERT_EQ(static_cast<GLboolean>(GL_FALSE), (a))
35 #define EXPECT_GL_TRUE(a) EXPECT_EQ(static_cast<GLboolean>(GL_TRUE), (a))
36 #define EXPECT_GL_FALSE(a) EXPECT_EQ(static_cast<GLboolean>(GL_FALSE), (a))
37
38 #define EXPECT_GL_ERROR(err) EXPECT_EQ(static_cast<GLenum>(err), glGetError())
39 #define EXPECT_GL_NO_ERROR() EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
40
41 #define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError())
42 #define ASSERT_GL_NO_ERROR() ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
43
44 #define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError())
45 #define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS)
46
47 // EGLBoolean is |unsigned int| but EGL_TRUE is 0, not 0u.
48 #define ASSERT_EGL_TRUE(a) ASSERT_EQ(static_cast<EGLBoolean>(EGL_TRUE), static_cast<EGLBoolean>(a))
49 #define ASSERT_EGL_FALSE(a) \
50 ASSERT_EQ(static_cast<EGLBoolean>(EGL_FALSE), static_cast<EGLBoolean>(a))
51 #define EXPECT_EGL_TRUE(a) EXPECT_EQ(static_cast<EGLBoolean>(EGL_TRUE), static_cast<EGLBoolean>(a))
52 #define EXPECT_EGL_FALSE(a) \
53 EXPECT_EQ(static_cast<EGLBoolean>(EGL_FALSE), static_cast<EGLBoolean>(a))
54
55 #define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError())
56 #define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS)
57
58 #define ASSERT_GLENUM_EQ(expected, actual) \
59 ASSERT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
60 #define EXPECT_GLENUM_EQ(expected, actual) \
61 EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
62 #define ASSERT_GLENUM_NE(expected, actual) \
63 ASSERT_NE(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
64 #define EXPECT_GLENUM_NE(expected, actual) \
65 EXPECT_NE(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
66
67 #define ASSERT_EGLENUM_EQ(expected, actual) \
68 ASSERT_EQ(static_cast<EGLenum>(expected), static_cast<EGLenum>(actual))
69 #define EXPECT_EGLENUM_EQ(expected, actual) \
70 EXPECT_EQ(static_cast<EGLenum>(expected), static_cast<EGLenum>(actual))
71
72 #define ASSERT_GL_FRAMEBUFFER_COMPLETE(framebuffer) \
73 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(framebuffer))
74 #define EXPECT_GL_FRAMEBUFFER_COMPLETE(framebuffer) \
75 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(framebuffer))
76
77 namespace angle
78 {
79 struct GLColorRGB
80 {
GLColorRGBGLColorRGB81 constexpr GLColorRGB() : R(0), G(0), B(0) {}
GLColorRGBGLColorRGB82 constexpr GLColorRGB(GLubyte r, GLubyte g, GLubyte b) : R(r), G(g), B(b) {}
83 GLColorRGB(const angle::Vector3 &floatColor);
84
dataGLColorRGB85 const GLubyte *data() const { return &R; }
dataGLColorRGB86 GLubyte *data() { return &R; }
87
88 GLubyte R, G, B;
89
90 static const GLColorRGB black;
91 static const GLColorRGB blue;
92 static const GLColorRGB green;
93 static const GLColorRGB red;
94 static const GLColorRGB yellow;
95 };
96
97 struct GLColor
98 {
GLColorGLColor99 constexpr GLColor() : R(0), G(0), B(0), A(0) {}
GLColorGLColor100 constexpr GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a) {}
101 GLColor(const angle::Vector4 &floatColor);
102 GLColor(GLuint colorValue);
103
104 angle::Vector4 toNormalizedVector() const;
105
106 GLubyte &operator[](size_t index) { return (&R)[index]; }
107
108 const GLubyte &operator[](size_t index) const { return (&R)[index]; }
109
dataGLColor110 const GLubyte *data() const { return &R; }
dataGLColor111 GLubyte *data() { return &R; }
112
113 testing::AssertionResult ExpectNear(const GLColor &expected, const GLColor &err) const;
114
115 GLubyte R, G, B, A;
116
117 static const GLColor black;
118 static const GLColor blue;
119 static const GLColor cyan;
120 static const GLColor green;
121 static const GLColor red;
122 static const GLColor transparentBlack;
123 static const GLColor white;
124 static const GLColor yellow;
125 static const GLColor magenta;
126 };
127
128 struct GLColor16UI
129 {
GLColor16UIGLColor16UI130 constexpr GLColor16UI() : GLColor16UI(0, 0, 0, 0) {}
GLColor16UIGLColor16UI131 constexpr GLColor16UI(GLushort r, GLushort g, GLushort b, GLushort a) : R(r), G(g), B(b), A(a)
132 {}
133
134 GLushort R, G, B, A;
135 };
136
137 struct GLColor32F
138 {
GLColor32FGLColor32F139 constexpr GLColor32F() : GLColor32F(0.0f, 0.0f, 0.0f, 0.0f) {}
GLColor32FGLColor32F140 constexpr GLColor32F(GLfloat r, GLfloat g, GLfloat b, GLfloat a) : R(r), G(g), B(b), A(a) {}
141
142 GLfloat R, G, B, A;
143 };
144
145 static constexpr GLColor32F kFloatBlack = {0.0f, 0.0f, 0.0f, 1.0f};
146 static constexpr GLColor32F kFloatRed = {1.0f, 0.0f, 0.0f, 1.0f};
147 static constexpr GLColor32F kFloatGreen = {0.0f, 1.0f, 0.0f, 1.0f};
148 static constexpr GLColor32F kFloatBlue = {0.0f, 0.0f, 1.0f, 1.0f};
149
150 // The input here for pixelPoints are the expected integer window coordinates, we add .5 to every
151 // one of them and re-scale the numbers to be between [-1,1]. Using this technique, we can make
152 // sure the rasterization stage will end up drawing pixels at the expected locations.
153 void CreatePixelCenterWindowCoords(const std::vector<Vector2> &pixelPoints,
154 int windowWidth,
155 int windowHeight,
156 std::vector<Vector3> *outVertices);
157
158 // Useful to cast any type to GLubyte.
159 template <typename TR, typename TG, typename TB, typename TA>
MakeGLColor(TR r,TG g,TB b,TA a)160 GLColor MakeGLColor(TR r, TG g, TB b, TA a)
161 {
162 return GLColor(static_cast<GLubyte>(r), static_cast<GLubyte>(g), static_cast<GLubyte>(b),
163 static_cast<GLubyte>(a));
164 }
165
166 GLColor RandomColor(angle::RNG *rng);
167
168 bool operator==(const GLColor &a, const GLColor &b);
169 bool operator!=(const GLColor &a, const GLColor &b);
170 std::ostream &operator<<(std::ostream &ostream, const GLColor &color);
171 GLColor ReadColor(GLint x, GLint y);
172
173 // Useful to cast any type to GLfloat.
174 template <typename TR, typename TG, typename TB, typename TA>
MakeGLColor32F(TR r,TG g,TB b,TA a)175 GLColor32F MakeGLColor32F(TR r, TG g, TB b, TA a)
176 {
177 return GLColor32F(static_cast<GLfloat>(r), static_cast<GLfloat>(g), static_cast<GLfloat>(b),
178 static_cast<GLfloat>(a));
179 }
180
181 bool operator==(const GLColor32F &a, const GLColor32F &b);
182 std::ostream &operator<<(std::ostream &ostream, const GLColor32F &color);
183 GLColor32F ReadColor32F(GLint x, GLint y);
184
185 constexpr std::array<GLenum, 6> kCubeFaces = {
186 {GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
187 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
188 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z}};
189
190 void LoadEntryPointsWithUtilLoader(angle::GLESDriverType driver);
191
192 } // namespace angle
193
194 #define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
195 EXPECT_EQ(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
196
197 #define EXPECT_PIXEL_NE(x, y, r, g, b, a) \
198 EXPECT_NE(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
199
200 #define EXPECT_PIXEL_32F_EQ(x, y, r, g, b, a) \
201 EXPECT_EQ(angle::MakeGLColor32F(r, g, b, a), angle::ReadColor32F(x, y))
202
203 #define EXPECT_PIXEL_ALPHA_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor(x, y).A)
204
205 #define EXPECT_PIXEL_ALPHA32F_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor32F(x, y).A)
206
207 #define EXPECT_PIXEL_COLOR_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor(x, y))
208 #define EXPECT_PIXEL_COLOR_EQ_VEC2(vec2, angleColor) \
209 EXPECT_EQ(angleColor, \
210 angle::ReadColor(static_cast<GLint>(vec2.x()), static_cast<GLint>(vec2.y())))
211
212 #define EXPECT_PIXEL_COLOR32F_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor32F(x, y))
213
214 #define EXPECT_PIXEL_RECT_EQ(x, y, width, height, color) \
215 do \
216 { \
217 std::vector<GLColor> actualColors(width *height); \
218 glReadPixels((x), (y), (width), (height), GL_RGBA, GL_UNSIGNED_BYTE, actualColors.data()); \
219 std::vector<GLColor> expectedColors(width *height, color); \
220 EXPECT_EQ(expectedColors, actualColors); \
221 } while (0)
222
223 #define EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, ctype, format, type) \
224 do \
225 { \
226 ctype pixel[4]; \
227 glReadPixels((x), (y), 1, 1, format, type, pixel); \
228 EXPECT_GL_NO_ERROR(); \
229 EXPECT_NEAR((r), pixel[0], abs_error); \
230 EXPECT_NEAR((g), pixel[1], abs_error); \
231 EXPECT_NEAR((b), pixel[2], abs_error); \
232 EXPECT_NEAR((a), pixel[3], abs_error); \
233 } while (0)
234
235 #define EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, ctype, format, type) \
236 do \
237 { \
238 ctype pixel[4]; \
239 glReadPixels((x), (y), 1, 1, format, type, pixel); \
240 EXPECT_GL_NO_ERROR(); \
241 EXPECT_EQ((r), pixel[0]); \
242 EXPECT_EQ((g), pixel[1]); \
243 EXPECT_EQ((b), pixel[2]); \
244 EXPECT_EQ((a), pixel[3]); \
245 } while (0)
246
247 #define EXPECT_PIXEL_RGB_EQ_HELPER(x, y, r, g, b, ctype, format, type) \
248 do \
249 { \
250 ctype pixel[4]; \
251 glReadPixels((x), (y), 1, 1, format, type, pixel); \
252 EXPECT_GL_NO_ERROR(); \
253 EXPECT_EQ((r), pixel[0]); \
254 EXPECT_EQ((g), pixel[1]); \
255 EXPECT_EQ((b), pixel[2]); \
256 } while (0)
257
258 #define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \
259 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLubyte, GL_RGBA, GL_UNSIGNED_BYTE)
260
261 #define EXPECT_PIXEL_32F_NEAR(x, y, r, g, b, a, abs_error) \
262 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLfloat, GL_RGBA, GL_FLOAT)
263
264 #define EXPECT_PIXEL_8I(x, y, r, g, b, a) \
265 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLbyte, GL_RGBA_INTEGER, GL_BYTE)
266
267 #define EXPECT_PIXEL_8UI(x, y, r, g, b, a) \
268 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLubyte, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE)
269
270 #define EXPECT_PIXEL_16UI(x, y, r, g, b, a) \
271 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLushort, GL_RGBA, GL_UNSIGNED_SHORT)
272
273 #define EXPECT_PIXEL_16UI_COLOR(x, y, color) \
274 EXPECT_PIXEL_16UI(x, y, color.R, color.G, color.B, color.A)
275
276 #define EXPECT_PIXEL_RGB_EQUAL(x, y, r, g, b) \
277 EXPECT_PIXEL_RGB_EQ_HELPER(x, y, r, g, b, GLubyte, GL_RGBA, GL_UNSIGNED_BYTE)
278
279 // TODO(jmadill): Figure out how we can use GLColor's nice printing with EXPECT_NEAR.
280 #define EXPECT_PIXEL_COLOR_NEAR(x, y, angleColor, abs_error) \
281 EXPECT_PIXEL_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
282
283 #define EXPECT_PIXEL_COLOR32F_NEAR(x, y, angleColor, abs_error) \
284 EXPECT_PIXEL32F_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
285
286 #define EXPECT_COLOR_NEAR(expected, actual, abs_error) \
287 do \
288 { \
289 EXPECT_NEAR(expected.R, actual.R, abs_error); \
290 EXPECT_NEAR(expected.G, actual.G, abs_error); \
291 EXPECT_NEAR(expected.B, actual.B, abs_error); \
292 EXPECT_NEAR(expected.A, actual.A, abs_error); \
293 } while (0)
294 #define EXPECT_PIXEL32F_NEAR(x, y, r, g, b, a, abs_error) \
295 do \
296 { \
297 GLfloat pixel[4]; \
298 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_FLOAT, pixel); \
299 EXPECT_GL_NO_ERROR(); \
300 EXPECT_NEAR((r), pixel[0], abs_error); \
301 EXPECT_NEAR((g), pixel[1], abs_error); \
302 EXPECT_NEAR((b), pixel[2], abs_error); \
303 EXPECT_NEAR((a), pixel[3], abs_error); \
304 } while (0)
305
306 #define EXPECT_PIXEL_COLOR32F_NEAR(x, y, angleColor, abs_error) \
307 EXPECT_PIXEL32F_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
308
309 class ANGLETestBase;
310 class EGLWindow;
311 class GLWindowBase;
312 class OSWindow;
313 class WGLWindow;
314
315 struct TestPlatformContext final : private angle::NonCopyable
316 {
317 bool ignoreMessages = false;
318 bool warningsAsErrors = false;
319 ANGLETestBase *currentTest = nullptr;
320 };
321
322 class ANGLETestBase
323 {
324 protected:
325 ANGLETestBase(const angle::PlatformParameters ¶ms);
326 virtual ~ANGLETestBase();
327
328 public:
329 void setWindowVisible(OSWindow *osWindow, bool isVisible);
330
overrideWorkaroundsD3D(angle::FeaturesD3D * featuresD3D)331 virtual void overrideWorkaroundsD3D(angle::FeaturesD3D *featuresD3D) {}
overrideFeaturesVk(angle::FeaturesVk * featuresVulkan)332 virtual void overrideFeaturesVk(angle::FeaturesVk *featuresVulkan) {}
333
334 static void ReleaseFixtures();
335
isSwiftshader()336 bool isSwiftshader() const
337 {
338 // Renderer might be swiftshader even if local swiftshader not used.
339 return mCurrentParams->isSwiftshader() || angle::IsSwiftshaderDevice();
340 }
341
enableDebugLayers()342 bool enableDebugLayers() const
343 {
344 return mCurrentParams->eglParameters.debugLayersEnabled != EGL_FALSE;
345 }
346
347 protected:
348 void ANGLETestSetUp();
349 void ANGLETestTearDown();
350
351 virtual void swapBuffers();
352
353 void setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale);
354 void setupIndexedQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale);
355 void setupIndexedQuadIndexBuffer();
356
357 void drawQuad(GLuint program, const std::string &positionAttribName, GLfloat positionAttribZ);
358 void drawQuad(GLuint program,
359 const std::string &positionAttribName,
360 GLfloat positionAttribZ,
361 GLfloat positionAttribXYScale);
362 void drawQuad(GLuint program,
363 const std::string &positionAttribName,
364 GLfloat positionAttribZ,
365 GLfloat positionAttribXYScale,
366 bool useVertexBuffer);
367 void drawQuadInstanced(GLuint program,
368 const std::string &positionAttribName,
369 GLfloat positionAttribZ,
370 GLfloat positionAttribXYScale,
371 bool useVertexBuffer,
372 GLuint numInstances);
373
374 static std::array<angle::Vector3, 6> GetQuadVertices();
375 static std::array<GLushort, 6> GetQuadIndices();
376 static std::array<angle::Vector3, 4> GetIndexedQuadVertices();
377
378 void drawIndexedQuad(GLuint program,
379 const std::string &positionAttribName,
380 GLfloat positionAttribZ);
381 void drawIndexedQuad(GLuint program,
382 const std::string &positionAttribName,
383 GLfloat positionAttribZ,
384 GLfloat positionAttribXYScale);
385 void drawIndexedQuad(GLuint program,
386 const std::string &positionAttribName,
387 GLfloat positionAttribZ,
388 GLfloat positionAttribXYScale,
389 bool useBufferObject);
390
391 void drawIndexedQuad(GLuint program,
392 const std::string &positionAttribName,
393 GLfloat positionAttribZ,
394 GLfloat positionAttribXYScale,
395 bool useBufferObject,
396 bool restrictedRange);
397
398 void draw2DTexturedQuad(GLfloat positionAttribZ,
399 GLfloat positionAttribXYScale,
400 bool useVertexBuffer);
401
402 // The layer parameter chooses the 3D texture layer to sample from.
403 void draw3DTexturedQuad(GLfloat positionAttribZ,
404 GLfloat positionAttribXYScale,
405 bool useVertexBuffer,
406 float layer);
407
408 void setWindowWidth(int width);
409 void setWindowHeight(int height);
410 void setConfigRedBits(int bits);
411 void setConfigGreenBits(int bits);
412 void setConfigBlueBits(int bits);
413 void setConfigAlphaBits(int bits);
414 void setConfigDepthBits(int bits);
415 void setConfigStencilBits(int bits);
416 void setConfigComponentType(EGLenum componentType);
417 void setMultisampleEnabled(bool enabled);
418 void setSamples(EGLint samples);
419 void setDebugEnabled(bool enabled);
420 void setNoErrorEnabled(bool enabled);
421 void setWebGLCompatibilityEnabled(bool webglCompatibility);
422 void setExtensionsEnabled(bool extensionsEnabled);
423 void setRobustAccess(bool enabled);
424 void setBindGeneratesResource(bool bindGeneratesResource);
425 void setClientArraysEnabled(bool enabled);
426 void setRobustResourceInit(bool enabled);
427 void setContextProgramCacheEnabled(bool enabled);
428 void setContextResetStrategy(EGLenum resetStrategy);
429 void forceNewDisplay();
430
431 // Some EGL extension tests would like to defer the Context init until the test body.
432 void setDeferContextInit(bool enabled);
433
434 int getClientMajorVersion() const;
435 int getClientMinorVersion() const;
436
437 GLWindowBase *getGLWindow() const;
438 EGLWindow *getEGLWindow() const;
439 int getWindowWidth() const;
440 int getWindowHeight() const;
441 bool isMultisampleEnabled() const;
442
443 EGLint getPlatformRenderer() const;
444
445 void ignoreD3D11SDKLayersWarnings();
446
447 // Allows a test to be more restrictive about platform warnings.
448 void treatPlatformWarningsAsErrors();
449
getOSWindow()450 OSWindow *getOSWindow() { return mFixture->osWindow; }
451
452 GLuint get2DTexturedQuadProgram();
453
454 // Has a float uniform "u_layer" to choose the 3D texture layer.
455 GLuint get3DTexturedQuadProgram();
456
457 class ScopedIgnorePlatformMessages : angle::NonCopyable
458 {
459 public:
460 ScopedIgnorePlatformMessages();
461 ~ScopedIgnorePlatformMessages();
462 };
463
464 // Can be used before we get a GL context.
isGLRenderer()465 bool isGLRenderer() const
466 {
467 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
468 }
469
isGLESRenderer()470 bool isGLESRenderer() const
471 {
472 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE;
473 }
474
isD3D11Renderer()475 bool isD3D11Renderer() const
476 {
477 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE;
478 }
479
isVulkanRenderer()480 bool isVulkanRenderer() const
481 {
482 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE;
483 }
484
isVulkanSwiftshaderRenderer()485 bool isVulkanSwiftshaderRenderer() const
486 {
487 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE &&
488 mCurrentParams->isSwiftshader();
489 }
490
491 bool platformSupportsMultithreading() const;
492
493 private:
494 void checkD3D11SDKLayersMessages();
495
496 void drawQuad(GLuint program,
497 const std::string &positionAttribName,
498 GLfloat positionAttribZ,
499 GLfloat positionAttribXYScale,
500 bool useVertexBuffer,
501 bool useInstancedDrawCalls,
502 GLuint numInstances);
503
504 void initOSWindow();
505
506 struct TestFixture
507 {
508 TestFixture();
509 ~TestFixture();
510
511 EGLWindow *eglWindow = nullptr;
512 WGLWindow *wglWindow = nullptr;
513 OSWindow *osWindow = nullptr;
514 ConfigParameters configParams;
515 uint32_t reuseCounter = 0;
516 };
517
518 int mWidth;
519 int mHeight;
520
521 bool mIgnoreD3D11SDKLayersWarnings;
522
523 // Used for indexed quad rendering
524 GLuint mQuadVertexBuffer;
525 GLuint mQuadIndexBuffer;
526
527 // Used for texture rendering.
528 GLuint m2DTexturedQuadProgram;
529 GLuint m3DTexturedQuadProgram;
530
531 bool mDeferContextInit;
532 bool mAlwaysForceNewDisplay;
533 bool mForceNewDisplay;
534
535 bool mSetUpCalled;
536 bool mTearDownCalled;
537
538 // Usually, we use an OS Window per "fixture" (a frontend and backend combination).
539 // This allows:
540 // 1. Reusing EGL Display on Windows.
541 // Other platforms have issues with display reuse even if a window per fixture is used.
542 // 2. Hiding only SwiftShader OS Window on Linux.
543 // OS Windows for other backends must be visible, to allow driver to communicate with X11.
544 // However, we must use a single OS Window for all backends on Android,
545 // since test Application can have only one window.
546 static OSWindow *mOSWindowSingleton;
547
548 static std::map<angle::PlatformParameters, TestFixture> gFixtures;
549 const angle::PlatformParameters *mCurrentParams;
550 TestFixture *mFixture;
551
552 // Workaround for NVIDIA not being able to share a window with OpenGL and Vulkan.
553 static Optional<EGLint> mLastRendererType;
554 static Optional<angle::GLESDriverType> mLastLoadedDriver;
555 };
556
557 template <typename Params = angle::PlatformParameters>
558 class ANGLETestWithParam : public ANGLETestBase, public ::testing::TestWithParam<Params>
559 {
560 protected:
561 ANGLETestWithParam();
562
testSetUp()563 virtual void testSetUp() {}
testTearDown()564 virtual void testTearDown() {}
565
recreateTestFixture()566 void recreateTestFixture()
567 {
568 TearDown();
569 SetUp();
570 }
571
572 private:
SetUp()573 void SetUp() final
574 {
575 ANGLETestBase::ANGLETestSetUp();
576 testSetUp();
577 }
578
TearDown()579 void TearDown() final
580 {
581 testTearDown();
582 ANGLETestBase::ANGLETestTearDown();
583 }
584 };
585
586 template <typename Params>
ANGLETestWithParam()587 ANGLETestWithParam<Params>::ANGLETestWithParam()
588 : ANGLETestBase(std::get<angle::PlatformParameters>(this->GetParam()))
589 {}
590
591 template <>
ANGLETestWithParam()592 inline ANGLETestWithParam<angle::PlatformParameters>::ANGLETestWithParam()
593 : ANGLETestBase(this->GetParam())
594 {}
595
596 // Note: this hack is not necessary in C++17. Once we switch to C++17, we can just rename
597 // ANGLETestWithParam to ANGLETest.
598 using ANGLETest = ANGLETestWithParam<>;
599
600 class ANGLETestEnvironment : public testing::Environment
601 {
602 public:
603 void SetUp() override;
604 void TearDown() override;
605
606 static angle::Library *GetDriverLibrary(angle::GLESDriverType driver);
607
608 private:
609 static angle::Library *GetAngleEGLLibrary();
610 static angle::Library *GetSystemEGLLibrary();
611 static angle::Library *GetSystemWGLLibrary();
612
613 // For loading entry points.
614 static std::unique_ptr<angle::Library> gAngleEGLLibrary;
615 static std::unique_ptr<angle::Library> gSystemEGLLibrary;
616 static std::unique_ptr<angle::Library> gSystemWGLLibrary;
617 };
618
619 extern angle::PlatformMethods gDefaultPlatformMethods;
620
621 #endif // ANGLE_TESTS_ANGLE_TEST_H_
622