| OLD | NEW |
| 1 // Modified from chromium/src/webkit/glue/gl_bindings_skia_cmd_buffer.cc | 1 // Modified from chromium/src/webkit/glue/gl_bindings_skia_cmd_buffer.cc |
| 2 | 2 |
| 3 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 4 // Use of this source code is governed by a BSD-style license that can be | 4 // Use of this source code is governed by a BSD-style license that can be |
| 5 // found in the LICENSE file. | 5 // found in the LICENSE file. |
| 6 | 6 |
| 7 #include "gl/GrGLInterface.h" | 7 #include "gl/GrGLInterface.h" |
| 8 #include "gl/GrGLAssembleInterface.h" | 8 #include "gl/GrGLAssembleInterface.h" |
| 9 #include "gl/GrGLExtensions.h" | 9 #include "gl/GrGLExtensions.h" |
| 10 #include "gl/GrGLUtil.h" | 10 #include "gl/GrGLUtil.h" |
| 11 | 11 |
| 12 #ifndef GL_GLEXT_PROTOTYPES | 12 #ifndef GL_GLEXT_PROTOTYPES |
| 13 #define GL_GLEXT_PROTOTYPES | 13 #define GL_GLEXT_PROTOTYPES |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 #include <GLES2/gl2.h> | 16 #include <GLES2/gl2.h> |
| 17 #include <GLES2/gl2ext.h> | 17 #include <GLES2/gl2ext.h> |
| 18 | 18 |
| 19 #include <EGL/egl.h> | 19 #include <EGL/egl.h> |
| 20 | 20 |
| 21 static GrGLInterface* create_es_interface(GrGLVersion version, | |
| 22 GrGLExtensions* extensions) { | |
| 23 if (version < GR_GL_VER(2,0)) { | |
| 24 return NULL; | |
| 25 } | |
| 26 | 21 |
| 27 GrGLInterface* interface = SkNEW(GrGLInterface); | 22 #define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F) |
| 28 interface->fStandard = kGLES_GrGLStandard; | 23 #define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "
gl" #F #S) |
| 29 GrGLInterface::Functions* functions = &interface->fFunctions; | 24 #define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl
" #F) |
| 30 | 25 |
| 31 functions->fActiveTexture = glActiveTexture; | 26 #define GET_LINKED(F) functions->f ## F = gl ## F |
| 32 functions->fAttachShader = glAttachShader; | 27 #define GET_LINKED_SUFFIX(F, S) functions->f ## F = gl ## F ##S |
| 33 functions->fBindAttribLocation = glBindAttribLocation; | 28 #define USE_LINKED 1 |
| 34 functions->fBindBuffer = glBindBuffer; | |
| 35 functions->fBindTexture = glBindTexture; | |
| 36 functions->fBindVertexArray = glBindVertexArrayOES; | |
| 37 functions->fBlendColor = glBlendColor; | |
| 38 functions->fBlendFunc = glBlendFunc; | |
| 39 functions->fBufferData = glBufferData; | |
| 40 functions->fBufferSubData = glBufferSubData; | |
| 41 functions->fClear = glClear; | |
| 42 functions->fClearColor = glClearColor; | |
| 43 functions->fClearStencil = glClearStencil; | |
| 44 functions->fColorMask = glColorMask; | |
| 45 functions->fCompileShader = glCompileShader; | |
| 46 functions->fCompressedTexImage2D = glCompressedTexImage2D; | |
| 47 functions->fCopyTexSubImage2D = glCopyTexSubImage2D; | |
| 48 functions->fCreateProgram = glCreateProgram; | |
| 49 functions->fCreateShader = glCreateShader; | |
| 50 functions->fCullFace = glCullFace; | |
| 51 functions->fDeleteBuffers = glDeleteBuffers; | |
| 52 functions->fDeleteProgram = glDeleteProgram; | |
| 53 functions->fDeleteShader = glDeleteShader; | |
| 54 functions->fDeleteTextures = glDeleteTextures; | |
| 55 functions->fDeleteVertexArrays = glDeleteVertexArraysOES; | |
| 56 functions->fDepthMask = glDepthMask; | |
| 57 functions->fDisable = glDisable; | |
| 58 functions->fDisableVertexAttribArray = glDisableVertexAttribArray; | |
| 59 functions->fDrawArrays = glDrawArrays; | |
| 60 functions->fDrawElements = glDrawElements; | |
| 61 functions->fEnable = glEnable; | |
| 62 functions->fEnableVertexAttribArray = glEnableVertexAttribArray; | |
| 63 functions->fFinish = glFinish; | |
| 64 functions->fFlush = glFlush; | |
| 65 functions->fFrontFace = glFrontFace; | |
| 66 functions->fGenBuffers = glGenBuffers; | |
| 67 functions->fGenerateMipmap = glGenerateMipmap; | |
| 68 functions->fGenTextures = glGenTextures; | |
| 69 functions->fGenVertexArrays = glGenVertexArraysOES; | |
| 70 functions->fGetBufferParameteriv = glGetBufferParameteriv; | |
| 71 functions->fGetError = glGetError; | |
| 72 functions->fGetIntegerv = glGetIntegerv; | |
| 73 functions->fGetProgramInfoLog = glGetProgramInfoLog; | |
| 74 functions->fGetProgramiv = glGetProgramiv; | |
| 75 functions->fGetShaderInfoLog = glGetShaderInfoLog; | |
| 76 functions->fGetShaderiv = glGetShaderiv; | |
| 77 functions->fGetString = glGetString; | |
| 78 #if GL_ES_VERSION_3_0 | |
| 79 functions->fGetStringi = glGetStringi; | |
| 80 #else | |
| 81 functions->fGetStringi = (GrGLGetStringiProc) eglGetProcAddress("glGetString
i"); | |
| 82 #endif | |
| 83 functions->fGetUniformLocation = glGetUniformLocation; | |
| 84 functions->fLineWidth = glLineWidth; | |
| 85 functions->fLinkProgram = glLinkProgram; | |
| 86 functions->fPixelStorei = glPixelStorei; | |
| 87 functions->fReadPixels = glReadPixels; | |
| 88 functions->fScissor = glScissor; | |
| 89 #if GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE | |
| 90 functions->fShaderSource = (GrGLShaderSourceProc) glShaderSource; | |
| 91 #else | |
| 92 functions->fShaderSource = glShaderSource; | |
| 93 #endif | |
| 94 functions->fStencilFunc = glStencilFunc; | |
| 95 functions->fStencilFuncSeparate = glStencilFuncSeparate; | |
| 96 functions->fStencilMask = glStencilMask; | |
| 97 functions->fStencilMaskSeparate = glStencilMaskSeparate; | |
| 98 functions->fStencilOp = glStencilOp; | |
| 99 functions->fStencilOpSeparate = glStencilOpSeparate; | |
| 100 functions->fTexImage2D = glTexImage2D; | |
| 101 functions->fTexParameteri = glTexParameteri; | |
| 102 functions->fTexParameteriv = glTexParameteriv; | |
| 103 functions->fTexSubImage2D = glTexSubImage2D; | |
| 104 | 29 |
| 105 if (version >= GR_GL_VER(3,0)) { | 30 #include "gl/GrGLAssembleGLESInterface.h" |
| 106 #if GL_ES_VERSION_3_0 | |
| 107 functions->fTexStorage2D = glTexStorage2D; | |
| 108 #else | |
| 109 functions->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress("glT
exStorage2D"); | |
| 110 #endif | |
| 111 } else { | |
| 112 #if GL_EXT_texture_storage | |
| 113 functions->fTexStorage2D = glTexStorage2DEXT; | |
| 114 #else | |
| 115 functions->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress("glT
exStorage2DEXT"); | |
| 116 #endif | |
| 117 } | |
| 118 | |
| 119 #if GL_EXT_discard_framebuffer | |
| 120 functions->fDiscardFramebuffer = glDiscardFramebufferEXT; | |
| 121 #endif | |
| 122 functions->fUniform1f = glUniform1f; | |
| 123 functions->fUniform1i = glUniform1i; | |
| 124 functions->fUniform1fv = glUniform1fv; | |
| 125 functions->fUniform1iv = glUniform1iv; | |
| 126 functions->fUniform2f = glUniform2f; | |
| 127 functions->fUniform2i = glUniform2i; | |
| 128 functions->fUniform2fv = glUniform2fv; | |
| 129 functions->fUniform2iv = glUniform2iv; | |
| 130 functions->fUniform3f = glUniform3f; | |
| 131 functions->fUniform3i = glUniform3i; | |
| 132 functions->fUniform3fv = glUniform3fv; | |
| 133 functions->fUniform3iv = glUniform3iv; | |
| 134 functions->fUniform4f = glUniform4f; | |
| 135 functions->fUniform4i = glUniform4i; | |
| 136 functions->fUniform4fv = glUniform4fv; | |
| 137 functions->fUniform4iv = glUniform4iv; | |
| 138 functions->fUniformMatrix2fv = glUniformMatrix2fv; | |
| 139 functions->fUniformMatrix3fv = glUniformMatrix3fv; | |
| 140 functions->fUniformMatrix4fv = glUniformMatrix4fv; | |
| 141 functions->fUseProgram = glUseProgram; | |
| 142 functions->fVertexAttrib4fv = glVertexAttrib4fv; | |
| 143 functions->fVertexAttribPointer = glVertexAttribPointer; | |
| 144 functions->fViewport = glViewport; | |
| 145 functions->fBindFramebuffer = glBindFramebuffer; | |
| 146 functions->fBindRenderbuffer = glBindRenderbuffer; | |
| 147 functions->fCheckFramebufferStatus = glCheckFramebufferStatus; | |
| 148 functions->fDeleteFramebuffers = glDeleteFramebuffers; | |
| 149 functions->fDeleteRenderbuffers = glDeleteRenderbuffers; | |
| 150 functions->fFramebufferRenderbuffer = glFramebufferRenderbuffer; | |
| 151 functions->fFramebufferTexture2D = glFramebufferTexture2D; | |
| 152 | |
| 153 if (version >= GR_GL_VER(3,0)) { | |
| 154 #if GL_ES_VERSION_3_0 | |
| 155 functions->fRenderbufferStorageMultisample = glRenderbufferStorageMultis
ample; | |
| 156 functions->fBlitFramebuffer = glBlitFramebuffer; | |
| 157 #else | |
| 158 functions->fRenderbufferStorageMultisample = (GrGLRenderbufferStorageMul
tisampleProc) eglGetProcAddress("glRenderbufferStorageMultisample"); | |
| 159 functions->fBlitFramebuffer = (GrGLBlitFramebufferProc) eglGetProcAddres
s("glBlitFramebuffer"); | |
| 160 #endif | |
| 161 } | |
| 162 | |
| 163 if (extensions->has("GL_EXT_multisampled_render_to_texture")) { | |
| 164 #if GL_EXT_multisampled_render_to_texture | |
| 165 functions->fFramebufferTexture2DMultisample = glFramebufferTexture2DMult
isampleEXT; | |
| 166 functions->fRenderbufferStorageMultisampleES2EXT = glRenderbufferStorage
MultisampleEXT; | |
| 167 #else | |
| 168 functions->fFramebufferTexture2DMultisample = (GrGLFramebufferTexture2DM
ultisampleProc) eglGetProcAddress("glFramebufferTexture2DMultisampleEXT"); | |
| 169 functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStor
ageMultisampleProc) eglGetProcAddress("glRenderbufferStorageMultisampleEXT"); | |
| 170 #endif | |
| 171 } else if (extensions->has("GL_IMG_multisampled_render_to_texture")) { | |
| 172 #if GL_IMG_multisampled_render_to_texture | |
| 173 functions->fFramebufferTexture2DMultisample = glFramebufferTexture2DMult
isampleIMG; | |
| 174 functions->fRenderbufferStorageMultisampleES2EXT = glRenderbufferStorage
MultisampleIMG; | |
| 175 #else | |
| 176 functions->fFramebufferTexture2DMultisample = (GrGLFramebufferTexture2DM
ultisampleProc) eglGetProcAddress("glFramebufferTexture2DMultisampleIMG"); | |
| 177 functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStor
ageMultisampleProc) eglGetProcAddress("glRenderbufferStorageMultisampleIMG"); | |
| 178 #endif | |
| 179 } | |
| 180 | |
| 181 functions->fGenFramebuffers = glGenFramebuffers; | |
| 182 functions->fGenRenderbuffers = glGenRenderbuffers; | |
| 183 functions->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachment
Parameteriv; | |
| 184 functions->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv; | |
| 185 functions->fRenderbufferStorage = glRenderbufferStorage; | |
| 186 | |
| 187 #if GL_OES_mapbuffer | |
| 188 functions->fMapBuffer = glMapBufferOES; | |
| 189 functions->fUnmapBuffer = glUnmapBufferOES; | |
| 190 #else | |
| 191 functions->fMapBuffer = (GrGLMapBufferProc) eglGetProcAddress("glMapBufferOE
S"); | |
| 192 functions->fUnmapBuffer = (GrGLUnmapBufferProc) eglGetProcAddress("glUnmapBu
fferOES"); | |
| 193 | |
| 194 #endif | |
| 195 | |
| 196 if (version >= GR_GL_VER(3,0)) { | |
| 197 #if GL_ES_VERSION_3_0 | |
| 198 functions->fMapBufferRange = glMapBufferRange; | |
| 199 functions->fFlushMappedBufferRange = glFlushMappedBufferRange; | |
| 200 #else | |
| 201 functions->fMapBufferRange = (GrGLMapBufferRangeProc) eglGetProcAddress(
"glMapBufferRange"); | |
| 202 functions->fFlushMappedBufferRange = (GrGLFlushMappedBufferRangeProc) eg
lGetProcAddress("glFlushMappedBufferRange"); | |
| 203 #endif | |
| 204 } else if (extensions->has("GL_EXT_map_buffer_range")) { | |
| 205 #if GL_EXT_map_buffer_range | |
| 206 functions->fMapBufferRange = glMapBufferRangeEXT; | |
| 207 functions->fFlushMappedBufferRange = glFlushMappedBufferRangeEXT; | |
| 208 #else | |
| 209 functions->fMapBufferRange = (GrGLMapBufferRangeProc) eglGetProcAddress(
"glMapBufferRangeEXT"); | |
| 210 functions->fFlushMappedBufferRange = (GrGLFlushMappedBufferRangeProc) eg
lGetProcAddress("glFlushMappedBufferRangeEXT"); | |
| 211 #endif | |
| 212 } | |
| 213 | |
| 214 if (extensions->has("GL_EXT_debug_marker")) { | |
| 215 functions->fInsertEventMarker = (GrGLInsertEventMarkerProc) eglGetProcAd
dress("glInsertEventMarker"); | |
| 216 functions->fPushGroupMarker = (GrGLInsertEventMarkerProc) eglGetProcAddr
ess("glPushGroupMarker"); | |
| 217 functions->fPopGroupMarker = (GrGLPopGroupMarkerProc) eglGetProcAddress(
"glPopGroupMarker"); | |
| 218 // The below check is here because a device has been found that has the
extension string but | |
| 219 // returns NULL from the eglGetProcAddress for the functions | |
| 220 if (NULL == functions->fInsertEventMarker || | |
| 221 NULL == functions->fPushGroupMarker || | |
| 222 NULL == functions->fPopGroupMarker) { | |
| 223 extensions->remove("GL_EXT_debug_marker"); | |
| 224 } | |
| 225 } | |
| 226 | |
| 227 #if GL_ES_VERSION_3_0 | |
| 228 functions->fInvalidateFramebuffer = glInvalidateFramebuffer; | |
| 229 functions->fInvalidateSubFramebuffer = glInvalidateSubFramebuffer; | |
| 230 #else | |
| 231 functions->fInvalidateFramebuffer = (GrGLInvalidateFramebufferProc) eglGetPr
ocAddress("glInvalidateFramebuffer"); | |
| 232 functions->fInvalidateSubFramebuffer = (GrGLInvalidateSubFramebufferProc) eg
lGetProcAddress("glInvalidateSubFramebuffer"); | |
| 233 #endif | |
| 234 functions->fInvalidateBufferData = (GrGLInvalidateBufferDataProc) eglGetProc
Address("glInvalidateBufferData"); | |
| 235 functions->fInvalidateBufferSubData = (GrGLInvalidateBufferSubDataProc) eglG
etProcAddress("glInvalidateBufferSubData"); | |
| 236 functions->fInvalidateTexImage = (GrGLInvalidateTexImageProc) eglGetProcAddr
ess("glInvalidateTexImage"); | |
| 237 functions->fInvalidateTexSubImage = (GrGLInvalidateTexSubImageProc) eglGetPr
ocAddress("glInvalidateTexSubImage"); | |
| 238 | |
| 239 return interface; | |
| 240 } | |
| 241 | 31 |
| 242 static GrGLFuncPtr android_get_gl_proc(void* ctx, const char name[]) { | 32 static GrGLFuncPtr android_get_gl_proc(void* ctx, const char name[]) { |
| 243 SkASSERT(NULL == ctx); | 33 SkASSERT(NULL == ctx); |
| 244 return eglGetProcAddress(name); | 34 return eglGetProcAddress(name); |
| 245 } | 35 } |
| 246 | 36 |
| 247 static const GrGLInterface* create_desktop_interface() { | |
| 248 return GrGLAssembleGLInterface(NULL, android_get_gl_proc); | |
| 249 } | |
| 250 | |
| 251 const GrGLInterface* GrGLCreateNativeInterface() { | 37 const GrGLInterface* GrGLCreateNativeInterface() { |
| 252 | 38 |
| 253 const char* verStr = reinterpret_cast<const char*>(glGetString(GR_GL_VERSION
)); | 39 const char* verStr = reinterpret_cast<const char*>(glGetString(GR_GL_VERSION
)); |
| 254 GrGLStandard standard = GrGLGetStandardInUseFromString(verStr); | 40 GrGLStandard standard = GrGLGetStandardInUseFromString(verStr); |
| 255 | 41 |
| 256 if (kGLES_GrGLStandard == standard) { | 42 if (kGLES_GrGLStandard == standard) { |
| 257 GrGLVersion version = GrGLGetVersionFromString(verStr); | 43 return GrGLAssembleGLESInterface(NULL, android_get_gl_proc); |
| 258 GrGLExtensions extensions; | |
| 259 GrGLGetStringiProc getStringi = (GrGLGetStringiProc) eglGetProcAddress("
glGetStringi"); | |
| 260 if (!extensions.init(standard, glGetString, getStringi, glGetIntegerv))
{ | |
| 261 return NULL; | |
| 262 } | |
| 263 GrGLInterface* interface = create_es_interface(version, &extensions); | |
| 264 | |
| 265 if (NULL != interface) { | |
| 266 interface->fExtensions.swap(&extensions); | |
| 267 } | |
| 268 | |
| 269 return interface; | |
| 270 } else if (kGL_GrGLStandard == standard) { | 44 } else if (kGL_GrGLStandard == standard) { |
| 271 return create_desktop_interface(); | 45 return GrGLAssembleGLInterface(NULL, android_get_gl_proc); |
| 272 } | 46 } |
| 273 | 47 |
| 274 return NULL; | 48 return NULL; |
| 275 } | 49 } |
| OLD | NEW |