0008-egl-optimise-eglMakeCurrent-for-the-case-where-nothi.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. From 9e3b9f4dfa273c5d0536c748153f65c0899bf3b8 Mon Sep 17 00:00:00 2001
  2. From: Frank Binns <frank.binns@imgtec.com>
  3. Date: Tue, 15 Sep 2015 14:15:31 +0100
  4. Subject: [PATCH] egl: optimise eglMakeCurrent for the case where nothing has
  5. changed
  6. When an application calls eglMakeCurrent with a context, draw surface and
  7. read surface that match those that are currently bound to the calling
  8. thread don't perform a flush as this is an expensive operation.
  9. ---
  10. src/egl/main/eglapi.c | 12 +++++++++++-
  11. 1 file changed, 11 insertions(+), 1 deletion(-)
  12. diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
  13. index 3cd69b9..234449a 100644
  14. --- a/src/egl/main/eglapi.c
  15. +++ b/src/egl/main/eglapi.c
  16. @@ -853,6 +853,7 @@ eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
  17. EGLContext ctx)
  18. {
  19. _EGLDisplay *disp = _eglLockDisplay(dpy);
  20. + _EGLContext *current_context = _eglGetCurrentContext();
  21. _EGLContext *context = _eglLookupContext(ctx, disp);
  22. _EGLSurface *draw_surf = _eglLookupSurface(draw, disp);
  23. _EGLSurface *read_surf = _eglLookupSurface(read, disp);
  24. @@ -909,7 +910,16 @@ eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
  25. draw_surf && !draw_surf->ProtectedContent)
  26. RETURN_EGL_ERROR(disp, EGL_BAD_ACCESS, EGL_FALSE);
  27. - ret = disp->Driver->MakeCurrent(disp, draw_surf, read_surf, context);
  28. + /* As an optimisation don't do anything unless something has changed */
  29. + if (context != current_context ||
  30. + (current_context &&
  31. + (draw_surf != current_context->DrawSurface ||
  32. + read_surf != current_context->ReadSurface)) ||
  33. + (!current_context && (draw_surf || read_surf))) {
  34. + ret = disp->Driver->MakeCurrent(disp, draw_surf, read_surf, context);
  35. + } else {
  36. + ret = EGL_TRUE;
  37. + }
  38. RETURN_EGL_EVAL(disp, ret);
  39. }