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