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