• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "gtest/gtest.h"
2 
3 #define GL_GLEXT_PROTOTYPES
4 
5 #include <EGL/egl.h>
6 #include <EGL/eglext.h>
7 
8 typedef EGLAPI EGLDisplay EGLAPIENTRY EGLGetDisplay(EGLNativeDisplayType display_id);
9 typedef EGLAPI EGLBoolean EGLAPIENTRY EGLInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor);
10 typedef EGLAPI EGLContext EGLAPIENTRY EGLGetCurrentContext(void);
11 typedef EGLAPI EGLSurface EGLAPIENTRY EGLGetCurrentSurface(EGLint readdraw);
12 
13 class EGLThreadTest : public testing::Test
14 {
15   public:
SetUp()16     virtual void SetUp() {}
TearDown()17     virtual void TearDown() {}
18 
19     EGLGetDisplay *mGetDisplay;
20     EGLInitialize *mInitialize;
21     EGLGetCurrentContext *mGetCurrentContext;
22     EGLGetCurrentSurface *mGetCurrentSurface;
23 
24     EGLDisplay mDisplay;
25 
26     HMODULE mEGL;
27     HMODULE mGLESv2;
28 
29     static DWORD WINAPI ThreadingTestEntryPoint(LPVOID thisPointer);
30 
31   private:
32     void ThreadingTest();
33 };
34 
ThreadingTestEntryPoint(LPVOID lpParameter)35 DWORD WINAPI EGLThreadTest::ThreadingTestEntryPoint(LPVOID lpParameter)
36 {
37     EGLThreadTest *test = (EGLThreadTest *)lpParameter;
38     test->ThreadingTest();
39     return 0;
40 }
41 
ThreadingTest()42 void EGLThreadTest::ThreadingTest()
43 {
44     mEGL = LoadLibrary(TEXT("libEGL.dll"));
45     mGLESv2 = LoadLibrary(TEXT("libGLESv2.dll"));
46 
47     EXPECT_TRUE(mEGL != NULL);
48     EXPECT_TRUE(mGLESv2 != NULL);
49 
50     mGetDisplay = (EGLGetDisplay *)GetProcAddress(mEGL, "eglGetDisplay");
51     mInitialize = (EGLInitialize *)GetProcAddress(mEGL, "eglInitialize");
52     mGetCurrentContext = (EGLGetCurrentContext *)GetProcAddress(mEGL, "eglGetCurrentContext");
53     mGetCurrentSurface = (EGLGetCurrentSurface *)GetProcAddress(mEGL, "eglGetCurrentSurface");
54 
55     EXPECT_TRUE(mGetDisplay != NULL);
56     EXPECT_TRUE(mInitialize != NULL);
57     EXPECT_TRUE(mGetCurrentContext != NULL);
58     EXPECT_TRUE(mGetCurrentSurface != NULL);
59 
60     mDisplay = mGetDisplay(EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE);
61 
62     EXPECT_TRUE(mDisplay!= EGL_NO_DISPLAY);
63 
64     mInitialize(mDisplay, NULL, NULL);
65     mGetCurrentContext();
66 }
67 
TEST_F(EGLThreadTest,thread_init_crash)68 TEST_F(EGLThreadTest, thread_init_crash)
69 {
70     DWORD threadId;
71     HANDLE threadHandle = CreateThread(NULL, 0, EGLThreadTest::ThreadingTestEntryPoint, this, 0, &threadId);
72     EXPECT_TRUE(threadHandle != NULL);
73 
74     // wait for signal from thread
75     DWORD waitResult = WaitForSingleObject(threadHandle, 1000);
76     EXPECT_EQ(waitResult, WAIT_OBJECT_0);
77 
78     // crash, because the TLS value is NULL on main thread
79     mGetCurrentSurface(EGL_DRAW);
80     mGetCurrentContext();
81 }