blob: d4133b42de884725e74707edd85f485f33e9a344 [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
Vincent Lang25ab4512016-05-13 18:13:59 +020025const GLColor16 GLColor16::white = GLColor16(65535u, 65535u, 65535u, 65535u);
26
Jamie Madill1fbc59f2016-02-24 15:25:51 -050027namespace
28{
29float ColorNorm(GLubyte channelValue)
30{
31 return static_cast<float>(channelValue) / 255.0f;
32}
Jamie Madill776a75b2016-05-17 13:43:17 -040033
34// Use a custom ANGLE platform class to capture and report internal errors.
35class TestPlatform : public angle::Platform
36{
37 public:
38 TestPlatform() : mIgnoreMessages(false) {}
39
40 void logError(const char *errorMessage) override;
41 void logWarning(const char *warningMessage) override;
42 void logInfo(const char *infoMessage) override;
43
44 void ignoreMessages();
45 void enableMessages();
46
47 private:
48 bool mIgnoreMessages;
49};
50
51void TestPlatform::logError(const char *errorMessage)
52{
53 if (mIgnoreMessages)
54 return;
55
56 FAIL() << errorMessage;
57}
58
59void TestPlatform::logWarning(const char *warningMessage)
60{
61 if (mIgnoreMessages)
62 return;
63
64 std::cerr << "Warning: " << warningMessage << std::endl;
65}
66
67void TestPlatform::logInfo(const char *infoMessage)
68{
69 if (mIgnoreMessages)
70 return;
71
72 angle::WriteDebugMessage("%s\n", infoMessage);
73}
74
75void TestPlatform::ignoreMessages()
76{
77 mIgnoreMessages = true;
78}
79
80void TestPlatform::enableMessages()
81{
82 mIgnoreMessages = false;
83}
84
85TestPlatform g_testPlatformInstance;
Jamie Madill1fbc59f2016-02-24 15:25:51 -050086} // anonymous namespace
87
Jamie Madill0dfa8072016-01-22 15:27:21 -050088GLColor::GLColor() : R(0), G(0), B(0), A(0)
89{
90}
91
92GLColor::GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a)
93{
94}
95
Jamie Madille2509a32016-02-01 14:09:05 -050096GLColor::GLColor(GLuint colorValue) : R(0), G(0), B(0), A(0)
97{
98 memcpy(&R, &colorValue, sizeof(GLuint));
99}
100
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500101Vector4 GLColor::toNormalizedVector() const
102{
103 return Vector4(ColorNorm(R), ColorNorm(G), ColorNorm(B), ColorNorm(A));
104}
105
Jamie Madill0dfa8072016-01-22 15:27:21 -0500106GLColor ReadColor(GLint x, GLint y)
107{
108 GLColor actual;
109 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &actual.R);
110 EXPECT_GL_NO_ERROR();
111 return actual;
112}
113
114bool operator==(const GLColor &a, const GLColor &b)
115{
116 return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
117}
118
119std::ostream &operator<<(std::ostream &ostream, const GLColor &color)
120{
121 ostream << "(" << static_cast<unsigned int>(color.R) << ", "
122 << static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B)
123 << ", " << static_cast<unsigned int>(color.A) << ")";
124 return ostream;
125}
126
Vincent Lang25ab4512016-05-13 18:13:59 +0200127GLColor16::GLColor16() : R(0), G(0), B(0), A(0)
128{
129}
130
131GLColor16::GLColor16(GLushort r, GLushort g, GLushort b, GLushort a) : R(r), G(g), B(b), A(a)
132{
133}
134
135GLColor16 ReadColor16(GLint x, GLint y)
136{
137 GLColor16 actual;
138 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_SHORT, &actual.R);
139 EXPECT_GL_NO_ERROR();
140 return actual;
141}
142
143bool operator==(const GLColor16 &a, const GLColor16 &b)
144{
145 return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
146}
147
148std::ostream &operator<<(std::ostream &ostream, const GLColor16 &color)
149{
150 ostream << "(" << static_cast<unsigned int>(color.R) << ", "
151 << static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B)
152 << ", " << static_cast<unsigned int>(color.A) << ")";
153 return ostream;
154}
155
Jamie Madill0dfa8072016-01-22 15:27:21 -0500156} // namespace angle
157
Jamie Madillfa05f602015-05-07 13:47:11 -0400158ANGLETest::ANGLETest()
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400159 : mEGLWindow(nullptr),
160 mWidth(16),
161 mHeight(16),
162 mIgnoreD3D11SDKLayersWarnings(false),
163 mQuadVertexBuffer(0)
Geoff Lang8a079e52013-10-18 16:13:33 -0400164{
Geoff Lang5ade8452015-09-02 11:00:30 -0400165 mEGLWindow =
166 new EGLWindow(GetParam().majorVersion, GetParam().minorVersion, GetParam().eglParameters);
Geoff Lang0d3683c2014-10-23 11:08:16 -0400167}
168
169ANGLETest::~ANGLETest()
170{
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400171 if (mQuadVertexBuffer)
172 {
173 glDeleteBuffers(1, &mQuadVertexBuffer);
174 }
Jamie Madill77a72f62015-04-14 11:18:32 -0400175 SafeDelete(mEGLWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400176}
177
Geoff Lang8a079e52013-10-18 16:13:33 -0400178void ANGLETest::SetUp()
179{
Jamie Madill776a75b2016-05-17 13:43:17 -0400180 angle::g_testPlatformInstance.enableMessages();
181
Corentin Wallezb44440d2015-07-22 17:54:20 -0400182 // Resize the window before creating the context so that the first make current
183 // sets the viewport and scissor box to the right size.
184 bool needSwap = false;
185 if (mOSWindow->getWidth() != mWidth || mOSWindow->getHeight() != mHeight)
Geoff Lang7f8dc492015-07-23 21:29:33 +0000186 {
Corentin Wallezb44440d2015-07-22 17:54:20 -0400187 if (!mOSWindow->resize(mWidth, mHeight))
188 {
189 FAIL() << "Failed to resize ANGLE test window.";
190 }
191 needSwap = true;
Geoff Lang7f8dc492015-07-23 21:29:33 +0000192 }
193
Geoff Lang8a079e52013-10-18 16:13:33 -0400194 if (!createEGLContext())
195 {
196 FAIL() << "egl context creation failed.";
197 }
Corentin Wallezb828b322015-07-16 17:51:30 -0400198
Corentin Wallezb44440d2015-07-22 17:54:20 -0400199 if (needSwap)
200 {
201 // Swap the buffers so that the default framebuffer picks up the resize
202 // which will allow follow-up test code to assume the framebuffer covers
203 // the whole window.
204 swapBuffers();
205 }
Corentin Wallez096725b2015-07-20 16:58:57 -0400206
Geoff Lang7f8dc492015-07-23 21:29:33 +0000207 // This Viewport command is not strictly necessary but we add it so that programs
208 // taking OpenGL traces can guess the size of the default framebuffer and show it
209 // in their UIs
210 glViewport(0, 0, mWidth, mHeight);
Jamie Madill508a5b72015-12-08 11:26:14 -0500211
212 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
213 angle::WriteDebugMessage("Entering %s.%s\n", info->test_case_name(), info->name());
Geoff Lang8a079e52013-10-18 16:13:33 -0400214}
215
216void ANGLETest::TearDown()
217{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800218 checkD3D11SDKLayersMessages();
219
Jamie Madill508a5b72015-12-08 11:26:14 -0500220 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
221 angle::WriteDebugMessage("Exiting %s.%s\n", info->test_case_name(), info->name());
222
Geoff Lang8a079e52013-10-18 16:13:33 -0400223 swapBuffers();
Jamie Madill9e16d402014-09-08 17:36:33 -0400224 mOSWindow->messageLoop();
225
Geoff Lang8a079e52013-10-18 16:13:33 -0400226 if (!destroyEGLContext())
227 {
228 FAIL() << "egl context destruction failed.";
229 }
Jamie Madill8add0eb2014-08-26 13:16:35 -0400230
231 // Check for quit message
232 Event myEvent;
233 while (mOSWindow->popEvent(&myEvent))
234 {
235 if (myEvent.Type == Event::EVENT_CLOSED)
236 {
237 exit(0);
238 }
239 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400240}
241
242void ANGLETest::swapBuffers()
243{
Jamie Madill77a72f62015-04-14 11:18:32 -0400244 if (mEGLWindow->isGLInitialized())
245 {
246 mEGLWindow->swap();
247 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400248}
249
Jamie Madill52b09c22016-04-11 14:12:31 -0400250// static
251std::array<Vector3, 6> ANGLETest::GetQuadVertices()
252{
253 std::array<Vector3, 6> vertices;
254 vertices[0] = Vector3(-1.0f, 1.0f, 0.5f);
255 vertices[1] = Vector3(-1.0f, -1.0f, 0.5f);
256 vertices[2] = Vector3(1.0f, -1.0f, 0.5f);
257 vertices[3] = Vector3(-1.0f, 1.0f, 0.5f);
258 vertices[4] = Vector3(1.0f, -1.0f, 0.5f);
259 vertices[5] = Vector3(1.0f, 1.0f, 0.5f);
260 return vertices;
261}
262
263void ANGLETest::setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale)
264{
265 if (mQuadVertexBuffer == 0)
266 {
267 glGenBuffers(1, &mQuadVertexBuffer);
268 }
269
270 auto quadVertices = GetQuadVertices();
271 for (Vector3 &vertex : quadVertices)
272 {
273 vertex.x *= positionAttribXYScale;
274 vertex.y *= positionAttribXYScale;
275 vertex.z = positionAttribZ;
276 }
277
278 glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer);
279 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 6, quadVertices.data(), GL_STATIC_DRAW);
280}
281
282// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200283void ANGLETest::drawQuad(GLuint program,
284 const std::string &positionAttribName,
285 GLfloat positionAttribZ)
286{
287 drawQuad(program, positionAttribName, positionAttribZ, 1.0f);
288}
289
Jamie Madill52b09c22016-04-11 14:12:31 -0400290// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200291void ANGLETest::drawQuad(GLuint program,
292 const std::string &positionAttribName,
293 GLfloat positionAttribZ,
294 GLfloat positionAttribXYScale)
Geoff Lang8a079e52013-10-18 16:13:33 -0400295{
Jamie Madill52b09c22016-04-11 14:12:31 -0400296 drawQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale, false);
297}
298
299void ANGLETest::drawQuad(GLuint program,
300 const std::string &positionAttribName,
301 GLfloat positionAttribZ,
302 GLfloat positionAttribXYScale,
303 bool useVertexBuffer)
304{
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200305 GLint previousProgram = 0;
306 glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgram);
307 if (previousProgram != static_cast<GLint>(program))
308 {
309 glUseProgram(program);
310 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400311
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200312 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
Geoff Lang8a079e52013-10-18 16:13:33 -0400313
Jamie Madill52b09c22016-04-11 14:12:31 -0400314 if (useVertexBuffer)
315 {
316 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
317 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
318 glBindBuffer(GL_ARRAY_BUFFER, 0);
319 }
320 else
321 {
322 auto quadVertices = GetQuadVertices();
323 for (Vector3 &vertex : quadVertices)
324 {
325 vertex.x *= positionAttribXYScale;
326 vertex.y *= positionAttribXYScale;
327 vertex.z = positionAttribZ;
328 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400329
Jamie Madill52b09c22016-04-11 14:12:31 -0400330 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, quadVertices.data());
331 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400332 glEnableVertexAttribArray(positionLocation);
333
334 glDrawArrays(GL_TRIANGLES, 0, 6);
335
336 glDisableVertexAttribArray(positionLocation);
337 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
338
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200339 if (previousProgram != static_cast<GLint>(program))
340 {
341 glUseProgram(previousProgram);
342 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400343}
344
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400345void ANGLETest::drawIndexedQuad(GLuint program,
346 const std::string &positionAttribName,
347 GLfloat positionAttribZ)
348{
349 drawIndexedQuad(program, positionAttribName, positionAttribZ, 1.0f);
350}
351
352void ANGLETest::drawIndexedQuad(GLuint program,
353 const std::string &positionAttribName,
354 GLfloat positionAttribZ,
355 GLfloat positionAttribXYScale)
356{
357 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
358
Jamie Madill52b09c22016-04-11 14:12:31 -0400359 GLint activeProgram = 0;
360 glGetIntegerv(GL_CURRENT_PROGRAM, &activeProgram);
361 if (static_cast<GLuint>(activeProgram) != program)
362 {
363 glUseProgram(program);
364 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400365
366 GLuint prevBinding = 0;
367 glGetIntegerv(GL_ARRAY_BUFFER_BINDING, reinterpret_cast<GLint *>(&prevBinding));
368
Jamie Madill52b09c22016-04-11 14:12:31 -0400369 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400370
371 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
372 glEnableVertexAttribArray(positionLocation);
373 glBindBuffer(GL_ARRAY_BUFFER, prevBinding);
374
375 const GLushort indices[] = {
376 0, 1, 2, 0, 2, 3,
377 };
378
379 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
380
381 glDisableVertexAttribArray(positionLocation);
382 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
383
Jamie Madill52b09c22016-04-11 14:12:31 -0400384 if (static_cast<GLuint>(activeProgram) != program)
385 {
386 glUseProgram(static_cast<GLuint>(activeProgram));
387 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400388}
389
Geoff Langefc551f2013-10-31 10:20:28 -0400390GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
391{
392 GLuint shader = glCreateShader(type);
393
394 const char *sourceArray[1] = { source.c_str() };
395 glShaderSource(shader, 1, sourceArray, NULL);
396 glCompileShader(shader);
397
398 GLint compileResult;
399 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
400
401 if (compileResult == 0)
402 {
403 GLint infoLogLength;
404 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
405
Jamie Madilld2c52e32015-10-14 17:07:05 -0400406 if (infoLogLength == 0)
407 {
408 std::cerr << "shader compilation failed with empty log." << std::endl;
409 }
410 else
411 {
412 std::vector<GLchar> infoLog(infoLogLength);
413 glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
Geoff Langefc551f2013-10-31 10:20:28 -0400414
Jamie Madilld2c52e32015-10-14 17:07:05 -0400415 std::cerr << "shader compilation failed: " << &infoLog[0];
416 }
Geoff Langefc551f2013-10-31 10:20:28 -0400417
418 glDeleteShader(shader);
419 shader = 0;
420 }
421
422 return shader;
423}
424
Austin Kinrossd544cc92016-01-11 15:26:42 -0800425void ANGLETest::checkD3D11SDKLayersMessages()
426{
427#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(NDEBUG)
428 // In debug D3D11 mode, check ID3D11InfoQueue to see if any D3D11 SDK Layers messages
429 // were outputted by the test
430 if (mIgnoreD3D11SDKLayersWarnings ||
431 mEGLWindow->getPlatform().renderer != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE ||
432 mEGLWindow->getDisplay() == EGL_NO_DISPLAY)
433 {
434 return;
435 }
436
437 const char *extensionString =
438 static_cast<const char *>(eglQueryString(mEGLWindow->getDisplay(), EGL_EXTENSIONS));
439 if (!strstr(extensionString, "EGL_EXT_device_query"))
440 {
441 return;
442 }
443
444 EGLAttrib device = 0;
445 EGLAttrib angleDevice = 0;
446
447 PFNEGLQUERYDISPLAYATTRIBEXTPROC queryDisplayAttribEXT;
448 PFNEGLQUERYDEVICEATTRIBEXTPROC queryDeviceAttribEXT;
449
450 queryDisplayAttribEXT = reinterpret_cast<PFNEGLQUERYDISPLAYATTRIBEXTPROC>(
451 eglGetProcAddress("eglQueryDisplayAttribEXT"));
452 queryDeviceAttribEXT = reinterpret_cast<PFNEGLQUERYDEVICEATTRIBEXTPROC>(
453 eglGetProcAddress("eglQueryDeviceAttribEXT"));
454 ASSERT_NE(nullptr, queryDisplayAttribEXT);
455 ASSERT_NE(nullptr, queryDeviceAttribEXT);
456
457 ASSERT_EGL_TRUE(queryDisplayAttribEXT(mEGLWindow->getDisplay(), EGL_DEVICE_EXT, &angleDevice));
458 ASSERT_EGL_TRUE(queryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(angleDevice),
459 EGL_D3D11_DEVICE_ANGLE, &device));
460 ID3D11Device *d3d11Device = reinterpret_cast<ID3D11Device *>(device);
461
462 ID3D11InfoQueue *infoQueue = nullptr;
463 HRESULT hr =
464 d3d11Device->QueryInterface(__uuidof(infoQueue), reinterpret_cast<void **>(&infoQueue));
465 if (SUCCEEDED(hr))
466 {
467 UINT64 numStoredD3DDebugMessages =
468 infoQueue->GetNumStoredMessagesAllowedByRetrievalFilter();
469
470 if (numStoredD3DDebugMessages > 0)
471 {
472 for (UINT64 i = 0; i < numStoredD3DDebugMessages; i++)
473 {
474 SIZE_T messageLength = 0;
475 hr = infoQueue->GetMessage(i, nullptr, &messageLength);
476
477 if (SUCCEEDED(hr))
478 {
479 D3D11_MESSAGE *pMessage =
480 reinterpret_cast<D3D11_MESSAGE *>(malloc(messageLength));
481 infoQueue->GetMessage(i, pMessage, &messageLength);
482
483 std::cout << "Message " << i << ":"
484 << " " << pMessage->pDescription << "\n";
485 free(pMessage);
486 }
487 }
488
489 FAIL() << numStoredD3DDebugMessages
490 << " D3D11 SDK Layers message(s) detected! Test Failed.\n";
491 }
492 }
493
494 SafeRelease(infoQueue);
495#endif
496}
497
Geoff Lang63046e22015-07-21 12:43:50 -0400498static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
499{
500 return strstr(allExtensions, extName.c_str()) != nullptr;
501}
502
Geoff Lang8a079e52013-10-18 16:13:33 -0400503bool ANGLETest::extensionEnabled(const std::string &extName)
504{
Geoff Lang63046e22015-07-21 12:43:50 -0400505 return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
506 extName);
507}
508
509bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
510{
511 return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
512}
513
514bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
515{
516 return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
Geoff Lang8a079e52013-10-18 16:13:33 -0400517}
518
Geoff Lang8a079e52013-10-18 16:13:33 -0400519void ANGLETest::setWindowWidth(int width)
520{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400521 mWidth = width;
Geoff Lang8a079e52013-10-18 16:13:33 -0400522}
523
524void ANGLETest::setWindowHeight(int height)
525{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400526 mHeight = height;
Geoff Lang8a079e52013-10-18 16:13:33 -0400527}
528
Geoff Langefc551f2013-10-31 10:20:28 -0400529void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400530{
Jamie Madill62af5462014-08-26 13:16:37 -0400531 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400532}
533
Geoff Langefc551f2013-10-31 10:20:28 -0400534void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400535{
Jamie Madill62af5462014-08-26 13:16:37 -0400536 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400537}
538
Geoff Langefc551f2013-10-31 10:20:28 -0400539void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400540{
Jamie Madill62af5462014-08-26 13:16:37 -0400541 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400542}
543
Geoff Langefc551f2013-10-31 10:20:28 -0400544void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400545{
Jamie Madill62af5462014-08-26 13:16:37 -0400546 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400547}
548
Geoff Langefc551f2013-10-31 10:20:28 -0400549void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400550{
Jamie Madill62af5462014-08-26 13:16:37 -0400551 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400552}
553
Geoff Langefc551f2013-10-31 10:20:28 -0400554void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400555{
Jamie Madill62af5462014-08-26 13:16:37 -0400556 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400557}
558
559void ANGLETest::setMultisampleEnabled(bool enabled)
560{
Jamie Madill62af5462014-08-26 13:16:37 -0400561 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400562}
563
Geoff Lang70d0f492015-12-10 17:45:46 -0500564void ANGLETest::setDebugEnabled(bool enabled)
565{
566 mEGLWindow->setDebugEnabled(enabled);
567}
568
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500569void ANGLETest::setNoErrorEnabled(bool enabled)
570{
571 mEGLWindow->setNoErrorEnabled(enabled);
572}
573
Geoff Lang8a079e52013-10-18 16:13:33 -0400574int ANGLETest::getClientVersion() const
575{
Geoff Lang5ade8452015-09-02 11:00:30 -0400576 return mEGLWindow->getClientMajorVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400577}
578
Vincent Lang25ab4512016-05-13 18:13:59 +0200579int ANGLETest::getClientMinorVersion() const
580{
581 return mEGLWindow->getClientMinorVersion();
582}
583
Geoff Langb9266272015-01-29 13:25:14 +0000584EGLWindow *ANGLETest::getEGLWindow() const
585{
586 return mEGLWindow;
587}
588
Geoff Lang8a079e52013-10-18 16:13:33 -0400589int ANGLETest::getWindowWidth() const
590{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400591 return mWidth;
Geoff Lang8a079e52013-10-18 16:13:33 -0400592}
593
594int ANGLETest::getWindowHeight() const
595{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400596 return mHeight;
Geoff Lang8a079e52013-10-18 16:13:33 -0400597}
598
Geoff Langefc551f2013-10-31 10:20:28 -0400599bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400600{
Jamie Madill62af5462014-08-26 13:16:37 -0400601 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400602}
603
604bool ANGLETest::createEGLContext()
605{
Jamie Madill62af5462014-08-26 13:16:37 -0400606 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400607}
608
609bool ANGLETest::destroyEGLContext()
610{
Jamie Madill62af5462014-08-26 13:16:37 -0400611 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400612 return true;
613}
Geoff Langbb134672013-10-23 13:06:46 -0400614
Geoff Lang0d3683c2014-10-23 11:08:16 -0400615bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400616{
617 mOSWindow = CreateOSWindow();
618 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
619 {
620 return false;
621 }
622
Geoff Lang0d3683c2014-10-23 11:08:16 -0400623 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400624
625 return true;
626}
627
Geoff Lang0d3683c2014-10-23 11:08:16 -0400628bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400629{
630 if (mOSWindow)
631 {
632 mOSWindow->destroy();
633 delete mOSWindow;
634 mOSWindow = NULL;
635 }
636
637 return true;
638}
639
Geoff Lang0d3683c2014-10-23 11:08:16 -0400640void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400641{
Jamie Madill4119ed32014-10-01 10:41:40 -0400642 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400643}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400644
Jamie Madill518b9fa2016-03-02 11:26:02 -0500645bool IsIntel()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500646{
647 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
648 return (rendererString.find("Intel") != std::string::npos);
649}
650
Jamie Madill518b9fa2016-03-02 11:26:02 -0500651bool IsAMD()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500652{
653 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
654 return (rendererString.find("AMD") != std::string::npos) ||
655 (rendererString.find("ATI") != std::string::npos);
656}
657
Jamie Madill518b9fa2016-03-02 11:26:02 -0500658bool IsNVIDIA()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500659{
660 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
661 return (rendererString.find("NVIDIA") != std::string::npos);
662}
663
Jamie Madill518b9fa2016-03-02 11:26:02 -0500664bool IsD3D11()
Jamie Madilld55d2832015-10-27 13:59:19 -0400665{
666 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
667 return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos);
668}
669
Jamie Madill518b9fa2016-03-02 11:26:02 -0500670bool IsD3D11_FL93()
Jamie Madill9fc36822015-11-18 13:08:07 -0500671{
672 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
673 return (rendererString.find("Direct3D11 vs_4_0_") != std::string::npos);
674}
675
Jamie Madill518b9fa2016-03-02 11:26:02 -0500676bool IsD3D9()
Jamie Madill9fc36822015-11-18 13:08:07 -0500677{
678 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
679 return (rendererString.find("Direct3D9") != std::string::npos);
680}
681
Jamie Madill518b9fa2016-03-02 11:26:02 -0500682bool IsD3DSM3()
Jamie Madill9fc36822015-11-18 13:08:07 -0500683{
Jamie Madill518b9fa2016-03-02 11:26:02 -0500684 return IsD3D9() || IsD3D11_FL93();
Jamie Madill9fc36822015-11-18 13:08:07 -0500685}
686
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400687bool IsLinux()
688{
689#if defined(ANGLE_PLATFORM_LINUX)
690 return true;
691#else
692 return false;
693#endif
694}
695
Jamie Madill518b9fa2016-03-02 11:26:02 -0500696bool IsOSX()
Ian Ewell292f0052016-02-04 10:37:32 -0500697{
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400698#if defined(ANGLE_PLATFORM_APPLE)
Ian Ewell292f0052016-02-04 10:37:32 -0500699 return true;
700#else
701 return false;
702#endif
703}
704
Jamie Madill518b9fa2016-03-02 11:26:02 -0500705bool ANGLETest::isOpenGL() const
706{
707 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
708}
709
Olli Etuaho87fc71c2016-05-11 14:25:21 +0300710bool ANGLETest::isGLES() const
711{
712 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE;
713}
714
Jamie Madillc3b9b262015-01-30 14:00:51 -0500715EGLint ANGLETest::getPlatformRenderer() const
716{
Jamie Madillf6859912015-01-30 17:05:35 -0500717 assert(mEGLWindow);
718 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500719}
720
Austin Kinrossd544cc92016-01-11 15:26:42 -0800721void ANGLETest::ignoreD3D11SDKLayersWarnings()
722{
723 // Some tests may need to disable the D3D11 SDK Layers Warnings checks
724 mIgnoreD3D11SDKLayersWarnings = true;
725}
726
Geoff Lang0d3683c2014-10-23 11:08:16 -0400727OSWindow *ANGLETest::mOSWindow = NULL;
728
729void ANGLETestEnvironment::SetUp()
730{
Jamie Madill776a75b2016-05-17 13:43:17 -0400731 mGLESLibrary.reset(angle::loadLibrary("libGLESv2"));
732 if (mGLESLibrary)
733 {
734 auto initFunc = reinterpret_cast<ANGLEPlatformInitializeFunc>(
735 mGLESLibrary->getSymbol("ANGLEPlatformInitialize"));
736 if (initFunc)
737 {
738 initFunc(&angle::g_testPlatformInstance);
739 }
740 }
741
Geoff Lang0d3683c2014-10-23 11:08:16 -0400742 if (!ANGLETest::InitTestWindow())
743 {
744 FAIL() << "Failed to create ANGLE test window.";
745 }
746}
747
748void ANGLETestEnvironment::TearDown()
749{
750 ANGLETest::DestroyTestWindow();
Jamie Madill776a75b2016-05-17 13:43:17 -0400751
752 if (mGLESLibrary)
753 {
754 auto shutdownFunc = reinterpret_cast<ANGLEPlatformShutdownFunc>(
755 mGLESLibrary->getSymbol("ANGLEPlatformShutdown"));
756 if (shutdownFunc)
757 {
758 shutdownFunc();
759 }
760 }
761}
762
763void IgnoreANGLEPlatformMessages()
764{
765 // Negative tests may trigger expected errors/warnings in the ANGLE Platform.
766 angle::g_testPlatformInstance.ignoreMessages();
Geoff Lang0d3683c2014-10-23 11:08:16 -0400767}