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

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

Issue 2081183002: Support texel and draw-indirect buffers in null GL contexts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 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 | « no previous file | tools/gpu/gl/debug/DebugGLTestContext.cpp » ('j') | 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 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "gl/GrGLInterface.h" 9 #include "gl/GrGLInterface.h"
10 #include "GrGLTestInterface.h" 10 #include "GrGLTestInterface.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // Index of the first entry of fBuffers in the free list. Free slots in fBuf fers are indices to 106 // Index of the first entry of fBuffers in the free list. Free slots in fBuf fers are indices to
107 // the next free slot. The last free slot has a value of kFreeListEnd. 107 // the next free slot. The last free slot has a value of kFreeListEnd.
108 intptr_t fFreeListHead; 108 intptr_t fFreeListHead;
109 SkTDArray<BufferObj*> fBuffers; 109 SkTDArray<BufferObj*> fBuffers;
110 }; 110 };
111 111
112 /** Null interface implementation */ 112 /** Null interface implementation */
113 class NullInterface : public GrGLTestInterface { 113 class NullInterface : public GrGLTestInterface {
114 public: 114 public:
115 NullInterface(bool enableNVPR) 115 NullInterface(bool enableNVPR)
116 : fCurrArrayBuffer(0) 116 : fCurrProgramID(0)
117 , fCurrElementArrayBuffer(0)
118 , fCurrPixelPackBuffer(0)
119 , fCurrPixelUnpackBuffer(0)
120 , fCurrProgramID(0)
121 , fCurrShaderID(0) 117 , fCurrShaderID(0)
122 , fCurrGenericID(0) 118 , fCurrGenericID(0)
123 , fCurrUniformLocation(0) 119 , fCurrUniformLocation(0)
124 , fCurrPathID(0) { 120 , fCurrPathID(0) {
121 memset(fBoundBuffers, 0, sizeof(fBoundBuffers));
125 fExtensions.push_back("GL_ARB_framebuffer_object"); 122 fExtensions.push_back("GL_ARB_framebuffer_object");
126 fExtensions.push_back("GL_ARB_blend_func_extended"); 123 fExtensions.push_back("GL_ARB_blend_func_extended");
127 fExtensions.push_back("GL_ARB_timer_query"); 124 fExtensions.push_back("GL_ARB_timer_query");
128 fExtensions.push_back("GL_ARB_draw_buffers"); 125 fExtensions.push_back("GL_ARB_draw_buffers");
129 fExtensions.push_back("GL_ARB_occlusion_query"); 126 fExtensions.push_back("GL_ARB_occlusion_query");
130 fExtensions.push_back("GL_EXT_stencil_wrap"); 127 fExtensions.push_back("GL_EXT_stencil_wrap");
131 if (enableNVPR) { 128 if (enableNVPR) {
132 fExtensions.push_back("GL_NV_path_rendering"); 129 fExtensions.push_back("GL_NV_path_rendering");
133 fExtensions.push_back("GL_ARB_program_interface_query"); 130 fExtensions.push_back("GL_ARB_program_interface_query");
134 } 131 }
135 fExtensions.push_back(nullptr); 132 fExtensions.push_back(nullptr);
136 133
137 this->init(kGL_GrGLStandard); 134 this->init(kGL_GrGLStandard);
138 } 135 }
139 136
140 GrGLenum checkFramebufferStatus(GrGLenum target) override { 137 GrGLenum checkFramebufferStatus(GrGLenum target) override {
141 return GR_GL_FRAMEBUFFER_COMPLETE; 138 return GR_GL_FRAMEBUFFER_COMPLETE;
142 } 139 }
143 140
144 GrGLvoid genBuffers(GrGLsizei n, GrGLuint* ids) override { 141 GrGLvoid genBuffers(GrGLsizei n, GrGLuint* ids) override {
145 for (int i = 0; i < n; ++i) { 142 for (int i = 0; i < n; ++i) {
146 BufferObj* buffer = fBufferManager.create(); 143 BufferObj* buffer = fBufferManager.create();
147 ids[i] = buffer->id(); 144 ids[i] = buffer->id();
148 } 145 }
149 } 146 }
150 147
151 GrGLvoid bufferData(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data , 148 GrGLvoid bufferData(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data ,
152 GrGLenum usage) override { 149 GrGLenum usage) override {
153 GrGLuint id = 0; 150 GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
154
155 switch (target) {
156 case GR_GL_ARRAY_BUFFER:
157 id = fCurrArrayBuffer;
158 break;
159 case GR_GL_ELEMENT_ARRAY_BUFFER:
160 id = fCurrElementArrayBuffer;
161 break;
162 case GR_GL_PIXEL_PACK_BUFFER:
163 id = fCurrPixelPackBuffer;
164 break;
165 case GR_GL_PIXEL_UNPACK_BUFFER:
166 id = fCurrPixelUnpackBuffer;
167 break;
168 default:
169 SkFAIL("Unexpected target to nullGLBufferData");
170 break;
171 }
172
173 if (id > 0) { 151 if (id > 0) {
174 BufferObj* buffer = fBufferManager.lookUp(id); 152 BufferObj* buffer = fBufferManager.lookUp(id);
175 buffer->allocate(size, (const GrGLchar*) data); 153 buffer->allocate(size, (const GrGLchar*) data);
176 } 154 }
177 } 155 }
178 156
179 GrGLuint createProgram() override { 157 GrGLuint createProgram() override {
180 return ++fCurrProgramID; 158 return ++fCurrProgramID;
181 } 159 }
182 160
183 GrGLuint createShader(GrGLenum type) override { 161 GrGLuint createShader(GrGLenum type) override {
184 return ++fCurrShaderID; 162 return ++fCurrShaderID;
185 } 163 }
186 164
187 GrGLvoid bindBuffer(GrGLenum target, GrGLuint buffer) override { 165 GrGLvoid bindBuffer(GrGLenum target, GrGLuint buffer) override {
188 switch (target) { 166 fBoundBuffers[GetBufferIndex(target)] = buffer;
189 case GR_GL_ARRAY_BUFFER:
190 fCurrArrayBuffer = buffer;
191 break;
192 case GR_GL_ELEMENT_ARRAY_BUFFER:
193 fCurrElementArrayBuffer = buffer;
194 break;
195 case GR_GL_PIXEL_PACK_BUFFER:
196 fCurrPixelPackBuffer = buffer;
197 break;
198 case GR_GL_PIXEL_UNPACK_BUFFER:
199 fCurrPixelUnpackBuffer = buffer;
200 break;
201 }
202 } 167 }
203 168
204 // deleting a bound buffer has the side effect of binding 0 169 // deleting a bound buffer has the side effect of binding 0
205 GrGLvoid deleteBuffers(GrGLsizei n, const GrGLuint* ids) override { 170 GrGLvoid deleteBuffers(GrGLsizei n, const GrGLuint* ids) override {
171 // First potentially unbind the buffers.
172 for (int buffIdx = 0; buffIdx < kNumBufferTargets; ++buffIdx) {
173 if (!fBoundBuffers[buffIdx]) {
174 continue;
175 }
176 for (int i = 0; i < n; ++i) {
177 if (ids[i] == fBoundBuffers[buffIdx]) {
178 fBoundBuffers[buffIdx] = 0;
179 break;
180 }
181 }
182 }
183
184 // Then actually "delete" the buffers.
206 for (int i = 0; i < n; ++i) { 185 for (int i = 0; i < n; ++i) {
207 if (ids[i] == fCurrArrayBuffer) {
208 fCurrArrayBuffer = 0;
209 }
210 if (ids[i] == fCurrElementArrayBuffer) {
211 fCurrElementArrayBuffer = 0;
212 }
213 if (ids[i] == fCurrPixelPackBuffer) {
214 fCurrPixelPackBuffer = 0;
215 }
216 if (ids[i] == fCurrPixelUnpackBuffer) {
217 fCurrPixelUnpackBuffer = 0;
218 }
219
220 if (ids[i] > 0) { 186 if (ids[i] > 0) {
221 BufferObj* buffer = fBufferManager.lookUp(ids[i]); 187 BufferObj* buffer = fBufferManager.lookUp(ids[i]);
222 fBufferManager.free(buffer); 188 fBufferManager.free(buffer);
223 } 189 }
224 } 190 }
225 } 191 }
226 192
227 GrGLvoid genFramebuffers(GrGLsizei n, GrGLuint *framebuffers) override { 193 GrGLvoid genFramebuffers(GrGLsizei n, GrGLuint *framebuffers) override {
228 this->genGenericIds(n, framebuffers); 194 this->genGenericIds(n, framebuffers);
229 } 195 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 return nullptr; 366 return nullptr;
401 } 367 }
402 } 368 }
403 369
404 GrGLint getUniformLocation(GrGLuint program, const char* name) override { 370 GrGLint getUniformLocation(GrGLuint program, const char* name) override {
405 return ++fCurrUniformLocation; 371 return ++fCurrUniformLocation;
406 } 372 }
407 373
408 GrGLvoid* mapBufferRange(GrGLenum target, GrGLintptr offset, GrGLsizeiptr le ngth, 374 GrGLvoid* mapBufferRange(GrGLenum target, GrGLintptr offset, GrGLsizeiptr le ngth,
409 GrGLbitfield access) override { 375 GrGLbitfield access) override {
410 GrGLuint id = 0; 376 GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
411 switch (target) {
412 case GR_GL_ARRAY_BUFFER:
413 id = fCurrArrayBuffer;
414 break;
415 case GR_GL_ELEMENT_ARRAY_BUFFER:
416 id = fCurrElementArrayBuffer;
417 break;
418 case GR_GL_PIXEL_PACK_BUFFER:
419 id = fCurrPixelPackBuffer;
420 break;
421 case GR_GL_PIXEL_UNPACK_BUFFER:
422 id = fCurrPixelUnpackBuffer;
423 break;
424 }
425
426 if (id > 0) { 377 if (id > 0) {
427 // We just ignore the offset and length here. 378 // We just ignore the offset and length here.
428 BufferObj* buffer = fBufferManager.lookUp(id); 379 BufferObj* buffer = fBufferManager.lookUp(id);
429 SkASSERT(!buffer->mapped()); 380 SkASSERT(!buffer->mapped());
430 buffer->setMapped(true); 381 buffer->setMapped(true);
431 return buffer->dataPtr(); 382 return buffer->dataPtr();
432 } 383 }
433 return nullptr; 384 return nullptr;
434 } 385 }
435 386
436 GrGLvoid* mapBuffer(GrGLenum target, GrGLenum access) override { 387 GrGLvoid* mapBuffer(GrGLenum target, GrGLenum access) override {
437 GrGLuint id = 0; 388 GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
438 switch (target) {
439 case GR_GL_ARRAY_BUFFER:
440 id = fCurrArrayBuffer;
441 break;
442 case GR_GL_ELEMENT_ARRAY_BUFFER:
443 id = fCurrElementArrayBuffer;
444 break;
445 case GR_GL_PIXEL_PACK_BUFFER:
446 id = fCurrPixelPackBuffer;
447 break;
448 case GR_GL_PIXEL_UNPACK_BUFFER:
449 id = fCurrPixelUnpackBuffer;
450 break;
451 }
452
453 if (id > 0) { 389 if (id > 0) {
454 BufferObj* buffer = fBufferManager.lookUp(id); 390 BufferObj* buffer = fBufferManager.lookUp(id);
455 SkASSERT(!buffer->mapped()); 391 SkASSERT(!buffer->mapped());
456 buffer->setMapped(true); 392 buffer->setMapped(true);
457 return buffer->dataPtr(); 393 return buffer->dataPtr();
458 } 394 }
459 395
460 SkASSERT(false); 396 SkASSERT(false);
461 return nullptr; // no buffer bound to target 397 return nullptr; // no buffer bound to target
462 } 398 }
463 399
464 GrGLboolean unmapBuffer(GrGLenum target) override { 400 GrGLboolean unmapBuffer(GrGLenum target) override {
465 GrGLuint id = 0; 401 GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
466 switch (target) {
467 case GR_GL_ARRAY_BUFFER:
468 id = fCurrArrayBuffer;
469 break;
470 case GR_GL_ELEMENT_ARRAY_BUFFER:
471 id = fCurrElementArrayBuffer;
472 break;
473 case GR_GL_PIXEL_PACK_BUFFER:
474 id = fCurrPixelPackBuffer;
475 break;
476 case GR_GL_PIXEL_UNPACK_BUFFER:
477 id = fCurrPixelUnpackBuffer;
478 break;
479 }
480 if (id > 0) { 402 if (id > 0) {
481 BufferObj* buffer = fBufferManager.lookUp(id); 403 BufferObj* buffer = fBufferManager.lookUp(id);
482 SkASSERT(buffer->mapped()); 404 SkASSERT(buffer->mapped());
483 buffer->setMapped(false); 405 buffer->setMapped(false);
484 return GR_GL_TRUE; 406 return GR_GL_TRUE;
485 } 407 }
486 408
487 GrAlwaysAssert(false); 409 GrAlwaysAssert(false);
488 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; 410 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION;
489 } 411 }
490 412
491 GrGLvoid getBufferParameteriv(GrGLenum target, GrGLenum pname, GrGLint* para ms) override { 413 GrGLvoid getBufferParameteriv(GrGLenum target, GrGLenum pname, GrGLint* para ms) override {
492 switch (pname) { 414 switch (pname) {
493 case GR_GL_BUFFER_MAPPED: { 415 case GR_GL_BUFFER_MAPPED: {
494 *params = GR_GL_FALSE; 416 *params = GR_GL_FALSE;
495 GrGLuint id = 0; 417 GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
496 switch (target) {
497 case GR_GL_ARRAY_BUFFER:
498 id = fCurrArrayBuffer;
499 break;
500 case GR_GL_ELEMENT_ARRAY_BUFFER:
501 id = fCurrElementArrayBuffer;
502 break;
503 case GR_GL_PIXEL_PACK_BUFFER:
504 id = fCurrPixelPackBuffer;
505 break;
506 case GR_GL_PIXEL_UNPACK_BUFFER:
507 id = fCurrPixelUnpackBuffer;
508 break;
509 }
510 if (id > 0) { 418 if (id > 0) {
511 BufferObj* buffer = fBufferManager.lookUp(id); 419 BufferObj* buffer = fBufferManager.lookUp(id);
512 if (buffer->mapped()) { 420 if (buffer->mapped()) {
513 *params = GR_GL_TRUE; 421 *params = GR_GL_TRUE;
514 } 422 }
515 } 423 }
516 break; } 424 break; }
517 default: 425 default:
518 SkFAIL("Unexpected pname to GetBufferParamateriv"); 426 SkFAIL("Unexpected pname to GetBufferParamateriv");
519 break; 427 break;
520 } 428 }
521 }; 429 };
522 430
523 // NV_path_rendering 431 // NV_path_rendering
524 GrGLuint genPaths(GrGLsizei range) override { 432 GrGLuint genPaths(GrGLsizei range) override {
525 return ++fCurrPathID; 433 return ++fCurrPathID;
526 } 434 }
527 435
528 436
529 private: 437 private:
438 inline int static GetBufferIndex(GrGLenum glTarget) {
439 switch (glTarget) {
440 default: SkFAIL("Unexpected GL target to G etBufferIndex");
441 case GR_GL_ARRAY_BUFFER: return 0;
442 case GR_GL_ELEMENT_ARRAY_BUFFER: return 1;
443 case GR_GL_TEXTURE_BUFFER: return 2;
444 case GR_GL_DRAW_INDIRECT_BUFFER: return 3;
445 case GR_GL_PIXEL_PACK_BUFFER: return 4;
446 case GR_GL_PIXEL_UNPACK_BUFFER: return 5;
447 }
448 }
449 constexpr int static kNumBufferTargets = 6;
450
530 BufferManager fBufferManager; 451 BufferManager fBufferManager;
531 GrGLuint fCurrArrayBuffer; 452 GrGLuint fBoundBuffers[kNumBufferTargets];
532 GrGLuint fCurrElementArrayBuffer;
533 GrGLuint fCurrPixelPackBuffer;
534 GrGLuint fCurrPixelUnpackBuffer;
535 GrGLuint fCurrProgramID; 453 GrGLuint fCurrProgramID;
536 GrGLuint fCurrShaderID; 454 GrGLuint fCurrShaderID;
537 GrGLuint fCurrGenericID; 455 GrGLuint fCurrGenericID;
538 GrGLuint fCurrUniformLocation; 456 GrGLuint fCurrUniformLocation;
539 GrGLuint fCurrPathID; 457 GrGLuint fCurrPathID;
540 SkTArray<const char*> fExtensions; 458 SkTArray<const char*> fExtensions;
541 459
542 // the OpenGLES 2.0 spec says this must be >= 128 460 // the OpenGLES 2.0 spec says this must be >= 128
543 static const GrGLint kDefaultMaxVertexUniformVectors = 128; 461 static const GrGLint kDefaultMaxVertexUniformVectors = 128;
544 462
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 break; 533 break;
616 } 534 }
617 } 535 }
618 536
619 typedef GrGLTestInterface INHERITED; 537 typedef GrGLTestInterface INHERITED;
620 }; 538 };
621 539
622 } // anonymous namespace 540 } // anonymous namespace
623 541
624 const GrGLInterface* GrGLCreateNullInterface(bool enableNVPR) { return new NullI nterface(enableNVPR); } 542 const GrGLInterface* GrGLCreateNullInterface(bool enableNVPR) { return new NullI nterface(enableNVPR); }
OLDNEW
« no previous file with comments | « no previous file | tools/gpu/gl/debug/DebugGLTestContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698