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