diff --git a/src/egl_context.c b/src/egl_context.c index 6a33396f..91cfefe3 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -232,6 +232,23 @@ static void swapBuffersEGL(_GLFWwindow* window) eglSwapBuffers(_glfw.egl.display, window->context.egl.surface); } +static void swapBuffersWithDamageEGL(_GLFWwindow* window, GLFWrect* rects, int n_rects) +{ + if (window != _glfwPlatformGetTls(&_glfw.contextSlot)) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "EGL: The context must be current on the calling thread when swapping buffers"); + return; + } + + if (eglSwapBuffersWithDamageKHR) + eglSwapBuffersWithDamageKHR(_glfw.egl.display, + window->context.egl.surface, + (EGLint*)rects, (EGLint)n_rects); + else + eglSwapBuffers(_glfw.egl.display, window->context.egl.surface); +} + static void swapIntervalEGL(int interval) { eglSwapInterval(_glfw.egl.display, interval); @@ -425,6 +442,12 @@ GLFWbool _glfwInitEGL(void) extensionSupportedEGL("EGL_KHR_get_all_proc_addresses"); _glfw.egl.KHR_context_flush_control = extensionSupportedEGL("EGL_KHR_context_flush_control"); + _glfw.egl.KHR_swap_buffers_with_damage = + extensionSupportedEGL("EGL_KHR_swap_buffers_with_damage"); + + if (_glfw.egl.KHR_swap_buffers_with_damage) + _glfw.egl.SwapBuffersWithDamageKHR = (PFN_eglSwapBuffersWithDamageKHR) + _glfw.egl.GetProcAddress("eglSwapBuffersWithDamageKHR"); return GLFW_TRUE; } @@ -694,6 +717,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, window->context.makeCurrent = makeContextCurrentEGL; window->context.swapBuffers = swapBuffersEGL; + window->context.swapBuffersWithDamage = swapBuffersWithDamageEGL; window->context.swapInterval = swapIntervalEGL; window->context.extensionSupported = extensionSupportedEGL; window->context.getProcAddress = getProcAddressEGL; diff --git a/src/egl_context.h b/src/egl_context.h index 8bfb7db6..5c78ab27 100644 --- a/src/egl_context.h +++ b/src/egl_context.h @@ -132,6 +132,7 @@ typedef EGLBoolean (EGLAPIENTRY * PFN_eglSwapBuffers)(EGLDisplay,EGLSurface); typedef EGLBoolean (EGLAPIENTRY * PFN_eglSwapInterval)(EGLDisplay,EGLint); typedef const char* (EGLAPIENTRY * PFN_eglQueryString)(EGLDisplay,EGLint); typedef GLFWglproc (EGLAPIENTRY * PFN_eglGetProcAddress)(const char*); +typedef EGLBoolean (EGLAPIENTRY * PFN_eglSwapBuffersWithDamageKHR)(EGLDisplay,EGLSurface,EGLint*,EGLint); #define eglGetConfigAttrib _glfw.egl.GetConfigAttrib #define eglGetConfigs _glfw.egl.GetConfigs #define eglGetDisplay _glfw.egl.GetDisplay @@ -148,6 +149,7 @@ typedef GLFWglproc (EGLAPIENTRY * PFN_eglGetProcAddress)(const char*); #define eglSwapInterval _glfw.egl.SwapInterval #define eglQueryString _glfw.egl.QueryString #define eglGetProcAddress _glfw.egl.GetProcAddress +#define eglSwapBuffersWithDamageKHR _glfw.egl.SwapBuffersWithDamageKHR #define _GLFW_EGL_CONTEXT_STATE _GLFWcontextEGL egl #define _GLFW_EGL_LIBRARY_CONTEXT_STATE _GLFWlibraryEGL egl @@ -178,6 +180,7 @@ typedef struct _GLFWlibraryEGL GLFWbool KHR_gl_colorspace; GLFWbool KHR_get_all_proc_addresses; GLFWbool KHR_context_flush_control; + GLFWbool KHR_swap_buffers_with_damage; void* handle; @@ -197,6 +200,7 @@ typedef struct _GLFWlibraryEGL PFN_eglSwapInterval SwapInterval; PFN_eglQueryString QueryString; PFN_eglGetProcAddress GetProcAddress; + PFN_eglSwapBuffersWithDamageKHR SwapBuffersWithDamageKHR; } _GLFWlibraryEGL;