• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2020 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 // egl_ext_stubs.cpp: Stubs for EXT extension entry points.
7 //
8 
9 #include "libGLESv2/egl_ext_stubs_autogen.h"
10 
11 #include "libANGLE/Device.h"
12 #include "libANGLE/Display.h"
13 #include "libANGLE/EGLSync.h"
14 #include "libANGLE/Surface.h"
15 #include "libANGLE/Thread.h"
16 #include "libANGLE/entry_points_utils.h"
17 #include "libANGLE/queryutils.h"
18 #include "libANGLE/renderer/DisplayImpl.h"
19 #include "libANGLE/validationEGL.h"
20 #include "libANGLE/validationEGL_autogen.h"
21 #include "libGLESv2/global_state.h"
22 
23 namespace egl
24 {
ClientWaitSyncKHR(Thread * thread,Display * display,SyncID syncID,EGLint flags,EGLTimeKHR timeout)25 EGLint ClientWaitSyncKHR(Thread *thread,
26                          Display *display,
27                          SyncID syncID,
28                          EGLint flags,
29                          EGLTimeKHR timeout)
30 {
31     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglClientWaitSync",
32                          GetDisplayIfValid(display), EGL_FALSE);
33     gl::Context *currentContext = thread->getContext();
34     EGLint syncStatus           = EGL_FALSE;
35     Sync *sync                  = display->getSync(syncID);
36     ANGLE_EGL_TRY_RETURN(thread,
37                          sync->clientWait(display, currentContext, flags, timeout, &syncStatus),
38                          "eglClientWaitSync", GetSyncIfValid(display, syncID), EGL_FALSE);
39 
40     thread->setSuccess();
41     return syncStatus;
42 }
43 
CreateImageKHR(Thread * thread,Display * display,gl::ContextID contextID,EGLenum target,EGLClientBuffer buffer,const AttributeMap & attributes)44 EGLImageKHR CreateImageKHR(Thread *thread,
45                            Display *display,
46                            gl::ContextID contextID,
47                            EGLenum target,
48                            EGLClientBuffer buffer,
49                            const AttributeMap &attributes)
50 {
51     gl::Context *context = display->getContext(contextID);
52 
53     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglCreateImageKHR",
54                          GetDisplayIfValid(display), EGL_NO_IMAGE);
55 
56     Image *image = nullptr;
57     ANGLE_EGL_TRY_RETURN(thread, display->createImage(context, target, buffer, attributes, &image),
58                          "", GetDisplayIfValid(display), EGL_NO_IMAGE);
59 
60     thread->setSuccess();
61     return reinterpret_cast<EGLImage>(static_cast<uintptr_t>(image->id().value));
62 }
63 
CreateNativeClientBufferANDROID(Thread * thread,const AttributeMap & attribMap)64 EGLClientBuffer CreateNativeClientBufferANDROID(Thread *thread, const AttributeMap &attribMap)
65 {
66     EGLClientBuffer eglClientBuffer = nullptr;
67     ANGLE_EGL_TRY_RETURN(thread,
68                          egl::Display::CreateNativeClientBuffer(attribMap, &eglClientBuffer),
69                          "eglCreateNativeClientBufferANDROID", nullptr, nullptr);
70 
71     thread->setSuccess();
72     return eglClientBuffer;
73 }
74 
CreatePlatformPixmapSurfaceEXT(Thread * thread,Display * display,Config * configPacked,void * native_pixmap,const AttributeMap & attributes)75 EGLSurface CreatePlatformPixmapSurfaceEXT(Thread *thread,
76                                           Display *display,
77                                           Config *configPacked,
78                                           void *native_pixmap,
79                                           const AttributeMap &attributes)
80 {
81     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglCreatePlatformPixmapSurfaceEXT",
82                          GetDisplayIfValid(display), EGL_NO_SURFACE);
83     thread->setError(EGL_BAD_DISPLAY, "eglCreatePlatformPixmapSurfaceEXT",
84                      GetDisplayIfValid(display), "CreatePlatformPixmapSurfaceEXT unimplemented.");
85     return EGL_NO_SURFACE;
86 }
87 
CreatePlatformWindowSurfaceEXT(Thread * thread,Display * display,Config * configPacked,void * native_window,const AttributeMap & attributes)88 EGLSurface CreatePlatformWindowSurfaceEXT(Thread *thread,
89                                           Display *display,
90                                           Config *configPacked,
91                                           void *native_window,
92                                           const AttributeMap &attributes)
93 {
94     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglCreatePlatformWindowSurfaceEXT",
95                          GetDisplayIfValid(display), EGL_NO_SURFACE);
96     Surface *surface = nullptr;
97 
98     // In X11, eglCreatePlatformWindowSurfaceEXT expects the native_window argument to be a pointer
99     // to a Window while the EGLNativeWindowType for X11 is its actual value.
100     // https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_platform_x11.txt
101     void *actualNativeWindow         = display->getImplementation()->isX11()
102                                            ? *reinterpret_cast<void **>(native_window)
103                                            : native_window;
104     EGLNativeWindowType nativeWindow = reinterpret_cast<EGLNativeWindowType>(actualNativeWindow);
105 
106     ANGLE_EGL_TRY_RETURN(
107         thread, display->createWindowSurface(configPacked, nativeWindow, attributes, &surface),
108         "eglCreatePlatformWindowSurfaceEXT", GetDisplayIfValid(display), EGL_NO_SURFACE);
109 
110     return reinterpret_cast<EGLSurface>(static_cast<uintptr_t>(surface->id().value));
111 }
112 
CreateStreamKHR(Thread * thread,Display * display,const AttributeMap & attributes)113 EGLStreamKHR CreateStreamKHR(Thread *thread, Display *display, const AttributeMap &attributes)
114 {
115     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglCreateStreamKHR",
116                          GetDisplayIfValid(display), EGL_NO_STREAM_KHR);
117     Stream *stream;
118     ANGLE_EGL_TRY_RETURN(thread, display->createStream(attributes, &stream), "eglCreateStreamKHR",
119                          GetDisplayIfValid(display), EGL_NO_STREAM_KHR);
120 
121     thread->setSuccess();
122     return static_cast<EGLStreamKHR>(stream);
123 }
124 
CreateSyncKHR(Thread * thread,Display * display,EGLenum type,const AttributeMap & attributes)125 EGLSyncKHR CreateSyncKHR(Thread *thread,
126                          Display *display,
127                          EGLenum type,
128                          const AttributeMap &attributes)
129 {
130     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglCreateSyncKHR",
131                          GetDisplayIfValid(display), EGL_NO_SYNC);
132     egl::Sync *syncObject = nullptr;
133     ANGLE_EGL_TRY_RETURN(thread,
134                          display->createSync(thread->getContext(), type, attributes, &syncObject),
135                          "eglCreateSyncKHR", GetDisplayIfValid(display), EGL_NO_SYNC);
136 
137     thread->setSuccess();
138     return reinterpret_cast<EGLSync>(static_cast<uintptr_t>(syncObject->id().value));
139 }
140 
DebugMessageControlKHR(Thread * thread,EGLDEBUGPROCKHR callback,const AttributeMap & attributes)141 EGLint DebugMessageControlKHR(Thread *thread,
142                               EGLDEBUGPROCKHR callback,
143                               const AttributeMap &attributes)
144 {
145     Debug *debug = GetDebug();
146     debug->setCallback(callback, attributes);
147 
148     thread->setSuccess();
149     return EGL_SUCCESS;
150 }
151 
DestroyImageKHR(Thread * thread,Display * display,egl::ImageID imageID)152 EGLBoolean DestroyImageKHR(Thread *thread, Display *display, egl::ImageID imageID)
153 {
154     Image *img = display->getImage(imageID);
155 
156     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglDestroyImageKHR",
157                          GetDisplayIfValid(display), EGL_FALSE);
158     display->destroyImage(img);
159 
160     thread->setSuccess();
161     return EGL_TRUE;
162 }
163 
DestroyStreamKHR(Thread * thread,Display * display,Stream * streamObject)164 EGLBoolean DestroyStreamKHR(Thread *thread, Display *display, Stream *streamObject)
165 {
166     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglDestroyStreamKHR",
167                          GetDisplayIfValid(display), EGL_FALSE);
168     display->destroyStream(streamObject);
169 
170     thread->setSuccess();
171     return EGL_TRUE;
172 }
173 
DestroySyncKHR(Thread * thread,Display * display,SyncID syncID)174 EGLBoolean DestroySyncKHR(Thread *thread, Display *display, SyncID syncID)
175 {
176     Sync *sync = display->getSync(syncID);
177     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglDestroySync",
178                          GetDisplayIfValid(display), EGL_FALSE);
179     display->destroySync(sync);
180 
181     thread->setSuccess();
182     return EGL_TRUE;
183 }
184 
DupNativeFenceFDANDROID(Thread * thread,Display * display,SyncID syncID)185 EGLint DupNativeFenceFDANDROID(Thread *thread, Display *display, SyncID syncID)
186 {
187     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglDupNativeFenceFDANDROID",
188                          GetDisplayIfValid(display), EGL_NO_NATIVE_FENCE_FD_ANDROID);
189     EGLint result    = EGL_NO_NATIVE_FENCE_FD_ANDROID;
190     Sync *syncObject = display->getSync(syncID);
191     ANGLE_EGL_TRY_RETURN(thread, syncObject->dupNativeFenceFD(display, &result),
192                          "eglDupNativeFenceFDANDROID", GetSyncIfValid(display, syncID),
193                          EGL_NO_NATIVE_FENCE_FD_ANDROID);
194 
195     thread->setSuccess();
196     return result;
197 }
198 
GetNativeClientBufferANDROID(Thread * thread,const struct AHardwareBuffer * buffer)199 EGLClientBuffer GetNativeClientBufferANDROID(Thread *thread, const struct AHardwareBuffer *buffer)
200 {
201     thread->setSuccess();
202     return egl::Display::GetNativeClientBuffer(buffer);
203 }
204 
GetPlatformDisplayEXT(Thread * thread,EGLenum platform,void * native_display,const AttributeMap & attribMap)205 EGLDisplay GetPlatformDisplayEXT(Thread *thread,
206                                  EGLenum platform,
207                                  void *native_display,
208                                  const AttributeMap &attribMap)
209 {
210     switch (platform)
211     {
212         case EGL_PLATFORM_ANGLE_ANGLE:
213         case EGL_PLATFORM_GBM_KHR:
214         case EGL_PLATFORM_WAYLAND_EXT:
215         {
216             return egl::Display::GetDisplayFromNativeDisplay(
217                 platform, gl::bitCast<EGLNativeDisplayType>(native_display), attribMap);
218         }
219         case EGL_PLATFORM_DEVICE_EXT:
220         {
221             Device *eglDevice = static_cast<Device *>(native_display);
222             return egl::Display::GetDisplayFromDevice(eglDevice, attribMap);
223         }
224         default:
225         {
226             UNREACHABLE();
227             return EGL_NO_DISPLAY;
228         }
229     }
230 }
231 
GetSyncAttribKHR(Thread * thread,Display * display,SyncID syncObject,EGLint attribute,EGLint * value)232 EGLBoolean GetSyncAttribKHR(Thread *thread,
233                             Display *display,
234                             SyncID syncObject,
235                             EGLint attribute,
236                             EGLint *value)
237 {
238     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglGetSyncAttrib",
239                          GetDisplayIfValid(display), EGL_FALSE);
240     ANGLE_EGL_TRY_RETURN(thread, GetSyncAttrib(display, syncObject, attribute, value),
241                          "eglGetSyncAttrib", GetSyncIfValid(display, syncObject), EGL_FALSE);
242 
243     thread->setSuccess();
244     return EGL_TRUE;
245 }
246 
LabelObjectKHR(Thread * thread,Display * display,ObjectType objectTypePacked,EGLObjectKHR object,EGLLabelKHR label)247 EGLint LabelObjectKHR(Thread *thread,
248                       Display *display,
249                       ObjectType objectTypePacked,
250                       EGLObjectKHR object,
251                       EGLLabelKHR label)
252 {
253     LabeledObject *labeledObject =
254         GetLabeledObjectIfValid(thread, display, objectTypePacked, object);
255     ASSERT(labeledObject != nullptr);
256     labeledObject->setLabel(label);
257 
258     thread->setSuccess();
259     return EGL_SUCCESS;
260 }
261 
PostSubBufferNV(Thread * thread,Display * display,SurfaceID surfaceID,EGLint x,EGLint y,EGLint width,EGLint height)262 EGLBoolean PostSubBufferNV(Thread *thread,
263                            Display *display,
264                            SurfaceID surfaceID,
265                            EGLint x,
266                            EGLint y,
267                            EGLint width,
268                            EGLint height)
269 {
270     Surface *eglSurface = display->getSurface(surfaceID);
271 
272     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglPostSubBufferNV",
273                          GetDisplayIfValid(display), EGL_FALSE);
274     Error error = eglSurface->postSubBuffer(thread->getContext(), x, y, width, height);
275     if (error.isError())
276     {
277         thread->setError(error, "eglPostSubBufferNV", GetSurfaceIfValid(display, surfaceID));
278         return EGL_FALSE;
279     }
280 
281     thread->setSuccess();
282     return EGL_TRUE;
283 }
284 
PresentationTimeANDROID(Thread * thread,Display * display,SurfaceID surfaceID,EGLnsecsANDROID time)285 EGLBoolean PresentationTimeANDROID(Thread *thread,
286                                    Display *display,
287                                    SurfaceID surfaceID,
288                                    EGLnsecsANDROID time)
289 {
290     Surface *eglSurface = display->getSurface(surfaceID);
291 
292     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglPresentationTimeANDROID",
293                          GetDisplayIfValid(display), EGL_FALSE);
294     ANGLE_EGL_TRY_RETURN(thread, eglSurface->setPresentationTime(time),
295                          "eglPresentationTimeANDROID", GetSurfaceIfValid(display, surfaceID),
296                          EGL_FALSE);
297 
298     return EGL_TRUE;
299 }
300 
GetCompositorTimingSupportedANDROID(Thread * thread,Display * display,SurfaceID surfaceID,CompositorTiming nameInternal)301 EGLBoolean GetCompositorTimingSupportedANDROID(Thread *thread,
302                                                Display *display,
303                                                SurfaceID surfaceID,
304                                                CompositorTiming nameInternal)
305 {
306     Surface *eglSurface = display->getSurface(surfaceID);
307 
308     thread->setSuccess();
309     return eglSurface->getSupportedCompositorTimings().test(nameInternal);
310 }
311 
GetCompositorTimingANDROID(Thread * thread,Display * display,SurfaceID surfaceID,EGLint numTimestamps,const EGLint * names,EGLnsecsANDROID * values)312 EGLBoolean GetCompositorTimingANDROID(Thread *thread,
313                                       Display *display,
314                                       SurfaceID surfaceID,
315                                       EGLint numTimestamps,
316                                       const EGLint *names,
317                                       EGLnsecsANDROID *values)
318 {
319     Surface *eglSurface = display->getSurface(surfaceID);
320 
321     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglGetCompositorTimingANDROIDD",
322                          GetDisplayIfValid(display), EGL_FALSE);
323     ANGLE_EGL_TRY_RETURN(thread, eglSurface->getCompositorTiming(numTimestamps, names, values),
324                          "eglGetCompositorTimingANDROIDD", GetSurfaceIfValid(display, surfaceID),
325                          EGL_FALSE);
326 
327     thread->setSuccess();
328     return EGL_TRUE;
329 }
330 
GetNextFrameIdANDROID(Thread * thread,Display * display,SurfaceID surfaceID,EGLuint64KHR * frameId)331 EGLBoolean GetNextFrameIdANDROID(Thread *thread,
332                                  Display *display,
333                                  SurfaceID surfaceID,
334                                  EGLuint64KHR *frameId)
335 {
336     Surface *eglSurface = display->getSurface(surfaceID);
337 
338     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglGetNextFrameIdANDROID",
339                          GetDisplayIfValid(display), EGL_FALSE);
340     ANGLE_EGL_TRY_RETURN(thread, eglSurface->getNextFrameId(frameId), "eglGetNextFrameIdANDROID",
341                          GetSurfaceIfValid(display, surfaceID), EGL_FALSE);
342 
343     thread->setSuccess();
344     return EGL_TRUE;
345 }
346 
GetFrameTimestampSupportedANDROID(Thread * thread,Display * display,SurfaceID surfaceID,Timestamp timestampInternal)347 EGLBoolean GetFrameTimestampSupportedANDROID(Thread *thread,
348                                              Display *display,
349                                              SurfaceID surfaceID,
350                                              Timestamp timestampInternal)
351 {
352     Surface *eglSurface = display->getSurface(surfaceID);
353 
354     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglQueryTimestampSupportedANDROID",
355                          GetDisplayIfValid(display), EGL_FALSE);
356     thread->setSuccess();
357     return eglSurface->getSupportedTimestamps().test(timestampInternal);
358 }
359 
GetFrameTimestampsANDROID(Thread * thread,Display * display,SurfaceID surfaceID,EGLuint64KHR frameId,EGLint numTimestamps,const EGLint * timestamps,EGLnsecsANDROID * values)360 EGLBoolean GetFrameTimestampsANDROID(Thread *thread,
361                                      Display *display,
362                                      SurfaceID surfaceID,
363                                      EGLuint64KHR frameId,
364                                      EGLint numTimestamps,
365                                      const EGLint *timestamps,
366                                      EGLnsecsANDROID *values)
367 {
368     Surface *eglSurface = display->getSurface(surfaceID);
369 
370     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglGetFrameTimestampsANDROID",
371                          GetDisplayIfValid(display), EGL_FALSE);
372     ANGLE_EGL_TRY_RETURN(
373         thread, eglSurface->getFrameTimestamps(frameId, numTimestamps, timestamps, values),
374         "eglGetFrameTimestampsANDROID", GetSurfaceIfValid(display, surfaceID), EGL_FALSE);
375 
376     thread->setSuccess();
377     return EGL_TRUE;
378 }
379 
QueryDebugKHR(Thread * thread,EGLint attribute,EGLAttrib * value)380 EGLBoolean QueryDebugKHR(Thread *thread, EGLint attribute, EGLAttrib *value)
381 {
382     Debug *debug = GetDebug();
383     switch (attribute)
384     {
385         case EGL_DEBUG_MSG_CRITICAL_KHR:
386         case EGL_DEBUG_MSG_ERROR_KHR:
387         case EGL_DEBUG_MSG_WARN_KHR:
388         case EGL_DEBUG_MSG_INFO_KHR:
389             *value = debug->isMessageTypeEnabled(FromEGLenum<MessageType>(attribute)) ? EGL_TRUE
390                                                                                       : EGL_FALSE;
391             break;
392         case EGL_DEBUG_CALLBACK_KHR:
393             *value = reinterpret_cast<EGLAttrib>(debug->getCallback());
394             break;
395 
396         default:
397             UNREACHABLE();
398     }
399 
400     thread->setSuccess();
401     return EGL_TRUE;
402 }
403 
QueryDeviceAttribEXT(Thread * thread,Device * dev,EGLint attribute,EGLAttrib * value)404 EGLBoolean QueryDeviceAttribEXT(Thread *thread, Device *dev, EGLint attribute, EGLAttrib *value)
405 {
406     ANGLE_EGL_TRY_RETURN(thread, dev->getAttribute(attribute, value), "eglQueryDeviceAttribEXT",
407                          GetDeviceIfValid(dev), EGL_FALSE);
408 
409     thread->setSuccess();
410     return EGL_TRUE;
411 }
412 
QueryDeviceStringEXT(Thread * thread,Device * dev,EGLint name)413 const char *QueryDeviceStringEXT(Thread *thread, Device *dev, EGLint name)
414 {
415     egl::Display *owningDisplay = dev->getOwningDisplay();
416     ANGLE_EGL_TRY_RETURN(thread, owningDisplay->prepareForCall(), "eglQueryDeviceStringEXT",
417                          GetDisplayIfValid(owningDisplay), EGL_FALSE);
418     const char *result;
419     switch (name)
420     {
421         case EGL_EXTENSIONS:
422             result = dev->getExtensionString().c_str();
423             break;
424         case EGL_DRM_DEVICE_FILE_EXT:
425         case EGL_DRM_RENDER_NODE_FILE_EXT:
426             result = dev->getDeviceString(name).c_str();
427             break;
428         default:
429             thread->setError(EglBadDevice(), "eglQueryDeviceStringEXT", GetDeviceIfValid(dev));
430             return nullptr;
431     }
432 
433     thread->setSuccess();
434     return result;
435 }
436 
QueryDisplayAttribEXT(Thread * thread,Display * display,EGLint attribute,EGLAttrib * value)437 EGLBoolean QueryDisplayAttribEXT(Thread *thread,
438                                  Display *display,
439                                  EGLint attribute,
440                                  EGLAttrib *value)
441 {
442     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglQueryDisplayAttribEXT",
443                          GetDisplayIfValid(display), EGL_FALSE);
444     *value = display->queryAttrib(attribute);
445     thread->setSuccess();
446     return EGL_TRUE;
447 }
448 
QueryStreamKHR(Thread * thread,Display * display,Stream * streamObject,EGLenum attribute,EGLint * value)449 EGLBoolean QueryStreamKHR(Thread *thread,
450                           Display *display,
451                           Stream *streamObject,
452                           EGLenum attribute,
453                           EGLint *value)
454 {
455     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglQueryStreamKHR",
456                          GetDisplayIfValid(display), EGL_FALSE);
457     switch (attribute)
458     {
459         case EGL_STREAM_STATE_KHR:
460             *value = streamObject->getState();
461             break;
462         case EGL_CONSUMER_LATENCY_USEC_KHR:
463             *value = streamObject->getConsumerLatency();
464             break;
465         case EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR:
466             *value = streamObject->getConsumerAcquireTimeout();
467             break;
468         default:
469             UNREACHABLE();
470     }
471 
472     thread->setSuccess();
473     return EGL_TRUE;
474 }
475 
QueryStreamu64KHR(Thread * thread,Display * display,Stream * streamObject,EGLenum attribute,EGLuint64KHR * value)476 EGLBoolean QueryStreamu64KHR(Thread *thread,
477                              Display *display,
478                              Stream *streamObject,
479                              EGLenum attribute,
480                              EGLuint64KHR *value)
481 {
482     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglQueryStreamu64KHR",
483                          GetDisplayIfValid(display), EGL_FALSE);
484     switch (attribute)
485     {
486         case EGL_PRODUCER_FRAME_KHR:
487             *value = streamObject->getProducerFrame();
488             break;
489         case EGL_CONSUMER_FRAME_KHR:
490             *value = streamObject->getConsumerFrame();
491             break;
492         default:
493             UNREACHABLE();
494     }
495 
496     thread->setSuccess();
497     return EGL_TRUE;
498 }
499 
QuerySurfacePointerANGLE(Thread * thread,Display * display,SurfaceID surfaceID,EGLint attribute,void ** value)500 EGLBoolean QuerySurfacePointerANGLE(Thread *thread,
501                                     Display *display,
502                                     SurfaceID surfaceID,
503                                     EGLint attribute,
504                                     void **value)
505 {
506     Surface *eglSurface = display->getSurface(surfaceID);
507 
508     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglQuerySurfacePointerANGLE",
509                          GetDisplayIfValid(display), EGL_FALSE);
510     Error error = eglSurface->querySurfacePointerANGLE(attribute, value);
511     if (error.isError())
512     {
513         thread->setError(error, "eglQuerySurfacePointerANGLE",
514                          GetSurfaceIfValid(display, surfaceID));
515         return EGL_FALSE;
516     }
517 
518     thread->setSuccess();
519     return EGL_TRUE;
520 }
521 
SetBlobCacheFuncsANDROID(Thread * thread,Display * display,EGLSetBlobFuncANDROID set,EGLGetBlobFuncANDROID get)522 void SetBlobCacheFuncsANDROID(Thread *thread,
523                               Display *display,
524                               EGLSetBlobFuncANDROID set,
525                               EGLGetBlobFuncANDROID get)
526 {
527     ANGLE_EGL_TRY(thread, display->prepareForCall(), "eglSetBlobCacheFuncsANDROID",
528                   GetDisplayIfValid(display));
529     thread->setSuccess();
530     display->setBlobCacheFuncs(set, get);
531 }
532 
SignalSyncKHR(Thread * thread,Display * display,SyncID syncID,EGLenum mode)533 EGLBoolean SignalSyncKHR(Thread *thread, Display *display, SyncID syncID, EGLenum mode)
534 {
535     gl::Context *currentContext = thread->getContext();
536     Sync *syncObject            = display->getSync(syncID);
537     ANGLE_EGL_TRY_RETURN(thread, syncObject->signal(display, currentContext, mode),
538                          "eglSignalSyncKHR", GetSyncIfValid(display, syncID), EGL_FALSE);
539 
540     thread->setSuccess();
541     return EGL_TRUE;
542 }
543 
StreamAttribKHR(Thread * thread,Display * display,Stream * streamObject,EGLenum attribute,EGLint value)544 EGLBoolean StreamAttribKHR(Thread *thread,
545                            Display *display,
546                            Stream *streamObject,
547                            EGLenum attribute,
548                            EGLint value)
549 {
550     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglStreamAttribKHR",
551                          GetDisplayIfValid(display), EGL_FALSE);
552     switch (attribute)
553     {
554         case EGL_CONSUMER_LATENCY_USEC_KHR:
555             streamObject->setConsumerLatency(value);
556             break;
557         case EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR:
558             streamObject->setConsumerAcquireTimeout(value);
559             break;
560         default:
561             UNREACHABLE();
562     }
563 
564     thread->setSuccess();
565     return EGL_TRUE;
566 }
567 
StreamConsumerAcquireKHR(Thread * thread,Display * display,Stream * streamObject)568 EGLBoolean StreamConsumerAcquireKHR(Thread *thread, Display *display, Stream *streamObject)
569 {
570     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglStreamConsumerAcquireKHR",
571                          GetDisplayIfValid(display), EGL_FALSE);
572     ANGLE_EGL_TRY_RETURN(thread, streamObject->consumerAcquire(thread->getContext()),
573                          "eglStreamConsumerAcquireKHR", GetStreamIfValid(display, streamObject),
574                          EGL_FALSE);
575     thread->setSuccess();
576     return EGL_TRUE;
577 }
578 
StreamConsumerGLTextureExternalKHR(Thread * thread,Display * display,Stream * streamObject)579 EGLBoolean StreamConsumerGLTextureExternalKHR(Thread *thread,
580                                               Display *display,
581                                               Stream *streamObject)
582 {
583     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglStreamConsumerGLTextureExternalKHR",
584                          GetDisplayIfValid(display), EGL_FALSE);
585     ANGLE_EGL_TRY_RETURN(
586         thread, streamObject->createConsumerGLTextureExternal(AttributeMap(), thread->getContext()),
587         "eglStreamConsumerGLTextureExternalKHR", GetStreamIfValid(display, streamObject),
588         EGL_FALSE);
589     thread->setSuccess();
590     return EGL_TRUE;
591 }
592 
StreamConsumerGLTextureExternalAttribsNV(Thread * thread,Display * display,Stream * streamObject,const AttributeMap & attributes)593 EGLBoolean StreamConsumerGLTextureExternalAttribsNV(Thread *thread,
594                                                     Display *display,
595                                                     Stream *streamObject,
596                                                     const AttributeMap &attributes)
597 {
598     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(),
599                          "eglStreamConsumerGLTextureExternalAttribsNV", GetDisplayIfValid(display),
600                          EGL_FALSE);
601 
602     gl::Context *context = gl::GetValidGlobalContext();
603     ANGLE_EGL_TRY_RETURN(thread, streamObject->createConsumerGLTextureExternal(attributes, context),
604                          "eglStreamConsumerGLTextureExternalAttribsNV",
605                          GetStreamIfValid(display, streamObject), EGL_FALSE);
606     thread->setSuccess();
607     return EGL_TRUE;
608 }
609 
StreamConsumerReleaseKHR(Thread * thread,Display * display,Stream * streamObject)610 EGLBoolean StreamConsumerReleaseKHR(Thread *thread, Display *display, Stream *streamObject)
611 {
612     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglStreamConsumerReleaseKHR",
613                          GetDisplayIfValid(display), EGL_FALSE);
614 
615     gl::Context *context = gl::GetValidGlobalContext();
616     ANGLE_EGL_TRY_RETURN(thread, streamObject->consumerRelease(context),
617                          "eglStreamConsumerReleaseKHR", GetStreamIfValid(display, streamObject),
618                          EGL_FALSE);
619     thread->setSuccess();
620     return EGL_TRUE;
621 }
622 
SwapBuffersWithDamageKHR(Thread * thread,Display * display,SurfaceID surfaceID,const EGLint * rects,EGLint n_rects)623 EGLBoolean SwapBuffersWithDamageKHR(Thread *thread,
624                                     Display *display,
625                                     SurfaceID surfaceID,
626                                     const EGLint *rects,
627                                     EGLint n_rects)
628 {
629     Surface *eglSurface = display->getSurface(surfaceID);
630 
631     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglSwapBuffersWithDamageKHR",
632                          GetDisplayIfValid(display), EGL_FALSE);
633     ANGLE_EGL_TRY_RETURN(thread, eglSurface->swapWithDamage(thread->getContext(), rects, n_rects),
634                          "eglSwapBuffersWithDamageKHR", GetSurfaceIfValid(display, surfaceID),
635                          EGL_FALSE);
636 
637     thread->setSuccess();
638     return EGL_TRUE;
639 }
640 
PrepareSwapBuffersANGLE(Thread * thread,Display * display,SurfaceID surfaceID)641 EGLBoolean PrepareSwapBuffersANGLE(Thread *thread, Display *display, SurfaceID surfaceID)
642 {
643     Surface *eglSurface = display->getSurface(surfaceID);
644 
645     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglPrepareSwapBuffersANGLE",
646                          GetDisplayIfValid(display), EGL_FALSE);
647     ANGLE_EGL_TRY_RETURN(thread, eglSurface->prepareSwap(thread->getContext()),
648                          "eglPrepareSwapBuffersANGLE", eglSurface, EGL_FALSE);
649 
650     thread->setSuccess();
651     return EGL_TRUE;
652 }
653 
WaitSyncKHR(Thread * thread,Display * display,SyncID syncID,EGLint flags)654 EGLint WaitSyncKHR(Thread *thread, Display *display, SyncID syncID, EGLint flags)
655 {
656     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglWaitSync",
657                          GetDisplayIfValid(display), EGL_FALSE);
658     gl::Context *currentContext = thread->getContext();
659     Sync *syncObject            = display->getSync(syncID);
660     ANGLE_EGL_TRY_RETURN(thread, syncObject->serverWait(display, currentContext, flags),
661                          "eglWaitSync", GetSyncIfValid(display, syncID), EGL_FALSE);
662 
663     thread->setSuccess();
664     return EGL_TRUE;
665 }
666 
CreateDeviceANGLE(Thread * thread,EGLint device_type,void * native_device,const EGLAttrib * attrib_list)667 EGLDeviceEXT CreateDeviceANGLE(Thread *thread,
668                                EGLint device_type,
669                                void *native_device,
670                                const EGLAttrib *attrib_list)
671 {
672     Device *device = nullptr;
673     ANGLE_EGL_TRY_RETURN(thread, Device::CreateDevice(device_type, native_device, &device),
674                          "eglCreateDeviceANGLE", GetThreadIfValid(thread), EGL_NO_DEVICE_EXT);
675 
676     thread->setSuccess();
677     return device;
678 }
679 
ReleaseDeviceANGLE(Thread * thread,Device * dev)680 EGLBoolean ReleaseDeviceANGLE(Thread *thread, Device *dev)
681 {
682     SafeDelete(dev);
683 
684     thread->setSuccess();
685     return EGL_TRUE;
686 }
687 
CreateStreamProducerD3DTextureANGLE(Thread * thread,Display * display,Stream * streamObject,const AttributeMap & attributes)688 EGLBoolean CreateStreamProducerD3DTextureANGLE(Thread *thread,
689                                                Display *display,
690                                                Stream *streamObject,
691                                                const AttributeMap &attributes)
692 {
693     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(),
694                          "eglCreateStreamProducerD3DTextureANGLE", GetDisplayIfValid(display),
695                          EGL_FALSE);
696     ANGLE_EGL_TRY_RETURN(thread, streamObject->createProducerD3D11Texture(attributes),
697                          "eglCreateStreamProducerD3DTextureANGLE",
698                          GetStreamIfValid(display, streamObject), EGL_FALSE);
699     thread->setSuccess();
700     return EGL_TRUE;
701 }
702 
StreamPostD3DTextureANGLE(Thread * thread,Display * display,Stream * streamObject,void * texture,const AttributeMap & attributes)703 EGLBoolean StreamPostD3DTextureANGLE(Thread *thread,
704                                      Display *display,
705                                      Stream *streamObject,
706                                      void *texture,
707                                      const AttributeMap &attributes)
708 {
709     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglStreamPostD3DTextureANGLE",
710                          GetDisplayIfValid(display), EGL_FALSE);
711     ANGLE_EGL_TRY_RETURN(thread, streamObject->postD3D11Texture(texture, attributes),
712                          "eglStreamPostD3DTextureANGLE", GetStreamIfValid(display, streamObject),
713                          EGL_FALSE);
714     thread->setSuccess();
715     return EGL_TRUE;
716 }
717 
GetMscRateANGLE(Thread * thread,Display * display,SurfaceID surfaceID,EGLint * numerator,EGLint * denominator)718 EGLBoolean GetMscRateANGLE(Thread *thread,
719                            Display *display,
720                            SurfaceID surfaceID,
721                            EGLint *numerator,
722                            EGLint *denominator)
723 {
724     Surface *eglSurface = display->getSurface(surfaceID);
725 
726     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglGetMscRateANGLE",
727                          GetDisplayIfValid(display), EGL_FALSE);
728     ANGLE_EGL_TRY_RETURN(thread, eglSurface->getMscRate(numerator, denominator),
729                          "eglGetMscRateANGLE", GetSurfaceIfValid(display, surfaceID), EGL_FALSE);
730 
731     thread->setSuccess();
732     return EGL_TRUE;
733 }
734 
GetSyncValuesCHROMIUM(Thread * thread,Display * display,SurfaceID surfaceID,EGLuint64KHR * ust,EGLuint64KHR * msc,EGLuint64KHR * sbc)735 EGLBoolean GetSyncValuesCHROMIUM(Thread *thread,
736                                  Display *display,
737                                  SurfaceID surfaceID,
738                                  EGLuint64KHR *ust,
739                                  EGLuint64KHR *msc,
740                                  EGLuint64KHR *sbc)
741 {
742     Surface *eglSurface = display->getSurface(surfaceID);
743 
744     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglGetSyncValuesCHROMIUM",
745                          GetDisplayIfValid(display), EGL_FALSE);
746     ANGLE_EGL_TRY_RETURN(thread, eglSurface->getSyncValues(ust, msc, sbc),
747                          "eglGetSyncValuesCHROMIUM", GetSurfaceIfValid(display, surfaceID),
748                          EGL_FALSE);
749 
750     thread->setSuccess();
751     return EGL_TRUE;
752 }
753 
ProgramCacheGetAttribANGLE(Thread * thread,Display * display,EGLenum attrib)754 EGLint ProgramCacheGetAttribANGLE(Thread *thread, Display *display, EGLenum attrib)
755 {
756     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglProgramCacheGetAttribANGLE",
757                          GetDisplayIfValid(display), 0);
758     thread->setSuccess();
759     return display->programCacheGetAttrib(attrib);
760 }
761 
ProgramCacheQueryANGLE(Thread * thread,Display * display,EGLint index,void * key,EGLint * keysize,void * binary,EGLint * binarysize)762 void ProgramCacheQueryANGLE(Thread *thread,
763                             Display *display,
764                             EGLint index,
765                             void *key,
766                             EGLint *keysize,
767                             void *binary,
768                             EGLint *binarysize)
769 {
770     ANGLE_EGL_TRY(thread, display->prepareForCall(), "eglProgramCacheQueryANGLE",
771                   GetDisplayIfValid(display));
772     ANGLE_EGL_TRY(thread, display->programCacheQuery(index, key, keysize, binary, binarysize),
773                   "eglProgramCacheQueryANGLE", GetDisplayIfValid(display));
774 
775     thread->setSuccess();
776 }
777 
ProgramCachePopulateANGLE(Thread * thread,Display * display,const void * key,EGLint keysize,const void * binary,EGLint binarysize)778 void ProgramCachePopulateANGLE(Thread *thread,
779                                Display *display,
780                                const void *key,
781                                EGLint keysize,
782                                const void *binary,
783                                EGLint binarysize)
784 {
785     ANGLE_EGL_TRY(thread, display->prepareForCall(), "eglProgramCachePopulateANGLE",
786                   GetDisplayIfValid(display));
787     ANGLE_EGL_TRY(thread, display->programCachePopulate(key, keysize, binary, binarysize),
788                   "eglProgramCachePopulateANGLE", GetDisplayIfValid(display));
789 
790     thread->setSuccess();
791 }
792 
ProgramCacheResizeANGLE(Thread * thread,Display * display,EGLint limit,EGLint mode)793 EGLint ProgramCacheResizeANGLE(Thread *thread, Display *display, EGLint limit, EGLint mode)
794 {
795     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglProgramCacheResizeANGLE",
796                          GetDisplayIfValid(display), 0);
797     thread->setSuccess();
798     return display->programCacheResize(limit, mode);
799 }
800 
QueryStringiANGLE(Thread * thread,Display * display,EGLint name,EGLint index)801 const char *QueryStringiANGLE(Thread *thread, Display *display, EGLint name, EGLint index)
802 {
803     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglQueryStringiANGLE",
804                          GetDisplayIfValid(display), nullptr);
805     thread->setSuccess();
806     return display->queryStringi(name, index);
807 }
808 
SwapBuffersWithFrameTokenANGLE(Thread * thread,Display * display,SurfaceID surfaceID,EGLFrameTokenANGLE frametoken)809 EGLBoolean SwapBuffersWithFrameTokenANGLE(Thread *thread,
810                                           Display *display,
811                                           SurfaceID surfaceID,
812                                           EGLFrameTokenANGLE frametoken)
813 {
814     Surface *eglSurface = display->getSurface(surfaceID);
815 
816     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglSwapBuffersWithFrameTokenANGLE",
817                          GetDisplayIfValid(display), EGL_FALSE);
818     ANGLE_EGL_TRY_RETURN(thread, eglSurface->swapWithFrameToken(thread->getContext(), frametoken),
819                          "eglSwapBuffersWithFrameTokenANGLE", GetDisplayIfValid(display),
820                          EGL_FALSE);
821 
822     thread->setSuccess();
823     return EGL_TRUE;
824 }
825 
ReleaseHighPowerGPUANGLE(Thread * thread,Display * display,gl::ContextID contextID)826 void ReleaseHighPowerGPUANGLE(Thread *thread, Display *display, gl::ContextID contextID)
827 {
828     gl::Context *context = display->getContext(contextID);
829     ANGLE_EGL_TRY(thread, display->prepareForCall(), "eglReleaseHighPowerGPUANGLE",
830                   GetDisplayIfValid(display));
831     ANGLE_EGL_TRY(thread, context->releaseHighPowerGPU(), "eglReleaseHighPowerGPUANGLE",
832                   GetDisplayIfValid(display));
833 
834     thread->setSuccess();
835 }
836 
ReacquireHighPowerGPUANGLE(Thread * thread,Display * display,gl::ContextID contextID)837 void ReacquireHighPowerGPUANGLE(Thread *thread, Display *display, gl::ContextID contextID)
838 {
839     gl::Context *context = display->getContext(contextID);
840     ANGLE_EGL_TRY(thread, display->prepareForCall(), "eglReacquireHighPowerGPUANGLE",
841                   GetDisplayIfValid(display));
842     ANGLE_EGL_TRY(thread, context->reacquireHighPowerGPU(), "eglReacquireHighPowerGPUANGLE",
843                   GetDisplayIfValid(display));
844 
845     thread->setSuccess();
846 }
847 
HandleGPUSwitchANGLE(Thread * thread,Display * display)848 void HandleGPUSwitchANGLE(Thread *thread, Display *display)
849 {
850     ANGLE_EGL_TRY(thread, display->prepareForCall(), "eglHandleGPUSwitchANGLE",
851                   GetDisplayIfValid(display));
852     ANGLE_EGL_TRY(thread, display->handleGPUSwitch(), "eglHandleGPUSwitchANGLE",
853                   GetDisplayIfValid(display));
854 
855     thread->setSuccess();
856 }
857 
ForceGPUSwitchANGLE(Thread * thread,Display * display,EGLint gpuIDHigh,EGLint gpuIDLow)858 void ForceGPUSwitchANGLE(Thread *thread, Display *display, EGLint gpuIDHigh, EGLint gpuIDLow)
859 {
860     ANGLE_EGL_TRY(thread, display->prepareForCall(), "eglForceGPUSwitchANGLE",
861                   GetDisplayIfValid(display));
862     ANGLE_EGL_TRY(thread, display->forceGPUSwitch(gpuIDHigh, gpuIDLow), "eglForceGPUSwitchANGLE",
863                   GetDisplayIfValid(display));
864 
865     thread->setSuccess();
866 }
867 
WaitUntilWorkScheduledANGLE(Thread * thread,Display * display)868 void WaitUntilWorkScheduledANGLE(Thread *thread, Display *display)
869 {
870     ANGLE_EGL_TRY(thread, display->prepareForCall(), "eglWaitUntilWorkScheduledANGLE",
871                   GetDisplayIfValid(display));
872     ANGLE_EGL_TRY(thread, display->waitUntilWorkScheduled(), "eglWaitUntilWorkScheduledANGLE",
873                   GetDisplayIfValid(display));
874 
875     thread->setSuccess();
876 }
877 
QueryDisplayAttribANGLE(Thread * thread,Display * display,EGLint attribute,EGLAttrib * value)878 EGLBoolean QueryDisplayAttribANGLE(Thread *thread,
879                                    Display *display,
880                                    EGLint attribute,
881                                    EGLAttrib *value)
882 {
883     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglQueryDisplayAttribEXT",
884                          GetDisplayIfValid(display), EGL_FALSE);
885     *value = display->queryAttrib(attribute);
886     thread->setSuccess();
887     return EGL_TRUE;
888 }
889 
LockSurfaceKHR(Thread * thread,egl::Display * display,SurfaceID surfaceID,const AttributeMap & attributes)890 EGLBoolean LockSurfaceKHR(Thread *thread,
891                           egl::Display *display,
892                           SurfaceID surfaceID,
893                           const AttributeMap &attributes)
894 {
895     Surface *surface = display->getSurface(surfaceID);
896 
897     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglLockSurfaceKHR",
898                          GetDisplayIfValid(display), EGL_FALSE);
899     ANGLE_EGL_TRY_RETURN(thread, surface->lockSurfaceKHR(display, attributes), "eglLockSurfaceKHR",
900                          GetSurfaceIfValid(display, surfaceID), EGL_FALSE);
901     thread->setSuccess();
902     return EGL_TRUE;
903 }
904 
UnlockSurfaceKHR(Thread * thread,egl::Display * display,SurfaceID surfaceID)905 EGLBoolean UnlockSurfaceKHR(Thread *thread, egl::Display *display, SurfaceID surfaceID)
906 {
907     Surface *surface = display->getSurface(surfaceID);
908 
909     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglUnlockSurfaceKHR",
910                          GetDisplayIfValid(display), EGL_FALSE);
911     ANGLE_EGL_TRY_RETURN(thread, surface->unlockSurfaceKHR(display), "eglQuerySurface64KHR",
912                          GetSurfaceIfValid(display, surfaceID), EGL_FALSE);
913     thread->setSuccess();
914     return EGL_TRUE;
915 }
916 
QuerySurface64KHR(Thread * thread,egl::Display * display,SurfaceID surfaceID,EGLint attribute,EGLAttribKHR * value)917 EGLBoolean QuerySurface64KHR(Thread *thread,
918                              egl::Display *display,
919                              SurfaceID surfaceID,
920                              EGLint attribute,
921                              EGLAttribKHR *value)
922 {
923     Surface *surface = display->getSurface(surfaceID);
924 
925     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglQuerySurface64KHR",
926                          GetDisplayIfValid(display), EGL_FALSE);
927     ANGLE_EGL_TRY_RETURN(
928         thread, QuerySurfaceAttrib64KHR(display, thread->getContext(), surface, attribute, value),
929         "eglQuerySurface64KHR", GetSurfaceIfValid(display, surfaceID), EGL_FALSE);
930     thread->setSuccess();
931     return EGL_TRUE;
932 }
933 
ExportVkImageANGLE(Thread * thread,egl::Display * display,egl::ImageID imageID,void * vk_image,void * vk_image_create_info)934 EGLBoolean ExportVkImageANGLE(Thread *thread,
935                               egl::Display *display,
936                               egl::ImageID imageID,
937                               void *vk_image,
938                               void *vk_image_create_info)
939 {
940     Image *image = display->getImage(imageID);
941 
942     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglExportVkImageANGLE",
943                          GetDisplayIfValid(display), EGL_FALSE);
944     ANGLE_EGL_TRY_RETURN(thread, image->exportVkImage(vk_image, vk_image_create_info),
945                          "eglExportVkImageANGLE", GetImageIfValid(display, imageID), EGL_FALSE);
946 
947     thread->setSuccess();
948     return EGL_TRUE;
949 }
950 
SetDamageRegionKHR(Thread * thread,egl::Display * display,SurfaceID surfaceID,EGLint * rects,EGLint n_rects)951 EGLBoolean SetDamageRegionKHR(Thread *thread,
952                               egl::Display *display,
953                               SurfaceID surfaceID,
954                               EGLint *rects,
955                               EGLint n_rects)
956 {
957     Surface *surface = display->getSurface(surfaceID);
958 
959     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglSetDamageRegionKHR",
960                          GetDisplayIfValid(display), EGL_FALSE);
961     surface->setDamageRegion(rects, n_rects);
962 
963     thread->setSuccess();
964     return EGL_TRUE;
965 }
966 
QueryDmaBufFormatsEXT(Thread * thread,egl::Display * display,EGLint max_formats,EGLint * formats,EGLint * num_formats)967 EGLBoolean QueryDmaBufFormatsEXT(Thread *thread,
968                                  egl::Display *display,
969                                  EGLint max_formats,
970                                  EGLint *formats,
971                                  EGLint *num_formats)
972 {
973     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglQueryDmaBufFormatsEXT",
974                          GetDisplayIfValid(display), EGL_FALSE);
975     ANGLE_EGL_TRY_RETURN(thread, display->queryDmaBufFormats(max_formats, formats, num_formats),
976                          "eglQueryDmaBufFormatsEXT", GetDisplayIfValid(display), EGL_FALSE);
977     thread->setSuccess();
978     return EGL_TRUE;
979 }
980 
QueryDmaBufModifiersEXT(Thread * thread,egl::Display * display,EGLint format,EGLint max_modifiers,EGLuint64KHR * modifiers,EGLBoolean * external_only,EGLint * num_modifiers)981 EGLBoolean QueryDmaBufModifiersEXT(Thread *thread,
982                                    egl::Display *display,
983                                    EGLint format,
984                                    EGLint max_modifiers,
985                                    EGLuint64KHR *modifiers,
986                                    EGLBoolean *external_only,
987                                    EGLint *num_modifiers)
988 {
989     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglQueryDmaBufModifiersEXT",
990                          GetDisplayIfValid(display), EGL_FALSE);
991     ANGLE_EGL_TRY_RETURN(thread,
992                          display->queryDmaBufModifiers(format, max_modifiers, modifiers,
993                                                        external_only, num_modifiers),
994                          "eglQueryDmaBufModifiersEXT", GetDisplayIfValid(display), EGL_FALSE);
995     thread->setSuccess();
996     return EGL_TRUE;
997 }
998 
CopyMetalSharedEventANGLE(Thread * thread,Display * display,SyncID syncID)999 void *CopyMetalSharedEventANGLE(Thread *thread, Display *display, SyncID syncID)
1000 {
1001     ANGLE_EGL_TRY_RETURN(thread, display->prepareForCall(), "eglCopyMetalSharedEventANGLE",
1002                          GetDisplayIfValid(display), nullptr);
1003     void *result     = nullptr;
1004     Sync *syncObject = display->getSync(syncID);
1005     ANGLE_EGL_TRY_RETURN(thread, syncObject->copyMetalSharedEventANGLE(display, &result),
1006                          "eglCopyMetalSharedEventANGLE", GetSyncIfValid(display, syncID), nullptr);
1007 
1008     thread->setSuccess();
1009     return result;
1010 }
1011 
AcquireExternalContextANGLE(Thread * thread,egl::Display * display,SurfaceID drawAndReadPacked)1012 void AcquireExternalContextANGLE(Thread *thread, egl::Display *display, SurfaceID drawAndReadPacked)
1013 {
1014     Surface *eglSurface = display->getSurface(drawAndReadPacked);
1015 
1016     ANGLE_EGL_TRY(thread, display->prepareForCall(), "eglAcquireExternalContextANGLE",
1017                   GetDisplayIfValid(display));
1018     ANGLE_EGL_TRY(thread, thread->getContext()->acquireExternalContext(eglSurface),
1019                   "eglAcquireExternalContextANGLE", GetDisplayIfValid(display));
1020 
1021     thread->setSuccess();
1022 }
1023 
ReleaseExternalContextANGLE(Thread * thread,egl::Display * display)1024 void ReleaseExternalContextANGLE(Thread *thread, egl::Display *display)
1025 {
1026     ANGLE_EGL_TRY(thread, display->prepareForCall(), "eglReleaseExternalContextANGLE",
1027                   GetDisplayIfValid(display));
1028     ANGLE_EGL_TRY(thread, thread->getContext()->releaseExternalContext(),
1029                   "eglReleaseExternalContextANGLE", GetDisplayIfValid(display));
1030 
1031     thread->setSuccess();
1032 }
1033 }  // namespace egl
1034