Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/test_utils/ANGLETest.cpp
1693 views
1
//
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
10
#include "ANGLETest.h"
11
12
#include <algorithm>
13
#include <cstdlib>
14
15
#include "common/platform.h"
16
#include "gpu_info_util/SystemInfo.h"
17
#include "test_utils/runner/TestSuite.h"
18
#include "util/EGLWindow.h"
19
#include "util/OSWindow.h"
20
#include "util/random_utils.h"
21
#include "util/test_utils.h"
22
23
#if defined(ANGLE_PLATFORM_WINDOWS)
24
# include <VersionHelpers.h>
25
#endif // defined(ANGLE_PLATFORM_WINDOWS)
26
27
namespace angle
28
{
29
30
const GLColorRGB GLColorRGB::black(0u, 0u, 0u);
31
const GLColorRGB GLColorRGB::blue(0u, 0u, 255u);
32
const GLColorRGB GLColorRGB::green(0u, 255u, 0u);
33
const GLColorRGB GLColorRGB::red(255u, 0u, 0u);
34
const GLColorRGB GLColorRGB::yellow(255u, 255u, 0);
35
36
const GLColor GLColor::black = GLColor(0u, 0u, 0u, 255u);
37
const GLColor GLColor::blue = GLColor(0u, 0u, 255u, 255u);
38
const GLColor GLColor::cyan = GLColor(0u, 255u, 255u, 255u);
39
const GLColor GLColor::green = GLColor(0u, 255u, 0u, 255u);
40
const GLColor GLColor::red = GLColor(255u, 0u, 0u, 255u);
41
const GLColor GLColor::transparentBlack = GLColor(0u, 0u, 0u, 0u);
42
const GLColor GLColor::white = GLColor(255u, 255u, 255u, 255u);
43
const GLColor GLColor::yellow = GLColor(255u, 255u, 0, 255u);
44
const GLColor GLColor::magenta = GLColor(255u, 0u, 255u, 255u);
45
46
namespace
47
{
48
float ColorNorm(GLubyte channelValue)
49
{
50
return static_cast<float>(channelValue) / 255.0f;
51
}
52
53
GLubyte ColorDenorm(float colorValue)
54
{
55
return static_cast<GLubyte>(colorValue * 255.0f);
56
}
57
58
void TestPlatform_logError(PlatformMethods *platform, const char *errorMessage)
59
{
60
auto *testPlatformContext = static_cast<TestPlatformContext *>(platform->context);
61
if (testPlatformContext->ignoreMessages)
62
return;
63
64
GTEST_NONFATAL_FAILURE_(errorMessage);
65
66
PrintStackBacktrace();
67
}
68
69
void TestPlatform_logWarning(PlatformMethods *platform, const char *warningMessage)
70
{
71
auto *testPlatformContext = static_cast<TestPlatformContext *>(platform->context);
72
if (testPlatformContext->ignoreMessages)
73
return;
74
75
if (testPlatformContext->warningsAsErrors)
76
{
77
FAIL() << warningMessage;
78
}
79
else
80
{
81
std::cerr << "Warning: " << warningMessage << std::endl;
82
}
83
}
84
85
void TestPlatform_logInfo(PlatformMethods *platform, const char *infoMessage) {}
86
87
void TestPlatform_overrideWorkaroundsD3D(PlatformMethods *platform, FeaturesD3D *featuresD3D)
88
{
89
auto *testPlatformContext = static_cast<TestPlatformContext *>(platform->context);
90
if (testPlatformContext->currentTest)
91
{
92
testPlatformContext->currentTest->overrideWorkaroundsD3D(featuresD3D);
93
}
94
}
95
96
void TestPlatform_overrideFeaturesVk(PlatformMethods *platform, FeaturesVk *featuresVulkan)
97
{
98
auto *testPlatformContext = static_cast<TestPlatformContext *>(platform->context);
99
if (testPlatformContext->currentTest)
100
{
101
testPlatformContext->currentTest->overrideFeaturesVk(featuresVulkan);
102
}
103
}
104
105
const std::array<Vector3, 6> kQuadVertices = {{
106
Vector3(-1.0f, 1.0f, 0.5f),
107
Vector3(-1.0f, -1.0f, 0.5f),
108
Vector3(1.0f, -1.0f, 0.5f),
109
Vector3(-1.0f, 1.0f, 0.5f),
110
Vector3(1.0f, -1.0f, 0.5f),
111
Vector3(1.0f, 1.0f, 0.5f),
112
}};
113
114
const std::array<Vector3, 4> kIndexedQuadVertices = {{
115
Vector3(-1.0f, 1.0f, 0.5f),
116
Vector3(-1.0f, -1.0f, 0.5f),
117
Vector3(1.0f, -1.0f, 0.5f),
118
Vector3(1.0f, 1.0f, 0.5f),
119
}};
120
121
constexpr std::array<GLushort, 6> kIndexedQuadIndices = {{0, 1, 2, 0, 2, 3}};
122
123
const char *GetColorName(GLColor color)
124
{
125
if (color == GLColor::red)
126
{
127
return "Red";
128
}
129
130
if (color == GLColor::green)
131
{
132
return "Green";
133
}
134
135
if (color == GLColor::blue)
136
{
137
return "Blue";
138
}
139
140
if (color == GLColor::white)
141
{
142
return "White";
143
}
144
145
if (color == GLColor::black)
146
{
147
return "Black";
148
}
149
150
if (color == GLColor::transparentBlack)
151
{
152
return "Transparent Black";
153
}
154
155
if (color == GLColor::yellow)
156
{
157
return "Yellow";
158
}
159
160
if (color == GLColor::magenta)
161
{
162
return "Magenta";
163
}
164
165
if (color == GLColor::cyan)
166
{
167
return "Cyan";
168
}
169
170
return nullptr;
171
}
172
173
const char *GetColorName(GLColorRGB color)
174
{
175
return GetColorName(GLColor(color.R, color.G, color.B, 255));
176
}
177
178
// Always re-use displays when using --bot-mode in the test runner.
179
bool gReuseDisplays = false;
180
181
bool ShouldAlwaysForceNewDisplay()
182
{
183
if (gReuseDisplays)
184
return false;
185
186
// We prefer to reuse config displays. This is faster and solves a driver issue where creating
187
// many displays causes crashes. However this exposes other driver bugs on many other platforms.
188
// Conservatively enable the feature only on Windows Intel and NVIDIA for now.
189
SystemInfo *systemInfo = GetTestSystemInfo();
190
return (!systemInfo || !IsWindows() || systemInfo->hasAMDGPU());
191
}
192
193
GPUTestConfig::API GetTestConfigAPIFromRenderer(EGLenum renderer, EGLenum deviceType)
194
{
195
switch (renderer)
196
{
197
case EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE:
198
return GPUTestConfig::kAPID3D11;
199
case EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE:
200
return GPUTestConfig::kAPID3D9;
201
case EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE:
202
return GPUTestConfig::kAPIGLDesktop;
203
case EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE:
204
return GPUTestConfig::kAPIGLES;
205
case EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE:
206
if (deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_SWIFTSHADER_ANGLE)
207
{
208
return GPUTestConfig::kAPISwiftShader;
209
}
210
else
211
{
212
return GPUTestConfig::kAPIVulkan;
213
}
214
case EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE:
215
return GPUTestConfig::kAPIMetal;
216
default:
217
std::cerr << "Unknown Renderer enum: 0x%X\n" << renderer;
218
return GPUTestConfig::kAPIUnknown;
219
}
220
}
221
} // anonymous namespace
222
223
GLColorRGB::GLColorRGB(const Vector3 &floatColor)
224
: R(ColorDenorm(floatColor.x())), G(ColorDenorm(floatColor.y())), B(ColorDenorm(floatColor.z()))
225
{}
226
227
GLColor::GLColor(const Vector4 &floatColor)
228
: R(ColorDenorm(floatColor.x())),
229
G(ColorDenorm(floatColor.y())),
230
B(ColorDenorm(floatColor.z())),
231
A(ColorDenorm(floatColor.w()))
232
{}
233
234
GLColor::GLColor(GLuint colorValue) : R(0), G(0), B(0), A(0)
235
{
236
memcpy(&R, &colorValue, sizeof(GLuint));
237
}
238
239
GLuint GLColor::asUint() const
240
{
241
GLuint uint = 0;
242
memcpy(&uint, &R, sizeof(GLuint));
243
return uint;
244
}
245
246
testing::AssertionResult GLColor::ExpectNear(const GLColor &expected, const GLColor &err) const
247
{
248
testing::AssertionResult result(
249
abs(int(expected.R) - this->R) <= err.R && abs(int(expected.G) - this->G) <= err.G &&
250
abs(int(expected.B) - this->B) <= err.B && abs(int(expected.A) - this->A) <= err.A);
251
if (!bool(result))
252
{
253
result << "Expected " << expected << "+/-" << err << ", was " << *this;
254
}
255
return result;
256
}
257
258
void CreatePixelCenterWindowCoords(const std::vector<Vector2> &pixelPoints,
259
int windowWidth,
260
int windowHeight,
261
std::vector<Vector3> *outVertices)
262
{
263
for (Vector2 pixelPoint : pixelPoints)
264
{
265
outVertices->emplace_back(Vector3((pixelPoint[0] + 0.5f) * 2.0f / windowWidth - 1.0f,
266
(pixelPoint[1] + 0.5f) * 2.0f / windowHeight - 1.0f,
267
0.0f));
268
}
269
}
270
271
Vector4 GLColor::toNormalizedVector() const
272
{
273
return Vector4(ColorNorm(R), ColorNorm(G), ColorNorm(B), ColorNorm(A));
274
}
275
276
GLColor RandomColor(angle::RNG *rng)
277
{
278
return GLColor(rng->randomIntBetween(0, 255), rng->randomIntBetween(0, 255),
279
rng->randomIntBetween(0, 255), rng->randomIntBetween(0, 255));
280
}
281
282
GLColor ReadColor(GLint x, GLint y)
283
{
284
GLColor actual;
285
glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &actual.R);
286
EXPECT_GL_NO_ERROR();
287
return actual;
288
}
289
290
bool operator==(const GLColor &a, const GLColor &b)
291
{
292
return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
293
}
294
295
bool operator!=(const GLColor &a, const GLColor &b)
296
{
297
return !(a == b);
298
}
299
300
std::ostream &operator<<(std::ostream &ostream, const GLColor &color)
301
{
302
const char *colorName = GetColorName(color);
303
if (colorName)
304
{
305
return ostream << colorName;
306
}
307
308
ostream << "(" << static_cast<unsigned int>(color.R) << ", "
309
<< static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B)
310
<< ", " << static_cast<unsigned int>(color.A) << ")";
311
return ostream;
312
}
313
314
bool operator==(const GLColorRGB &a, const GLColorRGB &b)
315
{
316
return a.R == b.R && a.G == b.G && a.B == b.B;
317
}
318
319
bool operator!=(const GLColorRGB &a, const GLColorRGB &b)
320
{
321
return !(a == b);
322
}
323
324
std::ostream &operator<<(std::ostream &ostream, const GLColorRGB &color)
325
{
326
const char *colorName = GetColorName(color);
327
if (colorName)
328
{
329
return ostream << colorName;
330
}
331
332
ostream << "(" << static_cast<unsigned int>(color.R) << ", "
333
<< static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B)
334
<< ")";
335
return ostream;
336
}
337
338
bool operator==(const GLColor32F &a, const GLColor32F &b)
339
{
340
return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
341
}
342
343
std::ostream &operator<<(std::ostream &ostream, const GLColor32F &color)
344
{
345
ostream << "(" << color.R << ", " << color.G << ", " << color.B << ", " << color.A << ")";
346
return ostream;
347
}
348
349
GLColor32F ReadColor32F(GLint x, GLint y)
350
{
351
GLColor32F actual;
352
glReadPixels((x), (y), 1, 1, GL_RGBA, GL_FLOAT, &actual.R);
353
EXPECT_GL_NO_ERROR();
354
return actual;
355
}
356
357
void LoadEntryPointsWithUtilLoader(angle::GLESDriverType driverType)
358
{
359
#if defined(ANGLE_USE_UTIL_LOADER)
360
PFNEGLGETPROCADDRESSPROC getProcAddress;
361
ANGLETestEnvironment::GetDriverLibrary(driverType)->getAs("eglGetProcAddress", &getProcAddress);
362
ASSERT_NE(nullptr, getProcAddress);
363
364
LoadEGL(getProcAddress);
365
LoadGLES(getProcAddress);
366
#endif // defined(ANGLE_USE_UTIL_LOADER)
367
}
368
} // namespace angle
369
370
using namespace angle;
371
372
PlatformMethods gDefaultPlatformMethods;
373
374
namespace
375
{
376
TestPlatformContext gPlatformContext;
377
378
// After a fixed number of iterations we reset the test window. This works around some driver bugs.
379
constexpr uint32_t kWindowReuseLimit = 50;
380
381
constexpr char kUseConfig[] = "--use-config=";
382
constexpr char kReuseDisplays[] = "--reuse-displays";
383
constexpr char kEnableANGLEPerTestCaptureLabel[] = "--angle-per-test-capture-label";
384
constexpr char kBatchId[] = "--batch-id=";
385
constexpr char kDelayTestStart[] = "--delay-test-start=";
386
constexpr char kRenderDoc[] = "--renderdoc";
387
388
void SetupEnvironmentVarsForCaptureReplay()
389
{
390
const ::testing::TestInfo *const testInfo =
391
::testing::UnitTest::GetInstance()->current_test_info();
392
std::string testName = std::string{testInfo->name()};
393
std::replace(testName.begin(), testName.end(), '/', '_');
394
SetEnvironmentVar("ANGLE_CAPTURE_LABEL",
395
(std::string{testInfo->test_case_name()} + "_" + testName).c_str());
396
}
397
} // anonymous namespace
398
399
int gTestStartDelaySeconds = 0;
400
401
int GetTestStartDelaySeconds()
402
{
403
return gTestStartDelaySeconds;
404
}
405
406
void SetTestStartDelay(const char *testStartDelay)
407
{
408
gTestStartDelaySeconds = std::stoi(testStartDelay);
409
}
410
411
bool gEnableRenderDocCapture = false;
412
413
// static
414
std::array<Vector3, 6> ANGLETestBase::GetQuadVertices()
415
{
416
return kQuadVertices;
417
}
418
419
// static
420
std::array<GLushort, 6> ANGLETestBase::GetQuadIndices()
421
{
422
return kIndexedQuadIndices;
423
}
424
425
// static
426
std::array<Vector3, 4> ANGLETestBase::GetIndexedQuadVertices()
427
{
428
return kIndexedQuadVertices;
429
}
430
431
testing::AssertionResult AssertEGLEnumsEqual(const char *lhsExpr,
432
const char *rhsExpr,
433
EGLenum lhs,
434
EGLenum rhs)
435
{
436
if (lhs == rhs)
437
{
438
return testing::AssertionSuccess();
439
}
440
else
441
{
442
std::stringstream strstr;
443
strstr << std::hex << lhsExpr << " (0x" << int(lhs) << ") != " << rhsExpr << " (0x"
444
<< int(rhs) << ")";
445
return testing::AssertionFailure() << strstr.str();
446
}
447
}
448
449
ANGLETestBase::ANGLETestBase(const PlatformParameters &params)
450
: mWidth(16),
451
mHeight(16),
452
mIgnoreD3D11SDKLayersWarnings(false),
453
mQuadVertexBuffer(0),
454
mQuadIndexBuffer(0),
455
m2DTexturedQuadProgram(0),
456
m3DTexturedQuadProgram(0),
457
mDeferContextInit(false),
458
mAlwaysForceNewDisplay(ShouldAlwaysForceNewDisplay()),
459
mForceNewDisplay(mAlwaysForceNewDisplay),
460
mSetUpCalled(false),
461
mTearDownCalled(false),
462
mCurrentParams(nullptr),
463
mFixture(nullptr)
464
{
465
// Override the default platform methods with the ANGLE test methods pointer.
466
PlatformParameters withMethods = params;
467
withMethods.eglParameters.platformMethods = &gDefaultPlatformMethods;
468
469
if (withMethods.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)
470
{
471
#if defined(ANGLE_ENABLE_VULKAN_VALIDATION_LAYERS)
472
withMethods.eglParameters.debugLayersEnabled = true;
473
#else
474
withMethods.eglParameters.debugLayersEnabled = false;
475
#endif
476
}
477
478
if (gEnableRenderDocCapture)
479
{
480
mRenderDoc.attach();
481
}
482
483
auto iter = gFixtures.find(withMethods);
484
if (iter != gFixtures.end())
485
{
486
mCurrentParams = &iter->first;
487
488
if (!params.noFixture)
489
{
490
mFixture = &iter->second;
491
mFixture->configParams.reset();
492
}
493
return;
494
}
495
496
TestFixture platform;
497
auto insertIter = gFixtures.emplace(withMethods, platform);
498
mCurrentParams = &insertIter.first->first;
499
500
if (!params.noFixture)
501
{
502
mFixture = &insertIter.first->second;
503
initOSWindow();
504
}
505
}
506
507
void ANGLETestBase::initOSWindow()
508
{
509
std::stringstream windowNameStream;
510
windowNameStream << "ANGLE Tests - " << *mCurrentParams;
511
std::string windowName = windowNameStream.str();
512
513
if (IsAndroid())
514
{
515
// Only one window per test application on Android, shared among all fixtures
516
mFixture->osWindow = mOSWindowSingleton;
517
}
518
519
if (!mFixture->osWindow)
520
{
521
mFixture->osWindow = OSWindow::New();
522
mFixture->osWindow->disableErrorMessageDialog();
523
if (!mFixture->osWindow->initialize(windowName.c_str(), 128, 128))
524
{
525
std::cerr << "Failed to initialize OS Window.\n";
526
}
527
528
if (IsAndroid())
529
{
530
// Initialize the single window on Andoird only once
531
mOSWindowSingleton = mFixture->osWindow;
532
}
533
}
534
535
if (!mFixture->osWindow->valid())
536
{
537
return;
538
}
539
540
// On Linux we must keep the test windows visible. On Windows it doesn't seem to need it.
541
setWindowVisible(getOSWindow(), !IsWindows());
542
543
switch (mCurrentParams->driver)
544
{
545
case GLESDriverType::AngleEGL:
546
case GLESDriverType::SystemEGL:
547
{
548
mFixture->eglWindow =
549
EGLWindow::New(mCurrentParams->majorVersion, mCurrentParams->minorVersion);
550
break;
551
}
552
553
case GLESDriverType::SystemWGL:
554
{
555
// WGL tests are currently disabled.
556
std::cerr << "Unsupported driver." << std::endl;
557
break;
558
}
559
}
560
}
561
562
ANGLETestBase::~ANGLETestBase()
563
{
564
if (mQuadVertexBuffer)
565
{
566
glDeleteBuffers(1, &mQuadVertexBuffer);
567
}
568
if (mQuadIndexBuffer)
569
{
570
glDeleteBuffers(1, &mQuadIndexBuffer);
571
}
572
if (m2DTexturedQuadProgram)
573
{
574
glDeleteProgram(m2DTexturedQuadProgram);
575
}
576
if (m3DTexturedQuadProgram)
577
{
578
glDeleteProgram(m3DTexturedQuadProgram);
579
}
580
581
if (!mSetUpCalled)
582
{
583
GTEST_NONFATAL_FAILURE_("SetUp not called.");
584
}
585
586
if (!mTearDownCalled)
587
{
588
GTEST_NONFATAL_FAILURE_("TearDown not called.");
589
}
590
}
591
592
void ANGLETestBase::ANGLETestSetUp()
593
{
594
mSetUpCalled = true;
595
596
// Delay test startup to allow a debugger to attach.
597
if (GetTestStartDelaySeconds())
598
{
599
angle::Sleep(GetTestStartDelaySeconds() * 1000);
600
}
601
602
gDefaultPlatformMethods.overrideWorkaroundsD3D = TestPlatform_overrideWorkaroundsD3D;
603
gDefaultPlatformMethods.overrideFeaturesVk = TestPlatform_overrideFeaturesVk;
604
gDefaultPlatformMethods.logError = TestPlatform_logError;
605
gDefaultPlatformMethods.logWarning = TestPlatform_logWarning;
606
gDefaultPlatformMethods.logInfo = TestPlatform_logInfo;
607
gDefaultPlatformMethods.context = &gPlatformContext;
608
609
gPlatformContext.ignoreMessages = false;
610
gPlatformContext.warningsAsErrors = false;
611
gPlatformContext.currentTest = this;
612
613
const testing::TestInfo *testInfo = testing::UnitTest::GetInstance()->current_test_info();
614
615
// Check the skip list.
616
617
angle::GPUTestConfig::API api = GetTestConfigAPIFromRenderer(mCurrentParams->getRenderer(),
618
mCurrentParams->getDeviceType());
619
GPUTestConfig testConfig = GPUTestConfig(api, 0, false);
620
621
std::stringstream fullTestNameStr;
622
fullTestNameStr << testInfo->test_case_name() << "." << testInfo->name();
623
std::string fullTestName = fullTestNameStr.str();
624
625
TestSuite *testSuite = TestSuite::GetInstance();
626
int32_t testExpectation =
627
testSuite->getTestExpectationWithConfigAndUpdateTimeout(testConfig, fullTestName);
628
629
if (testExpectation == GPUTestExpectationsParser::kGpuTestSkip)
630
{
631
GTEST_SKIP() << "Test skipped on this config";
632
}
633
634
if (IsWindows())
635
{
636
WriteDebugMessage("Entering %s\n", fullTestName.c_str());
637
}
638
639
if (mCurrentParams->noFixture)
640
{
641
LoadEntryPointsWithUtilLoader(mCurrentParams->driver);
642
mIsSetUp = true;
643
return;
644
}
645
646
if (mLastLoadedDriver.valid() && mCurrentParams->driver != mLastLoadedDriver.value())
647
{
648
LoadEntryPointsWithUtilLoader(mCurrentParams->driver);
649
mLastLoadedDriver = mCurrentParams->driver;
650
}
651
652
if (gEnableANGLEPerTestCaptureLabel)
653
{
654
SetupEnvironmentVarsForCaptureReplay();
655
}
656
657
if (!mFixture->osWindow->valid())
658
{
659
mIsSetUp = true;
660
return;
661
}
662
663
// Resize the window before creating the context so that the first make current
664
// sets the viewport and scissor box to the right size.
665
bool needSwap = false;
666
667
int osWindowWidth = mFixture->osWindow->getWidth();
668
int osWindowHeight = mFixture->osWindow->getHeight();
669
670
const bool isRotated = mCurrentParams->eglParameters.emulatedPrerotation == 90 ||
671
mCurrentParams->eglParameters.emulatedPrerotation == 270;
672
if (isRotated)
673
{
674
std::swap(osWindowWidth, osWindowHeight);
675
}
676
677
if (osWindowWidth != mWidth || osWindowHeight != mHeight)
678
{
679
int newWindowWidth = mWidth;
680
int newWindowHeight = mHeight;
681
if (isRotated)
682
{
683
std::swap(newWindowWidth, newWindowHeight);
684
}
685
686
if (!mFixture->osWindow->resize(newWindowWidth, newWindowHeight))
687
{
688
FAIL() << "Failed to resize ANGLE test window.";
689
}
690
needSwap = true;
691
}
692
// WGL tests are currently disabled.
693
if (mFixture->wglWindow)
694
{
695
FAIL() << "Unsupported driver.";
696
}
697
else
698
{
699
Library *driverLib = ANGLETestEnvironment::GetDriverLibrary(mCurrentParams->driver);
700
701
if (mForceNewDisplay || !mFixture->eglWindow->isDisplayInitialized())
702
{
703
mFixture->eglWindow->destroyGL();
704
if (!mFixture->eglWindow->initializeDisplay(mFixture->osWindow, driverLib,
705
mCurrentParams->driver,
706
mCurrentParams->eglParameters))
707
{
708
FAIL() << "EGL Display init failed.";
709
}
710
}
711
else if (mCurrentParams->eglParameters != mFixture->eglWindow->getPlatform())
712
{
713
FAIL() << "Internal parameter conflict error.";
714
}
715
716
if (!mFixture->eglWindow->initializeSurface(mFixture->osWindow, driverLib,
717
mFixture->configParams))
718
{
719
FAIL() << "egl surface init failed.";
720
}
721
722
if (!mDeferContextInit && !mFixture->eglWindow->initializeContext())
723
{
724
FAIL() << "GL Context init failed.";
725
}
726
}
727
728
if (needSwap)
729
{
730
// Swap the buffers so that the default framebuffer picks up the resize
731
// which will allow follow-up test code to assume the framebuffer covers
732
// the whole window.
733
swapBuffers();
734
}
735
736
// This Viewport command is not strictly necessary but we add it so that programs
737
// taking OpenGL traces can guess the size of the default framebuffer and show it
738
// in their UIs
739
glViewport(0, 0, mWidth, mHeight);
740
741
mIsSetUp = true;
742
743
mRenderDoc.startFrame();
744
}
745
746
void ANGLETestBase::ANGLETestPreTearDown()
747
{
748
// We swap an extra time before we call "tearDown" to capture resources before they're freed.
749
if (gEnableANGLEPerTestCaptureLabel)
750
{
751
swapBuffers();
752
}
753
}
754
755
void ANGLETestBase::ANGLETestTearDown()
756
{
757
mTearDownCalled = true;
758
gPlatformContext.currentTest = nullptr;
759
760
if (IsWindows())
761
{
762
const testing::TestInfo *info = testing::UnitTest::GetInstance()->current_test_info();
763
WriteDebugMessage("Exiting %s.%s\n", info->test_case_name(), info->name());
764
}
765
766
if (mCurrentParams->noFixture || !mFixture->osWindow->valid())
767
{
768
mRenderDoc.endFrame();
769
return;
770
}
771
772
swapBuffers();
773
mFixture->osWindow->messageLoop();
774
775
mRenderDoc.endFrame();
776
777
if (mFixture->eglWindow)
778
{
779
checkD3D11SDKLayersMessages();
780
}
781
782
if (mFixture->reuseCounter++ >= kWindowReuseLimit || mForceNewDisplay)
783
{
784
if (!mForceNewDisplay)
785
{
786
printf("Recreating test window because of reuse limit of %d\n", kWindowReuseLimit);
787
}
788
789
mFixture->reuseCounter = 0;
790
getGLWindow()->destroyGL();
791
}
792
else
793
{
794
mFixture->eglWindow->destroyContext();
795
mFixture->eglWindow->destroySurface();
796
}
797
798
// Check for quit message
799
Event myEvent;
800
while (mFixture->osWindow->popEvent(&myEvent))
801
{
802
if (myEvent.Type == Event::EVENT_CLOSED)
803
{
804
exit(0);
805
}
806
}
807
}
808
809
void ANGLETestBase::ReleaseFixtures()
810
{
811
for (auto it = gFixtures.begin(); it != gFixtures.end(); it++)
812
{
813
if (it->second.eglWindow)
814
{
815
it->second.eglWindow->destroyGL();
816
}
817
}
818
}
819
820
void ANGLETestBase::swapBuffers()
821
{
822
if (getGLWindow()->isGLInitialized())
823
{
824
getGLWindow()->swap();
825
826
if (mFixture->eglWindow)
827
{
828
EXPECT_EGL_SUCCESS();
829
}
830
}
831
}
832
833
void ANGLETestBase::setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale)
834
{
835
if (mQuadVertexBuffer == 0)
836
{
837
glGenBuffers(1, &mQuadVertexBuffer);
838
}
839
840
auto quadVertices = GetQuadVertices();
841
for (Vector3 &vertex : quadVertices)
842
{
843
vertex.x() *= positionAttribXYScale;
844
vertex.y() *= positionAttribXYScale;
845
vertex.z() = positionAttribZ;
846
}
847
848
glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer);
849
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 6, quadVertices.data(), GL_STATIC_DRAW);
850
}
851
852
void ANGLETestBase::setupIndexedQuadVertexBuffer(GLfloat positionAttribZ,
853
GLfloat positionAttribXYScale)
854
{
855
if (mQuadVertexBuffer == 0)
856
{
857
glGenBuffers(1, &mQuadVertexBuffer);
858
}
859
860
auto quadVertices = kIndexedQuadVertices;
861
for (Vector3 &vertex : quadVertices)
862
{
863
vertex.x() *= positionAttribXYScale;
864
vertex.y() *= positionAttribXYScale;
865
vertex.z() = positionAttribZ;
866
}
867
868
glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer);
869
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 4, quadVertices.data(), GL_STATIC_DRAW);
870
}
871
872
void ANGLETestBase::setupIndexedQuadIndexBuffer()
873
{
874
if (mQuadIndexBuffer == 0)
875
{
876
glGenBuffers(1, &mQuadIndexBuffer);
877
}
878
879
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mQuadIndexBuffer);
880
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(kIndexedQuadIndices), kIndexedQuadIndices.data(),
881
GL_STATIC_DRAW);
882
}
883
884
// static
885
void ANGLETestBase::drawQuad(GLuint program,
886
const std::string &positionAttribName,
887
GLfloat positionAttribZ)
888
{
889
drawQuad(program, positionAttribName, positionAttribZ, 1.0f);
890
}
891
892
// static
893
void ANGLETestBase::drawQuad(GLuint program,
894
const std::string &positionAttribName,
895
GLfloat positionAttribZ,
896
GLfloat positionAttribXYScale)
897
{
898
drawQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale, false);
899
}
900
901
void ANGLETestBase::drawQuad(GLuint program,
902
const std::string &positionAttribName,
903
GLfloat positionAttribZ,
904
GLfloat positionAttribXYScale,
905
bool useVertexBuffer)
906
{
907
drawQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale, useVertexBuffer,
908
false, false, 0u);
909
}
910
911
void ANGLETestBase::drawQuadInstanced(GLuint program,
912
const std::string &positionAttribName,
913
GLfloat positionAttribZ,
914
GLfloat positionAttribXYScale,
915
bool useVertexBuffer,
916
GLuint numInstances)
917
{
918
drawQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale, useVertexBuffer,
919
true, false, numInstances);
920
}
921
922
void ANGLETestBase::drawPatches(GLuint program,
923
const std::string &positionAttribName,
924
GLfloat positionAttribZ,
925
GLfloat positionAttribXYScale,
926
bool useVertexBuffer)
927
{
928
drawQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale, useVertexBuffer,
929
false, true, 0u);
930
}
931
932
void ANGLETestBase::drawQuad(GLuint program,
933
const std::string &positionAttribName,
934
GLfloat positionAttribZ,
935
GLfloat positionAttribXYScale,
936
bool useVertexBuffer,
937
bool useInstancedDrawCalls,
938
bool useTessellationPatches,
939
GLuint numInstances)
940
{
941
GLint previousProgram = 0;
942
glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgram);
943
if (previousProgram != static_cast<GLint>(program))
944
{
945
glUseProgram(program);
946
}
947
948
GLint previousBuffer = 0;
949
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &previousBuffer);
950
951
GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
952
953
std::array<Vector3, 6> quadVertices = GetQuadVertices();
954
955
if (useVertexBuffer)
956
{
957
setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
958
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
959
glBindBuffer(GL_ARRAY_BUFFER, previousBuffer);
960
}
961
else
962
{
963
for (Vector3 &vertex : quadVertices)
964
{
965
vertex.x() *= positionAttribXYScale;
966
vertex.y() *= positionAttribXYScale;
967
vertex.z() = positionAttribZ;
968
}
969
970
if (previousBuffer != 0)
971
{
972
glBindBuffer(GL_ARRAY_BUFFER, 0);
973
}
974
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, quadVertices.data());
975
if (previousBuffer != 0)
976
{
977
glBindBuffer(GL_ARRAY_BUFFER, previousBuffer);
978
}
979
}
980
glEnableVertexAttribArray(positionLocation);
981
GLenum drawMode = (useTessellationPatches) ? GL_PATCHES : GL_TRIANGLES;
982
983
if (useInstancedDrawCalls)
984
{
985
glDrawArraysInstanced(drawMode, 0, 6, numInstances);
986
}
987
else
988
{
989
glDrawArrays(drawMode, 0, 6);
990
}
991
992
glDisableVertexAttribArray(positionLocation);
993
glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
994
995
if (previousProgram != static_cast<GLint>(program))
996
{
997
glUseProgram(previousProgram);
998
}
999
}
1000
1001
void ANGLETestBase::drawQuadPPO(GLuint vertProgram,
1002
const std::string &positionAttribName,
1003
const GLfloat positionAttribZ,
1004
const GLfloat positionAttribXYScale)
1005
{
1006
GLint activeProgram = 0;
1007
glGetIntegerv(GL_CURRENT_PROGRAM, &activeProgram);
1008
if (activeProgram)
1009
{
1010
glUseProgram(0);
1011
}
1012
1013
std::array<Vector3, 6> quadVertices = GetQuadVertices();
1014
1015
for (Vector3 &vertex : quadVertices)
1016
{
1017
vertex.x() *= positionAttribXYScale;
1018
vertex.y() *= positionAttribXYScale;
1019
vertex.z() = positionAttribZ;
1020
}
1021
1022
GLint positionLocation = glGetAttribLocation(vertProgram, positionAttribName.c_str());
1023
1024
glBindBuffer(GL_ARRAY_BUFFER, 0);
1025
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, quadVertices.data());
1026
glEnableVertexAttribArray(positionLocation);
1027
1028
glDrawArrays(GL_TRIANGLES, 0, 6);
1029
1030
glDisableVertexAttribArray(positionLocation);
1031
glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
1032
1033
if (activeProgram)
1034
{
1035
glUseProgram(static_cast<GLuint>(activeProgram));
1036
}
1037
}
1038
1039
void ANGLETestBase::drawIndexedQuad(GLuint program,
1040
const std::string &positionAttribName,
1041
GLfloat positionAttribZ)
1042
{
1043
drawIndexedQuad(program, positionAttribName, positionAttribZ, 1.0f);
1044
}
1045
1046
void ANGLETestBase::drawIndexedQuad(GLuint program,
1047
const std::string &positionAttribName,
1048
GLfloat positionAttribZ,
1049
GLfloat positionAttribXYScale)
1050
{
1051
ASSERT(!mFixture->configParams.webGLCompatibility.valid() ||
1052
!mFixture->configParams.webGLCompatibility.value());
1053
drawIndexedQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale, false);
1054
}
1055
1056
void ANGLETestBase::drawIndexedQuad(GLuint program,
1057
const std::string &positionAttribName,
1058
GLfloat positionAttribZ,
1059
GLfloat positionAttribXYScale,
1060
bool useIndexBuffer)
1061
{
1062
drawIndexedQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale,
1063
useIndexBuffer, false);
1064
}
1065
1066
void ANGLETestBase::drawIndexedQuad(GLuint program,
1067
const std::string &positionAttribName,
1068
GLfloat positionAttribZ,
1069
GLfloat positionAttribXYScale,
1070
bool useIndexBuffer,
1071
bool restrictedRange)
1072
{
1073
GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
1074
1075
GLint activeProgram = 0;
1076
glGetIntegerv(GL_CURRENT_PROGRAM, &activeProgram);
1077
if (static_cast<GLuint>(activeProgram) != program)
1078
{
1079
glUseProgram(program);
1080
}
1081
1082
GLuint prevCoordBinding = 0;
1083
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, reinterpret_cast<GLint *>(&prevCoordBinding));
1084
1085
setupIndexedQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
1086
1087
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
1088
glEnableVertexAttribArray(positionLocation);
1089
glBindBuffer(GL_ARRAY_BUFFER, prevCoordBinding);
1090
1091
GLuint prevIndexBinding = 0;
1092
const GLvoid *indices;
1093
if (useIndexBuffer)
1094
{
1095
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING,
1096
reinterpret_cast<GLint *>(&prevIndexBinding));
1097
1098
setupIndexedQuadIndexBuffer();
1099
indices = 0;
1100
}
1101
else
1102
{
1103
indices = kIndexedQuadIndices.data();
1104
}
1105
1106
if (!restrictedRange)
1107
{
1108
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
1109
}
1110
else
1111
{
1112
glDrawRangeElements(GL_TRIANGLES, 0, 3, 6, GL_UNSIGNED_SHORT, indices);
1113
}
1114
1115
if (useIndexBuffer)
1116
{
1117
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, prevIndexBinding);
1118
}
1119
1120
glDisableVertexAttribArray(positionLocation);
1121
glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
1122
1123
if (static_cast<GLuint>(activeProgram) != program)
1124
{
1125
glUseProgram(static_cast<GLuint>(activeProgram));
1126
}
1127
}
1128
1129
GLuint ANGLETestBase::get2DTexturedQuadProgram()
1130
{
1131
if (m2DTexturedQuadProgram)
1132
{
1133
return m2DTexturedQuadProgram;
1134
}
1135
1136
constexpr char kVS[] =
1137
"attribute vec2 position;\n"
1138
"varying mediump vec2 texCoord;\n"
1139
"void main()\n"
1140
"{\n"
1141
" gl_Position = vec4(position, 0, 1);\n"
1142
" texCoord = position * 0.5 + vec2(0.5);\n"
1143
"}\n";
1144
1145
constexpr char kFS[] =
1146
"varying mediump vec2 texCoord;\n"
1147
"uniform sampler2D tex;\n"
1148
"void main()\n"
1149
"{\n"
1150
" gl_FragColor = texture2D(tex, texCoord);\n"
1151
"}\n";
1152
1153
m2DTexturedQuadProgram = CompileProgram(kVS, kFS);
1154
return m2DTexturedQuadProgram;
1155
}
1156
1157
GLuint ANGLETestBase::get3DTexturedQuadProgram()
1158
{
1159
if (m3DTexturedQuadProgram)
1160
{
1161
return m3DTexturedQuadProgram;
1162
}
1163
1164
constexpr char kVS[] = R"(#version 300 es
1165
in vec2 position;
1166
out vec2 texCoord;
1167
void main()
1168
{
1169
gl_Position = vec4(position, 0, 1);
1170
texCoord = position * 0.5 + vec2(0.5);
1171
})";
1172
1173
constexpr char kFS[] = R"(#version 300 es
1174
precision highp float;
1175
1176
in vec2 texCoord;
1177
out vec4 my_FragColor;
1178
1179
uniform highp sampler3D tex;
1180
uniform float u_layer;
1181
1182
void main()
1183
{
1184
my_FragColor = texture(tex, vec3(texCoord, u_layer));
1185
})";
1186
1187
m3DTexturedQuadProgram = CompileProgram(kVS, kFS);
1188
return m3DTexturedQuadProgram;
1189
}
1190
1191
void ANGLETestBase::draw2DTexturedQuad(GLfloat positionAttribZ,
1192
GLfloat positionAttribXYScale,
1193
bool useVertexBuffer)
1194
{
1195
ASSERT_NE(0u, get2DTexturedQuadProgram());
1196
drawQuad(get2DTexturedQuadProgram(), "position", positionAttribZ, positionAttribXYScale,
1197
useVertexBuffer);
1198
}
1199
1200
void ANGLETestBase::draw3DTexturedQuad(GLfloat positionAttribZ,
1201
GLfloat positionAttribXYScale,
1202
bool useVertexBuffer,
1203
float layer)
1204
{
1205
GLuint program = get3DTexturedQuadProgram();
1206
ASSERT_NE(0u, program);
1207
GLint activeProgram = 0;
1208
glGetIntegerv(GL_CURRENT_PROGRAM, &activeProgram);
1209
if (static_cast<GLuint>(activeProgram) != program)
1210
{
1211
glUseProgram(program);
1212
}
1213
glUniform1f(glGetUniformLocation(program, "u_layer"), layer);
1214
1215
drawQuad(program, "position", positionAttribZ, positionAttribXYScale, useVertexBuffer);
1216
1217
if (static_cast<GLuint>(activeProgram) != program)
1218
{
1219
glUseProgram(static_cast<GLuint>(activeProgram));
1220
}
1221
}
1222
1223
bool ANGLETestBase::platformSupportsMultithreading() const
1224
{
1225
return (IsOpenGLES() && IsAndroid()) || IsVulkan();
1226
}
1227
1228
void ANGLETestBase::checkD3D11SDKLayersMessages()
1229
{
1230
#if defined(ANGLE_PLATFORM_WINDOWS)
1231
// On Windows D3D11, check ID3D11InfoQueue to see if any D3D11 SDK Layers messages
1232
// were outputted by the test. We enable the Debug layers in Release tests as well.
1233
if (mIgnoreD3D11SDKLayersWarnings ||
1234
mFixture->eglWindow->getPlatform().renderer != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE ||
1235
mFixture->eglWindow->getDisplay() == EGL_NO_DISPLAY)
1236
{
1237
return;
1238
}
1239
1240
const char *extensionString = static_cast<const char *>(
1241
eglQueryString(mFixture->eglWindow->getDisplay(), EGL_EXTENSIONS));
1242
if (!extensionString)
1243
{
1244
std::cout << "Error getting extension string from EGL Window." << std::endl;
1245
return;
1246
}
1247
1248
if (!strstr(extensionString, "EGL_EXT_device_query"))
1249
{
1250
return;
1251
}
1252
1253
EGLAttrib device = 0;
1254
EGLAttrib angleDevice = 0;
1255
1256
ASSERT_EGL_TRUE(
1257
eglQueryDisplayAttribEXT(mFixture->eglWindow->getDisplay(), EGL_DEVICE_EXT, &angleDevice));
1258
ASSERT_EGL_TRUE(eglQueryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(angleDevice),
1259
EGL_D3D11_DEVICE_ANGLE, &device));
1260
ID3D11Device *d3d11Device = reinterpret_cast<ID3D11Device *>(device);
1261
1262
ID3D11InfoQueue *infoQueue = nullptr;
1263
HRESULT hr =
1264
d3d11Device->QueryInterface(__uuidof(infoQueue), reinterpret_cast<void **>(&infoQueue));
1265
if (SUCCEEDED(hr))
1266
{
1267
UINT64 numStoredD3DDebugMessages =
1268
infoQueue->GetNumStoredMessagesAllowedByRetrievalFilter();
1269
1270
if (numStoredD3DDebugMessages > 0)
1271
{
1272
for (UINT64 i = 0; i < numStoredD3DDebugMessages; i++)
1273
{
1274
SIZE_T messageLength = 0;
1275
hr = infoQueue->GetMessage(i, nullptr, &messageLength);
1276
1277
if (SUCCEEDED(hr))
1278
{
1279
D3D11_MESSAGE *pMessage =
1280
reinterpret_cast<D3D11_MESSAGE *>(malloc(messageLength));
1281
infoQueue->GetMessage(i, pMessage, &messageLength);
1282
1283
std::cout << "Message " << i << ":"
1284
<< " " << pMessage->pDescription << "\n";
1285
free(pMessage);
1286
}
1287
}
1288
// Clear the queue, so that previous failures are not reported
1289
// for subsequent, otherwise passing, tests
1290
infoQueue->ClearStoredMessages();
1291
1292
FAIL() << numStoredD3DDebugMessages
1293
<< " D3D11 SDK Layers message(s) detected! Test Failed.\n";
1294
}
1295
}
1296
1297
SafeRelease(infoQueue);
1298
#endif // defined(ANGLE_PLATFORM_WINDOWS)
1299
}
1300
1301
void ANGLETestBase::setWindowWidth(int width)
1302
{
1303
mWidth = width;
1304
}
1305
1306
void ANGLETestBase::setWindowHeight(int height)
1307
{
1308
mHeight = height;
1309
}
1310
1311
GLWindowBase *ANGLETestBase::getGLWindow() const
1312
{
1313
// WGL tests are currently disabled.
1314
assert(!mFixture->wglWindow);
1315
return mFixture->eglWindow;
1316
}
1317
1318
void ANGLETestBase::setConfigRedBits(int bits)
1319
{
1320
mFixture->configParams.redBits = bits;
1321
}
1322
1323
void ANGLETestBase::setConfigGreenBits(int bits)
1324
{
1325
mFixture->configParams.greenBits = bits;
1326
}
1327
1328
void ANGLETestBase::setConfigBlueBits(int bits)
1329
{
1330
mFixture->configParams.blueBits = bits;
1331
}
1332
1333
void ANGLETestBase::setConfigAlphaBits(int bits)
1334
{
1335
mFixture->configParams.alphaBits = bits;
1336
}
1337
1338
void ANGLETestBase::setConfigDepthBits(int bits)
1339
{
1340
mFixture->configParams.depthBits = bits;
1341
}
1342
1343
void ANGLETestBase::setConfigStencilBits(int bits)
1344
{
1345
mFixture->configParams.stencilBits = bits;
1346
}
1347
1348
void ANGLETestBase::setConfigComponentType(EGLenum componentType)
1349
{
1350
mFixture->configParams.componentType = componentType;
1351
}
1352
1353
void ANGLETestBase::setMultisampleEnabled(bool enabled)
1354
{
1355
mFixture->configParams.multisample = enabled;
1356
}
1357
1358
void ANGLETestBase::setSamples(EGLint samples)
1359
{
1360
mFixture->configParams.samples = samples;
1361
}
1362
1363
void ANGLETestBase::setDebugEnabled(bool enabled)
1364
{
1365
mFixture->configParams.debug = enabled;
1366
}
1367
1368
void ANGLETestBase::setNoErrorEnabled(bool enabled)
1369
{
1370
mFixture->configParams.noError = enabled;
1371
}
1372
1373
void ANGLETestBase::setWebGLCompatibilityEnabled(bool webglCompatibility)
1374
{
1375
mFixture->configParams.webGLCompatibility = webglCompatibility;
1376
}
1377
1378
void ANGLETestBase::setExtensionsEnabled(bool extensionsEnabled)
1379
{
1380
mFixture->configParams.extensionsEnabled = extensionsEnabled;
1381
}
1382
1383
void ANGLETestBase::setRobustAccess(bool enabled)
1384
{
1385
mFixture->configParams.robustAccess = enabled;
1386
}
1387
1388
void ANGLETestBase::setBindGeneratesResource(bool bindGeneratesResource)
1389
{
1390
mFixture->configParams.bindGeneratesResource = bindGeneratesResource;
1391
}
1392
1393
void ANGLETestBase::setClientArraysEnabled(bool enabled)
1394
{
1395
mFixture->configParams.clientArraysEnabled = enabled;
1396
}
1397
1398
void ANGLETestBase::setRobustResourceInit(bool enabled)
1399
{
1400
mFixture->configParams.robustResourceInit = enabled;
1401
}
1402
1403
void ANGLETestBase::setContextProgramCacheEnabled(bool enabled)
1404
{
1405
mFixture->configParams.contextProgramCacheEnabled = enabled;
1406
}
1407
1408
void ANGLETestBase::setContextResetStrategy(EGLenum resetStrategy)
1409
{
1410
mFixture->configParams.resetStrategy = resetStrategy;
1411
}
1412
1413
void ANGLETestBase::forceNewDisplay()
1414
{
1415
mForceNewDisplay = true;
1416
}
1417
1418
void ANGLETestBase::setDeferContextInit(bool enabled)
1419
{
1420
mDeferContextInit = enabled;
1421
}
1422
1423
int ANGLETestBase::getClientMajorVersion() const
1424
{
1425
return getGLWindow()->getClientMajorVersion();
1426
}
1427
1428
int ANGLETestBase::getClientMinorVersion() const
1429
{
1430
return getGLWindow()->getClientMinorVersion();
1431
}
1432
1433
EGLWindow *ANGLETestBase::getEGLWindow() const
1434
{
1435
return mFixture->eglWindow;
1436
}
1437
1438
int ANGLETestBase::getWindowWidth() const
1439
{
1440
return mWidth;
1441
}
1442
1443
int ANGLETestBase::getWindowHeight() const
1444
{
1445
return mHeight;
1446
}
1447
1448
bool ANGLETestBase::isEmulatedPrerotation() const
1449
{
1450
return mCurrentParams->eglParameters.emulatedPrerotation != 0;
1451
}
1452
1453
void ANGLETestBase::setWindowVisible(OSWindow *osWindow, bool isVisible)
1454
{
1455
// SwiftShader windows are not required to be visible for test correctness,
1456
// moreover, making a SwiftShader window visible flaky hangs on Xvfb, so we keep them hidden.
1457
if (isSwiftshader())
1458
{
1459
return;
1460
}
1461
osWindow->setVisible(isVisible);
1462
}
1463
1464
ANGLETestBase::TestFixture::TestFixture() = default;
1465
ANGLETestBase::TestFixture::~TestFixture() = default;
1466
1467
EGLint ANGLETestBase::getPlatformRenderer() const
1468
{
1469
assert(mFixture->eglWindow);
1470
return mFixture->eglWindow->getPlatform().renderer;
1471
}
1472
1473
void ANGLETestBase::ignoreD3D11SDKLayersWarnings()
1474
{
1475
// Some tests may need to disable the D3D11 SDK Layers Warnings checks
1476
mIgnoreD3D11SDKLayersWarnings = true;
1477
}
1478
1479
void ANGLETestBase::treatPlatformWarningsAsErrors()
1480
{
1481
#if defined(ANGLE_PLATFORM_WINDOWS)
1482
// Only do warnings-as-errors on 8 and above. We may fall back to the old
1483
// compiler DLL on Windows 7.
1484
gPlatformContext.warningsAsErrors = IsWindows8OrGreater();
1485
#endif // defined(ANGLE_PLATFORM_WINDOWS)
1486
}
1487
1488
ANGLETestBase::ScopedIgnorePlatformMessages::ScopedIgnorePlatformMessages()
1489
{
1490
gPlatformContext.ignoreMessages = true;
1491
}
1492
1493
ANGLETestBase::ScopedIgnorePlatformMessages::~ScopedIgnorePlatformMessages()
1494
{
1495
gPlatformContext.ignoreMessages = false;
1496
}
1497
1498
OSWindow *ANGLETestBase::mOSWindowSingleton = nullptr;
1499
std::map<angle::PlatformParameters, ANGLETestBase::TestFixture> ANGLETestBase::gFixtures;
1500
Optional<EGLint> ANGLETestBase::mLastRendererType;
1501
Optional<angle::GLESDriverType> ANGLETestBase::mLastLoadedDriver;
1502
1503
std::unique_ptr<Library> ANGLETestEnvironment::gAngleEGLLibrary;
1504
std::unique_ptr<Library> ANGLETestEnvironment::gSystemEGLLibrary;
1505
std::unique_ptr<Library> ANGLETestEnvironment::gSystemWGLLibrary;
1506
1507
void ANGLETestEnvironment::SetUp() {}
1508
1509
void ANGLETestEnvironment::TearDown()
1510
{
1511
ANGLETestBase::ReleaseFixtures();
1512
}
1513
1514
// static
1515
Library *ANGLETestEnvironment::GetDriverLibrary(angle::GLESDriverType driver)
1516
{
1517
switch (driver)
1518
{
1519
case angle::GLESDriverType::AngleEGL:
1520
return GetAngleEGLLibrary();
1521
case angle::GLESDriverType::SystemEGL:
1522
return GetSystemEGLLibrary();
1523
case angle::GLESDriverType::SystemWGL:
1524
return GetSystemWGLLibrary();
1525
default:
1526
return nullptr;
1527
}
1528
}
1529
1530
// static
1531
Library *ANGLETestEnvironment::GetAngleEGLLibrary()
1532
{
1533
#if defined(ANGLE_USE_UTIL_LOADER)
1534
if (!gAngleEGLLibrary)
1535
{
1536
gAngleEGLLibrary.reset(OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME, SearchType::ModuleDir));
1537
}
1538
#endif // defined(ANGLE_USE_UTIL_LOADER)
1539
return gAngleEGLLibrary.get();
1540
}
1541
1542
// static
1543
Library *ANGLETestEnvironment::GetSystemEGLLibrary()
1544
{
1545
#if defined(ANGLE_USE_UTIL_LOADER)
1546
if (!gSystemEGLLibrary)
1547
{
1548
gSystemEGLLibrary.reset(OpenSharedLibraryWithExtension(
1549
GetNativeEGLLibraryNameWithExtension(), SearchType::SystemDir));
1550
}
1551
#endif // defined(ANGLE_USE_UTIL_LOADER)
1552
return gSystemEGLLibrary.get();
1553
}
1554
1555
// static
1556
Library *ANGLETestEnvironment::GetSystemWGLLibrary()
1557
{
1558
#if defined(ANGLE_USE_UTIL_LOADER) && defined(ANGLE_PLATFORM_WINDOWS)
1559
if (!gSystemWGLLibrary)
1560
{
1561
gSystemWGLLibrary.reset(OpenSharedLibrary("opengl32", SearchType::SystemDir));
1562
}
1563
#endif // defined(ANGLE_USE_UTIL_LOADER) && defined(ANGLE_PLATFORM_WINDOWS)
1564
return gSystemWGLLibrary.get();
1565
}
1566
1567
void ANGLEProcessTestArgs(int *argc, char *argv[])
1568
{
1569
testing::AddGlobalTestEnvironment(new ANGLETestEnvironment());
1570
1571
for (int argIndex = 1; argIndex < *argc; argIndex++)
1572
{
1573
if (strncmp(argv[argIndex], kUseConfig, strlen(kUseConfig)) == 0)
1574
{
1575
SetSelectedConfig(argv[argIndex] + strlen(kUseConfig));
1576
}
1577
else if (strncmp(argv[argIndex], kReuseDisplays, strlen(kReuseDisplays)) == 0)
1578
{
1579
gReuseDisplays = true;
1580
}
1581
else if (strncmp(argv[argIndex], kBatchId, strlen(kBatchId)) == 0)
1582
{
1583
// Enable display reuse when running under --bot-mode.
1584
gReuseDisplays = true;
1585
}
1586
else if (strncmp(argv[argIndex], kEnableANGLEPerTestCaptureLabel,
1587
strlen(kEnableANGLEPerTestCaptureLabel)) == 0)
1588
{
1589
gEnableANGLEPerTestCaptureLabel = true;
1590
}
1591
else if (strncmp(argv[argIndex], kDelayTestStart, strlen(kDelayTestStart)) == 0)
1592
{
1593
SetTestStartDelay(argv[argIndex] + strlen(kDelayTestStart));
1594
}
1595
else if (strncmp(argv[argIndex], kRenderDoc, strlen(kRenderDoc)) == 0)
1596
{
1597
gEnableRenderDocCapture = true;
1598
}
1599
}
1600
}
1601
1602