blob: 6cbf7e6b34103a9a39f76f1e4288e95e09c92e8f [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 Madill776a75b2016-05-17 13:43:17 -040013#include "platform/Platform.h"
Jamie Madill8add0eb2014-08-26 13:16:35 -040014
Jamie Madill0dfa8072016-01-22 15:27:21 -050015namespace angle
16{
17
Jamie Madill9fc7b4c2016-06-08 15:30:14 -070018const GLColorRGB GLColorRGB::blue(0u, 0u, 255u);
19const GLColorRGB GLColorRGB::green(0u, 255u, 0u);
20const GLColorRGB GLColorRGB::red(255u, 0u, 0u);
21const GLColorRGB GLColorRGB::yellow(255u, 255u, 0);
22
Olli Etuahoa314b612016-03-10 16:43:00 +020023const GLColor GLColor::black = GLColor(0u, 0u, 0u, 255u);
Jamie Madill9b08a3d2016-06-08 15:30:12 -070024const GLColor GLColor::blue = GLColor(0u, 0u, 255u, 255u);
25const GLColor GLColor::cyan = GLColor(0u, 255u, 255u, 255u);
26const GLColor GLColor::green = GLColor(0u, 255u, 0u, 255u);
27const GLColor GLColor::red = GLColor(255u, 0u, 0u, 255u);
28const GLColor GLColor::yellow = GLColor(255u, 255u, 0, 255u);
Olli Etuaho190028d2016-05-13 12:11:29 +030029const GLColor GLColor::white = GLColor(255u, 255u, 255u, 255u);
Olli Etuahoa314b612016-03-10 16:43:00 +020030
Vincent Lang25ab4512016-05-13 18:13:59 +020031const GLColor16 GLColor16::white = GLColor16(65535u, 65535u, 65535u, 65535u);
32
Jamie Madill1fbc59f2016-02-24 15:25:51 -050033namespace
34{
35float ColorNorm(GLubyte channelValue)
36{
37 return static_cast<float>(channelValue) / 255.0f;
38}
Jamie Madill776a75b2016-05-17 13:43:17 -040039
40// Use a custom ANGLE platform class to capture and report internal errors.
41class TestPlatform : public angle::Platform
42{
43 public:
44 TestPlatform() : mIgnoreMessages(false) {}
45
46 void logError(const char *errorMessage) override;
47 void logWarning(const char *warningMessage) override;
48 void logInfo(const char *infoMessage) override;
49
50 void ignoreMessages();
51 void enableMessages();
52
53 private:
54 bool mIgnoreMessages;
55};
56
57void TestPlatform::logError(const char *errorMessage)
58{
59 if (mIgnoreMessages)
60 return;
61
62 FAIL() << errorMessage;
63}
64
65void TestPlatform::logWarning(const char *warningMessage)
66{
67 if (mIgnoreMessages)
68 return;
69
70 std::cerr << "Warning: " << warningMessage << std::endl;
71}
72
73void TestPlatform::logInfo(const char *infoMessage)
74{
75 if (mIgnoreMessages)
76 return;
77
78 angle::WriteDebugMessage("%s\n", infoMessage);
79}
80
81void TestPlatform::ignoreMessages()
82{
83 mIgnoreMessages = true;
84}
85
86void TestPlatform::enableMessages()
87{
88 mIgnoreMessages = false;
89}
90
91TestPlatform g_testPlatformInstance;
Jamie Madill1fbc59f2016-02-24 15:25:51 -050092} // anonymous namespace
93
Jamie Madill9fc7b4c2016-06-08 15:30:14 -070094GLColorRGB::GLColorRGB() : R(0), G(0), B(0)
95{
96}
97
98GLColorRGB::GLColorRGB(GLubyte r, GLubyte g, GLubyte b) : R(r), G(g), B(b)
99{
100}
101
Jamie Madill0dfa8072016-01-22 15:27:21 -0500102GLColor::GLColor() : R(0), G(0), B(0), A(0)
103{
104}
105
106GLColor::GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a)
107{
108}
109
Jamie Madille2509a32016-02-01 14:09:05 -0500110GLColor::GLColor(GLuint colorValue) : R(0), G(0), B(0), A(0)
111{
112 memcpy(&R, &colorValue, sizeof(GLuint));
113}
114
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500115Vector4 GLColor::toNormalizedVector() const
116{
117 return Vector4(ColorNorm(R), ColorNorm(G), ColorNorm(B), ColorNorm(A));
118}
119
Jamie Madill0dfa8072016-01-22 15:27:21 -0500120GLColor ReadColor(GLint x, GLint y)
121{
122 GLColor actual;
123 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &actual.R);
124 EXPECT_GL_NO_ERROR();
125 return actual;
126}
127
128bool operator==(const GLColor &a, const GLColor &b)
129{
130 return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
131}
132
133std::ostream &operator<<(std::ostream &ostream, const GLColor &color)
134{
135 ostream << "(" << static_cast<unsigned int>(color.R) << ", "
136 << static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B)
137 << ", " << static_cast<unsigned int>(color.A) << ")";
138 return ostream;
139}
140
Vincent Lang25ab4512016-05-13 18:13:59 +0200141GLColor16::GLColor16() : R(0), G(0), B(0), A(0)
142{
143}
144
145GLColor16::GLColor16(GLushort r, GLushort g, GLushort b, GLushort a) : R(r), G(g), B(b), A(a)
146{
147}
148
149GLColor16 ReadColor16(GLint x, GLint y)
150{
151 GLColor16 actual;
152 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_SHORT, &actual.R);
153 EXPECT_GL_NO_ERROR();
154 return actual;
155}
156
157bool operator==(const GLColor16 &a, const GLColor16 &b)
158{
159 return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
160}
161
162std::ostream &operator<<(std::ostream &ostream, const GLColor16 &color)
163{
164 ostream << "(" << static_cast<unsigned int>(color.R) << ", "
165 << static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B)
166 << ", " << static_cast<unsigned int>(color.A) << ")";
167 return ostream;
168}
169
Jamie Madill0dfa8072016-01-22 15:27:21 -0500170} // namespace angle
171
Jamie Madillfa05f602015-05-07 13:47:11 -0400172ANGLETest::ANGLETest()
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400173 : mEGLWindow(nullptr),
174 mWidth(16),
175 mHeight(16),
176 mIgnoreD3D11SDKLayersWarnings(false),
177 mQuadVertexBuffer(0)
Geoff Lang8a079e52013-10-18 16:13:33 -0400178{
Geoff Lang5ade8452015-09-02 11:00:30 -0400179 mEGLWindow =
180 new EGLWindow(GetParam().majorVersion, GetParam().minorVersion, GetParam().eglParameters);
Geoff Lang0d3683c2014-10-23 11:08:16 -0400181}
182
183ANGLETest::~ANGLETest()
184{
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400185 if (mQuadVertexBuffer)
186 {
187 glDeleteBuffers(1, &mQuadVertexBuffer);
188 }
Jamie Madill77a72f62015-04-14 11:18:32 -0400189 SafeDelete(mEGLWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400190}
191
Geoff Lang8a079e52013-10-18 16:13:33 -0400192void ANGLETest::SetUp()
193{
Jamie Madill776a75b2016-05-17 13:43:17 -0400194 angle::g_testPlatformInstance.enableMessages();
195
Corentin Wallezb44440d2015-07-22 17:54:20 -0400196 // Resize the window before creating the context so that the first make current
197 // sets the viewport and scissor box to the right size.
198 bool needSwap = false;
199 if (mOSWindow->getWidth() != mWidth || mOSWindow->getHeight() != mHeight)
Geoff Lang7f8dc492015-07-23 21:29:33 +0000200 {
Corentin Wallezb44440d2015-07-22 17:54:20 -0400201 if (!mOSWindow->resize(mWidth, mHeight))
202 {
203 FAIL() << "Failed to resize ANGLE test window.";
204 }
205 needSwap = true;
Geoff Lang7f8dc492015-07-23 21:29:33 +0000206 }
207
Geoff Lang8a079e52013-10-18 16:13:33 -0400208 if (!createEGLContext())
209 {
210 FAIL() << "egl context creation failed.";
211 }
Corentin Wallezb828b322015-07-16 17:51:30 -0400212
Corentin Wallezb44440d2015-07-22 17:54:20 -0400213 if (needSwap)
214 {
215 // Swap the buffers so that the default framebuffer picks up the resize
216 // which will allow follow-up test code to assume the framebuffer covers
217 // the whole window.
218 swapBuffers();
219 }
Corentin Wallez096725b2015-07-20 16:58:57 -0400220
Geoff Lang7f8dc492015-07-23 21:29:33 +0000221 // This Viewport command is not strictly necessary but we add it so that programs
222 // taking OpenGL traces can guess the size of the default framebuffer and show it
223 // in their UIs
224 glViewport(0, 0, mWidth, mHeight);
Jamie Madill508a5b72015-12-08 11:26:14 -0500225
226 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
227 angle::WriteDebugMessage("Entering %s.%s\n", info->test_case_name(), info->name());
Geoff Lang8a079e52013-10-18 16:13:33 -0400228}
229
230void ANGLETest::TearDown()
231{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800232 checkD3D11SDKLayersMessages();
233
Jamie Madill508a5b72015-12-08 11:26:14 -0500234 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
235 angle::WriteDebugMessage("Exiting %s.%s\n", info->test_case_name(), info->name());
236
Geoff Lang8a079e52013-10-18 16:13:33 -0400237 swapBuffers();
Jamie Madill9e16d402014-09-08 17:36:33 -0400238 mOSWindow->messageLoop();
239
Geoff Lang8a079e52013-10-18 16:13:33 -0400240 if (!destroyEGLContext())
241 {
242 FAIL() << "egl context destruction failed.";
243 }
Jamie Madill8add0eb2014-08-26 13:16:35 -0400244
245 // Check for quit message
246 Event myEvent;
247 while (mOSWindow->popEvent(&myEvent))
248 {
249 if (myEvent.Type == Event::EVENT_CLOSED)
250 {
251 exit(0);
252 }
253 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400254}
255
256void ANGLETest::swapBuffers()
257{
Jamie Madill77a72f62015-04-14 11:18:32 -0400258 if (mEGLWindow->isGLInitialized())
259 {
260 mEGLWindow->swap();
261 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400262}
263
Jamie Madill52b09c22016-04-11 14:12:31 -0400264// static
265std::array<Vector3, 6> ANGLETest::GetQuadVertices()
266{
267 std::array<Vector3, 6> vertices;
268 vertices[0] = Vector3(-1.0f, 1.0f, 0.5f);
269 vertices[1] = Vector3(-1.0f, -1.0f, 0.5f);
270 vertices[2] = Vector3(1.0f, -1.0f, 0.5f);
271 vertices[3] = Vector3(-1.0f, 1.0f, 0.5f);
272 vertices[4] = Vector3(1.0f, -1.0f, 0.5f);
273 vertices[5] = Vector3(1.0f, 1.0f, 0.5f);
274 return vertices;
275}
276
277void ANGLETest::setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale)
278{
279 if (mQuadVertexBuffer == 0)
280 {
281 glGenBuffers(1, &mQuadVertexBuffer);
282 }
283
284 auto quadVertices = GetQuadVertices();
285 for (Vector3 &vertex : quadVertices)
286 {
287 vertex.x *= positionAttribXYScale;
288 vertex.y *= positionAttribXYScale;
289 vertex.z = positionAttribZ;
290 }
291
292 glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer);
293 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 6, quadVertices.data(), GL_STATIC_DRAW);
294}
295
296// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200297void ANGLETest::drawQuad(GLuint program,
298 const std::string &positionAttribName,
299 GLfloat positionAttribZ)
300{
301 drawQuad(program, positionAttribName, positionAttribZ, 1.0f);
302}
303
Jamie Madill52b09c22016-04-11 14:12:31 -0400304// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200305void ANGLETest::drawQuad(GLuint program,
306 const std::string &positionAttribName,
307 GLfloat positionAttribZ,
308 GLfloat positionAttribXYScale)
Geoff Lang8a079e52013-10-18 16:13:33 -0400309{
Jamie Madill52b09c22016-04-11 14:12:31 -0400310 drawQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale, false);
311}
312
313void ANGLETest::drawQuad(GLuint program,
314 const std::string &positionAttribName,
315 GLfloat positionAttribZ,
316 GLfloat positionAttribXYScale,
317 bool useVertexBuffer)
318{
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200319 GLint previousProgram = 0;
320 glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgram);
321 if (previousProgram != static_cast<GLint>(program))
322 {
323 glUseProgram(program);
324 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400325
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200326 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
Geoff Lang8a079e52013-10-18 16:13:33 -0400327
Jamie Madill52b09c22016-04-11 14:12:31 -0400328 if (useVertexBuffer)
329 {
330 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
331 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
332 glBindBuffer(GL_ARRAY_BUFFER, 0);
333 }
334 else
335 {
336 auto quadVertices = GetQuadVertices();
337 for (Vector3 &vertex : quadVertices)
338 {
339 vertex.x *= positionAttribXYScale;
340 vertex.y *= positionAttribXYScale;
341 vertex.z = positionAttribZ;
342 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400343
Jamie Madill52b09c22016-04-11 14:12:31 -0400344 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, quadVertices.data());
345 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400346 glEnableVertexAttribArray(positionLocation);
347
348 glDrawArrays(GL_TRIANGLES, 0, 6);
349
350 glDisableVertexAttribArray(positionLocation);
351 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
352
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200353 if (previousProgram != static_cast<GLint>(program))
354 {
355 glUseProgram(previousProgram);
356 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400357}
358
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400359void ANGLETest::drawIndexedQuad(GLuint program,
360 const std::string &positionAttribName,
361 GLfloat positionAttribZ)
362{
363 drawIndexedQuad(program, positionAttribName, positionAttribZ, 1.0f);
364}
365
366void ANGLETest::drawIndexedQuad(GLuint program,
367 const std::string &positionAttribName,
368 GLfloat positionAttribZ,
369 GLfloat positionAttribXYScale)
370{
371 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
372
Jamie Madill52b09c22016-04-11 14:12:31 -0400373 GLint activeProgram = 0;
374 glGetIntegerv(GL_CURRENT_PROGRAM, &activeProgram);
375 if (static_cast<GLuint>(activeProgram) != program)
376 {
377 glUseProgram(program);
378 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400379
380 GLuint prevBinding = 0;
381 glGetIntegerv(GL_ARRAY_BUFFER_BINDING, reinterpret_cast<GLint *>(&prevBinding));
382
Jamie Madill52b09c22016-04-11 14:12:31 -0400383 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400384
385 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
386 glEnableVertexAttribArray(positionLocation);
387 glBindBuffer(GL_ARRAY_BUFFER, prevBinding);
388
389 const GLushort indices[] = {
390 0, 1, 2, 0, 2, 3,
391 };
392
393 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
394
395 glDisableVertexAttribArray(positionLocation);
396 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
397
Jamie Madill52b09c22016-04-11 14:12:31 -0400398 if (static_cast<GLuint>(activeProgram) != program)
399 {
400 glUseProgram(static_cast<GLuint>(activeProgram));
401 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400402}
403
Geoff Langefc551f2013-10-31 10:20:28 -0400404GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
405{
406 GLuint shader = glCreateShader(type);
407
408 const char *sourceArray[1] = { source.c_str() };
409 glShaderSource(shader, 1, sourceArray, NULL);
410 glCompileShader(shader);
411
412 GLint compileResult;
413 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
414
415 if (compileResult == 0)
416 {
417 GLint infoLogLength;
418 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
419
Jamie Madilld2c52e32015-10-14 17:07:05 -0400420 if (infoLogLength == 0)
421 {
422 std::cerr << "shader compilation failed with empty log." << std::endl;
423 }
424 else
425 {
426 std::vector<GLchar> infoLog(infoLogLength);
427 glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
Geoff Langefc551f2013-10-31 10:20:28 -0400428
Jamie Madilld2c52e32015-10-14 17:07:05 -0400429 std::cerr << "shader compilation failed: " << &infoLog[0];
430 }
Geoff Langefc551f2013-10-31 10:20:28 -0400431
432 glDeleteShader(shader);
433 shader = 0;
434 }
435
436 return shader;
437}
438
Austin Kinrossd544cc92016-01-11 15:26:42 -0800439void ANGLETest::checkD3D11SDKLayersMessages()
440{
441#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(NDEBUG)
442 // In debug D3D11 mode, check ID3D11InfoQueue to see if any D3D11 SDK Layers messages
443 // were outputted by the test
444 if (mIgnoreD3D11SDKLayersWarnings ||
445 mEGLWindow->getPlatform().renderer != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE ||
446 mEGLWindow->getDisplay() == EGL_NO_DISPLAY)
447 {
448 return;
449 }
450
451 const char *extensionString =
452 static_cast<const char *>(eglQueryString(mEGLWindow->getDisplay(), EGL_EXTENSIONS));
453 if (!strstr(extensionString, "EGL_EXT_device_query"))
454 {
455 return;
456 }
457
458 EGLAttrib device = 0;
459 EGLAttrib angleDevice = 0;
460
461 PFNEGLQUERYDISPLAYATTRIBEXTPROC queryDisplayAttribEXT;
462 PFNEGLQUERYDEVICEATTRIBEXTPROC queryDeviceAttribEXT;
463
464 queryDisplayAttribEXT = reinterpret_cast<PFNEGLQUERYDISPLAYATTRIBEXTPROC>(
465 eglGetProcAddress("eglQueryDisplayAttribEXT"));
466 queryDeviceAttribEXT = reinterpret_cast<PFNEGLQUERYDEVICEATTRIBEXTPROC>(
467 eglGetProcAddress("eglQueryDeviceAttribEXT"));
468 ASSERT_NE(nullptr, queryDisplayAttribEXT);
469 ASSERT_NE(nullptr, queryDeviceAttribEXT);
470
471 ASSERT_EGL_TRUE(queryDisplayAttribEXT(mEGLWindow->getDisplay(), EGL_DEVICE_EXT, &angleDevice));
472 ASSERT_EGL_TRUE(queryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(angleDevice),
473 EGL_D3D11_DEVICE_ANGLE, &device));
474 ID3D11Device *d3d11Device = reinterpret_cast<ID3D11Device *>(device);
475
476 ID3D11InfoQueue *infoQueue = nullptr;
477 HRESULT hr =
478 d3d11Device->QueryInterface(__uuidof(infoQueue), reinterpret_cast<void **>(&infoQueue));
479 if (SUCCEEDED(hr))
480 {
481 UINT64 numStoredD3DDebugMessages =
482 infoQueue->GetNumStoredMessagesAllowedByRetrievalFilter();
483
484 if (numStoredD3DDebugMessages > 0)
485 {
486 for (UINT64 i = 0; i < numStoredD3DDebugMessages; i++)
487 {
488 SIZE_T messageLength = 0;
489 hr = infoQueue->GetMessage(i, nullptr, &messageLength);
490
491 if (SUCCEEDED(hr))
492 {
493 D3D11_MESSAGE *pMessage =
494 reinterpret_cast<D3D11_MESSAGE *>(malloc(messageLength));
495 infoQueue->GetMessage(i, pMessage, &messageLength);
496
497 std::cout << "Message " << i << ":"
498 << " " << pMessage->pDescription << "\n";
499 free(pMessage);
500 }
501 }
502
503 FAIL() << numStoredD3DDebugMessages
504 << " D3D11 SDK Layers message(s) detected! Test Failed.\n";
505 }
506 }
507
508 SafeRelease(infoQueue);
509#endif
510}
511
Geoff Lang63046e22015-07-21 12:43:50 -0400512static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
513{
514 return strstr(allExtensions, extName.c_str()) != nullptr;
515}
516
Geoff Lang8a079e52013-10-18 16:13:33 -0400517bool ANGLETest::extensionEnabled(const std::string &extName)
518{
Geoff Lang63046e22015-07-21 12:43:50 -0400519 return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
520 extName);
521}
522
523bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
524{
525 return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
526}
527
528bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
529{
530 return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
Geoff Lang8a079e52013-10-18 16:13:33 -0400531}
532
Geoff Lang8a079e52013-10-18 16:13:33 -0400533void ANGLETest::setWindowWidth(int width)
534{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400535 mWidth = width;
Geoff Lang8a079e52013-10-18 16:13:33 -0400536}
537
538void ANGLETest::setWindowHeight(int height)
539{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400540 mHeight = height;
Geoff Lang8a079e52013-10-18 16:13:33 -0400541}
542
Geoff Langefc551f2013-10-31 10:20:28 -0400543void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400544{
Jamie Madill62af5462014-08-26 13:16:37 -0400545 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400546}
547
Geoff Langefc551f2013-10-31 10:20:28 -0400548void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400549{
Jamie Madill62af5462014-08-26 13:16:37 -0400550 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400551}
552
Geoff Langefc551f2013-10-31 10:20:28 -0400553void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400554{
Jamie Madill62af5462014-08-26 13:16:37 -0400555 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400556}
557
Geoff Langefc551f2013-10-31 10:20:28 -0400558void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400559{
Jamie Madill62af5462014-08-26 13:16:37 -0400560 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400561}
562
Geoff Langefc551f2013-10-31 10:20:28 -0400563void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400564{
Jamie Madill62af5462014-08-26 13:16:37 -0400565 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400566}
567
Geoff Langefc551f2013-10-31 10:20:28 -0400568void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400569{
Jamie Madill62af5462014-08-26 13:16:37 -0400570 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400571}
572
573void ANGLETest::setMultisampleEnabled(bool enabled)
574{
Jamie Madill62af5462014-08-26 13:16:37 -0400575 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400576}
577
Geoff Lang70d0f492015-12-10 17:45:46 -0500578void ANGLETest::setDebugEnabled(bool enabled)
579{
580 mEGLWindow->setDebugEnabled(enabled);
581}
582
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500583void ANGLETest::setNoErrorEnabled(bool enabled)
584{
585 mEGLWindow->setNoErrorEnabled(enabled);
586}
587
Geoff Lang8a079e52013-10-18 16:13:33 -0400588int ANGLETest::getClientVersion() const
589{
Geoff Lang5ade8452015-09-02 11:00:30 -0400590 return mEGLWindow->getClientMajorVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400591}
592
Vincent Lang25ab4512016-05-13 18:13:59 +0200593int ANGLETest::getClientMinorVersion() const
594{
595 return mEGLWindow->getClientMinorVersion();
596}
597
Geoff Langb9266272015-01-29 13:25:14 +0000598EGLWindow *ANGLETest::getEGLWindow() const
599{
600 return mEGLWindow;
601}
602
Geoff Lang8a079e52013-10-18 16:13:33 -0400603int ANGLETest::getWindowWidth() const
604{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400605 return mWidth;
Geoff Lang8a079e52013-10-18 16:13:33 -0400606}
607
608int ANGLETest::getWindowHeight() const
609{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400610 return mHeight;
Geoff Lang8a079e52013-10-18 16:13:33 -0400611}
612
Geoff Langefc551f2013-10-31 10:20:28 -0400613bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400614{
Jamie Madill62af5462014-08-26 13:16:37 -0400615 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400616}
617
618bool ANGLETest::createEGLContext()
619{
Jamie Madill62af5462014-08-26 13:16:37 -0400620 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400621}
622
623bool ANGLETest::destroyEGLContext()
624{
Jamie Madill62af5462014-08-26 13:16:37 -0400625 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400626 return true;
627}
Geoff Langbb134672013-10-23 13:06:46 -0400628
Geoff Lang0d3683c2014-10-23 11:08:16 -0400629bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400630{
631 mOSWindow = CreateOSWindow();
632 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
633 {
634 return false;
635 }
636
Geoff Lang0d3683c2014-10-23 11:08:16 -0400637 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400638
639 return true;
640}
641
Geoff Lang0d3683c2014-10-23 11:08:16 -0400642bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400643{
644 if (mOSWindow)
645 {
646 mOSWindow->destroy();
647 delete mOSWindow;
648 mOSWindow = NULL;
649 }
650
651 return true;
652}
653
Geoff Lang0d3683c2014-10-23 11:08:16 -0400654void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400655{
Jamie Madill4119ed32014-10-01 10:41:40 -0400656 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400657}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400658
Jamie Madill518b9fa2016-03-02 11:26:02 -0500659bool IsIntel()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500660{
661 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
662 return (rendererString.find("Intel") != std::string::npos);
663}
664
Yuly Novikovd3647802016-06-16 15:58:35 -0400665bool IsAdreno()
666{
667 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
668 return (rendererString.find("Adreno") != std::string::npos);
669}
670
Jamie Madill518b9fa2016-03-02 11:26:02 -0500671bool IsAMD()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500672{
673 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
674 return (rendererString.find("AMD") != std::string::npos) ||
675 (rendererString.find("ATI") != std::string::npos);
676}
677
Jamie Madill518b9fa2016-03-02 11:26:02 -0500678bool IsNVIDIA()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500679{
680 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
681 return (rendererString.find("NVIDIA") != std::string::npos);
682}
683
Jamie Madill518b9fa2016-03-02 11:26:02 -0500684bool IsD3D11()
Jamie Madilld55d2832015-10-27 13:59:19 -0400685{
686 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
687 return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos);
688}
689
Jamie Madill518b9fa2016-03-02 11:26:02 -0500690bool IsD3D11_FL93()
Jamie Madill9fc36822015-11-18 13:08:07 -0500691{
692 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
693 return (rendererString.find("Direct3D11 vs_4_0_") != std::string::npos);
694}
695
Jamie Madill518b9fa2016-03-02 11:26:02 -0500696bool IsD3D9()
Jamie Madill9fc36822015-11-18 13:08:07 -0500697{
698 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
699 return (rendererString.find("Direct3D9") != std::string::npos);
700}
701
Jamie Madill518b9fa2016-03-02 11:26:02 -0500702bool IsD3DSM3()
Jamie Madill9fc36822015-11-18 13:08:07 -0500703{
Jamie Madill518b9fa2016-03-02 11:26:02 -0500704 return IsD3D9() || IsD3D11_FL93();
Jamie Madill9fc36822015-11-18 13:08:07 -0500705}
706
Yuly Novikovd3647802016-06-16 15:58:35 -0400707bool IsAndroid()
708{
709#if defined(ANGLE_PLATFORM_ANDROID)
710 return true;
711#else
712 return false;
713#endif
714}
715
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400716bool IsLinux()
717{
718#if defined(ANGLE_PLATFORM_LINUX)
719 return true;
720#else
721 return false;
722#endif
723}
724
Jamie Madill518b9fa2016-03-02 11:26:02 -0500725bool IsOSX()
Ian Ewell292f0052016-02-04 10:37:32 -0500726{
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400727#if defined(ANGLE_PLATFORM_APPLE)
Ian Ewell292f0052016-02-04 10:37:32 -0500728 return true;
729#else
730 return false;
731#endif
732}
733
Jamie Madill518b9fa2016-03-02 11:26:02 -0500734bool ANGLETest::isOpenGL() const
735{
736 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
737}
738
Olli Etuaho87fc71c2016-05-11 14:25:21 +0300739bool ANGLETest::isGLES() const
740{
741 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE;
742}
743
Jamie Madillc3b9b262015-01-30 14:00:51 -0500744EGLint ANGLETest::getPlatformRenderer() const
745{
Jamie Madillf6859912015-01-30 17:05:35 -0500746 assert(mEGLWindow);
747 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500748}
749
Austin Kinrossd544cc92016-01-11 15:26:42 -0800750void ANGLETest::ignoreD3D11SDKLayersWarnings()
751{
752 // Some tests may need to disable the D3D11 SDK Layers Warnings checks
753 mIgnoreD3D11SDKLayersWarnings = true;
754}
755
Geoff Lang0d3683c2014-10-23 11:08:16 -0400756OSWindow *ANGLETest::mOSWindow = NULL;
757
758void ANGLETestEnvironment::SetUp()
759{
Jamie Madill776a75b2016-05-17 13:43:17 -0400760 mGLESLibrary.reset(angle::loadLibrary("libGLESv2"));
761 if (mGLESLibrary)
762 {
763 auto initFunc = reinterpret_cast<ANGLEPlatformInitializeFunc>(
764 mGLESLibrary->getSymbol("ANGLEPlatformInitialize"));
765 if (initFunc)
766 {
767 initFunc(&angle::g_testPlatformInstance);
768 }
769 }
770
Geoff Lang0d3683c2014-10-23 11:08:16 -0400771 if (!ANGLETest::InitTestWindow())
772 {
773 FAIL() << "Failed to create ANGLE test window.";
774 }
775}
776
777void ANGLETestEnvironment::TearDown()
778{
779 ANGLETest::DestroyTestWindow();
Jamie Madill776a75b2016-05-17 13:43:17 -0400780
781 if (mGLESLibrary)
782 {
783 auto shutdownFunc = reinterpret_cast<ANGLEPlatformShutdownFunc>(
784 mGLESLibrary->getSymbol("ANGLEPlatformShutdown"));
785 if (shutdownFunc)
786 {
787 shutdownFunc();
788 }
789 }
790}
791
792void IgnoreANGLEPlatformMessages()
793{
794 // Negative tests may trigger expected errors/warnings in the ANGLE Platform.
795 angle::g_testPlatformInstance.ignoreMessages();
Geoff Lang0d3683c2014-10-23 11:08:16 -0400796}