1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "GrGLNoOpInterface.h" 9 #include "SkString.h" 10 #include "SkThread.h" 11 12 // the OpenGLES 2.0 spec says this must be >= 128 13 static const GrGLint kDefaultMaxVertexUniformVectors = 128; 14 15 // the OpenGLES 2.0 spec says this must be >=16 16 static const GrGLint kDefaultMaxFragmentUniformVectors = 16; 17 18 // the OpenGLES 2.0 spec says this must be >= 8 19 static const GrGLint kDefaultMaxVertexAttribs = 8; 20 21 // the OpenGLES 2.0 spec says this must be >= 8 22 static const GrGLint kDefaultMaxVaryingVectors = 8; 23 24 static const char* kExtensions[] = { 25 "GL_ARB_framebuffer_object", 26 "GL_ARB_blend_func_extended", 27 "GL_ARB_timer_query", 28 "GL_ARB_draw_buffers", 29 "GL_ARB_occlusion_query", 30 "GL_EXT_blend_color", 31 "GL_EXT_stencil_wrap" 32 }; 33 34 namespace { 35 const GrGLubyte* combined_extensions_string() { 36 static SkString gExtString; 37 static SkMutex gMutex; 38 gMutex.acquire(); 39 if (0 == gExtString.size()) { 40 for (size_t i = 0; i < GR_ARRAY_COUNT(kExtensions) - 1; ++i) { 41 gExtString.append(kExtensions[i]); 42 gExtString.append(" "); 43 } 44 gExtString.append(kExtensions[GR_ARRAY_COUNT(kExtensions) - 1]); 45 } 46 gMutex.release(); 47 return (const GrGLubyte*) gExtString.c_str(); 48 } 49 } 50 51 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLBlendColor(GrGLclampf red, 52 GrGLclampf green, 53 GrGLclampf blue, 54 GrGLclampf alpha) { 55 } 56 57 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLBindFragDataLocation(GrGLuint program, 58 GrGLuint colorNumber, 59 const GrGLchar* name) { 60 } 61 62 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLBlendFunc(GrGLenum sfactor, 63 GrGLenum dfactor) { 64 } 65 66 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLBufferSubData(GrGLenum target, 67 GrGLintptr offset, 68 GrGLsizeiptr size, 69 const GrGLvoid* data) { 70 } 71 72 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLClear(GrGLbitfield mask) { 73 } 74 75 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLClearColor(GrGLclampf red, 76 GrGLclampf green, 77 GrGLclampf blue, 78 GrGLclampf alpha) { 79 } 80 81 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLClearStencil(GrGLint s) { 82 } 83 84 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLColorMask(GrGLboolean red, 85 GrGLboolean green, 86 GrGLboolean blue, 87 GrGLboolean alpha) { 88 } 89 90 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLCompileShader(GrGLuint shader) { 91 } 92 93 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLCompressedTexImage2D(GrGLenum target, 94 GrGLint level, 95 GrGLenum internalformat, 96 GrGLsizei width, 97 GrGLsizei height, 98 GrGLint border, 99 GrGLsizei imageSize, 100 const GrGLvoid* data) { 101 } 102 103 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLCopyTexSubImage2D(GrGLenum target, 104 GrGLint level, 105 GrGLint xoffset, 106 GrGLint yoffset, 107 GrGLint x, 108 GrGLint y, 109 GrGLsizei width, 110 GrGLsizei height) { 111 } 112 113 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLCullFace(GrGLenum mode) { 114 } 115 116 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLDepthMask(GrGLboolean flag) { 117 } 118 119 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLDisable(GrGLenum cap) { 120 } 121 122 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLDisableVertexAttribArray(GrGLuint index) { 123 } 124 125 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLDrawArrays(GrGLenum mode, 126 GrGLint first, 127 GrGLsizei count) { 128 } 129 130 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLDrawBuffer(GrGLenum mode) { 131 } 132 133 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLDrawBuffers(GrGLsizei n, 134 const GrGLenum* bufs) { 135 } 136 137 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLDrawElements(GrGLenum mode, 138 GrGLsizei count, 139 GrGLenum type, 140 const GrGLvoid* indices) { 141 } 142 143 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLEnable(GrGLenum cap) { 144 } 145 146 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLEnableVertexAttribArray(GrGLuint index) { 147 } 148 149 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLEndQuery(GrGLenum target) { 150 } 151 152 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLFinish() { 153 } 154 155 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLFlush() { 156 } 157 158 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLFrontFace(GrGLenum mode) { 159 } 160 161 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLLineWidth(GrGLfloat width) { 162 } 163 164 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLLinkProgram(GrGLuint program) { 165 } 166 167 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLQueryCounter(GrGLuint id, GrGLenum target) { 168 } 169 170 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLReadBuffer(GrGLenum src) { 171 } 172 173 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLScissor(GrGLint x, 174 GrGLint y, 175 GrGLsizei width, 176 GrGLsizei height) { 177 } 178 179 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLShaderSource(GrGLuint shader, 180 GrGLsizei count, 181 #if GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE 182 const char* const * str, 183 #else 184 const char** str, 185 #endif 186 const GrGLint* length) { 187 } 188 189 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLStencilFunc(GrGLenum func, GrGLint ref, GrGLuint mask) { 190 } 191 192 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLStencilFuncSeparate(GrGLenum face, 193 GrGLenum func, 194 GrGLint ref, 195 GrGLuint mask) { 196 } 197 198 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLStencilMask(GrGLuint mask) { 199 } 200 201 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLStencilMaskSeparate(GrGLenum face, GrGLuint mask) { 202 } 203 204 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLStencilOp(GrGLenum fail, GrGLenum zfail, GrGLenum zpass) { 205 } 206 207 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLStencilOpSeparate(GrGLenum face, 208 GrGLenum fail, 209 GrGLenum zfail, 210 GrGLenum zpass) { 211 } 212 213 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLTexImage2D(GrGLenum target, 214 GrGLint level, 215 GrGLint internalformat, 216 GrGLsizei width, 217 GrGLsizei height, 218 GrGLint border, 219 GrGLenum format, 220 GrGLenum type, 221 const GrGLvoid* pixels) { 222 } 223 224 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLTexParameteri(GrGLenum target, 225 GrGLenum pname, 226 GrGLint param) { 227 } 228 229 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLTexParameteriv(GrGLenum target, 230 GrGLenum pname, 231 const GrGLint* params) { 232 } 233 234 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLTexStorage2D(GrGLenum target, 235 GrGLsizei levels, 236 GrGLenum internalformat, 237 GrGLsizei width, 238 GrGLsizei height) { 239 } 240 241 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLDiscardFramebuffer(GrGLenum target, 242 GrGLsizei numAttachments, 243 const GrGLenum* attachments) { 244 } 245 246 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLTexSubImage2D(GrGLenum target, 247 GrGLint level, 248 GrGLint xoffset, 249 GrGLint yoffset, 250 GrGLsizei width, 251 GrGLsizei height, 252 GrGLenum format, 253 GrGLenum type, 254 const GrGLvoid* pixels) { 255 } 256 257 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform1f(GrGLint location, GrGLfloat v0) { 258 } 259 260 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform1i(GrGLint location, GrGLint v0) { 261 } 262 263 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform1fv(GrGLint location, 264 GrGLsizei count, 265 const GrGLfloat* v) { 266 } 267 268 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform1iv(GrGLint location, 269 GrGLsizei count, 270 const GrGLint* v) { 271 } 272 273 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform2f(GrGLint location, GrGLfloat v0, GrGLfloat v1) { 274 } 275 276 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform2i(GrGLint location, GrGLint v0, GrGLint v1) { 277 } 278 279 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform2fv(GrGLint location, 280 GrGLsizei count, 281 const GrGLfloat* v) { 282 } 283 284 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform2iv(GrGLint location, 285 GrGLsizei count, 286 const GrGLint* v) { 287 } 288 289 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform3f(GrGLint location, 290 GrGLfloat v0, 291 GrGLfloat v1, 292 GrGLfloat v2) { 293 } 294 295 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform3i(GrGLint location, 296 GrGLint v0, 297 GrGLint v1, 298 GrGLint v2) { 299 } 300 301 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform3fv(GrGLint location, 302 GrGLsizei count, 303 const GrGLfloat* v) { 304 } 305 306 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform3iv(GrGLint location, 307 GrGLsizei count, 308 const GrGLint* v) { 309 } 310 311 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform4f(GrGLint location, 312 GrGLfloat v0, 313 GrGLfloat v1, 314 GrGLfloat v2, 315 GrGLfloat v3) { 316 } 317 318 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform4i(GrGLint location, 319 GrGLint v0, 320 GrGLint v1, 321 GrGLint v2, 322 GrGLint v3) { 323 } 324 325 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform4fv(GrGLint location, 326 GrGLsizei count, 327 const GrGLfloat* v) { 328 } 329 330 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniform4iv(GrGLint location, 331 GrGLsizei count, 332 const GrGLint* v) { 333 } 334 335 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniformMatrix2fv(GrGLint location, 336 GrGLsizei count, 337 GrGLboolean transpose, 338 const GrGLfloat* value) { 339 } 340 341 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniformMatrix3fv(GrGLint location, 342 GrGLsizei count, 343 GrGLboolean transpose, 344 const GrGLfloat* value) { 345 } 346 347 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniformMatrix4fv(GrGLint location, 348 GrGLsizei count, 349 GrGLboolean transpose, 350 const GrGLfloat* value) { 351 } 352 353 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLVertexAttrib4fv(GrGLuint indx, const GrGLfloat* values) { 354 } 355 356 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLVertexAttribPointer(GrGLuint indx, 357 GrGLint size, 358 GrGLenum type, 359 GrGLboolean normalized, 360 GrGLsizei stride, 361 const GrGLvoid* ptr) { 362 } 363 364 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLViewport(GrGLint x, 365 GrGLint y, 366 GrGLsizei width, 367 GrGLsizei height) { 368 } 369 370 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLGetFramebufferAttachmentParameteriv(GrGLenum target, 371 GrGLenum attachment, 372 GrGLenum pname, 373 GrGLint* params) { 374 } 375 376 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLGetRenderbufferParameteriv(GrGLenum target, 377 GrGLenum pname, 378 GrGLint* params) { 379 } 380 381 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLRenderbufferStorage(GrGLenum target, 382 GrGLenum internalformat, 383 GrGLsizei width, 384 GrGLsizei height) { 385 } 386 387 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLRenderbufferStorageMultisample(GrGLenum target, 388 GrGLsizei samples, 389 GrGLenum internalformat, 390 GrGLsizei width, 391 GrGLsizei height) { 392 } 393 394 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLBlitFramebuffer(GrGLint srcX0, 395 GrGLint srcY0, 396 GrGLint srcX1, 397 GrGLint srcY1, 398 GrGLint dstX0, 399 GrGLint dstY0, 400 GrGLint dstX1, 401 GrGLint dstY1, 402 GrGLbitfield mask, 403 GrGLenum filter) { 404 } 405 406 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLResolveMultisampleFramebuffer() { 407 } 408 409 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLBindFragDataLocationIndexed(GrGLuint program, 410 GrGLuint colorNumber, 411 GrGLuint index, 412 const GrGLchar * name) { 413 } 414 415 GrGLenum GR_GL_FUNCTION_TYPE noOpGLCheckFramebufferStatus(GrGLenum target) { 416 417 GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); 418 419 return GR_GL_FRAMEBUFFER_COMPLETE; 420 } 421 422 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLGenIds(GrGLsizei n, GrGLuint* ids) { 423 static int gCurrID = 1; 424 for (int i = 0; i < n; ++i) { 425 ids[i] = ++gCurrID; 426 } 427 } 428 429 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLDeleteIds(GrGLsizei n, const GrGLuint* ids) { 430 } 431 432 GrGLenum GR_GL_FUNCTION_TYPE noOpGLGetError() { 433 return GR_GL_NO_ERROR; 434 } 435 436 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLGetIntegerv(GrGLenum pname, GrGLint* params) { 437 // TODO: remove from Ganesh the #defines for gets we don't use. 438 // We would like to minimize gets overall due to performance issues 439 switch (pname) { 440 case GR_GL_CONTEXT_PROFILE_MASK: 441 *params = GR_GL_CONTEXT_COMPATIBILITY_PROFILE_BIT; 442 break; 443 case GR_GL_STENCIL_BITS: 444 *params = 8; 445 break; 446 case GR_GL_SAMPLES: 447 *params = 1; 448 break; 449 case GR_GL_FRAMEBUFFER_BINDING: 450 *params = 0; 451 break; 452 case GR_GL_VIEWPORT: 453 params[0] = 0; 454 params[1] = 0; 455 params[2] = 800; 456 params[3] = 600; 457 break; 458 case GR_GL_MAX_TEXTURE_IMAGE_UNITS: 459 *params = 8; 460 break; 461 case GR_GL_MAX_VERTEX_UNIFORM_VECTORS: 462 *params = kDefaultMaxVertexUniformVectors; 463 break; 464 case GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS: 465 *params = kDefaultMaxFragmentUniformVectors; 466 break; 467 case GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS: 468 *params = 16 * 4; 469 break; 470 case GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS: 471 *params = 0; 472 break; 473 case GR_GL_COMPRESSED_TEXTURE_FORMATS: 474 break; 475 case GR_GL_MAX_TEXTURE_SIZE: 476 *params = 8192; 477 break; 478 case GR_GL_MAX_RENDERBUFFER_SIZE: 479 *params = 8192; 480 break; 481 case GR_GL_MAX_SAMPLES: 482 *params = 32; 483 break; 484 case GR_GL_MAX_VERTEX_ATTRIBS: 485 *params = kDefaultMaxVertexAttribs; 486 break; 487 case GR_GL_MAX_VARYING_VECTORS: 488 *params = kDefaultMaxVaryingVectors; 489 break; 490 case GR_GL_NUM_EXTENSIONS: 491 *params = GR_ARRAY_COUNT(kExtensions); 492 break; 493 default: 494 GrCrash("Unexpected pname to GetIntegerv"); 495 } 496 } 497 498 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLGetInfoLog(GrGLuint program, 499 GrGLsizei bufsize, 500 GrGLsizei* length, 501 char* infolog) { 502 if (length) { 503 *length = 0; 504 } 505 if (bufsize > 0) { 506 *infolog = 0; 507 } 508 } 509 510 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLGetShaderOrProgramiv(GrGLuint program, 511 GrGLenum pname, 512 GrGLint* params) { 513 switch (pname) { 514 case GR_GL_LINK_STATUS: // fallthru 515 case GR_GL_COMPILE_STATUS: 516 *params = GR_GL_TRUE; 517 break; 518 case GR_GL_INFO_LOG_LENGTH: 519 *params = 0; 520 break; 521 // we don't expect any other pnames 522 default: 523 GrCrash("Unexpected pname to GetProgramiv"); 524 break; 525 } 526 } 527 528 namespace { 529 template <typename T> 530 void query_result(GrGLenum GLtarget, GrGLenum pname, T *params) { 531 switch (pname) { 532 case GR_GL_QUERY_RESULT_AVAILABLE: 533 *params = GR_GL_TRUE; 534 break; 535 case GR_GL_QUERY_RESULT: 536 *params = 0; 537 break; 538 default: 539 GrCrash("Unexpected pname passed to GetQueryObject."); 540 break; 541 } 542 } 543 } 544 545 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLGetQueryiv(GrGLenum GLtarget, 546 GrGLenum pname, 547 GrGLint *params) { 548 switch (pname) { 549 case GR_GL_CURRENT_QUERY: 550 *params = 0; 551 break; 552 case GR_GL_QUERY_COUNTER_BITS: 553 *params = 32; 554 break; 555 default: 556 GrCrash("Unexpected pname passed GetQueryiv."); 557 } 558 } 559 560 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLGetQueryObjecti64v(GrGLuint id, 561 GrGLenum pname, 562 GrGLint64 *params) { 563 query_result(id, pname, params); 564 } 565 566 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLGetQueryObjectiv(GrGLuint id, 567 GrGLenum pname, 568 GrGLint *params) { 569 query_result(id, pname, params); 570 } 571 572 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLGetQueryObjectui64v(GrGLuint id, 573 GrGLenum pname, 574 GrGLuint64 *params) { 575 query_result(id, pname, params); 576 } 577 578 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLGetQueryObjectuiv(GrGLuint id, 579 GrGLenum pname, 580 GrGLuint *params) { 581 query_result(id, pname, params); 582 } 583 584 const GrGLubyte* GR_GL_FUNCTION_TYPE noOpGLGetString(GrGLenum name) { 585 switch (name) { 586 case GR_GL_EXTENSIONS: 587 return combined_extensions_string(); 588 case GR_GL_VERSION: 589 return (const GrGLubyte*)"4.0 Debug GL"; 590 case GR_GL_SHADING_LANGUAGE_VERSION: 591 return (const GrGLubyte*)"4.20.8 Debug GLSL"; 592 case GR_GL_VENDOR: 593 return (const GrGLubyte*)"Debug Vendor"; 594 case GR_GL_RENDERER: 595 return (const GrGLubyte*)"The Debug (Non-)Renderer"; 596 default: 597 GrCrash("Unexpected name passed to GetString"); 598 return NULL; 599 } 600 } 601 602 const GrGLubyte* GR_GL_FUNCTION_TYPE noOpGLGetStringi(GrGLenum name, GrGLuint i) { 603 switch (name) { 604 case GR_GL_EXTENSIONS: 605 if (static_cast<size_t>(i) <= GR_ARRAY_COUNT(kExtensions)) { 606 return (const GrGLubyte*) kExtensions[i]; 607 } else { 608 return NULL; 609 } 610 default: 611 GrCrash("Unexpected name passed to GetStringi"); 612 return NULL; 613 } 614 } 615 616 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLGetTexLevelParameteriv(GrGLenum target, 617 GrGLint level, 618 GrGLenum pname, 619 GrGLint* params) { 620 // we used to use this to query stuff about externally created textures, 621 // now we just require clients to tell us everything about the texture. 622 GrCrash("Should never query texture parameters."); 623 } 624 625 GrGLint GR_GL_FUNCTION_TYPE noOpGLGetUniformLocation(GrGLuint program, const char* name) { 626 static int gUniLocation = 0; 627 return ++gUniLocation; 628 } 629