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 "Color.h" 32 #include "IntRect.h" 33 #include "SkBitmap.h" 34 #include "SkMatrix.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 TileRenderInfo; 50 51 class GLUtils { 52 53 public: 54 // Matrix utilities 55 static void toGLMatrix(GLfloat* flattened, const TransformationMatrix& matrix); 56 static void toSkMatrix(SkMatrix& skmatrix, const TransformationMatrix& matrix); 57 static void setOrthographicMatrix(TransformationMatrix& ortho, float left, float top, 58 float right, float bottom, float nearZ, float farZ); 59 static bool has3dTransform(const TransformationMatrix& matrix); 60 61 // GL & EGL error checks 62 static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE); 63 static bool checkGlErrorOn(void* p, const char* op); 64 static bool checkGlError(const char* op); 65 static void checkSurfaceTextureError(const char* functionName, int status); 66 67 // GL & EGL extension checks 68 static bool isEGLImageSupported(); 69 static bool isEGLFenceSyncSupported(); 70 71 // Texture utilities 72 static void deleteTexture(GLuint* texture); 73 static GLuint createSampleColorTexture(int r, int g, int b); 74 static GLuint createSampleTexture(); 75 static GLuint createTileGLTexture(int width, int height); 76 77 static void createTextureWithBitmap(GLuint texture, const SkBitmap& bitmap, GLint filter = GL_LINEAR); 78 static void updateTextureWithBitmap(GLuint texture, const SkBitmap& bitmap, 79 const IntRect& inval = IntRect(), GLint filter = GL_LINEAR); 80 static void createEGLImageFromTexture(GLuint texture, EGLImageKHR* image); 81 static void createTextureFromEGLImage(GLuint texture, EGLImageKHR image, GLint filter = GL_LINEAR); 82 83 static void paintTextureWithBitmap(const TileRenderInfo* renderInfo, const SkBitmap& bitmap); 84 static void updateQueueWithBitmap(const TileRenderInfo* , const SkBitmap& bitmap); 85 static bool updateSharedSurfaceTextureWithBitmap(ANativeWindow* anw, const SkBitmap& bitmap); 86 static void convertToTransformationMatrix(const float* matrix, TransformationMatrix& transformMatrix); 87 88 static bool deepCopyBitmapSubset(const SkBitmap& sourceBitmap, 89 SkBitmap& subset, int left, int top); 90 static bool isPureColorBitmap(const SkBitmap& bitmap, Color& pureColor); 91 static bool skipTransferForPureColor(const TileRenderInfo* renderInfo, 92 const SkBitmap& bitmap); 93 static void clearBackgroundIfOpaque(const Color* backgroundColor); 94 static bool allowGLLog(); 95 static double m_previousLogTime; 96 static int m_currentLogCounter; 97 }; 98 99 } // namespace WebCore 100 101 #endif // USE(ACCELERATED_COMPOSITING) 102 #endif // GLUtils_h 103