blob: c91dd60e5cf686844f34451a227a6728f66cd9f2 [file] [log] [blame]
Jamie Madill508a5b72015-12-08 11:26:14 -05001//
2// Copyright 2015 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
Geoff Lang8a079e52013-10-18 16:13:33 -040010#include "ANGLETest.h"
Jamie Madill62af5462014-08-26 13:16:37 -040011#include "EGLWindow.h"
Jamie Madill8add0eb2014-08-26 13:16:35 -040012#include "OSWindow.h"
Jamie Madill508a5b72015-12-08 11:26:14 -050013#include "system_utils.h"
Jamie Madill8add0eb2014-08-26 13:16:35 -040014
Jamie Madill0dfa8072016-01-22 15:27:21 -050015namespace angle
16{
17
Olli Etuahoa314b612016-03-10 16:43:00 +020018const GLColor GLColor::red = GLColor(255u, 0u, 0u, 255u);
19const GLColor GLColor::green = GLColor(0u, 255u, 0u, 255u);
20const GLColor GLColor::blue = GLColor(0u, 0u, 255u, 255u);
21const GLColor GLColor::cyan = GLColor(0u, 255u, 255u, 255u);
22const GLColor GLColor::black = GLColor(0u, 0u, 0u, 255u);
Olli Etuaho190028d2016-05-13 12:11:29 +030023const GLColor GLColor::white = GLColor(255u, 255u, 255u, 255u);
Olli Etuahoa314b612016-03-10 16:43:00 +020024
Jamie Madill1fbc59f2016-02-24 15:25:51 -050025namespace
26{
27float ColorNorm(GLubyte channelValue)
28{
29 return static_cast<float>(channelValue) / 255.0f;
30}
31} // anonymous namespace
32
Jamie Madill0dfa8072016-01-22 15:27:21 -050033GLColor::GLColor() : R(0), G(0), B(0), A(0)
34{
35}
36
37GLColor::GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a)
38{
39}
40
Jamie Madille2509a32016-02-01 14:09:05 -050041GLColor::GLColor(GLuint colorValue) : R(0), G(0), B(0), A(0)
42{
43 memcpy(&R, &colorValue, sizeof(GLuint));
44}
45
Jamie Madill1fbc59f2016-02-24 15:25:51 -050046Vector4 GLColor::toNormalizedVector() const
47{
48 return Vector4(ColorNorm(R), ColorNorm(G), ColorNorm(B), ColorNorm(A));
49}
50
Jamie Madill0dfa8072016-01-22 15:27:21 -050051GLColor ReadColor(GLint x, GLint y)
52{
53 GLColor actual;
54 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &actual.R);
55 EXPECT_GL_NO_ERROR();
56 return actual;
57}
58
59bool operator==(const GLColor &a, const GLColor &b)
60{
61 return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
62}
63
64std::ostream &operator<<(std::ostream &ostream, const GLColor &color)
65{
66 ostream << "(" << static_cast<unsigned int>(color.R) << ", "
67 << static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B)
68 << ", " << static_cast<unsigned int>(color.A) << ")";
69 return ostream;
70}
71
72} // namespace angle
73
Jamie Madillfa05f602015-05-07 13:47:11 -040074ANGLETest::ANGLETest()
Jamie Madillbc4c4bc2016-03-23 21:04:43 -040075 : mEGLWindow(nullptr),
76 mWidth(16),
77 mHeight(16),
78 mIgnoreD3D11SDKLayersWarnings(false),
79 mQuadVertexBuffer(0)
Geoff Lang8a079e52013-10-18 16:13:33 -040080{
Geoff Lang5ade8452015-09-02 11:00:30 -040081 mEGLWindow =
82 new EGLWindow(GetParam().majorVersion, GetParam().minorVersion, GetParam().eglParameters);
Geoff Lang0d3683c2014-10-23 11:08:16 -040083}
84
85ANGLETest::~ANGLETest()
86{
Jamie Madillbc4c4bc2016-03-23 21:04:43 -040087 if (mQuadVertexBuffer)
88 {
89 glDeleteBuffers(1, &mQuadVertexBuffer);
90 }
Jamie Madill77a72f62015-04-14 11:18:32 -040091 SafeDelete(mEGLWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -040092}
93
Geoff Lang8a079e52013-10-18 16:13:33 -040094void ANGLETest::SetUp()
95{
Corentin Wallezb44440d2015-07-22 17:54:20 -040096 // Resize the window before creating the context so that the first make current
97 // sets the viewport and scissor box to the right size.
98 bool needSwap = false;
99 if (mOSWindow->getWidth() != mWidth || mOSWindow->getHeight() != mHeight)
Geoff Lang7f8dc492015-07-23 21:29:33 +0000100 {
Corentin Wallezb44440d2015-07-22 17:54:20 -0400101 if (!mOSWindow->resize(mWidth, mHeight))
102 {
103 FAIL() << "Failed to resize ANGLE test window.";
104 }
105 needSwap = true;
Geoff Lang7f8dc492015-07-23 21:29:33 +0000106 }
107
Geoff Lang8a079e52013-10-18 16:13:33 -0400108 if (!createEGLContext())
109 {
110 FAIL() << "egl context creation failed.";
111 }
Corentin Wallezb828b322015-07-16 17:51:30 -0400112
Corentin Wallezb44440d2015-07-22 17:54:20 -0400113 if (needSwap)
114 {
115 // Swap the buffers so that the default framebuffer picks up the resize
116 // which will allow follow-up test code to assume the framebuffer covers
117 // the whole window.
118 swapBuffers();
119 }
Corentin Wallez096725b2015-07-20 16:58:57 -0400120
Geoff Lang7f8dc492015-07-23 21:29:33 +0000121 // This Viewport command is not strictly necessary but we add it so that programs
122 // taking OpenGL traces can guess the size of the default framebuffer and show it
123 // in their UIs
124 glViewport(0, 0, mWidth, mHeight);
Jamie Madill508a5b72015-12-08 11:26:14 -0500125
126 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
127 angle::WriteDebugMessage("Entering %s.%s\n", info->test_case_name(), info->name());
Geoff Lang8a079e52013-10-18 16:13:33 -0400128}
129
130void ANGLETest::TearDown()
131{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800132 checkD3D11SDKLayersMessages();
133
Jamie Madill508a5b72015-12-08 11:26:14 -0500134 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
135 angle::WriteDebugMessage("Exiting %s.%s\n", info->test_case_name(), info->name());
136
Geoff Lang8a079e52013-10-18 16:13:33 -0400137 swapBuffers();
Jamie Madill9e16d402014-09-08 17:36:33 -0400138 mOSWindow->messageLoop();
139
Geoff Lang8a079e52013-10-18 16:13:33 -0400140 if (!destroyEGLContext())
141 {
142 FAIL() << "egl context destruction failed.";
143 }
Jamie Madill8add0eb2014-08-26 13:16:35 -0400144
145 // Check for quit message
146 Event myEvent;
147 while (mOSWindow->popEvent(&myEvent))
148 {
149 if (myEvent.Type == Event::EVENT_CLOSED)
150 {
151 exit(0);
152 }
153 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400154}
155
156void ANGLETest::swapBuffers()
157{
Jamie Madill77a72f62015-04-14 11:18:32 -0400158 if (mEGLWindow->isGLInitialized())
159 {
160 mEGLWindow->swap();
161 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400162}
163
Jamie Madill52b09c22016-04-11 14:12:31 -0400164// static
165std::array<Vector3, 6> ANGLETest::GetQuadVertices()
166{
167 std::array<Vector3, 6> vertices;
168 vertices[0] = Vector3(-1.0f, 1.0f, 0.5f);
169 vertices[1] = Vector3(-1.0f, -1.0f, 0.5f);
170 vertices[2] = Vector3(1.0f, -1.0f, 0.5f);
171 vertices[3] = Vector3(-1.0f, 1.0f, 0.5f);
172 vertices[4] = Vector3(1.0f, -1.0f, 0.5f);
173 vertices[5] = Vector3(1.0f, 1.0f, 0.5f);
174 return vertices;
175}
176
177void ANGLETest::setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale)
178{
179 if (mQuadVertexBuffer == 0)
180 {
181 glGenBuffers(1, &mQuadVertexBuffer);
182 }
183
184 auto quadVertices = GetQuadVertices();
185 for (Vector3 &vertex : quadVertices)
186 {
187 vertex.x *= positionAttribXYScale;
188 vertex.y *= positionAttribXYScale;
189 vertex.z = positionAttribZ;
190 }
191
192 glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer);
193 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 6, quadVertices.data(), GL_STATIC_DRAW);
194}
195
196// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200197void ANGLETest::drawQuad(GLuint program,
198 const std::string &positionAttribName,
199 GLfloat positionAttribZ)
200{
201 drawQuad(program, positionAttribName, positionAttribZ, 1.0f);
202}
203
Jamie Madill52b09c22016-04-11 14:12:31 -0400204// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200205void ANGLETest::drawQuad(GLuint program,
206 const std::string &positionAttribName,
207 GLfloat positionAttribZ,
208 GLfloat positionAttribXYScale)
Geoff Lang8a079e52013-10-18 16:13:33 -0400209{
Jamie Madill52b09c22016-04-11 14:12:31 -0400210 drawQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale, false);
211}
212
213void ANGLETest::drawQuad(GLuint program,
214 const std::string &positionAttribName,
215 GLfloat positionAttribZ,
216 GLfloat positionAttribXYScale,
217 bool useVertexBuffer)
218{
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200219 GLint previousProgram = 0;
220 glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgram);
221 if (previousProgram != static_cast<GLint>(program))
222 {
223 glUseProgram(program);
224 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400225
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200226 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
Geoff Lang8a079e52013-10-18 16:13:33 -0400227
Jamie Madill52b09c22016-04-11 14:12:31 -0400228 if (useVertexBuffer)
229 {
230 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
231 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
232 glBindBuffer(GL_ARRAY_BUFFER, 0);
233 }
234 else
235 {
236 auto quadVertices = GetQuadVertices();
237 for (Vector3 &vertex : quadVertices)
238 {
239 vertex.x *= positionAttribXYScale;
240 vertex.y *= positionAttribXYScale;
241 vertex.z = positionAttribZ;
242 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400243
Jamie Madill52b09c22016-04-11 14:12:31 -0400244 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, quadVertices.data());
245 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400246 glEnableVertexAttribArray(positionLocation);
247
248 glDrawArrays(GL_TRIANGLES, 0, 6);
249
250 glDisableVertexAttribArray(positionLocation);
251 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
252
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200253 if (previousProgram != static_cast<GLint>(program))
254 {
255 glUseProgram(previousProgram);
256 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400257}
258
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400259void ANGLETest::drawIndexedQuad(GLuint program,
260 const std::string &positionAttribName,
261 GLfloat positionAttribZ)
262{
263 drawIndexedQuad(program, positionAttribName, positionAttribZ, 1.0f);
264}
265
266void ANGLETest::drawIndexedQuad(GLuint program,
267 const std::string &positionAttribName,
268 GLfloat positionAttribZ,
269 GLfloat positionAttribXYScale)
270{
271 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
272
Jamie Madill52b09c22016-04-11 14:12:31 -0400273 GLint activeProgram = 0;
274 glGetIntegerv(GL_CURRENT_PROGRAM, &activeProgram);
275 if (static_cast<GLuint>(activeProgram) != program)
276 {
277 glUseProgram(program);
278 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400279
280 GLuint prevBinding = 0;
281 glGetIntegerv(GL_ARRAY_BUFFER_BINDING, reinterpret_cast<GLint *>(&prevBinding));
282
Jamie Madill52b09c22016-04-11 14:12:31 -0400283 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400284
285 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
286 glEnableVertexAttribArray(positionLocation);
287 glBindBuffer(GL_ARRAY_BUFFER, prevBinding);
288
289 const GLushort indices[] = {
290 0, 1, 2, 0, 2, 3,
291 };
292
293 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
294
295 glDisableVertexAttribArray(positionLocation);
296 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
297
Jamie Madill52b09c22016-04-11 14:12:31 -0400298 if (static_cast<GLuint>(activeProgram) != program)
299 {
300 glUseProgram(static_cast<GLuint>(activeProgram));
301 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400302}
303
Geoff Langefc551f2013-10-31 10:20:28 -0400304GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
305{
306 GLuint shader = glCreateShader(type);
307
308 const char *sourceArray[1] = { source.c_str() };
309 glShaderSource(shader, 1, sourceArray, NULL);
310 glCompileShader(shader);
311
312 GLint compileResult;
313 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
314
315 if (compileResult == 0)
316 {
317 GLint infoLogLength;
318 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
319
Jamie Madilld2c52e32015-10-14 17:07:05 -0400320 if (infoLogLength == 0)
321 {
322 std::cerr << "shader compilation failed with empty log." << std::endl;
323 }
324 else
325 {
326 std::vector<GLchar> infoLog(infoLogLength);
327 glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
Geoff Langefc551f2013-10-31 10:20:28 -0400328
Jamie Madilld2c52e32015-10-14 17:07:05 -0400329 std::cerr << "shader compilation failed: " << &infoLog[0];
330 }
Geoff Langefc551f2013-10-31 10:20:28 -0400331
332 glDeleteShader(shader);
333 shader = 0;
334 }
335
336 return shader;
337}
338
Austin Kinrossd544cc92016-01-11 15:26:42 -0800339void ANGLETest::checkD3D11SDKLayersMessages()
340{
341#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(NDEBUG)
342 // In debug D3D11 mode, check ID3D11InfoQueue to see if any D3D11 SDK Layers messages
343 // were outputted by the test
344 if (mIgnoreD3D11SDKLayersWarnings ||
345 mEGLWindow->getPlatform().renderer != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE ||
346 mEGLWindow->getDisplay() == EGL_NO_DISPLAY)
347 {
348 return;
349 }
350
351 const char *extensionString =
352 static_cast<const char *>(eglQueryString(mEGLWindow->getDisplay(), EGL_EXTENSIONS));
353 if (!strstr(extensionString, "EGL_EXT_device_query"))
354 {
355 return;
356 }
357
358 EGLAttrib device = 0;
359 EGLAttrib angleDevice = 0;
360
361 PFNEGLQUERYDISPLAYATTRIBEXTPROC queryDisplayAttribEXT;
362 PFNEGLQUERYDEVICEATTRIBEXTPROC queryDeviceAttribEXT;
363
364 queryDisplayAttribEXT = reinterpret_cast<PFNEGLQUERYDISPLAYATTRIBEXTPROC>(
365 eglGetProcAddress("eglQueryDisplayAttribEXT"));
366 queryDeviceAttribEXT = reinterpret_cast<PFNEGLQUERYDEVICEATTRIBEXTPROC>(
367 eglGetProcAddress("eglQueryDeviceAttribEXT"));
368 ASSERT_NE(nullptr, queryDisplayAttribEXT);
369 ASSERT_NE(nullptr, queryDeviceAttribEXT);
370
371 ASSERT_EGL_TRUE(queryDisplayAttribEXT(mEGLWindow->getDisplay(), EGL_DEVICE_EXT, &angleDevice));
372 ASSERT_EGL_TRUE(queryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(angleDevice),
373 EGL_D3D11_DEVICE_ANGLE, &device));
374 ID3D11Device *d3d11Device = reinterpret_cast<ID3D11Device *>(device);
375
376 ID3D11InfoQueue *infoQueue = nullptr;
377 HRESULT hr =
378 d3d11Device->QueryInterface(__uuidof(infoQueue), reinterpret_cast<void **>(&infoQueue));
379 if (SUCCEEDED(hr))
380 {
381 UINT64 numStoredD3DDebugMessages =
382 infoQueue->GetNumStoredMessagesAllowedByRetrievalFilter();
383
384 if (numStoredD3DDebugMessages > 0)
385 {
386 for (UINT64 i = 0; i < numStoredD3DDebugMessages; i++)
387 {
388 SIZE_T messageLength = 0;
389 hr = infoQueue->GetMessage(i, nullptr, &messageLength);
390
391 if (SUCCEEDED(hr))
392 {
393 D3D11_MESSAGE *pMessage =
394 reinterpret_cast<D3D11_MESSAGE *>(malloc(messageLength));
395 infoQueue->GetMessage(i, pMessage, &messageLength);
396
397 std::cout << "Message " << i << ":"
398 << " " << pMessage->pDescription << "\n";
399 free(pMessage);
400 }
401 }
402
403 FAIL() << numStoredD3DDebugMessages
404 << " D3D11 SDK Layers message(s) detected! Test Failed.\n";
405 }
406 }
407
408 SafeRelease(infoQueue);
409#endif
410}
411
Geoff Lang63046e22015-07-21 12:43:50 -0400412static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
413{
414 return strstr(allExtensions, extName.c_str()) != nullptr;
415}
416
Geoff Lang8a079e52013-10-18 16:13:33 -0400417bool ANGLETest::extensionEnabled(const std::string &extName)
418{
Geoff Lang63046e22015-07-21 12:43:50 -0400419 return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
420 extName);
421}
422
423bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
424{
425 return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
426}
427
428bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
429{
430 return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
Geoff Lang8a079e52013-10-18 16:13:33 -0400431}
432
Geoff Lang8a079e52013-10-18 16:13:33 -0400433void ANGLETest::setWindowWidth(int width)
434{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400435 mWidth = width;
Geoff Lang8a079e52013-10-18 16:13:33 -0400436}
437
438void ANGLETest::setWindowHeight(int height)
439{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400440 mHeight = height;
Geoff Lang8a079e52013-10-18 16:13:33 -0400441}
442
Geoff Langefc551f2013-10-31 10:20:28 -0400443void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400444{
Jamie Madill62af5462014-08-26 13:16:37 -0400445 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400446}
447
Geoff Langefc551f2013-10-31 10:20:28 -0400448void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400449{
Jamie Madill62af5462014-08-26 13:16:37 -0400450 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400451}
452
Geoff Langefc551f2013-10-31 10:20:28 -0400453void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400454{
Jamie Madill62af5462014-08-26 13:16:37 -0400455 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400456}
457
Geoff Langefc551f2013-10-31 10:20:28 -0400458void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400459{
Jamie Madill62af5462014-08-26 13:16:37 -0400460 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400461}
462
Geoff Langefc551f2013-10-31 10:20:28 -0400463void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400464{
Jamie Madill62af5462014-08-26 13:16:37 -0400465 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400466}
467
Geoff Langefc551f2013-10-31 10:20:28 -0400468void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400469{
Jamie Madill62af5462014-08-26 13:16:37 -0400470 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400471}
472
473void ANGLETest::setMultisampleEnabled(bool enabled)
474{
Jamie Madill62af5462014-08-26 13:16:37 -0400475 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400476}
477
Geoff Lang70d0f492015-12-10 17:45:46 -0500478void ANGLETest::setDebugEnabled(bool enabled)
479{
480 mEGLWindow->setDebugEnabled(enabled);
481}
482
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500483void ANGLETest::setNoErrorEnabled(bool enabled)
484{
485 mEGLWindow->setNoErrorEnabled(enabled);
486}
487
Geoff Lang8a079e52013-10-18 16:13:33 -0400488int ANGLETest::getClientVersion() const
489{
Geoff Lang5ade8452015-09-02 11:00:30 -0400490 return mEGLWindow->getClientMajorVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400491}
492
Geoff Langb9266272015-01-29 13:25:14 +0000493EGLWindow *ANGLETest::getEGLWindow() const
494{
495 return mEGLWindow;
496}
497
Geoff Lang8a079e52013-10-18 16:13:33 -0400498int ANGLETest::getWindowWidth() const
499{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400500 return mWidth;
Geoff Lang8a079e52013-10-18 16:13:33 -0400501}
502
503int ANGLETest::getWindowHeight() const
504{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400505 return mHeight;
Geoff Lang8a079e52013-10-18 16:13:33 -0400506}
507
Geoff Langefc551f2013-10-31 10:20:28 -0400508bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400509{
Jamie Madill62af5462014-08-26 13:16:37 -0400510 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400511}
512
513bool ANGLETest::createEGLContext()
514{
Jamie Madill62af5462014-08-26 13:16:37 -0400515 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400516}
517
518bool ANGLETest::destroyEGLContext()
519{
Jamie Madill62af5462014-08-26 13:16:37 -0400520 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400521 return true;
522}
Geoff Langbb134672013-10-23 13:06:46 -0400523
Geoff Lang0d3683c2014-10-23 11:08:16 -0400524bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400525{
526 mOSWindow = CreateOSWindow();
527 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
528 {
529 return false;
530 }
531
Geoff Lang0d3683c2014-10-23 11:08:16 -0400532 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400533
534 return true;
535}
536
Geoff Lang0d3683c2014-10-23 11:08:16 -0400537bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400538{
539 if (mOSWindow)
540 {
541 mOSWindow->destroy();
542 delete mOSWindow;
543 mOSWindow = NULL;
544 }
545
546 return true;
547}
548
Geoff Lang0d3683c2014-10-23 11:08:16 -0400549void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400550{
Jamie Madill4119ed32014-10-01 10:41:40 -0400551 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400552}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400553
Jamie Madill518b9fa2016-03-02 11:26:02 -0500554bool IsIntel()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500555{
556 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
557 return (rendererString.find("Intel") != std::string::npos);
558}
559
Jamie Madill518b9fa2016-03-02 11:26:02 -0500560bool IsAMD()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500561{
562 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
563 return (rendererString.find("AMD") != std::string::npos) ||
564 (rendererString.find("ATI") != std::string::npos);
565}
566
Jamie Madill518b9fa2016-03-02 11:26:02 -0500567bool IsNVIDIA()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500568{
569 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
570 return (rendererString.find("NVIDIA") != std::string::npos);
571}
572
Jamie Madill518b9fa2016-03-02 11:26:02 -0500573bool IsD3D11()
Jamie Madilld55d2832015-10-27 13:59:19 -0400574{
575 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
576 return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos);
577}
578
Jamie Madill518b9fa2016-03-02 11:26:02 -0500579bool IsD3D11_FL93()
Jamie Madill9fc36822015-11-18 13:08:07 -0500580{
581 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
582 return (rendererString.find("Direct3D11 vs_4_0_") != std::string::npos);
583}
584
Jamie Madill518b9fa2016-03-02 11:26:02 -0500585bool IsD3D9()
Jamie Madill9fc36822015-11-18 13:08:07 -0500586{
587 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
588 return (rendererString.find("Direct3D9") != std::string::npos);
589}
590
Jamie Madill518b9fa2016-03-02 11:26:02 -0500591bool IsD3DSM3()
Jamie Madill9fc36822015-11-18 13:08:07 -0500592{
Jamie Madill518b9fa2016-03-02 11:26:02 -0500593 return IsD3D9() || IsD3D11_FL93();
Jamie Madill9fc36822015-11-18 13:08:07 -0500594}
595
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400596bool IsLinux()
597{
598#if defined(ANGLE_PLATFORM_LINUX)
599 return true;
600#else
601 return false;
602#endif
603}
604
Jamie Madill518b9fa2016-03-02 11:26:02 -0500605bool IsOSX()
Ian Ewell292f0052016-02-04 10:37:32 -0500606{
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400607#if defined(ANGLE_PLATFORM_APPLE)
Ian Ewell292f0052016-02-04 10:37:32 -0500608 return true;
609#else
610 return false;
611#endif
612}
613
Jamie Madill518b9fa2016-03-02 11:26:02 -0500614bool ANGLETest::isOpenGL() const
615{
616 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
617}
618
Olli Etuaho87fc71c2016-05-11 14:25:21 +0300619bool ANGLETest::isGLES() const
620{
621 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE;
622}
623
Jamie Madillc3b9b262015-01-30 14:00:51 -0500624EGLint ANGLETest::getPlatformRenderer() const
625{
Jamie Madillf6859912015-01-30 17:05:35 -0500626 assert(mEGLWindow);
627 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500628}
629
Austin Kinrossd544cc92016-01-11 15:26:42 -0800630void ANGLETest::ignoreD3D11SDKLayersWarnings()
631{
632 // Some tests may need to disable the D3D11 SDK Layers Warnings checks
633 mIgnoreD3D11SDKLayersWarnings = true;
634}
635
Geoff Lang0d3683c2014-10-23 11:08:16 -0400636OSWindow *ANGLETest::mOSWindow = NULL;
637
638void ANGLETestEnvironment::SetUp()
639{
640 if (!ANGLETest::InitTestWindow())
641 {
642 FAIL() << "Failed to create ANGLE test window.";
643 }
644}
645
646void ANGLETestEnvironment::TearDown()
647{
648 ANGLETest::DestroyTestWindow();
649}