4106617915d89d963ead5ca2067c2d16df0ed027
[WebKit-https.git] / Source / WebCore / platform / graphics / GraphicsContext3D.h
1 /*
2  * Copyright (C) 2009, 2014 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef GraphicsContext3D_h
27 #define GraphicsContext3D_h
28
29 #include "ANGLEWebKitBridge.h"
30 #include "GraphicsTypes3D.h"
31 #include "Image.h"
32 #include "IntRect.h"
33 #include "PlatformLayer.h"
34 #include <memory>
35 #include <wtf/HashMap.h>
36 #include <wtf/ListHashSet.h>
37 #include <wtf/Noncopyable.h>
38 #include <wtf/RefCounted.h>
39 #include <wtf/text/WTFString.h>
40
41 #if USE(CA)
42 #include "PlatformCALayer.h"
43 #endif
44
45 // FIXME: Find a better way to avoid the name confliction for NO_ERROR.
46 #if PLATFORM(WIN)
47 #undef NO_ERROR
48 #elif PLATFORM(GTK)
49 // This define is from the X11 headers, but it's used below, so we must undefine it.
50 #undef VERSION
51 #endif
52
53 #if PLATFORM(COCOA)
54 #if PLATFORM(IOS)
55 #include <OpenGLES/ES2/gl.h>
56 #ifdef __OBJC__
57 #import <OpenGLES/EAGL.h>
58 #endif // __OBJC__
59 #endif // PLATFORM(IOS)
60 #include <wtf/RetainPtr.h>
61 OBJC_CLASS CALayer;
62 OBJC_CLASS WebGLLayer;
63 #elif PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN_CAIRO)
64 typedef unsigned int GLuint;
65 #endif
66
67 #if PLATFORM(IOS)
68 #ifdef __OBJC__
69 typedef EAGLContext* PlatformGraphicsContext3D;
70 #else
71 typedef void* PlatformGraphicsContext3D;
72 #endif // __OBJC__
73 #elif PLATFORM(MAC)
74 typedef struct _CGLContextObject *CGLContextObj;
75
76 typedef CGLContextObj PlatformGraphicsContext3D;
77 #else
78 typedef void* PlatformGraphicsContext3D;
79 typedef void* PlatformGraphicsSurface3D;
80 #endif
81
82 // These are currently the same among all implementations.
83 const PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
84 const Platform3DObject NullPlatform3DObject = 0;
85
86 namespace WebCore {
87 class Extensions3D;
88 #if USE(OPENGL_ES_2)
89 class Extensions3DOpenGLES;
90 #else
91 class Extensions3DOpenGL;
92 #endif
93 class HostWindow;
94 class Image;
95 class ImageBuffer;
96 class ImageSource;
97 class ImageData;
98 class IntRect;
99 class IntSize;
100 class WebGLRenderingContextBase;
101 #if USE(CAIRO)
102 class PlatformContextCairo;
103 #endif
104
105 typedef WTF::HashMap<CString, uint64_t> ShaderNameHash;
106
107 struct ActiveInfo {
108     String name;
109     GC3Denum type;
110     GC3Dint size;
111 };
112
113 class GraphicsContext3DPrivate;
114
115 class GraphicsContext3D : public RefCounted<GraphicsContext3D> {
116 public:
117     enum {
118         // WebGL 1 constants
119         DEPTH_BUFFER_BIT = 0x00000100,
120         STENCIL_BUFFER_BIT = 0x00000400,
121         COLOR_BUFFER_BIT = 0x00004000,
122         POINTS = 0x0000,
123         LINES = 0x0001,
124         LINE_LOOP = 0x0002,
125         LINE_STRIP = 0x0003,
126         TRIANGLES = 0x0004,
127         TRIANGLE_STRIP = 0x0005,
128         TRIANGLE_FAN = 0x0006,
129         ZERO = 0,
130         ONE = 1,
131         SRC_COLOR = 0x0300,
132         ONE_MINUS_SRC_COLOR = 0x0301,
133         SRC_ALPHA = 0x0302,
134         ONE_MINUS_SRC_ALPHA = 0x0303,
135         DST_ALPHA = 0x0304,
136         ONE_MINUS_DST_ALPHA = 0x0305,
137         DST_COLOR = 0x0306,
138         ONE_MINUS_DST_COLOR = 0x0307,
139         SRC_ALPHA_SATURATE = 0x0308,
140         FUNC_ADD = 0x8006,
141         BLEND_EQUATION = 0x8009,
142         BLEND_EQUATION_RGB = 0x8009,
143         BLEND_EQUATION_ALPHA = 0x883D,
144         FUNC_SUBTRACT = 0x800A,
145         FUNC_REVERSE_SUBTRACT = 0x800B,
146         BLEND_DST_RGB = 0x80C8,
147         BLEND_SRC_RGB = 0x80C9,
148         BLEND_DST_ALPHA = 0x80CA,
149         BLEND_SRC_ALPHA = 0x80CB,
150         CONSTANT_COLOR = 0x8001,
151         ONE_MINUS_CONSTANT_COLOR = 0x8002,
152         CONSTANT_ALPHA = 0x8003,
153         ONE_MINUS_CONSTANT_ALPHA = 0x8004,
154         BLEND_COLOR = 0x8005,
155         ARRAY_BUFFER = 0x8892,
156         ELEMENT_ARRAY_BUFFER = 0x8893,
157         ARRAY_BUFFER_BINDING = 0x8894,
158         ELEMENT_ARRAY_BUFFER_BINDING = 0x8895,
159         STREAM_DRAW = 0x88E0,
160         STATIC_DRAW = 0x88E4,
161         DYNAMIC_DRAW = 0x88E8,
162         BUFFER_SIZE = 0x8764,
163         BUFFER_USAGE = 0x8765,
164         CURRENT_VERTEX_ATTRIB = 0x8626,
165         FRONT = 0x0404,
166         BACK = 0x0405,
167         FRONT_AND_BACK = 0x0408,
168         TEXTURE_2D = 0x0DE1,
169         CULL_FACE = 0x0B44,
170         BLEND = 0x0BE2,
171         DITHER = 0x0BD0,
172         STENCIL_TEST = 0x0B90,
173         DEPTH_TEST = 0x0B71,
174         SCISSOR_TEST = 0x0C11,
175         POLYGON_OFFSET_FILL = 0x8037,
176         SAMPLE_ALPHA_TO_COVERAGE = 0x809E,
177         SAMPLE_COVERAGE = 0x80A0,
178         NO_ERROR = 0,
179         INVALID_ENUM = 0x0500,
180         INVALID_VALUE = 0x0501,
181         INVALID_OPERATION = 0x0502,
182         OUT_OF_MEMORY = 0x0505,
183         CW = 0x0900,
184         CCW = 0x0901,
185         LINE_WIDTH = 0x0B21,
186         ALIASED_POINT_SIZE_RANGE = 0x846D,
187         ALIASED_LINE_WIDTH_RANGE = 0x846E,
188         CULL_FACE_MODE = 0x0B45,
189         FRONT_FACE = 0x0B46,
190         DEPTH_RANGE = 0x0B70,
191         DEPTH_WRITEMASK = 0x0B72,
192         DEPTH_CLEAR_VALUE = 0x0B73,
193         DEPTH_FUNC = 0x0B74,
194         STENCIL_CLEAR_VALUE = 0x0B91,
195         STENCIL_FUNC = 0x0B92,
196         STENCIL_FAIL = 0x0B94,
197         STENCIL_PASS_DEPTH_FAIL = 0x0B95,
198         STENCIL_PASS_DEPTH_PASS = 0x0B96,
199         STENCIL_REF = 0x0B97,
200         STENCIL_VALUE_MASK = 0x0B93,
201         STENCIL_WRITEMASK = 0x0B98,
202         STENCIL_BACK_FUNC = 0x8800,
203         STENCIL_BACK_FAIL = 0x8801,
204         STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802,
205         STENCIL_BACK_PASS_DEPTH_PASS = 0x8803,
206         STENCIL_BACK_REF = 0x8CA3,
207         STENCIL_BACK_VALUE_MASK = 0x8CA4,
208         STENCIL_BACK_WRITEMASK = 0x8CA5,
209         VIEWPORT = 0x0BA2,
210         SCISSOR_BOX = 0x0C10,
211         COLOR_CLEAR_VALUE = 0x0C22,
212         COLOR_WRITEMASK = 0x0C23,
213         UNPACK_ALIGNMENT = 0x0CF5,
214         PACK_ALIGNMENT = 0x0D05,
215         MAX_TEXTURE_SIZE = 0x0D33,
216         MAX_VIEWPORT_DIMS = 0x0D3A,
217         SUBPIXEL_BITS = 0x0D50,
218         RED_BITS = 0x0D52,
219         GREEN_BITS = 0x0D53,
220         BLUE_BITS = 0x0D54,
221         ALPHA_BITS = 0x0D55,
222         DEPTH_BITS = 0x0D56,
223         STENCIL_BITS = 0x0D57,
224         POLYGON_OFFSET_UNITS = 0x2A00,
225         POLYGON_OFFSET_FACTOR = 0x8038,
226         TEXTURE_BINDING_2D = 0x8069,
227         SAMPLE_BUFFERS = 0x80A8,
228         SAMPLES = 0x80A9,
229         SAMPLE_COVERAGE_VALUE = 0x80AA,
230         SAMPLE_COVERAGE_INVERT = 0x80AB,
231         NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2,
232         COMPRESSED_TEXTURE_FORMATS = 0x86A3,
233         DONT_CARE = 0x1100,
234         FASTEST = 0x1101,
235         NICEST = 0x1102,
236         GENERATE_MIPMAP_HINT = 0x8192,
237         BYTE = 0x1400,
238         UNSIGNED_BYTE = 0x1401,
239         SHORT = 0x1402,
240         UNSIGNED_SHORT = 0x1403,
241         INT = 0x1404,
242         UNSIGNED_INT = 0x1405,
243         FLOAT = 0x1406,
244         HALF_FLOAT_OES = 0x8D61,
245         FIXED = 0x140C,
246         DEPTH_COMPONENT = 0x1902,
247         ALPHA = 0x1906,
248         RGB = 0x1907,
249         RGBA = 0x1908,
250         BGRA = 0x80E1,
251         LUMINANCE = 0x1909,
252         LUMINANCE_ALPHA = 0x190A,
253         UNSIGNED_SHORT_4_4_4_4 = 0x8033,
254         UNSIGNED_SHORT_5_5_5_1 = 0x8034,
255         UNSIGNED_SHORT_5_6_5 = 0x8363,
256         FRAGMENT_SHADER = 0x8B30,
257         VERTEX_SHADER = 0x8B31,
258         MAX_VERTEX_ATTRIBS = 0x8869,
259         MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB,
260         MAX_VARYING_VECTORS = 0x8DFC,
261         MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D,
262         MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C,
263         MAX_TEXTURE_IMAGE_UNITS = 0x8872,
264         MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD,
265         SHADER_TYPE = 0x8B4F,
266         DELETE_STATUS = 0x8B80,
267         LINK_STATUS = 0x8B82,
268         VALIDATE_STATUS = 0x8B83,
269         ATTACHED_SHADERS = 0x8B85,
270         ACTIVE_UNIFORMS = 0x8B86,
271         ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
272         ACTIVE_ATTRIBUTES = 0x8B89,
273         ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
274         SHADING_LANGUAGE_VERSION = 0x8B8C,
275         CURRENT_PROGRAM = 0x8B8D,
276         NEVER = 0x0200,
277         LESS = 0x0201,
278         EQUAL = 0x0202,
279         LEQUAL = 0x0203,
280         GREATER = 0x0204,
281         NOTEQUAL = 0x0205,
282         GEQUAL = 0x0206,
283         ALWAYS = 0x0207,
284         KEEP = 0x1E00,
285         REPLACE = 0x1E01,
286         INCR = 0x1E02,
287         DECR = 0x1E03,
288         INVERT = 0x150A,
289         INCR_WRAP = 0x8507,
290         DECR_WRAP = 0x8508,
291         VENDOR = 0x1F00,
292         RENDERER = 0x1F01,
293         VERSION = 0x1F02,
294         EXTENSIONS = 0x1F03,
295         NEAREST = 0x2600,
296         LINEAR = 0x2601,
297         NEAREST_MIPMAP_NEAREST = 0x2700,
298         LINEAR_MIPMAP_NEAREST = 0x2701,
299         NEAREST_MIPMAP_LINEAR = 0x2702,
300         LINEAR_MIPMAP_LINEAR = 0x2703,
301         TEXTURE_MAG_FILTER = 0x2800,
302         TEXTURE_MIN_FILTER = 0x2801,
303         TEXTURE_WRAP_S = 0x2802,
304         TEXTURE_WRAP_T = 0x2803,
305         TEXTURE = 0x1702,
306         TEXTURE_CUBE_MAP = 0x8513,
307         TEXTURE_BINDING_CUBE_MAP = 0x8514,
308         TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515,
309         TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516,
310         TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517,
311         TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518,
312         TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519,
313         TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A,
314         MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C,
315         TEXTURE0 = 0x84C0,
316         TEXTURE1 = 0x84C1,
317         TEXTURE2 = 0x84C2,
318         TEXTURE3 = 0x84C3,
319         TEXTURE4 = 0x84C4,
320         TEXTURE5 = 0x84C5,
321         TEXTURE6 = 0x84C6,
322         TEXTURE7 = 0x84C7,
323         TEXTURE8 = 0x84C8,
324         TEXTURE9 = 0x84C9,
325         TEXTURE10 = 0x84CA,
326         TEXTURE11 = 0x84CB,
327         TEXTURE12 = 0x84CC,
328         TEXTURE13 = 0x84CD,
329         TEXTURE14 = 0x84CE,
330         TEXTURE15 = 0x84CF,
331         TEXTURE16 = 0x84D0,
332         TEXTURE17 = 0x84D1,
333         TEXTURE18 = 0x84D2,
334         TEXTURE19 = 0x84D3,
335         TEXTURE20 = 0x84D4,
336         TEXTURE21 = 0x84D5,
337         TEXTURE22 = 0x84D6,
338         TEXTURE23 = 0x84D7,
339         TEXTURE24 = 0x84D8,
340         TEXTURE25 = 0x84D9,
341         TEXTURE26 = 0x84DA,
342         TEXTURE27 = 0x84DB,
343         TEXTURE28 = 0x84DC,
344         TEXTURE29 = 0x84DD,
345         TEXTURE30 = 0x84DE,
346         TEXTURE31 = 0x84DF,
347         ACTIVE_TEXTURE = 0x84E0,
348         REPEAT = 0x2901,
349         CLAMP_TO_EDGE = 0x812F,
350         MIRRORED_REPEAT = 0x8370,
351         FLOAT_VEC2 = 0x8B50,
352         FLOAT_VEC3 = 0x8B51,
353         FLOAT_VEC4 = 0x8B52,
354         INT_VEC2 = 0x8B53,
355         INT_VEC3 = 0x8B54,
356         INT_VEC4 = 0x8B55,
357         BOOL = 0x8B56,
358         BOOL_VEC2 = 0x8B57,
359         BOOL_VEC3 = 0x8B58,
360         BOOL_VEC4 = 0x8B59,
361         FLOAT_MAT2 = 0x8B5A,
362         FLOAT_MAT3 = 0x8B5B,
363         FLOAT_MAT4 = 0x8B5C,
364         SAMPLER_2D = 0x8B5E,
365         SAMPLER_CUBE = 0x8B60,
366         VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622,
367         VERTEX_ATTRIB_ARRAY_SIZE = 0x8623,
368         VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624,
369         VERTEX_ATTRIB_ARRAY_TYPE = 0x8625,
370         VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A,
371         VERTEX_ATTRIB_ARRAY_POINTER = 0x8645,
372         VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F,
373         IMPLEMENTATION_COLOR_READ_TYPE = 0x8B9A,
374         IMPLEMENTATION_COLOR_READ_FORMAT = 0x8B9B,
375         COMPILE_STATUS = 0x8B81,
376         INFO_LOG_LENGTH = 0x8B84,
377         SHADER_SOURCE_LENGTH = 0x8B88,
378         SHADER_COMPILER = 0x8DFA,
379         SHADER_BINARY_FORMATS = 0x8DF8,
380         NUM_SHADER_BINARY_FORMATS = 0x8DF9,
381         LOW_FLOAT = 0x8DF0,
382         MEDIUM_FLOAT = 0x8DF1,
383         HIGH_FLOAT = 0x8DF2,
384         LOW_INT = 0x8DF3,
385         MEDIUM_INT = 0x8DF4,
386         HIGH_INT = 0x8DF5,
387         FRAMEBUFFER = 0x8D40,
388         RENDERBUFFER = 0x8D41,
389         RGBA4 = 0x8056,
390         RGB5_A1 = 0x8057,
391         RGB565 = 0x8D62,
392         DEPTH_COMPONENT16 = 0x81A5,
393         STENCIL_INDEX = 0x1901,
394         STENCIL_INDEX8 = 0x8D48,
395         RENDERBUFFER_WIDTH = 0x8D42,
396         RENDERBUFFER_HEIGHT = 0x8D43,
397         RENDERBUFFER_INTERNAL_FORMAT = 0x8D44,
398         RENDERBUFFER_RED_SIZE = 0x8D50,
399         RENDERBUFFER_GREEN_SIZE = 0x8D51,
400         RENDERBUFFER_BLUE_SIZE = 0x8D52,
401         RENDERBUFFER_ALPHA_SIZE = 0x8D53,
402         RENDERBUFFER_DEPTH_SIZE = 0x8D54,
403         RENDERBUFFER_STENCIL_SIZE = 0x8D55,
404         FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0,
405         FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1,
406         FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2,
407         FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3,
408         COLOR_ATTACHMENT0 = 0x8CE0,
409         DEPTH_ATTACHMENT = 0x8D00,
410         STENCIL_ATTACHMENT = 0x8D20,
411         NONE = 0,
412         FRAMEBUFFER_COMPLETE = 0x8CD5,
413         FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6,
414         FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7,
415         FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9,
416         FRAMEBUFFER_UNSUPPORTED = 0x8CDD,
417         FRAMEBUFFER_BINDING = 0x8CA6,
418         RENDERBUFFER_BINDING = 0x8CA7,
419         MAX_RENDERBUFFER_SIZE = 0x84E8,
420         INVALID_FRAMEBUFFER_OPERATION = 0x0506,
421
422         // WebGL-specific enums
423         UNPACK_FLIP_Y_WEBGL = 0x9240,
424         UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241,
425         CONTEXT_LOST_WEBGL = 0x9242,
426         UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
427         BROWSER_DEFAULT_WEBGL = 0x9244,
428         VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE = 0x88FE,
429         
430         // WebGL2 constants
431         READ_BUFFER = 0x0C02,
432         UNPACK_ROW_LENGTH = 0x0CF2,
433         UNPACK_SKIP_ROWS = 0x0CF3,
434         UNPACK_SKIP_PIXELS = 0x0CF4,
435         PACK_ROW_LENGTH = 0x0D02,
436         PACK_SKIP_ROWS = 0x0D03,
437         PACK_SKIP_PIXELS = 0x0D04,
438         COLOR = 0x1800,
439         DEPTH = 0x1801,
440         STENCIL = 0x1802,
441         RED = 0x1903,
442         RGB8 = 0x8051,
443         RGBA8 = 0x8058,
444         RGB10_A2 = 0x8059,
445         TEXTURE_BINDING_3D = 0x806A,
446         UNPACK_SKIP_IMAGES = 0x806D,
447         UNPACK_IMAGE_HEIGHT = 0x806E,
448         TEXTURE_3D = 0x806F,
449         TEXTURE_WRAP_R = 0x8072,
450         MAX_3D_TEXTURE_SIZE = 0x8073,
451         UNSIGNED_INT_2_10_10_10_REV = 0x8368,
452         MAX_ELEMENTS_VERTICES = 0x80E8,
453         MAX_ELEMENTS_INDICES = 0x80E9,
454         TEXTURE_MIN_LOD = 0x813A,
455         TEXTURE_MAX_LOD = 0x813B,
456         TEXTURE_BASE_LEVEL = 0x813C,
457         TEXTURE_MAX_LEVEL = 0x813D,
458         MIN = 0x8007,
459         MAX = 0x8008,
460         DEPTH_COMPONENT24 = 0x81A6,
461         MAX_TEXTURE_LOD_BIAS = 0x84FD,
462         TEXTURE_COMPARE_MODE = 0x884C,
463         TEXTURE_COMPARE_FUNC = 0x884D,
464         CURRENT_QUERY = 0x8865,
465         QUERY_RESULT = 0x8866,
466         QUERY_RESULT_AVAILABLE = 0x8867,
467         STREAM_READ = 0x88E1,
468         STREAM_COPY = 0x88E2,
469         STATIC_READ = 0x88E5,
470         STATIC_COPY = 0x88E6,
471         DYNAMIC_READ = 0x88E9,
472         DYNAMIC_COPY = 0x88EA,
473         MAX_DRAW_BUFFERS = 0x8824,
474         DRAW_BUFFER0 = 0x8825,
475         DRAW_BUFFER1 = 0x8826,
476         DRAW_BUFFER2 = 0x8827,
477         DRAW_BUFFER3 = 0x8828,
478         DRAW_BUFFER4 = 0x8829,
479         DRAW_BUFFER5 = 0x882A,
480         DRAW_BUFFER6 = 0x882B,
481         DRAW_BUFFER7 = 0x882C,
482         DRAW_BUFFER8 = 0x882D,
483         DRAW_BUFFER9 = 0x882E,
484         DRAW_BUFFER10 = 0x882F,
485         DRAW_BUFFER11 = 0x8830,
486         DRAW_BUFFER12 = 0x8831,
487         DRAW_BUFFER13 = 0x8832,
488         DRAW_BUFFER14 = 0x8833,
489         DRAW_BUFFER15 = 0x8834,
490         MAX_FRAGMENT_UNIFORM_COMPONENTS = 0x8B49,
491         MAX_VERTEX_UNIFORM_COMPONENTS = 0x8B4A,
492         SAMPLER_3D = 0x8B5F,
493         SAMPLER_2D_SHADOW = 0x8B62,
494         FRAGMENT_SHADER_DERIVATIVE_HINT = 0x8B8B,
495         PIXEL_PACK_BUFFER = 0x88EB,
496         PIXEL_UNPACK_BUFFER = 0x88EC,
497         PIXEL_PACK_BUFFER_BINDING = 0x88ED,
498         PIXEL_UNPACK_BUFFER_BINDING = 0x88EF,
499         FLOAT_MAT2x3 = 0x8B65,
500         FLOAT_MAT2x4 = 0x8B66,
501         FLOAT_MAT3x2 = 0x8B67,
502         FLOAT_MAT3x4 = 0x8B68,
503         FLOAT_MAT4x2 = 0x8B69,
504         FLOAT_MAT4x3 = 0x8B6A,
505         SRGB = 0x8C40,
506         SRGB8 = 0x8C41,
507         SRGB_ALPHA = 0x8C42,
508         SRGB8_ALPHA8 = 0x8C43,
509         COMPARE_REF_TO_TEXTURE = 0x884E,
510         RGBA32F = 0x8814,
511         RGB32F = 0x8815,
512         RGBA16F = 0x881A,
513         RGB16F = 0x881B,
514         VERTEX_ATTRIB_ARRAY_INTEGER = 0x88FD,
515         MAX_ARRAY_TEXTURE_LAYERS = 0x88FF,
516         MIN_PROGRAM_TEXEL_OFFSET = 0x8904,
517         MAX_PROGRAM_TEXEL_OFFSET = 0x8905,
518         MAX_VARYING_COMPONENTS = 0x8B4B,
519         TEXTURE_2D_ARRAY = 0x8C1A,
520         TEXTURE_BINDING_2D_ARRAY = 0x8C1D,
521         R11F_G11F_B10F = 0x8C3A,
522         UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B,
523         RGB9_E5 = 0x8C3D,
524         UNSIGNED_INT_5_9_9_9_REV = 0x8C3E,
525         TRANSFORM_FEEDBACK_BUFFER_MODE = 0x8C7F,
526         MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS = 0x8C80,
527         TRANSFORM_FEEDBACK_VARYINGS = 0x8C83,
528         TRANSFORM_FEEDBACK_BUFFER_START = 0x8C84,
529         TRANSFORM_FEEDBACK_BUFFER_SIZE = 0x8C85,
530         TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN = 0x8C88,
531         RASTERIZER_DISCARD = 0x8C89,
532         MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS = 0x8C8A,
533         MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 0x8C8B,
534         INTERLEAVED_ATTRIBS = 0x8C8C,
535         SEPARATE_ATTRIBS = 0x8C8D,
536         TRANSFORM_FEEDBACK_BUFFER = 0x8C8E,
537         TRANSFORM_FEEDBACK_BUFFER_BINDING = 0x8C8F,
538         RGBA32UI = 0x8D70,
539         RGB32UI = 0x8D71,
540         RGBA16UI = 0x8D76,
541         RGB16UI = 0x8D77,
542         RGBA8UI = 0x8D7C,
543         RGB8UI = 0x8D7D,
544         RGBA32I = 0x8D82,
545         RGB32I = 0x8D83,
546         RGBA16I = 0x8D88,
547         RGB16I = 0x8D89,
548         RGBA8I = 0x8D8E,
549         RGB8I = 0x8D8F,
550         RED_INTEGER = 0x8D94,
551         RGB_INTEGER = 0x8D98,
552         RGBA_INTEGER = 0x8D99,
553         SAMPLER_2D_ARRAY = 0x8DC1,
554         SAMPLER_2D_ARRAY_SHADOW = 0x8DC4,
555         SAMPLER_CUBE_SHADOW = 0x8DC5,
556         UNSIGNED_INT_VEC2 = 0x8DC6,
557         UNSIGNED_INT_VEC3 = 0x8DC7,
558         UNSIGNED_INT_VEC4 = 0x8DC8,
559         INT_SAMPLER_2D = 0x8DCA,
560         INT_SAMPLER_3D = 0x8DCB,
561         INT_SAMPLER_CUBE = 0x8DCC,
562         INT_SAMPLER_2D_ARRAY = 0x8DCF,
563         UNSIGNED_INT_SAMPLER_2D = 0x8DD2,
564         UNSIGNED_INT_SAMPLER_3D = 0x8DD3,
565         UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4,
566         UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7,
567         DEPTH_COMPONENT32F = 0x8CAC,
568         DEPTH32F_STENCIL8 = 0x8CAD,
569         FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD,
570         FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING = 0x8210,
571         FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE = 0x8211,
572         FRAMEBUFFER_ATTACHMENT_RED_SIZE = 0x8212,
573         FRAMEBUFFER_ATTACHMENT_GREEN_SIZE = 0x8213,
574         FRAMEBUFFER_ATTACHMENT_BLUE_SIZE = 0x8214,
575         FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE = 0x8215,
576         FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE = 0x8216,
577         FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE = 0x8217,
578         FRAMEBUFFER_DEFAULT = 0x8218,
579         DEPTH_STENCIL_ATTACHMENT = 0x821A,
580         DEPTH_STENCIL = 0x84F9,
581         UNSIGNED_INT_24_8 = 0x84FA,
582         DEPTH24_STENCIL8 = 0x88F0,
583         UNSIGNED_NORMALIZED = 0x8C17,
584         DRAW_FRAMEBUFFER_BINDING = 0x8CA6, /* Same as FRAMEBUFFER_BINDING */
585         READ_FRAMEBUFFER = 0x8CA8,
586         DRAW_FRAMEBUFFER = 0x8CA9,
587         READ_FRAMEBUFFER_BINDING = 0x8CAA,
588         RENDERBUFFER_SAMPLES = 0x8CAB,
589         FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER = 0x8CD4,
590         MAX_COLOR_ATTACHMENTS = 0x8CDF,
591         COLOR_ATTACHMENT1 = 0x8CE1,
592         COLOR_ATTACHMENT2 = 0x8CE2,
593         COLOR_ATTACHMENT3 = 0x8CE3,
594         COLOR_ATTACHMENT4 = 0x8CE4,
595         COLOR_ATTACHMENT5 = 0x8CE5,
596         COLOR_ATTACHMENT6 = 0x8CE6,
597         COLOR_ATTACHMENT7 = 0x8CE7,
598         COLOR_ATTACHMENT8 = 0x8CE8,
599         COLOR_ATTACHMENT9 = 0x8CE9,
600         COLOR_ATTACHMENT10 = 0x8CEA,
601         COLOR_ATTACHMENT11 = 0x8CEB,
602         COLOR_ATTACHMENT12 = 0x8CEC,
603         COLOR_ATTACHMENT13 = 0x8CED,
604         COLOR_ATTACHMENT14 = 0x8CEE,
605         COLOR_ATTACHMENT15 = 0x8CEF,
606         FRAMEBUFFER_INCOMPLETE_MULTISAMPLE = 0x8D56,
607         MAX_SAMPLES = 0x8D57,
608         HALF_FLOAT = 0x140B,
609         RG = 0x8227,
610         RG_INTEGER = 0x8228,
611         R8 = 0x8229,
612         RG8 = 0x822B,
613         R16F = 0x822D,
614         R32F = 0x822E,
615         RG16F = 0x822F,
616         RG32F = 0x8230,
617         R8I = 0x8231,
618         R8UI = 0x8232,
619         R16I = 0x8233,
620         R16UI = 0x8234,
621         R32I = 0x8235,
622         R32UI = 0x8236,
623         RG8I = 0x8237,
624         RG8UI = 0x8238,
625         RG16I = 0x8239,
626         RG16UI = 0x823A,
627         RG32I = 0x823B,
628         RG32UI = 0x823C,
629         VERTEX_ARRAY_BINDING = 0x85B5,
630         R8_SNORM = 0x8F94,
631         RG8_SNORM = 0x8F95,
632         RGB8_SNORM = 0x8F96,
633         RGBA8_SNORM = 0x8F97,
634         SIGNED_NORMALIZED = 0x8F9C,
635         COPY_READ_BUFFER = 0x8F36,
636         COPY_WRITE_BUFFER = 0x8F37,
637         COPY_READ_BUFFER_BINDING = 0x8F36, /* Same as COPY_READ_BUFFER */
638         COPY_WRITE_BUFFER_BINDING = 0x8F37, /* Same as COPY_WRITE_BUFFER */
639         UNIFORM_BUFFER = 0x8A11,
640         UNIFORM_BUFFER_BINDING = 0x8A28,
641         UNIFORM_BUFFER_START = 0x8A29,
642         UNIFORM_BUFFER_SIZE = 0x8A2A,
643         MAX_VERTEX_UNIFORM_BLOCKS = 0x8A2B,
644         MAX_FRAGMENT_UNIFORM_BLOCKS = 0x8A2D,
645         MAX_COMBINED_UNIFORM_BLOCKS = 0x8A2E,
646         MAX_UNIFORM_BUFFER_BINDINGS = 0x8A2F,
647         MAX_UNIFORM_BLOCK_SIZE = 0x8A30,
648         MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = 0x8A31,
649         MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = 0x8A33,
650         UNIFORM_BUFFER_OFFSET_ALIGNMENT = 0x8A34,
651         ACTIVE_UNIFORM_BLOCKS = 0x8A36,
652         UNIFORM_TYPE = 0x8A37,
653         UNIFORM_SIZE = 0x8A38,
654         UNIFORM_BLOCK_INDEX = 0x8A3A,
655         UNIFORM_OFFSET = 0x8A3B,
656         UNIFORM_ARRAY_STRIDE = 0x8A3C,
657         UNIFORM_MATRIX_STRIDE = 0x8A3D,
658         UNIFORM_IS_ROW_MAJOR = 0x8A3E,
659         UNIFORM_BLOCK_BINDING = 0x8A3F,
660         UNIFORM_BLOCK_DATA_SIZE = 0x8A40,
661         UNIFORM_BLOCK_ACTIVE_UNIFORMS = 0x8A42,
662         UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8A43,
663         UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER = 0x8A44,
664         UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8A46,
665         INVALID_INDEX = 0xFFFFFFFF,
666         MAX_VERTEX_OUTPUT_COMPONENTS = 0x9122,
667         MAX_FRAGMENT_INPUT_COMPONENTS = 0x9125,
668         MAX_SERVER_WAIT_TIMEOUT = 0x9111,
669         OBJECT_TYPE = 0x9112,
670         SYNC_CONDITION = 0x9113,
671         SYNC_STATUS = 0x9114,
672         SYNC_FLAGS = 0x9115,
673         SYNC_FENCE = 0x9116,
674         SYNC_GPU_COMMANDS_COMPLETE = 0x9117,
675         UNSIGNALED = 0x9118,
676         SIGNALED = 0x9119,
677         ALREADY_SIGNALED = 0x911A,
678         TIMEOUT_EXPIRED = 0x911B,
679         CONDITION_SATISFIED = 0x911C,
680 #if PLATFORM(WIN)
681         WAIT_FAILED_WIN = 0x911D,
682 #else
683         WAIT_FAILED = 0x911D,
684 #endif
685         SYNC_FLUSH_COMMANDS_BIT = 0x00000001,
686         VERTEX_ATTRIB_ARRAY_DIVISOR = 0x88FE,
687         ANY_SAMPLES_PASSED = 0x8C2F,
688         ANY_SAMPLES_PASSED_CONSERVATIVE = 0x8D6A,
689         SAMPLER_BINDING = 0x8919,
690         RGB10_A2UI = 0x906F,
691         TEXTURE_SWIZZLE_R = 0x8E42,
692         TEXTURE_SWIZZLE_G = 0x8E43,
693         TEXTURE_SWIZZLE_B = 0x8E44,
694         TEXTURE_SWIZZLE_A = 0x8E45,
695         GREEN = 0x1904,
696         BLUE = 0x1905,
697         INT_2_10_10_10_REV = 0x8D9F,
698         TRANSFORM_FEEDBACK = 0x8E22,
699         TRANSFORM_FEEDBACK_PAUSED = 0x8E23,
700         TRANSFORM_FEEDBACK_ACTIVE = 0x8E24,
701         TRANSFORM_FEEDBACK_BINDING = 0x8E25,
702         COMPRESSED_R11_EAC = 0x9270,
703         COMPRESSED_SIGNED_R11_EAC = 0x9271,
704         COMPRESSED_RG11_EAC = 0x9272,
705         COMPRESSED_SIGNED_RG11_EAC = 0x9273,
706         COMPRESSED_RGB8_ETC2 = 0x9274,
707         COMPRESSED_SRGB8_ETC2 = 0x9275,
708         COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276,
709         COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277,
710         COMPRESSED_RGBA8_ETC2_EAC = 0x9278,
711         COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279,
712         TEXTURE_IMMUTABLE_FORMAT = 0x912F,
713         MAX_ELEMENT_INDEX = 0x8D6B,
714         NUM_SAMPLE_COUNTS = 0x9380,
715         TEXTURE_IMMUTABLE_LEVELS = 0x82DF, 
716
717         // OpenGL ES 3 constants
718         MAP_READ_BIT = 0x0001
719     };
720
721     // Context creation attributes.
722     struct Attributes {
723         bool alpha { true };
724         bool depth { true };
725         bool stencil { false };
726         bool antialias { true };
727         bool premultipliedAlpha { true };
728         bool preserveDrawingBuffer { false };
729         bool noExtensions { false };
730         bool shareResources { true };
731         bool preferLowPowerToHighPerformance { false };
732         bool forceSoftwareRenderer { false };
733         bool failIfMajorPerformanceCaveat { false };
734         bool useGLES3 { false };
735         float devicePixelRatio { 1 };
736     };
737
738     enum RenderStyle {
739         RenderOffscreen,
740         RenderDirectlyToHostWindow,
741         RenderToCurrentGLContext
742     };
743
744     class ContextLostCallback {
745     public:
746         virtual void onContextLost() = 0;
747         virtual ~ContextLostCallback() {}
748     };
749
750     class ErrorMessageCallback {
751     public:
752         virtual void onErrorMessage(const String& message, GC3Dint id) = 0;
753         virtual ~ErrorMessageCallback() { }
754     };
755
756     void setContextLostCallback(std::unique_ptr<ContextLostCallback>);
757     void setErrorMessageCallback(std::unique_ptr<ErrorMessageCallback>);
758
759     static RefPtr<GraphicsContext3D> create(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
760     static PassRefPtr<GraphicsContext3D> createForCurrentGLContext();
761     ~GraphicsContext3D();
762
763 #if PLATFORM(COCOA)
764     PlatformGraphicsContext3D platformGraphicsContext3D() const { return m_contextObj; }
765     Platform3DObject platformTexture() const { return m_compositorTexture; }
766     CALayer* platformLayer() const { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); }
767 #else
768     PlatformGraphicsContext3D platformGraphicsContext3D();
769     Platform3DObject platformTexture() const;
770     PlatformLayer* platformLayer() const;
771 #endif
772
773     bool makeContextCurrent();
774     void setWebGLContext(WebGLRenderingContextBase* base) { m_webglContext = base; }
775
776     // With multisampling on, blit from multisampleFBO to regular FBO.
777     void prepareTexture();
778
779     // Equivalent to ::glTexImage2D(). Allows pixels==0 with no allocation.
780     void texImage2DDirect(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels);
781
782     // Helper to texImage2D with pixel==0 case: pixels are initialized to 0.
783     // Return true if no GL error is synthesized.
784     // By default, alignment is 4, the OpenGL default setting.
785     bool texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint alignment = 4);
786
787     bool isGLES2Compliant() const;
788
789     //----------------------------------------------------------------------
790     // Helpers for texture uploading and pixel readback.
791     //
792
793     // Computes the components per pixel and bytes per component
794     // for the given format and type combination. Returns false if
795     // either was an invalid enum.
796     static bool computeFormatAndTypeParameters(GC3Denum format,
797                                                GC3Denum type,
798                                                unsigned int* componentsPerPixel,
799                                                unsigned int* bytesPerComponent);
800
801     // Computes the image size in bytes. If paddingInBytes is not null, padding
802     // is also calculated in return. Returns NO_ERROR if succeed, otherwise
803     // return the suggested GL error indicating the cause of the failure:
804     //   INVALID_VALUE if width/height is negative or overflow happens.
805     //   INVALID_ENUM if format/type is illegal.
806     static GC3Denum computeImageSizeInBytes(GC3Denum format,
807                                      GC3Denum type,
808                                      GC3Dsizei width,
809                                      GC3Dsizei height,
810                                      GC3Dint alignment,
811                                      unsigned int* imageSizeInBytes,
812                                      unsigned int* paddingInBytes);
813
814     static bool possibleFormatAndTypeForInternalFormat(GC3Denum internalFormat, GC3Denum& format, GC3Denum& type);
815
816     // Extracts the contents of the given ImageData into the passed Vector,
817     // packing the pixel data according to the given format and type,
818     // and obeying the flipY and premultiplyAlpha flags. Returns true
819     // upon success.
820     static bool extractImageData(ImageData*,
821                           GC3Denum format,
822                           GC3Denum type,
823                           bool flipY,
824                           bool premultiplyAlpha,
825                           Vector<uint8_t>& data);
826
827     // Helper function which extracts the user-supplied texture
828     // data, applying the flipY and premultiplyAlpha parameters.
829     // If the data is not tightly packed according to the passed
830     // unpackAlignment, the output data will be tightly packed.
831     // Returns true if successful, false if any error occurred.
832     static bool extractTextureData(unsigned int width, unsigned int height,
833                             GC3Denum format, GC3Denum type,
834                             unsigned int unpackAlignment,
835                             bool flipY, bool premultiplyAlpha,
836                             const void* pixels,
837                             Vector<uint8_t>& data);
838
839
840     // Attempt to enumerate all possible native image formats to
841     // reduce the amount of temporary allocations during texture
842     // uploading. This enum must be public because it is accessed
843     // by non-member functions.
844     enum DataFormat {
845         DataFormatRGBA8 = 0,
846         DataFormatRGBA16Little,
847         DataFormatRGBA16Big,
848         DataFormatRGBA16F,
849         DataFormatRGBA32F,
850         DataFormatRGB8,
851         DataFormatRGB16Little,
852         DataFormatRGB16Big,
853         DataFormatRGB16F,
854         DataFormatRGB32F,
855         DataFormatBGR8,
856         DataFormatBGRA8,
857         DataFormatBGRA16Little,
858         DataFormatBGRA16Big,
859         DataFormatARGB8,
860         DataFormatARGB16Little,
861         DataFormatARGB16Big,
862         DataFormatABGR8,
863         DataFormatRGBA5551,
864         DataFormatRGBA4444,
865         DataFormatRGB565,
866         DataFormatR8,
867         DataFormatR16Little,
868         DataFormatR16Big,
869         DataFormatR16F,
870         DataFormatR32F,
871         DataFormatRA8,
872         DataFormatRA16Little,
873         DataFormatRA16Big,
874         DataFormatRA16F,
875         DataFormatRA32F,
876         DataFormatAR8,
877         DataFormatAR16Little,
878         DataFormatAR16Big,
879         DataFormatA8,
880         DataFormatA16Little,
881         DataFormatA16Big,
882         DataFormatA16F,
883         DataFormatA32F,
884         DataFormatNumFormats
885     };
886
887     ALWAYS_INLINE static bool hasAlpha(DataFormat format)
888     {
889         switch (format) {
890         case GraphicsContext3D::DataFormatA8:
891         case GraphicsContext3D::DataFormatA16F:
892         case GraphicsContext3D::DataFormatA32F:
893         case GraphicsContext3D::DataFormatRA8:
894         case GraphicsContext3D::DataFormatAR8:
895         case GraphicsContext3D::DataFormatRA16F:
896         case GraphicsContext3D::DataFormatRA32F:
897         case GraphicsContext3D::DataFormatRGBA8:
898         case GraphicsContext3D::DataFormatBGRA8:
899         case GraphicsContext3D::DataFormatARGB8:
900         case GraphicsContext3D::DataFormatABGR8:
901         case GraphicsContext3D::DataFormatRGBA16F:
902         case GraphicsContext3D::DataFormatRGBA32F:
903         case GraphicsContext3D::DataFormatRGBA4444:
904         case GraphicsContext3D::DataFormatRGBA5551:
905             return true;
906         default:
907             return false;
908         }
909     }
910
911     ALWAYS_INLINE static bool hasColor(DataFormat format)
912     {
913         switch (format) {
914         case GraphicsContext3D::DataFormatRGBA8:
915         case GraphicsContext3D::DataFormatRGBA16F:
916         case GraphicsContext3D::DataFormatRGBA32F:
917         case GraphicsContext3D::DataFormatRGB8:
918         case GraphicsContext3D::DataFormatRGB16F:
919         case GraphicsContext3D::DataFormatRGB32F:
920         case GraphicsContext3D::DataFormatBGR8:
921         case GraphicsContext3D::DataFormatBGRA8:
922         case GraphicsContext3D::DataFormatARGB8:
923         case GraphicsContext3D::DataFormatABGR8:
924         case GraphicsContext3D::DataFormatRGBA5551:
925         case GraphicsContext3D::DataFormatRGBA4444:
926         case GraphicsContext3D::DataFormatRGB565:
927         case GraphicsContext3D::DataFormatR8:
928         case GraphicsContext3D::DataFormatR16F:
929         case GraphicsContext3D::DataFormatR32F:
930         case GraphicsContext3D::DataFormatRA8:
931         case GraphicsContext3D::DataFormatRA16F:
932         case GraphicsContext3D::DataFormatRA32F:
933         case GraphicsContext3D::DataFormatAR8:
934             return true;
935         default:
936             return false;
937         }
938     }
939
940     // Check if the format is one of the formats from the ImageData or DOM elements.
941     // The formats from ImageData is always RGBA8.
942     // The formats from DOM elements vary with Graphics ports. It can only be RGBA8 or BGRA8 for non-CG port while a little more for CG port.
943     static ALWAYS_INLINE bool srcFormatComesFromDOMElementOrImageData(DataFormat SrcFormat)
944     {
945 #if USE(CG)
946 #if CPU(BIG_ENDIAN)
947     return SrcFormat == DataFormatRGBA8 || SrcFormat == DataFormatARGB8 || SrcFormat == DataFormatRGB8
948         || SrcFormat == DataFormatRA8 || SrcFormat == DataFormatAR8 || SrcFormat == DataFormatR8 || SrcFormat == DataFormatA8;
949 #else
950     // That LITTLE_ENDIAN case has more possible formats than BIG_ENDIAN case is because some decoded image data is actually big endian
951     // even on little endian architectures.
952     return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatABGR8 || SrcFormat == DataFormatBGR8
953         || SrcFormat == DataFormatRGBA8 || SrcFormat == DataFormatARGB8 || SrcFormat == DataFormatRGB8
954         || SrcFormat == DataFormatR8 || SrcFormat == DataFormatA8
955         || SrcFormat == DataFormatRA8 || SrcFormat == DataFormatAR8;
956 #endif
957 #else
958     return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatRGBA8;
959 #endif
960     }
961
962     //----------------------------------------------------------------------
963     // Entry points for WebGL.
964     //
965
966     void activeTexture(GC3Denum texture);
967     void attachShader(Platform3DObject program, Platform3DObject shader);
968     void bindAttribLocation(Platform3DObject, GC3Duint index, const String& name);
969     void bindBuffer(GC3Denum target, Platform3DObject);
970     void bindFramebuffer(GC3Denum target, Platform3DObject);
971     void bindRenderbuffer(GC3Denum target, Platform3DObject);
972     void bindTexture(GC3Denum target, Platform3DObject);
973     void blendColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
974     void blendEquation(GC3Denum mode);
975     void blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha);
976     void blendFunc(GC3Denum sfactor, GC3Denum dfactor);
977     void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha);
978
979     void bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage);
980     void bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage);
981     void bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data);
982
983     void* mapBufferRange(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr length, GC3Dbitfield access);
984     GC3Dboolean unmapBuffer(GC3Denum target);
985     void copyBufferSubData(GC3Denum readTarget, GC3Denum writeTarget, GC3Dintptr readOffset, GC3Dintptr writeOffset, GC3Dsizeiptr);
986
987     GC3Denum checkFramebufferStatus(GC3Denum target);
988     void clear(GC3Dbitfield mask);
989     void clearColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
990     void clearDepth(GC3Dclampf depth);
991     void clearStencil(GC3Dint s);
992     void colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dboolean blue, GC3Dboolean alpha);
993     void compileShader(Platform3DObject);
994
995     void compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Dsizei imageSize, const void* data);
996     void compressedTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Dsizei imageSize, const void* data);
997     void copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border);
998     void copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
999     void cullFace(GC3Denum mode);
1000     void depthFunc(GC3Denum func);
1001     void depthMask(GC3Dboolean flag);
1002     void depthRange(GC3Dclampf zNear, GC3Dclampf zFar);
1003     void detachShader(Platform3DObject, Platform3DObject);
1004     void disable(GC3Denum cap);
1005     void disableVertexAttribArray(GC3Duint index);
1006     void drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count);
1007     void drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset);
1008
1009     void enable(GC3Denum cap);
1010     void enableVertexAttribArray(GC3Duint index);
1011     void finish();
1012     void flush();
1013     void framebufferRenderbuffer(GC3Denum target, GC3Denum attachment, GC3Denum renderbuffertarget, Platform3DObject);
1014     void framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum textarget, Platform3DObject, GC3Dint level);
1015     void frontFace(GC3Denum mode);
1016     void generateMipmap(GC3Denum target);
1017
1018     bool getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo&);
1019     bool getActiveAttribImpl(Platform3DObject program, GC3Duint index, ActiveInfo&);
1020     bool getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo&);
1021     bool getActiveUniformImpl(Platform3DObject program, GC3Duint index, ActiveInfo&);
1022     void getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders);
1023     GC3Dint getAttribLocation(Platform3DObject, const String& name);
1024     void getBooleanv(GC3Denum pname, GC3Dboolean* value);
1025     void getBufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
1026     Attributes getContextAttributes();
1027     GC3Denum getError();
1028     void getFloatv(GC3Denum pname, GC3Dfloat* value);
1029     void getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum pname, GC3Dint* value);
1030     void getIntegerv(GC3Denum pname, GC3Dint* value);
1031     void getInteger64v(GC3Denum pname, GC3Dint64* value);
1032     void getProgramiv(Platform3DObject program, GC3Denum pname, GC3Dint* value);
1033     void getNonBuiltInActiveSymbolCount(Platform3DObject program, GC3Denum pname, GC3Dint* value);
1034     String getProgramInfoLog(Platform3DObject);
1035     String getUnmangledInfoLog(Platform3DObject[2], GC3Dsizei, const String&);
1036     void getRenderbufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
1037     void getShaderiv(Platform3DObject, GC3Denum pname, GC3Dint* value);
1038     String getShaderInfoLog(Platform3DObject);
1039     void getShaderPrecisionFormat(GC3Denum shaderType, GC3Denum precisionType, GC3Dint* range, GC3Dint* precision);
1040     String getShaderSource(Platform3DObject);
1041     String getString(GC3Denum name);
1042     void getTexParameterfv(GC3Denum target, GC3Denum pname, GC3Dfloat* value);
1043     void getTexParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
1044     void getUniformfv(Platform3DObject program, GC3Dint location, GC3Dfloat* value);
1045     void getUniformiv(Platform3DObject program, GC3Dint location, GC3Dint* value);
1046     GC3Dint getUniformLocation(Platform3DObject, const String& name);
1047     void getVertexAttribfv(GC3Duint index, GC3Denum pname, GC3Dfloat* value);
1048     void getVertexAttribiv(GC3Duint index, GC3Denum pname, GC3Dint* value);
1049     GC3Dsizeiptr getVertexAttribOffset(GC3Duint index, GC3Denum pname);
1050
1051     void hint(GC3Denum target, GC3Denum mode);
1052     GC3Dboolean isBuffer(Platform3DObject);
1053     GC3Dboolean isEnabled(GC3Denum cap);
1054     GC3Dboolean isFramebuffer(Platform3DObject);
1055     GC3Dboolean isProgram(Platform3DObject);
1056     GC3Dboolean isRenderbuffer(Platform3DObject);
1057     GC3Dboolean isShader(Platform3DObject);
1058     GC3Dboolean isTexture(Platform3DObject);
1059     void lineWidth(GC3Dfloat);
1060     void linkProgram(Platform3DObject);
1061     void pixelStorei(GC3Denum pname, GC3Dint param);
1062     void polygonOffset(GC3Dfloat factor, GC3Dfloat units);
1063
1064     void readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data);
1065
1066     void releaseShaderCompiler();
1067
1068     void renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height);
1069     void sampleCoverage(GC3Dclampf value, GC3Dboolean invert);
1070     void scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
1071     void shaderSource(Platform3DObject, const String& string);
1072     void stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask);
1073     void stencilFuncSeparate(GC3Denum face, GC3Denum func, GC3Dint ref, GC3Duint mask);
1074     void stencilMask(GC3Duint mask);
1075     void stencilMaskSeparate(GC3Denum face, GC3Duint mask);
1076     void stencilOp(GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
1077     void stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
1078
1079     bool texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels);
1080     void texParameterf(GC3Denum target, GC3Denum pname, GC3Dfloat param);
1081     void texParameteri(GC3Denum target, GC3Denum pname, GC3Dint param);
1082     void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels);
1083
1084     void uniform1f(GC3Dint location, GC3Dfloat x);
1085     void uniform1fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
1086     void uniform1i(GC3Dint location, GC3Dint x);
1087     void uniform1iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
1088     void uniform2f(GC3Dint location, GC3Dfloat x, GC3Dfloat y);
1089     void uniform2fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
1090     void uniform2i(GC3Dint location, GC3Dint x, GC3Dint y);
1091     void uniform2iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
1092     void uniform3f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
1093     void uniform3fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
1094     void uniform3i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z);
1095     void uniform3iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
1096     void uniform4f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
1097     void uniform4fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
1098     void uniform4i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w);
1099     void uniform4iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
1100     void uniformMatrix2fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
1101     void uniformMatrix3fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
1102     void uniformMatrix4fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
1103
1104     void useProgram(Platform3DObject);
1105     void validateProgram(Platform3DObject);
1106     bool checkVaryingsPacking(Platform3DObject vertexShader, Platform3DObject fragmentShader) const;
1107     bool precisionsMatch(Platform3DObject vertexShader, Platform3DObject fragmentShader) const;
1108
1109     void vertexAttrib1f(GC3Duint index, GC3Dfloat x);
1110     void vertexAttrib1fv(GC3Duint index, GC3Dfloat* values);
1111     void vertexAttrib2f(GC3Duint index, GC3Dfloat x, GC3Dfloat y);
1112     void vertexAttrib2fv(GC3Duint index, GC3Dfloat* values);
1113     void vertexAttrib3f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
1114     void vertexAttrib3fv(GC3Duint index, GC3Dfloat* values);
1115     void vertexAttrib4f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
1116     void vertexAttrib4fv(GC3Duint index, GC3Dfloat* values);
1117     void vertexAttribPointer(GC3Duint index, GC3Dint size, GC3Denum type, GC3Dboolean normalized,
1118                              GC3Dsizei stride, GC3Dintptr offset);
1119
1120     void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
1121
1122     void reshape(int width, int height);
1123
1124     void drawArraysInstanced(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount);
1125     void drawElementsInstanced(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount);
1126     void vertexAttribDivisor(GC3Duint index, GC3Duint divisor);
1127
1128     // VertexArrayOject calls
1129     Platform3DObject createVertexArray();
1130     void deleteVertexArray(Platform3DObject);
1131     GC3Dboolean isVertexArray(Platform3DObject);
1132     void bindVertexArray(Platform3DObject);
1133
1134 #if PLATFORM(GTK) || PLATFORM(EFL) || USE(CAIRO)
1135     void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
1136                        int canvasWidth, int canvasHeight, PlatformContextCairo* context);
1137 #elif USE(CG)
1138     void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, GraphicsContext&);
1139 #endif
1140
1141     void markContextChanged();
1142     void markLayerComposited();
1143     bool layerComposited() const;
1144     void forceContextLost();
1145     void recycleContext();
1146
1147     void paintRenderingResultsToCanvas(ImageBuffer*);
1148     PassRefPtr<ImageData> paintRenderingResultsToImageData();
1149     bool paintCompositedResultsToCanvas(ImageBuffer*);
1150
1151 #if PLATFORM(IOS)
1152     void endPaint();
1153 #endif
1154
1155     // Support for buffer creation and deletion
1156     Platform3DObject createBuffer();
1157     Platform3DObject createFramebuffer();
1158     Platform3DObject createProgram();
1159     Platform3DObject createRenderbuffer();
1160     Platform3DObject createShader(GC3Denum);
1161     Platform3DObject createTexture();
1162
1163     void deleteBuffer(Platform3DObject);
1164     void deleteFramebuffer(Platform3DObject);
1165     void deleteProgram(Platform3DObject);
1166     void deleteRenderbuffer(Platform3DObject);
1167     void deleteShader(Platform3DObject);
1168     void deleteTexture(Platform3DObject);
1169
1170     // Synthesizes an OpenGL error which will be returned from a
1171     // later call to getError. This is used to emulate OpenGL ES
1172     // 2.0 behavior on the desktop and to enforce additional error
1173     // checking mandated by WebGL.
1174     //
1175     // Per the behavior of glGetError, this stores at most one
1176     // instance of any given error, and returns them from calls to
1177     // getError in the order they were added.
1178     void synthesizeGLError(GC3Denum error);
1179
1180     // Read real OpenGL errors, and move them to the synthetic
1181     // error list. Return true if at least one error is moved.
1182     bool moveErrorsToSyntheticErrorList();
1183
1184     // Support for extensions. Returns a non-null object, though not
1185     // all methods it contains may necessarily be supported on the
1186     // current hardware. Must call Extensions3D::supports() to
1187     // determine this.
1188     Extensions3D* getExtensions();
1189
1190     IntSize getInternalFramebufferSize() const;
1191
1192     static unsigned getClearBitsByAttachmentType(GC3Denum);
1193     static unsigned getClearBitsByFormat(GC3Denum);
1194
1195     enum ChannelBits {
1196         ChannelRed = 1,
1197         ChannelGreen = 2,
1198         ChannelBlue = 4,
1199         ChannelAlpha = 8,
1200         ChannelDepth = 16,
1201         ChannelStencil = 32,
1202         ChannelRGB = ChannelRed | ChannelGreen | ChannelBlue,
1203         ChannelRGBA = ChannelRGB | ChannelAlpha,
1204     };
1205
1206     static unsigned getChannelBitsByFormat(GC3Denum);
1207
1208     // Possible alpha operations that may need to occur during
1209     // pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must
1210     // be removed.
1211     enum AlphaOp {
1212         AlphaDoNothing = 0,
1213         AlphaDoPremultiply = 1,
1214         AlphaDoUnmultiply = 2
1215     };
1216
1217     enum ImageHtmlDomSource {
1218         HtmlDomImage = 0,
1219         HtmlDomCanvas = 1,
1220         HtmlDomVideo = 2,
1221         HtmlDomNone = 3
1222     };
1223
1224     // Packs the contents of the given Image which is passed in |pixels| into the passed Vector
1225     // according to the given format and type, and obeying the flipY and AlphaOp flags.
1226     // Returns true upon success.
1227     static bool packImageData(Image*, const void* pixels, GC3Denum format, GC3Denum type, bool flipY, AlphaOp, DataFormat sourceFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, Vector<uint8_t>& data);
1228
1229     class ImageExtractor {
1230     public:
1231         ImageExtractor(Image*, ImageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
1232
1233         // Each platform must provide an implementation of this method to deallocate or release resources
1234         // associated with the image if needed.
1235         ~ImageExtractor();
1236
1237         bool extractSucceeded() { return m_extractSucceeded; }
1238         const void* imagePixelData() { return m_imagePixelData; }
1239         unsigned imageWidth() { return m_imageWidth; }
1240         unsigned imageHeight() { return m_imageHeight; }
1241         DataFormat imageSourceFormat() { return m_imageSourceFormat; }
1242         AlphaOp imageAlphaOp() { return m_alphaOp; }
1243         unsigned imageSourceUnpackAlignment() { return m_imageSourceUnpackAlignment; }
1244         ImageHtmlDomSource imageHtmlDomSource() { return m_imageHtmlDomSource; }
1245     private:
1246         // Each platform must provide an implementation of this method.
1247         // Extracts the image and keeps track of its status, such as width, height, Source Alignment, format and AlphaOp etc,
1248         // needs to lock the resources or relevant data if needed and returns true upon success
1249         bool extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
1250
1251 #if USE(CAIRO)
1252         ImageSource* m_decoder;
1253         RefPtr<cairo_surface_t> m_imageSurface;
1254 #elif USE(CG)
1255         RetainPtr<CGImageRef> m_cgImage;
1256         RetainPtr<CGImageRef> m_decodedImage;
1257         RetainPtr<CFDataRef> m_pixelData;
1258         std::unique_ptr<uint8_t[]> m_formalizedRGBA8Data;
1259 #endif
1260         Image* m_image;
1261         ImageHtmlDomSource m_imageHtmlDomSource;
1262         bool m_extractSucceeded;
1263         const void* m_imagePixelData;
1264         unsigned m_imageWidth;
1265         unsigned m_imageHeight;
1266         DataFormat m_imageSourceFormat;
1267         AlphaOp m_alphaOp;
1268         unsigned m_imageSourceUnpackAlignment;
1269     };
1270
1271 private:
1272     GraphicsContext3D(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
1273     static int GPUCheckCounter;
1274
1275     // Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel
1276     // data into the specified OpenGL destination format and type.
1277     // A sourceUnpackAlignment of zero indicates that the source
1278     // data is tightly packed. Non-zero values may take a slow path.
1279     // Destination data will have no gaps between rows.
1280     static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned destinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool flipY);
1281
1282     // Take into account the user's requested context creation attributes,
1283     // in particular stencil and antialias, and determine which could or
1284     // could not be honored based on the capabilities of the OpenGL
1285     // implementation.
1286     void validateDepthStencil(const char* packedDepthStencilExtension);
1287     void validateAttributes();
1288     
1289     // Call to make during draw calls to check on the GPU's status.
1290     void checkGPUStatusIfNecessary();
1291
1292     // Read rendering results into a pixel array with the same format as the
1293     // backbuffer.
1294     void readRenderingResults(unsigned char* pixels, int pixelsSize);
1295     void readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels);
1296
1297 #if PLATFORM(IOS)
1298     void setRenderbufferStorageFromDrawable(GC3Dsizei width, GC3Dsizei height);
1299 #endif
1300
1301     bool reshapeFBOs(const IntSize&);
1302     void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
1303     void attachDepthAndStencilBufferIfNeeded(GLuint internalDepthStencilFormat, int width, int height);
1304 #if PLATFORM(EFL) && USE(GRAPHICS_SURFACE)
1305     void createGraphicsSurfaces(const IntSize&);
1306 #endif
1307
1308     int m_currentWidth, m_currentHeight;
1309     bool isResourceSafe();
1310
1311 #if PLATFORM(COCOA)
1312     RetainPtr<WebGLLayer> m_webGLLayer;
1313     PlatformGraphicsContext3D m_contextObj;
1314 #endif
1315
1316 #if PLATFORM(WIN) && USE(CA)
1317     RefPtr<PlatformCALayer> m_webGLLayer;
1318 #endif
1319
1320     typedef HashMap<String, sh::ShaderVariable> ShaderSymbolMap;
1321
1322     struct ShaderSourceEntry {
1323         GC3Denum type;
1324         String source;
1325         String translatedSource;
1326         String log;
1327         bool isValid;
1328         ShaderSymbolMap attributeMap;
1329         ShaderSymbolMap uniformMap;
1330         ShaderSymbolMap varyingMap;
1331         ShaderSourceEntry()
1332             : type(VERTEX_SHADER)
1333             , isValid(false)
1334         {
1335         }
1336         
1337         ShaderSymbolMap& symbolMap(enum ANGLEShaderSymbolType symbolType)
1338         {
1339             ASSERT(symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE || symbolType == SHADER_SYMBOL_TYPE_UNIFORM || symbolType == SHADER_SYMBOL_TYPE_VARYING);
1340             if (symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE)
1341                 return attributeMap;
1342             if (symbolType == SHADER_SYMBOL_TYPE_VARYING)
1343                 return varyingMap;
1344             return uniformMap;
1345         }
1346     };
1347
1348     typedef HashMap<Platform3DObject, ShaderSourceEntry> ShaderSourceMap;
1349     ShaderSourceMap m_shaderSourceMap;
1350
1351     struct ActiveShaderSymbolCounts {
1352         Vector<GC3Dint> filteredToActualAttributeIndexMap;
1353         Vector<GC3Dint> filteredToActualUniformIndexMap;
1354
1355         ActiveShaderSymbolCounts()
1356         {
1357         }
1358
1359         GC3Dint countForType(GC3Denum activeType)
1360         {
1361             ASSERT(activeType == ACTIVE_ATTRIBUTES || activeType == ACTIVE_UNIFORMS);
1362             if (activeType == ACTIVE_ATTRIBUTES)
1363                 return filteredToActualAttributeIndexMap.size();
1364
1365             return filteredToActualUniformIndexMap.size();
1366         }
1367     };
1368     typedef HashMap<Platform3DObject, ActiveShaderSymbolCounts> ShaderProgramSymbolCountMap;
1369     ShaderProgramSymbolCountMap m_shaderProgramSymbolCountMap;
1370
1371     typedef HashMap<String, String> HashedSymbolMap;
1372     HashedSymbolMap m_possiblyUnusedAttributeMap;
1373
1374     String mappedSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
1375     String mappedSymbolName(Platform3DObject shaders[2], size_t count, const String& name);
1376     String originalSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
1377
1378     ANGLEWebKitBridge m_compiler;
1379
1380     std::unique_ptr<ShaderNameHash> nameHashMapForShaders;
1381
1382 #if ((PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN)) && USE(OPENGL_ES_2))
1383     friend class Extensions3DOpenGLES;
1384     std::unique_ptr<Extensions3DOpenGLES> m_extensions;
1385 #else
1386     friend class Extensions3DOpenGL;
1387     std::unique_ptr<Extensions3DOpenGL> m_extensions;
1388 #endif
1389     friend class Extensions3DOpenGLCommon;
1390
1391     Attributes m_attrs;
1392     RenderStyle m_renderStyle;
1393     Vector<Vector<float>> m_vertexArray;
1394
1395     GC3Duint m_texture;
1396     GC3Duint m_compositorTexture;
1397     GC3Duint m_fbo;
1398 #if USE(COORDINATED_GRAPHICS_THREADED)
1399     GC3Duint m_intermediateTexture;
1400 #endif
1401
1402     GC3Duint m_depthBuffer;
1403     GC3Duint m_stencilBuffer;
1404     GC3Duint m_depthStencilBuffer;
1405
1406     bool m_layerComposited;
1407     GC3Duint m_internalColorFormat;
1408
1409     struct GraphicsContext3DState {
1410         GraphicsContext3DState()
1411             : boundFBO(0)
1412             , activeTexture(GraphicsContext3D::TEXTURE0)
1413             , boundTexture0(0)
1414         { }
1415
1416         GC3Duint boundFBO;
1417         GC3Denum activeTexture;
1418         GC3Duint boundTexture0;
1419     };
1420
1421     GraphicsContext3DState m_state;
1422
1423     // For multisampling
1424     GC3Duint m_multisampleFBO;
1425     GC3Duint m_multisampleDepthStencilBuffer;
1426     GC3Duint m_multisampleColorBuffer;
1427
1428     // Errors raised by synthesizeGLError().
1429     ListHashSet<GC3Denum> m_syntheticErrors;
1430
1431     friend class GraphicsContext3DPrivate;
1432     std::unique_ptr<GraphicsContext3DPrivate> m_private;
1433     
1434     WebGLRenderingContextBase* m_webglContext;
1435
1436     bool m_isForWebGL2 { false };
1437 };
1438
1439 } // namespace WebCore
1440
1441 #endif // GraphicsContext3D_h