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" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 /** | 115 /** |
116 * The state object for the null interface. | 116 * The state object for the null interface. |
117 */ | 117 */ |
118 class SkNullGLContext::ContextState : public SkRefCnt { | 118 class SkNullGLContext::ContextState : public SkRefCnt { |
119 public: | 119 public: |
120 | 120 |
121 | 121 |
122 BufferManager fBufferManager; | 122 BufferManager fBufferManager; |
123 GrGLuint fCurrArrayBuffer; | 123 GrGLuint fCurrArrayBuffer; |
124 GrGLuint fCurrElementArrayBuffer; | 124 GrGLuint fCurrElementArrayBuffer; |
125 GrGLuint fCurrPixelPackBuffer; | |
126 GrGLuint fCurrPixelUnpackBuffer; | |
127 GrGLuint fCurrProgramID; | 125 GrGLuint fCurrProgramID; |
128 GrGLuint fCurrShaderID; | 126 GrGLuint fCurrShaderID; |
129 | 127 |
130 | 128 |
131 ContextState() | 129 ContextState() |
132 : fCurrArrayBuffer(0) | 130 : fCurrArrayBuffer(0) |
133 , fCurrElementArrayBuffer(0) | 131 , fCurrElementArrayBuffer(0) |
134 , fCurrPixelPackBuffer(0) | |
135 , fCurrPixelUnpackBuffer(0) | |
136 , fCurrProgramID(0) | 132 , fCurrProgramID(0) |
137 , fCurrShaderID(0) {} | 133 , fCurrShaderID(0) {} |
138 | 134 |
139 static ContextState* Get() { return current_context(); } | 135 static ContextState* Get() { return current_context(); } |
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 |
(...skipping 23 matching lines...) Expand all Loading... |
169 State* state = State::Get(); | 165 State* state = State::Get(); |
170 GrGLuint id = 0; | 166 GrGLuint id = 0; |
171 | 167 |
172 switch (target) { | 168 switch (target) { |
173 case GR_GL_ARRAY_BUFFER: | 169 case GR_GL_ARRAY_BUFFER: |
174 id = state->fCurrArrayBuffer; | 170 id = state->fCurrArrayBuffer; |
175 break; | 171 break; |
176 case GR_GL_ELEMENT_ARRAY_BUFFER: | 172 case GR_GL_ELEMENT_ARRAY_BUFFER: |
177 id = state->fCurrElementArrayBuffer; | 173 id = state->fCurrElementArrayBuffer; |
178 break; | 174 break; |
179 case GR_GL_PIXEL_PACK_BUFFER: | |
180 id = state->fCurrPixelPackBuffer; | |
181 break; | |
182 case GR_GL_PIXEL_UNPACK_BUFFER: | |
183 id = state->fCurrPixelUnpackBuffer; | |
184 break; | |
185 default: | 175 default: |
186 SkFAIL("Unexpected target to nullGLBufferData"); | 176 SkFAIL("Unexpected target to nullGLBufferData"); |
187 break; | 177 break; |
188 } | 178 } |
189 | 179 |
190 if (id > 0) { | 180 if (id > 0) { |
191 BufferObj* buffer = state->fBufferManager.lookUp(id); | 181 BufferObj* buffer = state->fBufferManager.lookUp(id); |
192 buffer->allocate(size, (const GrGLchar*) data); | 182 buffer->allocate(size, (const GrGLchar*) data); |
193 } | 183 } |
194 } | 184 } |
(...skipping 23 matching lines...) Expand all Loading... |
218 | 208 |
219 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer)
{ | 209 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer)
{ |
220 State* state = State::Get(); | 210 State* state = State::Get(); |
221 switch (target) { | 211 switch (target) { |
222 case GR_GL_ARRAY_BUFFER: | 212 case GR_GL_ARRAY_BUFFER: |
223 state->fCurrArrayBuffer = buffer; | 213 state->fCurrArrayBuffer = buffer; |
224 break; | 214 break; |
225 case GR_GL_ELEMENT_ARRAY_BUFFER: | 215 case GR_GL_ELEMENT_ARRAY_BUFFER: |
226 state->fCurrElementArrayBuffer = buffer; | 216 state->fCurrElementArrayBuffer = buffer; |
227 break; | 217 break; |
228 case GR_GL_PIXEL_PACK_BUFFER: | |
229 state->fCurrPixelPackBuffer = buffer; | |
230 break; | |
231 case GR_GL_PIXEL_UNPACK_BUFFER: | |
232 state->fCurrPixelUnpackBuffer = buffer; | |
233 break; | |
234 } | 218 } |
235 } | 219 } |
236 | 220 |
237 // deleting a bound buffer has the side effect of binding 0 | 221 // deleting a bound buffer has the side effect of binding 0 |
238 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteBuffers(GrGLsizei n, const GrGLuint* id
s) { | 222 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteBuffers(GrGLsizei n, const GrGLuint* id
s) { |
239 State* state = State::Get(); | 223 State* state = State::Get(); |
240 for (int i = 0; i < n; ++i) { | 224 for (int i = 0; i < n; ++i) { |
241 if (ids[i] == state->fCurrArrayBuffer) { | 225 if (ids[i] == state->fCurrArrayBuffer) { |
242 state->fCurrArrayBuffer = 0; | 226 state->fCurrArrayBuffer = 0; |
243 } | 227 } |
244 if (ids[i] == state->fCurrElementArrayBuffer) { | 228 if (ids[i] == state->fCurrElementArrayBuffer) { |
245 state->fCurrElementArrayBuffer = 0; | 229 state->fCurrElementArrayBuffer = 0; |
246 } | 230 } |
247 if (ids[i] == state->fCurrPixelPackBuffer) { | |
248 state->fCurrPixelPackBuffer = 0; | |
249 } | |
250 if (ids[i] == state->fCurrPixelUnpackBuffer) { | |
251 state->fCurrPixelUnpackBuffer = 0; | |
252 } | |
253 | 231 |
254 BufferObj* buffer = state->fBufferManager.lookUp(ids[i]); | 232 BufferObj* buffer = state->fBufferManager.lookUp(ids[i]); |
255 state->fBufferManager.free(buffer); | 233 state->fBufferManager.free(buffer); |
256 } | 234 } |
257 } | 235 } |
258 | 236 |
259 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBufferRange(GrGLenum target, GrGLintptr o
ffset, | 237 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBufferRange(GrGLenum target, GrGLintptr o
ffset, |
260 GrGLsizeiptr length, GrGLbitf
ield access) { | 238 GrGLsizeiptr length, GrGLbitf
ield access) { |
261 State* state = State::Get(); | 239 State* state = State::Get(); |
262 GrGLuint id = 0; | 240 GrGLuint id = 0; |
263 switch (target) { | 241 switch (target) { |
264 case GR_GL_ARRAY_BUFFER: | 242 case GR_GL_ARRAY_BUFFER: |
265 id = state->fCurrArrayBuffer; | 243 id = state->fCurrArrayBuffer; |
266 break; | 244 break; |
267 case GR_GL_ELEMENT_ARRAY_BUFFER: | 245 case GR_GL_ELEMENT_ARRAY_BUFFER: |
268 id = state->fCurrElementArrayBuffer; | 246 id = state->fCurrElementArrayBuffer; |
269 break; | 247 break; |
270 case GR_GL_PIXEL_PACK_BUFFER: | |
271 id = state->fCurrPixelPackBuffer; | |
272 break; | |
273 case GR_GL_PIXEL_UNPACK_BUFFER: | |
274 id = state->fCurrPixelUnpackBuffer; | |
275 break; | |
276 } | 248 } |
277 | 249 |
278 if (id > 0) { | 250 if (id > 0) { |
279 // We just ignore the offset and length here. | 251 // We just ignore the offset and length here. |
280 BufferObj* buffer = state->fBufferManager.lookUp(id); | 252 BufferObj* buffer = state->fBufferManager.lookUp(id); |
281 SkASSERT(!buffer->mapped()); | 253 SkASSERT(!buffer->mapped()); |
282 buffer->setMapped(true); | 254 buffer->setMapped(true); |
283 return buffer->dataPtr(); | 255 return buffer->dataPtr(); |
284 } | 256 } |
285 return nullptr; | 257 return nullptr; |
286 } | 258 } |
287 | 259 |
288 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access)
{ | 260 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access)
{ |
289 State* state = State::Get(); | 261 State* state = State::Get(); |
290 GrGLuint id = 0; | 262 GrGLuint id = 0; |
291 switch (target) { | 263 switch (target) { |
292 case GR_GL_ARRAY_BUFFER: | 264 case GR_GL_ARRAY_BUFFER: |
293 id = state->fCurrArrayBuffer; | 265 id = state->fCurrArrayBuffer; |
294 break; | 266 break; |
295 case GR_GL_ELEMENT_ARRAY_BUFFER: | 267 case GR_GL_ELEMENT_ARRAY_BUFFER: |
296 id = state->fCurrElementArrayBuffer; | 268 id = state->fCurrElementArrayBuffer; |
297 break; | 269 break; |
298 case GR_GL_PIXEL_PACK_BUFFER: | |
299 id = state->fCurrPixelPackBuffer; | |
300 break; | |
301 case GR_GL_PIXEL_UNPACK_BUFFER: | |
302 id = state->fCurrPixelUnpackBuffer; | |
303 break; | |
304 } | 270 } |
305 | 271 |
306 if (id > 0) { | 272 if (id > 0) { |
307 BufferObj* buffer = state->fBufferManager.lookUp(id); | 273 BufferObj* buffer = state->fBufferManager.lookUp(id); |
308 SkASSERT(!buffer->mapped()); | 274 SkASSERT(!buffer->mapped()); |
309 buffer->setMapped(true); | 275 buffer->setMapped(true); |
310 return buffer->dataPtr(); | 276 return buffer->dataPtr(); |
311 } | 277 } |
312 | 278 |
313 SkASSERT(false); | 279 SkASSERT(false); |
314 return nullptr; // no buffer bound to target | 280 return nullptr; // no buffer bound to target |
315 } | 281 } |
316 | 282 |
317 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFlushMappedBufferRange(GrGLenum target, | 283 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFlushMappedBufferRange(GrGLenum target, |
318 GrGLintptr offset, | 284 GrGLintptr offset, |
319 GrGLsizeiptr length) {
} | 285 GrGLsizeiptr length) {
} |
320 | 286 |
321 | 287 |
322 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { | 288 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { |
323 State* state = State::Get(); | 289 State* state = State::Get(); |
324 GrGLuint id = 0; | 290 GrGLuint id = 0; |
325 switch (target) { | 291 switch (target) { |
326 case GR_GL_ARRAY_BUFFER: | 292 case GR_GL_ARRAY_BUFFER: |
327 id = state->fCurrArrayBuffer; | 293 id = state->fCurrArrayBuffer; |
328 break; | 294 break; |
329 case GR_GL_ELEMENT_ARRAY_BUFFER: | 295 case GR_GL_ELEMENT_ARRAY_BUFFER: |
330 id = state->fCurrElementArrayBuffer; | 296 id = state->fCurrElementArrayBuffer; |
331 break; | 297 break; |
332 case GR_GL_PIXEL_PACK_BUFFER: | |
333 id = state->fCurrPixelPackBuffer; | |
334 break; | |
335 case GR_GL_PIXEL_UNPACK_BUFFER: | |
336 id = state->fCurrPixelUnpackBuffer; | |
337 break; | |
338 } | 298 } |
339 if (id > 0) { | 299 if (id > 0) { |
340 BufferObj* buffer = state->fBufferManager.lookUp(id); | 300 BufferObj* buffer = state->fBufferManager.lookUp(id); |
341 SkASSERT(buffer->mapped()); | 301 SkASSERT(buffer->mapped()); |
342 buffer->setMapped(false); | 302 buffer->setMapped(false); |
343 return GR_GL_TRUE; | 303 return GR_GL_TRUE; |
344 } | 304 } |
345 | 305 |
346 GrAlwaysAssert(false); | 306 GrAlwaysAssert(false); |
347 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; | 307 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; |
348 } | 308 } |
349 | 309 |
350 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenu
m pname, GrGLint* params) { | 310 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenu
m pname, GrGLint* params) { |
351 State* state = State::Get(); | 311 State* state = State::Get(); |
352 switch (pname) { | 312 switch (pname) { |
353 case GR_GL_BUFFER_MAPPED: { | 313 case GR_GL_BUFFER_MAPPED: { |
354 *params = GR_GL_FALSE; | 314 *params = GR_GL_FALSE; |
355 GrGLuint id = 0; | 315 GrGLuint id = 0; |
356 switch (target) { | 316 switch (target) { |
357 case GR_GL_ARRAY_BUFFER: | 317 case GR_GL_ARRAY_BUFFER: |
358 id = state->fCurrArrayBuffer; | 318 id = state->fCurrArrayBuffer; |
359 break; | 319 break; |
360 case GR_GL_ELEMENT_ARRAY_BUFFER: | 320 case GR_GL_ELEMENT_ARRAY_BUFFER: |
361 id = state->fCurrElementArrayBuffer; | 321 id = state->fCurrElementArrayBuffer; |
362 break; | 322 break; |
363 case GR_GL_PIXEL_PACK_BUFFER: | |
364 id = state->fCurrPixelPackBuffer; | |
365 break; | |
366 case GR_GL_PIXEL_UNPACK_BUFFER: | |
367 id = state->fCurrPixelUnpackBuffer; | |
368 break; | |
369 } | 323 } |
370 if (id > 0) { | 324 if (id > 0) { |
371 BufferObj* buffer = state->fBufferManager.lookUp(id); | 325 BufferObj* buffer = state->fBufferManager.lookUp(id); |
372 if (buffer->mapped()) { | 326 if (buffer->mapped()) { |
373 *params = GR_GL_TRUE; | 327 *params = GR_GL_TRUE; |
374 } | 328 } |
375 } | 329 } |
376 break; } | 330 break; } |
377 default: | 331 default: |
378 SkFAIL("Unexpected pname to GetBufferParamateriv"); | 332 SkFAIL("Unexpected pname to GetBufferParamateriv"); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(fStat
e); | 553 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(fStat
e); |
600 #endif | 554 #endif |
601 } | 555 } |
602 | 556 |
603 SkNullGLContext::~SkNullGLContext() { | 557 SkNullGLContext::~SkNullGLContext() { |
604 this->teardown(); | 558 this->teardown(); |
605 fState->unref(); | 559 fState->unref(); |
606 } | 560 } |
607 | 561 |
608 void SkNullGLContext::onPlatformMakeCurrent() const { set_current_context(fState
); } | 562 void SkNullGLContext::onPlatformMakeCurrent() const { set_current_context(fState
); } |
OLD | NEW |