Chromium Code Reviews| 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 | 14 |
| 14 // Functions not declared in GrGLBogusInterface.h (not common with the Debug GL interface). | 15 class BufferObj { |
| 16 public: | |
| 17 SK_DECLARE_INST_COUNT_ROOT(BufferObj); | |
| 15 | 18 |
| 16 namespace { // added to suppress 'no previous prototype' warning | 19 BufferObj(GrGLuint id) : fID(id), fDataPtr(NULL), fSize(0), fMapped(false) { |
| 17 | |
| 18 class GrBufferObj { | |
| 19 public: | |
| 20 GrBufferObj(GrGLuint id) : fID(id), fDataPtr(NULL), fSize(0), fMapped(false) { | |
| 21 } | 20 } |
| 22 ~GrBufferObj() { SkDELETE_ARRAY(fDataPtr); } | 21 ~BufferObj() { SkDELETE_ARRAY(fDataPtr); } |
| 23 | 22 |
| 24 void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) { | 23 void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) { |
| 25 if (NULL != fDataPtr) { | 24 if (NULL != fDataPtr) { |
| 26 SkASSERT(0 != fSize); | 25 SkASSERT(0 != fSize); |
| 27 SkDELETE_ARRAY(fDataPtr); | 26 SkDELETE_ARRAY(fDataPtr); |
| 28 } | 27 } |
| 29 | 28 |
| 30 fSize = size; | 29 fSize = size; |
| 31 fDataPtr = SkNEW_ARRAY(char, size); | 30 fDataPtr = SkNEW_ARRAY(char, size); |
| 32 } | 31 } |
| 33 | 32 |
| 34 GrGLuint id() const { return fID; } | 33 GrGLuint id() const { return fID; } |
| 35 GrGLchar* dataPtr() { return fDataPtr; } | 34 GrGLchar* dataPtr() { return fDataPtr; } |
| 36 GrGLsizeiptr size() const { return fSize; } | 35 GrGLsizeiptr size() const { return fSize; } |
| 37 | 36 |
| 38 void setMapped(bool mapped) { fMapped = mapped; } | 37 void setMapped(bool mapped) { fMapped = mapped; } |
| 39 bool mapped() const { return fMapped; } | 38 bool mapped() const { return fMapped; } |
| 40 | 39 |
| 41 private: | 40 private: |
| 42 GrGLuint fID; | 41 GrGLuint fID; |
| 43 GrGLchar* fDataPtr; | 42 GrGLchar* fDataPtr; |
| 44 GrGLsizeiptr fSize; // size in bytes | 43 GrGLsizeiptr fSize; // size in bytes |
| 45 bool fMapped; | 44 bool fMapped; |
| 46 }; | 45 }; |
| 47 | 46 |
|
robertphillips
2014/08/14 14:10:17
// This class maintains a sparsely populated array
bsalomon
2014/08/14 14:52:08
Acknowledged.
| |
| 48 // In debug builds we do asserts that ensure we agree with GL about when a buffe r | 47 class BufferManager { |
| 49 // is mapped. | 48 public: |
| 50 static SkTDArray<GrBufferObj*> gBuffers; // slot 0 is reserved for head of free list | 49 SK_DECLARE_INST_COUNT_ROOT(BufferManager); |
| 51 static GrGLuint gCurrArrayBuffer; | |
| 52 static GrGLuint gCurrElementArrayBuffer; | |
| 53 | 50 |
| 54 static GrBufferObj* look_up(GrGLuint id) { | 51 BufferManager() : fFreeListHead(kFreeListEnd) {} |
| 55 GrBufferObj* buffer = gBuffers[id]; | |
| 56 SkASSERT(NULL != buffer && buffer->id() == id); | |
| 57 return buffer; | |
| 58 } | |
| 59 | 52 |
| 60 static GrBufferObj* create_buffer() { | 53 ~BufferManager() { |
| 61 if (0 == gBuffers.count()) { | 54 // NULL out the entries that are really free list links rather than ptrs before deleting. |
| 62 // slot zero is reserved for the head of the free list | 55 int curr = fFreeListHead; |
| 63 *gBuffers.append() = NULL; | 56 while (kFreeListEnd != curr) { |
| 57 int next = reinterpret_cast<int>(fBuffers[curr]); | |
| 58 fBuffers[curr] = NULL; | |
| 59 curr = next; | |
| 60 } | |
| 61 | |
| 62 fBuffers.deleteAll(); | |
| 64 } | 63 } |
| 65 | 64 |
| 66 GrGLuint id; | 65 BufferObj* lookUp(GrGLuint id) { |
| 67 GrBufferObj* buffer; | 66 BufferObj* buffer = fBuffers[id]; |
| 68 | 67 SkASSERT(NULL != buffer && buffer->id() == id); |
| 69 if (NULL == gBuffers[0]) { | 68 return buffer; |
| 70 // no free slots - create a new one | |
| 71 id = gBuffers.count(); | |
| 72 buffer = SkNEW_ARGS(GrBufferObj, (id)); | |
| 73 gBuffers.append(1, &buffer); | |
| 74 } else { | |
| 75 // recycle a slot from the free list | |
| 76 id = SkTCast<GrGLuint>(gBuffers[0]); | |
| 77 gBuffers[0] = gBuffers[id]; | |
| 78 | |
| 79 buffer = SkNEW_ARGS(GrBufferObj, (id)); | |
| 80 gBuffers[id] = buffer; | |
| 81 } | 69 } |
| 82 | 70 |
| 83 return buffer; | 71 BufferObj* create() { |
| 84 } | 72 GrGLuint id; |
| 73 BufferObj* buffer; | |
| 85 | 74 |
| 86 static void delete_buffer(GrBufferObj* buffer) { | 75 if (kFreeListEnd == fFreeListHead) { |
| 87 SkASSERT(gBuffers.count() > 0); | 76 // no free slots - create a new one |
| 77 id = fBuffers.count(); | |
| 78 buffer = SkNEW_ARGS(BufferObj, (id)); | |
| 79 *fBuffers.append() = buffer; | |
| 80 } else { | |
| 81 // grab the head of the free list and advance the head to the next f ree slot. | |
| 82 id = fFreeListHead; | |
| 83 fFreeListHead = reinterpret_cast<int>(fBuffers[id]); | |
| 88 | 84 |
| 89 GrGLuint id = buffer->id(); | 85 buffer = SkNEW_ARGS(BufferObj, (id)); |
| 90 SkDELETE(buffer); | 86 fBuffers[id] = buffer; |
| 87 } | |
| 91 | 88 |
| 92 // Add this slot to the free list | 89 return buffer; |
| 93 gBuffers[id] = gBuffers[0]; | 90 } |
| 94 gBuffers[0] = SkTCast<GrBufferObj*>((const void*)(intptr_t)id); | 91 |
| 95 } | 92 void free(BufferObj* buffer) { |
| 93 SkASSERT(fBuffers.count() > 0); | |
| 94 | |
| 95 GrGLuint id = buffer->id(); | |
| 96 SkDELETE(buffer); | |
| 97 | |
| 98 fBuffers[id] = reinterpret_cast<BufferObj*>(fFreeListHead); | |
| 99 fFreeListHead = id; | |
| 100 } | |
| 101 | |
| 102 private: | |
| 103 static const int kFreeListEnd = -1; | |
|
robertphillips
2014/08/14 14:10:17
Line these two up ?
bsalomon
2014/08/14 14:52:08
Done.
| |
| 104 int fFreeListHead; | |
| 105 SkTDArray<BufferObj*> fBuffers; | |
| 106 }; | |
| 107 | |
| 108 /** | |
| 109 * The global-to-thread state object for the null interface. All null interfaces on the | |
| 110 * same thread currently share one of these. This means two null contexts on the same thread | |
| 111 * can interfere with each other. It may make sense to more integrate this into SkNullGLContext | |
| 112 * and use it's makeCurrent mechanism. | |
| 113 */ | |
| 114 struct ThreadContext { | |
| 115 public: | |
| 116 SK_DECLARE_INST_COUNT_ROOT(ThreadContext); | |
| 117 | |
|
robertphillips
2014/08/14 14:10:17
fBufferMgr ?
bsalomon
2014/08/14 14:52:08
Done.
| |
| 118 BufferManager fBuffers; | |
|
robertphillips
2014/08/14 14:10:17
Line these guys up with fBuffers ?
bsalomon
2014/08/14 14:52:08
Done.
| |
| 119 GrGLuint fCurrArrayBuffer; | |
| 120 GrGLuint fCurrElementArrayBuffer; | |
| 121 GrGLuint fCurrProgramID; | |
| 122 GrGLuint fCurrShaderID; | |
| 123 | |
| 124 static ThreadContext* Get() { | |
| 125 return reinterpret_cast<ThreadContext*>(SkTLS::Get(Create, Delete)); | |
| 126 } | |
| 127 | |
| 128 ThreadContext() | |
| 129 : fCurrArrayBuffer(0) | |
| 130 , fCurrElementArrayBuffer(0) | |
| 131 , fCurrProgramID(0) | |
| 132 , fCurrShaderID(0) {} | |
| 133 | |
| 134 private: | |
| 135 static void* Create() { return SkNEW(ThreadContext ); } | |
| 136 static void Delete(void* context) { SkDELETE(reinterpret_cast<ThreadContext *>(context)); } | |
| 137 }; | |
| 138 | |
| 139 // Functions not declared in GrGLBogusInterface.h (not common with the Debug GL interface). | |
| 140 | |
| 141 namespace { // added to suppress 'no previous prototype' warning | |
| 96 | 142 |
| 97 GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {} | 143 GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {} |
| 98 GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shade r) {} | 144 GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shade r) {} |
| 99 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {} | 145 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {} |
| 100 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint index, const char* name) {} | 146 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint index, const char* name) {} |
| 101 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture ) {} | 147 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture ) {} |
| 102 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindVertexArray(GrGLuint id) {} | 148 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindVertexArray(GrGLuint id) {} |
| 103 | 149 |
| 104 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenBuffers(GrGLsizei n, GrGLuint* ids) { | 150 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenBuffers(GrGLsizei n, GrGLuint* ids) { |
| 105 | 151 ThreadContext* ctx = ThreadContext::Get(); |
| 106 for (int i = 0; i < n; ++i) { | 152 for (int i = 0; i < n; ++i) { |
| 107 GrBufferObj* buffer = create_buffer(); | 153 BufferObj* buffer = ctx->fBuffers.create(); |
| 108 ids[i] = buffer->id(); | 154 ids[i] = buffer->id(); |
| 109 } | 155 } |
| 110 } | 156 } |
| 111 | 157 |
| 112 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenerateMipmap(GrGLenum target) {} | 158 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenerateMipmap(GrGLenum target) {} |
| 113 | 159 |
| 114 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target, | 160 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target, |
| 115 GrGLsizeiptr size, | 161 GrGLsizeiptr size, |
| 116 const GrGLvoid* data, | 162 const GrGLvoid* data, |
| 117 GrGLenum usage) { | 163 GrGLenum usage) { |
| 164 ThreadContext* ctx = ThreadContext::Get(); | |
| 118 GrGLuint id = 0; | 165 GrGLuint id = 0; |
| 119 | 166 |
| 120 switch (target) { | 167 switch (target) { |
| 121 case GR_GL_ARRAY_BUFFER: | 168 case GR_GL_ARRAY_BUFFER: |
| 122 id = gCurrArrayBuffer; | 169 id = ctx->fCurrArrayBuffer; |
| 123 break; | 170 break; |
| 124 case GR_GL_ELEMENT_ARRAY_BUFFER: | 171 case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 125 id = gCurrElementArrayBuffer; | 172 id = ctx->fCurrElementArrayBuffer; |
| 126 break; | 173 break; |
| 127 default: | 174 default: |
| 128 SkFAIL("Unexpected target to nullGLBufferData"); | 175 SkFAIL("Unexpected target to nullGLBufferData"); |
| 129 break; | 176 break; |
| 130 } | 177 } |
| 131 | 178 |
| 132 if (id > 0) { | 179 if (id > 0) { |
| 133 GrBufferObj* buffer = look_up(id); | 180 BufferObj* buffer = ctx->fBuffers.lookUp(id); |
| 134 buffer->allocate(size, (const GrGLchar*) data); | 181 buffer->allocate(size, (const GrGLchar*) data); |
| 135 } | 182 } |
| 136 } | 183 } |
| 137 | 184 |
| 138 GrGLvoid GR_GL_FUNCTION_TYPE nullGLPixelStorei(GrGLenum pname, GrGLint param) {} | 185 GrGLvoid GR_GL_FUNCTION_TYPE nullGLPixelStorei(GrGLenum pname, GrGLint param) {} |
| 139 GrGLvoid GR_GL_FUNCTION_TYPE nullGLReadPixels(GrGLint x, GrGLint y, GrGLsizei wi dth, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {} | 186 GrGLvoid GR_GL_FUNCTION_TYPE nullGLReadPixels(GrGLint x, GrGLint y, GrGLsizei wi dth, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {} |
| 140 GrGLvoid GR_GL_FUNCTION_TYPE nullGLUseProgram(GrGLuint program) {} | 187 GrGLvoid GR_GL_FUNCTION_TYPE nullGLUseProgram(GrGLuint program) {} |
| 141 GrGLvoid GR_GL_FUNCTION_TYPE nullGLViewport(GrGLint x, GrGLint y, GrGLsizei widt h, GrGLsizei height) {} | 188 GrGLvoid GR_GL_FUNCTION_TYPE nullGLViewport(GrGLint x, GrGLint y, GrGLsizei widt h, GrGLsizei height) {} |
| 142 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindFramebuffer(GrGLenum target, GrGLuint fra mebuffer) {} | 189 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindFramebuffer(GrGLenum target, GrGLuint fra mebuffer) {} |
| 143 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindRenderbuffer(GrGLenum target, GrGLuint re nderbuffer) {} | 190 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindRenderbuffer(GrGLenum target, GrGLuint re nderbuffer) {} |
| 144 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteFramebuffers(GrGLsizei n, const GrGLuin t *framebuffers) {} | 191 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteFramebuffers(GrGLsizei n, const GrGLuin t *framebuffers) {} |
| 145 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteRenderbuffers(GrGLsizei n, const GrGLui nt *renderbuffers) {} | 192 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteRenderbuffers(GrGLsizei n, const GrGLui nt *renderbuffers) {} |
| 146 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferRenderbuffer(GrGLenum target, GrGL enum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer) {} | 193 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferRenderbuffer(GrGLenum target, GrGL enum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer) {} |
| 147 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferTexture2D(GrGLenum target, GrGLenu m attachment, GrGLenum textarget, GrGLuint texture, GrGLint level) {} | 194 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferTexture2D(GrGLenum target, GrGLenu m attachment, GrGLenum textarget, GrGLuint texture, GrGLint level) {} |
| 148 | 195 |
| 149 GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateProgram() { | 196 GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateProgram() { |
| 150 static GrGLuint gCurrID = 0; | 197 return ++ThreadContext::Get()->fCurrProgramID; |
| 151 return ++gCurrID; | |
| 152 } | 198 } |
| 153 | 199 |
| 154 GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateShader(GrGLenum type) { | 200 GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateShader(GrGLenum type) { |
| 155 static GrGLuint gCurrID = 0; | 201 return ++ThreadContext::Get()->fCurrShaderID; |
| 156 return ++gCurrID; | |
| 157 } | 202 } |
| 158 | 203 |
| 159 // same delete used for shaders and programs | 204 // same delete used for shaders and programs |
| 160 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDelete(GrGLuint program) { | 205 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDelete(GrGLuint program) { |
| 161 } | 206 } |
| 162 | 207 |
| 163 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer) { | 208 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer) { |
| 209 ThreadContext* ctx = ThreadContext::Get(); | |
| 164 switch (target) { | 210 switch (target) { |
| 165 case GR_GL_ARRAY_BUFFER: | 211 case GR_GL_ARRAY_BUFFER: |
| 166 gCurrArrayBuffer = buffer; | 212 ctx->fCurrArrayBuffer = buffer; |
| 167 break; | 213 break; |
| 168 case GR_GL_ELEMENT_ARRAY_BUFFER: | 214 case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 169 gCurrElementArrayBuffer = buffer; | 215 ctx->fCurrElementArrayBuffer = buffer; |
| 170 break; | 216 break; |
| 171 } | 217 } |
| 172 } | 218 } |
| 173 | 219 |
| 174 // deleting a bound buffer has the side effect of binding 0 | 220 // deleting a bound buffer has the side effect of binding 0 |
| 175 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteBuffers(GrGLsizei n, const GrGLuint* id s) { | 221 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteBuffers(GrGLsizei n, const GrGLuint* id s) { |
| 222 ThreadContext* ctx = ThreadContext::Get(); | |
| 176 for (int i = 0; i < n; ++i) { | 223 for (int i = 0; i < n; ++i) { |
| 177 if (ids[i] == gCurrArrayBuffer) { | 224 if (ids[i] == ctx->fCurrArrayBuffer) { |
| 178 gCurrArrayBuffer = 0; | 225 ctx->fCurrArrayBuffer = 0; |
| 179 } | 226 } |
| 180 if (ids[i] == gCurrElementArrayBuffer) { | 227 if (ids[i] == ctx->fCurrElementArrayBuffer) { |
| 181 gCurrElementArrayBuffer = 0; | 228 ctx->fCurrElementArrayBuffer = 0; |
| 182 } | 229 } |
| 183 | 230 |
| 184 GrBufferObj* buffer = look_up(ids[i]); | 231 BufferObj* buffer = ctx->fBuffers.lookUp(ids[i]); |
| 185 delete_buffer(buffer); | 232 ctx->fBuffers.free(buffer); |
| 186 } | 233 } |
| 187 } | 234 } |
| 188 | 235 |
| 189 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBufferRange(GrGLenum target, GrGLintptr o ffset, | 236 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBufferRange(GrGLenum target, GrGLintptr o ffset, |
| 190 GrGLsizeiptr length, GrGLbitf ield access) { | 237 GrGLsizeiptr length, GrGLbitf ield access) { |
| 238 ThreadContext* ctx = ThreadContext::Get(); | |
| 191 GrGLuint id = 0; | 239 GrGLuint id = 0; |
| 192 switch (target) { | 240 switch (target) { |
| 193 case GR_GL_ARRAY_BUFFER: | 241 case GR_GL_ARRAY_BUFFER: |
| 194 id = gCurrArrayBuffer; | 242 id = ctx->fCurrArrayBuffer; |
| 195 break; | 243 break; |
| 196 case GR_GL_ELEMENT_ARRAY_BUFFER: | 244 case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 197 id = gCurrElementArrayBuffer; | 245 id = ctx->fCurrElementArrayBuffer; |
| 198 break; | 246 break; |
| 199 } | 247 } |
| 200 | 248 |
| 201 if (id > 0) { | 249 if (id > 0) { |
| 202 // We just ignore the offset and length here. | 250 // We just ignore the offset and length here. |
| 203 GrBufferObj* buffer = look_up(id); | 251 BufferObj* buffer = ctx->fBuffers.lookUp(id); |
| 204 SkASSERT(!buffer->mapped()); | 252 SkASSERT(!buffer->mapped()); |
| 205 buffer->setMapped(true); | 253 buffer->setMapped(true); |
| 206 return buffer->dataPtr(); | 254 return buffer->dataPtr(); |
| 207 } | 255 } |
| 208 return NULL; | 256 return NULL; |
| 209 } | 257 } |
| 210 | 258 |
| 211 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access) { | 259 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access) { |
| 260 ThreadContext* ctx = ThreadContext::Get(); | |
| 212 GrGLuint id = 0; | 261 GrGLuint id = 0; |
| 213 switch (target) { | 262 switch (target) { |
| 214 case GR_GL_ARRAY_BUFFER: | 263 case GR_GL_ARRAY_BUFFER: |
| 215 id = gCurrArrayBuffer; | 264 id = ctx->fCurrArrayBuffer; |
| 216 break; | 265 break; |
| 217 case GR_GL_ELEMENT_ARRAY_BUFFER: | 266 case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 218 id = gCurrElementArrayBuffer; | 267 id = ctx->fCurrElementArrayBuffer; |
| 219 break; | 268 break; |
| 220 } | 269 } |
| 221 | 270 |
| 222 if (id > 0) { | 271 if (id > 0) { |
| 223 GrBufferObj* buffer = look_up(id); | 272 BufferObj* buffer = ctx->fBuffers.lookUp(id); |
| 224 SkASSERT(!buffer->mapped()); | 273 SkASSERT(!buffer->mapped()); |
| 225 buffer->setMapped(true); | 274 buffer->setMapped(true); |
| 226 return buffer->dataPtr(); | 275 return buffer->dataPtr(); |
| 227 } | 276 } |
| 228 | 277 |
| 229 SkASSERT(false); | 278 SkASSERT(false); |
| 230 return NULL; // no buffer bound to target | 279 return NULL; // no buffer bound to target |
| 231 } | 280 } |
| 232 | 281 |
| 233 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFlushMappedBufferRange(GrGLenum target, | 282 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFlushMappedBufferRange(GrGLenum target, |
| 234 GrGLintptr offset, | 283 GrGLintptr offset, |
| 235 GrGLsizeiptr length) { } | 284 GrGLsizeiptr length) { } |
| 236 | 285 |
| 237 | 286 |
| 238 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { | 287 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { |
| 288 ThreadContext* ctx = ThreadContext::Get(); | |
| 239 GrGLuint id = 0; | 289 GrGLuint id = 0; |
| 240 switch (target) { | 290 switch (target) { |
| 241 case GR_GL_ARRAY_BUFFER: | 291 case GR_GL_ARRAY_BUFFER: |
| 242 id = gCurrArrayBuffer; | 292 id = ctx->fCurrArrayBuffer; |
| 243 break; | 293 break; |
| 244 case GR_GL_ELEMENT_ARRAY_BUFFER: | 294 case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 245 id = gCurrElementArrayBuffer; | 295 id = ctx->fCurrElementArrayBuffer; |
| 246 break; | 296 break; |
| 247 } | 297 } |
| 248 if (id > 0) { | 298 if (id > 0) { |
| 249 GrBufferObj* buffer = look_up(id); | 299 BufferObj* buffer = ctx->fBuffers.lookUp(id); |
| 250 SkASSERT(buffer->mapped()); | 300 SkASSERT(buffer->mapped()); |
| 251 buffer->setMapped(false); | 301 buffer->setMapped(false); |
| 252 return GR_GL_TRUE; | 302 return GR_GL_TRUE; |
| 253 } | 303 } |
| 254 | 304 |
| 255 GrAlwaysAssert(false); | 305 GrAlwaysAssert(false); |
| 256 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; | 306 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; |
| 257 } | 307 } |
| 258 | 308 |
| 259 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenu m pname, GrGLint* params) { | 309 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenu m pname, GrGLint* params) { |
| 310 ThreadContext* ctx = ThreadContext::Get(); | |
| 260 switch (pname) { | 311 switch (pname) { |
| 261 case GR_GL_BUFFER_MAPPED: { | 312 case GR_GL_BUFFER_MAPPED: { |
| 262 *params = GR_GL_FALSE; | 313 *params = GR_GL_FALSE; |
| 263 GrGLuint id = 0; | 314 GrGLuint id = 0; |
| 264 switch (target) { | 315 switch (target) { |
| 265 case GR_GL_ARRAY_BUFFER: | 316 case GR_GL_ARRAY_BUFFER: |
| 266 id = gCurrArrayBuffer; | 317 id = ctx->fCurrArrayBuffer; |
| 267 break; | 318 break; |
| 268 case GR_GL_ELEMENT_ARRAY_BUFFER: | 319 case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 269 id = gCurrElementArrayBuffer; | 320 id = ctx->fCurrElementArrayBuffer; |
| 270 break; | 321 break; |
| 271 } | 322 } |
| 272 if (id > 0) { | 323 if (id > 0) { |
| 273 GrBufferObj* buffer = look_up(id); | 324 BufferObj* buffer = ctx->fBuffers.lookUp(id); |
| 274 if (buffer->mapped()) { | 325 if (buffer->mapped()) { |
| 275 *params = GR_GL_TRUE; | 326 *params = GR_GL_TRUE; |
| 276 } | 327 } |
| 277 } | 328 } |
| 278 break; } | 329 break; } |
| 279 default: | 330 default: |
| 280 SkFAIL("Unexpected pname to GetBufferParamateriv"); | 331 SkFAIL("Unexpected pname to GetBufferParamateriv"); |
| 281 break; | 332 break; |
| 282 } | 333 } |
| 283 }; | 334 }; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 functions->fBlitFramebuffer = noOpGLBlitFramebuffer; | 470 functions->fBlitFramebuffer = noOpGLBlitFramebuffer; |
| 420 functions->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFramebuf fer; | 471 functions->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFramebuf fer; |
| 421 functions->fMatrixLoadf = noOpGLMatrixLoadf; | 472 functions->fMatrixLoadf = noOpGLMatrixLoadf; |
| 422 functions->fMatrixLoadIdentity = noOpGLMatrixLoadIdentity; | 473 functions->fMatrixLoadIdentity = noOpGLMatrixLoadIdentity; |
| 423 functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed; | 474 functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed; |
| 424 | 475 |
| 425 interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functio ns->fGetStringi, | 476 interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functio ns->fGetStringi, |
| 426 functions->fGetIntegerv); | 477 functions->fGetIntegerv); |
| 427 return interface; | 478 return interface; |
| 428 } | 479 } |
| OLD | NEW |