| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "gl/GrGLInterface.h" | 9 #include "gl/GrGLInterface.h" |
| 10 #include "GrGLDefines.h" | 10 #include "GrGLDefines.h" |
| 11 #include "SkTDArray.h" | 11 #include "SkTDArray.h" |
| 12 #include "GrGLNoOpInterface.h" | 12 #include "GrGLNoOpInterface.h" |
| 13 | 13 |
| 14 // Functions not declared in GrGLBogusInterface.h (not common with the Debug GL
interface). | 14 // Functions not declared in GrGLBogusInterface.h (not common with the Debug GL
interface). |
| 15 | 15 |
| 16 namespace { // added to suppress 'no previous prototype' warning | 16 namespace { // added to suppress 'no previous prototype' warning |
| 17 | 17 |
| 18 class GrBufferObj { | 18 class GrBufferObj { |
| 19 public: | 19 public: |
| 20 GrBufferObj(GrGLuint id) : fID(id), fDataPtr(NULL), fSize(0), fMapped(false)
{ | 20 GrBufferObj(GrGLuint id) : fID(id), fDataPtr(NULL), fSize(0), fMapped(false)
{ |
| 21 } | 21 } |
| 22 ~GrBufferObj() { SkDELETE_ARRAY(fDataPtr); } | 22 ~GrBufferObj() { SkDELETE_ARRAY(fDataPtr); } |
| 23 | 23 |
| 24 void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) { | 24 void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) { |
| 25 if (NULL != fDataPtr) { | 25 if (NULL != fDataPtr) { |
| 26 GrAssert(0 != fSize); | 26 SkASSERT(0 != fSize); |
| 27 SkDELETE_ARRAY(fDataPtr); | 27 SkDELETE_ARRAY(fDataPtr); |
| 28 } | 28 } |
| 29 | 29 |
| 30 fSize = size; | 30 fSize = size; |
| 31 fDataPtr = SkNEW_ARRAY(char, size); | 31 fDataPtr = SkNEW_ARRAY(char, size); |
| 32 } | 32 } |
| 33 | 33 |
| 34 GrGLuint id() const { return fID; } | 34 GrGLuint id() const { return fID; } |
| 35 GrGLchar* dataPtr() { return fDataPtr; } | 35 GrGLchar* dataPtr() { return fDataPtr; } |
| 36 GrGLsizeiptr size() const { return fSize; } | 36 GrGLsizeiptr size() const { return fSize; } |
| 37 | 37 |
| 38 void setMapped(bool mapped) { fMapped = mapped; } | 38 void setMapped(bool mapped) { fMapped = mapped; } |
| 39 bool mapped() const { return fMapped; } | 39 bool mapped() const { return fMapped; } |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 GrGLuint fID; | 42 GrGLuint fID; |
| 43 GrGLchar* fDataPtr; | 43 GrGLchar* fDataPtr; |
| 44 GrGLsizeiptr fSize; // size in bytes | 44 GrGLsizeiptr fSize; // size in bytes |
| 45 bool fMapped; | 45 bool fMapped; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 // In debug builds we do asserts that ensure we agree with GL about when a buffe
r | 48 // In debug builds we do asserts that ensure we agree with GL about when a buffe
r |
| 49 // is mapped. | 49 // is mapped. |
| 50 static SkTDArray<GrBufferObj*> gBuffers; // slot 0 is reserved for head of free
list | 50 static SkTDArray<GrBufferObj*> gBuffers; // slot 0 is reserved for head of free
list |
| 51 static GrGLuint gCurrArrayBuffer; | 51 static GrGLuint gCurrArrayBuffer; |
| 52 static GrGLuint gCurrElementArrayBuffer; | 52 static GrGLuint gCurrElementArrayBuffer; |
| 53 | 53 |
| 54 static GrBufferObj* look_up(GrGLuint id) { | 54 static GrBufferObj* look_up(GrGLuint id) { |
| 55 GrBufferObj* buffer = gBuffers[id]; | 55 GrBufferObj* buffer = gBuffers[id]; |
| 56 GrAssert(NULL != buffer && buffer->id() == id); | 56 SkASSERT(NULL != buffer && buffer->id() == id); |
| 57 return buffer; | 57 return buffer; |
| 58 } | 58 } |
| 59 | 59 |
| 60 static GrBufferObj* create_buffer() { | 60 static GrBufferObj* create_buffer() { |
| 61 if (0 == gBuffers.count()) { | 61 if (0 == gBuffers.count()) { |
| 62 // slot zero is reserved for the head of the free list | 62 // slot zero is reserved for the head of the free list |
| 63 *gBuffers.append() = NULL; | 63 *gBuffers.append() = NULL; |
| 64 } | 64 } |
| 65 | 65 |
| 66 GrGLuint id; | 66 GrGLuint id; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 77 gBuffers[0] = gBuffers[id]; | 77 gBuffers[0] = gBuffers[id]; |
| 78 | 78 |
| 79 buffer = SkNEW_ARGS(GrBufferObj, (id)); | 79 buffer = SkNEW_ARGS(GrBufferObj, (id)); |
| 80 gBuffers[id] = buffer; | 80 gBuffers[id] = buffer; |
| 81 } | 81 } |
| 82 | 82 |
| 83 return buffer; | 83 return buffer; |
| 84 } | 84 } |
| 85 | 85 |
| 86 static void delete_buffer(GrBufferObj* buffer) { | 86 static void delete_buffer(GrBufferObj* buffer) { |
| 87 GrAssert(gBuffers.count() > 0); | 87 SkASSERT(gBuffers.count() > 0); |
| 88 | 88 |
| 89 GrGLuint id = buffer->id(); | 89 GrGLuint id = buffer->id(); |
| 90 SkDELETE(buffer); | 90 SkDELETE(buffer); |
| 91 | 91 |
| 92 // Add this slot to the free list | 92 // Add this slot to the free list |
| 93 gBuffers[id] = gBuffers[0]; | 93 gBuffers[id] = gBuffers[0]; |
| 94 gBuffers[0] = SkTCast<GrBufferObj*>((const void*)(intptr_t)id); | 94 gBuffers[0] = SkTCast<GrBufferObj*>((const void*)(intptr_t)id); |
| 95 } | 95 } |
| 96 | 96 |
| 97 GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {} | 97 GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {} |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 case GR_GL_ARRAY_BUFFER: | 193 case GR_GL_ARRAY_BUFFER: |
| 194 id = gCurrArrayBuffer; | 194 id = gCurrArrayBuffer; |
| 195 break; | 195 break; |
| 196 case GR_GL_ELEMENT_ARRAY_BUFFER: | 196 case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 197 id = gCurrElementArrayBuffer; | 197 id = gCurrElementArrayBuffer; |
| 198 break; | 198 break; |
| 199 } | 199 } |
| 200 | 200 |
| 201 if (id > 0) { | 201 if (id > 0) { |
| 202 GrBufferObj* buffer = look_up(id); | 202 GrBufferObj* buffer = look_up(id); |
| 203 GrAssert(!buffer->mapped()); | 203 SkASSERT(!buffer->mapped()); |
| 204 buffer->setMapped(true); | 204 buffer->setMapped(true); |
| 205 return buffer->dataPtr(); | 205 return buffer->dataPtr(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 GrAssert(false); | 208 SkASSERT(false); |
| 209 return NULL; // no buffer bound to target | 209 return NULL; // no buffer bound to target |
| 210 } | 210 } |
| 211 | 211 |
| 212 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { | 212 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { |
| 213 GrGLuint id = 0; | 213 GrGLuint id = 0; |
| 214 switch (target) { | 214 switch (target) { |
| 215 case GR_GL_ARRAY_BUFFER: | 215 case GR_GL_ARRAY_BUFFER: |
| 216 id = gCurrArrayBuffer; | 216 id = gCurrArrayBuffer; |
| 217 break; | 217 break; |
| 218 case GR_GL_ELEMENT_ARRAY_BUFFER: | 218 case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 219 id = gCurrElementArrayBuffer; | 219 id = gCurrElementArrayBuffer; |
| 220 break; | 220 break; |
| 221 } | 221 } |
| 222 if (id > 0) { | 222 if (id > 0) { |
| 223 GrBufferObj* buffer = look_up(id); | 223 GrBufferObj* buffer = look_up(id); |
| 224 GrAssert(buffer->mapped()); | 224 SkASSERT(buffer->mapped()); |
| 225 buffer->setMapped(false); | 225 buffer->setMapped(false); |
| 226 return GR_GL_TRUE; | 226 return GR_GL_TRUE; |
| 227 } | 227 } |
| 228 | 228 |
| 229 GrAlwaysAssert(false); | 229 GrAlwaysAssert(false); |
| 230 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; | 230 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; |
| 231 } | 231 } |
| 232 | 232 |
| 233 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenu
m pname, GrGLint* params) { | 233 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenu
m pname, GrGLint* params) { |
| 234 switch (pname) { | 234 switch (pname) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 interface->fRenderbufferStorageMultisample = noOpGLRenderbufferStorageMu
ltisample; | 386 interface->fRenderbufferStorageMultisample = noOpGLRenderbufferStorageMu
ltisample; |
| 387 interface->fBlitFramebuffer = noOpGLBlitFramebuffer; | 387 interface->fBlitFramebuffer = noOpGLBlitFramebuffer; |
| 388 interface->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFram
ebuffer; | 388 interface->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFram
ebuffer; |
| 389 interface->fMapBuffer = nullGLMapBuffer; | 389 interface->fMapBuffer = nullGLMapBuffer; |
| 390 interface->fUnmapBuffer = nullGLUnmapBuffer; | 390 interface->fUnmapBuffer = nullGLUnmapBuffer; |
| 391 interface->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationInde
xed; | 391 interface->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationInde
xed; |
| 392 } | 392 } |
| 393 glInterface.get()->ref(); | 393 glInterface.get()->ref(); |
| 394 return glInterface.get(); | 394 return glInterface.get(); |
| 395 } | 395 } |
| OLD | NEW |