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
EGLMakeCurrentPerfTest()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 LoadProc getProc = reinterpret_cast<LoadProc>(mEGLLibrary->getSymbol("eglGetProcAddress"));
70
71 if (!getProc)
72 {
73 abortTest();
74 }
75 else
76 {
77 LoadUtilEGL(getProc);
78 // Test harness warmup calls glFinish so we need GLES too.
79 LoadUtilGLES(getProc);
80
81 if (!eglGetPlatformDisplayEXT)
82 {
83 abortTest();
84 }
85 else
86 {
87 mDisplay = eglGetPlatformDisplayEXT(
88 EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(mOSWindow->getNativeDisplay()),
89 &displayAttributes[0]);
90 }
91 }
92 }
93
SetUp()94 void EGLMakeCurrentPerfTest::SetUp()
95 {
96 ANGLEPerfTest::SetUp();
97
98 ASSERT_NE(EGL_NO_DISPLAY, mDisplay);
99 EGLint majorVersion, minorVersion;
100 ASSERT_TRUE(eglInitialize(mDisplay, &majorVersion, &minorVersion));
101
102 EGLint numConfigs;
103 EGLint configAttrs[] = {EGL_RED_SIZE,
104 8,
105 EGL_GREEN_SIZE,
106 8,
107 EGL_BLUE_SIZE,
108 8,
109 EGL_RENDERABLE_TYPE,
110 GetParam().majorVersion == 3 ? EGL_OPENGL_ES3_BIT : EGL_OPENGL_ES2_BIT,
111 EGL_SURFACE_TYPE,
112 EGL_WINDOW_BIT,
113 EGL_NONE};
114
115 ASSERT_TRUE(eglChooseConfig(mDisplay, configAttrs, &mConfig, 1, &numConfigs));
116
117 mContexts[0] = eglCreateContext(mDisplay, mConfig, EGL_NO_CONTEXT, nullptr);
118 ASSERT_NE(EGL_NO_CONTEXT, mContexts[0]);
119 mContexts[1] = eglCreateContext(mDisplay, mConfig, EGL_NO_CONTEXT, nullptr);
120 ASSERT_NE(EGL_NO_CONTEXT, mContexts[1]);
121
122 mSurface = eglCreateWindowSurface(mDisplay, mConfig, mOSWindow->getNativeWindow(), nullptr);
123 ASSERT_NE(EGL_NO_SURFACE, mSurface);
124 ASSERT_TRUE(eglMakeCurrent(mDisplay, mSurface, mSurface, mContexts[0]));
125 }
126
TearDown()127 void EGLMakeCurrentPerfTest::TearDown()
128 {
129 ANGLEPerfTest::TearDown();
130 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
131 eglDestroySurface(mDisplay, mSurface);
132 eglDestroyContext(mDisplay, mContexts[0]);
133 eglDestroyContext(mDisplay, mContexts[1]);
134 }
135
step()136 void EGLMakeCurrentPerfTest::step()
137 {
138 int mCurrContext = 0;
139 for (int x = 0; x < ITERATIONS; x++)
140 {
141 mCurrContext = (mCurrContext + 1) % mContexts.size();
142 eglMakeCurrent(mDisplay, mSurface, mSurface, mContexts[mCurrContext]);
143 }
144 }
145
TEST_P(EGLMakeCurrentPerfTest,Run)146 TEST_P(EGLMakeCurrentPerfTest, Run)
147 {
148 run();
149 }
150
151 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLMakeCurrentPerfTest);
152 // We want to run this test on GL(ES) and Vulkan everywhere except Android
153 #if !defined(ANGLE_PLATFORM_ANDROID)
154 ANGLE_INSTANTIATE_TEST(EGLMakeCurrentPerfTest,
155 angle::ES2_D3D11(),
156 angle::ES2_METAL(),
157 angle::ES2_OPENGL(),
158 angle::ES2_OPENGLES(),
159 angle::ES2_VULKAN());
160 #endif
161
162 } // namespace
163