| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef GLUTILS_H |
| 17 |
#define GLUTILS_H |
| 18 |
|
| 19 |
#include "Debug.h" |
| 20 |
|
| 21 |
#include <log/log.h> |
| 22 |
|
| 23 |
#include <EGL/egl.h> |
| 24 |
#include <EGL/eglext.h> |
| 25 |
#include <GLES2/gl2.h> |
| 26 |
#include <GLES2/gl2ext.h> |
| 27 |
#include <GLES3/gl3.h> |
| 28 |
|
| 29 |
namespace android { |
| 30 |
namespace uirenderer { |
| 31 |
|
| 32 |
#if DEBUG_OPENGL |
| 33 |
#define GL_CHECKPOINT(LEVEL) \ |
| 34 |
do { \ |
| 35 |
if (DEBUG_OPENGL >= DEBUG_LEVEL_##LEVEL) { \ |
| 36 |
LOG_ALWAYS_FATAL_IF(android::uirenderer::GLUtils::dumpGLErrors(), "GL errors! %s:%d", \ |
| 37 |
__FILE__, __LINE__); \ |
| 38 |
} \ |
| 39 |
} while (0) |
| 40 |
#else |
| 41 |
#define GL_CHECKPOINT(LEVEL) |
| 42 |
#endif |
| 43 |
|
| 44 |
class GLUtils { |
| 45 |
public: |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
static bool dumpGLErrors(); |
| 51 |
|
| 52 |
static const char* getGLFramebufferError(); |
| 53 |
}; |
| 54 |
|
| 55 |
class AutoEglImage { |
| 56 |
public: |
| 57 |
AutoEglImage(EGLDisplay display, EGLClientBuffer clientBuffer) : mDisplay(display) { |
| 58 |
EGLint imageAttrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
| 59 |
image = eglCreateImageKHR(display, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, clientBuffer, |
| 60 |
imageAttrs); |
| 61 |
} |
| 62 |
|
| 63 |
~AutoEglImage() { |
| 64 |
if (image != EGL_NO_IMAGE_KHR) { |
| 65 |
eglDestroyImageKHR(mDisplay, image); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
EGLImageKHR image = EGL_NO_IMAGE_KHR; |
| 70 |
|
| 71 |
private: |
| 72 |
EGLDisplay mDisplay = EGL_NO_DISPLAY; |
| 73 |
}; |
| 74 |
|
| 75 |
class AutoSkiaGlTexture { |
| 76 |
public: |
| 77 |
AutoSkiaGlTexture() { |
| 78 |
glGenTextures(1, &mTexture); |
| 79 |
glBindTexture(GL_TEXTURE_2D, mTexture); |
| 80 |
} |
| 81 |
|
| 82 |
~AutoSkiaGlTexture() { glDeleteTextures(1, &mTexture); } |
| 83 |
|
| 84 |
GLuint mTexture = 0; |
| 85 |
}; |
| 86 |
|
| 87 |
class AutoGLFramebuffer { |
| 88 |
public: |
| 89 |
AutoGLFramebuffer() { |
| 90 |
glGenFramebuffers(1, &mFb); |
| 91 |
glBindFramebuffer(GL_FRAMEBUFFER, mFb); |
| 92 |
} |
| 93 |
|
| 94 |
~AutoGLFramebuffer() { glDeleteFramebuffers(1, &mFb); } |
| 95 |
|
| 96 |
GLuint mFb; |
| 97 |
}; |
| 98 |
|
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
#endif |