blob: f0a3e7d4bdd13ae9884f45879eee6c45c6df17ff [file] [log] [blame]
bsalomon@google.com74913722011-10-27 20:44:19 +00001/*
2 * Copyright 2011 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
tomhudson@google.com6bf38b52012-02-14 15:11:59 +00009#include "gl/GrGLInterface.h"
bsalomon@google.com91bcc942012-05-07 17:28:41 +000010#include "GrGLDefines.h"
bsalomon@google.com21cbec42013-01-07 17:23:00 +000011#include "SkTDArray.h"
bsalomon@google.com8f943612013-02-26 14:34:43 +000012#include "GrGLNoOpInterface.h"
bsalomon776d3552014-08-14 08:13:27 -070013#include "SkTLS.h"
bsalomon@google.com8f943612013-02-26 14:34:43 +000014
bsalomon7e340072015-02-11 12:07:31 -080015// TODO: Delete this file after chrome starts using SkNullGLContext.
16
17// added to suppress 'no previous prototype' warning and because this code is duplicated in
18// SkNullGLContext.cpp
19namespace {
20
bsalomon776d3552014-08-14 08:13:27 -070021class BufferObj {
robertphillips@google.comd6543e52013-07-18 17:39:14 +000022public:
mtklein2766c002015-06-26 11:45:03 -070023
bsalomon776d3552014-08-14 08:13:27 -070024
halcanary96fcdcc2015-08-27 07:41:13 -070025 BufferObj(GrGLuint id) : fID(id), fDataPtr(nullptr), fSize(0), fMapped(false) {
robertphillips@google.comd6543e52013-07-18 17:39:14 +000026 }
halcanary385fe4d2015-08-26 13:07:48 -070027 ~BufferObj() { delete[] fDataPtr; }
robertphillips@google.comd6543e52013-07-18 17:39:14 +000028
robertphillips@google.comae6b7772013-07-18 18:07:39 +000029 void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) {
bsalomon49f085d2014-09-05 13:34:00 -070030 if (fDataPtr) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000031 SkASSERT(0 != fSize);
halcanary385fe4d2015-08-26 13:07:48 -070032 delete[] fDataPtr;
robertphillips@google.comd6543e52013-07-18 17:39:14 +000033 }
34
35 fSize = size;
halcanary385fe4d2015-08-26 13:07:48 -070036 fDataPtr = new char[size];
robertphillips@google.comd6543e52013-07-18 17:39:14 +000037 }
38
39 GrGLuint id() const { return fID; }
40 GrGLchar* dataPtr() { return fDataPtr; }
robertphillips@google.comae6b7772013-07-18 18:07:39 +000041 GrGLsizeiptr size() const { return fSize; }
robertphillips@google.comd6543e52013-07-18 17:39:14 +000042
43 void setMapped(bool mapped) { fMapped = mapped; }
44 bool mapped() const { return fMapped; }
45
46private:
47 GrGLuint fID;
48 GrGLchar* fDataPtr;
robertphillips@google.comae6b7772013-07-18 18:07:39 +000049 GrGLsizeiptr fSize; // size in bytes
robertphillips@google.comd6543e52013-07-18 17:39:14 +000050 bool fMapped;
51};
52
bsalomon776d3552014-08-14 08:13:27 -070053// This class maintains a sparsely populated array of buffer pointers.
54class BufferManager {
55public:
mtklein2766c002015-06-26 11:45:03 -070056
robertphillips@google.comd6543e52013-07-18 17:39:14 +000057
bsalomon776d3552014-08-14 08:13:27 -070058 BufferManager() : fFreeListHead(kFreeListEnd) {}
robertphillips@google.comd6543e52013-07-18 17:39:14 +000059
bsalomon776d3552014-08-14 08:13:27 -070060 ~BufferManager() {
halcanary96fcdcc2015-08-27 07:41:13 -070061 // nullptr out the entries that are really free list links rather than ptrs before deleting.
bsalomon776d3552014-08-14 08:13:27 -070062 intptr_t curr = fFreeListHead;
63 while (kFreeListEnd != curr) {
64 intptr_t next = reinterpret_cast<intptr_t>(fBuffers[SkToS32(curr)]);
halcanary96fcdcc2015-08-27 07:41:13 -070065 fBuffers[SkToS32(curr)] = nullptr;
bsalomon776d3552014-08-14 08:13:27 -070066 curr = next;
67 }
68
69 fBuffers.deleteAll();
robertphillips@google.comd6543e52013-07-18 17:39:14 +000070 }
71
bsalomon776d3552014-08-14 08:13:27 -070072 BufferObj* lookUp(GrGLuint id) {
73 BufferObj* buffer = fBuffers[id];
bsalomon49f085d2014-09-05 13:34:00 -070074 SkASSERT(buffer && buffer->id() == id);
bsalomon776d3552014-08-14 08:13:27 -070075 return buffer;
robertphillips@google.comd6543e52013-07-18 17:39:14 +000076 }
77
bsalomon776d3552014-08-14 08:13:27 -070078 BufferObj* create() {
79 GrGLuint id;
80 BufferObj* buffer;
robertphillips@google.comd6543e52013-07-18 17:39:14 +000081
bsalomon776d3552014-08-14 08:13:27 -070082 if (kFreeListEnd == fFreeListHead) {
83 // no free slots - create a new one
84 id = fBuffers.count();
halcanary385fe4d2015-08-26 13:07:48 -070085 buffer = new BufferObj(id);
bsalomon776d3552014-08-14 08:13:27 -070086 *fBuffers.append() = buffer;
87 } else {
88 // grab the head of the free list and advance the head to the next free slot.
89 id = static_cast<GrGLuint>(fFreeListHead);
90 fFreeListHead = reinterpret_cast<intptr_t>(fBuffers[id]);
robertphillips@google.comd6543e52013-07-18 17:39:14 +000091
halcanary385fe4d2015-08-26 13:07:48 -070092 buffer = new BufferObj(id);
bsalomon776d3552014-08-14 08:13:27 -070093 fBuffers[id] = buffer;
94 }
robertphillips@google.comd6543e52013-07-18 17:39:14 +000095
bsalomon776d3552014-08-14 08:13:27 -070096 return buffer;
97 }
98
99 void free(BufferObj* buffer) {
100 SkASSERT(fBuffers.count() > 0);
101
102 GrGLuint id = buffer->id();
halcanary385fe4d2015-08-26 13:07:48 -0700103 delete buffer;
bsalomon776d3552014-08-14 08:13:27 -0700104
105 fBuffers[id] = reinterpret_cast<BufferObj*>(fFreeListHead);
106 fFreeListHead = id;
107 }
108
109private:
110 static const intptr_t kFreeListEnd = -1;
111 // Index of the first entry of fBuffers in the free list. Free slots in fBuffers are indices to
112 // the next free slot. The last free slot has a value of kFreeListEnd.
113 intptr_t fFreeListHead;
114 SkTDArray<BufferObj*> fBuffers;
115};
116
117/**
118 * The global-to-thread state object for the null interface. All null interfaces on the
119 * same thread currently share one of these. This means two null contexts on the same thread
120 * can interfere with each other. It may make sense to more integrate this into SkNullGLContext
121 * and use it's makeCurrent mechanism.
122 */
123struct ThreadContext {
124public:
mtklein2766c002015-06-26 11:45:03 -0700125
bsalomon776d3552014-08-14 08:13:27 -0700126
127 BufferManager fBufferManager;
128 GrGLuint fCurrArrayBuffer;
129 GrGLuint fCurrElementArrayBuffer;
130 GrGLuint fCurrProgramID;
131 GrGLuint fCurrShaderID;
132
133 static ThreadContext* Get() {
134 return reinterpret_cast<ThreadContext*>(SkTLS::Get(Create, Delete));
135 }
136
137 ThreadContext()
138 : fCurrArrayBuffer(0)
139 , fCurrElementArrayBuffer(0)
140 , fCurrProgramID(0)
141 , fCurrShaderID(0) {}
142
143private:
halcanary385fe4d2015-08-26 13:07:48 -0700144 static void* Create() { return new ThreadContext; }
145 static void Delete(void* context) { delete reinterpret_cast<ThreadContext*>(context); }
bsalomon776d3552014-08-14 08:13:27 -0700146};
147
148// Functions not declared in GrGLBogusInterface.h (not common with the Debug GL interface).
149
bsalomon@google.com74913722011-10-27 20:44:19 +0000150GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {}
151GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shader) {}
152GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {}
153GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint index, const char* name) {}
154GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture) {}
bsalomon@google.comecd84842013-03-01 15:36:02 +0000155GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindVertexArray(GrGLuint id) {}
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000156
157GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenBuffers(GrGLsizei n, GrGLuint* ids) {
bsalomon776d3552014-08-14 08:13:27 -0700158 ThreadContext* ctx = ThreadContext::Get();
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000159 for (int i = 0; i < n; ++i) {
bsalomon776d3552014-08-14 08:13:27 -0700160 BufferObj* buffer = ctx->fBufferManager.create();
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000161 ids[i] = buffer->id();
162 }
163}
164
commit-bot@chromium.orgcffff792013-07-26 16:36:04 +0000165GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenerateMipmap(GrGLenum target) {}
166
skia.committer@gmail.coma7991982013-07-19 07:00:57 +0000167GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target,
168 GrGLsizeiptr size,
169 const GrGLvoid* data,
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000170 GrGLenum usage) {
bsalomon776d3552014-08-14 08:13:27 -0700171 ThreadContext* ctx = ThreadContext::Get();
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000172 GrGLuint id = 0;
173
174 switch (target) {
175 case GR_GL_ARRAY_BUFFER:
bsalomon776d3552014-08-14 08:13:27 -0700176 id = ctx->fCurrArrayBuffer;
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000177 break;
178 case GR_GL_ELEMENT_ARRAY_BUFFER:
bsalomon776d3552014-08-14 08:13:27 -0700179 id = ctx->fCurrElementArrayBuffer;
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000180 break;
181 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000182 SkFAIL("Unexpected target to nullGLBufferData");
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000183 break;
184 }
185
186 if (id > 0) {
bsalomon776d3552014-08-14 08:13:27 -0700187 BufferObj* buffer = ctx->fBufferManager.lookUp(id);
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000188 buffer->allocate(size, (const GrGLchar*) data);
189 }
190}
191
bsalomon@google.com74913722011-10-27 20:44:19 +0000192GrGLvoid GR_GL_FUNCTION_TYPE nullGLPixelStorei(GrGLenum pname, GrGLint param) {}
bsalomon@google.com74913722011-10-27 20:44:19 +0000193GrGLvoid GR_GL_FUNCTION_TYPE nullGLReadPixels(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {}
bsalomon@google.com74913722011-10-27 20:44:19 +0000194GrGLvoid GR_GL_FUNCTION_TYPE nullGLUseProgram(GrGLuint program) {}
bsalomon@google.com74913722011-10-27 20:44:19 +0000195GrGLvoid GR_GL_FUNCTION_TYPE nullGLViewport(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height) {}
196GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindFramebuffer(GrGLenum target, GrGLuint framebuffer) {}
197GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindRenderbuffer(GrGLenum target, GrGLuint renderbuffer) {}
198GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteFramebuffers(GrGLsizei n, const GrGLuint *framebuffers) {}
199GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteRenderbuffers(GrGLsizei n, const GrGLuint *renderbuffers) {}
200GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferRenderbuffer(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer) {}
201GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level) {}
bsalomon@google.com74913722011-10-27 20:44:19 +0000202
203GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateProgram() {
bsalomon776d3552014-08-14 08:13:27 -0700204 return ++ThreadContext::Get()->fCurrProgramID;
bsalomon@google.com74913722011-10-27 20:44:19 +0000205}
206
207GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateShader(GrGLenum type) {
bsalomon776d3552014-08-14 08:13:27 -0700208 return ++ThreadContext::Get()->fCurrShaderID;
bsalomon@google.com74913722011-10-27 20:44:19 +0000209}
210
211// same delete used for shaders and programs
212GrGLvoid GR_GL_FUNCTION_TYPE nullGLDelete(GrGLuint program) {
213}
214
bsalomon@google.com74913722011-10-27 20:44:19 +0000215GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer) {
bsalomon776d3552014-08-14 08:13:27 -0700216 ThreadContext* ctx = ThreadContext::Get();
bsalomon@google.com74913722011-10-27 20:44:19 +0000217 switch (target) {
218 case GR_GL_ARRAY_BUFFER:
bsalomon776d3552014-08-14 08:13:27 -0700219 ctx->fCurrArrayBuffer = buffer;
bsalomon@google.com74913722011-10-27 20:44:19 +0000220 break;
221 case GR_GL_ELEMENT_ARRAY_BUFFER:
bsalomon776d3552014-08-14 08:13:27 -0700222 ctx->fCurrElementArrayBuffer = buffer;
bsalomon@google.com74913722011-10-27 20:44:19 +0000223 break;
224 }
225}
226
227// deleting a bound buffer has the side effect of binding 0
228GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteBuffers(GrGLsizei n, const GrGLuint* ids) {
bsalomon776d3552014-08-14 08:13:27 -0700229 ThreadContext* ctx = ThreadContext::Get();
bsalomon@google.com74913722011-10-27 20:44:19 +0000230 for (int i = 0; i < n; ++i) {
bsalomon776d3552014-08-14 08:13:27 -0700231 if (ids[i] == ctx->fCurrArrayBuffer) {
232 ctx->fCurrArrayBuffer = 0;
bsalomon@google.com74913722011-10-27 20:44:19 +0000233 }
bsalomon776d3552014-08-14 08:13:27 -0700234 if (ids[i] == ctx->fCurrElementArrayBuffer) {
235 ctx->fCurrElementArrayBuffer = 0;
bsalomon@google.com74913722011-10-27 20:44:19 +0000236 }
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000237
bsalomon776d3552014-08-14 08:13:27 -0700238 BufferObj* buffer = ctx->fBufferManager.lookUp(ids[i]);
239 ctx->fBufferManager.free(buffer);
bsalomon@google.com74913722011-10-27 20:44:19 +0000240 }
241}
242
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000243GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBufferRange(GrGLenum target, GrGLintptr offset,
244 GrGLsizeiptr length, GrGLbitfield access) {
bsalomon776d3552014-08-14 08:13:27 -0700245 ThreadContext* ctx = ThreadContext::Get();
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000246 GrGLuint id = 0;
247 switch (target) {
248 case GR_GL_ARRAY_BUFFER:
bsalomon776d3552014-08-14 08:13:27 -0700249 id = ctx->fCurrArrayBuffer;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000250 break;
251 case GR_GL_ELEMENT_ARRAY_BUFFER:
bsalomon776d3552014-08-14 08:13:27 -0700252 id = ctx->fCurrElementArrayBuffer;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000253 break;
254 }
djsollen@google.com53b614b2014-05-02 17:44:34 +0000255
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000256 if (id > 0) {
257 // We just ignore the offset and length here.
bsalomon776d3552014-08-14 08:13:27 -0700258 BufferObj* buffer = ctx->fBufferManager.lookUp(id);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000259 SkASSERT(!buffer->mapped());
260 buffer->setMapped(true);
261 return buffer->dataPtr();
262 }
halcanary96fcdcc2015-08-27 07:41:13 -0700263 return nullptr;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000264}
265
266GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access) {
bsalomon776d3552014-08-14 08:13:27 -0700267 ThreadContext* ctx = ThreadContext::Get();
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000268 GrGLuint id = 0;
bsalomon@google.com74913722011-10-27 20:44:19 +0000269 switch (target) {
270 case GR_GL_ARRAY_BUFFER:
bsalomon776d3552014-08-14 08:13:27 -0700271 id = ctx->fCurrArrayBuffer;
bsalomon@google.com74913722011-10-27 20:44:19 +0000272 break;
273 case GR_GL_ELEMENT_ARRAY_BUFFER:
bsalomon776d3552014-08-14 08:13:27 -0700274 id = ctx->fCurrElementArrayBuffer;
bsalomon@google.com74913722011-10-27 20:44:19 +0000275 break;
276 }
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000277
278 if (id > 0) {
bsalomon776d3552014-08-14 08:13:27 -0700279 BufferObj* buffer = ctx->fBufferManager.lookUp(id);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000280 SkASSERT(!buffer->mapped());
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000281 buffer->setMapped(true);
282 return buffer->dataPtr();
bsalomon@google.com74913722011-10-27 20:44:19 +0000283 }
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000284
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000285 SkASSERT(false);
halcanary96fcdcc2015-08-27 07:41:13 -0700286 return nullptr; // no buffer bound to target
bsalomon@google.com74913722011-10-27 20:44:19 +0000287}
288
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000289GrGLvoid GR_GL_FUNCTION_TYPE nullGLFlushMappedBufferRange(GrGLenum target,
290 GrGLintptr offset,
291 GrGLsizeiptr length) {}
292
293
bsalomon@google.com74913722011-10-27 20:44:19 +0000294GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) {
bsalomon776d3552014-08-14 08:13:27 -0700295 ThreadContext* ctx = ThreadContext::Get();
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000296 GrGLuint id = 0;
bsalomon@google.com74913722011-10-27 20:44:19 +0000297 switch (target) {
298 case GR_GL_ARRAY_BUFFER:
bsalomon776d3552014-08-14 08:13:27 -0700299 id = ctx->fCurrArrayBuffer;
bsalomon@google.com74913722011-10-27 20:44:19 +0000300 break;
301 case GR_GL_ELEMENT_ARRAY_BUFFER:
bsalomon776d3552014-08-14 08:13:27 -0700302 id = ctx->fCurrElementArrayBuffer;
bsalomon@google.com74913722011-10-27 20:44:19 +0000303 break;
304 }
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000305 if (id > 0) {
bsalomon776d3552014-08-14 08:13:27 -0700306 BufferObj* buffer = ctx->fBufferManager.lookUp(id);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000307 SkASSERT(buffer->mapped());
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000308 buffer->setMapped(false);
309 return GR_GL_TRUE;
bsalomon@google.com74913722011-10-27 20:44:19 +0000310 }
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000311
312 GrAlwaysAssert(false);
313 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION;
bsalomon@google.com74913722011-10-27 20:44:19 +0000314}
315
316GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenum pname, GrGLint* params) {
bsalomon776d3552014-08-14 08:13:27 -0700317 ThreadContext* ctx = ThreadContext::Get();
bsalomon@google.com74913722011-10-27 20:44:19 +0000318 switch (pname) {
319 case GR_GL_BUFFER_MAPPED: {
320 *params = GR_GL_FALSE;
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000321 GrGLuint id = 0;
bsalomon@google.com74913722011-10-27 20:44:19 +0000322 switch (target) {
323 case GR_GL_ARRAY_BUFFER:
bsalomon776d3552014-08-14 08:13:27 -0700324 id = ctx->fCurrArrayBuffer;
bsalomon@google.com74913722011-10-27 20:44:19 +0000325 break;
326 case GR_GL_ELEMENT_ARRAY_BUFFER:
bsalomon776d3552014-08-14 08:13:27 -0700327 id = ctx->fCurrElementArrayBuffer;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000328 break;
bsalomon@google.com74913722011-10-27 20:44:19 +0000329 }
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000330 if (id > 0) {
bsalomon776d3552014-08-14 08:13:27 -0700331 BufferObj* buffer = ctx->fBufferManager.lookUp(id);
robertphillips@google.comd6543e52013-07-18 17:39:14 +0000332 if (buffer->mapped()) {
333 *params = GR_GL_TRUE;
bsalomon@google.com74913722011-10-27 20:44:19 +0000334 }
335 }
336 break; }
337 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000338 SkFAIL("Unexpected pname to GetBufferParamateriv");
bsalomon@google.com74913722011-10-27 20:44:19 +0000339 break;
340 }
341};
342
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000343} // end anonymous namespace
344
bsalomon@google.com74913722011-10-27 20:44:19 +0000345const GrGLInterface* GrGLCreateNullInterface() {
halcanary385fe4d2015-08-26 13:07:48 -0700346 GrGLInterface* interface = new GrGLInterface;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000347
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000348 interface->fStandard = kGL_GrGLStandard;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000349
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000350 GrGLInterface::Functions* functions = &interface->fFunctions;
351 functions->fActiveTexture = nullGLActiveTexture;
352 functions->fAttachShader = nullGLAttachShader;
353 functions->fBeginQuery = nullGLBeginQuery;
354 functions->fBindAttribLocation = nullGLBindAttribLocation;
355 functions->fBindBuffer = nullGLBindBuffer;
356 functions->fBindFragDataLocation = noOpGLBindFragDataLocation;
357 functions->fBindTexture = nullGLBindTexture;
358 functions->fBindVertexArray = nullGLBindVertexArray;
359 functions->fBlendColor = noOpGLBlendColor;
cdaltonbae6f6c2015-04-22 10:39:03 -0700360 functions->fBlendEquation = noOpGLBlendEquation;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000361 functions->fBlendFunc = noOpGLBlendFunc;
362 functions->fBufferData = nullGLBufferData;
363 functions->fBufferSubData = noOpGLBufferSubData;
364 functions->fClear = noOpGLClear;
365 functions->fClearColor = noOpGLClearColor;
366 functions->fClearStencil = noOpGLClearStencil;
367 functions->fColorMask = noOpGLColorMask;
368 functions->fCompileShader = noOpGLCompileShader;
369 functions->fCompressedTexImage2D = noOpGLCompressedTexImage2D;
krajcevski37d20f72014-06-11 10:38:47 -0700370 functions->fCompressedTexSubImage2D = noOpGLCompressedTexSubImage2D;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000371 functions->fCopyTexSubImage2D = noOpGLCopyTexSubImage2D;
372 functions->fCreateProgram = nullGLCreateProgram;
373 functions->fCreateShader = nullGLCreateShader;
374 functions->fCullFace = noOpGLCullFace;
375 functions->fDeleteBuffers = nullGLDeleteBuffers;
376 functions->fDeleteProgram = nullGLDelete;
377 functions->fDeleteQueries = noOpGLDeleteIds;
378 functions->fDeleteShader = nullGLDelete;
379 functions->fDeleteTextures = noOpGLDeleteIds;
380 functions->fDeleteVertexArrays = noOpGLDeleteIds;
381 functions->fDepthMask = noOpGLDepthMask;
382 functions->fDisable = noOpGLDisable;
383 functions->fDisableVertexAttribArray = noOpGLDisableVertexAttribArray;
384 functions->fDrawArrays = noOpGLDrawArrays;
cdalton626e1ff2015-06-12 13:56:46 -0700385 functions->fDrawArraysInstanced = noOpGLDrawArraysInstanced;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000386 functions->fDrawBuffer = noOpGLDrawBuffer;
387 functions->fDrawBuffers = noOpGLDrawBuffers;
388 functions->fDrawElements = noOpGLDrawElements;
cdalton626e1ff2015-06-12 13:56:46 -0700389 functions->fDrawElementsInstanced = noOpGLDrawElementsInstanced;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000390 functions->fEnable = noOpGLEnable;
391 functions->fEnableVertexAttribArray = noOpGLEnableVertexAttribArray;
392 functions->fEndQuery = noOpGLEndQuery;
393 functions->fFinish = noOpGLFinish;
394 functions->fFlush = noOpGLFlush;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000395 functions->fFlushMappedBufferRange = nullGLFlushMappedBufferRange;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000396 functions->fFrontFace = noOpGLFrontFace;
397 functions->fGenBuffers = nullGLGenBuffers;
398 functions->fGenerateMipmap = nullGLGenerateMipmap;
399 functions->fGenQueries = noOpGLGenIds;
400 functions->fGenTextures = noOpGLGenIds;
401 functions->fGenVertexArrays = noOpGLGenIds;
402 functions->fGetBufferParameteriv = nullGLGetBufferParameteriv;
403 functions->fGetError = noOpGLGetError;
404 functions->fGetIntegerv = noOpGLGetIntegerv;
405 functions->fGetQueryObjecti64v = noOpGLGetQueryObjecti64v;
406 functions->fGetQueryObjectiv = noOpGLGetQueryObjectiv;
407 functions->fGetQueryObjectui64v = noOpGLGetQueryObjectui64v;
408 functions->fGetQueryObjectuiv = noOpGLGetQueryObjectuiv;
409 functions->fGetQueryiv = noOpGLGetQueryiv;
410 functions->fGetProgramInfoLog = noOpGLGetInfoLog;
411 functions->fGetProgramiv = noOpGLGetShaderOrProgramiv;
412 functions->fGetShaderInfoLog = noOpGLGetInfoLog;
413 functions->fGetShaderiv = noOpGLGetShaderOrProgramiv;
414 functions->fGetString = noOpGLGetString;
415 functions->fGetStringi = noOpGLGetStringi;
416 functions->fGetTexLevelParameteriv = noOpGLGetTexLevelParameteriv;
417 functions->fGetUniformLocation = noOpGLGetUniformLocation;
418 functions->fInsertEventMarker = noOpGLInsertEventMarker;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000419 functions->fLineWidth = noOpGLLineWidth;
420 functions->fLinkProgram = noOpGLLinkProgram;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000421 functions->fMapBuffer = nullGLMapBuffer;
422 functions->fMapBufferRange = nullGLMapBufferRange;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000423 functions->fPixelStorei = nullGLPixelStorei;
424 functions->fPopGroupMarker = noOpGLPopGroupMarker;
425 functions->fPushGroupMarker = noOpGLPushGroupMarker;
426 functions->fQueryCounter = noOpGLQueryCounter;
427 functions->fReadBuffer = noOpGLReadBuffer;
428 functions->fReadPixels = nullGLReadPixels;
429 functions->fScissor = noOpGLScissor;
430 functions->fShaderSource = noOpGLShaderSource;
431 functions->fStencilFunc = noOpGLStencilFunc;
432 functions->fStencilFuncSeparate = noOpGLStencilFuncSeparate;
433 functions->fStencilMask = noOpGLStencilMask;
434 functions->fStencilMaskSeparate = noOpGLStencilMaskSeparate;
435 functions->fStencilOp = noOpGLStencilOp;
436 functions->fStencilOpSeparate = noOpGLStencilOpSeparate;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000437 functions->fTexImage2D = noOpGLTexImage2D;
438 functions->fTexParameteri = noOpGLTexParameteri;
439 functions->fTexParameteriv = noOpGLTexParameteriv;
440 functions->fTexSubImage2D = noOpGLTexSubImage2D;
441 functions->fTexStorage2D = noOpGLTexStorage2D;
442 functions->fDiscardFramebuffer = noOpGLDiscardFramebuffer;
443 functions->fUniform1f = noOpGLUniform1f;
444 functions->fUniform1i = noOpGLUniform1i;
445 functions->fUniform1fv = noOpGLUniform1fv;
446 functions->fUniform1iv = noOpGLUniform1iv;
447 functions->fUniform2f = noOpGLUniform2f;
448 functions->fUniform2i = noOpGLUniform2i;
449 functions->fUniform2fv = noOpGLUniform2fv;
450 functions->fUniform2iv = noOpGLUniform2iv;
451 functions->fUniform3f = noOpGLUniform3f;
452 functions->fUniform3i = noOpGLUniform3i;
453 functions->fUniform3fv = noOpGLUniform3fv;
454 functions->fUniform3iv = noOpGLUniform3iv;
455 functions->fUniform4f = noOpGLUniform4f;
456 functions->fUniform4i = noOpGLUniform4i;
457 functions->fUniform4fv = noOpGLUniform4fv;
458 functions->fUniform4iv = noOpGLUniform4iv;
459 functions->fUniformMatrix2fv = noOpGLUniformMatrix2fv;
460 functions->fUniformMatrix3fv = noOpGLUniformMatrix3fv;
461 functions->fUniformMatrix4fv = noOpGLUniformMatrix4fv;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000462 functions->fUnmapBuffer = nullGLUnmapBuffer;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000463 functions->fUseProgram = nullGLUseProgram;
egdaniel27c15212014-10-24 15:00:50 -0700464 functions->fVertexAttrib1f = noOpGLVertexAttrib1f;
465 functions->fVertexAttrib2fv = noOpGLVertexAttrib2fv;
466 functions->fVertexAttrib3fv = noOpGLVertexAttrib3fv;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000467 functions->fVertexAttrib4fv = noOpGLVertexAttrib4fv;
468 functions->fVertexAttribPointer = noOpGLVertexAttribPointer;
cdalton626e1ff2015-06-12 13:56:46 -0700469 functions->fVertexAttribDivisor = noOpGLVertexAttribDivisor;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000470 functions->fViewport = nullGLViewport;
471 functions->fBindFramebuffer = nullGLBindFramebuffer;
472 functions->fBindRenderbuffer = nullGLBindRenderbuffer;
473 functions->fCheckFramebufferStatus = noOpGLCheckFramebufferStatus;
474 functions->fDeleteFramebuffers = nullGLDeleteFramebuffers;
475 functions->fDeleteRenderbuffers = nullGLDeleteRenderbuffers;
476 functions->fFramebufferRenderbuffer = nullGLFramebufferRenderbuffer;
477 functions->fFramebufferTexture2D = nullGLFramebufferTexture2D;
478 functions->fGenFramebuffers = noOpGLGenIds;
479 functions->fGenRenderbuffers = noOpGLGenIds;
480 functions->fGetFramebufferAttachmentParameteriv = noOpGLGetFramebufferAttachmentParameteriv;
481 functions->fGetRenderbufferParameteriv = noOpGLGetRenderbufferParameteriv;
482 functions->fRenderbufferStorage = noOpGLRenderbufferStorage;
483 functions->fRenderbufferStorageMultisample = noOpGLRenderbufferStorageMultisample;
484 functions->fBlitFramebuffer = noOpGLBlitFramebuffer;
485 functions->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFramebuffer;
commit-bot@chromium.orgf6696722014-04-25 06:21:30 +0000486 functions->fMatrixLoadf = noOpGLMatrixLoadf;
487 functions->fMatrixLoadIdentity = noOpGLMatrixLoadIdentity;
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000488 functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed;
489
490 interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functions->fGetStringi,
bsalomonb1a32ad2015-11-16 06:48:44 -0800491 functions->fGetIntegerv, nullptr, GR_EGL_NO_DISPLAY);
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000492 return interface;
bsalomon@google.com74913722011-10-27 20:44:19 +0000493}