Home | History | Annotate | Download | only in gl
      1 /*
      2  * Copyright 2014 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 
      9 #include "gl/GrGLAssembleInterface.h"
     10 #include "GrGLUtil.h"
     11 
     12 #define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F)
     13 #define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F #S)
     14 #define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl" #F)
     15 
     16 #define GET_EGL_PROC_SUFFIX(F, S) functions->fEGL ## F = (GrEGL ## F ## Proc) get(ctx, "egl" #F #S)
     17 
     18 sk_sp<const GrGLInterface> GrGLMakeAssembledInterface(void *ctx, GrGLGetProc get) {
     19     GET_PROC_LOCAL(GetString);
     20     if (nullptr == GetString) {
     21         return nullptr;
     22     }
     23 
     24     const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION));
     25     if (nullptr == verStr) {
     26         return nullptr;
     27     }
     28 
     29     GrGLStandard standard = GrGLGetStandardInUseFromString(verStr);
     30 
     31     if (kGLES_GrGLStandard == standard) {
     32         return GrGLMakeAssembledGLESInterface(ctx, get);
     33     } else if (kGL_GrGLStandard == standard) {
     34         return GrGLMakeAssembledGLInterface(ctx, get);
     35     }
     36     return nullptr;
     37 }
     38 
     39 static void get_egl_query_and_display(GrEGLQueryStringProc* queryString, GrEGLDisplay* display,
     40                                       void* ctx, GrGLGetProc get) {
     41     *queryString = (GrEGLQueryStringProc) get(ctx, "eglQueryString");
     42     *display = GR_EGL_NO_DISPLAY;
     43     if (*queryString) {
     44         GrEGLGetCurrentDisplayProc getCurrentDisplay =
     45             (GrEGLGetCurrentDisplayProc) get(ctx, "eglGetCurrentDisplay");
     46         if (getCurrentDisplay) {
     47             *display = getCurrentDisplay();
     48         } else {
     49             *queryString = nullptr;
     50         }
     51     }
     52 }
     53 
     54 sk_sp<const GrGLInterface> GrGLMakeAssembledGLInterface(void *ctx, GrGLGetProc get) {
     55     GET_PROC_LOCAL(GetString);
     56     GET_PROC_LOCAL(GetStringi);
     57     GET_PROC_LOCAL(GetIntegerv);
     58 
     59     // GetStringi may be nullptr depending on the GL version.
     60     if (nullptr == GetString || nullptr == GetIntegerv) {
     61         return nullptr;
     62     }
     63 
     64     const char* versionString = (const char*) GetString(GR_GL_VERSION);
     65     GrGLVersion glVer = GrGLGetVersionFromString(versionString);
     66 
     67     if (glVer < GR_GL_VER(2,0) || GR_GL_INVALID_VER == glVer) {
     68         // This is our minimum for non-ES GL.
     69         return nullptr;
     70     }
     71 
     72     GrEGLQueryStringProc queryString;
     73     GrEGLDisplay display;
     74     get_egl_query_and_display(&queryString, &display, ctx, get);
     75     GrGLExtensions extensions;
     76     if (!extensions.init(kGL_GrGLStandard, GetString, GetStringi, GetIntegerv, queryString,
     77                          display)) {
     78         return nullptr;
     79     }
     80 
     81     sk_sp<GrGLInterface> interface(new GrGLInterface());
     82     GrGLInterface::Functions* functions = &interface->fFunctions;
     83 
     84     GET_PROC(ActiveTexture);
     85     GET_PROC(AttachShader);
     86     GET_PROC(BindAttribLocation);
     87     GET_PROC(BindBuffer);
     88     if (glVer >= GR_GL_VER(3,0)) {
     89         GET_PROC(BindFragDataLocation);
     90     }
     91     GET_PROC(BeginQuery);
     92     GET_PROC(BindTexture);
     93 
     94     if (extensions.has("GL_KHR_blend_equation_advanced")) {
     95         GET_PROC_SUFFIX(BlendBarrier, KHR);
     96     } else if (extensions.has("GL_NV_blend_equation_advanced")) {
     97         GET_PROC_SUFFIX(BlendBarrier, NV);
     98     }
     99 
    100     GET_PROC(BlendColor);
    101     GET_PROC(BlendEquation);
    102     GET_PROC(BlendFunc);
    103     GET_PROC(BufferData);
    104     GET_PROC(BufferSubData);
    105     GET_PROC(Clear);
    106     GET_PROC(ClearColor);
    107     GET_PROC(ClearStencil);
    108     if (glVer >= GR_GL_VER(4,4) || extensions.has("GL_ARB_clear_texture")) {
    109         GET_PROC(ClearTexImage);
    110         GET_PROC(ClearTexSubImage);
    111     }
    112     GET_PROC(ColorMask);
    113     GET_PROC(CompileShader);
    114     GET_PROC(CompressedTexImage2D);
    115     GET_PROC(CompressedTexSubImage2D);
    116     GET_PROC(CopyTexSubImage2D);
    117     GET_PROC(CreateProgram);
    118     GET_PROC(CreateShader);
    119     GET_PROC(CullFace);
    120     GET_PROC(DeleteBuffers);
    121     GET_PROC(DeleteProgram);
    122     GET_PROC(DeleteQueries);
    123     GET_PROC(DeleteShader);
    124     GET_PROC(DeleteTextures);
    125     GET_PROC(DepthMask);
    126     GET_PROC(Disable);
    127     GET_PROC(DisableVertexAttribArray);
    128     GET_PROC(DrawArrays);
    129     GET_PROC(DrawBuffer);
    130     GET_PROC(DrawBuffers);
    131     GET_PROC(DrawElements);
    132 
    133     if (glVer >= GR_GL_VER(3,1) || extensions.has("GL_ARB_draw_instanced") ||
    134         extensions.has("GL_EXT_draw_instanced")) {
    135         GET_PROC(DrawArraysInstanced);
    136         GET_PROC(DrawElementsInstanced);
    137     }
    138 
    139     if (glVer >= GR_GL_VER(4,0) || extensions.has("GL_ARB_draw_indirect")) {
    140         GET_PROC(DrawArraysIndirect);
    141         GET_PROC(DrawElementsIndirect);
    142     }
    143     GET_PROC(DrawRangeElements);
    144     GET_PROC(Enable);
    145     GET_PROC(EnableVertexAttribArray);
    146     GET_PROC(EndQuery);
    147     GET_PROC(Finish);
    148     GET_PROC(Flush);
    149     GET_PROC(FrontFace);
    150     GET_PROC(GenBuffers);
    151     GET_PROC(GetBufferParameteriv);
    152     GET_PROC(GetError);
    153     GET_PROC(GetIntegerv);
    154     if (glVer >= GR_GL_VER(3,2) || extensions.has("GL_ARB_texture_multisample")) {
    155         GET_PROC(GetMultisamplefv);
    156     }
    157     GET_PROC(GetQueryObjectiv);
    158     GET_PROC(GetQueryObjectuiv);
    159     if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
    160         GET_PROC(GetQueryObjecti64v);
    161         GET_PROC(GetQueryObjectui64v);
    162         GET_PROC(QueryCounter);
    163     } else if (extensions.has("GL_EXT_timer_query")) {
    164         GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
    165         GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
    166     }
    167     GET_PROC(GetQueryiv);
    168     GET_PROC(GetProgramInfoLog);
    169     GET_PROC(GetProgramiv);
    170     GET_PROC(GetShaderInfoLog);
    171     GET_PROC(GetShaderiv);
    172     GET_PROC(GetString);
    173     GET_PROC(GetStringi);
    174     GET_PROC(GetShaderPrecisionFormat);
    175     GET_PROC(GetTexLevelParameteriv);
    176     GET_PROC(GenQueries);
    177     GET_PROC(GenTextures);
    178     GET_PROC(GetUniformLocation);
    179     GET_PROC(IsTexture);
    180     GET_PROC(LineWidth);
    181     GET_PROC(LinkProgram);
    182     GET_PROC(MapBuffer);
    183 
    184     if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_multi_draw_indirect")) {
    185         GET_PROC(MultiDrawArraysIndirect);
    186         GET_PROC(MultiDrawElementsIndirect);
    187     }
    188 
    189     GET_PROC(PixelStorei);
    190     GET_PROC(PolygonMode);
    191     if (extensions.has("GL_EXT_raster_multisample")) {
    192         GET_PROC_SUFFIX(RasterSamples, EXT);
    193     }
    194     GET_PROC(ReadBuffer);
    195     GET_PROC(ReadPixels);
    196     GET_PROC(Scissor);
    197     GET_PROC(ShaderSource);
    198     GET_PROC(StencilFunc);
    199     GET_PROC(StencilFuncSeparate);
    200     GET_PROC(StencilMask);
    201     GET_PROC(StencilMaskSeparate);
    202     GET_PROC(StencilOp);
    203     GET_PROC(StencilOpSeparate);
    204     if (glVer >= GR_GL_VER(3,1)) {
    205         GET_PROC(TexBuffer);
    206     }
    207     if (glVer >= GR_GL_VER(4,3)) {
    208         GET_PROC(TexBufferRange);
    209     }
    210     GET_PROC(TexImage2D);
    211     GET_PROC(TexParameteri);
    212     GET_PROC(TexParameteriv);
    213     if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) {
    214         GET_PROC(TexStorage2D);
    215     } else if (extensions.has("GL_EXT_texture_storage")) {
    216         GET_PROC_SUFFIX(TexStorage2D, EXT);
    217     }
    218     GET_PROC(TexSubImage2D);
    219     if (glVer >= GR_GL_VER(4,5) || extensions.has("GL_ARB_texture_barrier")) {
    220         GET_PROC(TextureBarrier);
    221     } else if (extensions.has("GL_NV_texture_barrier")) {
    222         GET_PROC_SUFFIX(TextureBarrier, NV);
    223     }
    224     GET_PROC(Uniform1f);
    225     GET_PROC(Uniform1i);
    226     GET_PROC(Uniform1fv);
    227     GET_PROC(Uniform1iv);
    228     GET_PROC(Uniform2f);
    229     GET_PROC(Uniform2i);
    230     GET_PROC(Uniform2fv);
    231     GET_PROC(Uniform2iv);
    232     GET_PROC(Uniform3f);
    233     GET_PROC(Uniform3i);
    234     GET_PROC(Uniform3fv);
    235     GET_PROC(Uniform3iv);
    236     GET_PROC(Uniform4f);
    237     GET_PROC(Uniform4i);
    238     GET_PROC(Uniform4fv);
    239     GET_PROC(Uniform4iv);
    240     GET_PROC(UniformMatrix2fv);
    241     GET_PROC(UniformMatrix3fv);
    242     GET_PROC(UniformMatrix4fv);
    243     GET_PROC(UnmapBuffer);
    244     GET_PROC(UseProgram);
    245     GET_PROC(VertexAttrib1f);
    246     GET_PROC(VertexAttrib2fv);
    247     GET_PROC(VertexAttrib3fv);
    248     GET_PROC(VertexAttrib4fv);
    249 
    250     if (glVer >= GR_GL_VER(3,2) || extensions.has("GL_ARB_instanced_arrays")) {
    251         GET_PROC(VertexAttribDivisor);
    252     }
    253 
    254     if (glVer >= GR_GL_VER(3,0)) {
    255         GET_PROC(VertexAttribIPointer);
    256     }
    257 
    258     GET_PROC(VertexAttribPointer);
    259     GET_PROC(Viewport);
    260     GET_PROC(BindFragDataLocationIndexed);
    261 
    262     if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) {
    263         // no ARB suffix for GL_ARB_vertex_array_object
    264         GET_PROC(BindVertexArray);
    265         GET_PROC(GenVertexArrays);
    266         GET_PROC(DeleteVertexArrays);
    267     } else if (extensions.has("GL_APPLE_vertex_array_object")) {
    268         GET_PROC_SUFFIX(BindVertexArray, APPLE);
    269         GET_PROC_SUFFIX(GenVertexArrays, APPLE);
    270         GET_PROC_SUFFIX(DeleteVertexArrays, APPLE);
    271     }
    272 
    273     if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_map_buffer_range")) {
    274         GET_PROC(MapBufferRange);
    275         GET_PROC(FlushMappedBufferRange);
    276     }
    277 
    278     // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
    279     // GL_ARB_framebuffer_object doesn't use ARB suffix.)
    280     if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
    281         GET_PROC(GenerateMipmap);
    282         GET_PROC(GenFramebuffers);
    283         GET_PROC(GetFramebufferAttachmentParameteriv);
    284         GET_PROC(GetRenderbufferParameteriv);
    285         GET_PROC(BindFramebuffer);
    286         GET_PROC(FramebufferTexture2D);
    287         GET_PROC(CheckFramebufferStatus);
    288         GET_PROC(DeleteFramebuffers);
    289         GET_PROC(RenderbufferStorage);
    290         GET_PROC(GenRenderbuffers);
    291         GET_PROC(DeleteRenderbuffers);
    292         GET_PROC(FramebufferRenderbuffer);
    293         GET_PROC(BindRenderbuffer);
    294         GET_PROC(RenderbufferStorageMultisample);
    295         GET_PROC(BlitFramebuffer);
    296     } else if (extensions.has("GL_EXT_framebuffer_object")) {
    297         GET_PROC_SUFFIX(GenerateMipmap, EXT);
    298         GET_PROC_SUFFIX(GenFramebuffers, EXT);
    299         GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
    300         GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
    301         GET_PROC_SUFFIX(BindFramebuffer, EXT);
    302         GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
    303         GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
    304         GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
    305         GET_PROC_SUFFIX(RenderbufferStorage, EXT);
    306         GET_PROC_SUFFIX(GenRenderbuffers, EXT);
    307         GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
    308         GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
    309         GET_PROC_SUFFIX(BindRenderbuffer, EXT);
    310         if (extensions.has("GL_EXT_framebuffer_multisample")) {
    311             GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
    312         }
    313         if (extensions.has("GL_EXT_framebuffer_blit")) {
    314             GET_PROC_SUFFIX(BlitFramebuffer, EXT);
    315         }
    316     } else {
    317         // we must have FBOs
    318         return nullptr;
    319     }
    320 
    321     if (extensions.has("GL_NV_path_rendering")) {
    322         GET_PROC_SUFFIX(MatrixLoadf, EXT);
    323         GET_PROC_SUFFIX(MatrixLoadIdentity, EXT);
    324         GET_PROC_SUFFIX(PathCommands, NV);
    325         GET_PROC_SUFFIX(PathParameteri, NV);
    326         GET_PROC_SUFFIX(PathParameterf, NV);
    327         GET_PROC_SUFFIX(GenPaths, NV);
    328         GET_PROC_SUFFIX(DeletePaths, NV);
    329         GET_PROC_SUFFIX(IsPath, NV);
    330         GET_PROC_SUFFIX(PathStencilFunc, NV);
    331         GET_PROC_SUFFIX(StencilFillPath, NV);
    332         GET_PROC_SUFFIX(StencilStrokePath, NV);
    333         GET_PROC_SUFFIX(StencilFillPathInstanced, NV);
    334         GET_PROC_SUFFIX(StencilStrokePathInstanced, NV);
    335         GET_PROC_SUFFIX(CoverFillPath, NV);
    336         GET_PROC_SUFFIX(CoverStrokePath, NV);
    337         GET_PROC_SUFFIX(CoverFillPathInstanced, NV);
    338         GET_PROC_SUFFIX(CoverStrokePathInstanced, NV);
    339         GET_PROC_SUFFIX(StencilThenCoverFillPath, NV);
    340         GET_PROC_SUFFIX(StencilThenCoverStrokePath, NV);
    341         GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, NV);
    342         GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, NV);
    343         GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV);
    344     }
    345 
    346     if (extensions.has("GL_NV_framebuffer_mixed_samples")) {
    347         GET_PROC_SUFFIX(CoverageModulation, NV);
    348     }
    349 
    350     if (extensions.has("GL_EXT_debug_marker")) {
    351         GET_PROC_SUFFIX(InsertEventMarker, EXT);
    352         GET_PROC_SUFFIX(PushGroupMarker, EXT);
    353         GET_PROC_SUFFIX(PopGroupMarker, EXT);
    354     }
    355 
    356     if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_invalidate_subdata")) {
    357         GET_PROC(InvalidateBufferData);
    358         GET_PROC(InvalidateBufferSubData);
    359         GET_PROC(InvalidateFramebuffer);
    360         GET_PROC(InvalidateSubFramebuffer);
    361         GET_PROC(InvalidateTexImage);
    362         GET_PROC(InvalidateTexSubImage);
    363     }
    364 
    365     if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_program_interface_query")) {
    366         GET_PROC(GetProgramResourceLocation);
    367     }
    368 
    369     if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_KHR_debug")) {
    370         // KHR_debug defines these methods to have no suffix in an OpenGL (not ES) context.
    371         GET_PROC(DebugMessageControl);
    372         GET_PROC(DebugMessageInsert);
    373         GET_PROC(DebugMessageCallback);
    374         GET_PROC(GetDebugMessageLog);
    375         GET_PROC(PushDebugGroup);
    376         GET_PROC(PopDebugGroup);
    377         GET_PROC(ObjectLabel);
    378     }
    379 
    380     if (extensions.has("GL_EXT_window_rectangles")) {
    381         GET_PROC_SUFFIX(WindowRectangles, EXT);
    382     }
    383 
    384     if (extensions.has("EGL_KHR_image") || extensions.has("EGL_KHR_image_base")) {
    385         GET_EGL_PROC_SUFFIX(CreateImage, KHR);
    386         GET_EGL_PROC_SUFFIX(DestroyImage, KHR);
    387     }
    388 
    389     if (glVer >= GR_GL_VER(4, 0) || extensions.has("GL_ARB_sample_shading")) {
    390         GET_PROC(MinSampleShading);
    391     }
    392 
    393     if (glVer >= GR_GL_VER(3, 2) || extensions.has("GL_ARB_sync")) {
    394         GET_PROC(FenceSync);
    395         GET_PROC(IsSync);
    396         GET_PROC(ClientWaitSync);
    397         GET_PROC(WaitSync);
    398         GET_PROC(DeleteSync);
    399     }
    400 
    401     if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_internalformat_query")) {
    402         GET_PROC(GetInternalformativ);
    403     }
    404 
    405     if (glVer >= GR_GL_VER(4, 1)) {
    406         GET_PROC(GetProgramBinary);
    407         GET_PROC(ProgramBinary);
    408         GET_PROC(ProgramParameteri);
    409     }
    410 
    411     interface->fStandard = kGL_GrGLStandard;
    412     interface->fExtensions.swap(&extensions);
    413 
    414     return interface;
    415 }
    416 
    417 sk_sp<const GrGLInterface> GrGLMakeAssembledGLESInterface(void *ctx, GrGLGetProc get) {
    418     GET_PROC_LOCAL(GetString);
    419     if (nullptr == GetString) {
    420         return nullptr;
    421     }
    422 
    423     const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION));
    424     GrGLVersion version = GrGLGetVersionFromString(verStr);
    425 
    426     if (version < GR_GL_VER(2,0)) {
    427         return nullptr;
    428     }
    429 
    430     GET_PROC_LOCAL(GetIntegerv);
    431     GET_PROC_LOCAL(GetStringi);
    432     GrEGLQueryStringProc queryString;
    433     GrEGLDisplay display;
    434     get_egl_query_and_display(&queryString, &display, ctx, get);
    435     GrGLExtensions extensions;
    436     if (!extensions.init(kGLES_GrGLStandard, GetString, GetStringi, GetIntegerv, queryString,
    437                          display)) {
    438         return nullptr;
    439     }
    440 
    441     sk_sp<GrGLInterface> interface(new GrGLInterface);
    442     GrGLInterface::Functions* functions = &interface->fFunctions;
    443 
    444     GET_PROC(ActiveTexture);
    445     GET_PROC(AttachShader);
    446     GET_PROC(BindAttribLocation);
    447     GET_PROC(BindBuffer);
    448     GET_PROC(BindTexture);
    449     GET_PROC_SUFFIX(BindVertexArray, OES);
    450 
    451     if (version >= GR_GL_VER(3,0) && extensions.has("GL_EXT_blend_func_extended")) {
    452         GET_PROC_SUFFIX(BindFragDataLocation, EXT);
    453         GET_PROC_SUFFIX(BindFragDataLocationIndexed, EXT);
    454     }
    455 
    456     if (extensions.has("GL_KHR_blend_equation_advanced")) {
    457         GET_PROC_SUFFIX(BlendBarrier, KHR);
    458     } else if (extensions.has("GL_NV_blend_equation_advanced")) {
    459         GET_PROC_SUFFIX(BlendBarrier, NV);
    460     }
    461 
    462     GET_PROC(BlendColor);
    463     GET_PROC(BlendEquation);
    464     GET_PROC(BlendFunc);
    465     GET_PROC(BufferData);
    466     GET_PROC(BufferSubData);
    467     GET_PROC(Clear);
    468     GET_PROC(ClearColor);
    469     GET_PROC(ClearStencil);
    470     if (extensions.has("GL_EXT_clear_texture")) {
    471         GET_PROC_SUFFIX(ClearTexImage, EXT);
    472         GET_PROC_SUFFIX(ClearTexSubImage, EXT);
    473     }
    474     GET_PROC(ColorMask);
    475     GET_PROC(CompileShader);
    476     GET_PROC(CompressedTexImage2D);
    477     GET_PROC(CompressedTexSubImage2D);
    478     GET_PROC(CopyTexSubImage2D);
    479     GET_PROC(CreateProgram);
    480     GET_PROC(CreateShader);
    481     GET_PROC(CullFace);
    482     GET_PROC(DeleteBuffers);
    483     GET_PROC(DeleteProgram);
    484     GET_PROC(DeleteShader);
    485     GET_PROC(DeleteTextures);
    486     GET_PROC_SUFFIX(DeleteVertexArrays, OES);
    487     GET_PROC(DepthMask);
    488     GET_PROC(Disable);
    489     GET_PROC(DisableVertexAttribArray);
    490     GET_PROC(DrawArrays);
    491 
    492     if (version >= GR_GL_VER(3,0)) {
    493         GET_PROC(DrawArraysInstanced);
    494         GET_PROC(DrawBuffers);
    495         GET_PROC(DrawElementsInstanced);
    496     } else if (extensions.has("GL_EXT_draw_instanced")) {
    497         GET_PROC_SUFFIX(DrawArraysInstanced, EXT);
    498         GET_PROC_SUFFIX(DrawElementsInstanced, EXT);
    499     }
    500 
    501     if (version >= GR_GL_VER(3,1)) {
    502         GET_PROC(DrawArraysIndirect);
    503         GET_PROC(DrawElementsIndirect);
    504     }
    505 
    506     GET_PROC(DrawElements);
    507     if (version >= GR_GL_VER(3,0)) {
    508         GET_PROC(DrawRangeElements);
    509     }
    510     GET_PROC(Enable);
    511     GET_PROC(EnableVertexAttribArray);
    512     GET_PROC(Finish);
    513     GET_PROC(Flush);
    514     GET_PROC(FrontFace);
    515     GET_PROC(GenBuffers);
    516     GET_PROC(GenerateMipmap);
    517     GET_PROC(GenTextures);
    518     GET_PROC_SUFFIX(GenVertexArrays, OES);
    519     GET_PROC(GetBufferParameteriv);
    520     GET_PROC(GetError);
    521     GET_PROC(GetIntegerv);
    522 
    523     if (version >= GR_GL_VER(3,1)) {
    524         GET_PROC(GetMultisamplefv);
    525     }
    526 
    527     GET_PROC(GetProgramInfoLog);
    528     GET_PROC(GetProgramiv);
    529     GET_PROC(GetShaderInfoLog);
    530     GET_PROC(GetShaderPrecisionFormat);
    531     GET_PROC(GetShaderiv);
    532     GET_PROC(GetString);
    533     GET_PROC(GetStringi);
    534     if (version >= GR_GL_VER(3,1)) {
    535         GET_PROC(GetTexLevelParameteriv);
    536     }
    537     GET_PROC(GetUniformLocation);
    538     GET_PROC(IsTexture);
    539     GET_PROC(LineWidth);
    540     GET_PROC(LinkProgram);
    541 
    542     if (extensions.has("GL_EXT_multi_draw_indirect")) {
    543         GET_PROC_SUFFIX(MultiDrawArraysIndirect, EXT);
    544         GET_PROC_SUFFIX(MultiDrawElementsIndirect, EXT);
    545     }
    546 
    547     GET_PROC(PixelStorei);
    548 
    549     if (extensions.has("GL_EXT_raster_multisample")) {
    550         GET_PROC_SUFFIX(RasterSamples, EXT);
    551     }
    552 
    553     if (version >= GR_GL_VER(3,0)) {
    554         GET_PROC(ReadBuffer);
    555     }
    556     GET_PROC(ReadPixels);
    557     GET_PROC(Scissor);
    558     GET_PROC(ShaderSource);
    559     GET_PROC(StencilFunc);
    560     GET_PROC(StencilFuncSeparate);
    561     GET_PROC(StencilMask);
    562     GET_PROC(StencilMaskSeparate);
    563     GET_PROC(StencilOp);
    564     GET_PROC(StencilOpSeparate);
    565 
    566     if (version >= GR_GL_VER(3,2)) {
    567         GET_PROC(TexBuffer);
    568         GET_PROC(TexBufferRange);
    569     } else if (extensions.has("GL_OES_texture_buffer")) {
    570         GET_PROC_SUFFIX(TexBuffer, OES);
    571         GET_PROC_SUFFIX(TexBufferRange, OES);
    572     } else if (extensions.has("GL_EXT_texture_buffer")) {
    573         GET_PROC_SUFFIX(TexBuffer, EXT);
    574         GET_PROC_SUFFIX(TexBufferRange, EXT);
    575     }
    576 
    577     GET_PROC(TexImage2D);
    578     GET_PROC(TexParameteri);
    579     GET_PROC(TexParameteriv);
    580     GET_PROC(TexSubImage2D);
    581 
    582     if (version >= GR_GL_VER(3,0)) {
    583         GET_PROC(TexStorage2D);
    584     } else {
    585         GET_PROC_SUFFIX(TexStorage2D, EXT);
    586     }
    587 
    588     if (extensions.has("GL_NV_texture_barrier")) {
    589         GET_PROC_SUFFIX(TextureBarrier, NV);
    590     }
    591 
    592     GET_PROC_SUFFIX(DiscardFramebuffer, EXT);
    593     GET_PROC(Uniform1f);
    594     GET_PROC(Uniform1i);
    595     GET_PROC(Uniform1fv);
    596     GET_PROC(Uniform1iv);
    597     GET_PROC(Uniform2f);
    598     GET_PROC(Uniform2i);
    599     GET_PROC(Uniform2fv);
    600     GET_PROC(Uniform2iv);
    601     GET_PROC(Uniform3f);
    602     GET_PROC(Uniform3i);
    603     GET_PROC(Uniform3fv);
    604     GET_PROC(Uniform3iv);
    605     GET_PROC(Uniform4f);
    606     GET_PROC(Uniform4i);
    607     GET_PROC(Uniform4fv);
    608     GET_PROC(Uniform4iv);
    609     GET_PROC(UniformMatrix2fv);
    610     GET_PROC(UniformMatrix3fv);
    611     GET_PROC(UniformMatrix4fv);
    612     GET_PROC(UseProgram);
    613     GET_PROC(VertexAttrib1f);
    614     GET_PROC(VertexAttrib2fv);
    615     GET_PROC(VertexAttrib3fv);
    616     GET_PROC(VertexAttrib4fv);
    617 
    618     if (version >= GR_GL_VER(3,0)) {
    619         GET_PROC(VertexAttribDivisor);
    620     } else if (extensions.has("GL_EXT_instanced_arrays")) {
    621         GET_PROC_SUFFIX(VertexAttribDivisor, EXT);
    622     }
    623 
    624     if (version >= GR_GL_VER(3,0)) {
    625         GET_PROC(VertexAttribIPointer);
    626     }
    627 
    628     GET_PROC(VertexAttribPointer);
    629     GET_PROC(Viewport);
    630     GET_PROC(BindFramebuffer);
    631     GET_PROC(BindRenderbuffer);
    632     GET_PROC(CheckFramebufferStatus);
    633     GET_PROC(DeleteFramebuffers);
    634     GET_PROC(DeleteRenderbuffers);
    635     GET_PROC(FramebufferRenderbuffer);
    636     GET_PROC(FramebufferTexture2D);
    637 
    638     if (version >= GR_GL_VER(3,0)) {
    639         GET_PROC(RenderbufferStorageMultisample);
    640         GET_PROC(BlitFramebuffer);
    641     } else if (extensions.has("GL_CHROMIUM_framebuffer_multisample")) {
    642         GET_PROC_SUFFIX(RenderbufferStorageMultisample, CHROMIUM);
    643         GET_PROC_SUFFIX(BlitFramebuffer, CHROMIUM);
    644     } else {
    645         if (extensions.has("GL_ANGLE_framebuffer_multisample")) {
    646             GET_PROC_SUFFIX(RenderbufferStorageMultisample, ANGLE);
    647         }
    648         if (extensions.has("GL_ANGLE_framebuffer_blit")) {
    649             GET_PROC_SUFFIX(BlitFramebuffer, ANGLE);
    650         }
    651     }
    652 
    653     if (extensions.has("GL_CHROMIUM_map_sub")) {
    654         GET_PROC_SUFFIX(MapBufferSubData, CHROMIUM);
    655         GET_PROC_SUFFIX(MapTexSubImage2D, CHROMIUM);
    656         GET_PROC_SUFFIX(UnmapBufferSubData, CHROMIUM);
    657         GET_PROC_SUFFIX(UnmapTexSubImage2D, CHROMIUM);
    658     }
    659 
    660     if (extensions.has("GL_EXT_multisampled_render_to_texture")) {
    661         GET_PROC_SUFFIX(FramebufferTexture2DMultisample, EXT);
    662         functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleEXT");
    663     } else if (extensions.has("GL_IMG_multisampled_render_to_texture")) {
    664         GET_PROC_SUFFIX(FramebufferTexture2DMultisample, IMG);
    665         functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleIMG");
    666     } else if (extensions.has("GL_APPLE_framebuffer_multisample")) {
    667         functions->fRenderbufferStorageMultisampleES2APPLE = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleAPPLE");
    668         GET_PROC_SUFFIX(ResolveMultisampleFramebuffer, APPLE);
    669     }
    670 
    671     GET_PROC(GenFramebuffers);
    672     GET_PROC(GenRenderbuffers);
    673     GET_PROC(GetFramebufferAttachmentParameteriv);
    674     GET_PROC(GetRenderbufferParameteriv);
    675     GET_PROC(RenderbufferStorage);
    676 
    677     // There are several APIs for buffer mapping:
    678     // ES2 + GL_OES_mapbuffer: MapBufferOES and UnmapBufferOES
    679     // ES2 + GL_EXT_map_buffer_range: Adds MapBufferRangeEXT and FlushMappedBufferRangeEXT
    680     // ES3: MapBufferRange, FlushMappedBufferRange, and UnmapBuffer are core (so no suffix).
    681     //
    682     // MapBuffer is not part of ES3, but implementations may still report the OES versions of
    683     // MapBuffer and UnmapBuffer, per the older GL_OES_mapbuffer extension. Some implementations
    684     // let us mix the newer MapBufferRange with the older UnmapBufferOES, but we've hit others that
    685     // don't permit it. Note that in GrGLBuffer, we choose which API to use based on version and
    686     // extensions. This code is written so that we never mix OES and non-OES functions.
    687     GET_PROC_SUFFIX(MapBuffer, OES);
    688     if (version >= GR_GL_VER(3, 0)) {
    689         GET_PROC(UnmapBuffer);
    690     } else {
    691         GET_PROC_SUFFIX(UnmapBuffer, OES);
    692     }
    693 
    694     if (version >= GR_GL_VER(3,0)) {
    695         GET_PROC(MapBufferRange);
    696         GET_PROC(FlushMappedBufferRange);
    697     } else if (extensions.has("GL_EXT_map_buffer_range")) {
    698         GET_PROC_SUFFIX(MapBufferRange, EXT);
    699         GET_PROC_SUFFIX(FlushMappedBufferRange, EXT);
    700     }
    701 
    702     if (extensions.has("GL_EXT_debug_marker")) {
    703         GET_PROC_SUFFIX(InsertEventMarker, EXT);
    704         GET_PROC_SUFFIX(PushGroupMarker, EXT);
    705         GET_PROC_SUFFIX(PopGroupMarker, EXT);
    706     }
    707 
    708     GET_PROC(InvalidateFramebuffer);
    709     GET_PROC(InvalidateSubFramebuffer);
    710     GET_PROC(InvalidateBufferData);
    711     GET_PROC(InvalidateBufferSubData);
    712     GET_PROC(InvalidateTexImage);
    713     GET_PROC(InvalidateTexSubImage);
    714 
    715     if (version >= GR_GL_VER(3,1)) {
    716         GET_PROC(GetProgramResourceLocation);
    717     }
    718 
    719     if (extensions.has("GL_NV_path_rendering")) {
    720         GET_PROC_SUFFIX(MatrixLoadf, EXT);
    721         GET_PROC_SUFFIX(MatrixLoadIdentity, EXT);
    722         GET_PROC_SUFFIX(PathCommands, NV);
    723         GET_PROC_SUFFIX(PathParameteri, NV);
    724         GET_PROC_SUFFIX(PathParameterf, NV);
    725         GET_PROC_SUFFIX(GenPaths, NV);
    726         GET_PROC_SUFFIX(DeletePaths, NV);
    727         GET_PROC_SUFFIX(IsPath, NV);
    728         GET_PROC_SUFFIX(PathStencilFunc, NV);
    729         GET_PROC_SUFFIX(StencilFillPath, NV);
    730         GET_PROC_SUFFIX(StencilStrokePath, NV);
    731         GET_PROC_SUFFIX(StencilFillPathInstanced, NV);
    732         GET_PROC_SUFFIX(StencilStrokePathInstanced, NV);
    733         GET_PROC_SUFFIX(CoverFillPath, NV);
    734         GET_PROC_SUFFIX(CoverStrokePath, NV);
    735         GET_PROC_SUFFIX(CoverFillPathInstanced, NV);
    736         GET_PROC_SUFFIX(CoverStrokePathInstanced, NV);
    737         GET_PROC_SUFFIX(StencilThenCoverFillPath, NV);
    738         GET_PROC_SUFFIX(StencilThenCoverStrokePath, NV);
    739         GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, NV);
    740         GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, NV);
    741         GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV);
    742     }
    743 
    744     if (extensions.has("GL_CHROMIUM_path_rendering")) {
    745         GET_PROC_SUFFIX(MatrixLoadf, CHROMIUM);
    746         GET_PROC_SUFFIX(MatrixLoadIdentity, CHROMIUM);
    747         GET_PROC_SUFFIX(PathCommands, CHROMIUM);
    748         GET_PROC_SUFFIX(PathParameteri, CHROMIUM);
    749         GET_PROC_SUFFIX(PathParameterf, CHROMIUM);
    750         GET_PROC_SUFFIX(GenPaths, CHROMIUM);
    751         GET_PROC_SUFFIX(DeletePaths, CHROMIUM);
    752         GET_PROC_SUFFIX(IsPath, CHROMIUM);
    753         GET_PROC_SUFFIX(PathStencilFunc, CHROMIUM);
    754         GET_PROC_SUFFIX(StencilFillPath, CHROMIUM);
    755         GET_PROC_SUFFIX(StencilStrokePath, CHROMIUM);
    756         GET_PROC_SUFFIX(StencilFillPathInstanced, CHROMIUM);
    757         GET_PROC_SUFFIX(StencilStrokePathInstanced, CHROMIUM);
    758         GET_PROC_SUFFIX(CoverFillPath, CHROMIUM);
    759         GET_PROC_SUFFIX(CoverStrokePath, CHROMIUM);
    760         GET_PROC_SUFFIX(CoverFillPathInstanced, CHROMIUM);
    761         GET_PROC_SUFFIX(CoverStrokePathInstanced, CHROMIUM);
    762         GET_PROC_SUFFIX(StencilThenCoverFillPath, CHROMIUM);
    763         GET_PROC_SUFFIX(StencilThenCoverStrokePath, CHROMIUM);
    764         GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, CHROMIUM);
    765         GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, CHROMIUM);
    766         GET_PROC_SUFFIX(ProgramPathFragmentInputGen, CHROMIUM);
    767         // GL_CHROMIUM_path_rendering additions:
    768         GET_PROC_SUFFIX(BindFragmentInputLocation, CHROMIUM);
    769     }
    770 
    771     if (extensions.has("GL_NV_framebuffer_mixed_samples")) {
    772         GET_PROC_SUFFIX(CoverageModulation, NV);
    773     }
    774     if (extensions.has("GL_CHROMIUM_framebuffer_mixed_samples")) {
    775         GET_PROC_SUFFIX(CoverageModulation, CHROMIUM);
    776     }
    777 
    778     if (extensions.has("GL_KHR_debug")) {
    779         GET_PROC_SUFFIX(DebugMessageControl, KHR);
    780         GET_PROC_SUFFIX(DebugMessageInsert, KHR);
    781         GET_PROC_SUFFIX(DebugMessageCallback, KHR);
    782         GET_PROC_SUFFIX(GetDebugMessageLog, KHR);
    783         GET_PROC_SUFFIX(PushDebugGroup, KHR);
    784         GET_PROC_SUFFIX(PopDebugGroup, KHR);
    785         GET_PROC_SUFFIX(ObjectLabel, KHR);
    786         // In general we have a policy against removing extension strings when the driver does
    787         // not provide function pointers for an advertised extension. However, because there is a
    788         // known device that advertises GL_KHR_debug but fails to provide the functions and this is
    789         // a debugging- only extension we've made an exception. This also can happen when using
    790         // APITRACE.
    791         if (!interface->fFunctions.fDebugMessageControl) {
    792             extensions.remove("GL_KHR_debug");
    793         }
    794     }
    795 
    796     if (extensions.has("GL_CHROMIUM_bind_uniform_location")) {
    797         GET_PROC_SUFFIX(BindUniformLocation, CHROMIUM);
    798     }
    799 
    800     if (extensions.has("GL_EXT_window_rectangles")) {
    801         GET_PROC_SUFFIX(WindowRectangles, EXT);
    802     }
    803 
    804     if (extensions.has("EGL_KHR_image") || extensions.has("EGL_KHR_image_base")) {
    805         GET_EGL_PROC_SUFFIX(CreateImage, KHR);
    806         GET_EGL_PROC_SUFFIX(DestroyImage, KHR);
    807     }
    808 
    809     if (extensions.has("GL_OES_sample_shading")) {
    810         GET_PROC_SUFFIX(MinSampleShading, OES);
    811     }
    812 
    813     if (version >= GR_GL_VER(3, 0)) {
    814         GET_PROC(FenceSync);
    815         GET_PROC(IsSync);
    816         GET_PROC(ClientWaitSync);
    817         GET_PROC(WaitSync);
    818         GET_PROC(DeleteSync);
    819     } else if (extensions.has("GL_APPLE_sync")) {
    820         GET_PROC_SUFFIX(FenceSync, APPLE);
    821         GET_PROC_SUFFIX(IsSync, APPLE);
    822         GET_PROC_SUFFIX(ClientWaitSync, APPLE);
    823         GET_PROC_SUFFIX(WaitSync, APPLE);
    824         GET_PROC_SUFFIX(DeleteSync, APPLE);
    825     }
    826 
    827     if (version >= GR_GL_VER(3,0)) {
    828         GET_PROC(GetInternalformativ);
    829     }
    830 
    831     if (version >= GR_GL_VER(3, 0)) {
    832         GET_PROC(GetProgramBinary);
    833         GET_PROC(ProgramBinary);
    834         GET_PROC(ProgramParameteri);
    835     }
    836 
    837     interface->fStandard = kGLES_GrGLStandard;
    838     interface->fExtensions.swap(&extensions);
    839 
    840     return interface;
    841 }
    842 
    843 SK_API const GrGLInterface* GrGLAssembleInterface(void *ctx, GrGLGetProc get) {
    844     return GrGLMakeAssembledInterface(ctx, get).release();
    845 }
    846