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

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

Issue 916733002: Support multiple null GL contexts on a thread. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add back old GrGLCreateNullInterface until Chrome stops using it 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 | « src/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"
11 #include "GrGLDefines.h"
12 #include "GrGLNoOpInterface.h"
13 #include "SkTDArray.h"
14 #include "SkTLS.h"
15
16 static const SkNullGLContext* current_context();
17
18 //////////////////////////////////////////////////////////////////////////////// /////////////////
19
20 class BufferObj {
21 public:
22 SK_DECLARE_INST_COUNT(BufferObj);
23
24 BufferObj(GrGLuint id) : fID(id), fDataPtr(NULL), fSize(0), fMapped(false) { }
25 ~BufferObj() { SkDELETE_ARRAY(fDataPtr); }
26
27 void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) {
28 if (fDataPtr) {
29 SkASSERT(0 != fSize);
30 SkDELETE_ARRAY(fDataPtr);
31 }
32
33 fSize = size;
34 fDataPtr = SkNEW_ARRAY(char, size);
35 }
36
37 GrGLuint id() const { return fID; }
38 GrGLchar* dataPtr() { return fDataPtr; }
39 GrGLsizeiptr size() const { return fSize; }
40
41 void setMapped(bool mapped) { fMapped = mapped; }
42 bool mapped() const { return fMapped; }
43
44 private:
45 GrGLuint fID;
46 GrGLchar* fDataPtr;
47 GrGLsizeiptr fSize; // size in bytes
48 bool fMapped;
49 };
50
51 // This class maintains a sparsely populated array of buffer pointers.
52 class BufferManager {
53 public:
54 SK_DECLARE_INST_COUNT(BufferManager);
55
56 BufferManager() : fFreeListHead(kFreeListEnd) {}
57
58 ~BufferManager() {
59 // NULL out the entries that are really free list links rather than ptrs before deleting.
60 intptr_t curr = fFreeListHead;
61 while (kFreeListEnd != curr) {
62 intptr_t next = reinterpret_cast<intptr_t>(fBuffers[SkToS32(curr)]);
63 fBuffers[SkToS32(curr)] = NULL;
64 curr = next;
65 }
66
67 fBuffers.deleteAll();
68 }
69
70 BufferObj* lookUp(GrGLuint id) {
71 BufferObj* buffer = fBuffers[id];
72 SkASSERT(buffer && buffer->id() == id);
73 return buffer;
74 }
75
76 BufferObj* create() {
77 GrGLuint id;
78 BufferObj* buffer;
79
80 if (kFreeListEnd == fFreeListHead) {
81 // no free slots - create a new one
82 id = fBuffers.count();
83 buffer = SkNEW_ARGS(BufferObj, (id));
84 *fBuffers.append() = buffer;
85 } else {
86 // grab the head of the free list and advance the head to the next f ree slot.
87 id = static_cast<GrGLuint>(fFreeListHead);
88 fFreeListHead = reinterpret_cast<intptr_t>(fBuffers[id]);
89
90 buffer = SkNEW_ARGS(BufferObj, (id));
91 fBuffers[id] = buffer;
92 }
93
94 return buffer;
95 }
96
97 void free(BufferObj* buffer) {
98 SkASSERT(fBuffers.count() > 0);
99
100 GrGLuint id = buffer->id();
101 SkDELETE(buffer);
102
103 fBuffers[id] = reinterpret_cast<BufferObj*>(fFreeListHead);
104 fFreeListHead = id;
105 }
106
107 private:
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
110 // the next free slot. The last free slot has a value of kFreeListEnd.
111 intptr_t fFreeListHead;
112 SkTDArray<BufferObj*> fBuffers;
113 };
114
115 /**
116 * The state object for the null interface.
117 */
118 struct SkNullGLContext::ContextState {
119 public:
120 SK_DECLARE_INST_COUNT(ContextState);
121
122 BufferManager fBufferManager;
123 GrGLuint fCurrArrayBuffer;
124 GrGLuint fCurrElementArrayBuffer;
125 GrGLuint fCurrProgramID;
126 GrGLuint fCurrShaderID;
127
128
129 ContextState()
130 : fCurrArrayBuffer(0)
131 , fCurrElementArrayBuffer(0)
132 , fCurrProgramID(0)
133 , fCurrShaderID(0) {}
134
135 static ContextState* Get() {
136 const SkNullGLContext* context = current_context();
137 SkASSERT(context);
138 return context->fState;
139 }
140 };
141
142 typedef SkNullGLContext::ContextState State;
143
144 // Functions not declared in GrGLBogusInterface.h (not common with the Debug GL interface).
145
146 namespace { // added to suppress 'no previous prototype' warning
147
148 GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {}
149 GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shade r) {}
150 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {}
151 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint index, const char* name) {}
152 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture ) {}
153 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindVertexArray(GrGLuint id) {}
154
155 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenBuffers(GrGLsizei n, GrGLuint* ids) {
156 State* state = State::Get();
157 for (int i = 0; i < n; ++i) {
158 BufferObj* buffer = state->fBufferManager.create();
159 ids[i] = buffer->id();
160 }
161 }
162
163 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenerateMipmap(GrGLenum target) {}
164
165 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target,
166 GrGLsizeiptr size,
167 const GrGLvoid* data,
168 GrGLenum usage) {
169 State* state = State::Get();
170 GrGLuint id = 0;
171
172 switch (target) {
173 case GR_GL_ARRAY_BUFFER:
174 id = state->fCurrArrayBuffer;
175 break;
176 case GR_GL_ELEMENT_ARRAY_BUFFER:
177 id = state->fCurrElementArrayBuffer;
178 break;
179 default:
180 SkFAIL("Unexpected target to nullGLBufferData");
181 break;
182 }
183
184 if (id > 0) {
185 BufferObj* buffer = state->fBufferManager.lookUp(id);
186 buffer->allocate(size, (const GrGLchar*) data);
187 }
188 }
189
190 GrGLvoid GR_GL_FUNCTION_TYPE nullGLPixelStorei(GrGLenum pname, GrGLint param) {}
191 GrGLvoid GR_GL_FUNCTION_TYPE nullGLReadPixels(GrGLint x, GrGLint y, GrGLsizei wi dth, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {}
192 GrGLvoid GR_GL_FUNCTION_TYPE nullGLUseProgram(GrGLuint program) {}
193 GrGLvoid GR_GL_FUNCTION_TYPE nullGLViewport(GrGLint x, GrGLint y, GrGLsizei widt h, GrGLsizei height) {}
194 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindFramebuffer(GrGLenum target, GrGLuint fra mebuffer) {}
195 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindRenderbuffer(GrGLenum target, GrGLuint re nderbuffer) {}
196 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteFramebuffers(GrGLsizei n, const GrGLuin t *framebuffers) {}
197 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteRenderbuffers(GrGLsizei n, const GrGLui nt *renderbuffers) {}
198 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferRenderbuffer(GrGLenum target, GrGL enum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer) {}
199 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferTexture2D(GrGLenum target, GrGLenu m attachment, GrGLenum textarget, GrGLuint texture, GrGLint level) {}
200
201 GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateProgram() {
202 return ++State::Get()->fCurrProgramID;
203 }
204
205 GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateShader(GrGLenum type) {
206 return ++State::Get()->fCurrShaderID;
207 }
208
209 // same delete used for shaders and programs
210 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDelete(GrGLuint program) {
211 }
212
213 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer) {
214 State* state = State::Get();
215 switch (target) {
216 case GR_GL_ARRAY_BUFFER:
217 state->fCurrArrayBuffer = buffer;
218 break;
219 case GR_GL_ELEMENT_ARRAY_BUFFER:
220 state->fCurrElementArrayBuffer = buffer;
221 break;
222 }
223 }
224
225 // deleting a bound buffer has the side effect of binding 0
226 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteBuffers(GrGLsizei n, const GrGLuint* id s) {
227 State* state = State::Get();
228 for (int i = 0; i < n; ++i) {
229 if (ids[i] == state->fCurrArrayBuffer) {
230 state->fCurrArrayBuffer = 0;
231 }
232 if (ids[i] == state->fCurrElementArrayBuffer) {
233 state->fCurrElementArrayBuffer = 0;
234 }
235
236 BufferObj* buffer = state->fBufferManager.lookUp(ids[i]);
237 state->fBufferManager.free(buffer);
238 }
239 }
240
241 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBufferRange(GrGLenum target, GrGLintptr o ffset,
242 GrGLsizeiptr length, GrGLbitf ield access) {
243 State* state = State::Get();
244 GrGLuint id = 0;
245 switch (target) {
246 case GR_GL_ARRAY_BUFFER:
247 id = state->fCurrArrayBuffer;
248 break;
249 case GR_GL_ELEMENT_ARRAY_BUFFER:
250 id = state->fCurrElementArrayBuffer;
251 break;
252 }
253
254 if (id > 0) {
255 // We just ignore the offset and length here.
256 BufferObj* buffer = state->fBufferManager.lookUp(id);
257 SkASSERT(!buffer->mapped());
258 buffer->setMapped(true);
259 return buffer->dataPtr();
260 }
261 return NULL;
262 }
263
264 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access) {
265 State* state = State::Get();
266 GrGLuint id = 0;
267 switch (target) {
268 case GR_GL_ARRAY_BUFFER:
269 id = state->fCurrArrayBuffer;
270 break;
271 case GR_GL_ELEMENT_ARRAY_BUFFER:
272 id = state->fCurrElementArrayBuffer;
273 break;
274 }
275
276 if (id > 0) {
277 BufferObj* buffer = state->fBufferManager.lookUp(id);
278 SkASSERT(!buffer->mapped());
279 buffer->setMapped(true);
280 return buffer->dataPtr();
281 }
282
283 SkASSERT(false);
284 return NULL; // no buffer bound to target
285 }
286
287 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFlushMappedBufferRange(GrGLenum target,
288 GrGLintptr offset,
289 GrGLsizeiptr length) { }
290
291
292 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) {
293 State* state = State::Get();
294 GrGLuint id = 0;
295 switch (target) {
296 case GR_GL_ARRAY_BUFFER:
297 id = state->fCurrArrayBuffer;
298 break;
299 case GR_GL_ELEMENT_ARRAY_BUFFER:
300 id = state->fCurrElementArrayBuffer;
301 break;
302 }
303 if (id > 0) {
304 BufferObj* buffer = state->fBufferManager.lookUp(id);
305 SkASSERT(buffer->mapped());
306 buffer->setMapped(false);
307 return GR_GL_TRUE;
308 }
309
310 GrAlwaysAssert(false);
311 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION;
312 }
313
314 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenu m pname, GrGLint* params) {
315 State* state = State::Get();
316 switch (pname) {
317 case GR_GL_BUFFER_MAPPED: {
318 *params = GR_GL_FALSE;
319 GrGLuint id = 0;
320 switch (target) {
321 case GR_GL_ARRAY_BUFFER:
322 id = state->fCurrArrayBuffer;
323 break;
324 case GR_GL_ELEMENT_ARRAY_BUFFER:
325 id = state->fCurrElementArrayBuffer;
326 break;
327 }
328 if (id > 0) {
329 BufferObj* buffer = state->fBufferManager.lookUp(id);
330 if (buffer->mapped()) {
331 *params = GR_GL_TRUE;
332 }
333 }
334 break; }
335 default:
336 SkFAIL("Unexpected pname to GetBufferParamateriv");
337 break;
338 }
339 };
340
341 } // end anonymous namespace
342
343 static const GrGLInterface* create_null_interface() {
344 GrGLInterface* interface = SkNEW(GrGLInterface);
345
346 interface->fStandard = kGL_GrGLStandard;
347
348 GrGLInterface::Functions* functions = &interface->fFunctions;
349 functions->fActiveTexture = nullGLActiveTexture;
350 functions->fAttachShader = nullGLAttachShader;
351 functions->fBeginQuery = nullGLBeginQuery;
352 functions->fBindAttribLocation = nullGLBindAttribLocation;
353 functions->fBindBuffer = nullGLBindBuffer;
354 functions->fBindFragDataLocation = noOpGLBindFragDataLocation;
355 functions->fBindTexture = nullGLBindTexture;
356 functions->fBindVertexArray = nullGLBindVertexArray;
357 functions->fBlendColor = noOpGLBlendColor;
358 functions->fBlendFunc = noOpGLBlendFunc;
359 functions->fBufferData = nullGLBufferData;
360 functions->fBufferSubData = noOpGLBufferSubData;
361 functions->fClear = noOpGLClear;
362 functions->fClearColor = noOpGLClearColor;
363 functions->fClearStencil = noOpGLClearStencil;
364 functions->fColorMask = noOpGLColorMask;
365 functions->fCompileShader = noOpGLCompileShader;
366 functions->fCompressedTexImage2D = noOpGLCompressedTexImage2D;
367 functions->fCompressedTexSubImage2D = noOpGLCompressedTexSubImage2D;
368 functions->fCopyTexSubImage2D = noOpGLCopyTexSubImage2D;
369 functions->fCreateProgram = nullGLCreateProgram;
370 functions->fCreateShader = nullGLCreateShader;
371 functions->fCullFace = noOpGLCullFace;
372 functions->fDeleteBuffers = nullGLDeleteBuffers;
373 functions->fDeleteProgram = nullGLDelete;
374 functions->fDeleteQueries = noOpGLDeleteIds;
375 functions->fDeleteShader = nullGLDelete;
376 functions->fDeleteTextures = noOpGLDeleteIds;
377 functions->fDeleteVertexArrays = noOpGLDeleteIds;
378 functions->fDepthMask = noOpGLDepthMask;
379 functions->fDisable = noOpGLDisable;
380 functions->fDisableVertexAttribArray = noOpGLDisableVertexAttribArray;
381 functions->fDrawArrays = noOpGLDrawArrays;
382 functions->fDrawBuffer = noOpGLDrawBuffer;
383 functions->fDrawBuffers = noOpGLDrawBuffers;
384 functions->fDrawElements = noOpGLDrawElements;
385 functions->fEnable = noOpGLEnable;
386 functions->fEnableVertexAttribArray = noOpGLEnableVertexAttribArray;
387 functions->fEndQuery = noOpGLEndQuery;
388 functions->fFinish = noOpGLFinish;
389 functions->fFlush = noOpGLFlush;
390 functions->fFlushMappedBufferRange = nullGLFlushMappedBufferRange;
391 functions->fFrontFace = noOpGLFrontFace;
392 functions->fGenBuffers = nullGLGenBuffers;
393 functions->fGenerateMipmap = nullGLGenerateMipmap;
394 functions->fGenQueries = noOpGLGenIds;
395 functions->fGenTextures = noOpGLGenIds;
396 functions->fGenVertexArrays = noOpGLGenIds;
397 functions->fGetBufferParameteriv = nullGLGetBufferParameteriv;
398 functions->fGetError = noOpGLGetError;
399 functions->fGetIntegerv = noOpGLGetIntegerv;
400 functions->fGetQueryObjecti64v = noOpGLGetQueryObjecti64v;
401 functions->fGetQueryObjectiv = noOpGLGetQueryObjectiv;
402 functions->fGetQueryObjectui64v = noOpGLGetQueryObjectui64v;
403 functions->fGetQueryObjectuiv = noOpGLGetQueryObjectuiv;
404 functions->fGetQueryiv = noOpGLGetQueryiv;
405 functions->fGetProgramInfoLog = noOpGLGetInfoLog;
406 functions->fGetProgramiv = noOpGLGetShaderOrProgramiv;
407 functions->fGetShaderInfoLog = noOpGLGetInfoLog;
408 functions->fGetShaderiv = noOpGLGetShaderOrProgramiv;
409 functions->fGetString = noOpGLGetString;
410 functions->fGetStringi = noOpGLGetStringi;
411 functions->fGetTexLevelParameteriv = noOpGLGetTexLevelParameteriv;
412 functions->fGetUniformLocation = noOpGLGetUniformLocation;
413 functions->fInsertEventMarker = noOpGLInsertEventMarker;
414 functions->fLineWidth = noOpGLLineWidth;
415 functions->fLinkProgram = noOpGLLinkProgram;
416 functions->fMapBuffer = nullGLMapBuffer;
417 functions->fMapBufferRange = nullGLMapBufferRange;
418 functions->fPixelStorei = nullGLPixelStorei;
419 functions->fPopGroupMarker = noOpGLPopGroupMarker;
420 functions->fPushGroupMarker = noOpGLPushGroupMarker;
421 functions->fQueryCounter = noOpGLQueryCounter;
422 functions->fReadBuffer = noOpGLReadBuffer;
423 functions->fReadPixels = nullGLReadPixels;
424 functions->fScissor = noOpGLScissor;
425 functions->fShaderSource = noOpGLShaderSource;
426 functions->fStencilFunc = noOpGLStencilFunc;
427 functions->fStencilFuncSeparate = noOpGLStencilFuncSeparate;
428 functions->fStencilMask = noOpGLStencilMask;
429 functions->fStencilMaskSeparate = noOpGLStencilMaskSeparate;
430 functions->fStencilOp = noOpGLStencilOp;
431 functions->fStencilOpSeparate = noOpGLStencilOpSeparate;
432 functions->fTexImage2D = noOpGLTexImage2D;
433 functions->fTexParameteri = noOpGLTexParameteri;
434 functions->fTexParameteriv = noOpGLTexParameteriv;
435 functions->fTexSubImage2D = noOpGLTexSubImage2D;
436 functions->fTexStorage2D = noOpGLTexStorage2D;
437 functions->fDiscardFramebuffer = noOpGLDiscardFramebuffer;
438 functions->fUniform1f = noOpGLUniform1f;
439 functions->fUniform1i = noOpGLUniform1i;
440 functions->fUniform1fv = noOpGLUniform1fv;
441 functions->fUniform1iv = noOpGLUniform1iv;
442 functions->fUniform2f = noOpGLUniform2f;
443 functions->fUniform2i = noOpGLUniform2i;
444 functions->fUniform2fv = noOpGLUniform2fv;
445 functions->fUniform2iv = noOpGLUniform2iv;
446 functions->fUniform3f = noOpGLUniform3f;
447 functions->fUniform3i = noOpGLUniform3i;
448 functions->fUniform3fv = noOpGLUniform3fv;
449 functions->fUniform3iv = noOpGLUniform3iv;
450 functions->fUniform4f = noOpGLUniform4f;
451 functions->fUniform4i = noOpGLUniform4i;
452 functions->fUniform4fv = noOpGLUniform4fv;
453 functions->fUniform4iv = noOpGLUniform4iv;
454 functions->fUniformMatrix2fv = noOpGLUniformMatrix2fv;
455 functions->fUniformMatrix3fv = noOpGLUniformMatrix3fv;
456 functions->fUniformMatrix4fv = noOpGLUniformMatrix4fv;
457 functions->fUnmapBuffer = nullGLUnmapBuffer;
458 functions->fUseProgram = nullGLUseProgram;
459 functions->fVertexAttrib1f = noOpGLVertexAttrib1f;
460 functions->fVertexAttrib2fv = noOpGLVertexAttrib2fv;
461 functions->fVertexAttrib3fv = noOpGLVertexAttrib3fv;
462 functions->fVertexAttrib4fv = noOpGLVertexAttrib4fv;
463 functions->fVertexAttribPointer = noOpGLVertexAttribPointer;
464 functions->fViewport = nullGLViewport;
465 functions->fBindFramebuffer = nullGLBindFramebuffer;
466 functions->fBindRenderbuffer = nullGLBindRenderbuffer;
467 functions->fCheckFramebufferStatus = noOpGLCheckFramebufferStatus;
468 functions->fDeleteFramebuffers = nullGLDeleteFramebuffers;
469 functions->fDeleteRenderbuffers = nullGLDeleteRenderbuffers;
470 functions->fFramebufferRenderbuffer = nullGLFramebufferRenderbuffer;
471 functions->fFramebufferTexture2D = nullGLFramebufferTexture2D;
472 functions->fGenFramebuffers = noOpGLGenIds;
473 functions->fGenRenderbuffers = noOpGLGenIds;
474 functions->fGetFramebufferAttachmentParameteriv = noOpGLGetFramebufferAttach mentParameteriv;
475 functions->fGetRenderbufferParameteriv = noOpGLGetRenderbufferParameteriv;
476 functions->fRenderbufferStorage = noOpGLRenderbufferStorage;
477 functions->fRenderbufferStorageMultisample = noOpGLRenderbufferStorageMultis ample;
478 functions->fBlitFramebuffer = noOpGLBlitFramebuffer;
479 functions->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFramebuf fer;
480 functions->fMatrixLoadf = noOpGLMatrixLoadf;
481 functions->fMatrixLoadIdentity = noOpGLMatrixLoadIdentity;
482 functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed;
483
484 interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functio ns->fGetStringi,
485 functions->fGetIntegerv);
486 return interface;
487 }
488
489 //////////////////////////////////////////////////////////////////////////////
490
491 static void* create_tls() {
492 const SkNullGLContext** current = SkNEW(const SkNullGLContext*);
493 *current = NULL;
494 return current;
495 }
496
497 static void delete_tls(void* ctx) {
498 const SkNullGLContext** current = static_cast<const SkNullGLContext**>(ctx);
499 if (*current) {
500 (*current)->unref();
501 }
502 SkDELETE(current);
503 }
504
505 static const SkNullGLContext* current_context() {
506 return *static_cast<const SkNullGLContext**>(SkTLS::Get(create_tls, delete_t ls));
507 }
508
509 static void set_current_context(const SkNullGLContext* context) {
510 const SkNullGLContext** current =
511 static_cast<const SkNullGLContext**>(SkTLS::Get(create_tls, delete_tls)) ;
512 if (*current) {
513 (*current)->unref();
514 }
515 *current = context;
516 if (context) {
517 context->ref();
518 }
519 }
520
521 SkNullGLContext* SkNullGLContext::Create(GrGLStandard forcedGpuAPI) {
522 if (kGLES_GrGLStandard == forcedGpuAPI) {
523 return NULL;
524 }
525 SkNullGLContext* ctx = SkNEW(SkNullGLContext);
526 if (!ctx->isValid()) {
527 SkDELETE(ctx);
528 return NULL;
529 }
530 return ctx;
531 }
10 532
11 SkNullGLContext::SkNullGLContext() { 533 SkNullGLContext::SkNullGLContext() {
12 fGL.reset(GrGLCreateNullInterface()); 534 fGL.reset(create_null_interface());
535 fState = SkNEW(ContextState);
13 } 536 }
14 537
15 SkNullGLContext::~SkNullGLContext() { 538 SkNullGLContext::~SkNullGLContext() {
16 fGL.reset(NULL); 539 fGL.reset(NULL);
17 } 540 SkDELETE(fState);
18 541 }
542
543 void SkNullGLContext::makeCurrent() const { set_current_context(this); }
OLDNEW
« no previous file with comments | « src/gpu/gl/SkNullGLContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698