Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/perf_tests/EGLMakeCurrentPerf.cpp
1693 views
1
//
2
// Copyright 2018 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
// EGLMakeCurrentPerfTest:
7
// Performance test for eglMakeCurrent.
8
//
9
10
#include "ANGLEPerfTest.h"
11
#include "common/platform.h"
12
#include "common/system_utils.h"
13
#include "platform/PlatformMethods.h"
14
#include "test_utils/angle_test_configs.h"
15
#include "test_utils/angle_test_instantiate.h"
16
17
#define ITERATIONS 20
18
19
using namespace testing;
20
21
namespace
22
{
23
class EGLMakeCurrentPerfTest : public ANGLEPerfTest,
24
public WithParamInterface<angle::PlatformParameters>
25
{
26
public:
27
EGLMakeCurrentPerfTest();
28
29
void step() override;
30
void SetUp() override;
31
void TearDown() override;
32
33
private:
34
OSWindow *mOSWindow;
35
EGLDisplay mDisplay;
36
EGLSurface mSurface;
37
EGLConfig mConfig;
38
std::array<EGLContext, 2> mContexts;
39
std::unique_ptr<angle::Library> mEGLLibrary;
40
};
41
42
EGLMakeCurrentPerfTest::EGLMakeCurrentPerfTest()
43
: ANGLEPerfTest("EGLMakeCurrent", "", "_run", ITERATIONS),
44
mOSWindow(nullptr),
45
mDisplay(EGL_NO_DISPLAY),
46
mSurface(EGL_NO_SURFACE),
47
mConfig(nullptr),
48
mContexts({})
49
{
50
auto platform = GetParam().eglParameters;
51
52
std::vector<EGLint> displayAttributes;
53
displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
54
displayAttributes.push_back(platform.renderer);
55
displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE);
56
displayAttributes.push_back(platform.majorVersion);
57
displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE);
58
displayAttributes.push_back(platform.minorVersion);
59
displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE);
60
displayAttributes.push_back(platform.deviceType);
61
displayAttributes.push_back(EGL_NONE);
62
63
mOSWindow = OSWindow::New();
64
mOSWindow->initialize("EGLMakeCurrent Test", 64, 64);
65
66
mEGLLibrary.reset(
67
angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME, angle::SearchType::ModuleDir));
68
69
angle::LoadProc getProc =
70
reinterpret_cast<angle::LoadProc>(mEGLLibrary->getSymbol("eglGetProcAddress"));
71
72
if (!getProc)
73
{
74
abortTest();
75
}
76
else
77
{
78
angle::LoadEGL(getProc);
79
80
if (!eglGetPlatformDisplayEXT)
81
{
82
abortTest();
83
}
84
else
85
{
86
mDisplay = eglGetPlatformDisplayEXT(
87
EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(mOSWindow->getNativeDisplay()),
88
&displayAttributes[0]);
89
}
90
}
91
}
92
93
void EGLMakeCurrentPerfTest::SetUp()
94
{
95
ASSERT_NE(EGL_NO_DISPLAY, mDisplay);
96
EGLint majorVersion, minorVersion;
97
ASSERT_TRUE(eglInitialize(mDisplay, &majorVersion, &minorVersion));
98
99
EGLint numConfigs;
100
EGLint configAttrs[] = {EGL_RED_SIZE,
101
8,
102
EGL_GREEN_SIZE,
103
8,
104
EGL_BLUE_SIZE,
105
8,
106
EGL_RENDERABLE_TYPE,
107
GetParam().majorVersion == 3 ? EGL_OPENGL_ES3_BIT : EGL_OPENGL_ES2_BIT,
108
EGL_SURFACE_TYPE,
109
EGL_WINDOW_BIT,
110
EGL_NONE};
111
112
ASSERT_TRUE(eglChooseConfig(mDisplay, configAttrs, &mConfig, 1, &numConfigs));
113
114
mContexts[0] = eglCreateContext(mDisplay, mConfig, EGL_NO_CONTEXT, nullptr);
115
ASSERT_NE(EGL_NO_CONTEXT, mContexts[0]);
116
mContexts[1] = eglCreateContext(mDisplay, mConfig, EGL_NO_CONTEXT, nullptr);
117
ASSERT_NE(EGL_NO_CONTEXT, mContexts[1]);
118
119
mSurface = eglCreateWindowSurface(mDisplay, mConfig, mOSWindow->getNativeWindow(), nullptr);
120
ASSERT_NE(EGL_NO_SURFACE, mSurface);
121
ASSERT_TRUE(eglMakeCurrent(mDisplay, mSurface, mSurface, mContexts[0]));
122
}
123
124
void EGLMakeCurrentPerfTest::TearDown()
125
{
126
ANGLEPerfTest::TearDown();
127
eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
128
eglDestroySurface(mDisplay, mSurface);
129
eglDestroyContext(mDisplay, mContexts[0]);
130
eglDestroyContext(mDisplay, mContexts[1]);
131
}
132
133
void EGLMakeCurrentPerfTest::step()
134
{
135
int mCurrContext = 0;
136
for (int x = 0; x < ITERATIONS; x++)
137
{
138
mCurrContext = (mCurrContext + 1) % mContexts.size();
139
eglMakeCurrent(mDisplay, mSurface, mSurface, mContexts[mCurrContext]);
140
}
141
}
142
143
TEST_P(EGLMakeCurrentPerfTest, Run)
144
{
145
run();
146
}
147
148
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLMakeCurrentPerfTest);
149
// We want to run this test on GL(ES) and Vulkan everywhere except Android
150
#if !defined(ANGLE_PLATFORM_ANDROID)
151
ANGLE_INSTANTIATE_TEST(EGLMakeCurrentPerfTest,
152
angle::ES2_D3D11(),
153
angle::ES2_METAL(),
154
angle::ES2_OPENGL(),
155
angle::ES2_OPENGLES(),
156
angle::ES2_VULKAN());
157
#endif
158
159
} // namespace
160
161