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