1 /* 2 * Copyright 2010, The Android Open Source Project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef GLUtils_h 27 #define GLUtils_h 28 29 #if USE(ACCELERATED_COMPOSITING) 30 31 #include "SkBitmap.h" 32 #include "SkMatrix.h" 33 #include "SkSize.h" 34 #include "TextureInfo.h" 35 #include "TransformationMatrix.h" 36 #include <EGL/egl.h> 37 #include <EGL/eglext.h> 38 #include <GLES2/gl2.h> 39 #include <GLES2/gl2ext.h> 40 41 namespace android { 42 43 class SurfaceTexture; 44 45 } // namespace android 46 47 namespace WebCore { 48 49 class GLUtils { 50 51 public: 52 // Matrix utilities 53 static void toGLMatrix(GLfloat* flattened, const TransformationMatrix& matrix); 54 static void toSkMatrix(SkMatrix& skmatrix, const TransformationMatrix& matrix); 55 static void setOrthographicMatrix(TransformationMatrix& ortho, float left, float top, 56 float right, float bottom, float nearZ, float farZ); 57 58 // GL & EGL error checks 59 static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE); 60 static bool checkGlErrorOn(void* p, const char* op); 61 static bool checkGlError(const char* op); 62 static void checkSurfaceTextureError(const char* functionName, int status); 63 64 // GL & EGL extension checks 65 static bool isEGLImageSupported(); 66 static bool isEGLFenceSyncSupported(); 67 68 // Texture utilities 69 static EGLContext createBackgroundContext(EGLContext sharedContext); 70 static void deleteTexture(GLuint* texture); 71 static GLuint createSampleColorTexture(int r, int g, int b); 72 static GLuint createSampleTexture(); 73 static GLuint createBaseTileGLTexture(int width, int height); 74 75 static void createTextureWithBitmap(GLuint texture, const SkBitmap& bitmap, GLint filter = GL_LINEAR); 76 static void updateTextureWithBitmap(GLuint texture, int x, int y, const SkBitmap& bitmap, GLint filter = GL_LINEAR); 77 static void createEGLImageFromTexture(GLuint texture, EGLImageKHR* image); 78 static void createTextureFromEGLImage(GLuint texture, EGLImageKHR image, GLint filter = GL_LINEAR); 79 80 static void paintTextureWithBitmap(const TileRenderInfo* renderInfo, const SkBitmap& bitmap); 81 #if DEPRECATED_SURFACE_TEXTURE_MODE 82 static void createSurfaceTextureWithBitmap(const TileRenderInfo* , const SkBitmap& bitmap, GLint filter = GL_LINEAR); 83 static void updateSurfaceTextureWithBitmap(const TileRenderInfo* , int x, int y, const SkBitmap& bitmap, GLint filter = GL_LINEAR); 84 #endif 85 static void updateSharedSurfaceTextureWithBitmap(const TileRenderInfo* , int x, int y, const SkBitmap& bitmap); 86 }; 87 88 } // namespace WebCore 89 90 #endif // USE(ACCELERATED_COMPOSITING) 91 #endif // GLUtils_h 92