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