blob: a9032a144e5ee2c1839116babd6475a92422354a [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::black = GLColor(0u, 0u, 0u, 255u);
Jamie Madill9b08a3d2016-06-08 15:30:12 -070019const GLColor GLColor::blue = GLColor(0u, 0u, 255u, 255u);
20const GLColor GLColor::cyan = GLColor(0u, 255u, 255u, 255u);
21const GLColor GLColor::green = GLColor(0u, 255u, 0u, 255u);
22const GLColor GLColor::red = GLColor(255u, 0u, 0u, 255u);
23const GLColor GLColor::yellow = GLColor(255u, 255u, 0, 255u);
Olli Etuaho190028d2016-05-13 12:11:29 +030024const GLColor GLColor::white = GLColor(255u, 255u, 255u, 255u);
Olli Etuahoa314b612016-03-10 16:43:00 +020025
Vincent Lang25ab4512016-05-13 18:13:59 +020026const GLColor16 GLColor16::white = GLColor16(65535u, 65535u, 65535u, 65535u);
27
Jamie Madill1fbc59f2016-02-24 15:25:51 -050028namespace
29{
30float ColorNorm(GLubyte channelValue)
31{
32 return static_cast<float>(channelValue) / 255.0f;
33}
Jamie Madill776a75b2016-05-17 13:43:17 -040034
35// Use a custom ANGLE platform class to capture and report internal errors.
36class TestPlatform : public angle::Platform
37{
38 public:
39 TestPlatform() : mIgnoreMessages(false) {}
40
41 void logError(const char *errorMessage) override;
42 void logWarning(const char *warningMessage) override;
43 void logInfo(const char *infoMessage) override;
44
45 void ignoreMessages();
46 void enableMessages();
47
48 private:
49 bool mIgnoreMessages;
50};
51
52void TestPlatform::logError(const char *errorMessage)
53{
54 if (mIgnoreMessages)
55 return;
56
57 FAIL() << errorMessage;
58}
59
60void TestPlatform::logWarning(const char *warningMessage)
61{
62 if (mIgnoreMessages)
63 return;
64
65 std::cerr << "Warning: " << warningMessage << std::endl;
66}
67
68void TestPlatform::logInfo(const char *infoMessage)
69{
70 if (mIgnoreMessages)
71 return;
72
73 angle::WriteDebugMessage("%s\n", infoMessage);
74}
75
76void TestPlatform::ignoreMessages()
77{
78 mIgnoreMessages = true;
79}
80
81void TestPlatform::enableMessages()
82{
83 mIgnoreMessages = false;
84}
85
86TestPlatform g_testPlatformInstance;
Jamie Madill1fbc59f2016-02-24 15:25:51 -050087} // anonymous namespace
88
Jamie Madill0dfa8072016-01-22 15:27:21 -050089GLColor::GLColor() : R(0), G(0), B(0), A(0)
90{
91}
92
93GLColor::GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a)
94{
95}
96
Jamie Madille2509a32016-02-01 14:09:05 -050097GLColor::GLColor(GLuint colorValue) : R(0), G(0), B(0), A(0)
98{
99 memcpy(&R, &colorValue, sizeof(GLuint));
100}
101
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500102Vector4 GLColor::toNormalizedVector() const
103{
104 return Vector4(ColorNorm(R), ColorNorm(G), ColorNorm(B), ColorNorm(A));
105}
106
Jamie Madill0dfa8072016-01-22 15:27:21 -0500107GLColor ReadColor(GLint x, GLint y)
108{
109 GLColor actual;
110 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &actual.R);
111 EXPECT_GL_NO_ERROR();
112 return actual;
113}
114
115bool operator==(const GLColor &a, const GLColor &b)
116{
117 return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
118}
119
120std::ostream &operator<<(std::ostream &ostream, const GLColor &color)
121{
122 ostream << "(" << static_cast<unsigned int>(color.R) << ", "
123 << static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B)
124 << ", " << static_cast<unsigned int>(color.A) << ")";
125 return ostream;
126}
127
Vincent Lang25ab4512016-05-13 18:13:59 +0200128GLColor16::GLColor16() : R(0), G(0), B(0), A(0)
129{
130}
131
132GLColor16::GLColor16(GLushort r, GLushort g, GLushort b, GLushort a) : R(r), G(g), B(b), A(a)
133{
134}
135
136GLColor16 ReadColor16(GLint x, GLint y)
137{
138 GLColor16 actual;
139 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_SHORT, &actual.R);
140 EXPECT_GL_NO_ERROR();
141 return actual;
142}
143
144bool operator==(const GLColor16 &a, const GLColor16 &b)
145{
146 return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
147}
148
149std::ostream &operator<<(std::ostream &ostream, const GLColor16 &color)
150{
151 ostream << "(" << static_cast<unsigned int>(color.R) << ", "
152 << static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B)
153 << ", " << static_cast<unsigned int>(color.A) << ")";
154 return ostream;
155}
156
Jamie Madill0dfa8072016-01-22 15:27:21 -0500157} // namespace angle
158
Jamie Madillfa05f602015-05-07 13:47:11 -0400159ANGLETest::ANGLETest()
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400160 : mEGLWindow(nullptr),
161 mWidth(16),
162 mHeight(16),
163 mIgnoreD3D11SDKLayersWarnings(false),
164 mQuadVertexBuffer(0)
Geoff Lang8a079e52013-10-18 16:13:33 -0400165{
Geoff Lang5ade8452015-09-02 11:00:30 -0400166 mEGLWindow =
167 new EGLWindow(GetParam().majorVersion, GetParam().minorVersion, GetParam().eglParameters);
Geoff Lang0d3683c2014-10-23 11:08:16 -0400168}
169
170ANGLETest::~ANGLETest()
171{
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400172 if (mQuadVertexBuffer)
173 {
174 glDeleteBuffers(1, &mQuadVertexBuffer);
175 }
Jamie Madill77a72f62015-04-14 11:18:32 -0400176 SafeDelete(mEGLWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400177}
178
Geoff Lang8a079e52013-10-18 16:13:33 -0400179void ANGLETest::SetUp()
180{
Jamie Madill776a75b2016-05-17 13:43:17 -0400181 angle::g_testPlatformInstance.enableMessages();
182
Corentin Wallezb44440d2015-07-22 17:54:20 -0400183 // Resize the window before creating the context so that the first make current
184 // sets the viewport and scissor box to the right size.
185 bool needSwap = false;
186 if (mOSWindow->getWidth() != mWidth || mOSWindow->getHeight() != mHeight)
Geoff Lang7f8dc492015-07-23 21:29:33 +0000187 {
Corentin Wallezb44440d2015-07-22 17:54:20 -0400188 if (!mOSWindow->resize(mWidth, mHeight))
189 {
190 FAIL() << "Failed to resize ANGLE test window.";
191 }
192 needSwap = true;
Geoff Lang7f8dc492015-07-23 21:29:33 +0000193 }
194
Geoff Lang8a079e52013-10-18 16:13:33 -0400195 if (!createEGLContext())
196 {
197 FAIL() << "egl context creation failed.";
198 }
Corentin Wallezb828b322015-07-16 17:51:30 -0400199
Corentin Wallezb44440d2015-07-22 17:54:20 -0400200 if (needSwap)
201 {
202 // Swap the buffers so that the default framebuffer picks up the resize
203 // which will allow follow-up test code to assume the framebuffer covers
204 // the whole window.
205 swapBuffers();
206 }
Corentin Wallez096725b2015-07-20 16:58:57 -0400207
Geoff Lang7f8dc492015-07-23 21:29:33 +0000208 // This Viewport command is not strictly necessary but we add it so that programs
209 // taking OpenGL traces can guess the size of the default framebuffer and show it
210 // in their UIs
211 glViewport(0, 0, mWidth, mHeight);
Jamie Madill508a5b72015-12-08 11:26:14 -0500212
213 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
214 angle::WriteDebugMessage("Entering %s.%s\n", info->test_case_name(), info->name());
Geoff Lang8a079e52013-10-18 16:13:33 -0400215}
216
217void ANGLETest::TearDown()
218{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800219 checkD3D11SDKLayersMessages();
220
Jamie Madill508a5b72015-12-08 11:26:14 -0500221 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
222 angle::WriteDebugMessage("Exiting %s.%s\n", info->test_case_name(), info->name());
223
Geoff Lang8a079e52013-10-18 16:13:33 -0400224 swapBuffers();
Jamie Madill9e16d402014-09-08 17:36:33 -0400225 mOSWindow->messageLoop();
226
Geoff Lang8a079e52013-10-18 16:13:33 -0400227 if (!destroyEGLContext())
228 {
229 FAIL() << "egl context destruction failed.";
230 }
Jamie Madill8add0eb2014-08-26 13:16:35 -0400231
232 // Check for quit message
233 Event myEvent;
234 while (mOSWindow->popEvent(&myEvent))
235 {
236 if (myEvent.Type == Event::EVENT_CLOSED)
237 {
238 exit(0);
239 }
240 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400241}
242
243void ANGLETest::swapBuffers()
244{
Jamie Madill77a72f62015-04-14 11:18:32 -0400245 if (mEGLWindow->isGLInitialized())
246 {
247 mEGLWindow->swap();
248 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400249}
250
Jamie Madill52b09c22016-04-11 14:12:31 -0400251// static
252std::array<Vector3, 6> ANGLETest::GetQuadVertices()
253{
254 std::array<Vector3, 6> vertices;
255 vertices[0] = Vector3(-1.0f, 1.0f, 0.5f);
256 vertices[1] = Vector3(-1.0f, -1.0f, 0.5f);
257 vertices[2] = Vector3(1.0f, -1.0f, 0.5f);
258 vertices[3] = Vector3(-1.0f, 1.0f, 0.5f);
259 vertices[4] = Vector3(1.0f, -1.0f, 0.5f);
260 vertices[5] = Vector3(1.0f, 1.0f, 0.5f);
261 return vertices;
262}
263
264void ANGLETest::setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale)
265{
266 if (mQuadVertexBuffer == 0)
267 {
268 glGenBuffers(1, &mQuadVertexBuffer);
269 }
270
271 auto quadVertices = GetQuadVertices();
272 for (Vector3 &vertex : quadVertices)
273 {
274 vertex.x *= positionAttribXYScale;
275 vertex.y *= positionAttribXYScale;
276 vertex.z = positionAttribZ;
277 }
278
279 glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer);
280 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 6, quadVertices.data(), GL_STATIC_DRAW);
281}
282
283// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200284void ANGLETest::drawQuad(GLuint program,
285 const std::string &positionAttribName,
286 GLfloat positionAttribZ)
287{
288 drawQuad(program, positionAttribName, positionAttribZ, 1.0f);
289}
290
Jamie Madill52b09c22016-04-11 14:12:31 -0400291// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200292void ANGLETest::drawQuad(GLuint program,
293 const std::string &positionAttribName,
294 GLfloat positionAttribZ,
295 GLfloat positionAttribXYScale)
Geoff Lang8a079e52013-10-18 16:13:33 -0400296{
Jamie Madill52b09c22016-04-11 14:12:31 -0400297 drawQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale, false);
298}
299
300void ANGLETest::drawQuad(GLuint program,
301 const std::string &positionAttribName,
302 GLfloat positionAttribZ,
303 GLfloat positionAttribXYScale,
304 bool useVertexBuffer)
305{
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200306 GLint previousProgram = 0;
307 glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgram);
308 if (previousProgram != static_cast<GLint>(program))
309 {
310 glUseProgram(program);
311 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400312
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200313 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
Geoff Lang8a079e52013-10-18 16:13:33 -0400314
Jamie Madill52b09c22016-04-11 14:12:31 -0400315 if (useVertexBuffer)
316 {
317 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
318 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
319 glBindBuffer(GL_ARRAY_BUFFER, 0);
320 }
321 else
322 {
323 auto quadVertices = GetQuadVertices();
324 for (Vector3 &vertex : quadVertices)
325 {
326 vertex.x *= positionAttribXYScale;
327 vertex.y *= positionAttribXYScale;
328 vertex.z = positionAttribZ;
329 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400330
Jamie Madill52b09c22016-04-11 14:12:31 -0400331 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, quadVertices.data());
332 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400333 glEnableVertexAttribArray(positionLocation);
334
335 glDrawArrays(GL_TRIANGLES, 0, 6);
336
337 glDisableVertexAttribArray(positionLocation);
338 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
339
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200340 if (previousProgram != static_cast<GLint>(program))
341 {
342 glUseProgram(previousProgram);
343 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400344}
345
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400346void ANGLETest::drawIndexedQuad(GLuint program,
347 const std::string &positionAttribName,
348 GLfloat positionAttribZ)
349{
350 drawIndexedQuad(program, positionAttribName, positionAttribZ, 1.0f);
351}
352
353void ANGLETest::drawIndexedQuad(GLuint program,
354 const std::string &positionAttribName,
355 GLfloat positionAttribZ,
356 GLfloat positionAttribXYScale)
357{
358 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
359
Jamie Madill52b09c22016-04-11 14:12:31 -0400360 GLint activeProgram = 0;
361 glGetIntegerv(GL_CURRENT_PROGRAM, &activeProgram);
362 if (static_cast<GLuint>(activeProgram) != program)
363 {
364 glUseProgram(program);
365 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400366
367 GLuint prevBinding = 0;
368 glGetIntegerv(GL_ARRAY_BUFFER_BINDING, reinterpret_cast<GLint *>(&prevBinding));
369
Jamie Madill52b09c22016-04-11 14:12:31 -0400370 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400371
372 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
373 glEnableVertexAttribArray(positionLocation);
374 glBindBuffer(GL_ARRAY_BUFFER, prevBinding);
375
376 const GLushort indices[] = {
377 0, 1, 2, 0, 2, 3,
378 };
379
380 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
381
382 glDisableVertexAttribArray(positionLocation);
383 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
384
Jamie Madill52b09c22016-04-11 14:12:31 -0400385 if (static_cast<GLuint>(activeProgram) != program)
386 {
387 glUseProgram(static_cast<GLuint>(activeProgram));
388 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400389}
390
Geoff Langefc551f2013-10-31 10:20:28 -0400391GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
392{
393 GLuint shader = glCreateShader(type);
394
395 const char *sourceArray[1] = { source.c_str() };
396 glShaderSource(shader, 1, sourceArray, NULL);
397 glCompileShader(shader);
398
399 GLint compileResult;
400 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
401
402 if (compileResult == 0)
403 {
404 GLint infoLogLength;
405 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
406
Jamie Madilld2c52e32015-10-14 17:07:05 -0400407 if (infoLogLength == 0)
408 {
409 std::cerr << "shader compilation failed with empty log." << std::endl;
410 }
411 else
412 {
413 std::vector<GLchar> infoLog(infoLogLength);
414 glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
Geoff Langefc551f2013-10-31 10:20:28 -0400415
Jamie Madilld2c52e32015-10-14 17:07:05 -0400416 std::cerr << "shader compilation failed: " << &infoLog[0];
417 }
Geoff Langefc551f2013-10-31 10:20:28 -0400418
419 glDeleteShader(shader);
420 shader = 0;
421 }
422
423 return shader;
424}
425
Austin Kinrossd544cc92016-01-11 15:26:42 -0800426void ANGLETest::checkD3D11SDKLayersMessages()
427{
428#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(NDEBUG)
429 // In debug D3D11 mode, check ID3D11InfoQueue to see if any D3D11 SDK Layers messages
430 // were outputted by the test
431 if (mIgnoreD3D11SDKLayersWarnings ||
432 mEGLWindow->getPlatform().renderer != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE ||
433 mEGLWindow->getDisplay() == EGL_NO_DISPLAY)
434 {
435 return;
436 }
437
438 const char *extensionString =
439 static_cast<const char *>(eglQueryString(mEGLWindow->getDisplay(), EGL_EXTENSIONS));
440 if (!strstr(extensionString, "EGL_EXT_device_query"))
441 {
442 return;
443 }
444
445 EGLAttrib device = 0;
446 EGLAttrib angleDevice = 0;
447
448 PFNEGLQUERYDISPLAYATTRIBEXTPROC queryDisplayAttribEXT;
449 PFNEGLQUERYDEVICEATTRIBEXTPROC queryDeviceAttribEXT;
450
451 queryDisplayAttribEXT = reinterpret_cast<PFNEGLQUERYDISPLAYATTRIBEXTPROC>(
452 eglGetProcAddress("eglQueryDisplayAttribEXT"));
453 queryDeviceAttribEXT = reinterpret_cast<PFNEGLQUERYDEVICEATTRIBEXTPROC>(
454 eglGetProcAddress("eglQueryDeviceAttribEXT"));
455 ASSERT_NE(nullptr, queryDisplayAttribEXT);
456 ASSERT_NE(nullptr, queryDeviceAttribEXT);
457
458 ASSERT_EGL_TRUE(queryDisplayAttribEXT(mEGLWindow->getDisplay(), EGL_DEVICE_EXT, &angleDevice));
459 ASSERT_EGL_TRUE(queryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(angleDevice),
460 EGL_D3D11_DEVICE_ANGLE, &device));
461 ID3D11Device *d3d11Device = reinterpret_cast<ID3D11Device *>(device);
462
463 ID3D11InfoQueue *infoQueue = nullptr;
464 HRESULT hr =
465 d3d11Device->QueryInterface(__uuidof(infoQueue), reinterpret_cast<void **>(&infoQueue));
466 if (SUCCEEDED(hr))
467 {
468 UINT64 numStoredD3DDebugMessages =
469 infoQueue->GetNumStoredMessagesAllowedByRetrievalFilter();
470
471 if (numStoredD3DDebugMessages > 0)
472 {
473 for (UINT64 i = 0; i < numStoredD3DDebugMessages; i++)
474 {
475 SIZE_T messageLength = 0;
476 hr = infoQueue->GetMessage(i, nullptr, &messageLength);
477
478 if (SUCCEEDED(hr))
479 {
480 D3D11_MESSAGE *pMessage =
481 reinterpret_cast<D3D11_MESSAGE *>(malloc(messageLength));
482 infoQueue->GetMessage(i, pMessage, &messageLength);
483
484 std::cout << "Message " << i << ":"
485 << " " << pMessage->pDescription << "\n";
486 free(pMessage);
487 }
488 }
489
490 FAIL() << numStoredD3DDebugMessages
491 << " D3D11 SDK Layers message(s) detected! Test Failed.\n";
492 }
493 }
494
495 SafeRelease(infoQueue);
496#endif
497}
498
Geoff Lang63046e22015-07-21 12:43:50 -0400499static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
500{
501 return strstr(allExtensions, extName.c_str()) != nullptr;
502}
503
Geoff Lang8a079e52013-10-18 16:13:33 -0400504bool ANGLETest::extensionEnabled(const std::string &extName)
505{
Geoff Lang63046e22015-07-21 12:43:50 -0400506 return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
507 extName);
508}
509
510bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
511{
512 return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
513}
514
515bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
516{
517 return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
Geoff Lang8a079e52013-10-18 16:13:33 -0400518}
519
Geoff Lang8a079e52013-10-18 16:13:33 -0400520void ANGLETest::setWindowWidth(int width)
521{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400522 mWidth = width;
Geoff Lang8a079e52013-10-18 16:13:33 -0400523}
524
525void ANGLETest::setWindowHeight(int height)
526{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400527 mHeight = height;
Geoff Lang8a079e52013-10-18 16:13:33 -0400528}
529
Geoff Langefc551f2013-10-31 10:20:28 -0400530void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400531{
Jamie Madill62af5462014-08-26 13:16:37 -0400532 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400533}
534
Geoff Langefc551f2013-10-31 10:20:28 -0400535void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400536{
Jamie Madill62af5462014-08-26 13:16:37 -0400537 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400538}
539
Geoff Langefc551f2013-10-31 10:20:28 -0400540void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400541{
Jamie Madill62af5462014-08-26 13:16:37 -0400542 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400543}
544
Geoff Langefc551f2013-10-31 10:20:28 -0400545void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400546{
Jamie Madill62af5462014-08-26 13:16:37 -0400547 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400548}
549
Geoff Langefc551f2013-10-31 10:20:28 -0400550void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400551{
Jamie Madill62af5462014-08-26 13:16:37 -0400552 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400553}
554
Geoff Langefc551f2013-10-31 10:20:28 -0400555void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400556{
Jamie Madill62af5462014-08-26 13:16:37 -0400557 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400558}
559
560void ANGLETest::setMultisampleEnabled(bool enabled)
561{
Jamie Madill62af5462014-08-26 13:16:37 -0400562 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400563}
564
Geoff Lang70d0f492015-12-10 17:45:46 -0500565void ANGLETest::setDebugEnabled(bool enabled)
566{
567 mEGLWindow->setDebugEnabled(enabled);
568}
569
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500570void ANGLETest::setNoErrorEnabled(bool enabled)
571{
572 mEGLWindow->setNoErrorEnabled(enabled);
573}
574
Geoff Lang8a079e52013-10-18 16:13:33 -0400575int ANGLETest::getClientVersion() const
576{
Geoff Lang5ade8452015-09-02 11:00:30 -0400577 return mEGLWindow->getClientMajorVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400578}
579
Vincent Lang25ab4512016-05-13 18:13:59 +0200580int ANGLETest::getClientMinorVersion() const
581{
582 return mEGLWindow->getClientMinorVersion();
583}
584
Geoff Langb9266272015-01-29 13:25:14 +0000585EGLWindow *ANGLETest::getEGLWindow() const
586{
587 return mEGLWindow;
588}
589
Geoff Lang8a079e52013-10-18 16:13:33 -0400590int ANGLETest::getWindowWidth() const
591{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400592 return mWidth;
Geoff Lang8a079e52013-10-18 16:13:33 -0400593}
594
595int ANGLETest::getWindowHeight() const
596{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400597 return mHeight;
Geoff Lang8a079e52013-10-18 16:13:33 -0400598}
599
Geoff Langefc551f2013-10-31 10:20:28 -0400600bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400601{
Jamie Madill62af5462014-08-26 13:16:37 -0400602 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400603}
604
605bool ANGLETest::createEGLContext()
606{
Jamie Madill62af5462014-08-26 13:16:37 -0400607 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400608}
609
610bool ANGLETest::destroyEGLContext()
611{
Jamie Madill62af5462014-08-26 13:16:37 -0400612 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400613 return true;
614}
Geoff Langbb134672013-10-23 13:06:46 -0400615
Geoff Lang0d3683c2014-10-23 11:08:16 -0400616bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400617{
618 mOSWindow = CreateOSWindow();
619 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
620 {
621 return false;
622 }
623
Geoff Lang0d3683c2014-10-23 11:08:16 -0400624 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400625
626 return true;
627}
628
Geoff Lang0d3683c2014-10-23 11:08:16 -0400629bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400630{
631 if (mOSWindow)
632 {
633 mOSWindow->destroy();
634 delete mOSWindow;
635 mOSWindow = NULL;
636 }
637
638 return true;
639}
640
Geoff Lang0d3683c2014-10-23 11:08:16 -0400641void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400642{
Jamie Madill4119ed32014-10-01 10:41:40 -0400643 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400644}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400645
Jamie Madill518b9fa2016-03-02 11:26:02 -0500646bool IsIntel()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500647{
648 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
649 return (rendererString.find("Intel") != std::string::npos);
650}
651
Jamie Madill518b9fa2016-03-02 11:26:02 -0500652bool IsAMD()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500653{
654 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
655 return (rendererString.find("AMD") != std::string::npos) ||
656 (rendererString.find("ATI") != std::string::npos);
657}
658
Jamie Madill518b9fa2016-03-02 11:26:02 -0500659bool IsNVIDIA()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500660{
661 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
662 return (rendererString.find("NVIDIA") != std::string::npos);
663}
664
Jamie Madill518b9fa2016-03-02 11:26:02 -0500665bool IsD3D11()
Jamie Madilld55d2832015-10-27 13:59:19 -0400666{
667 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
668 return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos);
669}
670
Jamie Madill518b9fa2016-03-02 11:26:02 -0500671bool IsD3D11_FL93()
Jamie Madill9fc36822015-11-18 13:08:07 -0500672{
673 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
674 return (rendererString.find("Direct3D11 vs_4_0_") != std::string::npos);
675}
676
Jamie Madill518b9fa2016-03-02 11:26:02 -0500677bool IsD3D9()
Jamie Madill9fc36822015-11-18 13:08:07 -0500678{
679 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
680 return (rendererString.find("Direct3D9") != std::string::npos);
681}
682
Jamie Madill518b9fa2016-03-02 11:26:02 -0500683bool IsD3DSM3()
Jamie Madill9fc36822015-11-18 13:08:07 -0500684{
Jamie Madill518b9fa2016-03-02 11:26:02 -0500685 return IsD3D9() || IsD3D11_FL93();
Jamie Madill9fc36822015-11-18 13:08:07 -0500686}
687
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400688bool IsLinux()
689{
690#if defined(ANGLE_PLATFORM_LINUX)
691 return true;
692#else
693 return false;
694#endif
695}
696
Jamie Madill518b9fa2016-03-02 11:26:02 -0500697bool IsOSX()
Ian Ewell292f0052016-02-04 10:37:32 -0500698{
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400699#if defined(ANGLE_PLATFORM_APPLE)
Ian Ewell292f0052016-02-04 10:37:32 -0500700 return true;
701#else
702 return false;
703#endif
704}
705
Jamie Madill518b9fa2016-03-02 11:26:02 -0500706bool ANGLETest::isOpenGL() const
707{
708 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
709}
710
Olli Etuaho87fc71c2016-05-11 14:25:21 +0300711bool ANGLETest::isGLES() const
712{
713 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE;
714}
715
Jamie Madillc3b9b262015-01-30 14:00:51 -0500716EGLint ANGLETest::getPlatformRenderer() const
717{
Jamie Madillf6859912015-01-30 17:05:35 -0500718 assert(mEGLWindow);
719 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500720}
721
Austin Kinrossd544cc92016-01-11 15:26:42 -0800722void ANGLETest::ignoreD3D11SDKLayersWarnings()
723{
724 // Some tests may need to disable the D3D11 SDK Layers Warnings checks
725 mIgnoreD3D11SDKLayersWarnings = true;
726}
727
Geoff Lang0d3683c2014-10-23 11:08:16 -0400728OSWindow *ANGLETest::mOSWindow = NULL;
729
730void ANGLETestEnvironment::SetUp()
731{
Jamie Madill776a75b2016-05-17 13:43:17 -0400732 mGLESLibrary.reset(angle::loadLibrary("libGLESv2"));
733 if (mGLESLibrary)
734 {
735 auto initFunc = reinterpret_cast<ANGLEPlatformInitializeFunc>(
736 mGLESLibrary->getSymbol("ANGLEPlatformInitialize"));
737 if (initFunc)
738 {
739 initFunc(&angle::g_testPlatformInstance);
740 }
741 }
742
Geoff Lang0d3683c2014-10-23 11:08:16 -0400743 if (!ANGLETest::InitTestWindow())
744 {
745 FAIL() << "Failed to create ANGLE test window.";
746 }
747}
748
749void ANGLETestEnvironment::TearDown()
750{
751 ANGLETest::DestroyTestWindow();
Jamie Madill776a75b2016-05-17 13:43:17 -0400752
753 if (mGLESLibrary)
754 {
755 auto shutdownFunc = reinterpret_cast<ANGLEPlatformShutdownFunc>(
756 mGLESLibrary->getSymbol("ANGLEPlatformShutdown"));
757 if (shutdownFunc)
758 {
759 shutdownFunc();
760 }
761 }
762}
763
764void IgnoreANGLEPlatformMessages()
765{
766 // Negative tests may trigger expected errors/warnings in the ANGLE Platform.
767 angle::g_testPlatformInstance.ignoreMessages();
Geoff Lang0d3683c2014-10-23 11:08:16 -0400768}