blob: d7b43e749d545cd332ae54fb6c11bfcbe52416e1 [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
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}
Jamie Madill776a75b2016-05-17 13:43:17 -040031
32// Use a custom ANGLE platform class to capture and report internal errors.
33class TestPlatform : public angle::Platform
34{
35 public:
36 TestPlatform() : mIgnoreMessages(false) {}
37
38 void logError(const char *errorMessage) override;
39 void logWarning(const char *warningMessage) override;
40 void logInfo(const char *infoMessage) override;
41
42 void ignoreMessages();
43 void enableMessages();
44
45 private:
46 bool mIgnoreMessages;
47};
48
49void TestPlatform::logError(const char *errorMessage)
50{
51 if (mIgnoreMessages)
52 return;
53
54 FAIL() << errorMessage;
55}
56
57void TestPlatform::logWarning(const char *warningMessage)
58{
59 if (mIgnoreMessages)
60 return;
61
62 std::cerr << "Warning: " << warningMessage << std::endl;
63}
64
65void TestPlatform::logInfo(const char *infoMessage)
66{
67 if (mIgnoreMessages)
68 return;
69
70 angle::WriteDebugMessage("%s\n", infoMessage);
71}
72
73void TestPlatform::ignoreMessages()
74{
75 mIgnoreMessages = true;
76}
77
78void TestPlatform::enableMessages()
79{
80 mIgnoreMessages = false;
81}
82
83TestPlatform g_testPlatformInstance;
Jamie Madill1fbc59f2016-02-24 15:25:51 -050084} // anonymous namespace
85
Jamie Madill0dfa8072016-01-22 15:27:21 -050086GLColor::GLColor() : R(0), G(0), B(0), A(0)
87{
88}
89
90GLColor::GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a)
91{
92}
93
Jamie Madille2509a32016-02-01 14:09:05 -050094GLColor::GLColor(GLuint colorValue) : R(0), G(0), B(0), A(0)
95{
96 memcpy(&R, &colorValue, sizeof(GLuint));
97}
98
Jamie Madill1fbc59f2016-02-24 15:25:51 -050099Vector4 GLColor::toNormalizedVector() const
100{
101 return Vector4(ColorNorm(R), ColorNorm(G), ColorNorm(B), ColorNorm(A));
102}
103
Jamie Madill0dfa8072016-01-22 15:27:21 -0500104GLColor ReadColor(GLint x, GLint y)
105{
106 GLColor actual;
107 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &actual.R);
108 EXPECT_GL_NO_ERROR();
109 return actual;
110}
111
112bool operator==(const GLColor &a, const GLColor &b)
113{
114 return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
115}
116
117std::ostream &operator<<(std::ostream &ostream, const GLColor &color)
118{
119 ostream << "(" << static_cast<unsigned int>(color.R) << ", "
120 << static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B)
121 << ", " << static_cast<unsigned int>(color.A) << ")";
122 return ostream;
123}
124
125} // namespace angle
126
Jamie Madillfa05f602015-05-07 13:47:11 -0400127ANGLETest::ANGLETest()
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400128 : mEGLWindow(nullptr),
129 mWidth(16),
130 mHeight(16),
131 mIgnoreD3D11SDKLayersWarnings(false),
132 mQuadVertexBuffer(0)
Geoff Lang8a079e52013-10-18 16:13:33 -0400133{
Geoff Lang5ade8452015-09-02 11:00:30 -0400134 mEGLWindow =
135 new EGLWindow(GetParam().majorVersion, GetParam().minorVersion, GetParam().eglParameters);
Geoff Lang0d3683c2014-10-23 11:08:16 -0400136}
137
138ANGLETest::~ANGLETest()
139{
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400140 if (mQuadVertexBuffer)
141 {
142 glDeleteBuffers(1, &mQuadVertexBuffer);
143 }
Jamie Madill77a72f62015-04-14 11:18:32 -0400144 SafeDelete(mEGLWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400145}
146
Geoff Lang8a079e52013-10-18 16:13:33 -0400147void ANGLETest::SetUp()
148{
Jamie Madill776a75b2016-05-17 13:43:17 -0400149 angle::g_testPlatformInstance.enableMessages();
150
Corentin Wallezb44440d2015-07-22 17:54:20 -0400151 // Resize the window before creating the context so that the first make current
152 // sets the viewport and scissor box to the right size.
153 bool needSwap = false;
154 if (mOSWindow->getWidth() != mWidth || mOSWindow->getHeight() != mHeight)
Geoff Lang7f8dc492015-07-23 21:29:33 +0000155 {
Corentin Wallezb44440d2015-07-22 17:54:20 -0400156 if (!mOSWindow->resize(mWidth, mHeight))
157 {
158 FAIL() << "Failed to resize ANGLE test window.";
159 }
160 needSwap = true;
Geoff Lang7f8dc492015-07-23 21:29:33 +0000161 }
162
Geoff Lang8a079e52013-10-18 16:13:33 -0400163 if (!createEGLContext())
164 {
165 FAIL() << "egl context creation failed.";
166 }
Corentin Wallezb828b322015-07-16 17:51:30 -0400167
Corentin Wallezb44440d2015-07-22 17:54:20 -0400168 if (needSwap)
169 {
170 // Swap the buffers so that the default framebuffer picks up the resize
171 // which will allow follow-up test code to assume the framebuffer covers
172 // the whole window.
173 swapBuffers();
174 }
Corentin Wallez096725b2015-07-20 16:58:57 -0400175
Geoff Lang7f8dc492015-07-23 21:29:33 +0000176 // This Viewport command is not strictly necessary but we add it so that programs
177 // taking OpenGL traces can guess the size of the default framebuffer and show it
178 // in their UIs
179 glViewport(0, 0, mWidth, mHeight);
Jamie Madill508a5b72015-12-08 11:26:14 -0500180
181 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
182 angle::WriteDebugMessage("Entering %s.%s\n", info->test_case_name(), info->name());
Geoff Lang8a079e52013-10-18 16:13:33 -0400183}
184
185void ANGLETest::TearDown()
186{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800187 checkD3D11SDKLayersMessages();
188
Jamie Madill508a5b72015-12-08 11:26:14 -0500189 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
190 angle::WriteDebugMessage("Exiting %s.%s\n", info->test_case_name(), info->name());
191
Geoff Lang8a079e52013-10-18 16:13:33 -0400192 swapBuffers();
Jamie Madill9e16d402014-09-08 17:36:33 -0400193 mOSWindow->messageLoop();
194
Geoff Lang8a079e52013-10-18 16:13:33 -0400195 if (!destroyEGLContext())
196 {
197 FAIL() << "egl context destruction failed.";
198 }
Jamie Madill8add0eb2014-08-26 13:16:35 -0400199
200 // Check for quit message
201 Event myEvent;
202 while (mOSWindow->popEvent(&myEvent))
203 {
204 if (myEvent.Type == Event::EVENT_CLOSED)
205 {
206 exit(0);
207 }
208 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400209}
210
211void ANGLETest::swapBuffers()
212{
Jamie Madill77a72f62015-04-14 11:18:32 -0400213 if (mEGLWindow->isGLInitialized())
214 {
215 mEGLWindow->swap();
216 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400217}
218
Jamie Madill52b09c22016-04-11 14:12:31 -0400219// static
220std::array<Vector3, 6> ANGLETest::GetQuadVertices()
221{
222 std::array<Vector3, 6> vertices;
223 vertices[0] = Vector3(-1.0f, 1.0f, 0.5f);
224 vertices[1] = Vector3(-1.0f, -1.0f, 0.5f);
225 vertices[2] = Vector3(1.0f, -1.0f, 0.5f);
226 vertices[3] = Vector3(-1.0f, 1.0f, 0.5f);
227 vertices[4] = Vector3(1.0f, -1.0f, 0.5f);
228 vertices[5] = Vector3(1.0f, 1.0f, 0.5f);
229 return vertices;
230}
231
232void ANGLETest::setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale)
233{
234 if (mQuadVertexBuffer == 0)
235 {
236 glGenBuffers(1, &mQuadVertexBuffer);
237 }
238
239 auto quadVertices = GetQuadVertices();
240 for (Vector3 &vertex : quadVertices)
241 {
242 vertex.x *= positionAttribXYScale;
243 vertex.y *= positionAttribXYScale;
244 vertex.z = positionAttribZ;
245 }
246
247 glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer);
248 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 6, quadVertices.data(), GL_STATIC_DRAW);
249}
250
251// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200252void ANGLETest::drawQuad(GLuint program,
253 const std::string &positionAttribName,
254 GLfloat positionAttribZ)
255{
256 drawQuad(program, positionAttribName, positionAttribZ, 1.0f);
257}
258
Jamie Madill52b09c22016-04-11 14:12:31 -0400259// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200260void ANGLETest::drawQuad(GLuint program,
261 const std::string &positionAttribName,
262 GLfloat positionAttribZ,
263 GLfloat positionAttribXYScale)
Geoff Lang8a079e52013-10-18 16:13:33 -0400264{
Jamie Madill52b09c22016-04-11 14:12:31 -0400265 drawQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale, false);
266}
267
268void ANGLETest::drawQuad(GLuint program,
269 const std::string &positionAttribName,
270 GLfloat positionAttribZ,
271 GLfloat positionAttribXYScale,
272 bool useVertexBuffer)
273{
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200274 GLint previousProgram = 0;
275 glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgram);
276 if (previousProgram != static_cast<GLint>(program))
277 {
278 glUseProgram(program);
279 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400280
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200281 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
Geoff Lang8a079e52013-10-18 16:13:33 -0400282
Jamie Madill52b09c22016-04-11 14:12:31 -0400283 if (useVertexBuffer)
284 {
285 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
286 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
287 glBindBuffer(GL_ARRAY_BUFFER, 0);
288 }
289 else
290 {
291 auto quadVertices = GetQuadVertices();
292 for (Vector3 &vertex : quadVertices)
293 {
294 vertex.x *= positionAttribXYScale;
295 vertex.y *= positionAttribXYScale;
296 vertex.z = positionAttribZ;
297 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400298
Jamie Madill52b09c22016-04-11 14:12:31 -0400299 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, quadVertices.data());
300 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400301 glEnableVertexAttribArray(positionLocation);
302
303 glDrawArrays(GL_TRIANGLES, 0, 6);
304
305 glDisableVertexAttribArray(positionLocation);
306 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
307
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200308 if (previousProgram != static_cast<GLint>(program))
309 {
310 glUseProgram(previousProgram);
311 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400312}
313
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400314void ANGLETest::drawIndexedQuad(GLuint program,
315 const std::string &positionAttribName,
316 GLfloat positionAttribZ)
317{
318 drawIndexedQuad(program, positionAttribName, positionAttribZ, 1.0f);
319}
320
321void ANGLETest::drawIndexedQuad(GLuint program,
322 const std::string &positionAttribName,
323 GLfloat positionAttribZ,
324 GLfloat positionAttribXYScale)
325{
326 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
327
Jamie Madill52b09c22016-04-11 14:12:31 -0400328 GLint activeProgram = 0;
329 glGetIntegerv(GL_CURRENT_PROGRAM, &activeProgram);
330 if (static_cast<GLuint>(activeProgram) != program)
331 {
332 glUseProgram(program);
333 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400334
335 GLuint prevBinding = 0;
336 glGetIntegerv(GL_ARRAY_BUFFER_BINDING, reinterpret_cast<GLint *>(&prevBinding));
337
Jamie Madill52b09c22016-04-11 14:12:31 -0400338 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400339
340 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
341 glEnableVertexAttribArray(positionLocation);
342 glBindBuffer(GL_ARRAY_BUFFER, prevBinding);
343
344 const GLushort indices[] = {
345 0, 1, 2, 0, 2, 3,
346 };
347
348 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
349
350 glDisableVertexAttribArray(positionLocation);
351 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
352
Jamie Madill52b09c22016-04-11 14:12:31 -0400353 if (static_cast<GLuint>(activeProgram) != program)
354 {
355 glUseProgram(static_cast<GLuint>(activeProgram));
356 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400357}
358
Geoff Langefc551f2013-10-31 10:20:28 -0400359GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
360{
361 GLuint shader = glCreateShader(type);
362
363 const char *sourceArray[1] = { source.c_str() };
364 glShaderSource(shader, 1, sourceArray, NULL);
365 glCompileShader(shader);
366
367 GLint compileResult;
368 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
369
370 if (compileResult == 0)
371 {
372 GLint infoLogLength;
373 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
374
Jamie Madilld2c52e32015-10-14 17:07:05 -0400375 if (infoLogLength == 0)
376 {
377 std::cerr << "shader compilation failed with empty log." << std::endl;
378 }
379 else
380 {
381 std::vector<GLchar> infoLog(infoLogLength);
382 glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
Geoff Langefc551f2013-10-31 10:20:28 -0400383
Jamie Madilld2c52e32015-10-14 17:07:05 -0400384 std::cerr << "shader compilation failed: " << &infoLog[0];
385 }
Geoff Langefc551f2013-10-31 10:20:28 -0400386
387 glDeleteShader(shader);
388 shader = 0;
389 }
390
391 return shader;
392}
393
Austin Kinrossd544cc92016-01-11 15:26:42 -0800394void ANGLETest::checkD3D11SDKLayersMessages()
395{
396#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(NDEBUG)
397 // In debug D3D11 mode, check ID3D11InfoQueue to see if any D3D11 SDK Layers messages
398 // were outputted by the test
399 if (mIgnoreD3D11SDKLayersWarnings ||
400 mEGLWindow->getPlatform().renderer != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE ||
401 mEGLWindow->getDisplay() == EGL_NO_DISPLAY)
402 {
403 return;
404 }
405
406 const char *extensionString =
407 static_cast<const char *>(eglQueryString(mEGLWindow->getDisplay(), EGL_EXTENSIONS));
408 if (!strstr(extensionString, "EGL_EXT_device_query"))
409 {
410 return;
411 }
412
413 EGLAttrib device = 0;
414 EGLAttrib angleDevice = 0;
415
416 PFNEGLQUERYDISPLAYATTRIBEXTPROC queryDisplayAttribEXT;
417 PFNEGLQUERYDEVICEATTRIBEXTPROC queryDeviceAttribEXT;
418
419 queryDisplayAttribEXT = reinterpret_cast<PFNEGLQUERYDISPLAYATTRIBEXTPROC>(
420 eglGetProcAddress("eglQueryDisplayAttribEXT"));
421 queryDeviceAttribEXT = reinterpret_cast<PFNEGLQUERYDEVICEATTRIBEXTPROC>(
422 eglGetProcAddress("eglQueryDeviceAttribEXT"));
423 ASSERT_NE(nullptr, queryDisplayAttribEXT);
424 ASSERT_NE(nullptr, queryDeviceAttribEXT);
425
426 ASSERT_EGL_TRUE(queryDisplayAttribEXT(mEGLWindow->getDisplay(), EGL_DEVICE_EXT, &angleDevice));
427 ASSERT_EGL_TRUE(queryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(angleDevice),
428 EGL_D3D11_DEVICE_ANGLE, &device));
429 ID3D11Device *d3d11Device = reinterpret_cast<ID3D11Device *>(device);
430
431 ID3D11InfoQueue *infoQueue = nullptr;
432 HRESULT hr =
433 d3d11Device->QueryInterface(__uuidof(infoQueue), reinterpret_cast<void **>(&infoQueue));
434 if (SUCCEEDED(hr))
435 {
436 UINT64 numStoredD3DDebugMessages =
437 infoQueue->GetNumStoredMessagesAllowedByRetrievalFilter();
438
439 if (numStoredD3DDebugMessages > 0)
440 {
441 for (UINT64 i = 0; i < numStoredD3DDebugMessages; i++)
442 {
443 SIZE_T messageLength = 0;
444 hr = infoQueue->GetMessage(i, nullptr, &messageLength);
445
446 if (SUCCEEDED(hr))
447 {
448 D3D11_MESSAGE *pMessage =
449 reinterpret_cast<D3D11_MESSAGE *>(malloc(messageLength));
450 infoQueue->GetMessage(i, pMessage, &messageLength);
451
452 std::cout << "Message " << i << ":"
453 << " " << pMessage->pDescription << "\n";
454 free(pMessage);
455 }
456 }
457
458 FAIL() << numStoredD3DDebugMessages
459 << " D3D11 SDK Layers message(s) detected! Test Failed.\n";
460 }
461 }
462
463 SafeRelease(infoQueue);
464#endif
465}
466
Geoff Lang63046e22015-07-21 12:43:50 -0400467static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
468{
469 return strstr(allExtensions, extName.c_str()) != nullptr;
470}
471
Geoff Lang8a079e52013-10-18 16:13:33 -0400472bool ANGLETest::extensionEnabled(const std::string &extName)
473{
Geoff Lang63046e22015-07-21 12:43:50 -0400474 return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
475 extName);
476}
477
478bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
479{
480 return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
481}
482
483bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
484{
485 return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
Geoff Lang8a079e52013-10-18 16:13:33 -0400486}
487
Geoff Lang8a079e52013-10-18 16:13:33 -0400488void ANGLETest::setWindowWidth(int width)
489{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400490 mWidth = width;
Geoff Lang8a079e52013-10-18 16:13:33 -0400491}
492
493void ANGLETest::setWindowHeight(int height)
494{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400495 mHeight = height;
Geoff Lang8a079e52013-10-18 16:13:33 -0400496}
497
Geoff Langefc551f2013-10-31 10:20:28 -0400498void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400499{
Jamie Madill62af5462014-08-26 13:16:37 -0400500 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400501}
502
Geoff Langefc551f2013-10-31 10:20:28 -0400503void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400504{
Jamie Madill62af5462014-08-26 13:16:37 -0400505 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400506}
507
Geoff Langefc551f2013-10-31 10:20:28 -0400508void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400509{
Jamie Madill62af5462014-08-26 13:16:37 -0400510 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400511}
512
Geoff Langefc551f2013-10-31 10:20:28 -0400513void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400514{
Jamie Madill62af5462014-08-26 13:16:37 -0400515 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400516}
517
Geoff Langefc551f2013-10-31 10:20:28 -0400518void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400519{
Jamie Madill62af5462014-08-26 13:16:37 -0400520 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400521}
522
Geoff Langefc551f2013-10-31 10:20:28 -0400523void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400524{
Jamie Madill62af5462014-08-26 13:16:37 -0400525 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400526}
527
528void ANGLETest::setMultisampleEnabled(bool enabled)
529{
Jamie Madill62af5462014-08-26 13:16:37 -0400530 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400531}
532
Geoff Lang70d0f492015-12-10 17:45:46 -0500533void ANGLETest::setDebugEnabled(bool enabled)
534{
535 mEGLWindow->setDebugEnabled(enabled);
536}
537
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500538void ANGLETest::setNoErrorEnabled(bool enabled)
539{
540 mEGLWindow->setNoErrorEnabled(enabled);
541}
542
Geoff Lang8a079e52013-10-18 16:13:33 -0400543int ANGLETest::getClientVersion() const
544{
Geoff Lang5ade8452015-09-02 11:00:30 -0400545 return mEGLWindow->getClientMajorVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400546}
547
Geoff Langb9266272015-01-29 13:25:14 +0000548EGLWindow *ANGLETest::getEGLWindow() const
549{
550 return mEGLWindow;
551}
552
Geoff Lang8a079e52013-10-18 16:13:33 -0400553int ANGLETest::getWindowWidth() const
554{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400555 return mWidth;
Geoff Lang8a079e52013-10-18 16:13:33 -0400556}
557
558int ANGLETest::getWindowHeight() const
559{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400560 return mHeight;
Geoff Lang8a079e52013-10-18 16:13:33 -0400561}
562
Geoff Langefc551f2013-10-31 10:20:28 -0400563bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400564{
Jamie Madill62af5462014-08-26 13:16:37 -0400565 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400566}
567
568bool ANGLETest::createEGLContext()
569{
Jamie Madill62af5462014-08-26 13:16:37 -0400570 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400571}
572
573bool ANGLETest::destroyEGLContext()
574{
Jamie Madill62af5462014-08-26 13:16:37 -0400575 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400576 return true;
577}
Geoff Langbb134672013-10-23 13:06:46 -0400578
Geoff Lang0d3683c2014-10-23 11:08:16 -0400579bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400580{
581 mOSWindow = CreateOSWindow();
582 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
583 {
584 return false;
585 }
586
Geoff Lang0d3683c2014-10-23 11:08:16 -0400587 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400588
589 return true;
590}
591
Geoff Lang0d3683c2014-10-23 11:08:16 -0400592bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400593{
594 if (mOSWindow)
595 {
596 mOSWindow->destroy();
597 delete mOSWindow;
598 mOSWindow = NULL;
599 }
600
601 return true;
602}
603
Geoff Lang0d3683c2014-10-23 11:08:16 -0400604void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400605{
Jamie Madill4119ed32014-10-01 10:41:40 -0400606 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400607}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400608
Jamie Madill518b9fa2016-03-02 11:26:02 -0500609bool IsIntel()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500610{
611 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
612 return (rendererString.find("Intel") != std::string::npos);
613}
614
Jamie Madill518b9fa2016-03-02 11:26:02 -0500615bool IsAMD()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500616{
617 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
618 return (rendererString.find("AMD") != std::string::npos) ||
619 (rendererString.find("ATI") != std::string::npos);
620}
621
Jamie Madill518b9fa2016-03-02 11:26:02 -0500622bool IsNVIDIA()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500623{
624 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
625 return (rendererString.find("NVIDIA") != std::string::npos);
626}
627
Jamie Madill518b9fa2016-03-02 11:26:02 -0500628bool IsD3D11()
Jamie Madilld55d2832015-10-27 13:59:19 -0400629{
630 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
631 return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos);
632}
633
Jamie Madill518b9fa2016-03-02 11:26:02 -0500634bool IsD3D11_FL93()
Jamie Madill9fc36822015-11-18 13:08:07 -0500635{
636 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
637 return (rendererString.find("Direct3D11 vs_4_0_") != std::string::npos);
638}
639
Jamie Madill518b9fa2016-03-02 11:26:02 -0500640bool IsD3D9()
Jamie Madill9fc36822015-11-18 13:08:07 -0500641{
642 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
643 return (rendererString.find("Direct3D9") != std::string::npos);
644}
645
Jamie Madill518b9fa2016-03-02 11:26:02 -0500646bool IsD3DSM3()
Jamie Madill9fc36822015-11-18 13:08:07 -0500647{
Jamie Madill518b9fa2016-03-02 11:26:02 -0500648 return IsD3D9() || IsD3D11_FL93();
Jamie Madill9fc36822015-11-18 13:08:07 -0500649}
650
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400651bool IsLinux()
652{
653#if defined(ANGLE_PLATFORM_LINUX)
654 return true;
655#else
656 return false;
657#endif
658}
659
Jamie Madill518b9fa2016-03-02 11:26:02 -0500660bool IsOSX()
Ian Ewell292f0052016-02-04 10:37:32 -0500661{
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400662#if defined(ANGLE_PLATFORM_APPLE)
Ian Ewell292f0052016-02-04 10:37:32 -0500663 return true;
664#else
665 return false;
666#endif
667}
668
Jamie Madill518b9fa2016-03-02 11:26:02 -0500669bool ANGLETest::isOpenGL() const
670{
671 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
672}
673
Olli Etuaho87fc71c2016-05-11 14:25:21 +0300674bool ANGLETest::isGLES() const
675{
676 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE;
677}
678
Jamie Madillc3b9b262015-01-30 14:00:51 -0500679EGLint ANGLETest::getPlatformRenderer() const
680{
Jamie Madillf6859912015-01-30 17:05:35 -0500681 assert(mEGLWindow);
682 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500683}
684
Austin Kinrossd544cc92016-01-11 15:26:42 -0800685void ANGLETest::ignoreD3D11SDKLayersWarnings()
686{
687 // Some tests may need to disable the D3D11 SDK Layers Warnings checks
688 mIgnoreD3D11SDKLayersWarnings = true;
689}
690
Geoff Lang0d3683c2014-10-23 11:08:16 -0400691OSWindow *ANGLETest::mOSWindow = NULL;
692
693void ANGLETestEnvironment::SetUp()
694{
Jamie Madill776a75b2016-05-17 13:43:17 -0400695 mGLESLibrary.reset(angle::loadLibrary("libGLESv2"));
696 if (mGLESLibrary)
697 {
698 auto initFunc = reinterpret_cast<ANGLEPlatformInitializeFunc>(
699 mGLESLibrary->getSymbol("ANGLEPlatformInitialize"));
700 if (initFunc)
701 {
702 initFunc(&angle::g_testPlatformInstance);
703 }
704 }
705
Geoff Lang0d3683c2014-10-23 11:08:16 -0400706 if (!ANGLETest::InitTestWindow())
707 {
708 FAIL() << "Failed to create ANGLE test window.";
709 }
710}
711
712void ANGLETestEnvironment::TearDown()
713{
714 ANGLETest::DestroyTestWindow();
Jamie Madill776a75b2016-05-17 13:43:17 -0400715
716 if (mGLESLibrary)
717 {
718 auto shutdownFunc = reinterpret_cast<ANGLEPlatformShutdownFunc>(
719 mGLESLibrary->getSymbol("ANGLEPlatformShutdown"));
720 if (shutdownFunc)
721 {
722 shutdownFunc();
723 }
724 }
725}
726
727void IgnoreANGLEPlatformMessages()
728{
729 // Negative tests may trigger expected errors/warnings in the ANGLE Platform.
730 angle::g_testPlatformInstance.ignoreMessages();
Geoff Lang0d3683c2014-10-23 11:08:16 -0400731}