Fix crash in SpeechRecognizerImpl introduced in AudioParams refactor.
[chromium-blink-merge.git] / gpu / command_buffer / common / gles2_cmd_utils.cc
blob063a37e2b6567701754864475ccfee3108509d3c
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file is here so other GLES2 related files can have a common set of
6 // includes where appropriate.
8 #include <sstream>
9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h>
11 #include <GLES2/gl2extchromium.h>
12 #include <GLES3/gl3.h>
14 #include "base/numerics/safe_math.h"
15 #include "gpu/command_buffer/common/gles2_cmd_format.h"
16 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
18 namespace gpu {
19 namespace gles2 {
21 namespace gl_error_bit {
22 enum GLErrorBit {
23 kNoError = 0,
24 kInvalidEnum = (1 << 0),
25 kInvalidValue = (1 << 1),
26 kInvalidOperation = (1 << 2),
27 kOutOfMemory = (1 << 3),
28 kInvalidFrameBufferOperation = (1 << 4),
29 kContextLost = (1 << 5)
33 int GLES2Util::GLGetNumValuesReturned(int id) const {
34 switch (id) {
35 // -- glGetBooleanv, glGetFloatv, glGetIntergerv
36 case GL_ACTIVE_TEXTURE:
37 return 1;
38 case GL_ALIASED_LINE_WIDTH_RANGE:
39 return 2;
40 case GL_ALIASED_POINT_SIZE_RANGE:
41 return 2;
42 case GL_ALPHA_BITS:
43 return 1;
44 case GL_ARRAY_BUFFER_BINDING:
45 return 1;
46 case GL_BLEND:
47 return 1;
48 case GL_BLEND_COLOR:
49 return 4;
50 case GL_BLEND_DST_ALPHA:
51 return 1;
52 case GL_BLEND_DST_RGB:
53 return 1;
54 case GL_BLEND_EQUATION_ALPHA:
55 return 1;
56 case GL_BLEND_EQUATION_RGB:
57 return 1;
58 case GL_BLEND_SRC_ALPHA:
59 return 1;
60 case GL_BLEND_SRC_RGB:
61 return 1;
62 case GL_BLUE_BITS:
63 return 1;
64 case GL_COLOR_CLEAR_VALUE:
65 return 4;
66 case GL_COLOR_WRITEMASK:
67 return 4;
68 case GL_COMPRESSED_TEXTURE_FORMATS:
69 return num_compressed_texture_formats_;
70 case GL_CULL_FACE:
71 return 1;
72 case GL_CULL_FACE_MODE:
73 return 1;
74 case GL_CURRENT_PROGRAM:
75 return 1;
76 case GL_DEPTH_BITS:
77 return 1;
78 case GL_DEPTH_CLEAR_VALUE:
79 return 1;
80 case GL_DEPTH_FUNC:
81 return 1;
82 case GL_DEPTH_RANGE:
83 return 2;
84 case GL_DEPTH_TEST:
85 return 1;
86 case GL_DEPTH_WRITEMASK:
87 return 1;
88 case GL_DITHER:
89 return 1;
90 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
91 return 1;
92 case GL_FRAMEBUFFER_BINDING:
93 return 1;
94 case GL_FRONT_FACE:
95 return 1;
96 case GL_GENERATE_MIPMAP_HINT:
97 return 1;
98 case GL_GREEN_BITS:
99 return 1;
100 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
101 return 1;
102 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
103 return 1;
104 case GL_LINE_WIDTH:
105 return 1;
106 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
107 return 1;
108 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
109 return 1;
110 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
111 return 1;
112 case GL_MAX_RENDERBUFFER_SIZE:
113 return 1;
114 case GL_MAX_TEXTURE_IMAGE_UNITS:
115 return 1;
116 case GL_MAX_TEXTURE_SIZE:
117 return 1;
118 case GL_MAX_VARYING_VECTORS:
119 return 1;
120 case GL_MAX_VERTEX_ATTRIBS:
121 return 1;
122 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
123 return 1;
124 case GL_MAX_VERTEX_UNIFORM_VECTORS:
125 return 1;
126 case GL_MAX_VIEWPORT_DIMS:
127 return 2;
128 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
129 return 1;
130 case GL_NUM_SHADER_BINARY_FORMATS:
131 return 1;
132 case GL_PACK_ALIGNMENT:
133 return 1;
134 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
135 return 1;
136 case GL_POLYGON_OFFSET_FACTOR:
137 return 1;
138 case GL_POLYGON_OFFSET_FILL:
139 return 1;
140 case GL_POLYGON_OFFSET_UNITS:
141 return 1;
142 case GL_RED_BITS:
143 return 1;
144 case GL_RENDERBUFFER_BINDING:
145 return 1;
146 case GL_SAMPLE_BUFFERS:
147 return 1;
148 case GL_SAMPLE_COVERAGE_INVERT:
149 return 1;
150 case GL_SAMPLE_COVERAGE_VALUE:
151 return 1;
152 case GL_SAMPLES:
153 return 1;
154 case GL_SCISSOR_BOX:
155 return 4;
156 case GL_SCISSOR_TEST:
157 return 1;
158 case GL_SHADER_BINARY_FORMATS:
159 return num_shader_binary_formats_;
160 case GL_SHADER_COMPILER:
161 return 1;
162 case GL_STENCIL_BACK_FAIL:
163 return 1;
164 case GL_STENCIL_BACK_FUNC:
165 return 1;
166 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
167 return 1;
168 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
169 return 1;
170 case GL_STENCIL_BACK_REF:
171 return 1;
172 case GL_STENCIL_BACK_VALUE_MASK:
173 return 1;
174 case GL_STENCIL_BACK_WRITEMASK:
175 return 1;
176 case GL_STENCIL_BITS:
177 return 1;
178 case GL_STENCIL_CLEAR_VALUE:
179 return 1;
180 case GL_STENCIL_FAIL:
181 return 1;
182 case GL_STENCIL_FUNC:
183 return 1;
184 case GL_STENCIL_PASS_DEPTH_FAIL:
185 return 1;
186 case GL_STENCIL_PASS_DEPTH_PASS:
187 return 1;
188 case GL_STENCIL_REF:
189 return 1;
190 case GL_STENCIL_TEST:
191 return 1;
192 case GL_STENCIL_VALUE_MASK:
193 return 1;
194 case GL_STENCIL_WRITEMASK:
195 return 1;
196 case GL_SUBPIXEL_BITS:
197 return 1;
198 case GL_TEXTURE_BINDING_2D:
199 return 1;
200 case GL_TEXTURE_BINDING_CUBE_MAP:
201 return 1;
202 case GL_TEXTURE_BINDING_EXTERNAL_OES:
203 return 1;
204 case GL_TEXTURE_BINDING_RECTANGLE_ARB:
205 return 1;
206 case GL_UNPACK_ALIGNMENT:
207 return 1;
208 case GL_VIEWPORT:
209 return 4;
211 // ES3
212 case GL_COPY_READ_BUFFER_BINDING:
213 return 1;
214 case GL_COPY_WRITE_BUFFER_BINDING:
215 return 1;
216 case GL_PIXEL_PACK_BUFFER_BINDING:
217 return 1;
218 case GL_PIXEL_UNPACK_BUFFER_BINDING:
219 return 1;
220 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
221 return 1;
222 case GL_UNIFORM_BUFFER_BINDING:
223 return 1;
225 // -- glGetBooleanv, glGetFloatv, glGetIntergerv with
226 // GL_CHROMIUM_framebuffer_multisample
227 case GL_MAX_SAMPLES_EXT:
228 return 1;
229 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
230 return 1;
232 // -- glGetBufferParameteriv
233 case GL_BUFFER_SIZE:
234 return 1;
235 case GL_BUFFER_USAGE:
236 return 1;
238 // ES3
239 case GL_BUFFER_MAPPED:
240 return 1;
241 case GL_BUFFER_ACCESS_FLAGS:
242 return 1;
243 case GL_BUFFER_MAP_LENGTH:
244 return 1;
245 case GL_BUFFER_MAP_OFFSET:
246 return 1;
248 // -- glGetFramebufferAttachmentParameteriv
249 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
250 return 1;
251 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
252 return 1;
253 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
254 return 1;
255 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
256 return 1;
257 // -- glGetFramebufferAttachmentParameteriv with
258 // GL_EXT_multisampled_render_to_texture
259 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT:
260 return 1;
261 // -- glGetFramebufferAttachmentParameteriv with
262 // GL_EXT_sRGB
263 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT:
264 return 1;
265 // ES3
266 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
267 return 1;
268 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
269 return 1;
270 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
271 return 1;
272 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
273 return 1;
274 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
275 return 1;
276 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
277 return 1;
278 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
279 return 1;
280 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
281 return 1;
283 // -- glGetProgramiv
284 case GL_DELETE_STATUS:
285 return 1;
286 case GL_LINK_STATUS:
287 return 1;
288 case GL_VALIDATE_STATUS:
289 return 1;
290 case GL_INFO_LOG_LENGTH:
291 return 1;
292 case GL_ATTACHED_SHADERS:
293 return 1;
294 case GL_ACTIVE_ATTRIBUTES:
295 return 1;
296 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
297 return 1;
298 case GL_ACTIVE_UNIFORMS:
299 return 1;
300 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
301 return 1;
303 // -- glGetRenderbufferAttachmentParameteriv
304 case GL_RENDERBUFFER_WIDTH:
305 return 1;
306 case GL_RENDERBUFFER_HEIGHT:
307 return 1;
308 case GL_RENDERBUFFER_INTERNAL_FORMAT:
309 return 1;
310 case GL_RENDERBUFFER_RED_SIZE:
311 return 1;
312 case GL_RENDERBUFFER_GREEN_SIZE:
313 return 1;
314 case GL_RENDERBUFFER_BLUE_SIZE:
315 return 1;
316 case GL_RENDERBUFFER_ALPHA_SIZE:
317 return 1;
318 case GL_RENDERBUFFER_DEPTH_SIZE:
319 return 1;
320 case GL_RENDERBUFFER_STENCIL_SIZE:
321 return 1;
322 // -- glGetRenderbufferAttachmentParameteriv with
323 // GL_EXT_multisampled_render_to_texture
324 case GL_RENDERBUFFER_SAMPLES_EXT:
325 return 1;
327 // -- glGetShaderiv
328 case GL_SHADER_TYPE:
329 return 1;
330 // Already defined under glGetFramebufferAttachemntParameteriv.
331 // case GL_DELETE_STATUS:
332 // return 1;
333 case GL_COMPILE_STATUS:
334 return 1;
335 // Already defined under glGetFramebufferAttachemntParameteriv.
336 // case GL_INFO_LOG_LENGTH:
337 // return 1;
338 case GL_SHADER_SOURCE_LENGTH:
339 return 1;
340 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
341 return 1;
343 // -- glGetTexParameterfv, glGetTexParameteriv
344 case GL_TEXTURE_MAG_FILTER:
345 return 1;
346 case GL_TEXTURE_MIN_FILTER:
347 return 1;
348 case GL_TEXTURE_WRAP_R:
349 return 1;
350 case GL_TEXTURE_WRAP_S:
351 return 1;
352 case GL_TEXTURE_WRAP_T:
353 return 1;
354 case GL_TEXTURE_COMPARE_FUNC:
355 return 1;
356 case GL_TEXTURE_COMPARE_MODE:
357 return 1;
358 case GL_TEXTURE_MAX_LOD:
359 return 1;
360 case GL_TEXTURE_MIN_LOD:
361 return 1;
362 case GL_TEXTURE_BASE_LEVEL:
363 return 1;
364 case GL_TEXTURE_MAX_LEVEL:
365 return 1;
366 case GL_TEXTURE_IMMUTABLE_FORMAT:
367 return 1;
368 case GL_TEXTURE_IMMUTABLE_LEVELS:
369 return 1;
370 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
371 return 1;
373 // -- glGetVertexAttrib
374 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
375 return 1;
376 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
377 return 1;
378 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
379 return 1;
380 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
381 return 1;
382 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
383 return 1;
384 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
385 return 1;
386 case GL_CURRENT_VERTEX_ATTRIB:
387 return 4;
388 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
389 return 1;
390 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
391 return 1;
393 // -- glGetSynciv
394 case GL_OBJECT_TYPE:
395 return 1;
396 case GL_SYNC_STATUS:
397 return 1;
398 case GL_SYNC_CONDITION:
399 return 1;
400 case GL_SYNC_FLAGS:
401 return 1;
403 // -- glHint with GL_OES_standard_derivatives
404 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
405 return 1;
407 // Chromium internal bind_generates_resource query
408 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
409 return 1;
411 // bad enum
412 default:
413 return 0;
417 namespace {
419 // Return the number of elements per group of a specified format.
420 int ElementsPerGroup(int format, int type) {
421 switch (type) {
422 case GL_UNSIGNED_SHORT_5_6_5:
423 case GL_UNSIGNED_SHORT_4_4_4_4:
424 case GL_UNSIGNED_SHORT_5_5_5_1:
425 case GL_UNSIGNED_INT_24_8_OES:
426 case GL_UNSIGNED_INT_2_10_10_10_REV:
427 case GL_UNSIGNED_INT_10F_11F_11F_REV:
428 case GL_UNSIGNED_INT_5_9_9_9_REV:
429 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
430 return 1;
431 default:
432 break;
435 switch (format) {
436 case GL_RGB:
437 case GL_RGB_INTEGER:
438 case GL_SRGB_EXT:
439 return 3;
440 case GL_LUMINANCE_ALPHA:
441 case GL_RG_EXT:
442 case GL_RG_INTEGER:
443 return 2;
444 case GL_RGBA:
445 case GL_RGBA_INTEGER:
446 case GL_BGRA_EXT:
447 case GL_SRGB_ALPHA_EXT:
448 return 4;
449 case GL_ALPHA:
450 case GL_LUMINANCE:
451 case GL_DEPTH_COMPONENT:
452 case GL_DEPTH_COMPONENT24_OES:
453 case GL_DEPTH_COMPONENT32_OES:
454 case GL_DEPTH_COMPONENT16:
455 case GL_DEPTH24_STENCIL8_OES:
456 case GL_DEPTH_STENCIL_OES:
457 case GL_RED_EXT:
458 case GL_RED_INTEGER:
459 return 1;
460 default:
461 return 0;
465 // Return the number of bytes per element, based on the element type.
466 int BytesPerElement(int type) {
467 switch (type) {
468 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
469 return 8;
470 case GL_FLOAT:
471 case GL_UNSIGNED_INT_24_8_OES:
472 case GL_UNSIGNED_INT:
473 case GL_INT:
474 case GL_UNSIGNED_INT_2_10_10_10_REV:
475 case GL_UNSIGNED_INT_10F_11F_11F_REV:
476 case GL_UNSIGNED_INT_5_9_9_9_REV:
477 return 4;
478 case GL_HALF_FLOAT:
479 case GL_HALF_FLOAT_OES:
480 case GL_UNSIGNED_SHORT:
481 case GL_SHORT:
482 case GL_UNSIGNED_SHORT_5_6_5:
483 case GL_UNSIGNED_SHORT_4_4_4_4:
484 case GL_UNSIGNED_SHORT_5_5_5_1:
485 return 2;
486 case GL_UNSIGNED_BYTE:
487 case GL_BYTE:
488 return 1;
489 default:
490 return 0;
494 } // anonymous namespace
496 uint32 GLES2Util::ComputeImageGroupSize(int format, int type) {
497 int bytes_per_element = BytesPerElement(type);
498 DCHECK_GE(8, bytes_per_element);
499 int elements_per_group = ElementsPerGroup(format, type);
500 DCHECK_GE(4, elements_per_group);
501 return bytes_per_element * elements_per_group;
504 bool GLES2Util::ComputeImagePaddedRowSize(
505 int width, int format, int type, int unpack_alignment,
506 uint32* padded_row_size) {
507 DCHECK(unpack_alignment == 1 || unpack_alignment == 2 ||
508 unpack_alignment == 4 || unpack_alignment == 8);
509 uint32 bytes_per_group = ComputeImageGroupSize(format, type);
510 uint32 unpadded_row_size;
511 if (!SafeMultiplyUint32(width, bytes_per_group, &unpadded_row_size)) {
512 return false;
514 uint32 temp;
515 if (!SafeAddUint32(unpadded_row_size, unpack_alignment - 1, &temp)) {
516 return false;
518 *padded_row_size = (temp / unpack_alignment) * unpack_alignment;
519 return true;
522 // Returns the amount of data glTexImage*D or glTexSubImage*D will access.
523 bool GLES2Util::ComputeImageDataSizes(
524 int width, int height, int depth, int format, int type,
525 int unpack_alignment, uint32* size, uint32* ret_unpadded_row_size,
526 uint32* ret_padded_row_size) {
527 DCHECK(unpack_alignment == 1 || unpack_alignment == 2 ||
528 unpack_alignment == 4 || unpack_alignment == 8);
529 uint32 bytes_per_group = ComputeImageGroupSize(format, type);
530 uint32 row_size;
531 if (!SafeMultiplyUint32(width, bytes_per_group, &row_size)) {
532 return false;
534 uint32 num_of_rows;
535 if (!SafeMultiplyUint32(height, depth, &num_of_rows)) {
536 return false;
538 if (num_of_rows > 1) {
539 uint32 temp;
540 if (!SafeAddUint32(row_size, unpack_alignment - 1, &temp)) {
541 return false;
543 uint32 padded_row_size = (temp / unpack_alignment) * unpack_alignment;
544 uint32 size_of_all_but_last_row;
545 if (!SafeMultiplyUint32((num_of_rows - 1), padded_row_size,
546 &size_of_all_but_last_row)) {
547 return false;
549 if (!SafeAddUint32(size_of_all_but_last_row, row_size, size)) {
550 return false;
552 if (ret_padded_row_size) {
553 *ret_padded_row_size = padded_row_size;
555 } else {
556 *size = row_size;
557 if (ret_padded_row_size) {
558 *ret_padded_row_size = row_size;
561 if (ret_unpadded_row_size) {
562 *ret_unpadded_row_size = row_size;
565 return true;
568 size_t GLES2Util::RenderbufferBytesPerPixel(int format) {
569 switch (format) {
570 case GL_STENCIL_INDEX8:
571 return 1;
572 case GL_RGBA4:
573 case GL_RGB565:
574 case GL_RGB5_A1:
575 case GL_DEPTH_COMPONENT16:
576 return 2;
577 case GL_RGB:
578 case GL_RGBA:
579 case GL_DEPTH24_STENCIL8_OES:
580 case GL_RGB8_OES:
581 case GL_RGBA8_OES:
582 case GL_DEPTH_COMPONENT24_OES:
583 return 4;
584 default:
585 return 0;
589 uint32 GLES2Util::GetElementSizeForUniformType(int type) {
590 switch (type) {
591 case GL_FLOAT:
592 case GL_FLOAT_VEC2:
593 case GL_FLOAT_VEC3:
594 case GL_FLOAT_VEC4:
595 case GL_FLOAT_MAT2:
596 case GL_FLOAT_MAT3:
597 case GL_FLOAT_MAT4:
598 return sizeof(GLfloat);
599 case GL_INT:
600 case GL_INT_VEC2:
601 case GL_INT_VEC3:
602 case GL_INT_VEC4:
603 case GL_BOOL:
604 case GL_BOOL_VEC2:
605 case GL_BOOL_VEC3:
606 case GL_BOOL_VEC4:
607 case GL_SAMPLER_2D:
608 case GL_SAMPLER_CUBE:
609 case GL_SAMPLER_2D_RECT_ARB: // extension.
610 case GL_SAMPLER_EXTERNAL_OES: // extension.
611 return sizeof(GLint);
613 // ES3 types.
614 case GL_UNSIGNED_INT:
615 case GL_UNSIGNED_INT_VEC2:
616 case GL_UNSIGNED_INT_VEC3:
617 case GL_UNSIGNED_INT_VEC4:
618 return sizeof(GLuint);
619 case GL_SAMPLER_3D:
620 case GL_SAMPLER_2D_SHADOW:
621 case GL_SAMPLER_2D_ARRAY:
622 case GL_SAMPLER_2D_ARRAY_SHADOW:
623 case GL_SAMPLER_CUBE_SHADOW:
624 case GL_INT_SAMPLER_2D:
625 case GL_INT_SAMPLER_3D:
626 case GL_INT_SAMPLER_CUBE:
627 case GL_INT_SAMPLER_2D_ARRAY:
628 case GL_UNSIGNED_INT_SAMPLER_2D:
629 case GL_UNSIGNED_INT_SAMPLER_3D:
630 case GL_UNSIGNED_INT_SAMPLER_CUBE:
631 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
632 return sizeof(GLint);
633 case GL_FLOAT_MAT2x3:
634 case GL_FLOAT_MAT3x2:
635 case GL_FLOAT_MAT2x4:
636 case GL_FLOAT_MAT4x2:
637 case GL_FLOAT_MAT3x4:
638 case GL_FLOAT_MAT4x3:
639 return sizeof(GLfloat);
641 default:
642 return 0;
646 uint32 GLES2Util::GetElementCountForUniformType(int type) {
647 switch (type) {
648 case GL_FLOAT:
649 case GL_INT:
650 case GL_BOOL:
651 case GL_SAMPLER_2D:
652 case GL_SAMPLER_CUBE:
653 case GL_SAMPLER_2D_RECT_ARB: // extension.
654 case GL_SAMPLER_EXTERNAL_OES: // extension.
655 return 1;
656 case GL_FLOAT_VEC2:
657 case GL_INT_VEC2:
658 case GL_BOOL_VEC2:
659 return 2;
660 case GL_FLOAT_VEC3:
661 case GL_INT_VEC3:
662 case GL_BOOL_VEC3:
663 return 3;
664 case GL_FLOAT_VEC4:
665 case GL_INT_VEC4:
666 case GL_BOOL_VEC4:
667 case GL_FLOAT_MAT2:
668 return 4;
669 case GL_FLOAT_MAT3:
670 return 9;
671 case GL_FLOAT_MAT4:
672 return 16;
674 // ES3 types.
675 case GL_UNSIGNED_INT:
676 case GL_SAMPLER_3D:
677 case GL_SAMPLER_2D_SHADOW:
678 case GL_SAMPLER_2D_ARRAY:
679 case GL_SAMPLER_2D_ARRAY_SHADOW:
680 case GL_SAMPLER_CUBE_SHADOW:
681 case GL_INT_SAMPLER_2D:
682 case GL_INT_SAMPLER_3D:
683 case GL_INT_SAMPLER_CUBE:
684 case GL_INT_SAMPLER_2D_ARRAY:
685 case GL_UNSIGNED_INT_SAMPLER_2D:
686 case GL_UNSIGNED_INT_SAMPLER_3D:
687 case GL_UNSIGNED_INT_SAMPLER_CUBE:
688 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
689 return 1;
690 case GL_UNSIGNED_INT_VEC2:
691 return 2;
692 case GL_UNSIGNED_INT_VEC3:
693 return 3;
694 case GL_UNSIGNED_INT_VEC4:
695 return 4;
696 case GL_FLOAT_MAT2x3:
697 case GL_FLOAT_MAT3x2:
698 return 6;
699 case GL_FLOAT_MAT2x4:
700 case GL_FLOAT_MAT4x2:
701 return 8;
702 case GL_FLOAT_MAT3x4:
703 case GL_FLOAT_MAT4x3:
704 return 12;
706 default:
707 return 0;
711 size_t GLES2Util::GetGLTypeSizeForTexturesAndBuffers(uint32 type) {
712 switch (type) {
713 case GL_BYTE:
714 return sizeof(GLbyte); // NOLINT
715 case GL_UNSIGNED_BYTE:
716 return sizeof(GLubyte); // NOLINT
717 case GL_SHORT:
718 return sizeof(GLshort); // NOLINT
719 case GL_UNSIGNED_SHORT:
720 return sizeof(GLushort); // NOLINT
721 case GL_INT:
722 return sizeof(GLint); // NOLINT
723 case GL_UNSIGNED_INT:
724 return sizeof(GLuint); // NOLINT
725 case GL_FLOAT:
726 return sizeof(GLfloat); // NOLINT
727 case GL_FIXED:
728 return sizeof(GLfixed); // NOLINT
729 default:
730 return 0;
734 size_t GLES2Util::GetGLTypeSizeForPathCoordType(uint32 type) {
735 switch (type) {
736 case GL_BYTE:
737 return sizeof(GLbyte); // NOLINT
738 case GL_UNSIGNED_BYTE:
739 return sizeof(GLubyte); // NOLINT
740 case GL_SHORT:
741 return sizeof(GLshort); // NOLINT
742 case GL_UNSIGNED_SHORT:
743 return sizeof(GLushort); // NOLINT
744 case GL_FLOAT:
745 return sizeof(GLfloat); // NOLINT
746 default:
747 return 0;
751 uint32 GLES2Util::GLErrorToErrorBit(uint32 error) {
752 switch (error) {
753 case GL_INVALID_ENUM:
754 return gl_error_bit::kInvalidEnum;
755 case GL_INVALID_VALUE:
756 return gl_error_bit::kInvalidValue;
757 case GL_INVALID_OPERATION:
758 return gl_error_bit::kInvalidOperation;
759 case GL_OUT_OF_MEMORY:
760 return gl_error_bit::kOutOfMemory;
761 case GL_INVALID_FRAMEBUFFER_OPERATION:
762 return gl_error_bit::kInvalidFrameBufferOperation;
763 case GL_CONTEXT_LOST_KHR:
764 return gl_error_bit::kContextLost;
765 default:
766 NOTREACHED();
767 return gl_error_bit::kNoError;
771 uint32 GLES2Util::GLErrorBitToGLError(uint32 error_bit) {
772 switch (error_bit) {
773 case gl_error_bit::kInvalidEnum:
774 return GL_INVALID_ENUM;
775 case gl_error_bit::kInvalidValue:
776 return GL_INVALID_VALUE;
777 case gl_error_bit::kInvalidOperation:
778 return GL_INVALID_OPERATION;
779 case gl_error_bit::kOutOfMemory:
780 return GL_OUT_OF_MEMORY;
781 case gl_error_bit::kInvalidFrameBufferOperation:
782 return GL_INVALID_FRAMEBUFFER_OPERATION;
783 case gl_error_bit::kContextLost:
784 return GL_CONTEXT_LOST_KHR;
785 default:
786 NOTREACHED();
787 return GL_NO_ERROR;
791 uint32 GLES2Util::IndexToGLFaceTarget(int index) {
792 static uint32 faces[] = {
793 GL_TEXTURE_CUBE_MAP_POSITIVE_X,
794 GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
795 GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
796 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
797 GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
798 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
800 return faces[index];
803 size_t GLES2Util::GLTargetToFaceIndex(uint32 target) {
804 switch (target) {
805 case GL_TEXTURE_2D:
806 case GL_TEXTURE_EXTERNAL_OES:
807 case GL_TEXTURE_RECTANGLE_ARB:
808 case GL_TEXTURE_3D:
809 case GL_TEXTURE_2D_ARRAY:
810 return 0;
811 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
812 return 0;
813 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
814 return 1;
815 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
816 return 2;
817 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
818 return 3;
819 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
820 return 4;
821 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
822 return 5;
823 default:
824 NOTREACHED();
825 return 0;
829 uint32 GLES2Util::GetGLReadPixelsImplementationFormat(
830 uint32 internal_format) {
831 switch (internal_format) {
832 case GL_R8:
833 case GL_R16F:
834 case GL_R32F:
835 return GL_RED;
836 case GL_R8UI:
837 case GL_R8I:
838 case GL_R16UI:
839 case GL_R16I:
840 case GL_R32UI:
841 case GL_R32I:
842 return GL_RED_INTEGER;
843 case GL_RG8:
844 case GL_RG16F:
845 case GL_RG32F:
846 return GL_RG;
847 case GL_RG8UI:
848 case GL_RG8I:
849 case GL_RG16UI:
850 case GL_RG16I:
851 case GL_RG32UI:
852 case GL_RG32I:
853 return GL_RG_INTEGER;
854 case GL_RGB:
855 case GL_RGB8:
856 case GL_RGB565:
857 case GL_R11F_G11F_B10F:
858 case GL_RGB16F:
859 case GL_RGB32F:
860 return GL_RGB;
861 case GL_RGBA8UI:
862 case GL_RGBA8I:
863 case GL_RGB10_A2UI:
864 case GL_RGBA16UI:
865 case GL_RGBA16I:
866 case GL_RGBA32UI:
867 case GL_RGBA32I:
868 return GL_RGBA_INTEGER;
869 default:
870 return GL_RGBA;
874 uint32 GLES2Util::GetGLReadPixelsImplementationType(
875 uint32 internal_format, uint32 texture_type) {
876 switch (internal_format) {
877 case GL_R16UI:
878 case GL_RG16UI:
879 case GL_RGBA16UI:
880 case GL_RGB10_A2:
881 case GL_RGB10_A2UI:
882 return GL_UNSIGNED_SHORT;
883 case GL_R32UI:
884 case GL_RG32UI:
885 case GL_RGBA32UI:
886 return GL_UNSIGNED_INT;
887 case GL_R8I:
888 case GL_RG8I:
889 case GL_RGBA8I:
890 return GL_BYTE;
891 case GL_R16I:
892 case GL_RG16I:
893 case GL_RGBA16I:
894 return GL_SHORT;
895 case GL_R32I:
896 case GL_RG32I:
897 case GL_RGBA32I:
898 return GL_INT;
899 case GL_R32F:
900 case GL_RG32F:
901 case GL_RGB32F:
902 case GL_RGBA32F:
903 return GL_FLOAT;
904 case GL_R16F:
905 case GL_RG16F:
906 case GL_R11F_G11F_B10F:
907 case GL_RGB16F:
908 case GL_RGBA16F:
909 // TODO(zmo): Consider return GL_UNSIGNED_INT_10F_11F_11F_REV and
910 // GL_HALF_FLOAT.
911 return GL_FLOAT;
912 case GL_RGBA:
913 case GL_RGB:
914 // Unsized internal format, check the type
915 switch (texture_type) {
916 case GL_FLOAT:
917 case GL_HALF_FLOAT_OES:
918 return GL_FLOAT;
919 // TODO(zmo): Consider return GL_UNSIGNED_SHORT_5_6_5,
920 // GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_5_5_5_1, and
921 // GL_UNSIGNED_INT_2_10_10_10_REV.
922 default:
923 return GL_UNSIGNED_BYTE;
925 default:
926 return GL_UNSIGNED_BYTE;
930 uint32 GLES2Util::GetChannelsForFormat(int format) {
931 switch (format) {
932 case GL_ALPHA:
933 case GL_ALPHA16F_EXT:
934 case GL_ALPHA32F_EXT:
935 return kAlpha;
936 case GL_LUMINANCE:
937 return kRGB;
938 case GL_LUMINANCE_ALPHA:
939 return kRGBA;
940 case GL_RGB:
941 case GL_RGB8_OES:
942 case GL_RGB565:
943 case GL_RGB16F_EXT:
944 case GL_RGB32F_EXT:
945 case GL_SRGB_EXT:
946 case GL_SRGB8:
947 case GL_RGB8_SNORM:
948 case GL_R11F_G11F_B10F:
949 case GL_RGB9_E5:
950 case GL_RGB8UI:
951 case GL_RGB8I:
952 case GL_RGB16UI:
953 case GL_RGB16I:
954 case GL_RGB32UI:
955 case GL_RGB32I:
956 return kRGB;
957 case GL_BGRA_EXT:
958 case GL_BGRA8_EXT:
959 case GL_RGBA16F_EXT:
960 case GL_RGBA32F_EXT:
961 case GL_RGBA:
962 case GL_RGBA8_OES:
963 case GL_RGBA4:
964 case GL_RGB5_A1:
965 case GL_SRGB_ALPHA_EXT:
966 case GL_SRGB8_ALPHA8_EXT:
967 case GL_RGBA8_SNORM:
968 case GL_RGB10_A2:
969 case GL_RGBA8UI:
970 case GL_RGBA8I:
971 case GL_RGB10_A2UI:
972 case GL_RGBA16UI:
973 case GL_RGBA16I:
974 case GL_RGBA32UI:
975 case GL_RGBA32I:
976 return kRGBA;
977 case GL_DEPTH_COMPONENT32_OES:
978 case GL_DEPTH_COMPONENT24_OES:
979 case GL_DEPTH_COMPONENT16:
980 case GL_DEPTH_COMPONENT:
981 case GL_DEPTH_COMPONENT32F:
982 return kDepth;
983 case GL_STENCIL_INDEX8:
984 return kStencil;
985 case GL_DEPTH_STENCIL_OES:
986 case GL_DEPTH24_STENCIL8_OES:
987 case GL_DEPTH32F_STENCIL8:
988 return kDepth | kStencil;
989 case GL_RED_EXT:
990 case GL_R8:
991 case GL_R8_SNORM:
992 case GL_R16F:
993 case GL_R32F:
994 case GL_R8UI:
995 case GL_R8I:
996 case GL_R16UI:
997 case GL_R16I:
998 case GL_R32UI:
999 case GL_R32I:
1000 return kRed;
1001 case GL_RG_EXT:
1002 case GL_RG8:
1003 case GL_RG8_SNORM:
1004 case GL_RG16F:
1005 case GL_RG32F:
1006 case GL_RG8UI:
1007 case GL_RG8I:
1008 case GL_RG16UI:
1009 case GL_RG16I:
1010 case GL_RG32UI:
1011 case GL_RG32I:
1012 return kRed | kGreen;
1013 default:
1014 return 0x0000;
1018 uint32 GLES2Util::GetChannelsNeededForAttachmentType(
1019 int type, uint32 max_color_attachments) {
1020 switch (type) {
1021 case GL_DEPTH_ATTACHMENT:
1022 return kDepth;
1023 case GL_STENCIL_ATTACHMENT:
1024 return kStencil;
1025 default:
1026 if (type >= GL_COLOR_ATTACHMENT0 &&
1027 type < static_cast<int>(
1028 GL_COLOR_ATTACHMENT0 + max_color_attachments)) {
1029 return kRGBA;
1031 return 0x0000;
1035 std::string GLES2Util::GetStringEnum(uint32 value) {
1036 const EnumToString* entry = enum_to_string_table_;
1037 const EnumToString* end = entry + enum_to_string_table_len_;
1038 for (;entry < end; ++entry) {
1039 if (value == entry->value) {
1040 return entry->name;
1043 std::stringstream ss;
1044 ss.fill('0');
1045 ss.width(value < 0x10000 ? 4 : 8);
1046 ss << std::hex << value;
1047 return "0x" + ss.str();
1050 std::string GLES2Util::GetStringError(uint32 value) {
1051 static EnumToString string_table[] = {
1052 { GL_NONE, "GL_NONE" },
1054 return GLES2Util::GetQualifiedEnumString(
1055 string_table, arraysize(string_table), value);
1058 std::string GLES2Util::GetStringBool(uint32 value) {
1059 return value ? "GL_TRUE" : "GL_FALSE";
1062 std::string GLES2Util::GetQualifiedEnumString(
1063 const EnumToString* table, size_t count, uint32 value) {
1064 for (const EnumToString* end = table + count; table < end; ++table) {
1065 if (table->value == value) {
1066 return table->name;
1069 return GetStringEnum(value);
1072 bool GLES2Util::ParseUniformName(
1073 const std::string& name,
1074 size_t* array_pos,
1075 int* element_index,
1076 bool* getting_array) {
1077 if (name.empty())
1078 return false;
1079 bool getting_array_location = false;
1080 size_t open_pos = std::string::npos;
1081 base::CheckedNumeric<int> index = 0;
1082 if (name[name.size() - 1] == ']') {
1083 if (name.size() < 3) {
1084 return false;
1086 open_pos = name.find_last_of('[');
1087 if (open_pos == std::string::npos ||
1088 open_pos >= name.size() - 2) {
1089 return false;
1091 size_t last = name.size() - 1;
1092 for (size_t pos = open_pos + 1; pos < last; ++pos) {
1093 int8 digit = name[pos] - '0';
1094 if (digit < 0 || digit > 9) {
1095 return false;
1097 index = index * 10 + digit;
1099 if (!index.IsValid()) {
1100 return false;
1102 getting_array_location = true;
1104 *getting_array = getting_array_location;
1105 *element_index = index.ValueOrDie();
1106 *array_pos = open_pos;
1107 return true;
1110 size_t GLES2Util::CalcClearBufferivDataCount(int buffer) {
1111 switch (buffer) {
1112 case GL_COLOR:
1113 return 4;
1114 case GL_STENCIL:
1115 return 1;
1116 default:
1117 return 0;
1121 size_t GLES2Util::CalcClearBufferfvDataCount(int buffer) {
1122 switch (buffer) {
1123 case GL_COLOR:
1124 return 4;
1125 case GL_DEPTH:
1126 return 1;
1127 default:
1128 return 0;
1132 // static
1133 void GLES2Util::MapUint64ToTwoUint32(
1134 uint64_t v64, uint32_t* v32_0, uint32_t* v32_1) {
1135 DCHECK(v32_0 && v32_1);
1136 *v32_0 = static_cast<uint32_t>(v64 & 0xFFFFFFFF);
1137 *v32_1 = static_cast<uint32_t>((v64 & 0xFFFFFFFF00000000) >> 32);
1140 // static
1141 uint64_t GLES2Util::MapTwoUint32ToUint64(uint32_t v32_0, uint32_t v32_1) {
1142 uint64_t v64 = v32_1;
1143 return (v64 << 32) | v32_0;
1146 // static
1147 uint32_t GLES2Util::MapBufferTargetToBindingEnum(uint32_t target) {
1148 switch (target) {
1149 case GL_ARRAY_BUFFER:
1150 return GL_ARRAY_BUFFER_BINDING;
1151 case GL_COPY_READ_BUFFER:
1152 return GL_COPY_READ_BUFFER_BINDING;
1153 case GL_COPY_WRITE_BUFFER:
1154 return GL_COPY_WRITE_BUFFER_BINDING;
1155 case GL_ELEMENT_ARRAY_BUFFER:
1156 return GL_ELEMENT_ARRAY_BUFFER_BINDING;
1157 case GL_PIXEL_PACK_BUFFER:
1158 return GL_PIXEL_PACK_BUFFER_BINDING;
1159 case GL_PIXEL_UNPACK_BUFFER:
1160 return GL_PIXEL_UNPACK_BUFFER_BINDING;
1161 case GL_TRANSFORM_FEEDBACK_BUFFER:
1162 return GL_TRANSFORM_FEEDBACK_BUFFER_BINDING;
1163 case GL_UNIFORM_BUFFER:
1164 return GL_UNIFORM_BUFFER_BINDING;
1165 default:
1166 return 0;
1170 // static
1171 bool GLES2Util::IsUnsignedIntegerFormat(uint32_t internal_format) {
1172 switch (internal_format) {
1173 case GL_R8UI:
1174 case GL_R16UI:
1175 case GL_R32UI:
1176 case GL_RG8UI:
1177 case GL_RG16UI:
1178 case GL_RG32UI:
1179 case GL_RGBA8UI:
1180 case GL_RGB10_A2UI:
1181 case GL_RGBA16UI:
1182 case GL_RGBA32UI:
1183 return true;
1184 default:
1185 return false;
1189 // static
1190 bool GLES2Util::IsSignedIntegerFormat(uint32_t internal_format) {
1191 switch (internal_format) {
1192 case GL_R8I:
1193 case GL_R16I:
1194 case GL_R32I:
1195 case GL_RG8I:
1196 case GL_RG16I:
1197 case GL_RG32I:
1198 case GL_RGBA8I:
1199 case GL_RGBA16I:
1200 case GL_RGBA32I:
1201 return true;
1202 default:
1203 return false;
1207 // static
1208 bool GLES2Util::IsIntegerFormat(uint32_t internal_format) {
1209 return (IsUnsignedIntegerFormat(internal_format) ||
1210 IsSignedIntegerFormat(internal_format));
1214 namespace {
1216 // WebGraphicsContext3DCommandBufferImpl configuration attributes. Those in
1217 // the 16-bit range are the same as used by EGL. Those outside the 16-bit range
1218 // are unique to Chromium. Attributes are matched using a closest fit algorithm.
1220 // From <EGL/egl.h>.
1221 const int32 kAlphaSize = 0x3021; // EGL_ALPHA_SIZE
1222 const int32 kBlueSize = 0x3022; // EGL_BLUE_SIZE
1223 const int32 kGreenSize = 0x3023; // EGL_GREEN_SIZE
1224 const int32 kRedSize = 0x3024; // EGL_RED_SIZE
1225 const int32 kDepthSize = 0x3025; // EGL_DEPTH_SIZE
1226 const int32 kStencilSize = 0x3026; // EGL_STENCIL_SIZE
1227 const int32 kSamples = 0x3031; // EGL_SAMPLES
1228 const int32 kSampleBuffers = 0x3032; // EGL_SAMPLE_BUFFERS
1229 const int32 kNone = 0x3038; // EGL_NONE
1230 const int32 kSwapBehavior = 0x3093; // EGL_SWAP_BEHAVIOR
1231 const int32 kBufferPreserved = 0x3094; // EGL_BUFFER_PRESERVED
1232 const int32 kBufferDestroyed = 0x3095; // EGL_BUFFER_DESTROYED
1234 // Chromium only.
1235 const int32 kBindGeneratesResource = 0x10000;
1236 const int32 kFailIfMajorPerfCaveat = 0x10001;
1237 const int32 kLoseContextWhenOutOfMemory = 0x10002;
1238 const int32 kWebGLVersion = 0x10003;
1240 } // namespace
1242 ContextCreationAttribHelper::ContextCreationAttribHelper()
1243 : alpha_size(-1),
1244 blue_size(-1),
1245 green_size(-1),
1246 red_size(-1),
1247 depth_size(-1),
1248 stencil_size(-1),
1249 samples(-1),
1250 sample_buffers(-1),
1251 buffer_preserved(true),
1252 bind_generates_resource(true),
1253 fail_if_major_perf_caveat(false),
1254 lose_context_when_out_of_memory(false),
1255 webgl_version(0) {
1258 void ContextCreationAttribHelper::Serialize(std::vector<int32>* attribs) const {
1259 if (alpha_size != -1) {
1260 attribs->push_back(kAlphaSize);
1261 attribs->push_back(alpha_size);
1263 if (blue_size != -1) {
1264 attribs->push_back(kBlueSize);
1265 attribs->push_back(blue_size);
1267 if (green_size != -1) {
1268 attribs->push_back(kGreenSize);
1269 attribs->push_back(green_size);
1271 if (red_size != -1) {
1272 attribs->push_back(kRedSize);
1273 attribs->push_back(red_size);
1275 if (depth_size != -1) {
1276 attribs->push_back(kDepthSize);
1277 attribs->push_back(depth_size);
1279 if (stencil_size != -1) {
1280 attribs->push_back(kStencilSize);
1281 attribs->push_back(stencil_size);
1283 if (samples != -1) {
1284 attribs->push_back(kSamples);
1285 attribs->push_back(samples);
1287 if (sample_buffers != -1) {
1288 attribs->push_back(kSampleBuffers);
1289 attribs->push_back(sample_buffers);
1291 attribs->push_back(kSwapBehavior);
1292 attribs->push_back(buffer_preserved ? kBufferPreserved : kBufferDestroyed);
1293 attribs->push_back(kBindGeneratesResource);
1294 attribs->push_back(bind_generates_resource ? 1 : 0);
1295 attribs->push_back(kFailIfMajorPerfCaveat);
1296 attribs->push_back(fail_if_major_perf_caveat ? 1 : 0);
1297 attribs->push_back(kLoseContextWhenOutOfMemory);
1298 attribs->push_back(lose_context_when_out_of_memory ? 1 : 0);
1299 attribs->push_back(kWebGLVersion);
1300 attribs->push_back(webgl_version);
1301 attribs->push_back(kNone);
1304 bool ContextCreationAttribHelper::Parse(const std::vector<int32>& attribs) {
1305 for (size_t i = 0; i < attribs.size(); i += 2) {
1306 const int32 attrib = attribs[i];
1307 if (i + 1 >= attribs.size()) {
1308 if (attrib == kNone) {
1309 return true;
1312 DLOG(ERROR) << "Missing value after context creation attribute: "
1313 << attrib;
1314 return false;
1317 const int32 value = attribs[i+1];
1318 switch (attrib) {
1319 case kAlphaSize:
1320 alpha_size = value;
1321 break;
1322 case kBlueSize:
1323 blue_size = value;
1324 break;
1325 case kGreenSize:
1326 green_size = value;
1327 break;
1328 case kRedSize:
1329 red_size = value;
1330 break;
1331 case kDepthSize:
1332 depth_size = value;
1333 break;
1334 case kStencilSize:
1335 stencil_size = value;
1336 break;
1337 case kSamples:
1338 samples = value;
1339 break;
1340 case kSampleBuffers:
1341 sample_buffers = value;
1342 break;
1343 case kSwapBehavior:
1344 buffer_preserved = value == kBufferPreserved;
1345 break;
1346 case kBindGeneratesResource:
1347 bind_generates_resource = value != 0;
1348 break;
1349 case kFailIfMajorPerfCaveat:
1350 fail_if_major_perf_caveat = value != 0;
1351 break;
1352 case kLoseContextWhenOutOfMemory:
1353 lose_context_when_out_of_memory = value != 0;
1354 break;
1355 case kWebGLVersion:
1356 webgl_version = value;
1357 break;
1358 case kNone:
1359 // Terminate list, even if more attributes.
1360 return true;
1361 default:
1362 DLOG(ERROR) << "Invalid context creation attribute: " << attrib;
1363 return false;
1367 return true;
1370 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"
1372 } // namespace gles2
1373 } // namespace gpu