1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/gl/GrGLCreateNullInterface.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,402 @@ 1.4 +/* 1.5 + * Copyright 2011 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 + 1.12 +#include "gl/GrGLInterface.h" 1.13 +#include "GrGLDefines.h" 1.14 +#include "SkTDArray.h" 1.15 +#include "GrGLNoOpInterface.h" 1.16 + 1.17 +// Functions not declared in GrGLBogusInterface.h (not common with the Debug GL interface). 1.18 + 1.19 +namespace { // added to suppress 'no previous prototype' warning 1.20 + 1.21 +class GrBufferObj { 1.22 +public: 1.23 + GrBufferObj(GrGLuint id) : fID(id), fDataPtr(NULL), fSize(0), fMapped(false) { 1.24 + } 1.25 + ~GrBufferObj() { SkDELETE_ARRAY(fDataPtr); } 1.26 + 1.27 + void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) { 1.28 + if (NULL != fDataPtr) { 1.29 + SkASSERT(0 != fSize); 1.30 + SkDELETE_ARRAY(fDataPtr); 1.31 + } 1.32 + 1.33 + fSize = size; 1.34 + fDataPtr = SkNEW_ARRAY(char, size); 1.35 + } 1.36 + 1.37 + GrGLuint id() const { return fID; } 1.38 + GrGLchar* dataPtr() { return fDataPtr; } 1.39 + GrGLsizeiptr size() const { return fSize; } 1.40 + 1.41 + void setMapped(bool mapped) { fMapped = mapped; } 1.42 + bool mapped() const { return fMapped; } 1.43 + 1.44 +private: 1.45 + GrGLuint fID; 1.46 + GrGLchar* fDataPtr; 1.47 + GrGLsizeiptr fSize; // size in bytes 1.48 + bool fMapped; 1.49 +}; 1.50 + 1.51 +// In debug builds we do asserts that ensure we agree with GL about when a buffer 1.52 +// is mapped. 1.53 +static SkTDArray<GrBufferObj*> gBuffers; // slot 0 is reserved for head of free list 1.54 +static GrGLuint gCurrArrayBuffer; 1.55 +static GrGLuint gCurrElementArrayBuffer; 1.56 + 1.57 +static GrBufferObj* look_up(GrGLuint id) { 1.58 + GrBufferObj* buffer = gBuffers[id]; 1.59 + SkASSERT(NULL != buffer && buffer->id() == id); 1.60 + return buffer; 1.61 +} 1.62 + 1.63 +static GrBufferObj* create_buffer() { 1.64 + if (0 == gBuffers.count()) { 1.65 + // slot zero is reserved for the head of the free list 1.66 + *gBuffers.append() = NULL; 1.67 + } 1.68 + 1.69 + GrGLuint id; 1.70 + GrBufferObj* buffer; 1.71 + 1.72 + if (NULL == gBuffers[0]) { 1.73 + // no free slots - create a new one 1.74 + id = gBuffers.count(); 1.75 + buffer = SkNEW_ARGS(GrBufferObj, (id)); 1.76 + gBuffers.append(1, &buffer); 1.77 + } else { 1.78 + // recycle a slot from the free list 1.79 + id = SkTCast<GrGLuint>(gBuffers[0]); 1.80 + gBuffers[0] = gBuffers[id]; 1.81 + 1.82 + buffer = SkNEW_ARGS(GrBufferObj, (id)); 1.83 + gBuffers[id] = buffer; 1.84 + } 1.85 + 1.86 + return buffer; 1.87 +} 1.88 + 1.89 +static void delete_buffer(GrBufferObj* buffer) { 1.90 + SkASSERT(gBuffers.count() > 0); 1.91 + 1.92 + GrGLuint id = buffer->id(); 1.93 + SkDELETE(buffer); 1.94 + 1.95 + // Add this slot to the free list 1.96 + gBuffers[id] = gBuffers[0]; 1.97 + gBuffers[0] = SkTCast<GrBufferObj*>((const void*)(intptr_t)id); 1.98 +} 1.99 + 1.100 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {} 1.101 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shader) {} 1.102 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {} 1.103 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint index, const char* name) {} 1.104 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture) {} 1.105 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindVertexArray(GrGLuint id) {} 1.106 + 1.107 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenBuffers(GrGLsizei n, GrGLuint* ids) { 1.108 + 1.109 + for (int i = 0; i < n; ++i) { 1.110 + GrBufferObj* buffer = create_buffer(); 1.111 + ids[i] = buffer->id(); 1.112 + } 1.113 +} 1.114 + 1.115 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenerateMipmap(GrGLenum target) {} 1.116 + 1.117 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target, 1.118 + GrGLsizeiptr size, 1.119 + const GrGLvoid* data, 1.120 + GrGLenum usage) { 1.121 + GrGLuint id = 0; 1.122 + 1.123 + switch (target) { 1.124 + case GR_GL_ARRAY_BUFFER: 1.125 + id = gCurrArrayBuffer; 1.126 + break; 1.127 + case GR_GL_ELEMENT_ARRAY_BUFFER: 1.128 + id = gCurrElementArrayBuffer; 1.129 + break; 1.130 + default: 1.131 + GrCrash("Unexpected target to nullGLBufferData"); 1.132 + break; 1.133 + } 1.134 + 1.135 + if (id > 0) { 1.136 + GrBufferObj* buffer = look_up(id); 1.137 + buffer->allocate(size, (const GrGLchar*) data); 1.138 + } 1.139 +} 1.140 + 1.141 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLPixelStorei(GrGLenum pname, GrGLint param) {} 1.142 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLReadPixels(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {} 1.143 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLUseProgram(GrGLuint program) {} 1.144 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLViewport(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height) {} 1.145 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindFramebuffer(GrGLenum target, GrGLuint framebuffer) {} 1.146 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindRenderbuffer(GrGLenum target, GrGLuint renderbuffer) {} 1.147 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteFramebuffers(GrGLsizei n, const GrGLuint *framebuffers) {} 1.148 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteRenderbuffers(GrGLsizei n, const GrGLuint *renderbuffers) {} 1.149 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferRenderbuffer(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer) {} 1.150 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level) {} 1.151 + 1.152 +GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateProgram() { 1.153 + static GrGLuint gCurrID = 0; 1.154 + return ++gCurrID; 1.155 +} 1.156 + 1.157 +GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateShader(GrGLenum type) { 1.158 + static GrGLuint gCurrID = 0; 1.159 + return ++gCurrID; 1.160 +} 1.161 + 1.162 +// same delete used for shaders and programs 1.163 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLDelete(GrGLuint program) { 1.164 +} 1.165 + 1.166 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer) { 1.167 + switch (target) { 1.168 + case GR_GL_ARRAY_BUFFER: 1.169 + gCurrArrayBuffer = buffer; 1.170 + break; 1.171 + case GR_GL_ELEMENT_ARRAY_BUFFER: 1.172 + gCurrElementArrayBuffer = buffer; 1.173 + break; 1.174 + } 1.175 +} 1.176 + 1.177 +// deleting a bound buffer has the side effect of binding 0 1.178 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteBuffers(GrGLsizei n, const GrGLuint* ids) { 1.179 + for (int i = 0; i < n; ++i) { 1.180 + if (ids[i] == gCurrArrayBuffer) { 1.181 + gCurrArrayBuffer = 0; 1.182 + } 1.183 + if (ids[i] == gCurrElementArrayBuffer) { 1.184 + gCurrElementArrayBuffer = 0; 1.185 + } 1.186 + 1.187 + GrBufferObj* buffer = look_up(ids[i]); 1.188 + delete_buffer(buffer); 1.189 + } 1.190 +} 1.191 + 1.192 +GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access) { 1.193 + 1.194 + GrGLuint id = 0; 1.195 + switch (target) { 1.196 + case GR_GL_ARRAY_BUFFER: 1.197 + id = gCurrArrayBuffer; 1.198 + break; 1.199 + case GR_GL_ELEMENT_ARRAY_BUFFER: 1.200 + id = gCurrElementArrayBuffer; 1.201 + break; 1.202 + } 1.203 + 1.204 + if (id > 0) { 1.205 + GrBufferObj* buffer = look_up(id); 1.206 + SkASSERT(!buffer->mapped()); 1.207 + buffer->setMapped(true); 1.208 + return buffer->dataPtr(); 1.209 + } 1.210 + 1.211 + SkASSERT(false); 1.212 + return NULL; // no buffer bound to target 1.213 +} 1.214 + 1.215 +GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { 1.216 + GrGLuint id = 0; 1.217 + switch (target) { 1.218 + case GR_GL_ARRAY_BUFFER: 1.219 + id = gCurrArrayBuffer; 1.220 + break; 1.221 + case GR_GL_ELEMENT_ARRAY_BUFFER: 1.222 + id = gCurrElementArrayBuffer; 1.223 + break; 1.224 + } 1.225 + if (id > 0) { 1.226 + GrBufferObj* buffer = look_up(id); 1.227 + SkASSERT(buffer->mapped()); 1.228 + buffer->setMapped(false); 1.229 + return GR_GL_TRUE; 1.230 + } 1.231 + 1.232 + GrAlwaysAssert(false); 1.233 + return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; 1.234 +} 1.235 + 1.236 +GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenum pname, GrGLint* params) { 1.237 + switch (pname) { 1.238 + case GR_GL_BUFFER_MAPPED: { 1.239 + *params = GR_GL_FALSE; 1.240 + GrGLuint id = 0; 1.241 + switch (target) { 1.242 + case GR_GL_ARRAY_BUFFER: 1.243 + id = gCurrArrayBuffer; 1.244 + break; 1.245 + case GR_GL_ELEMENT_ARRAY_BUFFER: 1.246 + id = gCurrElementArrayBuffer; 1.247 + break; 1.248 + } 1.249 + if (id > 0) { 1.250 + GrBufferObj* buffer = look_up(id); 1.251 + if (buffer->mapped()) { 1.252 + *params = GR_GL_TRUE; 1.253 + } 1.254 + } 1.255 + break; } 1.256 + default: 1.257 + GrCrash("Unexpected pname to GetBufferParamateriv"); 1.258 + break; 1.259 + } 1.260 +}; 1.261 + 1.262 +} // end anonymous namespace 1.263 + 1.264 +const GrGLInterface* GrGLCreateNullInterface() { 1.265 + GrGLInterface* interface = SkNEW(GrGLInterface); 1.266 + 1.267 + interface->fStandard = kGL_GrGLStandard; 1.268 + 1.269 + GrGLInterface::Functions* functions = &interface->fFunctions; 1.270 + functions->fActiveTexture = nullGLActiveTexture; 1.271 + functions->fAttachShader = nullGLAttachShader; 1.272 + functions->fBeginQuery = nullGLBeginQuery; 1.273 + functions->fBindAttribLocation = nullGLBindAttribLocation; 1.274 + functions->fBindBuffer = nullGLBindBuffer; 1.275 + functions->fBindFragDataLocation = noOpGLBindFragDataLocation; 1.276 + functions->fBindTexture = nullGLBindTexture; 1.277 + functions->fBindVertexArray = nullGLBindVertexArray; 1.278 + functions->fBlendColor = noOpGLBlendColor; 1.279 + functions->fBlendFunc = noOpGLBlendFunc; 1.280 + functions->fBufferData = nullGLBufferData; 1.281 + functions->fBufferSubData = noOpGLBufferSubData; 1.282 + functions->fClear = noOpGLClear; 1.283 + functions->fClearColor = noOpGLClearColor; 1.284 + functions->fClearStencil = noOpGLClearStencil; 1.285 + functions->fColorMask = noOpGLColorMask; 1.286 + functions->fCompileShader = noOpGLCompileShader; 1.287 + functions->fCompressedTexImage2D = noOpGLCompressedTexImage2D; 1.288 + functions->fCopyTexSubImage2D = noOpGLCopyTexSubImage2D; 1.289 + functions->fCreateProgram = nullGLCreateProgram; 1.290 + functions->fCreateShader = nullGLCreateShader; 1.291 + functions->fCullFace = noOpGLCullFace; 1.292 + functions->fDeleteBuffers = nullGLDeleteBuffers; 1.293 + functions->fDeleteProgram = nullGLDelete; 1.294 + functions->fDeleteQueries = noOpGLDeleteIds; 1.295 + functions->fDeleteShader = nullGLDelete; 1.296 + functions->fDeleteTextures = noOpGLDeleteIds; 1.297 + functions->fDeleteVertexArrays = noOpGLDeleteIds; 1.298 + functions->fDepthMask = noOpGLDepthMask; 1.299 + functions->fDisable = noOpGLDisable; 1.300 + functions->fDisableVertexAttribArray = noOpGLDisableVertexAttribArray; 1.301 + functions->fDrawArrays = noOpGLDrawArrays; 1.302 + functions->fDrawBuffer = noOpGLDrawBuffer; 1.303 + functions->fDrawBuffers = noOpGLDrawBuffers; 1.304 + functions->fDrawElements = noOpGLDrawElements; 1.305 + functions->fEnable = noOpGLEnable; 1.306 + functions->fEnableVertexAttribArray = noOpGLEnableVertexAttribArray; 1.307 + functions->fEndQuery = noOpGLEndQuery; 1.308 + functions->fFinish = noOpGLFinish; 1.309 + functions->fFlush = noOpGLFlush; 1.310 + functions->fFrontFace = noOpGLFrontFace; 1.311 + functions->fGenBuffers = nullGLGenBuffers; 1.312 + functions->fGenerateMipmap = nullGLGenerateMipmap; 1.313 + functions->fGenQueries = noOpGLGenIds; 1.314 + functions->fGenTextures = noOpGLGenIds; 1.315 + functions->fGenVertexArrays = noOpGLGenIds; 1.316 + functions->fGetBufferParameteriv = nullGLGetBufferParameteriv; 1.317 + functions->fGetError = noOpGLGetError; 1.318 + functions->fGetIntegerv = noOpGLGetIntegerv; 1.319 + functions->fGetQueryObjecti64v = noOpGLGetQueryObjecti64v; 1.320 + functions->fGetQueryObjectiv = noOpGLGetQueryObjectiv; 1.321 + functions->fGetQueryObjectui64v = noOpGLGetQueryObjectui64v; 1.322 + functions->fGetQueryObjectuiv = noOpGLGetQueryObjectuiv; 1.323 + functions->fGetQueryiv = noOpGLGetQueryiv; 1.324 + functions->fGetProgramInfoLog = noOpGLGetInfoLog; 1.325 + functions->fGetProgramiv = noOpGLGetShaderOrProgramiv; 1.326 + functions->fGetShaderInfoLog = noOpGLGetInfoLog; 1.327 + functions->fGetShaderiv = noOpGLGetShaderOrProgramiv; 1.328 + functions->fGetString = noOpGLGetString; 1.329 + functions->fGetStringi = noOpGLGetStringi; 1.330 + functions->fGetTexLevelParameteriv = noOpGLGetTexLevelParameteriv; 1.331 + functions->fGetUniformLocation = noOpGLGetUniformLocation; 1.332 + functions->fInsertEventMarker = noOpGLInsertEventMarker; 1.333 + functions->fLoadIdentity = noOpGLLoadIdentity; 1.334 + functions->fLoadMatrixf = noOpGLLoadMatrixf; 1.335 + functions->fLineWidth = noOpGLLineWidth; 1.336 + functions->fLinkProgram = noOpGLLinkProgram; 1.337 + functions->fMatrixMode = noOpGLMatrixMode; 1.338 + functions->fPixelStorei = nullGLPixelStorei; 1.339 + functions->fPopGroupMarker = noOpGLPopGroupMarker; 1.340 + functions->fPushGroupMarker = noOpGLPushGroupMarker; 1.341 + functions->fQueryCounter = noOpGLQueryCounter; 1.342 + functions->fReadBuffer = noOpGLReadBuffer; 1.343 + functions->fReadPixels = nullGLReadPixels; 1.344 + functions->fScissor = noOpGLScissor; 1.345 + functions->fShaderSource = noOpGLShaderSource; 1.346 + functions->fStencilFunc = noOpGLStencilFunc; 1.347 + functions->fStencilFuncSeparate = noOpGLStencilFuncSeparate; 1.348 + functions->fStencilMask = noOpGLStencilMask; 1.349 + functions->fStencilMaskSeparate = noOpGLStencilMaskSeparate; 1.350 + functions->fStencilOp = noOpGLStencilOp; 1.351 + functions->fStencilOpSeparate = noOpGLStencilOpSeparate; 1.352 + functions->fTexGenfv = noOpGLTexGenfv; 1.353 + functions->fTexGeni = noOpGLTexGeni; 1.354 + functions->fTexImage2D = noOpGLTexImage2D; 1.355 + functions->fTexParameteri = noOpGLTexParameteri; 1.356 + functions->fTexParameteriv = noOpGLTexParameteriv; 1.357 + functions->fTexSubImage2D = noOpGLTexSubImage2D; 1.358 + functions->fTexStorage2D = noOpGLTexStorage2D; 1.359 + functions->fDiscardFramebuffer = noOpGLDiscardFramebuffer; 1.360 + functions->fUniform1f = noOpGLUniform1f; 1.361 + functions->fUniform1i = noOpGLUniform1i; 1.362 + functions->fUniform1fv = noOpGLUniform1fv; 1.363 + functions->fUniform1iv = noOpGLUniform1iv; 1.364 + functions->fUniform2f = noOpGLUniform2f; 1.365 + functions->fUniform2i = noOpGLUniform2i; 1.366 + functions->fUniform2fv = noOpGLUniform2fv; 1.367 + functions->fUniform2iv = noOpGLUniform2iv; 1.368 + functions->fUniform3f = noOpGLUniform3f; 1.369 + functions->fUniform3i = noOpGLUniform3i; 1.370 + functions->fUniform3fv = noOpGLUniform3fv; 1.371 + functions->fUniform3iv = noOpGLUniform3iv; 1.372 + functions->fUniform4f = noOpGLUniform4f; 1.373 + functions->fUniform4i = noOpGLUniform4i; 1.374 + functions->fUniform4fv = noOpGLUniform4fv; 1.375 + functions->fUniform4iv = noOpGLUniform4iv; 1.376 + functions->fUniformMatrix2fv = noOpGLUniformMatrix2fv; 1.377 + functions->fUniformMatrix3fv = noOpGLUniformMatrix3fv; 1.378 + functions->fUniformMatrix4fv = noOpGLUniformMatrix4fv; 1.379 + functions->fUseProgram = nullGLUseProgram; 1.380 + functions->fVertexAttrib4fv = noOpGLVertexAttrib4fv; 1.381 + functions->fVertexAttribPointer = noOpGLVertexAttribPointer; 1.382 + functions->fViewport = nullGLViewport; 1.383 + functions->fBindFramebuffer = nullGLBindFramebuffer; 1.384 + functions->fBindRenderbuffer = nullGLBindRenderbuffer; 1.385 + functions->fCheckFramebufferStatus = noOpGLCheckFramebufferStatus; 1.386 + functions->fDeleteFramebuffers = nullGLDeleteFramebuffers; 1.387 + functions->fDeleteRenderbuffers = nullGLDeleteRenderbuffers; 1.388 + functions->fFramebufferRenderbuffer = nullGLFramebufferRenderbuffer; 1.389 + functions->fFramebufferTexture2D = nullGLFramebufferTexture2D; 1.390 + functions->fGenFramebuffers = noOpGLGenIds; 1.391 + functions->fGenRenderbuffers = noOpGLGenIds; 1.392 + functions->fGetFramebufferAttachmentParameteriv = noOpGLGetFramebufferAttachmentParameteriv; 1.393 + functions->fGetRenderbufferParameteriv = noOpGLGetRenderbufferParameteriv; 1.394 + functions->fRenderbufferStorage = noOpGLRenderbufferStorage; 1.395 + functions->fRenderbufferStorageMultisample = noOpGLRenderbufferStorageMultisample; 1.396 + functions->fBlitFramebuffer = noOpGLBlitFramebuffer; 1.397 + functions->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFramebuffer; 1.398 + functions->fMapBuffer = nullGLMapBuffer; 1.399 + functions->fUnmapBuffer = nullGLUnmapBuffer; 1.400 + functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed; 1.401 + 1.402 + interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functions->fGetStringi, 1.403 + functions->fGetIntegerv); 1.404 + return interface; 1.405 +}