Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: src/gpu/gl/SkNullGLContext.cpp

Issue 919783002: Make null GL context use callback to make current (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: struct- Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/gpu/gl/SkNullGLContext.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 const SkNullGLContext* 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 SK_DECLARE_INST_COUNT(BufferObj); 22 SK_DECLARE_INST_COUNT(BufferObj);
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() { SkDELETE_ARRAY(fDataPtr); }
26 26
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
112 SkTDArray<BufferObj*> fBuffers; 112 SkTDArray<BufferObj*> fBuffers;
113 }; 113 };
114 114
115 /** 115 /**
116 * The state object for the null interface. 116 * The state object for the null interface.
117 */ 117 */
118 struct SkNullGLContext::ContextState { 118 class SkNullGLContext::ContextState : public SkRefCnt {
119 public: 119 public:
120 SK_DECLARE_INST_COUNT(ContextState); 120 SK_DECLARE_INST_COUNT(ContextState);
121 121
122 BufferManager fBufferManager; 122 BufferManager fBufferManager;
123 GrGLuint fCurrArrayBuffer; 123 GrGLuint fCurrArrayBuffer;
124 GrGLuint fCurrElementArrayBuffer; 124 GrGLuint fCurrElementArrayBuffer;
125 GrGLuint fCurrProgramID; 125 GrGLuint fCurrProgramID;
126 GrGLuint fCurrShaderID; 126 GrGLuint fCurrShaderID;
127 127
128 128
129 ContextState() 129 ContextState()
130 : fCurrArrayBuffer(0) 130 : fCurrArrayBuffer(0)
131 , fCurrElementArrayBuffer(0) 131 , fCurrElementArrayBuffer(0)
132 , fCurrProgramID(0) 132 , fCurrProgramID(0)
133 , fCurrShaderID(0) {} 133 , fCurrShaderID(0) {}
134 134
135 static ContextState* Get() { 135 static ContextState* Get() { return current_context(); }
136 const SkNullGLContext* context = current_context();
137 SkASSERT(context);
138 return context->fState;
139 }
140 }; 136 };
141 137
142 typedef SkNullGLContext::ContextState State; 138 typedef SkNullGLContext::ContextState State;
143 139
144 // Functions not declared in GrGLBogusInterface.h (not common with the Debug GL interface). 140 // Functions not declared in GrGLBogusInterface.h (not common with the Debug GL interface).
145 141
146 namespace { // added to suppress 'no previous prototype' warning 142 namespace { // added to suppress 'no previous prototype' warning
147 143
148 GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {} 144 GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {}
149 GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shade r) {} 145 GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shade r) {}
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 *params = GR_GL_TRUE; 327 *params = GR_GL_TRUE;
332 } 328 }
333 } 329 }
334 break; } 330 break; }
335 default: 331 default:
336 SkFAIL("Unexpected pname to GetBufferParamateriv"); 332 SkFAIL("Unexpected pname to GetBufferParamateriv");
337 break; 333 break;
338 } 334 }
339 }; 335 };
340 336
337 class NullInterface : public GrGLInterface {
338 public:
339 NullInterface(State* state) : fState(SkRef(state)) {}
340 ~NullInterface() SK_OVERRIDE {
341 fState->unref();
342 }
343 State* fState;
344 };
345
341 } // end anonymous namespace 346 } // end anonymous namespace
342 347
343 static const GrGLInterface* create_null_interface() { 348 static GrGLInterface* create_null_interface(State* state) {
344 GrGLInterface* interface = SkNEW(GrGLInterface); 349 GrGLInterface* interface = SkNEW_ARGS(NullInterface, (state));
345 350
346 interface->fStandard = kGL_GrGLStandard; 351 interface->fStandard = kGL_GrGLStandard;
347 352
348 GrGLInterface::Functions* functions = &interface->fFunctions; 353 GrGLInterface::Functions* functions = &interface->fFunctions;
349 functions->fActiveTexture = nullGLActiveTexture; 354 functions->fActiveTexture = nullGLActiveTexture;
350 functions->fAttachShader = nullGLAttachShader; 355 functions->fAttachShader = nullGLAttachShader;
351 functions->fBeginQuery = nullGLBeginQuery; 356 functions->fBeginQuery = nullGLBeginQuery;
352 functions->fBindAttribLocation = nullGLBindAttribLocation; 357 functions->fBindAttribLocation = nullGLBindAttribLocation;
353 functions->fBindBuffer = nullGLBindBuffer; 358 functions->fBindBuffer = nullGLBindBuffer;
354 functions->fBindFragDataLocation = noOpGLBindFragDataLocation; 359 functions->fBindFragDataLocation = noOpGLBindFragDataLocation;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed; 487 functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed;
483 488
484 interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functio ns->fGetStringi, 489 interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functio ns->fGetStringi,
485 functions->fGetIntegerv); 490 functions->fGetIntegerv);
486 return interface; 491 return interface;
487 } 492 }
488 493
489 ////////////////////////////////////////////////////////////////////////////// 494 //////////////////////////////////////////////////////////////////////////////
490 495
491 static void* create_tls() { 496 static void* create_tls() {
492 const SkNullGLContext** current = SkNEW(const SkNullGLContext*); 497 State** current = SkNEW(State*);
493 *current = NULL; 498 *current = NULL;
494 return current; 499 return current;
495 } 500 }
496 501
497 static void delete_tls(void* ctx) { 502 static void delete_tls(void* ctx) {
498 const SkNullGLContext** current = static_cast<const SkNullGLContext**>(ctx); 503 State** current = static_cast<State**>(ctx);
499 if (*current) { 504 if (*current) {
500 (*current)->unref(); 505 (*current)->unref();
501 } 506 }
502 SkDELETE(current); 507 SkDELETE(current);
503 } 508 }
504 509
505 static const SkNullGLContext* current_context() { 510 static State* current_context() {
506 return *static_cast<const SkNullGLContext**>(SkTLS::Get(create_tls, delete_t ls)); 511 return *static_cast<State**>(SkTLS::Get(create_tls, delete_tls));
507 } 512 }
508 513
509 static void set_current_context(const SkNullGLContext* context) { 514 static void set_current_context(State* state) {
510 const SkNullGLContext** current = 515 State** current = static_cast<State**>(SkTLS::Get(create_tls, delete_tls));
511 static_cast<const SkNullGLContext**>(SkTLS::Get(create_tls, delete_tls)) ;
512 if (*current) { 516 if (*current) {
513 (*current)->unref(); 517 (*current)->unref();
514 } 518 }
515 *current = context; 519 *current = state;
516 if (context) { 520 if (state) {
517 context->ref(); 521 state->ref();
518 } 522 }
519 } 523 }
520 524
525 #if GR_GL_PER_GL_FUNC_CALLBACK
526 static void set_current_context_from_interface(const GrGLInterface* interface) {
527 set_current_context(reinterpret_cast<State*>(interface->fCallbackData));
528 }
529 #endif
530
521 SkNullGLContext* SkNullGLContext::Create(GrGLStandard forcedGpuAPI) { 531 SkNullGLContext* SkNullGLContext::Create(GrGLStandard forcedGpuAPI) {
522 if (kGLES_GrGLStandard == forcedGpuAPI) { 532 if (kGLES_GrGLStandard == forcedGpuAPI) {
523 return NULL; 533 return NULL;
524 } 534 }
525 SkNullGLContext* ctx = SkNEW(SkNullGLContext); 535 SkNullGLContext* ctx = SkNEW(SkNullGLContext);
526 if (!ctx->isValid()) { 536 if (!ctx->isValid()) {
527 SkDELETE(ctx); 537 SkDELETE(ctx);
528 return NULL; 538 return NULL;
529 } 539 }
530 return ctx; 540 return ctx;
531 } 541 }
532 542
533 SkNullGLContext::SkNullGLContext() { 543 SkNullGLContext::SkNullGLContext() {
534 fGL.reset(create_null_interface());
535 fState = SkNEW(ContextState); 544 fState = SkNEW(ContextState);
545 GrGLInterface* interface = create_null_interface(fState);
546 fGL.reset(interface);
547 #if GR_GL_PER_GL_FUNC_CALLBACK
548 interface->fCallback = set_current_context_from_interface;
549 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(fStat e);
550 #endif
536 } 551 }
537 552
538 SkNullGLContext::~SkNullGLContext() { 553 SkNullGLContext::~SkNullGLContext() {
539 fGL.reset(NULL); 554 fGL.reset(NULL);
540 SkDELETE(fState); 555 fState->unref();
541 } 556 }
542 557
543 void SkNullGLContext::makeCurrent() const { set_current_context(this); } 558 void SkNullGLContext::makeCurrent() const { set_current_context(fState); }
OLDNEW
« no previous file with comments | « include/gpu/gl/SkNullGLContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698