| 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 #include "SkTLS.h" | 13 #include "SkTLS.h" |
| 14 | 14 |
| 15 // TODO: Delete this file after chrome starts using SkNullGLContext. | 15 // TODO: Delete this file after chrome starts using SkNullGLContext. |
| 16 | 16 |
| 17 // added to suppress 'no previous prototype' warning and because this code is du
plicated in | 17 // added to suppress 'no previous prototype' warning and because this code is du
plicated in |
| 18 // SkNullGLContext.cpp | 18 // SkNullGLContext.cpp |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class BufferObj { | 21 class BufferObj { |
| 22 public: | 22 public: |
| 23 | 23 |
| 24 | 24 |
| 25 BufferObj(GrGLuint id) : fID(id), fDataPtr(NULL), fSize(0), fMapped(false) { | 25 BufferObj(GrGLuint id) : fID(id), fDataPtr(NULL), fSize(0), fMapped(false) { |
| 26 } | 26 } |
| 27 ~BufferObj() { SkDELETE_ARRAY(fDataPtr); } | 27 ~BufferObj() { delete[] fDataPtr; } |
| 28 | 28 |
| 29 void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) { | 29 void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) { |
| 30 if (fDataPtr) { | 30 if (fDataPtr) { |
| 31 SkASSERT(0 != fSize); | 31 SkASSERT(0 != fSize); |
| 32 SkDELETE_ARRAY(fDataPtr); | 32 delete[] fDataPtr; |
| 33 } | 33 } |
| 34 | 34 |
| 35 fSize = size; | 35 fSize = size; |
| 36 fDataPtr = SkNEW_ARRAY(char, size); | 36 fDataPtr = new char[size]; |
| 37 } | 37 } |
| 38 | 38 |
| 39 GrGLuint id() const { return fID; } | 39 GrGLuint id() const { return fID; } |
| 40 GrGLchar* dataPtr() { return fDataPtr; } | 40 GrGLchar* dataPtr() { return fDataPtr; } |
| 41 GrGLsizeiptr size() const { return fSize; } | 41 GrGLsizeiptr size() const { return fSize; } |
| 42 | 42 |
| 43 void setMapped(bool mapped) { fMapped = mapped; } | 43 void setMapped(bool mapped) { fMapped = mapped; } |
| 44 bool mapped() const { return fMapped; } | 44 bool mapped() const { return fMapped; } |
| 45 | 45 |
| 46 private: | 46 private: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 75 return buffer; | 75 return buffer; |
| 76 } | 76 } |
| 77 | 77 |
| 78 BufferObj* create() { | 78 BufferObj* create() { |
| 79 GrGLuint id; | 79 GrGLuint id; |
| 80 BufferObj* buffer; | 80 BufferObj* buffer; |
| 81 | 81 |
| 82 if (kFreeListEnd == fFreeListHead) { | 82 if (kFreeListEnd == fFreeListHead) { |
| 83 // no free slots - create a new one | 83 // no free slots - create a new one |
| 84 id = fBuffers.count(); | 84 id = fBuffers.count(); |
| 85 buffer = SkNEW_ARGS(BufferObj, (id)); | 85 buffer = new BufferObj(id); |
| 86 *fBuffers.append() = buffer; | 86 *fBuffers.append() = buffer; |
| 87 } else { | 87 } else { |
| 88 // grab the head of the free list and advance the head to the next f
ree slot. | 88 // grab the head of the free list and advance the head to the next f
ree slot. |
| 89 id = static_cast<GrGLuint>(fFreeListHead); | 89 id = static_cast<GrGLuint>(fFreeListHead); |
| 90 fFreeListHead = reinterpret_cast<intptr_t>(fBuffers[id]); | 90 fFreeListHead = reinterpret_cast<intptr_t>(fBuffers[id]); |
| 91 | 91 |
| 92 buffer = SkNEW_ARGS(BufferObj, (id)); | 92 buffer = new BufferObj(id); |
| 93 fBuffers[id] = buffer; | 93 fBuffers[id] = buffer; |
| 94 } | 94 } |
| 95 | 95 |
| 96 return buffer; | 96 return buffer; |
| 97 } | 97 } |
| 98 | 98 |
| 99 void free(BufferObj* buffer) { | 99 void free(BufferObj* buffer) { |
| 100 SkASSERT(fBuffers.count() > 0); | 100 SkASSERT(fBuffers.count() > 0); |
| 101 | 101 |
| 102 GrGLuint id = buffer->id(); | 102 GrGLuint id = buffer->id(); |
| 103 SkDELETE(buffer); | 103 delete buffer; |
| 104 | 104 |
| 105 fBuffers[id] = reinterpret_cast<BufferObj*>(fFreeListHead); | 105 fBuffers[id] = reinterpret_cast<BufferObj*>(fFreeListHead); |
| 106 fFreeListHead = id; | 106 fFreeListHead = id; |
| 107 } | 107 } |
| 108 | 108 |
| 109 private: | 109 private: |
| 110 static const intptr_t kFreeListEnd = -1; | 110 static const intptr_t kFreeListEnd = -1; |
| 111 // Index of the first entry of fBuffers in the free list. Free slots in fBuf
fers are indices to | 111 // Index of the first entry of fBuffers in the free list. Free slots in fBuf
fers are indices to |
| 112 // the next free slot. The last free slot has a value of kFreeListEnd. | 112 // the next free slot. The last free slot has a value of kFreeListEnd. |
| 113 intptr_t fFreeListHead; | 113 intptr_t fFreeListHead; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 134 return reinterpret_cast<ThreadContext*>(SkTLS::Get(Create, Delete)); | 134 return reinterpret_cast<ThreadContext*>(SkTLS::Get(Create, Delete)); |
| 135 } | 135 } |
| 136 | 136 |
| 137 ThreadContext() | 137 ThreadContext() |
| 138 : fCurrArrayBuffer(0) | 138 : fCurrArrayBuffer(0) |
| 139 , fCurrElementArrayBuffer(0) | 139 , fCurrElementArrayBuffer(0) |
| 140 , fCurrProgramID(0) | 140 , fCurrProgramID(0) |
| 141 , fCurrShaderID(0) {} | 141 , fCurrShaderID(0) {} |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 static void* Create() { return SkNEW(ThreadContext ); } | 144 static void* Create() { return new ThreadContext; } |
| 145 static void Delete(void* context) { SkDELETE(reinterpret_cast<ThreadContext
*>(context)); } | 145 static void Delete(void* context) { delete reinterpret_cast<ThreadContext*>(
context); } |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 // Functions not declared in GrGLBogusInterface.h (not common with the Debug GL
interface). | 148 // Functions not declared in GrGLBogusInterface.h (not common with the Debug GL
interface). |
| 149 | 149 |
| 150 GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {} | 150 GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {} |
| 151 GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shade
r) {} | 151 GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shade
r) {} |
| 152 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {} | 152 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {} |
| 153 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint
index, const char* name) {} | 153 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint
index, const char* name) {} |
| 154 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture
) {} | 154 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture
) {} |
| 155 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindVertexArray(GrGLuint id) {} | 155 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindVertexArray(GrGLuint id) {} |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 break; } | 336 break; } |
| 337 default: | 337 default: |
| 338 SkFAIL("Unexpected pname to GetBufferParamateriv"); | 338 SkFAIL("Unexpected pname to GetBufferParamateriv"); |
| 339 break; | 339 break; |
| 340 } | 340 } |
| 341 }; | 341 }; |
| 342 | 342 |
| 343 } // end anonymous namespace | 343 } // end anonymous namespace |
| 344 | 344 |
| 345 const GrGLInterface* GrGLCreateNullInterface() { | 345 const GrGLInterface* GrGLCreateNullInterface() { |
| 346 GrGLInterface* interface = SkNEW(GrGLInterface); | 346 GrGLInterface* interface = new GrGLInterface; |
| 347 | 347 |
| 348 interface->fStandard = kGL_GrGLStandard; | 348 interface->fStandard = kGL_GrGLStandard; |
| 349 | 349 |
| 350 GrGLInterface::Functions* functions = &interface->fFunctions; | 350 GrGLInterface::Functions* functions = &interface->fFunctions; |
| 351 functions->fActiveTexture = nullGLActiveTexture; | 351 functions->fActiveTexture = nullGLActiveTexture; |
| 352 functions->fAttachShader = nullGLAttachShader; | 352 functions->fAttachShader = nullGLAttachShader; |
| 353 functions->fBeginQuery = nullGLBeginQuery; | 353 functions->fBeginQuery = nullGLBeginQuery; |
| 354 functions->fBindAttribLocation = nullGLBindAttribLocation; | 354 functions->fBindAttribLocation = nullGLBindAttribLocation; |
| 355 functions->fBindBuffer = nullGLBindBuffer; | 355 functions->fBindBuffer = nullGLBindBuffer; |
| 356 functions->fBindFragDataLocation = noOpGLBindFragDataLocation; | 356 functions->fBindFragDataLocation = noOpGLBindFragDataLocation; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 functions->fBlitFramebuffer = noOpGLBlitFramebuffer; | 484 functions->fBlitFramebuffer = noOpGLBlitFramebuffer; |
| 485 functions->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFramebuf
fer; | 485 functions->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFramebuf
fer; |
| 486 functions->fMatrixLoadf = noOpGLMatrixLoadf; | 486 functions->fMatrixLoadf = noOpGLMatrixLoadf; |
| 487 functions->fMatrixLoadIdentity = noOpGLMatrixLoadIdentity; | 487 functions->fMatrixLoadIdentity = noOpGLMatrixLoadIdentity; |
| 488 functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed; | 488 functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed; |
| 489 | 489 |
| 490 interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functio
ns->fGetStringi, | 490 interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functio
ns->fGetStringi, |
| 491 functions->fGetIntegerv); | 491 functions->fGetIntegerv); |
| 492 return interface; | 492 return interface; |
| 493 } | 493 } |
| OLD | NEW |