OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "gl/SkNullGLContext.h" | 9 #include "gl/SkNullGLContext.h" |
10 #include "gl/GrGLInterface.h" | 10 #include "gl/GrGLInterface.h" |
11 #include "GrGLDefines.h" | 11 #include "GrGLDefines.h" |
12 #include "GrGLNoOpInterface.h" | 12 #include "GrGLNoOpInterface.h" |
13 #include "SkTDArray.h" | 13 #include "SkTDArray.h" |
14 #include "SkTLS.h" | 14 #include "SkTLS.h" |
15 | 15 |
16 static SkNullGLContext::ContextState* current_context(); | 16 static SkNullGLContext::ContextState* current_context(); |
17 | 17 |
18 ////////////////////////////////////////////////////////////////////////////////
///////////////// | 18 ////////////////////////////////////////////////////////////////////////////////
///////////////// |
19 | 19 |
20 class BufferObj { | 20 class BufferObj { |
21 public: | 21 public: |
22 | 22 |
23 | 23 |
24 BufferObj(GrGLuint id) : fID(id), fDataPtr(NULL), fSize(0), fMapped(false) {
} | 24 BufferObj(GrGLuint id) : fID(id), fDataPtr(nullptr), fSize(0), fMapped(false
) {} |
25 ~BufferObj() { delete[] fDataPtr; } | 25 ~BufferObj() { delete[] fDataPtr; } |
26 | 26 |
27 void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) { | 27 void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) { |
28 if (fDataPtr) { | 28 if (fDataPtr) { |
29 SkASSERT(0 != fSize); | 29 SkASSERT(0 != fSize); |
30 delete[] fDataPtr; | 30 delete[] fDataPtr; |
31 } | 31 } |
32 | 32 |
33 fSize = size; | 33 fSize = size; |
34 fDataPtr = new char[size]; | 34 fDataPtr = new char[size]; |
(...skipping 14 matching lines...) Expand all Loading... |
49 }; | 49 }; |
50 | 50 |
51 // This class maintains a sparsely populated array of buffer pointers. | 51 // This class maintains a sparsely populated array of buffer pointers. |
52 class BufferManager { | 52 class BufferManager { |
53 public: | 53 public: |
54 | 54 |
55 | 55 |
56 BufferManager() : fFreeListHead(kFreeListEnd) {} | 56 BufferManager() : fFreeListHead(kFreeListEnd) {} |
57 | 57 |
58 ~BufferManager() { | 58 ~BufferManager() { |
59 // NULL out the entries that are really free list links rather than ptrs
before deleting. | 59 // nullptr out the entries that are really free list links rather than p
trs before deleting. |
60 intptr_t curr = fFreeListHead; | 60 intptr_t curr = fFreeListHead; |
61 while (kFreeListEnd != curr) { | 61 while (kFreeListEnd != curr) { |
62 intptr_t next = reinterpret_cast<intptr_t>(fBuffers[SkToS32(curr)]); | 62 intptr_t next = reinterpret_cast<intptr_t>(fBuffers[SkToS32(curr)]); |
63 fBuffers[SkToS32(curr)] = NULL; | 63 fBuffers[SkToS32(curr)] = nullptr; |
64 curr = next; | 64 curr = next; |
65 } | 65 } |
66 | 66 |
67 fBuffers.deleteAll(); | 67 fBuffers.deleteAll(); |
68 } | 68 } |
69 | 69 |
70 BufferObj* lookUp(GrGLuint id) { | 70 BufferObj* lookUp(GrGLuint id) { |
71 BufferObj* buffer = fBuffers[id]; | 71 BufferObj* buffer = fBuffers[id]; |
72 SkASSERT(buffer && buffer->id() == id); | 72 SkASSERT(buffer && buffer->id() == id); |
73 return buffer; | 73 return buffer; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 break; | 247 break; |
248 } | 248 } |
249 | 249 |
250 if (id > 0) { | 250 if (id > 0) { |
251 // We just ignore the offset and length here. | 251 // We just ignore the offset and length here. |
252 BufferObj* buffer = state->fBufferManager.lookUp(id); | 252 BufferObj* buffer = state->fBufferManager.lookUp(id); |
253 SkASSERT(!buffer->mapped()); | 253 SkASSERT(!buffer->mapped()); |
254 buffer->setMapped(true); | 254 buffer->setMapped(true); |
255 return buffer->dataPtr(); | 255 return buffer->dataPtr(); |
256 } | 256 } |
257 return NULL; | 257 return nullptr; |
258 } | 258 } |
259 | 259 |
260 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access)
{ | 260 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access)
{ |
261 State* state = State::Get(); | 261 State* state = State::Get(); |
262 GrGLuint id = 0; | 262 GrGLuint id = 0; |
263 switch (target) { | 263 switch (target) { |
264 case GR_GL_ARRAY_BUFFER: | 264 case GR_GL_ARRAY_BUFFER: |
265 id = state->fCurrArrayBuffer; | 265 id = state->fCurrArrayBuffer; |
266 break; | 266 break; |
267 case GR_GL_ELEMENT_ARRAY_BUFFER: | 267 case GR_GL_ELEMENT_ARRAY_BUFFER: |
268 id = state->fCurrElementArrayBuffer; | 268 id = state->fCurrElementArrayBuffer; |
269 break; | 269 break; |
270 } | 270 } |
271 | 271 |
272 if (id > 0) { | 272 if (id > 0) { |
273 BufferObj* buffer = state->fBufferManager.lookUp(id); | 273 BufferObj* buffer = state->fBufferManager.lookUp(id); |
274 SkASSERT(!buffer->mapped()); | 274 SkASSERT(!buffer->mapped()); |
275 buffer->setMapped(true); | 275 buffer->setMapped(true); |
276 return buffer->dataPtr(); | 276 return buffer->dataPtr(); |
277 } | 277 } |
278 | 278 |
279 SkASSERT(false); | 279 SkASSERT(false); |
280 return NULL; // no buffer bound to target | 280 return nullptr; // no buffer bound to target |
281 } | 281 } |
282 | 282 |
283 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFlushMappedBufferRange(GrGLenum target, | 283 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFlushMappedBufferRange(GrGLenum target, |
284 GrGLintptr offset, | 284 GrGLintptr offset, |
285 GrGLsizeiptr length) {
} | 285 GrGLsizeiptr length) {
} |
286 | 286 |
287 | 287 |
288 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { | 288 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { |
289 State* state = State::Get(); | 289 State* state = State::Get(); |
290 GrGLuint id = 0; | 290 GrGLuint id = 0; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 492 |
493 interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functio
ns->fGetStringi, | 493 interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functio
ns->fGetStringi, |
494 functions->fGetIntegerv); | 494 functions->fGetIntegerv); |
495 return interface; | 495 return interface; |
496 } | 496 } |
497 | 497 |
498 ////////////////////////////////////////////////////////////////////////////// | 498 ////////////////////////////////////////////////////////////////////////////// |
499 | 499 |
500 static void* create_tls() { | 500 static void* create_tls() { |
501 State** current = new State*; | 501 State** current = new State*; |
502 *current = NULL; | 502 *current = nullptr; |
503 return current; | 503 return current; |
504 } | 504 } |
505 | 505 |
506 static void delete_tls(void* ctx) { | 506 static void delete_tls(void* ctx) { |
507 State** current = static_cast<State**>(ctx); | 507 State** current = static_cast<State**>(ctx); |
508 if (*current) { | 508 if (*current) { |
509 (*current)->unref(); | 509 (*current)->unref(); |
510 } | 510 } |
511 delete current; | 511 delete current; |
512 } | 512 } |
(...skipping 14 matching lines...) Expand all Loading... |
527 } | 527 } |
528 | 528 |
529 #if GR_GL_PER_GL_FUNC_CALLBACK | 529 #if GR_GL_PER_GL_FUNC_CALLBACK |
530 static void set_current_context_from_interface(const GrGLInterface* interface) { | 530 static void set_current_context_from_interface(const GrGLInterface* interface) { |
531 set_current_context(reinterpret_cast<State*>(interface->fCallbackData)); | 531 set_current_context(reinterpret_cast<State*>(interface->fCallbackData)); |
532 } | 532 } |
533 #endif | 533 #endif |
534 | 534 |
535 SkNullGLContext* SkNullGLContext::Create(GrGLStandard forcedGpuAPI) { | 535 SkNullGLContext* SkNullGLContext::Create(GrGLStandard forcedGpuAPI) { |
536 if (kGLES_GrGLStandard == forcedGpuAPI) { | 536 if (kGLES_GrGLStandard == forcedGpuAPI) { |
537 return NULL; | 537 return nullptr; |
538 } | 538 } |
539 SkNullGLContext* ctx = new SkNullGLContext; | 539 SkNullGLContext* ctx = new SkNullGLContext; |
540 if (!ctx->isValid()) { | 540 if (!ctx->isValid()) { |
541 delete ctx; | 541 delete ctx; |
542 return NULL; | 542 return nullptr; |
543 } | 543 } |
544 return ctx; | 544 return ctx; |
545 } | 545 } |
546 | 546 |
547 SkNullGLContext::SkNullGLContext() { | 547 SkNullGLContext::SkNullGLContext() { |
548 fState = new ContextState; | 548 fState = new ContextState; |
549 GrGLInterface* interface = create_null_interface(fState); | 549 GrGLInterface* interface = create_null_interface(fState); |
550 this->init(interface); | 550 this->init(interface); |
551 #if GR_GL_PER_GL_FUNC_CALLBACK | 551 #if GR_GL_PER_GL_FUNC_CALLBACK |
552 interface->fCallback = set_current_context_from_interface; | 552 interface->fCallback = set_current_context_from_interface; |
553 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(fStat
e); | 553 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(fStat
e); |
554 #endif | 554 #endif |
555 } | 555 } |
556 | 556 |
557 SkNullGLContext::~SkNullGLContext() { | 557 SkNullGLContext::~SkNullGLContext() { |
558 this->teardown(); | 558 this->teardown(); |
559 fState->unref(); | 559 fState->unref(); |
560 } | 560 } |
561 | 561 |
562 void SkNullGLContext::onPlatformMakeCurrent() const { set_current_context(fState
); } | 562 void SkNullGLContext::onPlatformMakeCurrent() const { set_current_context(fState
); } |
OLD | NEW |