xref: /aosp_15_r20/external/angle/src/libGLESv2/egl_stubs.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2020 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker // egl_stubs.cpp: Stubs for EGL entry points.
7*8975f5c5SAndroid Build Coastguard Worker //
8*8975f5c5SAndroid Build Coastguard Worker 
9*8975f5c5SAndroid Build Coastguard Worker #include "libGLESv2/egl_stubs_autogen.h"
10*8975f5c5SAndroid Build Coastguard Worker 
11*8975f5c5SAndroid Build Coastguard Worker #include "common/angle_version_info.h"
12*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Context.h"
13*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Display.h"
14*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/EGLSync.h"
15*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Surface.h"
16*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Thread.h"
17*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/queryutils.h"
18*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/validationEGL.h"
19*8975f5c5SAndroid Build Coastguard Worker #include "libGLESv2/global_state.h"
20*8975f5c5SAndroid Build Coastguard Worker #include "libGLESv2/proc_table_egl.h"
21*8975f5c5SAndroid Build Coastguard Worker 
22*8975f5c5SAndroid Build Coastguard Worker namespace egl
23*8975f5c5SAndroid Build Coastguard Worker {
24*8975f5c5SAndroid Build Coastguard Worker namespace
25*8975f5c5SAndroid Build Coastguard Worker {
26*8975f5c5SAndroid Build Coastguard Worker 
CompareProc(const ProcEntry & a,const char * b)27*8975f5c5SAndroid Build Coastguard Worker bool CompareProc(const ProcEntry &a, const char *b)
28*8975f5c5SAndroid Build Coastguard Worker {
29*8975f5c5SAndroid Build Coastguard Worker     return strcmp(a.first, b) < 0;
30*8975f5c5SAndroid Build Coastguard Worker }
31*8975f5c5SAndroid Build Coastguard Worker 
ClipConfigs(const std::vector<const Config * > & filteredConfigs,EGLConfig * outputConfigs,EGLint configSize,EGLint * numConfigs)32*8975f5c5SAndroid Build Coastguard Worker void ClipConfigs(const std::vector<const Config *> &filteredConfigs,
33*8975f5c5SAndroid Build Coastguard Worker                  EGLConfig *outputConfigs,
34*8975f5c5SAndroid Build Coastguard Worker                  EGLint configSize,
35*8975f5c5SAndroid Build Coastguard Worker                  EGLint *numConfigs)
36*8975f5c5SAndroid Build Coastguard Worker {
37*8975f5c5SAndroid Build Coastguard Worker     EGLint resultSize = static_cast<EGLint>(filteredConfigs.size());
38*8975f5c5SAndroid Build Coastguard Worker     if (outputConfigs)
39*8975f5c5SAndroid Build Coastguard Worker     {
40*8975f5c5SAndroid Build Coastguard Worker         resultSize = std::max(std::min(resultSize, configSize), 0);
41*8975f5c5SAndroid Build Coastguard Worker         for (EGLint i = 0; i < resultSize; i++)
42*8975f5c5SAndroid Build Coastguard Worker         {
43*8975f5c5SAndroid Build Coastguard Worker             outputConfigs[i] = const_cast<Config *>(filteredConfigs[i]);
44*8975f5c5SAndroid Build Coastguard Worker         }
45*8975f5c5SAndroid Build Coastguard Worker     }
46*8975f5c5SAndroid Build Coastguard Worker     *numConfigs = resultSize;
47*8975f5c5SAndroid Build Coastguard Worker }
48*8975f5c5SAndroid Build Coastguard Worker }  // anonymous namespace
49*8975f5c5SAndroid Build Coastguard Worker 
BindAPI(Thread * thread,EGLenum api)50*8975f5c5SAndroid Build Coastguard Worker EGLBoolean BindAPI(Thread *thread, EGLenum api)
51*8975f5c5SAndroid Build Coastguard Worker {
52*8975f5c5SAndroid Build Coastguard Worker     thread->setAPI(api);
53*8975f5c5SAndroid Build Coastguard Worker 
54*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
55*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
56*8975f5c5SAndroid Build Coastguard Worker }
57*8975f5c5SAndroid Build Coastguard Worker 
BindTexImage(Thread * thread,Display * display,egl::SurfaceID surfaceID,EGLint buffer)58*8975f5c5SAndroid Build Coastguard Worker EGLBoolean BindTexImage(Thread *thread, Display *display, egl::SurfaceID surfaceID, EGLint buffer)
59*8975f5c5SAndroid Build Coastguard Worker {
60*8975f5c5SAndroid Build Coastguard Worker     Surface *eglSurface = display->getSurface(surfaceID);
61*8975f5c5SAndroid Build Coastguard Worker 
62*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglBindTexImage",
63*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
64*8975f5c5SAndroid Build Coastguard Worker 
65*8975f5c5SAndroid Build Coastguard Worker     gl::Context *context = thread->getContext();
66*8975f5c5SAndroid Build Coastguard Worker     if (context && !context->isContextLost())
67*8975f5c5SAndroid Build Coastguard Worker     {
68*8975f5c5SAndroid Build Coastguard Worker         gl::TextureType type =
69*8975f5c5SAndroid Build Coastguard Worker             egl_gl::EGLTextureTargetToTextureType(eglSurface->getTextureTarget());
70*8975f5c5SAndroid Build Coastguard Worker         gl::Texture *textureObject = context->getTextureByType(type);
71*8975f5c5SAndroid Build Coastguard Worker         ANGLE_EGL_TRY_RETURN(thread, eglSurface->bindTexImage(context, textureObject, buffer),
72*8975f5c5SAndroid Build Coastguard Worker                              "eglBindTexImage", GetSurfaceIfValid(display, surfaceID), EGL_FALSE);
73*8975f5c5SAndroid Build Coastguard Worker     }
74*8975f5c5SAndroid Build Coastguard Worker 
75*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
76*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
77*8975f5c5SAndroid Build Coastguard Worker }
78*8975f5c5SAndroid Build Coastguard Worker 
ChooseConfig(Thread * thread,Display * display,const AttributeMap & attribMap,EGLConfig * configs,EGLint config_size,EGLint * num_config)79*8975f5c5SAndroid Build Coastguard Worker EGLBoolean ChooseConfig(Thread *thread,
80*8975f5c5SAndroid Build Coastguard Worker                         Display *display,
81*8975f5c5SAndroid Build Coastguard Worker                         const AttributeMap &attribMap,
82*8975f5c5SAndroid Build Coastguard Worker                         EGLConfig *configs,
83*8975f5c5SAndroid Build Coastguard Worker                         EGLint config_size,
84*8975f5c5SAndroid Build Coastguard Worker                         EGLint *num_config)
85*8975f5c5SAndroid Build Coastguard Worker {
86*8975f5c5SAndroid Build Coastguard Worker     ClipConfigs(display->chooseConfig(attribMap), configs, config_size, num_config);
87*8975f5c5SAndroid Build Coastguard Worker 
88*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
89*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
90*8975f5c5SAndroid Build Coastguard Worker }
91*8975f5c5SAndroid Build Coastguard Worker 
ClientWaitSync(Thread * thread,Display * display,SyncID syncID,EGLint flags,EGLTime timeout)92*8975f5c5SAndroid Build Coastguard Worker EGLint ClientWaitSync(Thread *thread,
93*8975f5c5SAndroid Build Coastguard Worker                       Display *display,
94*8975f5c5SAndroid Build Coastguard Worker                       SyncID syncID,
95*8975f5c5SAndroid Build Coastguard Worker                       EGLint flags,
96*8975f5c5SAndroid Build Coastguard Worker                       EGLTime timeout)
97*8975f5c5SAndroid Build Coastguard Worker {
98*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglClientWaitSync",
99*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
100*8975f5c5SAndroid Build Coastguard Worker     gl::Context *currentContext = thread->getContext();
101*8975f5c5SAndroid Build Coastguard Worker     EGLint syncStatus           = EGL_FALSE;
102*8975f5c5SAndroid Build Coastguard Worker     Sync *syncObject            = display->getSync(syncID);
103*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(
104*8975f5c5SAndroid Build Coastguard Worker         thread, syncObject->clientWait(display, currentContext, flags, timeout, &syncStatus),
105*8975f5c5SAndroid Build Coastguard Worker         "eglClientWaitSync", GetSyncIfValid(display, syncID), EGL_FALSE);
106*8975f5c5SAndroid Build Coastguard Worker 
107*8975f5c5SAndroid Build Coastguard Worker     // When performing CPU wait through UnlockedTailCall we need to handle any error conditions
108*8975f5c5SAndroid Build Coastguard Worker     if (egl::Display::GetCurrentThreadUnlockedTailCall()->any())
109*8975f5c5SAndroid Build Coastguard Worker     {
110*8975f5c5SAndroid Build Coastguard Worker         auto handleErrorStatus = [thread, display, syncID](void *result) {
111*8975f5c5SAndroid Build Coastguard Worker             EGLint *eglResult = static_cast<EGLint *>(result);
112*8975f5c5SAndroid Build Coastguard Worker             ASSERT(eglResult);
113*8975f5c5SAndroid Build Coastguard Worker             if (*eglResult == EGL_FALSE)
114*8975f5c5SAndroid Build Coastguard Worker             {
115*8975f5c5SAndroid Build Coastguard Worker                 thread->setError(egl::Error(EGL_BAD_ALLOC), "eglClientWaitSync",
116*8975f5c5SAndroid Build Coastguard Worker                                  GetSyncIfValid(display, syncID));
117*8975f5c5SAndroid Build Coastguard Worker             }
118*8975f5c5SAndroid Build Coastguard Worker             else
119*8975f5c5SAndroid Build Coastguard Worker             {
120*8975f5c5SAndroid Build Coastguard Worker                 thread->setSuccess();
121*8975f5c5SAndroid Build Coastguard Worker             }
122*8975f5c5SAndroid Build Coastguard Worker         };
123*8975f5c5SAndroid Build Coastguard Worker         egl::Display::GetCurrentThreadUnlockedTailCall()->add(handleErrorStatus);
124*8975f5c5SAndroid Build Coastguard Worker     }
125*8975f5c5SAndroid Build Coastguard Worker     else
126*8975f5c5SAndroid Build Coastguard Worker     {
127*8975f5c5SAndroid Build Coastguard Worker         thread->setSuccess();
128*8975f5c5SAndroid Build Coastguard Worker     }
129*8975f5c5SAndroid Build Coastguard Worker     return syncStatus;
130*8975f5c5SAndroid Build Coastguard Worker }
131*8975f5c5SAndroid Build Coastguard Worker 
CopyBuffers(Thread * thread,Display * display,egl::SurfaceID surfaceID,EGLNativePixmapType target)132*8975f5c5SAndroid Build Coastguard Worker EGLBoolean CopyBuffers(Thread *thread,
133*8975f5c5SAndroid Build Coastguard Worker                        Display *display,
134*8975f5c5SAndroid Build Coastguard Worker                        egl::SurfaceID surfaceID,
135*8975f5c5SAndroid Build Coastguard Worker                        EGLNativePixmapType target)
136*8975f5c5SAndroid Build Coastguard Worker {
137*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglCopyBuffers",
138*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
139*8975f5c5SAndroid Build Coastguard Worker     UNIMPLEMENTED();  // FIXME
140*8975f5c5SAndroid Build Coastguard Worker 
141*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
142*8975f5c5SAndroid Build Coastguard Worker     return 0;
143*8975f5c5SAndroid Build Coastguard Worker }
144*8975f5c5SAndroid Build Coastguard Worker 
CreateContext(Thread * thread,Display * display,Config * configuration,gl::ContextID sharedContextID,const AttributeMap & attributes)145*8975f5c5SAndroid Build Coastguard Worker EGLContext CreateContext(Thread *thread,
146*8975f5c5SAndroid Build Coastguard Worker                          Display *display,
147*8975f5c5SAndroid Build Coastguard Worker                          Config *configuration,
148*8975f5c5SAndroid Build Coastguard Worker                          gl::ContextID sharedContextID,
149*8975f5c5SAndroid Build Coastguard Worker                          const AttributeMap &attributes)
150*8975f5c5SAndroid Build Coastguard Worker {
151*8975f5c5SAndroid Build Coastguard Worker     gl::Context *sharedGLContext = display->getContext(sharedContextID);
152*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglCreateContext",
153*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_NO_CONTEXT);
154*8975f5c5SAndroid Build Coastguard Worker     gl::Context *context = nullptr;
155*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(
156*8975f5c5SAndroid Build Coastguard Worker         thread, display->createContext(configuration, sharedGLContext, attributes, &context),
157*8975f5c5SAndroid Build Coastguard Worker         "eglCreateContext", GetDisplayIfValid(display), EGL_NO_CONTEXT);
158*8975f5c5SAndroid Build Coastguard Worker 
159*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
160*8975f5c5SAndroid Build Coastguard Worker     return reinterpret_cast<EGLContext>(static_cast<uintptr_t>(context->id().value));
161*8975f5c5SAndroid Build Coastguard Worker }
162*8975f5c5SAndroid Build Coastguard Worker 
CreateImage(Thread * thread,Display * display,gl::ContextID contextID,EGLenum target,EGLClientBuffer buffer,const AttributeMap & attributes)163*8975f5c5SAndroid Build Coastguard Worker EGLImage CreateImage(Thread *thread,
164*8975f5c5SAndroid Build Coastguard Worker                      Display *display,
165*8975f5c5SAndroid Build Coastguard Worker                      gl::ContextID contextID,
166*8975f5c5SAndroid Build Coastguard Worker                      EGLenum target,
167*8975f5c5SAndroid Build Coastguard Worker                      EGLClientBuffer buffer,
168*8975f5c5SAndroid Build Coastguard Worker                      const AttributeMap &attributes)
169*8975f5c5SAndroid Build Coastguard Worker {
170*8975f5c5SAndroid Build Coastguard Worker     gl::Context *context = display->getContext(contextID);
171*8975f5c5SAndroid Build Coastguard Worker 
172*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglCreateImage",
173*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
174*8975f5c5SAndroid Build Coastguard Worker 
175*8975f5c5SAndroid Build Coastguard Worker     Image *image = nullptr;
176*8975f5c5SAndroid Build Coastguard Worker     Error error  = display->createImage(context, target, buffer, attributes, &image);
177*8975f5c5SAndroid Build Coastguard Worker     if (error.isError())
178*8975f5c5SAndroid Build Coastguard Worker     {
179*8975f5c5SAndroid Build Coastguard Worker         thread->setError(error, "eglCreateImage", GetDisplayIfValid(display));
180*8975f5c5SAndroid Build Coastguard Worker         return EGL_NO_IMAGE;
181*8975f5c5SAndroid Build Coastguard Worker     }
182*8975f5c5SAndroid Build Coastguard Worker 
183*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
184*8975f5c5SAndroid Build Coastguard Worker     return reinterpret_cast<EGLImage>(static_cast<uintptr_t>(image->id().value));
185*8975f5c5SAndroid Build Coastguard Worker }
186*8975f5c5SAndroid Build Coastguard Worker 
CreatePbufferFromClientBuffer(Thread * thread,Display * display,EGLenum buftype,EGLClientBuffer buffer,Config * configuration,const AttributeMap & attributes)187*8975f5c5SAndroid Build Coastguard Worker EGLSurface CreatePbufferFromClientBuffer(Thread *thread,
188*8975f5c5SAndroid Build Coastguard Worker                                          Display *display,
189*8975f5c5SAndroid Build Coastguard Worker                                          EGLenum buftype,
190*8975f5c5SAndroid Build Coastguard Worker                                          EGLClientBuffer buffer,
191*8975f5c5SAndroid Build Coastguard Worker                                          Config *configuration,
192*8975f5c5SAndroid Build Coastguard Worker                                          const AttributeMap &attributes)
193*8975f5c5SAndroid Build Coastguard Worker {
194*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(),
195*8975f5c5SAndroid Build Coastguard Worker                                           "eglCreatePbufferFromClientBuffer",
196*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_NO_SURFACE);
197*8975f5c5SAndroid Build Coastguard Worker     Surface *surface = nullptr;
198*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread,
199*8975f5c5SAndroid Build Coastguard Worker                          display->createPbufferFromClientBuffer(configuration, buftype, buffer,
200*8975f5c5SAndroid Build Coastguard Worker                                                                 attributes, &surface),
201*8975f5c5SAndroid Build Coastguard Worker                          "eglCreatePbufferFromClientBuffer", GetDisplayIfValid(display),
202*8975f5c5SAndroid Build Coastguard Worker                          EGL_NO_SURFACE);
203*8975f5c5SAndroid Build Coastguard Worker 
204*8975f5c5SAndroid Build Coastguard Worker     return reinterpret_cast<EGLSurface>(static_cast<uintptr_t>(surface->id().value));
205*8975f5c5SAndroid Build Coastguard Worker }
206*8975f5c5SAndroid Build Coastguard Worker 
CreatePbufferSurface(Thread * thread,Display * display,Config * configuration,const AttributeMap & attributes)207*8975f5c5SAndroid Build Coastguard Worker EGLSurface CreatePbufferSurface(Thread *thread,
208*8975f5c5SAndroid Build Coastguard Worker                                 Display *display,
209*8975f5c5SAndroid Build Coastguard Worker                                 Config *configuration,
210*8975f5c5SAndroid Build Coastguard Worker                                 const AttributeMap &attributes)
211*8975f5c5SAndroid Build Coastguard Worker {
212*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(),
213*8975f5c5SAndroid Build Coastguard Worker                                           "eglCreatePbufferSurface", GetDisplayIfValid(display),
214*8975f5c5SAndroid Build Coastguard Worker                                           EGL_NO_SURFACE);
215*8975f5c5SAndroid Build Coastguard Worker     Surface *surface = nullptr;
216*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, display->createPbufferSurface(configuration, attributes, &surface),
217*8975f5c5SAndroid Build Coastguard Worker                          "eglCreatePbufferSurface", GetDisplayIfValid(display), EGL_NO_SURFACE);
218*8975f5c5SAndroid Build Coastguard Worker 
219*8975f5c5SAndroid Build Coastguard Worker     return reinterpret_cast<EGLSurface>(static_cast<uintptr_t>(surface->id().value));
220*8975f5c5SAndroid Build Coastguard Worker }
221*8975f5c5SAndroid Build Coastguard Worker 
CreatePixmapSurface(Thread * thread,Display * display,Config * configuration,EGLNativePixmapType pixmap,const AttributeMap & attributes)222*8975f5c5SAndroid Build Coastguard Worker EGLSurface CreatePixmapSurface(Thread *thread,
223*8975f5c5SAndroid Build Coastguard Worker                                Display *display,
224*8975f5c5SAndroid Build Coastguard Worker                                Config *configuration,
225*8975f5c5SAndroid Build Coastguard Worker                                EGLNativePixmapType pixmap,
226*8975f5c5SAndroid Build Coastguard Worker                                const AttributeMap &attributes)
227*8975f5c5SAndroid Build Coastguard Worker {
228*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(),
229*8975f5c5SAndroid Build Coastguard Worker                                           "eglCreatePixmapSurface", GetDisplayIfValid(display),
230*8975f5c5SAndroid Build Coastguard Worker                                           EGL_NO_SURFACE);
231*8975f5c5SAndroid Build Coastguard Worker     Surface *surface = nullptr;
232*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread,
233*8975f5c5SAndroid Build Coastguard Worker                          display->createPixmapSurface(configuration, pixmap, attributes, &surface),
234*8975f5c5SAndroid Build Coastguard Worker                          "eglCreatePixmapSurface", GetDisplayIfValid(display), EGL_NO_SURFACE);
235*8975f5c5SAndroid Build Coastguard Worker 
236*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
237*8975f5c5SAndroid Build Coastguard Worker     return reinterpret_cast<EGLSurface>(static_cast<uintptr_t>(surface->id().value));
238*8975f5c5SAndroid Build Coastguard Worker }
239*8975f5c5SAndroid Build Coastguard Worker 
CreatePlatformPixmapSurface(Thread * thread,Display * display,Config * configuration,void * pixmap,const AttributeMap & attributes)240*8975f5c5SAndroid Build Coastguard Worker EGLSurface CreatePlatformPixmapSurface(Thread *thread,
241*8975f5c5SAndroid Build Coastguard Worker                                        Display *display,
242*8975f5c5SAndroid Build Coastguard Worker                                        Config *configuration,
243*8975f5c5SAndroid Build Coastguard Worker                                        void *pixmap,
244*8975f5c5SAndroid Build Coastguard Worker                                        const AttributeMap &attributes)
245*8975f5c5SAndroid Build Coastguard Worker {
246*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(),
247*8975f5c5SAndroid Build Coastguard Worker                                           "eglCreatePlatformPixmapSurface",
248*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_NO_SURFACE);
249*8975f5c5SAndroid Build Coastguard Worker     Surface *surface                 = nullptr;
250*8975f5c5SAndroid Build Coastguard Worker     EGLNativePixmapType nativePixmap = reinterpret_cast<EGLNativePixmapType>(pixmap);
251*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(
252*8975f5c5SAndroid Build Coastguard Worker         thread, display->createPixmapSurface(configuration, nativePixmap, attributes, &surface),
253*8975f5c5SAndroid Build Coastguard Worker         "eglCreatePlatformPixmapSurface", GetDisplayIfValid(display), EGL_NO_SURFACE);
254*8975f5c5SAndroid Build Coastguard Worker 
255*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
256*8975f5c5SAndroid Build Coastguard Worker     return reinterpret_cast<EGLSurface>(static_cast<uintptr_t>(surface->id().value));
257*8975f5c5SAndroid Build Coastguard Worker }
258*8975f5c5SAndroid Build Coastguard Worker 
CreatePlatformWindowSurface(Thread * thread,Display * display,Config * configuration,void * win,const AttributeMap & attributes)259*8975f5c5SAndroid Build Coastguard Worker EGLSurface CreatePlatformWindowSurface(Thread *thread,
260*8975f5c5SAndroid Build Coastguard Worker                                        Display *display,
261*8975f5c5SAndroid Build Coastguard Worker                                        Config *configuration,
262*8975f5c5SAndroid Build Coastguard Worker                                        void *win,
263*8975f5c5SAndroid Build Coastguard Worker                                        const AttributeMap &attributes)
264*8975f5c5SAndroid Build Coastguard Worker {
265*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(),
266*8975f5c5SAndroid Build Coastguard Worker                                           "eglCreatePlatformWindowSurface",
267*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_NO_SURFACE);
268*8975f5c5SAndroid Build Coastguard Worker     Surface *surface                 = nullptr;
269*8975f5c5SAndroid Build Coastguard Worker     EGLNativeWindowType nativeWindow = reinterpret_cast<EGLNativeWindowType>(win);
270*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(
271*8975f5c5SAndroid Build Coastguard Worker         thread, display->createWindowSurface(configuration, nativeWindow, attributes, &surface),
272*8975f5c5SAndroid Build Coastguard Worker         "eglCreatePlatformWindowSurface", GetDisplayIfValid(display), EGL_NO_SURFACE);
273*8975f5c5SAndroid Build Coastguard Worker 
274*8975f5c5SAndroid Build Coastguard Worker     return reinterpret_cast<EGLSurface>(static_cast<uintptr_t>(surface->id().value));
275*8975f5c5SAndroid Build Coastguard Worker }
276*8975f5c5SAndroid Build Coastguard Worker 
CreateSync(Thread * thread,Display * display,EGLenum type,const AttributeMap & attributes)277*8975f5c5SAndroid Build Coastguard Worker EGLSync CreateSync(Thread *thread, Display *display, EGLenum type, const AttributeMap &attributes)
278*8975f5c5SAndroid Build Coastguard Worker {
279*8975f5c5SAndroid Build Coastguard Worker     gl::Context *currentContext = thread->getContext();
280*8975f5c5SAndroid Build Coastguard Worker 
281*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglCreateSync",
282*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
283*8975f5c5SAndroid Build Coastguard Worker     Sync *syncObject = nullptr;
284*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, display->createSync(currentContext, type, attributes, &syncObject),
285*8975f5c5SAndroid Build Coastguard Worker                          "eglCreateSync", GetDisplayIfValid(display), EGL_NO_SYNC);
286*8975f5c5SAndroid Build Coastguard Worker 
287*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
288*8975f5c5SAndroid Build Coastguard Worker     return reinterpret_cast<EGLSync>(static_cast<uintptr_t>(syncObject->id().value));
289*8975f5c5SAndroid Build Coastguard Worker }
290*8975f5c5SAndroid Build Coastguard Worker 
CreateWindowSurface(Thread * thread,Display * display,Config * configuration,EGLNativeWindowType win,const AttributeMap & attributes)291*8975f5c5SAndroid Build Coastguard Worker EGLSurface CreateWindowSurface(Thread *thread,
292*8975f5c5SAndroid Build Coastguard Worker                                Display *display,
293*8975f5c5SAndroid Build Coastguard Worker                                Config *configuration,
294*8975f5c5SAndroid Build Coastguard Worker                                EGLNativeWindowType win,
295*8975f5c5SAndroid Build Coastguard Worker                                const AttributeMap &attributes)
296*8975f5c5SAndroid Build Coastguard Worker {
297*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(),
298*8975f5c5SAndroid Build Coastguard Worker                                           "eglCreateWindowSurface", GetDisplayIfValid(display),
299*8975f5c5SAndroid Build Coastguard Worker                                           EGL_NO_SURFACE);
300*8975f5c5SAndroid Build Coastguard Worker 
301*8975f5c5SAndroid Build Coastguard Worker     Surface *surface = nullptr;
302*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread,
303*8975f5c5SAndroid Build Coastguard Worker                          display->createWindowSurface(configuration, win, attributes, &surface),
304*8975f5c5SAndroid Build Coastguard Worker                          "eglCreateWindowSurface", GetDisplayIfValid(display), EGL_NO_SURFACE);
305*8975f5c5SAndroid Build Coastguard Worker 
306*8975f5c5SAndroid Build Coastguard Worker     return reinterpret_cast<EGLSurface>(static_cast<uintptr_t>(surface->id().value));
307*8975f5c5SAndroid Build Coastguard Worker }
308*8975f5c5SAndroid Build Coastguard Worker 
DestroyContext(Thread * thread,Display * display,gl::ContextID contextID)309*8975f5c5SAndroid Build Coastguard Worker EGLBoolean DestroyContext(Thread *thread, Display *display, gl::ContextID contextID)
310*8975f5c5SAndroid Build Coastguard Worker {
311*8975f5c5SAndroid Build Coastguard Worker     gl::Context *context = display->getContext(contextID);
312*8975f5c5SAndroid Build Coastguard Worker 
313*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglDestroyContext",
314*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
315*8975f5c5SAndroid Build Coastguard Worker 
316*8975f5c5SAndroid Build Coastguard Worker     ScopedSyncCurrentContextFromThread scopedSyncCurrent(thread);
317*8975f5c5SAndroid Build Coastguard Worker 
318*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, display->destroyContext(thread, context), "eglDestroyContext",
319*8975f5c5SAndroid Build Coastguard Worker                          GetContextIfValid(display, contextID), EGL_FALSE);
320*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
321*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
322*8975f5c5SAndroid Build Coastguard Worker }
323*8975f5c5SAndroid Build Coastguard Worker 
DestroyImage(Thread * thread,Display * display,ImageID imageID)324*8975f5c5SAndroid Build Coastguard Worker EGLBoolean DestroyImage(Thread *thread, Display *display, ImageID imageID)
325*8975f5c5SAndroid Build Coastguard Worker {
326*8975f5c5SAndroid Build Coastguard Worker     Image *img = display->getImage(imageID);
327*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglDestroyImage",
328*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
329*8975f5c5SAndroid Build Coastguard Worker     display->destroyImage(img);
330*8975f5c5SAndroid Build Coastguard Worker 
331*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
332*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
333*8975f5c5SAndroid Build Coastguard Worker }
334*8975f5c5SAndroid Build Coastguard Worker 
DestroySurface(Thread * thread,Display * display,egl::SurfaceID surfaceID)335*8975f5c5SAndroid Build Coastguard Worker EGLBoolean DestroySurface(Thread *thread, Display *display, egl::SurfaceID surfaceID)
336*8975f5c5SAndroid Build Coastguard Worker {
337*8975f5c5SAndroid Build Coastguard Worker     Surface *eglSurface = display->getSurface(surfaceID);
338*8975f5c5SAndroid Build Coastguard Worker 
339*8975f5c5SAndroid Build Coastguard Worker     // Workaround https://issuetracker.google.com/292285899
340*8975f5c5SAndroid Build Coastguard Worker     // When destroying surface, if the surface
341*8975f5c5SAndroid Build Coastguard Worker     // is still bound by the context of the current rendering
342*8975f5c5SAndroid Build Coastguard Worker     // thread, release the surface by passing EGL_NO_SURFACE to eglMakeCurrent().
343*8975f5c5SAndroid Build Coastguard Worker     if (display->getFrontendFeatures().uncurrentEglSurfaceUponSurfaceDestroy.enabled &&
344*8975f5c5SAndroid Build Coastguard Worker         eglSurface->isCurrentOnAnyContext() &&
345*8975f5c5SAndroid Build Coastguard Worker         (thread->getCurrentDrawSurface() == eglSurface ||
346*8975f5c5SAndroid Build Coastguard Worker          thread->getCurrentReadSurface() == eglSurface))
347*8975f5c5SAndroid Build Coastguard Worker     {
348*8975f5c5SAndroid Build Coastguard Worker         SurfaceID drawSurface             = PackParam<SurfaceID>(EGL_NO_SURFACE);
349*8975f5c5SAndroid Build Coastguard Worker         SurfaceID readSurface             = PackParam<SurfaceID>(EGL_NO_SURFACE);
350*8975f5c5SAndroid Build Coastguard Worker         const gl::Context *currentContext = thread->getContext();
351*8975f5c5SAndroid Build Coastguard Worker         const gl::ContextID contextID     = currentContext == nullptr
352*8975f5c5SAndroid Build Coastguard Worker                                                 ? PackParam<gl::ContextID>(EGL_NO_CONTEXT)
353*8975f5c5SAndroid Build Coastguard Worker                                                 : currentContext->id();
354*8975f5c5SAndroid Build Coastguard Worker 
355*8975f5c5SAndroid Build Coastguard Worker         // if surfaceless context is supported, only release the surface.
356*8975f5c5SAndroid Build Coastguard Worker         if (display->getExtensions().surfacelessContext)
357*8975f5c5SAndroid Build Coastguard Worker         {
358*8975f5c5SAndroid Build Coastguard Worker             MakeCurrent(thread, display, drawSurface, readSurface, contextID);
359*8975f5c5SAndroid Build Coastguard Worker         }
360*8975f5c5SAndroid Build Coastguard Worker         else
361*8975f5c5SAndroid Build Coastguard Worker         {
362*8975f5c5SAndroid Build Coastguard Worker             // if surfaceless context is not supported, release the context, too.
363*8975f5c5SAndroid Build Coastguard Worker             MakeCurrent(thread, display, drawSurface, readSurface,
364*8975f5c5SAndroid Build Coastguard Worker                         PackParam<gl::ContextID>(EGL_NO_CONTEXT));
365*8975f5c5SAndroid Build Coastguard Worker         }
366*8975f5c5SAndroid Build Coastguard Worker     }
367*8975f5c5SAndroid Build Coastguard Worker 
368*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglDestroySurface",
369*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
370*8975f5c5SAndroid Build Coastguard Worker 
371*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, display->destroySurface(eglSurface), "eglDestroySurface",
372*8975f5c5SAndroid Build Coastguard Worker                          GetSurfaceIfValid(display, surfaceID), EGL_FALSE);
373*8975f5c5SAndroid Build Coastguard Worker 
374*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
375*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
376*8975f5c5SAndroid Build Coastguard Worker }
377*8975f5c5SAndroid Build Coastguard Worker 
DestroySync(Thread * thread,Display * display,SyncID syncID)378*8975f5c5SAndroid Build Coastguard Worker EGLBoolean DestroySync(Thread *thread, Display *display, SyncID syncID)
379*8975f5c5SAndroid Build Coastguard Worker {
380*8975f5c5SAndroid Build Coastguard Worker     Sync *sync = display->getSync(syncID);
381*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglDestroySync",
382*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
383*8975f5c5SAndroid Build Coastguard Worker     display->destroySync(sync);
384*8975f5c5SAndroid Build Coastguard Worker 
385*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
386*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
387*8975f5c5SAndroid Build Coastguard Worker }
388*8975f5c5SAndroid Build Coastguard Worker 
GetConfigAttrib(Thread * thread,Display * display,Config * configuration,EGLint attribute,EGLint * value)389*8975f5c5SAndroid Build Coastguard Worker EGLBoolean GetConfigAttrib(Thread *thread,
390*8975f5c5SAndroid Build Coastguard Worker                            Display *display,
391*8975f5c5SAndroid Build Coastguard Worker                            Config *configuration,
392*8975f5c5SAndroid Build Coastguard Worker                            EGLint attribute,
393*8975f5c5SAndroid Build Coastguard Worker                            EGLint *value)
394*8975f5c5SAndroid Build Coastguard Worker {
395*8975f5c5SAndroid Build Coastguard Worker     QueryConfigAttrib(configuration, attribute, value);
396*8975f5c5SAndroid Build Coastguard Worker 
397*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
398*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
399*8975f5c5SAndroid Build Coastguard Worker }
400*8975f5c5SAndroid Build Coastguard Worker 
GetConfigs(Thread * thread,Display * display,EGLConfig * configs,EGLint config_size,EGLint * num_config)401*8975f5c5SAndroid Build Coastguard Worker EGLBoolean GetConfigs(Thread *thread,
402*8975f5c5SAndroid Build Coastguard Worker                       Display *display,
403*8975f5c5SAndroid Build Coastguard Worker                       EGLConfig *configs,
404*8975f5c5SAndroid Build Coastguard Worker                       EGLint config_size,
405*8975f5c5SAndroid Build Coastguard Worker                       EGLint *num_config)
406*8975f5c5SAndroid Build Coastguard Worker {
407*8975f5c5SAndroid Build Coastguard Worker     ClipConfigs(display->getConfigs(AttributeMap()), configs, config_size, num_config);
408*8975f5c5SAndroid Build Coastguard Worker 
409*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
410*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
411*8975f5c5SAndroid Build Coastguard Worker }
412*8975f5c5SAndroid Build Coastguard Worker 
GetCurrentContext(Thread * thread)413*8975f5c5SAndroid Build Coastguard Worker EGLContext GetCurrentContext(Thread *thread)
414*8975f5c5SAndroid Build Coastguard Worker {
415*8975f5c5SAndroid Build Coastguard Worker     gl::Context *context = thread->getContext();
416*8975f5c5SAndroid Build Coastguard Worker 
417*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
418*8975f5c5SAndroid Build Coastguard Worker     return reinterpret_cast<EGLContext>(context ? static_cast<uintptr_t>(context->id().value) : 0);
419*8975f5c5SAndroid Build Coastguard Worker }
420*8975f5c5SAndroid Build Coastguard Worker 
GetCurrentDisplay(Thread * thread)421*8975f5c5SAndroid Build Coastguard Worker EGLDisplay GetCurrentDisplay(Thread *thread)
422*8975f5c5SAndroid Build Coastguard Worker {
423*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
424*8975f5c5SAndroid Build Coastguard Worker     if (thread->getContext() != nullptr)
425*8975f5c5SAndroid Build Coastguard Worker     {
426*8975f5c5SAndroid Build Coastguard Worker         return thread->getContext()->getDisplay();
427*8975f5c5SAndroid Build Coastguard Worker     }
428*8975f5c5SAndroid Build Coastguard Worker     return EGL_NO_DISPLAY;
429*8975f5c5SAndroid Build Coastguard Worker }
430*8975f5c5SAndroid Build Coastguard Worker 
GetCurrentSurface(Thread * thread,EGLint readdraw)431*8975f5c5SAndroid Build Coastguard Worker EGLSurface GetCurrentSurface(Thread *thread, EGLint readdraw)
432*8975f5c5SAndroid Build Coastguard Worker {
433*8975f5c5SAndroid Build Coastguard Worker     Surface *surface =
434*8975f5c5SAndroid Build Coastguard Worker         (readdraw == EGL_READ) ? thread->getCurrentReadSurface() : thread->getCurrentDrawSurface();
435*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
436*8975f5c5SAndroid Build Coastguard Worker     if (surface)
437*8975f5c5SAndroid Build Coastguard Worker     {
438*8975f5c5SAndroid Build Coastguard Worker         return reinterpret_cast<EGLSurface>(static_cast<uintptr_t>(surface->id().value));
439*8975f5c5SAndroid Build Coastguard Worker     }
440*8975f5c5SAndroid Build Coastguard Worker     else
441*8975f5c5SAndroid Build Coastguard Worker     {
442*8975f5c5SAndroid Build Coastguard Worker         return EGL_NO_SURFACE;
443*8975f5c5SAndroid Build Coastguard Worker     }
444*8975f5c5SAndroid Build Coastguard Worker }
445*8975f5c5SAndroid Build Coastguard Worker 
GetDisplay(Thread * thread,EGLNativeDisplayType display_id)446*8975f5c5SAndroid Build Coastguard Worker EGLDisplay GetDisplay(Thread *thread, EGLNativeDisplayType display_id)
447*8975f5c5SAndroid Build Coastguard Worker {
448*8975f5c5SAndroid Build Coastguard Worker     return Display::GetDisplayFromNativeDisplay(EGL_PLATFORM_ANGLE_ANGLE, display_id,
449*8975f5c5SAndroid Build Coastguard Worker                                                 AttributeMap());
450*8975f5c5SAndroid Build Coastguard Worker }
451*8975f5c5SAndroid Build Coastguard Worker 
GetError(Thread * thread)452*8975f5c5SAndroid Build Coastguard Worker EGLint GetError(Thread *thread)
453*8975f5c5SAndroid Build Coastguard Worker {
454*8975f5c5SAndroid Build Coastguard Worker     EGLint error = thread->getError();
455*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
456*8975f5c5SAndroid Build Coastguard Worker     return error;
457*8975f5c5SAndroid Build Coastguard Worker }
458*8975f5c5SAndroid Build Coastguard Worker 
GetPlatformDisplay(Thread * thread,EGLenum platform,void * native_display,const AttributeMap & attribMap)459*8975f5c5SAndroid Build Coastguard Worker EGLDisplay GetPlatformDisplay(Thread *thread,
460*8975f5c5SAndroid Build Coastguard Worker                               EGLenum platform,
461*8975f5c5SAndroid Build Coastguard Worker                               void *native_display,
462*8975f5c5SAndroid Build Coastguard Worker                               const AttributeMap &attribMap)
463*8975f5c5SAndroid Build Coastguard Worker {
464*8975f5c5SAndroid Build Coastguard Worker     switch (platform)
465*8975f5c5SAndroid Build Coastguard Worker     {
466*8975f5c5SAndroid Build Coastguard Worker         case EGL_PLATFORM_ANGLE_ANGLE:
467*8975f5c5SAndroid Build Coastguard Worker         case EGL_PLATFORM_GBM_KHR:
468*8975f5c5SAndroid Build Coastguard Worker         case EGL_PLATFORM_WAYLAND_EXT:
469*8975f5c5SAndroid Build Coastguard Worker         case EGL_PLATFORM_SURFACELESS_MESA:
470*8975f5c5SAndroid Build Coastguard Worker         {
471*8975f5c5SAndroid Build Coastguard Worker             return Display::GetDisplayFromNativeDisplay(
472*8975f5c5SAndroid Build Coastguard Worker                 platform, gl::bitCast<EGLNativeDisplayType>(native_display), attribMap);
473*8975f5c5SAndroid Build Coastguard Worker         }
474*8975f5c5SAndroid Build Coastguard Worker         case EGL_PLATFORM_DEVICE_EXT:
475*8975f5c5SAndroid Build Coastguard Worker         {
476*8975f5c5SAndroid Build Coastguard Worker             Device *eglDevice = static_cast<Device *>(native_display);
477*8975f5c5SAndroid Build Coastguard Worker             return Display::GetDisplayFromDevice(eglDevice, attribMap);
478*8975f5c5SAndroid Build Coastguard Worker         }
479*8975f5c5SAndroid Build Coastguard Worker         default:
480*8975f5c5SAndroid Build Coastguard Worker         {
481*8975f5c5SAndroid Build Coastguard Worker             UNREACHABLE();
482*8975f5c5SAndroid Build Coastguard Worker             return EGL_NO_DISPLAY;
483*8975f5c5SAndroid Build Coastguard Worker         }
484*8975f5c5SAndroid Build Coastguard Worker     }
485*8975f5c5SAndroid Build Coastguard Worker }
486*8975f5c5SAndroid Build Coastguard Worker 
GetProcAddress(Thread * thread,const char * procname)487*8975f5c5SAndroid Build Coastguard Worker __eglMustCastToProperFunctionPointerType GetProcAddress(Thread *thread, const char *procname)
488*8975f5c5SAndroid Build Coastguard Worker {
489*8975f5c5SAndroid Build Coastguard Worker     const ProcEntry *entry =
490*8975f5c5SAndroid Build Coastguard Worker         std::lower_bound(&g_procTable[0], &g_procTable[g_numProcs], procname, CompareProc);
491*8975f5c5SAndroid Build Coastguard Worker 
492*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
493*8975f5c5SAndroid Build Coastguard Worker 
494*8975f5c5SAndroid Build Coastguard Worker     if (entry == &g_procTable[g_numProcs] || strcmp(entry->first, procname) != 0)
495*8975f5c5SAndroid Build Coastguard Worker     {
496*8975f5c5SAndroid Build Coastguard Worker         return nullptr;
497*8975f5c5SAndroid Build Coastguard Worker     }
498*8975f5c5SAndroid Build Coastguard Worker 
499*8975f5c5SAndroid Build Coastguard Worker     return entry->second;
500*8975f5c5SAndroid Build Coastguard Worker }
501*8975f5c5SAndroid Build Coastguard Worker 
GetSyncAttrib(Thread * thread,Display * display,SyncID syncID,EGLint attribute,EGLAttrib * value)502*8975f5c5SAndroid Build Coastguard Worker EGLBoolean GetSyncAttrib(Thread *thread,
503*8975f5c5SAndroid Build Coastguard Worker                          Display *display,
504*8975f5c5SAndroid Build Coastguard Worker                          SyncID syncID,
505*8975f5c5SAndroid Build Coastguard Worker                          EGLint attribute,
506*8975f5c5SAndroid Build Coastguard Worker                          EGLAttrib *value)
507*8975f5c5SAndroid Build Coastguard Worker {
508*8975f5c5SAndroid Build Coastguard Worker     EGLint valueExt;
509*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, GetSyncAttrib(display, syncID, attribute, &valueExt),
510*8975f5c5SAndroid Build Coastguard Worker                          "eglGetSyncAttrib", GetSyncIfValid(display, syncID), EGL_FALSE);
511*8975f5c5SAndroid Build Coastguard Worker     *value = valueExt;
512*8975f5c5SAndroid Build Coastguard Worker 
513*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
514*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
515*8975f5c5SAndroid Build Coastguard Worker }
516*8975f5c5SAndroid Build Coastguard Worker 
Initialize(Thread * thread,Display * display,EGLint * major,EGLint * minor)517*8975f5c5SAndroid Build Coastguard Worker EGLBoolean Initialize(Thread *thread, Display *display, EGLint *major, EGLint *minor)
518*8975f5c5SAndroid Build Coastguard Worker {
519*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, display->initialize(), "eglInitialize", GetDisplayIfValid(display),
520*8975f5c5SAndroid Build Coastguard Worker                          EGL_FALSE);
521*8975f5c5SAndroid Build Coastguard Worker 
522*8975f5c5SAndroid Build Coastguard Worker     if (major)
523*8975f5c5SAndroid Build Coastguard Worker     {
524*8975f5c5SAndroid Build Coastguard Worker         *major = kEglMajorVersion;
525*8975f5c5SAndroid Build Coastguard Worker     }
526*8975f5c5SAndroid Build Coastguard Worker     if (minor)
527*8975f5c5SAndroid Build Coastguard Worker     {
528*8975f5c5SAndroid Build Coastguard Worker         *minor = kEglMinorVersion;
529*8975f5c5SAndroid Build Coastguard Worker     }
530*8975f5c5SAndroid Build Coastguard Worker 
531*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
532*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
533*8975f5c5SAndroid Build Coastguard Worker }
534*8975f5c5SAndroid Build Coastguard Worker 
MakeCurrent(Thread * thread,Display * display,egl::SurfaceID drawSurfaceID,egl::SurfaceID readSurfaceID,gl::ContextID contextID)535*8975f5c5SAndroid Build Coastguard Worker EGLBoolean MakeCurrent(Thread *thread,
536*8975f5c5SAndroid Build Coastguard Worker                        Display *display,
537*8975f5c5SAndroid Build Coastguard Worker                        egl::SurfaceID drawSurfaceID,
538*8975f5c5SAndroid Build Coastguard Worker                        egl::SurfaceID readSurfaceID,
539*8975f5c5SAndroid Build Coastguard Worker                        gl::ContextID contextID)
540*8975f5c5SAndroid Build Coastguard Worker {
541*8975f5c5SAndroid Build Coastguard Worker     Surface *drawSurface = display->getSurface(drawSurfaceID);
542*8975f5c5SAndroid Build Coastguard Worker     Surface *readSurface = display->getSurface(readSurfaceID);
543*8975f5c5SAndroid Build Coastguard Worker     gl::Context *context = display->getContext(contextID);
544*8975f5c5SAndroid Build Coastguard Worker 
545*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglMakeCurrent",
546*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
547*8975f5c5SAndroid Build Coastguard Worker     ScopedSyncCurrentContextFromThread scopedSyncCurrent(thread);
548*8975f5c5SAndroid Build Coastguard Worker 
549*8975f5c5SAndroid Build Coastguard Worker     Surface *previousDraw        = thread->getCurrentDrawSurface();
550*8975f5c5SAndroid Build Coastguard Worker     Surface *previousRead        = thread->getCurrentReadSurface();
551*8975f5c5SAndroid Build Coastguard Worker     gl::Context *previousContext = thread->getContext();
552*8975f5c5SAndroid Build Coastguard Worker 
553*8975f5c5SAndroid Build Coastguard Worker     // Only call makeCurrent if the context or surfaces have changed.
554*8975f5c5SAndroid Build Coastguard Worker     if (previousDraw != drawSurface || previousRead != readSurface || previousContext != context)
555*8975f5c5SAndroid Build Coastguard Worker     {
556*8975f5c5SAndroid Build Coastguard Worker         ANGLE_EGL_TRY_RETURN(
557*8975f5c5SAndroid Build Coastguard Worker             thread,
558*8975f5c5SAndroid Build Coastguard Worker             display->makeCurrent(thread, previousContext, drawSurface, readSurface, context),
559*8975f5c5SAndroid Build Coastguard Worker             "eglMakeCurrent", GetContextIfValid(display, contextID), EGL_FALSE);
560*8975f5c5SAndroid Build Coastguard Worker     }
561*8975f5c5SAndroid Build Coastguard Worker 
562*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
563*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
564*8975f5c5SAndroid Build Coastguard Worker }
565*8975f5c5SAndroid Build Coastguard Worker 
QueryAPI(Thread * thread)566*8975f5c5SAndroid Build Coastguard Worker EGLenum QueryAPI(Thread *thread)
567*8975f5c5SAndroid Build Coastguard Worker {
568*8975f5c5SAndroid Build Coastguard Worker     EGLenum API = thread->getAPI();
569*8975f5c5SAndroid Build Coastguard Worker 
570*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
571*8975f5c5SAndroid Build Coastguard Worker     return API;
572*8975f5c5SAndroid Build Coastguard Worker }
573*8975f5c5SAndroid Build Coastguard Worker 
QueryContext(Thread * thread,Display * display,gl::ContextID contextID,EGLint attribute,EGLint * value)574*8975f5c5SAndroid Build Coastguard Worker EGLBoolean QueryContext(Thread *thread,
575*8975f5c5SAndroid Build Coastguard Worker                         Display *display,
576*8975f5c5SAndroid Build Coastguard Worker                         gl::ContextID contextID,
577*8975f5c5SAndroid Build Coastguard Worker                         EGLint attribute,
578*8975f5c5SAndroid Build Coastguard Worker                         EGLint *value)
579*8975f5c5SAndroid Build Coastguard Worker {
580*8975f5c5SAndroid Build Coastguard Worker     gl::Context *context = display->getContext(contextID);
581*8975f5c5SAndroid Build Coastguard Worker 
582*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglQueryContext",
583*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
584*8975f5c5SAndroid Build Coastguard Worker     QueryContextAttrib(context, attribute, value);
585*8975f5c5SAndroid Build Coastguard Worker 
586*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
587*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
588*8975f5c5SAndroid Build Coastguard Worker }
589*8975f5c5SAndroid Build Coastguard Worker 
QueryString(Thread * thread,Display * display,EGLint name)590*8975f5c5SAndroid Build Coastguard Worker const char *QueryString(Thread *thread, Display *display, EGLint name)
591*8975f5c5SAndroid Build Coastguard Worker {
592*8975f5c5SAndroid Build Coastguard Worker     if (display)
593*8975f5c5SAndroid Build Coastguard Worker     {
594*8975f5c5SAndroid Build Coastguard Worker         ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglQueryString",
595*8975f5c5SAndroid Build Coastguard Worker                                               GetDisplayIfValid(display), nullptr);
596*8975f5c5SAndroid Build Coastguard Worker     }
597*8975f5c5SAndroid Build Coastguard Worker 
598*8975f5c5SAndroid Build Coastguard Worker     const char *result = nullptr;
599*8975f5c5SAndroid Build Coastguard Worker     switch (name)
600*8975f5c5SAndroid Build Coastguard Worker     {
601*8975f5c5SAndroid Build Coastguard Worker         case EGL_CLIENT_APIS:
602*8975f5c5SAndroid Build Coastguard Worker             result = display->getClientAPIString().c_str();
603*8975f5c5SAndroid Build Coastguard Worker             break;
604*8975f5c5SAndroid Build Coastguard Worker         case EGL_EXTENSIONS:
605*8975f5c5SAndroid Build Coastguard Worker             if (display == EGL_NO_DISPLAY)
606*8975f5c5SAndroid Build Coastguard Worker             {
607*8975f5c5SAndroid Build Coastguard Worker                 result = Display::GetClientExtensionString().c_str();
608*8975f5c5SAndroid Build Coastguard Worker             }
609*8975f5c5SAndroid Build Coastguard Worker             else
610*8975f5c5SAndroid Build Coastguard Worker             {
611*8975f5c5SAndroid Build Coastguard Worker                 result = display->getExtensionString().c_str();
612*8975f5c5SAndroid Build Coastguard Worker             }
613*8975f5c5SAndroid Build Coastguard Worker             break;
614*8975f5c5SAndroid Build Coastguard Worker         case EGL_VENDOR:
615*8975f5c5SAndroid Build Coastguard Worker             result = display->getVendorString().c_str();
616*8975f5c5SAndroid Build Coastguard Worker             break;
617*8975f5c5SAndroid Build Coastguard Worker         case EGL_VERSION:
618*8975f5c5SAndroid Build Coastguard Worker         {
619*8975f5c5SAndroid Build Coastguard Worker             static const char *sVersionString =
620*8975f5c5SAndroid Build Coastguard Worker                 MakeStaticString(std::string("1.5 (ANGLE ") + angle::GetANGLEVersionString() + ")");
621*8975f5c5SAndroid Build Coastguard Worker             result = sVersionString;
622*8975f5c5SAndroid Build Coastguard Worker             break;
623*8975f5c5SAndroid Build Coastguard Worker         }
624*8975f5c5SAndroid Build Coastguard Worker         default:
625*8975f5c5SAndroid Build Coastguard Worker             UNREACHABLE();
626*8975f5c5SAndroid Build Coastguard Worker             break;
627*8975f5c5SAndroid Build Coastguard Worker     }
628*8975f5c5SAndroid Build Coastguard Worker 
629*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
630*8975f5c5SAndroid Build Coastguard Worker     return result;
631*8975f5c5SAndroid Build Coastguard Worker }
632*8975f5c5SAndroid Build Coastguard Worker 
QuerySurface(Thread * thread,Display * display,egl::SurfaceID surfaceID,EGLint attribute,EGLint * value)633*8975f5c5SAndroid Build Coastguard Worker EGLBoolean QuerySurface(Thread *thread,
634*8975f5c5SAndroid Build Coastguard Worker                         Display *display,
635*8975f5c5SAndroid Build Coastguard Worker                         egl::SurfaceID surfaceID,
636*8975f5c5SAndroid Build Coastguard Worker                         EGLint attribute,
637*8975f5c5SAndroid Build Coastguard Worker                         EGLint *value)
638*8975f5c5SAndroid Build Coastguard Worker {
639*8975f5c5SAndroid Build Coastguard Worker     Surface *eglSurface = display->getSurface(surfaceID);
640*8975f5c5SAndroid Build Coastguard Worker 
641*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglQuerySurface",
642*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
643*8975f5c5SAndroid Build Coastguard Worker 
644*8975f5c5SAndroid Build Coastguard Worker     // Update GetContextLock_QuerySurface() switch accordingly to take a ContextMutex lock for
645*8975f5c5SAndroid Build Coastguard Worker     // attributes that require current Context.
646*8975f5c5SAndroid Build Coastguard Worker     const gl::Context *context;
647*8975f5c5SAndroid Build Coastguard Worker     switch (attribute)
648*8975f5c5SAndroid Build Coastguard Worker     {
649*8975f5c5SAndroid Build Coastguard Worker         // EGL_BUFFER_AGE_EXT uses Context, so lock was taken in GetContextLock_QuerySurface().
650*8975f5c5SAndroid Build Coastguard Worker         case EGL_BUFFER_AGE_EXT:
651*8975f5c5SAndroid Build Coastguard Worker             context = thread->getContext();
652*8975f5c5SAndroid Build Coastguard Worker             break;
653*8975f5c5SAndroid Build Coastguard Worker         // Other attributes are not using Context, pass nullptr to be explicit about that.
654*8975f5c5SAndroid Build Coastguard Worker         default:
655*8975f5c5SAndroid Build Coastguard Worker             context = nullptr;
656*8975f5c5SAndroid Build Coastguard Worker             break;
657*8975f5c5SAndroid Build Coastguard Worker     }
658*8975f5c5SAndroid Build Coastguard Worker 
659*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, QuerySurfaceAttrib(display, context, eglSurface, attribute, value),
660*8975f5c5SAndroid Build Coastguard Worker                          "eglQuerySurface", GetSurfaceIfValid(display, surfaceID), EGL_FALSE);
661*8975f5c5SAndroid Build Coastguard Worker 
662*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
663*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
664*8975f5c5SAndroid Build Coastguard Worker }
665*8975f5c5SAndroid Build Coastguard Worker 
ReleaseTexImage(Thread * thread,Display * display,egl::SurfaceID surfaceID,EGLint buffer)666*8975f5c5SAndroid Build Coastguard Worker EGLBoolean ReleaseTexImage(Thread *thread,
667*8975f5c5SAndroid Build Coastguard Worker                            Display *display,
668*8975f5c5SAndroid Build Coastguard Worker                            egl::SurfaceID surfaceID,
669*8975f5c5SAndroid Build Coastguard Worker                            EGLint buffer)
670*8975f5c5SAndroid Build Coastguard Worker {
671*8975f5c5SAndroid Build Coastguard Worker     Surface *eglSurface = display->getSurface(surfaceID);
672*8975f5c5SAndroid Build Coastguard Worker 
673*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglReleaseTexImage",
674*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
675*8975f5c5SAndroid Build Coastguard Worker     gl::Context *context = thread->getContext();
676*8975f5c5SAndroid Build Coastguard Worker     if (context && !context->isContextLost())
677*8975f5c5SAndroid Build Coastguard Worker     {
678*8975f5c5SAndroid Build Coastguard Worker         gl::Texture *texture = eglSurface->getBoundTexture();
679*8975f5c5SAndroid Build Coastguard Worker 
680*8975f5c5SAndroid Build Coastguard Worker         if (texture)
681*8975f5c5SAndroid Build Coastguard Worker         {
682*8975f5c5SAndroid Build Coastguard Worker             ANGLE_EGL_TRY_RETURN(thread, eglSurface->releaseTexImage(thread->getContext(), buffer),
683*8975f5c5SAndroid Build Coastguard Worker                                  "eglReleaseTexImage", GetSurfaceIfValid(display, surfaceID),
684*8975f5c5SAndroid Build Coastguard Worker                                  EGL_FALSE);
685*8975f5c5SAndroid Build Coastguard Worker         }
686*8975f5c5SAndroid Build Coastguard Worker     }
687*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
688*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
689*8975f5c5SAndroid Build Coastguard Worker }
690*8975f5c5SAndroid Build Coastguard Worker 
ReleaseThread(Thread * thread)691*8975f5c5SAndroid Build Coastguard Worker EGLBoolean ReleaseThread(Thread *thread)
692*8975f5c5SAndroid Build Coastguard Worker {
693*8975f5c5SAndroid Build Coastguard Worker     ScopedSyncCurrentContextFromThread scopedSyncCurrent(thread);
694*8975f5c5SAndroid Build Coastguard Worker 
695*8975f5c5SAndroid Build Coastguard Worker     Surface *previousDraw        = thread->getCurrentDrawSurface();
696*8975f5c5SAndroid Build Coastguard Worker     Surface *previousRead        = thread->getCurrentReadSurface();
697*8975f5c5SAndroid Build Coastguard Worker     gl::Context *previousContext = thread->getContext();
698*8975f5c5SAndroid Build Coastguard Worker     Display *previousDisplay     = thread->getDisplay();
699*8975f5c5SAndroid Build Coastguard Worker 
700*8975f5c5SAndroid Build Coastguard Worker     if (previousDisplay != EGL_NO_DISPLAY)
701*8975f5c5SAndroid Build Coastguard Worker     {
702*8975f5c5SAndroid Build Coastguard Worker         ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, previousDisplay->prepareForCall(),
703*8975f5c5SAndroid Build Coastguard Worker                                               "eglReleaseThread",
704*8975f5c5SAndroid Build Coastguard Worker                                               GetDisplayIfValid(previousDisplay), EGL_FALSE);
705*8975f5c5SAndroid Build Coastguard Worker         // Only call makeCurrent if the context or surfaces have changed.
706*8975f5c5SAndroid Build Coastguard Worker         if (previousDraw != EGL_NO_SURFACE || previousRead != EGL_NO_SURFACE ||
707*8975f5c5SAndroid Build Coastguard Worker             previousContext != EGL_NO_CONTEXT)
708*8975f5c5SAndroid Build Coastguard Worker         {
709*8975f5c5SAndroid Build Coastguard Worker             ANGLE_EGL_TRY_RETURN(
710*8975f5c5SAndroid Build Coastguard Worker                 thread,
711*8975f5c5SAndroid Build Coastguard Worker                 previousDisplay->makeCurrent(thread, previousContext, nullptr, nullptr, nullptr),
712*8975f5c5SAndroid Build Coastguard Worker                 "eglReleaseThread", nullptr, EGL_FALSE);
713*8975f5c5SAndroid Build Coastguard Worker         }
714*8975f5c5SAndroid Build Coastguard Worker         ANGLE_EGL_TRY_RETURN(thread, previousDisplay->releaseThread(), "eglReleaseThread",
715*8975f5c5SAndroid Build Coastguard Worker                              GetDisplayIfValid(previousDisplay), EGL_FALSE);
716*8975f5c5SAndroid Build Coastguard Worker     }
717*8975f5c5SAndroid Build Coastguard Worker 
718*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
719*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
720*8975f5c5SAndroid Build Coastguard Worker }
721*8975f5c5SAndroid Build Coastguard Worker 
SurfaceAttrib(Thread * thread,Display * display,egl::SurfaceID surfaceID,EGLint attribute,EGLint value)722*8975f5c5SAndroid Build Coastguard Worker EGLBoolean SurfaceAttrib(Thread *thread,
723*8975f5c5SAndroid Build Coastguard Worker                          Display *display,
724*8975f5c5SAndroid Build Coastguard Worker                          egl::SurfaceID surfaceID,
725*8975f5c5SAndroid Build Coastguard Worker                          EGLint attribute,
726*8975f5c5SAndroid Build Coastguard Worker                          EGLint value)
727*8975f5c5SAndroid Build Coastguard Worker {
728*8975f5c5SAndroid Build Coastguard Worker     Surface *eglSurface = display->getSurface(surfaceID);
729*8975f5c5SAndroid Build Coastguard Worker 
730*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglSurfaceAttrib",
731*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
732*8975f5c5SAndroid Build Coastguard Worker 
733*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, SetSurfaceAttrib(eglSurface, attribute, value), "eglSurfaceAttrib",
734*8975f5c5SAndroid Build Coastguard Worker                          GetDisplayIfValid(display), EGL_FALSE);
735*8975f5c5SAndroid Build Coastguard Worker 
736*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
737*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
738*8975f5c5SAndroid Build Coastguard Worker }
739*8975f5c5SAndroid Build Coastguard Worker 
SwapBuffers(Thread * thread,Display * display,egl::SurfaceID surfaceID)740*8975f5c5SAndroid Build Coastguard Worker EGLBoolean SwapBuffers(Thread *thread, Display *display, egl::SurfaceID surfaceID)
741*8975f5c5SAndroid Build Coastguard Worker {
742*8975f5c5SAndroid Build Coastguard Worker     Surface *eglSurface = display->getSurface(surfaceID);
743*8975f5c5SAndroid Build Coastguard Worker 
744*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglSwapBuffers",
745*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
746*8975f5c5SAndroid Build Coastguard Worker 
747*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, eglSurface->swap(thread->getContext()), "eglSwapBuffers",
748*8975f5c5SAndroid Build Coastguard Worker                          GetSurfaceIfValid(display, surfaceID), EGL_FALSE);
749*8975f5c5SAndroid Build Coastguard Worker 
750*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
751*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
752*8975f5c5SAndroid Build Coastguard Worker }
753*8975f5c5SAndroid Build Coastguard Worker 
SwapInterval(Thread * thread,Display * display,EGLint interval)754*8975f5c5SAndroid Build Coastguard Worker EGLBoolean SwapInterval(Thread *thread, Display *display, EGLint interval)
755*8975f5c5SAndroid Build Coastguard Worker {
756*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglSwapInterval",
757*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
758*8975f5c5SAndroid Build Coastguard Worker 
759*8975f5c5SAndroid Build Coastguard Worker     Surface *drawSurface        = static_cast<Surface *>(thread->getCurrentDrawSurface());
760*8975f5c5SAndroid Build Coastguard Worker     const Config *surfaceConfig = drawSurface->getConfig();
761*8975f5c5SAndroid Build Coastguard Worker     EGLint clampedInterval      = std::min(std::max(interval, surfaceConfig->minSwapInterval),
762*8975f5c5SAndroid Build Coastguard Worker                                            surfaceConfig->maxSwapInterval);
763*8975f5c5SAndroid Build Coastguard Worker 
764*8975f5c5SAndroid Build Coastguard Worker     drawSurface->setSwapInterval(display, clampedInterval);
765*8975f5c5SAndroid Build Coastguard Worker 
766*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
767*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
768*8975f5c5SAndroid Build Coastguard Worker }
769*8975f5c5SAndroid Build Coastguard Worker 
Terminate(Thread * thread,Display * display)770*8975f5c5SAndroid Build Coastguard Worker EGLBoolean Terminate(Thread *thread, Display *display)
771*8975f5c5SAndroid Build Coastguard Worker {
772*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglTerminate",
773*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
774*8975f5c5SAndroid Build Coastguard Worker 
775*8975f5c5SAndroid Build Coastguard Worker     ScopedSyncCurrentContextFromThread scopedSyncCurrent(thread);
776*8975f5c5SAndroid Build Coastguard Worker 
777*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, display->terminate(thread, Display::TerminateReason::Api),
778*8975f5c5SAndroid Build Coastguard Worker                          "eglTerminate", GetDisplayIfValid(display), EGL_FALSE);
779*8975f5c5SAndroid Build Coastguard Worker 
780*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
781*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
782*8975f5c5SAndroid Build Coastguard Worker }
783*8975f5c5SAndroid Build Coastguard Worker 
WaitClient(Thread * thread)784*8975f5c5SAndroid Build Coastguard Worker EGLBoolean WaitClient(Thread *thread)
785*8975f5c5SAndroid Build Coastguard Worker {
786*8975f5c5SAndroid Build Coastguard Worker     Display *display = thread->getDisplay();
787*8975f5c5SAndroid Build Coastguard Worker     if (display == nullptr)
788*8975f5c5SAndroid Build Coastguard Worker     {
789*8975f5c5SAndroid Build Coastguard Worker         // EGL spec says this about eglWaitClient -
790*8975f5c5SAndroid Build Coastguard Worker         //    If there is no current context for the current rendering API,
791*8975f5c5SAndroid Build Coastguard Worker         //    the function has no effect but still returns EGL_TRUE.
792*8975f5c5SAndroid Build Coastguard Worker         return EGL_TRUE;
793*8975f5c5SAndroid Build Coastguard Worker     }
794*8975f5c5SAndroid Build Coastguard Worker 
795*8975f5c5SAndroid Build Coastguard Worker     gl::Context *context = thread->getContext();
796*8975f5c5SAndroid Build Coastguard Worker 
797*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglWaitClient",
798*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
799*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, display->waitClient(context), "eglWaitClient",
800*8975f5c5SAndroid Build Coastguard Worker                          GetContextIfValid(display, context->id()), EGL_FALSE);
801*8975f5c5SAndroid Build Coastguard Worker 
802*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
803*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
804*8975f5c5SAndroid Build Coastguard Worker }
805*8975f5c5SAndroid Build Coastguard Worker 
WaitGL(Thread * thread)806*8975f5c5SAndroid Build Coastguard Worker EGLBoolean WaitGL(Thread *thread)
807*8975f5c5SAndroid Build Coastguard Worker {
808*8975f5c5SAndroid Build Coastguard Worker     Display *display = thread->getDisplay();
809*8975f5c5SAndroid Build Coastguard Worker     if (display == nullptr)
810*8975f5c5SAndroid Build Coastguard Worker     {
811*8975f5c5SAndroid Build Coastguard Worker         // EGL spec says this about eglWaitGL -
812*8975f5c5SAndroid Build Coastguard Worker         //    eglWaitGL is ignored if there is no current EGL rendering context for OpenGL ES.
813*8975f5c5SAndroid Build Coastguard Worker         return EGL_TRUE;
814*8975f5c5SAndroid Build Coastguard Worker     }
815*8975f5c5SAndroid Build Coastguard Worker 
816*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglWaitGL",
817*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
818*8975f5c5SAndroid Build Coastguard Worker 
819*8975f5c5SAndroid Build Coastguard Worker     // eglWaitGL like calling eglWaitClient with the OpenGL ES API bound. Since we only implement
820*8975f5c5SAndroid Build Coastguard Worker     // OpenGL ES we can do the call directly.
821*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, display->waitClient(thread->getContext()), "eglWaitGL",
822*8975f5c5SAndroid Build Coastguard Worker                          GetDisplayIfValid(display), EGL_FALSE);
823*8975f5c5SAndroid Build Coastguard Worker 
824*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
825*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
826*8975f5c5SAndroid Build Coastguard Worker }
827*8975f5c5SAndroid Build Coastguard Worker 
WaitNative(Thread * thread,EGLint engine)828*8975f5c5SAndroid Build Coastguard Worker EGLBoolean WaitNative(Thread *thread, EGLint engine)
829*8975f5c5SAndroid Build Coastguard Worker {
830*8975f5c5SAndroid Build Coastguard Worker     Display *display = thread->getDisplay();
831*8975f5c5SAndroid Build Coastguard Worker     if (display == nullptr)
832*8975f5c5SAndroid Build Coastguard Worker     {
833*8975f5c5SAndroid Build Coastguard Worker         // EGL spec says this about eglWaitNative -
834*8975f5c5SAndroid Build Coastguard Worker         //    eglWaitNative is ignored if there is no current EGL rendering context.
835*8975f5c5SAndroid Build Coastguard Worker         return EGL_TRUE;
836*8975f5c5SAndroid Build Coastguard Worker     }
837*8975f5c5SAndroid Build Coastguard Worker 
838*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglWaitNative",
839*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
840*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, display->waitNative(thread->getContext(), engine), "eglWaitNative",
841*8975f5c5SAndroid Build Coastguard Worker                          GetThreadIfValid(thread), EGL_FALSE);
842*8975f5c5SAndroid Build Coastguard Worker 
843*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
844*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
845*8975f5c5SAndroid Build Coastguard Worker }
846*8975f5c5SAndroid Build Coastguard Worker 
WaitSync(Thread * thread,Display * display,SyncID syncID,EGLint flags)847*8975f5c5SAndroid Build Coastguard Worker EGLBoolean WaitSync(Thread *thread, Display *display, SyncID syncID, EGLint flags)
848*8975f5c5SAndroid Build Coastguard Worker {
849*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(thread, display->prepareForCall(), "eglWaitSync",
850*8975f5c5SAndroid Build Coastguard Worker                                           GetDisplayIfValid(display), EGL_FALSE);
851*8975f5c5SAndroid Build Coastguard Worker     gl::Context *currentContext = thread->getContext();
852*8975f5c5SAndroid Build Coastguard Worker     Sync *syncObject            = display->getSync(syncID);
853*8975f5c5SAndroid Build Coastguard Worker     ANGLE_EGL_TRY_RETURN(thread, syncObject->serverWait(display, currentContext, flags),
854*8975f5c5SAndroid Build Coastguard Worker                          "eglWaitSync", GetSyncIfValid(display, syncID), EGL_FALSE);
855*8975f5c5SAndroid Build Coastguard Worker 
856*8975f5c5SAndroid Build Coastguard Worker     thread->setSuccess();
857*8975f5c5SAndroid Build Coastguard Worker     return EGL_TRUE;
858*8975f5c5SAndroid Build Coastguard Worker }
859*8975f5c5SAndroid Build Coastguard Worker }  // namespace egl
860