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(NULL), fSize(0), fMapped(false) {
} |
25 ~BufferObj() { SkDELETE_ARRAY(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 SkDELETE_ARRAY(fDataPtr); | 30 delete[] fDataPtr; |
31 } | 31 } |
32 | 32 |
33 fSize = size; | 33 fSize = size; |
34 fDataPtr = SkNEW_ARRAY(char, size); | 34 fDataPtr = new char[size]; |
35 } | 35 } |
36 | 36 |
37 GrGLuint id() const { return fID; } | 37 GrGLuint id() const { return fID; } |
38 GrGLchar* dataPtr() { return fDataPtr; } | 38 GrGLchar* dataPtr() { return fDataPtr; } |
39 GrGLsizeiptr size() const { return fSize; } | 39 GrGLsizeiptr size() const { return fSize; } |
40 | 40 |
41 void setMapped(bool mapped) { fMapped = mapped; } | 41 void setMapped(bool mapped) { fMapped = mapped; } |
42 bool mapped() const { return fMapped; } | 42 bool mapped() const { return fMapped; } |
43 | 43 |
44 private: | 44 private: |
(...skipping 28 matching lines...) Expand all Loading... |
73 return buffer; | 73 return buffer; |
74 } | 74 } |
75 | 75 |
76 BufferObj* create() { | 76 BufferObj* create() { |
77 GrGLuint id; | 77 GrGLuint id; |
78 BufferObj* buffer; | 78 BufferObj* buffer; |
79 | 79 |
80 if (kFreeListEnd == fFreeListHead) { | 80 if (kFreeListEnd == fFreeListHead) { |
81 // no free slots - create a new one | 81 // no free slots - create a new one |
82 id = fBuffers.count(); | 82 id = fBuffers.count(); |
83 buffer = SkNEW_ARGS(BufferObj, (id)); | 83 buffer = new BufferObj(id); |
84 *fBuffers.append() = buffer; | 84 *fBuffers.append() = buffer; |
85 } else { | 85 } else { |
86 // grab the head of the free list and advance the head to the next f
ree slot. | 86 // grab the head of the free list and advance the head to the next f
ree slot. |
87 id = static_cast<GrGLuint>(fFreeListHead); | 87 id = static_cast<GrGLuint>(fFreeListHead); |
88 fFreeListHead = reinterpret_cast<intptr_t>(fBuffers[id]); | 88 fFreeListHead = reinterpret_cast<intptr_t>(fBuffers[id]); |
89 | 89 |
90 buffer = SkNEW_ARGS(BufferObj, (id)); | 90 buffer = new BufferObj(id); |
91 fBuffers[id] = buffer; | 91 fBuffers[id] = buffer; |
92 } | 92 } |
93 | 93 |
94 return buffer; | 94 return buffer; |
95 } | 95 } |
96 | 96 |
97 void free(BufferObj* buffer) { | 97 void free(BufferObj* buffer) { |
98 SkASSERT(fBuffers.count() > 0); | 98 SkASSERT(fBuffers.count() > 0); |
99 | 99 |
100 GrGLuint id = buffer->id(); | 100 GrGLuint id = buffer->id(); |
101 SkDELETE(buffer); | 101 delete buffer; |
102 | 102 |
103 fBuffers[id] = reinterpret_cast<BufferObj*>(fFreeListHead); | 103 fBuffers[id] = reinterpret_cast<BufferObj*>(fFreeListHead); |
104 fFreeListHead = id; | 104 fFreeListHead = id; |
105 } | 105 } |
106 | 106 |
107 private: | 107 private: |
108 static const intptr_t kFreeListEnd = -1; | 108 static const intptr_t kFreeListEnd = -1; |
109 // Index of the first entry of fBuffers in the free list. Free slots in fBuf
fers are indices to | 109 // Index of the first entry of fBuffers in the free list. Free slots in fBuf
fers are indices to |
110 // the next free slot. The last free slot has a value of kFreeListEnd. | 110 // the next free slot. The last free slot has a value of kFreeListEnd. |
111 intptr_t fFreeListHead; | 111 intptr_t fFreeListHead; |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 NullInterface(State* state) : fState(SkRef(state)) {} | 339 NullInterface(State* state) : fState(SkRef(state)) {} |
340 ~NullInterface() override { | 340 ~NullInterface() override { |
341 fState->unref(); | 341 fState->unref(); |
342 } | 342 } |
343 State* fState; | 343 State* fState; |
344 }; | 344 }; |
345 | 345 |
346 } // end anonymous namespace | 346 } // end anonymous namespace |
347 | 347 |
348 static GrGLInterface* create_null_interface(State* state) { | 348 static GrGLInterface* create_null_interface(State* state) { |
349 GrGLInterface* interface = SkNEW_ARGS(NullInterface, (state)); | 349 GrGLInterface* interface = new NullInterface(state); |
350 | 350 |
351 interface->fStandard = kGL_GrGLStandard; | 351 interface->fStandard = kGL_GrGLStandard; |
352 | 352 |
353 GrGLInterface::Functions* functions = &interface->fFunctions; | 353 GrGLInterface::Functions* functions = &interface->fFunctions; |
354 functions->fActiveTexture = nullGLActiveTexture; | 354 functions->fActiveTexture = nullGLActiveTexture; |
355 functions->fAttachShader = nullGLAttachShader; | 355 functions->fAttachShader = nullGLAttachShader; |
356 functions->fBeginQuery = nullGLBeginQuery; | 356 functions->fBeginQuery = nullGLBeginQuery; |
357 functions->fBindAttribLocation = nullGLBindAttribLocation; | 357 functions->fBindAttribLocation = nullGLBindAttribLocation; |
358 functions->fBindBuffer = nullGLBindBuffer; | 358 functions->fBindBuffer = nullGLBindBuffer; |
359 functions->fBindFragDataLocation = noOpGLBindFragDataLocation; | 359 functions->fBindFragDataLocation = noOpGLBindFragDataLocation; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed; | 491 functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed; |
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 = SkNEW(State*); | 501 State** current = new State*; |
502 *current = NULL; | 502 *current = NULL; |
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 SkDELETE(current); | 511 delete current; |
512 } | 512 } |
513 | 513 |
514 static State* current_context() { | 514 static State* current_context() { |
515 return *static_cast<State**>(SkTLS::Get(create_tls, delete_tls)); | 515 return *static_cast<State**>(SkTLS::Get(create_tls, delete_tls)); |
516 } | 516 } |
517 | 517 |
518 static void set_current_context(State* state) { | 518 static void set_current_context(State* state) { |
519 State** current = static_cast<State**>(SkTLS::Get(create_tls, delete_tls)); | 519 State** current = static_cast<State**>(SkTLS::Get(create_tls, delete_tls)); |
520 if (*current) { | 520 if (*current) { |
521 (*current)->unref(); | 521 (*current)->unref(); |
522 } | 522 } |
523 *current = state; | 523 *current = state; |
524 if (state) { | 524 if (state) { |
525 state->ref(); | 525 state->ref(); |
526 } | 526 } |
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 NULL; |
538 } | 538 } |
539 SkNullGLContext* ctx = SkNEW(SkNullGLContext); | 539 SkNullGLContext* ctx = new SkNullGLContext; |
540 if (!ctx->isValid()) { | 540 if (!ctx->isValid()) { |
541 SkDELETE(ctx); | 541 delete ctx; |
542 return NULL; | 542 return NULL; |
543 } | 543 } |
544 return ctx; | 544 return ctx; |
545 } | 545 } |
546 | 546 |
547 SkNullGLContext::SkNullGLContext() { | 547 SkNullGLContext::SkNullGLContext() { |
548 fState = SkNEW(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 |