1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef GLLIBRARYEGL_H_
6 #define GLLIBRARYEGL_H_
9 # include "mozilla/X11Util.h"
13 #include "mozilla/EnumTypeTraits.h"
14 #include "mozilla/Maybe.h"
15 #include "mozilla/RefPtr.h"
16 #include "nsISupports.h"
21 #include <unordered_map>
23 #ifdef MOZ_WIDGET_ANDROID
24 # include "mozilla/ProfilerLabels.h"
28 # define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)mozilla::DefaultXDisplay())
30 # define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0)
36 struct AHardwareBuffer
;
46 class DataSourceSurface
;
53 PRLibrary
* LoadApitraceLibrary();
55 void BeforeEGLCall(const char* funcName
);
56 void AfterEGLCall(const char* funcName
);
60 * Known GL extensions that can be queried by
61 * IsExtensionSupported. The results of this are cached, and as
62 * such it's safe to use this even in performance critical code.
63 * If you add to this array, remember to add to the string names
64 * in GLLibraryEGL.cpp.
66 enum class EGLLibExtension
{
67 ANDROID_get_native_client_buffer
,
68 ANGLE_device_creation
,
69 ANGLE_device_creation_d3d11
,
71 ANGLE_platform_angle_d3d
,
77 * Known GL extensions that can be queried by
78 * IsExtensionSupported. The results of this are cached, and as
79 * such it's safe to use this even in performance critical code.
80 * If you add to this array, remember to add to the string names
81 * in GLLibraryEGL.cpp.
83 enum class EGLExtension
{
86 KHR_gl_texture_2D_image
,
87 ANGLE_surface_d3d_texture_2d_share_handle
,
88 EXT_create_context_robustness
,
92 ANDROID_native_fence_sync
,
93 EGL_ANDROID_image_crop
,
94 ANGLE_d3d_share_handle_client_buffer
,
97 KHR_stream_consumer_gltexture
,
98 NV_stream_consumer_gltexture_yuv
,
99 ANGLE_stream_producer_d3d_texture
,
100 KHR_surfaceless_context
,
101 KHR_create_context_no_error
,
102 MOZ_create_context_provoking_vertex_dont_care
,
103 EXT_swap_buffers_with_damage
,
104 KHR_swap_buffers_with_damage
,
107 NV_robustness_video_memory_purge
,
113 class GLLibraryEGL final
{
114 friend class EglDisplay
;
117 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GLLibraryEGL
)
120 PRLibrary
* mEGLLibrary
= nullptr;
121 PRLibrary
* mGLLibrary
= nullptr;
122 bool mIsANGLE
= false;
123 std::bitset
<UnderlyingValue(EGLLibExtension::Max
)> mAvailableExtensions
;
124 std::weak_ptr
<EglDisplay
> mDefaultDisplay
;
125 std::unordered_map
<EGLDisplay
, std::weak_ptr
<EglDisplay
>> mActiveDisplays
;
128 static RefPtr
<GLLibraryEGL
> Create(nsACString
* const out_failureId
);
131 ~GLLibraryEGL() = default;
133 bool Init(nsACString
* const out_failureId
);
134 void InitLibExtensions();
137 Maybe
<SymbolLoader
> GetSymbolLoader() const;
139 std::shared_ptr
<EglDisplay
> CreateDisplay(bool forceAccel
,
140 nsACString
* const out_failureId
);
141 std::shared_ptr
<EglDisplay
> CreateDisplay(ID3D11Device
*);
142 std::shared_ptr
<EglDisplay
> DefaultDisplay(nsACString
* const out_failureId
);
144 bool IsExtensionSupported(EGLLibExtension aKnownExtension
) const {
145 return mAvailableExtensions
[UnderlyingValue(aKnownExtension
)];
148 void MarkExtensionUnsupported(EGLLibExtension aKnownExtension
) {
149 mAvailableExtensions
[UnderlyingValue(aKnownExtension
)] = false;
152 bool IsANGLE() const { return mIsANGLE
; }
157 #ifdef MOZ_WIDGET_ANDROID
158 # define PROFILE_CALL AUTO_PROFILER_LABEL(__func__, GRAPHICS);
160 # define PROFILE_CALL
163 #ifndef MOZ_FUNCTION_NAME
165 # define MOZ_FUNCTION_NAME __PRETTY_FUNCTION__
166 # elif defined(_MSC_VER)
167 # define MOZ_FUNCTION_NAME __FUNCTION__
169 # define MOZ_FUNCTION_NAME \
170 __func__ // defined in C99, supported in various C++ compilers. Just raw
176 # define BEFORE_CALL BeforeEGLCall(MOZ_FUNCTION_NAME);
177 # define AFTER_CALL AfterEGLCall(MOZ_FUNCTION_NAME);
186 const auto ret = mSymbols.X; \
191 EGLDisplay
fGetDisplay(void* display_id
) const {
192 WRAP(fGetDisplay(display_id
));
195 EGLDisplay
fGetPlatformDisplay(EGLenum platform
, void* native_display
,
196 const EGLAttrib
* attrib_list
) const {
197 WRAP(fGetPlatformDisplay(platform
, native_display
, attrib_list
));
200 EGLSurface
fGetCurrentSurface(EGLint id
) const {
201 WRAP(fGetCurrentSurface(id
));
204 EGLContext
fGetCurrentContext() const { WRAP(fGetCurrentContext()); }
206 EGLBoolean
fBindAPI(EGLenum api
) const { WRAP(fBindAPI(api
)); }
208 EGLint
fGetError() const { WRAP(fGetError()); }
210 EGLBoolean
fWaitNative(EGLint engine
) const { WRAP(fWaitNative(engine
)); }
212 EGLCastToRelevantPtr
fGetProcAddress(const char* procname
) const {
213 WRAP(fGetProcAddress(procname
));
216 // ANGLE_device_creation
217 EGLDeviceEXT
fCreateDeviceANGLE(EGLint device_type
, void* native_device
,
218 const EGLAttrib
* attrib_list
) const {
219 WRAP(fCreateDeviceANGLE(device_type
, native_device
, attrib_list
));
222 EGLBoolean
fReleaseDeviceANGLE(EGLDeviceEXT device
) {
223 WRAP(fReleaseDeviceANGLE(device
));
226 // ANDROID_get_native_client_buffer
227 EGLClientBuffer
fGetNativeClientBufferANDROID(
228 const struct AHardwareBuffer
* buffer
) {
229 WRAP(fGetNativeClientBufferANDROID(buffer
));
233 EGLBoolean
fTerminate(EGLDisplay display
) const { WRAP(fTerminate(display
)); }
235 EGLBoolean
fMakeCurrent(EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
,
236 EGLContext ctx
) const {
237 WRAP(fMakeCurrent(dpy
, draw
, read
, ctx
));
240 EGLBoolean
fDestroyContext(EGLDisplay dpy
, EGLContext ctx
) const {
241 WRAP(fDestroyContext(dpy
, ctx
));
244 EGLContext
fCreateContext(EGLDisplay dpy
, EGLConfig config
,
245 EGLContext share_context
,
246 const EGLint
* attrib_list
) const {
247 WRAP(fCreateContext(dpy
, config
, share_context
, attrib_list
));
250 EGLBoolean
fDestroySurface(EGLDisplay dpy
, EGLSurface surface
) const {
251 WRAP(fDestroySurface(dpy
, surface
));
255 EGLSurface
fCreateWindowSurface(EGLDisplay dpy
, EGLConfig config
,
256 EGLNativeWindowType win
,
257 const EGLint
* attrib_list
) const {
258 WRAP(fCreateWindowSurface(dpy
, config
, win
, attrib_list
));
262 EGLSurface
fCreatePbufferSurface(EGLDisplay dpy
, EGLConfig config
,
263 const EGLint
* attrib_list
) const {
264 WRAP(fCreatePbufferSurface(dpy
, config
, attrib_list
));
267 EGLSurface
fCreatePbufferFromClientBuffer(EGLDisplay dpy
, EGLenum buftype
,
268 EGLClientBuffer buffer
,
270 const EGLint
* attrib_list
) const {
271 WRAP(fCreatePbufferFromClientBuffer(dpy
, buftype
, buffer
, config
,
275 EGLSurface
fCreatePixmapSurface(EGLDisplay dpy
, EGLConfig config
,
276 EGLNativePixmapType pixmap
,
277 const EGLint
* attrib_list
) const {
278 WRAP(fCreatePixmapSurface(dpy
, config
, pixmap
, attrib_list
));
281 EGLBoolean
fInitialize(EGLDisplay dpy
, EGLint
* major
, EGLint
* minor
) const {
282 WRAP(fInitialize(dpy
, major
, minor
));
285 EGLBoolean
fChooseConfig(EGLDisplay dpy
, const EGLint
* attrib_list
,
286 EGLConfig
* configs
, EGLint config_size
,
287 EGLint
* num_config
) const {
288 WRAP(fChooseConfig(dpy
, attrib_list
, configs
, config_size
, num_config
));
291 EGLBoolean
fGetConfigAttrib(EGLDisplay dpy
, EGLConfig config
,
292 EGLint attribute
, EGLint
* value
) const {
293 WRAP(fGetConfigAttrib(dpy
, config
, attribute
, value
));
296 EGLBoolean
fGetConfigs(EGLDisplay dpy
, EGLConfig
* configs
, EGLint config_size
,
297 EGLint
* num_config
) const {
298 WRAP(fGetConfigs(dpy
, configs
, config_size
, num_config
));
301 EGLBoolean
fSwapBuffers(EGLDisplay dpy
, EGLSurface surface
) const {
302 WRAP(fSwapBuffers(dpy
, surface
));
305 EGLBoolean
fCopyBuffers(EGLDisplay dpy
, EGLSurface surface
,
306 EGLNativePixmapType target
) const {
307 WRAP(fCopyBuffers(dpy
, surface
, target
));
311 const GLubyte
* fQueryString(EGLDisplay dpy
, EGLint name
) const {
312 WRAP(fQueryString(dpy
, name
));
316 EGLBoolean
fQueryContext(EGLDisplay dpy
, EGLContext ctx
, EGLint attribute
,
317 EGLint
* value
) const {
318 WRAP(fQueryContext(dpy
, ctx
, attribute
, value
));
321 EGLBoolean
fBindTexImage(EGLDisplay dpy
, EGLSurface surface
,
322 EGLint buffer
) const {
323 WRAP(fBindTexImage(dpy
, surface
, buffer
));
326 EGLBoolean
fReleaseTexImage(EGLDisplay dpy
, EGLSurface surface
,
327 EGLint buffer
) const {
328 WRAP(fReleaseTexImage(dpy
, surface
, buffer
));
331 EGLBoolean
fSwapInterval(EGLDisplay dpy
, EGLint interval
) const {
332 WRAP(fSwapInterval(dpy
, interval
));
335 EGLImage
fCreateImage(EGLDisplay dpy
, EGLContext ctx
, EGLenum target
,
336 EGLClientBuffer buffer
,
337 const EGLint
* attrib_list
) const {
338 WRAP(fCreateImageKHR(dpy
, ctx
, target
, buffer
, attrib_list
));
341 EGLBoolean
fDestroyImage(EGLDisplay dpy
, EGLImage image
) const {
342 WRAP(fDestroyImageKHR(dpy
, image
));
345 EGLBoolean
fQuerySurface(EGLDisplay dpy
, EGLSurface surface
, EGLint attribute
,
346 EGLint
* value
) const {
347 WRAP(fQuerySurface(dpy
, surface
, attribute
, value
));
350 EGLBoolean
fQuerySurfacePointerANGLE(EGLDisplay dpy
, EGLSurface surface
,
351 EGLint attribute
, void** value
) const {
352 WRAP(fQuerySurfacePointerANGLE(dpy
, surface
, attribute
, value
));
355 EGLSync
fCreateSync(EGLDisplay dpy
, EGLenum type
,
356 const EGLint
* attrib_list
) const {
357 WRAP(fCreateSyncKHR(dpy
, type
, attrib_list
));
360 EGLBoolean
fDestroySync(EGLDisplay dpy
, EGLSync sync
) const {
361 WRAP(fDestroySyncKHR(dpy
, sync
));
364 EGLint
fClientWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
,
365 EGLTime timeout
) const {
366 WRAP(fClientWaitSyncKHR(dpy
, sync
, flags
, timeout
));
369 EGLBoolean
fGetSyncAttrib(EGLDisplay dpy
, EGLSync sync
, EGLint attribute
,
370 EGLint
* value
) const {
371 WRAP(fGetSyncAttribKHR(dpy
, sync
, attribute
, value
));
374 EGLint
fWaitSync(EGLDisplay dpy
, EGLSync sync
, EGLint flags
) const {
375 WRAP(fWaitSyncKHR(dpy
, sync
, flags
));
378 EGLint
fDupNativeFenceFDANDROID(EGLDisplay dpy
, EGLSync sync
) const {
379 WRAP(fDupNativeFenceFDANDROID(dpy
, sync
));
383 EGLStreamKHR
fCreateStreamKHR(EGLDisplay dpy
,
384 const EGLint
* attrib_list
) const {
385 WRAP(fCreateStreamKHR(dpy
, attrib_list
));
388 EGLBoolean
fDestroyStreamKHR(EGLDisplay dpy
, EGLStreamKHR stream
) const {
389 WRAP(fDestroyStreamKHR(dpy
, stream
));
392 EGLBoolean
fQueryStreamKHR(EGLDisplay dpy
, EGLStreamKHR stream
,
393 EGLenum attribute
, EGLint
* value
) const {
394 WRAP(fQueryStreamKHR(dpy
, stream
, attribute
, value
));
397 // KHR_stream_consumer_gltexture
398 EGLBoolean
fStreamConsumerGLTextureExternalKHR(EGLDisplay dpy
,
399 EGLStreamKHR stream
) const {
400 WRAP(fStreamConsumerGLTextureExternalKHR(dpy
, stream
));
403 EGLBoolean
fStreamConsumerAcquireKHR(EGLDisplay dpy
,
404 EGLStreamKHR stream
) const {
405 WRAP(fStreamConsumerAcquireKHR(dpy
, stream
));
408 EGLBoolean
fStreamConsumerReleaseKHR(EGLDisplay dpy
,
409 EGLStreamKHR stream
) const {
410 WRAP(fStreamConsumerReleaseKHR(dpy
, stream
));
414 EGLBoolean
fQueryDisplayAttribEXT(EGLDisplay dpy
, EGLint attribute
,
415 EGLAttrib
* value
) const {
416 WRAP(fQueryDisplayAttribEXT(dpy
, attribute
, value
));
420 EGLBoolean
fQueryDeviceAttribEXT(EGLDeviceEXT device
, EGLint attribute
,
421 EGLAttrib
* value
) const {
422 WRAP(fQueryDeviceAttribEXT(device
, attribute
, value
));
426 // NV_stream_consumer_gltexture_yuv
427 EGLBoolean
fStreamConsumerGLTextureExternalAttribsNV(
428 EGLDisplay dpy
, EGLStreamKHR stream
, const EGLAttrib
* attrib_list
) const {
429 WRAP(fStreamConsumerGLTextureExternalAttribsNV(dpy
, stream
, attrib_list
));
432 // ANGLE_stream_producer_d3d_texture
433 EGLBoolean
fCreateStreamProducerD3DTextureANGLE(
434 EGLDisplay dpy
, EGLStreamKHR stream
, const EGLAttrib
* attrib_list
) const {
435 WRAP(fCreateStreamProducerD3DTextureANGLE(dpy
, stream
, attrib_list
));
438 EGLBoolean
fStreamPostD3DTextureANGLE(EGLDisplay dpy
, EGLStreamKHR stream
,
440 const EGLAttrib
* attrib_list
) const {
441 WRAP(fStreamPostD3DTextureANGLE(dpy
, stream
, texture
, attrib_list
));
444 // EGL_EXT_swap_buffers_with_damage / EGL_KHR_swap_buffers_with_damage
445 EGLBoolean
fSwapBuffersWithDamage(EGLDisplay dpy
, EGLSurface surface
,
446 const EGLint
* rects
, EGLint n_rects
) {
447 WRAP(fSwapBuffersWithDamage(dpy
, surface
, rects
, n_rects
));
450 // EGL_KHR_partial_update
451 EGLBoolean
fSetDamageRegion(EGLDisplay dpy
, EGLSurface surface
,
452 const EGLint
* rects
, EGLint n_rects
) {
453 WRAP(fSetDamageRegion(dpy
, surface
, rects
, n_rects
));
460 #undef MOZ_FUNCTION_NAME
466 EGLCastToRelevantPtr(GLAPIENTRY
* fGetProcAddress
)(const char* procname
);
467 EGLDisplay(GLAPIENTRY
* fGetDisplay
)(void* display_id
);
468 EGLDisplay(GLAPIENTRY
* fGetPlatformDisplay
)(EGLenum platform
,
469 void* native_display
,
470 const EGLAttrib
* attrib_list
);
471 EGLBoolean(GLAPIENTRY
* fTerminate
)(EGLDisplay dpy
);
472 EGLSurface(GLAPIENTRY
* fGetCurrentSurface
)(EGLint
);
473 EGLContext(GLAPIENTRY
* fGetCurrentContext
)(void);
474 EGLBoolean(GLAPIENTRY
* fMakeCurrent
)(EGLDisplay dpy
, EGLSurface draw
,
475 EGLSurface read
, EGLContext ctx
);
476 EGLBoolean(GLAPIENTRY
* fDestroyContext
)(EGLDisplay dpy
, EGLContext ctx
);
477 EGLContext(GLAPIENTRY
* fCreateContext
)(EGLDisplay dpy
, EGLConfig config
,
478 EGLContext share_context
,
479 const EGLint
* attrib_list
);
480 EGLBoolean(GLAPIENTRY
* fDestroySurface
)(EGLDisplay dpy
, EGLSurface surface
);
481 EGLSurface(GLAPIENTRY
* fCreateWindowSurface
)(EGLDisplay dpy
,
483 EGLNativeWindowType win
,
484 const EGLint
* attrib_list
);
485 EGLSurface(GLAPIENTRY
* fCreatePbufferSurface
)(EGLDisplay dpy
,
487 const EGLint
* attrib_list
);
488 EGLSurface(GLAPIENTRY
* fCreatePbufferFromClientBuffer
)(
489 EGLDisplay dpy
, EGLenum buftype
, EGLClientBuffer buffer
,
490 EGLConfig config
, const EGLint
* attrib_list
);
491 EGLSurface(GLAPIENTRY
* fCreatePixmapSurface
)(EGLDisplay dpy
,
493 EGLNativePixmapType pixmap
,
494 const EGLint
* attrib_list
);
495 EGLBoolean(GLAPIENTRY
* fBindAPI
)(EGLenum api
);
496 EGLBoolean(GLAPIENTRY
* fInitialize
)(EGLDisplay dpy
, EGLint
* major
,
498 EGLBoolean(GLAPIENTRY
* fChooseConfig
)(EGLDisplay dpy
,
499 const EGLint
* attrib_list
,
503 EGLint(GLAPIENTRY
* fGetError
)(void);
504 EGLBoolean(GLAPIENTRY
* fGetConfigAttrib
)(EGLDisplay dpy
, EGLConfig config
,
505 EGLint attribute
, EGLint
* value
);
506 EGLBoolean(GLAPIENTRY
* fGetConfigs
)(EGLDisplay dpy
, EGLConfig
* configs
,
507 EGLint config_size
, EGLint
* num_config
);
508 EGLBoolean(GLAPIENTRY
* fWaitNative
)(EGLint engine
);
509 EGLBoolean(GLAPIENTRY
* fSwapBuffers
)(EGLDisplay dpy
, EGLSurface surface
);
510 EGLBoolean(GLAPIENTRY
* fCopyBuffers
)(EGLDisplay dpy
, EGLSurface surface
,
511 EGLNativePixmapType target
);
512 const GLubyte
*(GLAPIENTRY
* fQueryString
)(EGLDisplay
, EGLint name
);
513 EGLBoolean(GLAPIENTRY
* fQueryContext
)(EGLDisplay dpy
, EGLContext ctx
,
514 EGLint attribute
, EGLint
* value
);
515 EGLBoolean(GLAPIENTRY
* fBindTexImage
)(EGLDisplay
, EGLSurface surface
,
517 EGLBoolean(GLAPIENTRY
* fReleaseTexImage
)(EGLDisplay
, EGLSurface surface
,
519 EGLBoolean(GLAPIENTRY
* fSwapInterval
)(EGLDisplay dpy
, EGLint interval
);
520 EGLImage(GLAPIENTRY
* fCreateImageKHR
)(EGLDisplay dpy
, EGLContext ctx
,
522 EGLClientBuffer buffer
,
523 const EGLint
* attrib_list
);
524 EGLBoolean(GLAPIENTRY
* fDestroyImageKHR
)(EGLDisplay dpy
, EGLImage image
);
525 EGLBoolean(GLAPIENTRY
* fQuerySurface
)(EGLDisplay dpy
, EGLSurface surface
,
526 EGLint attribute
, EGLint
* value
);
527 EGLBoolean(GLAPIENTRY
* fQuerySurfacePointerANGLE
)(EGLDisplay dpy
,
531 EGLSync(GLAPIENTRY
* fCreateSyncKHR
)(EGLDisplay dpy
, EGLenum type
,
532 const EGLint
* attrib_list
);
533 EGLBoolean(GLAPIENTRY
* fDestroySyncKHR
)(EGLDisplay dpy
, EGLSync sync
);
534 EGLint(GLAPIENTRY
* fClientWaitSyncKHR
)(EGLDisplay dpy
, EGLSync sync
,
535 EGLint flags
, EGLTime timeout
);
536 EGLBoolean(GLAPIENTRY
* fGetSyncAttribKHR
)(EGLDisplay dpy
, EGLSync sync
,
537 EGLint attribute
, EGLint
* value
);
538 EGLint(GLAPIENTRY
* fWaitSyncKHR
)(EGLDisplay dpy
, EGLSync sync
,
540 EGLint(GLAPIENTRY
* fDupNativeFenceFDANDROID
)(EGLDisplay dpy
, EGLSync sync
);
542 EGLStreamKHR(GLAPIENTRY
* fCreateStreamKHR
)(EGLDisplay dpy
,
543 const EGLint
* attrib_list
);
544 EGLBoolean(GLAPIENTRY
* fDestroyStreamKHR
)(EGLDisplay dpy
,
545 EGLStreamKHR stream
);
546 EGLBoolean(GLAPIENTRY
* fQueryStreamKHR
)(EGLDisplay dpy
, EGLStreamKHR stream
,
547 EGLenum attribute
, EGLint
* value
);
548 // KHR_stream_consumer_gltexture
549 EGLBoolean(GLAPIENTRY
* fStreamConsumerGLTextureExternalKHR
)(
550 EGLDisplay dpy
, EGLStreamKHR stream
);
551 EGLBoolean(GLAPIENTRY
* fStreamConsumerAcquireKHR
)(EGLDisplay dpy
,
552 EGLStreamKHR stream
);
553 EGLBoolean(GLAPIENTRY
* fStreamConsumerReleaseKHR
)(EGLDisplay dpy
,
554 EGLStreamKHR stream
);
556 EGLBoolean(GLAPIENTRY
* fQueryDisplayAttribEXT
)(EGLDisplay dpy
,
559 EGLBoolean(GLAPIENTRY
* fQueryDeviceAttribEXT
)(EGLDeviceEXT device
,
562 // NV_stream_consumer_gltexture_yuv
563 EGLBoolean(GLAPIENTRY
* fStreamConsumerGLTextureExternalAttribsNV
)(
564 EGLDisplay dpy
, EGLStreamKHR stream
, const EGLAttrib
* attrib_list
);
565 // ANGLE_stream_producer_d3d_texture
566 EGLBoolean(GLAPIENTRY
* fCreateStreamProducerD3DTextureANGLE
)(
567 EGLDisplay dpy
, EGLStreamKHR stream
, const EGLAttrib
* attrib_list
);
568 EGLBoolean(GLAPIENTRY
* fStreamPostD3DTextureANGLE
)(
569 EGLDisplay dpy
, EGLStreamKHR stream
, void* texture
,
570 const EGLAttrib
* attrib_list
);
571 // ANGLE_device_creation
572 EGLDeviceEXT(GLAPIENTRY
* fCreateDeviceANGLE
)(EGLint device_type
,
574 const EGLAttrib
* attrib_list
);
575 EGLBoolean(GLAPIENTRY
* fReleaseDeviceANGLE
)(EGLDeviceEXT device
);
576 // EGL_EXT_swap_buffers_with_damage / EGL_KHR_swap_buffers_with_damage
577 EGLBoolean(GLAPIENTRY
* fSwapBuffersWithDamage
)(EGLDisplay dpy
,
581 // EGL_KHR_partial_update
582 EGLBoolean(GLAPIENTRY
* fSetDamageRegion
)(EGLDisplay dpy
, EGLSurface surface
,
585 EGLClientBuffer(GLAPIENTRY
* fGetNativeClientBufferANDROID
)(
586 const struct AHardwareBuffer
* buffer
);
590 class EglDisplay final
{
592 const RefPtr
<GLLibraryEGL
> mLib
;
593 const EGLDisplay mDisplay
;
597 std::bitset
<UnderlyingValue(EGLExtension::Max
)> mAvailableExtensions
;
599 struct PrivateUseOnly final
{};
602 static std::shared_ptr
<EglDisplay
> Create(GLLibraryEGL
&, EGLDisplay
,
605 // Only `public` for make_shared.
606 EglDisplay(const PrivateUseOnly
&, GLLibraryEGL
&, EGLDisplay
, bool isWarp
);
611 bool IsExtensionSupported(EGLExtension aKnownExtension
) const {
612 return mAvailableExtensions
[UnderlyingValue(aKnownExtension
)];
615 void MarkExtensionUnsupported(EGLExtension aKnownExtension
) {
616 mAvailableExtensions
[UnderlyingValue(aKnownExtension
)] = false;
619 void DumpEGLConfig(EGLConfig
) const;
620 void DumpEGLConfigs() const;
626 bool HasKHRImageBase() const {
627 return IsExtensionSupported(EGLExtension::KHR_image
) ||
628 IsExtensionSupported(EGLExtension::KHR_image_base
);
631 bool HasKHRImagePixmap() const {
632 return IsExtensionSupported(EGLExtension::KHR_image
) ||
633 IsExtensionSupported(EGLExtension::KHR_image_pixmap
);
638 EGLBoolean
fTerminate() { return mLib
->fTerminate(mDisplay
); }
640 EGLBoolean
fMakeCurrent(EGLSurface draw
, EGLSurface read
,
641 EGLContext ctx
) const {
642 return mLib
->fMakeCurrent(mDisplay
, draw
, read
, ctx
);
645 EGLBoolean
fDestroyContext(EGLContext ctx
) const {
646 return mLib
->fDestroyContext(mDisplay
, ctx
);
649 EGLContext
fCreateContext(EGLConfig config
, EGLContext share_context
,
650 const EGLint
* attrib_list
) const {
651 return mLib
->fCreateContext(mDisplay
, config
, share_context
, attrib_list
);
654 EGLBoolean
fDestroySurface(EGLSurface surface
) const {
655 return mLib
->fDestroySurface(mDisplay
, surface
);
658 EGLSurface
fCreateWindowSurface(EGLConfig config
, EGLNativeWindowType win
,
659 const EGLint
* attrib_list
) const {
660 return mLib
->fCreateWindowSurface(mDisplay
, config
, win
, attrib_list
);
663 EGLSurface
fCreatePbufferSurface(EGLConfig config
,
664 const EGLint
* attrib_list
) const {
665 return mLib
->fCreatePbufferSurface(mDisplay
, config
, attrib_list
);
668 EGLSurface
fCreatePbufferFromClientBuffer(EGLenum buftype
,
669 EGLClientBuffer buffer
,
671 const EGLint
* attrib_list
) const {
672 return mLib
->fCreatePbufferFromClientBuffer(mDisplay
, buftype
, buffer
,
673 config
, attrib_list
);
676 EGLBoolean
fChooseConfig(const EGLint
* attrib_list
, EGLConfig
* configs
,
677 EGLint config_size
, EGLint
* num_config
) const {
678 return mLib
->fChooseConfig(mDisplay
, attrib_list
, configs
, config_size
,
682 EGLBoolean
fGetConfigAttrib(EGLConfig config
, EGLint attribute
,
683 EGLint
* value
) const {
684 return mLib
->fGetConfigAttrib(mDisplay
, config
, attribute
, value
);
687 EGLBoolean
fGetConfigs(EGLConfig
* configs
, EGLint config_size
,
688 EGLint
* num_config
) const {
689 return mLib
->fGetConfigs(mDisplay
, configs
, config_size
, num_config
);
692 EGLBoolean
fSwapBuffers(EGLSurface surface
) const {
693 return mLib
->fSwapBuffers(mDisplay
, surface
);
696 EGLBoolean
fBindTexImage(EGLSurface surface
, EGLint buffer
) const {
697 return mLib
->fBindTexImage(mDisplay
, surface
, buffer
);
700 EGLBoolean
fReleaseTexImage(EGLSurface surface
, EGLint buffer
) const {
701 return mLib
->fReleaseTexImage(mDisplay
, surface
, buffer
);
704 EGLBoolean
fSwapInterval(EGLint interval
) const {
705 return mLib
->fSwapInterval(mDisplay
, interval
);
708 EGLImage
fCreateImage(EGLContext ctx
, EGLenum target
, EGLClientBuffer buffer
,
709 const EGLint
* attribList
) const {
710 MOZ_ASSERT(HasKHRImageBase());
711 return mLib
->fCreateImage(mDisplay
, ctx
, target
, buffer
, attribList
);
714 EGLBoolean
fDestroyImage(EGLImage image
) const {
715 MOZ_ASSERT(HasKHRImageBase());
716 return mLib
->fDestroyImage(mDisplay
, image
);
719 EGLBoolean
fQuerySurface(EGLSurface surface
, EGLint attribute
,
720 EGLint
* value
) const {
721 return mLib
->fQuerySurface(mDisplay
, surface
, attribute
, value
);
724 EGLBoolean
fQuerySurfacePointerANGLE(EGLSurface surface
, EGLint attribute
,
725 void** value
) const {
726 MOZ_ASSERT(IsExtensionSupported(
727 EGLExtension::ANGLE_surface_d3d_texture_2d_share_handle
));
728 return mLib
->fQuerySurfacePointerANGLE(mDisplay
, surface
, attribute
, value
);
731 EGLSync
fCreateSync(EGLenum type
, const EGLint
* attrib_list
) const {
732 MOZ_ASSERT(IsExtensionSupported(EGLExtension::KHR_fence_sync
));
733 return mLib
->fCreateSync(mDisplay
, type
, attrib_list
);
736 EGLBoolean
fDestroySync(EGLSync sync
) const {
737 MOZ_ASSERT(IsExtensionSupported(EGLExtension::KHR_fence_sync
));
738 return mLib
->fDestroySync(mDisplay
, sync
);
741 EGLint
fClientWaitSync(EGLSync sync
, EGLint flags
, EGLTime timeout
) const {
742 MOZ_ASSERT(IsExtensionSupported(EGLExtension::KHR_fence_sync
));
743 return mLib
->fClientWaitSync(mDisplay
, sync
, flags
, timeout
);
746 EGLBoolean
fGetSyncAttrib(EGLSync sync
, EGLint attribute
,
747 EGLint
* value
) const {
748 MOZ_ASSERT(IsExtensionSupported(EGLExtension::KHR_fence_sync
));
749 return mLib
->fGetSyncAttrib(mDisplay
, sync
, attribute
, value
);
752 EGLint
fWaitSync(EGLSync sync
, EGLint flags
) const {
753 MOZ_ASSERT(IsExtensionSupported(EGLExtension::KHR_wait_sync
));
754 return mLib
->fWaitSync(mDisplay
, sync
, flags
);
757 EGLint
fDupNativeFenceFDANDROID(EGLSync sync
) const {
758 MOZ_ASSERT(IsExtensionSupported(EGLExtension::ANDROID_native_fence_sync
));
759 return mLib
->fDupNativeFenceFDANDROID(mDisplay
, sync
);
763 EGLBoolean
fQueryDisplayAttribEXT(EGLint attribute
, EGLAttrib
* value
) const {
764 MOZ_ASSERT(mLib
->IsExtensionSupported(EGLLibExtension::EXT_device_query
));
765 return mLib
->fQueryDisplayAttribEXT(mDisplay
, attribute
, value
);
769 EGLStreamKHR
fCreateStreamKHR(const EGLint
* attrib_list
) const {
770 MOZ_ASSERT(IsExtensionSupported(EGLExtension::KHR_stream
));
771 return mLib
->fCreateStreamKHR(mDisplay
, attrib_list
);
774 EGLBoolean
fDestroyStreamKHR(EGLStreamKHR stream
) const {
775 MOZ_ASSERT(IsExtensionSupported(EGLExtension::KHR_stream
));
776 return mLib
->fDestroyStreamKHR(mDisplay
, stream
);
779 EGLBoolean
fQueryStreamKHR(EGLStreamKHR stream
, EGLenum attribute
,
780 EGLint
* value
) const {
781 MOZ_ASSERT(IsExtensionSupported(EGLExtension::KHR_stream
));
782 return mLib
->fQueryStreamKHR(mDisplay
, stream
, attribute
, value
);
785 // KHR_stream_consumer_gltexture
786 EGLBoolean
fStreamConsumerGLTextureExternalKHR(EGLStreamKHR stream
) const {
788 IsExtensionSupported(EGLExtension::KHR_stream_consumer_gltexture
));
789 return mLib
->fStreamConsumerGLTextureExternalKHR(mDisplay
, stream
);
792 EGLBoolean
fStreamConsumerAcquireKHR(EGLStreamKHR stream
) const {
794 IsExtensionSupported(EGLExtension::KHR_stream_consumer_gltexture
));
795 return mLib
->fStreamConsumerAcquireKHR(mDisplay
, stream
);
798 EGLBoolean
fStreamConsumerReleaseKHR(EGLStreamKHR stream
) const {
800 IsExtensionSupported(EGLExtension::KHR_stream_consumer_gltexture
));
801 return mLib
->fStreamConsumerReleaseKHR(mDisplay
, stream
);
804 // NV_stream_consumer_gltexture_yuv
805 EGLBoolean
fStreamConsumerGLTextureExternalAttribsNV(
806 EGLStreamKHR stream
, const EGLAttrib
* attrib_list
) const {
808 IsExtensionSupported(EGLExtension::NV_stream_consumer_gltexture_yuv
));
809 return mLib
->fStreamConsumerGLTextureExternalAttribsNV(mDisplay
, stream
,
813 // ANGLE_stream_producer_d3d_texture
814 EGLBoolean
fCreateStreamProducerD3DTextureANGLE(
815 EGLStreamKHR stream
, const EGLAttrib
* attrib_list
) const {
817 IsExtensionSupported(EGLExtension::ANGLE_stream_producer_d3d_texture
));
818 return mLib
->fCreateStreamProducerD3DTextureANGLE(mDisplay
, stream
,
822 EGLBoolean
fStreamPostD3DTextureANGLE(EGLStreamKHR stream
, void* texture
,
823 const EGLAttrib
* attrib_list
) const {
825 IsExtensionSupported(EGLExtension::ANGLE_stream_producer_d3d_texture
));
826 return mLib
->fStreamPostD3DTextureANGLE(mDisplay
, stream
, texture
,
830 // EGL_EXT_swap_buffers_with_damage / EGL_KHR_swap_buffers_with_damage
831 EGLBoolean
fSwapBuffersWithDamage(EGLSurface surface
, const EGLint
* rects
,
834 IsExtensionSupported(EGLExtension::EXT_swap_buffers_with_damage
) ||
835 IsExtensionSupported(EGLExtension::KHR_swap_buffers_with_damage
));
836 return mLib
->fSwapBuffersWithDamage(mDisplay
, surface
, rects
, n_rects
);
839 // EGL_KHR_partial_update
840 EGLBoolean
fSetDamageRegion(EGLSurface surface
, const EGLint
* rects
,
842 MOZ_ASSERT(IsExtensionSupported(EGLExtension::KHR_partial_update
));
843 return mLib
->fSetDamageRegion(mDisplay
, surface
, rects
, n_rects
);
848 } /* namespace mozilla */
850 #endif /* GLLIBRARYEGL_H_ */