| 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(nullptr), fSize(0), fMapped(false
) { |
| 26 } | 26 } |
| 27 ~BufferObj() { delete[] 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 delete[] fDataPtr; | 32 delete[] fDataPtr; |
| 33 } | 33 } |
| 34 | 34 |
| 35 fSize = size; | 35 fSize = size; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 // This class maintains a sparsely populated array of buffer pointers. | 53 // This class maintains a sparsely populated array of buffer pointers. |
| 54 class BufferManager { | 54 class BufferManager { |
| 55 public: | 55 public: |
| 56 | 56 |
| 57 | 57 |
| 58 BufferManager() : fFreeListHead(kFreeListEnd) {} | 58 BufferManager() : fFreeListHead(kFreeListEnd) {} |
| 59 | 59 |
| 60 ~BufferManager() { | 60 ~BufferManager() { |
| 61 // NULL out the entries that are really free list links rather than ptrs
before deleting. | 61 // nullptr out the entries that are really free list links rather than p
trs before deleting. |
| 62 intptr_t curr = fFreeListHead; | 62 intptr_t curr = fFreeListHead; |
| 63 while (kFreeListEnd != curr) { | 63 while (kFreeListEnd != curr) { |
| 64 intptr_t next = reinterpret_cast<intptr_t>(fBuffers[SkToS32(curr)]); | 64 intptr_t next = reinterpret_cast<intptr_t>(fBuffers[SkToS32(curr)]); |
| 65 fBuffers[SkToS32(curr)] = NULL; | 65 fBuffers[SkToS32(curr)] = nullptr; |
| 66 curr = next; | 66 curr = next; |
| 67 } | 67 } |
| 68 | 68 |
| 69 fBuffers.deleteAll(); | 69 fBuffers.deleteAll(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 BufferObj* lookUp(GrGLuint id) { | 72 BufferObj* lookUp(GrGLuint id) { |
| 73 BufferObj* buffer = fBuffers[id]; | 73 BufferObj* buffer = fBuffers[id]; |
| 74 SkASSERT(buffer && buffer->id() == id); | 74 SkASSERT(buffer && buffer->id() == id); |
| 75 return buffer; | 75 return buffer; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 break; | 253 break; |
| 254 } | 254 } |
| 255 | 255 |
| 256 if (id > 0) { | 256 if (id > 0) { |
| 257 // We just ignore the offset and length here. | 257 // We just ignore the offset and length here. |
| 258 BufferObj* buffer = ctx->fBufferManager.lookUp(id); | 258 BufferObj* buffer = ctx->fBufferManager.lookUp(id); |
| 259 SkASSERT(!buffer->mapped()); | 259 SkASSERT(!buffer->mapped()); |
| 260 buffer->setMapped(true); | 260 buffer->setMapped(true); |
| 261 return buffer->dataPtr(); | 261 return buffer->dataPtr(); |
| 262 } | 262 } |
| 263 return NULL; | 263 return nullptr; |
| 264 } | 264 } |
| 265 | 265 |
| 266 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access)
{ | 266 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access)
{ |
| 267 ThreadContext* ctx = ThreadContext::Get(); | 267 ThreadContext* ctx = ThreadContext::Get(); |
| 268 GrGLuint id = 0; | 268 GrGLuint id = 0; |
| 269 switch (target) { | 269 switch (target) { |
| 270 case GR_GL_ARRAY_BUFFER: | 270 case GR_GL_ARRAY_BUFFER: |
| 271 id = ctx->fCurrArrayBuffer; | 271 id = ctx->fCurrArrayBuffer; |
| 272 break; | 272 break; |
| 273 case GR_GL_ELEMENT_ARRAY_BUFFER: | 273 case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 274 id = ctx->fCurrElementArrayBuffer; | 274 id = ctx->fCurrElementArrayBuffer; |
| 275 break; | 275 break; |
| 276 } | 276 } |
| 277 | 277 |
| 278 if (id > 0) { | 278 if (id > 0) { |
| 279 BufferObj* buffer = ctx->fBufferManager.lookUp(id); | 279 BufferObj* buffer = ctx->fBufferManager.lookUp(id); |
| 280 SkASSERT(!buffer->mapped()); | 280 SkASSERT(!buffer->mapped()); |
| 281 buffer->setMapped(true); | 281 buffer->setMapped(true); |
| 282 return buffer->dataPtr(); | 282 return buffer->dataPtr(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 SkASSERT(false); | 285 SkASSERT(false); |
| 286 return NULL; // no buffer bound to target | 286 return nullptr; // no buffer bound to target |
| 287 } | 287 } |
| 288 | 288 |
| 289 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFlushMappedBufferRange(GrGLenum target, | 289 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFlushMappedBufferRange(GrGLenum target, |
| 290 GrGLintptr offset, | 290 GrGLintptr offset, |
| 291 GrGLsizeiptr length) {
} | 291 GrGLsizeiptr length) {
} |
| 292 | 292 |
| 293 | 293 |
| 294 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { | 294 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { |
| 295 ThreadContext* ctx = ThreadContext::Get(); | 295 ThreadContext* ctx = ThreadContext::Get(); |
| 296 GrGLuint id = 0; | 296 GrGLuint id = 0; |
| (...skipping 187 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 |