GrGLCreateNullInterface.cpp revision 91bcc94e8710c1ec5126a31cd805a6c64bb3c39d
1
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#include "gl/GrGLInterface.h"
11#include "../GrTDArray.h"
12#include "GrGLDefines.h"
13
14GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {}
15GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shader) {}
16GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {}
17GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint index, const char* name) {}
18GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture) {}
19GrGLvoid GR_GL_FUNCTION_TYPE nullGLBlendColor(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha) {}
20GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindFragDataLocation(GrGLuint program, GrGLuint colorNumber, const GrGLchar* name) {}
21GrGLvoid GR_GL_FUNCTION_TYPE nullGLBlendFunc(GrGLenum sfactor, GrGLenum dfactor) {}
22GrGLvoid GR_GL_FUNCTION_TYPE nullGLBlendEquation(GrGLenum mode) {}
23GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data, GrGLenum usage) {}
24GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferSubData(GrGLenum target, GrGLintptr offset, GrGLsizeiptr size, const GrGLvoid* data) {}
25GrGLvoid GR_GL_FUNCTION_TYPE nullGLClear(GrGLbitfield mask) {}
26GrGLvoid GR_GL_FUNCTION_TYPE nullGLClearColor(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha) {}
27GrGLvoid GR_GL_FUNCTION_TYPE nullGLClearStencil(GrGLint s) {}
28GrGLvoid GR_GL_FUNCTION_TYPE nullGLColorMask(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha) {}
29GrGLvoid GR_GL_FUNCTION_TYPE nullGLCompileShader(GrGLuint shader) {}
30GrGLvoid GR_GL_FUNCTION_TYPE nullGLCompressedTexImage2D(GrGLenum target, GrGLint level, GrGLenum internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLsizei imageSize, const GrGLvoid* data) {}
31GrGLvoid GR_GL_FUNCTION_TYPE nullGLCullFace(GrGLenum mode) {}
32GrGLvoid GR_GL_FUNCTION_TYPE nullGLDepthMask(GrGLboolean flag) {}
33GrGLvoid GR_GL_FUNCTION_TYPE nullGLDisable(GrGLenum cap) {}
34GrGLvoid GR_GL_FUNCTION_TYPE nullGLDisableVertexAttribArray(GrGLuint index) {}
35GrGLvoid GR_GL_FUNCTION_TYPE nullGLDrawArrays(GrGLenum mode, GrGLint first, GrGLsizei count) {}
36GrGLvoid GR_GL_FUNCTION_TYPE nullGLDrawBuffer(GrGLenum mode) {}
37GrGLvoid GR_GL_FUNCTION_TYPE nullGLDrawBuffers(GrGLsizei n, const GrGLenum* bufs) {}
38GrGLvoid GR_GL_FUNCTION_TYPE nullGLDrawElements(GrGLenum mode, GrGLsizei count, GrGLenum type, const GrGLvoid* indices) {}
39GrGLvoid GR_GL_FUNCTION_TYPE nullGLEnable(GrGLenum cap) {}
40GrGLvoid GR_GL_FUNCTION_TYPE nullGLEnableVertexAttribArray(GrGLuint index) {}
41GrGLvoid GR_GL_FUNCTION_TYPE nullGLEndQuery(GrGLenum target) {}
42GrGLvoid GR_GL_FUNCTION_TYPE nullGLFinish() {}
43GrGLvoid GR_GL_FUNCTION_TYPE nullGLFlush() {}
44GrGLvoid GR_GL_FUNCTION_TYPE nullGLFrontFace(GrGLenum mode) {}
45GrGLvoid GR_GL_FUNCTION_TYPE nullGLLineWidth(GrGLfloat width) {}
46GrGLvoid GR_GL_FUNCTION_TYPE nullGLLinkProgram(GrGLuint program) {}
47GrGLvoid GR_GL_FUNCTION_TYPE nullGLPixelStorei(GrGLenum pname, GrGLint param) {}
48GrGLvoid GR_GL_FUNCTION_TYPE nullGLQueryCounter(GrGLuint id, GrGLenum target) {}
49GrGLvoid GR_GL_FUNCTION_TYPE nullGLReadBuffer(GrGLenum src) {}
50GrGLvoid GR_GL_FUNCTION_TYPE nullGLReadPixels(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {}
51GrGLvoid GR_GL_FUNCTION_TYPE nullGLScissor(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height) {}
52GrGLvoid GR_GL_FUNCTION_TYPE nullGLShaderSource(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length) {}
53GrGLvoid GR_GL_FUNCTION_TYPE nullGLStencilFunc(GrGLenum func, GrGLint ref, GrGLuint mask) {}
54GrGLvoid GR_GL_FUNCTION_TYPE nullGLStencilFuncSeparate(GrGLenum face, GrGLenum func, GrGLint ref, GrGLuint mask) {}
55GrGLvoid GR_GL_FUNCTION_TYPE nullGLStencilMask(GrGLuint mask) {}
56GrGLvoid GR_GL_FUNCTION_TYPE nullGLStencilMaskSeparate(GrGLenum face, GrGLuint mask) {}
57GrGLvoid GR_GL_FUNCTION_TYPE nullGLStencilOp(GrGLenum fail, GrGLenum zfail, GrGLenum zpass) {}
58GrGLvoid GR_GL_FUNCTION_TYPE nullGLStencilOpSeparate(GrGLenum face, GrGLenum fail, GrGLenum zfail, GrGLenum zpass) {}
59GrGLvoid GR_GL_FUNCTION_TYPE nullGLTexImage2D(GrGLenum target, GrGLint level, GrGLint internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLenum format, GrGLenum type, const GrGLvoid* pixels) {}
60GrGLvoid GR_GL_FUNCTION_TYPE nullGLTexParameteri(GrGLenum target, GrGLenum pname, GrGLint param) {}
61GrGLvoid GR_GL_FUNCTION_TYPE nullGLTexStorage2D(GrGLenum target, GrGLsizei levels, GrGLenum internalformat, GrGLsizei width, GrGLsizei height) {}
62GrGLvoid GR_GL_FUNCTION_TYPE nullGLTexSubImage2D(GrGLenum target, GrGLint level, GrGLint xoffset, GrGLint yoffset, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, const GrGLvoid* pixels) {}
63GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform1f(GrGLint location, GrGLfloat v0) {}
64GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform1i(GrGLint location, GrGLint v0) {}
65GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform1fv(GrGLint location, GrGLsizei count, const GrGLfloat* v) {}
66GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform1iv(GrGLint location, GrGLsizei count, const GrGLint* v) {}
67GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform2f(GrGLint location, GrGLfloat v0, GrGLfloat v1) {}
68GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform2i(GrGLint location, GrGLint v0, GrGLint v1) {}
69GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform2fv(GrGLint location, GrGLsizei count, const GrGLfloat* v) {}
70GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform2iv(GrGLint location, GrGLsizei count, const GrGLint* v) {}
71GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform3f(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2) {}
72GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform3i(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2) {}
73GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform3fv(GrGLint location, GrGLsizei count, const GrGLfloat* v) {}
74GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform3iv(GrGLint location, GrGLsizei count, const GrGLint* v) {}
75GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform4f(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2, GrGLfloat v3) {}
76GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform4i(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2, GrGLint v3) {}
77GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform4fv(GrGLint location, GrGLsizei count, const GrGLfloat* v) {}
78GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniform4iv(GrGLint location, GrGLsizei count, const GrGLint* v) {}
79GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniformMatrix2fv(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value) {}
80GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniformMatrix3fv(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value) {}
81GrGLvoid GR_GL_FUNCTION_TYPE nullGLUniformMatrix4fv(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value) {}
82GrGLvoid GR_GL_FUNCTION_TYPE nullGLUseProgram(GrGLuint program) {}
83GrGLvoid GR_GL_FUNCTION_TYPE nullGLVertexAttrib4fv(GrGLuint indx, const GrGLfloat* values) {}
84GrGLvoid GR_GL_FUNCTION_TYPE nullGLVertexAttribPointer(GrGLuint indx, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const GrGLvoid* ptr) {}
85GrGLvoid GR_GL_FUNCTION_TYPE nullGLViewport(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height) {}
86GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindFramebuffer(GrGLenum target, GrGLuint framebuffer) {}
87GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindRenderbuffer(GrGLenum target, GrGLuint renderbuffer) {}
88GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteFramebuffers(GrGLsizei n, const GrGLuint *framebuffers) {}
89GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteRenderbuffers(GrGLsizei n, const GrGLuint *renderbuffers) {}
90GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferRenderbuffer(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer) {}
91GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level) {}
92GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetFramebufferAttachmentParameteriv(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params) {}
93GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetRenderbufferParameteriv(GrGLenum target, GrGLenum pname, GrGLint* params) {}
94GrGLvoid GR_GL_FUNCTION_TYPE nullGLRenderbufferStorage(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height) {}
95GrGLvoid GR_GL_FUNCTION_TYPE nullGLRenderbufferStorageMultisample(GrGLenum target, GrGLsizei samples, GrGLenum internalformat, GrGLsizei width, GrGLsizei height) {}
96GrGLvoid GR_GL_FUNCTION_TYPE nullGLBlitFramebuffer(GrGLint srcX0, GrGLint srcY0, GrGLint srcX1, GrGLint srcY1, GrGLint dstX0, GrGLint dstY0, GrGLint dstX1, GrGLint dstY1, GrGLbitfield mask, GrGLenum filter) {}
97GrGLvoid GR_GL_FUNCTION_TYPE nullGLResolveMultisampleFramebuffer() {}
98GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindFragDataLocationIndexed(GrGLuint program, GrGLuint colorNumber, GrGLuint index, const GrGLchar * name) {}
99
100GrGLenum GR_GL_FUNCTION_TYPE nullGLCheckFramebufferStatus(GrGLenum target) {
101    return GR_GL_FRAMEBUFFER_COMPLETE;
102}
103
104GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateProgram() {
105    static int gCurrID = 0;
106    return ++gCurrID;
107}
108
109GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateShader(GrGLenum type) {
110    static int gCurrID = 0;
111    return ++gCurrID;
112}
113
114// same delete used for shaders and programs
115GrGLvoid GR_GL_FUNCTION_TYPE nullGLDelete(GrGLuint program) {
116}
117
118// same function used for all glGen*(GLsize i, GLuint*) functions
119GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenIds(GrGLsizei n, GrGLuint* ids) {
120    static int gCurrID = 0;
121    for (int i = 0; i < n; ++i) {
122        ids[i] = ++gCurrID;
123    }
124}
125// same delete function for all glDelete*(GLsize i, const GLuint*) except buffers
126GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteIds(GrGLsizei n, const GrGLuint* ids) {}
127
128// In debug builds we do asserts that ensure we agree with GL about when a buffer
129// is mapped.
130static GrTDArray<GrGLuint> gMappedBuffers;
131static GrGLuint gCurrArrayBuffer;
132static GrGLuint gCurrElementArrayBuffer;
133
134GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer) {
135    switch (target) {
136    case GR_GL_ARRAY_BUFFER:
137        gCurrArrayBuffer = buffer;
138        break;
139    case GR_GL_ELEMENT_ARRAY_BUFFER:
140        gCurrElementArrayBuffer = buffer;
141        break;
142    }
143}
144
145// deleting a bound buffer has the side effect of binding 0
146GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteBuffers(GrGLsizei n, const GrGLuint* ids) {
147    for (int i = 0; i < n; ++i) {
148        if (ids[i] == gCurrArrayBuffer) {
149            gCurrArrayBuffer = 0;
150        }
151        if (ids[i] == gCurrElementArrayBuffer) {
152            gCurrElementArrayBuffer = 0;
153        }
154        for (int j = 0; j < gMappedBuffers.count(); ++j) {
155            if (gMappedBuffers[j] == ids[i]) {
156                gMappedBuffers.remove(j);
157                // don't break b/c we didn't check for dupes on insert
158                --j;
159            }
160        }
161    }
162}
163
164GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access) {
165    // We just reserve 32MB of RAM for all locks and hope its big enough
166    static SkAutoMalloc gBufferData(32 * (1 << 20));
167    GrGLuint buf = 0;
168    switch (target) {
169        case GR_GL_ARRAY_BUFFER:
170            buf = gCurrArrayBuffer;
171            break;
172        case GR_GL_ELEMENT_ARRAY_BUFFER:
173            buf = gCurrElementArrayBuffer;
174            break;
175    }
176    if (buf) {
177        *gMappedBuffers.append() = buf;
178    }
179    return gBufferData.get();
180}
181
182GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) {
183    GrGLuint buf = 0;
184    switch (target) {
185    case GR_GL_ARRAY_BUFFER:
186        buf = gCurrArrayBuffer;
187        break;
188    case GR_GL_ELEMENT_ARRAY_BUFFER:
189        buf = gCurrElementArrayBuffer;
190        break;
191    }
192    if (buf) {
193        for (int i = 0; i < gMappedBuffers.count(); ++i) {
194            if (gMappedBuffers[i] == buf) {
195                gMappedBuffers.remove(i);
196                // don't break b/c we didn't check for dupes on insert
197                --i;
198            }
199        }
200    }
201    return GR_GL_TRUE;
202}
203
204GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenum pname, GrGLint* params) {
205    switch (pname) {
206        case GR_GL_BUFFER_MAPPED: {
207            *params = GR_GL_FALSE;
208            GrGLuint buf = 0;
209            switch (target) {
210                case GR_GL_ARRAY_BUFFER:
211                    buf = gCurrArrayBuffer;
212                    break;
213                case GR_GL_ELEMENT_ARRAY_BUFFER:
214                    buf = gCurrElementArrayBuffer;
215                    break;
216            }
217            if (buf) {
218                for (int i = 0; i < gMappedBuffers.count(); ++i) {
219                    if (gMappedBuffers[i] == buf) {
220                        *params = GR_GL_TRUE;
221                        break;
222                    }
223                }
224            }
225            break; }
226        default:
227            GrCrash("Unexpected pname to GetBufferParamateriv");
228            break;
229    }
230};
231
232GrGLenum GR_GL_FUNCTION_TYPE nullGLGetError() {
233    return GR_GL_NO_ERROR;
234}
235
236GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetIntegerv(GrGLenum pname, GrGLint* params) {
237    switch (pname) {
238        case GR_GL_STENCIL_BITS:
239            *params = 8;
240            break;
241        case GR_GL_SAMPLES:
242            *params = 1;
243            break;
244        case GR_GL_FRAMEBUFFER_BINDING:
245            *params = 0;
246            break;
247        case GR_GL_VIEWPORT:
248            params[0] = 0;
249            params[1] = 0;
250            params[2] = 800;
251            params[3] = 600;
252            break;
253        case GR_GL_MAX_TEXTURE_IMAGE_UNITS:
254            *params = 8;
255            break;
256        case GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS:
257            *params = 16;
258            break;
259        case GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
260            *params = 16 * 4;
261            break;
262        case GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS:
263            *params = 0;
264            break;
265        case GR_GL_COMPRESSED_TEXTURE_FORMATS:
266            break;
267        case GR_GL_MAX_TEXTURE_SIZE:
268            *params = 8192;
269            break;
270        case GR_GL_MAX_RENDERBUFFER_SIZE:
271            *params = 8192;
272            break;
273        case GR_GL_MAX_SAMPLES:
274            *params = 32;
275            break;
276        case GR_GL_MAX_VERTEX_ATTRIBS:
277            *params = 16;
278            break;
279        default:
280            GrCrash("Unexpected pname to GetIntegerv");
281    }
282}
283// used for both the program and shader info logs
284GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetInfoLog(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, char* infolog) {
285    if (length) {
286        *length = 0;
287    }
288    if (bufsize > 0) {
289        *infolog = 0;
290    }
291}
292
293// used for both the program and shader params
294GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetShaderOrProgramiv(GrGLuint program, GrGLenum pname, GrGLint* params) {
295    switch (pname) {
296        case GR_GL_LINK_STATUS:  // fallthru
297        case GR_GL_COMPILE_STATUS:
298            *params = GR_GL_TRUE;
299            break;
300        case GR_GL_INFO_LOG_LENGTH:
301            *params = 0;
302            break;
303        // we don't expect any other pnames
304        default:
305            GrCrash("Unexpected pname to GetProgramiv");
306            break;
307    }
308}
309
310namespace {
311template <typename T>
312void query_result(GrGLenum GLtarget, GrGLenum pname, T *params) {
313    switch (pname) {
314        case GR_GL_QUERY_RESULT_AVAILABLE:
315            *params = GR_GL_TRUE;
316            break;
317        case GR_GL_QUERY_RESULT:
318            *params = 0;
319            break;
320        default:
321            GrCrash("Unexpected pname passed to GetQueryObject.");
322            break;
323    }
324}
325}
326
327// Queries on the null GL just don't do anything at all. We could potentially make
328// the timers work.
329GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetQueryiv(GrGLenum GLtarget, GrGLenum pname, GrGLint *params) {
330    switch (pname) {
331        case GR_GL_CURRENT_QUERY:
332            *params = 0;
333            break;
334        case GR_GL_QUERY_COUNTER_BITS:
335            *params = 32;
336            break;
337        default:
338            GrCrash("Unexpected pname passed GetQueryiv.");
339    }
340}
341GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetQueryObjecti64v(GrGLuint id, GrGLenum pname, GrGLint64 *params) {
342    query_result(id, pname, params);
343}
344GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetQueryObjectiv(GrGLuint id, GrGLenum pname, GrGLint *params) {
345    query_result(id, pname, params);
346}
347GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetQueryObjectui64v(GrGLuint id, GrGLenum pname, GrGLuint64 *params) {
348    query_result(id, pname, params);
349}
350GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetQueryObjectuiv(GrGLuint id, GrGLenum pname, GrGLuint *params) {
351    query_result(id, pname, params);
352}
353
354const GrGLubyte* GR_GL_FUNCTION_TYPE nullGLGetString(GrGLenum name) {
355    switch (name) {
356        case GR_GL_EXTENSIONS:
357            return (const GrGLubyte*)"GL_ARB_framebuffer_object GL_ARB_blend_func_extended GL_ARB_timer_query GL_ARB_draw_buffers GL_ARB_occlusion_query GL_EXT_blend_color GL_EXT_stencil_wrap";
358        case GR_GL_VERSION:
359            return (const GrGLubyte*)"4.0 Null GL";
360        case GR_GL_SHADING_LANGUAGE_VERSION:
361            return (const GrGLubyte*)"4.20.8 Null GLSL";
362        default:
363            GrCrash("Unexpected name to GetString");
364            return NULL;
365    }
366}
367
368// we used to use this to query stuff about externally created textures, now we just
369// require clients to tell us everything about the texture.
370GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetTexLevelParameteriv(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint* params) {
371    GrCrash("Should never query texture parameters.");
372}
373
374GrGLint GR_GL_FUNCTION_TYPE nullGLGetUniformLocation(GrGLuint program, const char* name) {
375    static int gUniLocation = 0;
376    return ++gUniLocation;
377}
378
379const GrGLInterface* GrGLCreateNullInterface() {
380    // The gl functions are not context-specific so we create one global
381    // interface
382    static SkAutoTUnref<GrGLInterface> glInterface;
383    if (!glInterface.get()) {
384        GrGLInterface* interface = new GrGLInterface;
385        glInterface.reset(interface);
386        interface->fBindingsExported = kDesktop_GrGLBinding;
387        interface->fActiveTexture = nullGLActiveTexture;
388        interface->fAttachShader = nullGLAttachShader;
389        interface->fBeginQuery = nullGLBeginQuery;
390        interface->fBindAttribLocation = nullGLBindAttribLocation;
391        interface->fBindBuffer = nullGLBindBuffer;
392        interface->fBindFragDataLocation = nullGLBindFragDataLocation;
393        interface->fBindTexture = nullGLBindTexture;
394        interface->fBlendColor = nullGLBlendColor;
395        interface->fBlendFunc = nullGLBlendFunc;
396        interface->fBlendEquation = nullGLBlendEquation;
397        interface->fBufferData = nullGLBufferData;
398        interface->fBufferSubData = nullGLBufferSubData;
399        interface->fClear = nullGLClear;
400        interface->fClearColor = nullGLClearColor;
401        interface->fClearStencil = nullGLClearStencil;
402        interface->fColorMask = nullGLColorMask;
403        interface->fCompileShader = nullGLCompileShader;
404        interface->fCompressedTexImage2D = nullGLCompressedTexImage2D;
405        interface->fCreateProgram = nullGLCreateProgram;
406        interface->fCreateShader = nullGLCreateShader;
407        interface->fCullFace = nullGLCullFace;
408        interface->fDeleteBuffers = nullGLDeleteBuffers;
409        interface->fDeleteProgram = nullGLDelete;
410        interface->fDeleteQueries = nullGLDeleteIds;
411        interface->fDeleteShader = nullGLDelete;
412        interface->fDeleteTextures = nullGLDeleteIds;
413        interface->fDepthMask = nullGLDepthMask;
414        interface->fDisable = nullGLDisable;
415        interface->fDisableVertexAttribArray = nullGLDisableVertexAttribArray;
416        interface->fDrawArrays = nullGLDrawArrays;
417        interface->fDrawBuffer = nullGLDrawBuffer;
418        interface->fDrawBuffers = nullGLDrawBuffers;
419        interface->fDrawElements = nullGLDrawElements;
420        interface->fEnable = nullGLEnable;
421        interface->fEnableVertexAttribArray = nullGLEnableVertexAttribArray;
422        interface->fEndQuery = nullGLEndQuery;
423        interface->fFinish = nullGLFinish;
424        interface->fFlush = nullGLFlush;
425        interface->fFrontFace = nullGLFrontFace;
426        interface->fGenBuffers = nullGLGenIds;
427        interface->fGenQueries = nullGLGenIds;
428        interface->fGenTextures = nullGLGenIds;
429        interface->fGetBufferParameteriv = nullGLGetBufferParameteriv;
430        interface->fGetError = nullGLGetError;
431        interface->fGetIntegerv = nullGLGetIntegerv;
432        interface->fGetQueryObjecti64v = nullGLGetQueryObjecti64v;
433        interface->fGetQueryObjectiv = nullGLGetQueryObjectiv;
434        interface->fGetQueryObjectui64v = nullGLGetQueryObjectui64v;
435        interface->fGetQueryObjectuiv = nullGLGetQueryObjectuiv;
436        interface->fGetQueryiv = nullGLGetQueryiv;
437        interface->fGetProgramInfoLog = nullGLGetInfoLog;
438        interface->fGetProgramiv = nullGLGetShaderOrProgramiv;
439        interface->fGetShaderInfoLog = nullGLGetInfoLog;
440        interface->fGetShaderiv = nullGLGetShaderOrProgramiv;
441        interface->fGetString = nullGLGetString;
442        interface->fGetTexLevelParameteriv = nullGLGetTexLevelParameteriv;
443        interface->fGetUniformLocation = nullGLGetUniformLocation;
444        interface->fLineWidth = nullGLLineWidth;
445        interface->fLinkProgram = nullGLLinkProgram;
446        interface->fPixelStorei = nullGLPixelStorei;
447        interface->fQueryCounter = nullGLQueryCounter;
448        interface->fReadBuffer = nullGLReadBuffer;
449        interface->fReadPixels = nullGLReadPixels;
450        interface->fScissor = nullGLScissor;
451        interface->fShaderSource = nullGLShaderSource;
452        interface->fStencilFunc = nullGLStencilFunc;
453        interface->fStencilFuncSeparate = nullGLStencilFuncSeparate;
454        interface->fStencilMask = nullGLStencilMask;
455        interface->fStencilMaskSeparate = nullGLStencilMaskSeparate;
456        interface->fStencilOp = nullGLStencilOp;
457        interface->fStencilOpSeparate = nullGLStencilOpSeparate;
458        interface->fTexImage2D = nullGLTexImage2D;
459        interface->fTexParameteri = nullGLTexParameteri;
460        interface->fTexSubImage2D = nullGLTexSubImage2D;
461        interface->fTexStorage2D = nullGLTexStorage2D;
462        interface->fUniform1f = nullGLUniform1f;
463        interface->fUniform1i = nullGLUniform1i;
464        interface->fUniform1fv = nullGLUniform1fv;
465        interface->fUniform1iv = nullGLUniform1iv;
466        interface->fUniform2f = nullGLUniform2f;
467        interface->fUniform2i = nullGLUniform2i;
468        interface->fUniform2fv = nullGLUniform2fv;
469        interface->fUniform2iv = nullGLUniform2iv;
470        interface->fUniform3f = nullGLUniform3f;
471        interface->fUniform3i = nullGLUniform3i;
472        interface->fUniform3fv = nullGLUniform3fv;
473        interface->fUniform3iv = nullGLUniform3iv;
474        interface->fUniform4f = nullGLUniform4f;
475        interface->fUniform4i = nullGLUniform4i;
476        interface->fUniform4fv = nullGLUniform4fv;
477        interface->fUniform4iv = nullGLUniform4iv;
478        interface->fUniformMatrix2fv = nullGLUniformMatrix2fv;
479        interface->fUniformMatrix3fv = nullGLUniformMatrix3fv;
480        interface->fUniformMatrix4fv = nullGLUniformMatrix4fv;
481        interface->fUseProgram = nullGLUseProgram;
482        interface->fVertexAttrib4fv = nullGLVertexAttrib4fv;
483        interface->fVertexAttribPointer = nullGLVertexAttribPointer;
484        interface->fViewport = nullGLViewport;
485        interface->fBindFramebuffer = nullGLBindFramebuffer;
486        interface->fBindRenderbuffer = nullGLBindRenderbuffer;
487        interface->fCheckFramebufferStatus = nullGLCheckFramebufferStatus;
488        interface->fDeleteFramebuffers = nullGLDeleteFramebuffers;
489        interface->fDeleteRenderbuffers = nullGLDeleteRenderbuffers;
490        interface->fFramebufferRenderbuffer = nullGLFramebufferRenderbuffer;
491        interface->fFramebufferTexture2D = nullGLFramebufferTexture2D;
492        interface->fGenFramebuffers = nullGLGenIds;
493        interface->fGenRenderbuffers = nullGLGenIds;
494        interface->fGetFramebufferAttachmentParameteriv = nullGLGetFramebufferAttachmentParameteriv;
495        interface->fGetRenderbufferParameteriv = nullGLGetRenderbufferParameteriv;
496        interface->fRenderbufferStorage = nullGLRenderbufferStorage;
497        interface->fRenderbufferStorageMultisample = nullGLRenderbufferStorageMultisample;
498        interface->fBlitFramebuffer = nullGLBlitFramebuffer;
499        interface->fResolveMultisampleFramebuffer = nullGLResolveMultisampleFramebuffer;
500        interface->fMapBuffer = nullGLMapBuffer;
501        interface->fUnmapBuffer = nullGLUnmapBuffer;
502        interface->fBindFragDataLocationIndexed = nullGLBindFragDataLocationIndexed;
503    }
504    glInterface.get()->ref();
505    return glInterface.get();
506}
507