Correct missing EXT_sRGB Format Handling
[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
718     // Context creation attributes.
719     struct Attributes {
720         Attributes()
721             : alpha(true)
722             , depth(true)
723             , stencil(false)
724             , antialias(true)
725             , premultipliedAlpha(true)
726             , preserveDrawingBuffer(false)
727             , noExtensions(false)
728             , shareResources(true)
729             , preferDiscreteGPU(false)
730             , forceSoftwareRenderer(false)
731             , devicePixelRatio(1)
732         {
733         }
734
735         bool alpha;
736         bool depth;
737         bool stencil;
738         bool antialias;
739         bool premultipliedAlpha;
740         bool preserveDrawingBuffer;
741         bool noExtensions;
742         bool shareResources;
743         bool preferDiscreteGPU;
744         bool forceSoftwareRenderer;
745         float devicePixelRatio;
746     };
747
748     enum RenderStyle {
749         RenderOffscreen,
750         RenderDirectlyToHostWindow,
751         RenderToCurrentGLContext
752     };
753
754     class ContextLostCallback {
755     public:
756         virtual void onContextLost() = 0;
757         virtual ~ContextLostCallback() {}
758     };
759
760     class ErrorMessageCallback {
761     public:
762         virtual void onErrorMessage(const String& message, GC3Dint id) = 0;
763         virtual ~ErrorMessageCallback() { }
764     };
765
766     void setContextLostCallback(std::unique_ptr<ContextLostCallback>);
767     void setErrorMessageCallback(std::unique_ptr<ErrorMessageCallback>);
768
769     static PassRefPtr<GraphicsContext3D> create(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
770     static PassRefPtr<GraphicsContext3D> createForCurrentGLContext();
771     ~GraphicsContext3D();
772
773 #if PLATFORM(COCOA)
774     PlatformGraphicsContext3D platformGraphicsContext3D() const { return m_contextObj; }
775     Platform3DObject platformTexture() const { return m_compositorTexture; }
776     CALayer* platformLayer() const { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); }
777 #else
778     PlatformGraphicsContext3D platformGraphicsContext3D();
779     Platform3DObject platformTexture() const;
780     PlatformLayer* platformLayer() const;
781 #endif
782
783     bool makeContextCurrent();
784     void setWebGLContext(WebGLRenderingContextBase* base) { m_webglContext = base; }
785
786     // With multisampling on, blit from multisampleFBO to regular FBO.
787     void prepareTexture();
788
789     // Equivalent to ::glTexImage2D(). Allows pixels==0 with no allocation.
790     void texImage2DDirect(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels);
791
792     // Helper to texImage2D with pixel==0 case: pixels are initialized to 0.
793     // Return true if no GL error is synthesized.
794     // By default, alignment is 4, the OpenGL default setting.
795     bool texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint alignment = 4);
796
797     bool isGLES2Compliant() const;
798
799     //----------------------------------------------------------------------
800     // Helpers for texture uploading and pixel readback.
801     //
802
803     // Computes the components per pixel and bytes per component
804     // for the given format and type combination. Returns false if
805     // either was an invalid enum.
806     static bool computeFormatAndTypeParameters(GC3Denum format,
807                                                GC3Denum type,
808                                                unsigned int* componentsPerPixel,
809                                                unsigned int* bytesPerComponent);
810
811     // Computes the image size in bytes. If paddingInBytes is not null, padding
812     // is also calculated in return. Returns NO_ERROR if succeed, otherwise
813     // return the suggested GL error indicating the cause of the failure:
814     //   INVALID_VALUE if width/height is negative or overflow happens.
815     //   INVALID_ENUM if format/type is illegal.
816     static GC3Denum computeImageSizeInBytes(GC3Denum format,
817                                      GC3Denum type,
818                                      GC3Dsizei width,
819                                      GC3Dsizei height,
820                                      GC3Dint alignment,
821                                      unsigned int* imageSizeInBytes,
822                                      unsigned int* paddingInBytes);
823
824     // Extracts the contents of the given ImageData into the passed Vector,
825     // packing the pixel data according to the given format and type,
826     // and obeying the flipY and premultiplyAlpha flags. Returns true
827     // upon success.
828     static bool extractImageData(ImageData*,
829                           GC3Denum format,
830                           GC3Denum type,
831                           bool flipY,
832                           bool premultiplyAlpha,
833                           Vector<uint8_t>& data);
834
835     // Helper function which extracts the user-supplied texture
836     // data, applying the flipY and premultiplyAlpha parameters.
837     // If the data is not tightly packed according to the passed
838     // unpackAlignment, the output data will be tightly packed.
839     // Returns true if successful, false if any error occurred.
840     static bool extractTextureData(unsigned int width, unsigned int height,
841                             GC3Denum format, GC3Denum type,
842                             unsigned int unpackAlignment,
843                             bool flipY, bool premultiplyAlpha,
844                             const void* pixels,
845                             Vector<uint8_t>& data);
846
847
848     // Attempt to enumerate all possible native image formats to
849     // reduce the amount of temporary allocations during texture
850     // uploading. This enum must be public because it is accessed
851     // by non-member functions.
852     enum DataFormat {
853         DataFormatRGBA8 = 0,
854         DataFormatRGBA16Little,
855         DataFormatRGBA16Big,
856         DataFormatRGBA16F,
857         DataFormatRGBA32F,
858         DataFormatRGB8,
859         DataFormatRGB16Little,
860         DataFormatRGB16Big,
861         DataFormatRGB16F,
862         DataFormatRGB32F,
863         DataFormatBGR8,
864         DataFormatBGRA8,
865         DataFormatBGRA16Little,
866         DataFormatBGRA16Big,
867         DataFormatARGB8,
868         DataFormatARGB16Little,
869         DataFormatARGB16Big,
870         DataFormatABGR8,
871         DataFormatRGBA5551,
872         DataFormatRGBA4444,
873         DataFormatRGB565,
874         DataFormatR8,
875         DataFormatR16Little,
876         DataFormatR16Big,
877         DataFormatR16F,
878         DataFormatR32F,
879         DataFormatRA8,
880         DataFormatRA16Little,
881         DataFormatRA16Big,
882         DataFormatRA16F,
883         DataFormatRA32F,
884         DataFormatAR8,
885         DataFormatAR16Little,
886         DataFormatAR16Big,
887         DataFormatA8,
888         DataFormatA16Little,
889         DataFormatA16Big,
890         DataFormatA16F,
891         DataFormatA32F,
892         DataFormatNumFormats
893     };
894
895     ALWAYS_INLINE static bool hasAlpha(DataFormat format)
896     {
897         return format == GraphicsContext3D::DataFormatA8
898             || format == GraphicsContext3D::DataFormatA16F
899             || format == GraphicsContext3D::DataFormatA32F
900             || format == GraphicsContext3D::DataFormatRA8
901             || format == GraphicsContext3D::DataFormatAR8
902             || format == GraphicsContext3D::DataFormatRA16F
903             || format == GraphicsContext3D::DataFormatRA32F
904             || format == GraphicsContext3D::DataFormatRGBA8
905             || format == GraphicsContext3D::DataFormatBGRA8
906             || format == GraphicsContext3D::DataFormatARGB8
907             || format == GraphicsContext3D::DataFormatABGR8
908             || format == GraphicsContext3D::DataFormatRGBA16F
909             || format == GraphicsContext3D::DataFormatRGBA32F
910             || format == GraphicsContext3D::DataFormatRGBA4444
911             || format == GraphicsContext3D::DataFormatRGBA5551;
912     }
913
914     ALWAYS_INLINE static bool hasColor(DataFormat format)
915     {
916         return format == GraphicsContext3D::DataFormatRGBA8
917             || format == GraphicsContext3D::DataFormatRGBA16F
918             || format == GraphicsContext3D::DataFormatRGBA32F
919             || format == GraphicsContext3D::DataFormatRGB8
920             || format == GraphicsContext3D::DataFormatRGB16F
921             || format == GraphicsContext3D::DataFormatRGB32F
922             || format == GraphicsContext3D::DataFormatBGR8
923             || format == GraphicsContext3D::DataFormatBGRA8
924             || format == GraphicsContext3D::DataFormatARGB8
925             || format == GraphicsContext3D::DataFormatABGR8
926             || format == GraphicsContext3D::DataFormatRGBA5551
927             || format == GraphicsContext3D::DataFormatRGBA4444
928             || format == GraphicsContext3D::DataFormatRGB565
929             || format == GraphicsContext3D::DataFormatR8
930             || format == GraphicsContext3D::DataFormatR16F
931             || format == GraphicsContext3D::DataFormatR32F
932             || format == GraphicsContext3D::DataFormatRA8
933             || format == GraphicsContext3D::DataFormatRA16F
934             || format == GraphicsContext3D::DataFormatRA32F
935             || format == GraphicsContext3D::DataFormatAR8;
936     }
937
938     // Check if the format is one of the formats from the ImageData or DOM elements.
939     // The formats from ImageData is always RGBA8.
940     // 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.
941     static ALWAYS_INLINE bool srcFormatComesFromDOMElementOrImageData(DataFormat SrcFormat)
942     {
943 #if USE(CG)
944 #if CPU(BIG_ENDIAN)
945     return SrcFormat == DataFormatRGBA8 || SrcFormat == DataFormatARGB8 || SrcFormat == DataFormatRGB8
946         || SrcFormat == DataFormatRA8 || SrcFormat == DataFormatAR8 || SrcFormat == DataFormatR8 || SrcFormat == DataFormatA8;
947 #else
948     // That LITTLE_ENDIAN case has more possible formats than BIG_ENDIAN case is because some decoded image data is actually big endian
949     // even on little endian architectures.
950     return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatABGR8 || SrcFormat == DataFormatBGR8
951         || SrcFormat == DataFormatRGBA8 || SrcFormat == DataFormatARGB8 || SrcFormat == DataFormatRGB8
952         || SrcFormat == DataFormatR8 || SrcFormat == DataFormatA8
953         || SrcFormat == DataFormatRA8 || SrcFormat == DataFormatAR8;
954 #endif
955 #else
956     return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatRGBA8;
957 #endif
958     }
959
960     //----------------------------------------------------------------------
961     // Entry points for WebGL.
962     //
963
964     void activeTexture(GC3Denum texture);
965     void attachShader(Platform3DObject program, Platform3DObject shader);
966     void bindAttribLocation(Platform3DObject, GC3Duint index, const String& name);
967     void bindBuffer(GC3Denum target, Platform3DObject);
968     void bindFramebuffer(GC3Denum target, Platform3DObject);
969     void bindRenderbuffer(GC3Denum target, Platform3DObject);
970     void bindTexture(GC3Denum target, Platform3DObject);
971     void blendColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
972     void blendEquation(GC3Denum mode);
973     void blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha);
974     void blendFunc(GC3Denum sfactor, GC3Denum dfactor);
975     void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha);
976
977     void bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage);
978     void bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage);
979     void bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data);
980
981     GC3Denum checkFramebufferStatus(GC3Denum target);
982     void clear(GC3Dbitfield mask);
983     void clearColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
984     void clearDepth(GC3Dclampf depth);
985     void clearStencil(GC3Dint s);
986     void colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dboolean blue, GC3Dboolean alpha);
987     void compileShader(Platform3DObject);
988
989     void compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Dsizei imageSize, const void* data);
990     void compressedTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Dsizei imageSize, const void* data);
991     void copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border);
992     void copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
993     void cullFace(GC3Denum mode);
994     void depthFunc(GC3Denum func);
995     void depthMask(GC3Dboolean flag);
996     void depthRange(GC3Dclampf zNear, GC3Dclampf zFar);
997     void detachShader(Platform3DObject, Platform3DObject);
998     void disable(GC3Denum cap);
999     void disableVertexAttribArray(GC3Duint index);
1000     void drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count);
1001     void drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset);
1002
1003     void enable(GC3Denum cap);
1004     void enableVertexAttribArray(GC3Duint index);
1005     void finish();
1006     void flush();
1007     void framebufferRenderbuffer(GC3Denum target, GC3Denum attachment, GC3Denum renderbuffertarget, Platform3DObject);
1008     void framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum textarget, Platform3DObject, GC3Dint level);
1009     void frontFace(GC3Denum mode);
1010     void generateMipmap(GC3Denum target);
1011
1012     bool getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo&);
1013     bool getActiveAttribImpl(Platform3DObject program, GC3Duint index, ActiveInfo&);
1014     bool getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo&);
1015     bool getActiveUniformImpl(Platform3DObject program, GC3Duint index, ActiveInfo&);
1016     void getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders);
1017     GC3Dint getAttribLocation(Platform3DObject, const String& name);
1018     void getBooleanv(GC3Denum pname, GC3Dboolean* value);
1019     void getBufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
1020     Attributes getContextAttributes();
1021     GC3Denum getError();
1022     void getFloatv(GC3Denum pname, GC3Dfloat* value);
1023     void getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum pname, GC3Dint* value);
1024     void getIntegerv(GC3Denum pname, GC3Dint* value);
1025     void getInteger64v(GC3Denum pname, GC3Dint64* value);
1026     void getProgramiv(Platform3DObject program, GC3Denum pname, GC3Dint* value);
1027     void getNonBuiltInActiveSymbolCount(Platform3DObject program, GC3Denum pname, GC3Dint* value);
1028     String getProgramInfoLog(Platform3DObject);
1029     String getUnmangledInfoLog(Platform3DObject[2], GC3Dsizei, const String&);
1030     void getRenderbufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
1031     void getShaderiv(Platform3DObject, GC3Denum pname, GC3Dint* value);
1032     String getShaderInfoLog(Platform3DObject);
1033     void getShaderPrecisionFormat(GC3Denum shaderType, GC3Denum precisionType, GC3Dint* range, GC3Dint* precision);
1034     String getShaderSource(Platform3DObject);
1035     String getString(GC3Denum name);
1036     void getTexParameterfv(GC3Denum target, GC3Denum pname, GC3Dfloat* value);
1037     void getTexParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
1038     void getUniformfv(Platform3DObject program, GC3Dint location, GC3Dfloat* value);
1039     void getUniformiv(Platform3DObject program, GC3Dint location, GC3Dint* value);
1040     GC3Dint getUniformLocation(Platform3DObject, const String& name);
1041     void getVertexAttribfv(GC3Duint index, GC3Denum pname, GC3Dfloat* value);
1042     void getVertexAttribiv(GC3Duint index, GC3Denum pname, GC3Dint* value);
1043     GC3Dsizeiptr getVertexAttribOffset(GC3Duint index, GC3Denum pname);
1044
1045     void hint(GC3Denum target, GC3Denum mode);
1046     GC3Dboolean isBuffer(Platform3DObject);
1047     GC3Dboolean isEnabled(GC3Denum cap);
1048     GC3Dboolean isFramebuffer(Platform3DObject);
1049     GC3Dboolean isProgram(Platform3DObject);
1050     GC3Dboolean isRenderbuffer(Platform3DObject);
1051     GC3Dboolean isShader(Platform3DObject);
1052     GC3Dboolean isTexture(Platform3DObject);
1053     void lineWidth(GC3Dfloat);
1054     void linkProgram(Platform3DObject);
1055     void pixelStorei(GC3Denum pname, GC3Dint param);
1056     void polygonOffset(GC3Dfloat factor, GC3Dfloat units);
1057
1058     void readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data);
1059
1060     void releaseShaderCompiler();
1061
1062     void renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height);
1063     void sampleCoverage(GC3Dclampf value, GC3Dboolean invert);
1064     void scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
1065     void shaderSource(Platform3DObject, const String& string);
1066     void stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask);
1067     void stencilFuncSeparate(GC3Denum face, GC3Denum func, GC3Dint ref, GC3Duint mask);
1068     void stencilMask(GC3Duint mask);
1069     void stencilMaskSeparate(GC3Denum face, GC3Duint mask);
1070     void stencilOp(GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
1071     void stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
1072
1073     bool texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels);
1074     void texParameterf(GC3Denum target, GC3Denum pname, GC3Dfloat param);
1075     void texParameteri(GC3Denum target, GC3Denum pname, GC3Dint param);
1076     void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels);
1077
1078     void uniform1f(GC3Dint location, GC3Dfloat x);
1079     void uniform1fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
1080     void uniform1i(GC3Dint location, GC3Dint x);
1081     void uniform1iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
1082     void uniform2f(GC3Dint location, GC3Dfloat x, GC3Dfloat y);
1083     void uniform2fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
1084     void uniform2i(GC3Dint location, GC3Dint x, GC3Dint y);
1085     void uniform2iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
1086     void uniform3f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
1087     void uniform3fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
1088     void uniform3i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z);
1089     void uniform3iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
1090     void uniform4f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
1091     void uniform4fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
1092     void uniform4i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w);
1093     void uniform4iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
1094     void uniformMatrix2fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
1095     void uniformMatrix3fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
1096     void uniformMatrix4fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
1097
1098     void useProgram(Platform3DObject);
1099     void validateProgram(Platform3DObject);
1100     bool checkVaryingsPacking(Platform3DObject vertexShader, Platform3DObject fragmentShader) const;
1101     bool precisionsMatch(Platform3DObject vertexShader, Platform3DObject fragmentShader) const;
1102
1103     void vertexAttrib1f(GC3Duint index, GC3Dfloat x);
1104     void vertexAttrib1fv(GC3Duint index, GC3Dfloat* values);
1105     void vertexAttrib2f(GC3Duint index, GC3Dfloat x, GC3Dfloat y);
1106     void vertexAttrib2fv(GC3Duint index, GC3Dfloat* values);
1107     void vertexAttrib3f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
1108     void vertexAttrib3fv(GC3Duint index, GC3Dfloat* values);
1109     void vertexAttrib4f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
1110     void vertexAttrib4fv(GC3Duint index, GC3Dfloat* values);
1111     void vertexAttribPointer(GC3Duint index, GC3Dint size, GC3Denum type, GC3Dboolean normalized,
1112                              GC3Dsizei stride, GC3Dintptr offset);
1113
1114     void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
1115
1116     void reshape(int width, int height);
1117
1118     void drawArraysInstanced(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount);
1119     void drawElementsInstanced(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount);
1120     void vertexAttribDivisor(GC3Duint index, GC3Duint divisor);
1121
1122     // VertexArrayOject calls
1123     Platform3DObject createVertexArray();
1124     void deleteVertexArray(Platform3DObject);
1125     GC3Dboolean isVertexArray(Platform3DObject);
1126     void bindVertexArray(Platform3DObject);
1127
1128 #if PLATFORM(GTK) || PLATFORM(EFL) || USE(CAIRO)
1129     void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
1130                        int canvasWidth, int canvasHeight, PlatformContextCairo* context);
1131 #elif USE(CG)
1132     void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, GraphicsContext&);
1133 #endif
1134
1135     void markContextChanged();
1136     void markLayerComposited();
1137     bool layerComposited() const;
1138     void forceContextLost();
1139
1140     void paintRenderingResultsToCanvas(ImageBuffer*);
1141     PassRefPtr<ImageData> paintRenderingResultsToImageData();
1142     bool paintCompositedResultsToCanvas(ImageBuffer*);
1143
1144 #if PLATFORM(IOS)
1145     void endPaint();
1146 #endif
1147
1148     // Support for buffer creation and deletion
1149     Platform3DObject createBuffer();
1150     Platform3DObject createFramebuffer();
1151     Platform3DObject createProgram();
1152     Platform3DObject createRenderbuffer();
1153     Platform3DObject createShader(GC3Denum);
1154     Platform3DObject createTexture();
1155
1156     void deleteBuffer(Platform3DObject);
1157     void deleteFramebuffer(Platform3DObject);
1158     void deleteProgram(Platform3DObject);
1159     void deleteRenderbuffer(Platform3DObject);
1160     void deleteShader(Platform3DObject);
1161     void deleteTexture(Platform3DObject);
1162
1163     // Synthesizes an OpenGL error which will be returned from a
1164     // later call to getError. This is used to emulate OpenGL ES
1165     // 2.0 behavior on the desktop and to enforce additional error
1166     // checking mandated by WebGL.
1167     //
1168     // Per the behavior of glGetError, this stores at most one
1169     // instance of any given error, and returns them from calls to
1170     // getError in the order they were added.
1171     void synthesizeGLError(GC3Denum error);
1172
1173     // Read real OpenGL errors, and move them to the synthetic
1174     // error list. Return true if at least one error is moved.
1175     bool moveErrorsToSyntheticErrorList();
1176
1177     // Support for extensions. Returns a non-null object, though not
1178     // all methods it contains may necessarily be supported on the
1179     // current hardware. Must call Extensions3D::supports() to
1180     // determine this.
1181     Extensions3D* getExtensions();
1182
1183     IntSize getInternalFramebufferSize() const;
1184
1185     static unsigned getClearBitsByAttachmentType(GC3Denum);
1186     static unsigned getClearBitsByFormat(GC3Denum);
1187
1188     enum ChannelBits {
1189         ChannelRed = 1,
1190         ChannelGreen = 2,
1191         ChannelBlue = 4,
1192         ChannelAlpha = 8,
1193         ChannelDepth = 16,
1194         ChannelStencil = 32,
1195         ChannelRGB = ChannelRed | ChannelGreen | ChannelBlue,
1196         ChannelRGBA = ChannelRGB | ChannelAlpha,
1197     };
1198
1199     static unsigned getChannelBitsByFormat(GC3Denum);
1200
1201     // Possible alpha operations that may need to occur during
1202     // pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must
1203     // be removed.
1204     enum AlphaOp {
1205         AlphaDoNothing = 0,
1206         AlphaDoPremultiply = 1,
1207         AlphaDoUnmultiply = 2
1208     };
1209
1210     enum ImageHtmlDomSource {
1211         HtmlDomImage = 0,
1212         HtmlDomCanvas = 1,
1213         HtmlDomVideo = 2,
1214         HtmlDomNone = 3
1215     };
1216
1217     // Packs the contents of the given Image which is passed in |pixels| into the passed Vector
1218     // according to the given format and type, and obeying the flipY and AlphaOp flags.
1219     // Returns true upon success.
1220     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);
1221
1222     class ImageExtractor {
1223     public:
1224         ImageExtractor(Image*, ImageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
1225
1226         // Each platform must provide an implementation of this method to deallocate or release resources
1227         // associated with the image if needed.
1228         ~ImageExtractor();
1229
1230         bool extractSucceeded() { return m_extractSucceeded; }
1231         const void* imagePixelData() { return m_imagePixelData; }
1232         unsigned imageWidth() { return m_imageWidth; }
1233         unsigned imageHeight() { return m_imageHeight; }
1234         DataFormat imageSourceFormat() { return m_imageSourceFormat; }
1235         AlphaOp imageAlphaOp() { return m_alphaOp; }
1236         unsigned imageSourceUnpackAlignment() { return m_imageSourceUnpackAlignment; }
1237         ImageHtmlDomSource imageHtmlDomSource() { return m_imageHtmlDomSource; }
1238     private:
1239         // Each platform must provide an implementation of this method.
1240         // Extracts the image and keeps track of its status, such as width, height, Source Alignment, format and AlphaOp etc,
1241         // needs to lock the resources or relevant data if needed and returns true upon success
1242         bool extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
1243
1244 #if USE(CAIRO)
1245         ImageSource* m_decoder;
1246         RefPtr<cairo_surface_t> m_imageSurface;
1247 #elif USE(CG)
1248         CGImageRef m_cgImage;
1249         RetainPtr<CGImageRef> m_decodedImage;
1250         RetainPtr<CFDataRef> m_pixelData;
1251         std::unique_ptr<uint8_t[]> m_formalizedRGBA8Data;
1252 #endif
1253         Image* m_image;
1254         ImageHtmlDomSource m_imageHtmlDomSource;
1255         bool m_extractSucceeded;
1256         const void* m_imagePixelData;
1257         unsigned m_imageWidth;
1258         unsigned m_imageHeight;
1259         DataFormat m_imageSourceFormat;
1260         AlphaOp m_alphaOp;
1261         unsigned m_imageSourceUnpackAlignment;
1262     };
1263
1264 private:
1265     GraphicsContext3D(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
1266     static int numActiveContexts;
1267     static int GPUCheckCounter;
1268
1269     // Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel
1270     // data into the specified OpenGL destination format and type.
1271     // A sourceUnpackAlignment of zero indicates that the source
1272     // data is tightly packed. Non-zero values may take a slow path.
1273     // Destination data will have no gaps between rows.
1274     static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned destinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool flipY);
1275
1276     // Take into account the user's requested context creation attributes,
1277     // in particular stencil and antialias, and determine which could or
1278     // could not be honored based on the capabilities of the OpenGL
1279     // implementation.
1280     void validateDepthStencil(const char* packedDepthStencilExtension);
1281     void validateAttributes();
1282     
1283     // Call to make during draw calls to check on the GPU's status.
1284     void checkGPUStatusIfNecessary();
1285
1286     // Read rendering results into a pixel array with the same format as the
1287     // backbuffer.
1288     void readRenderingResults(unsigned char* pixels, int pixelsSize);
1289     void readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels);
1290
1291 #if PLATFORM(IOS)
1292     bool setRenderbufferStorageFromDrawable(GC3Dsizei width, GC3Dsizei height);
1293 #endif
1294
1295     bool reshapeFBOs(const IntSize&);
1296     void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
1297     void attachDepthAndStencilBufferIfNeeded(GLuint internalDepthStencilFormat, int width, int height);
1298 #if PLATFORM(EFL) && USE(GRAPHICS_SURFACE)
1299     void createGraphicsSurfaces(const IntSize&);
1300 #endif
1301
1302     int m_currentWidth, m_currentHeight;
1303     bool isResourceSafe();
1304
1305 #if PLATFORM(COCOA)
1306     RetainPtr<WebGLLayer> m_webGLLayer;
1307     PlatformGraphicsContext3D m_contextObj;
1308 #endif
1309
1310 #if PLATFORM(WIN) && USE(CA)
1311     RefPtr<PlatformCALayer> m_webGLLayer;
1312 #endif
1313
1314     struct SymbolInfo {
1315         SymbolInfo()
1316             : type(0)
1317             , size(0)
1318             , precision(GL_NONE) // Invalid precision.
1319             , staticUse(0)
1320         {
1321         }
1322
1323         SymbolInfo(GC3Denum type, int size, const String& mappedName, sh::GLenum precision, int staticUse)
1324             : type(type)
1325             , size(size)
1326             , mappedName(mappedName)
1327             , precision(precision)
1328             , staticUse(staticUse)
1329         {
1330         }
1331
1332         bool operator==(SymbolInfo& other) const
1333         {
1334             return type == other.type && size == other.size && mappedName == other.mappedName;
1335         }
1336
1337         GC3Denum type;
1338         int size;
1339         String mappedName;
1340         sh::GLenum precision;
1341         int staticUse;
1342     };
1343
1344     typedef HashMap<String, SymbolInfo> ShaderSymbolMap;
1345
1346     struct ShaderSourceEntry {
1347         GC3Denum type;
1348         String source;
1349         String translatedSource;
1350         String log;
1351         bool isValid;
1352         ShaderSymbolMap attributeMap;
1353         ShaderSymbolMap uniformMap;
1354         ShaderSymbolMap varyingMap;
1355         ShaderSourceEntry()
1356             : type(VERTEX_SHADER)
1357             , isValid(false)
1358         {
1359         }
1360         
1361         ShaderSymbolMap& symbolMap(enum ANGLEShaderSymbolType symbolType)
1362         {
1363             ASSERT(symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE || symbolType == SHADER_SYMBOL_TYPE_UNIFORM || symbolType == SHADER_SYMBOL_TYPE_VARYING);
1364             if (symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE)
1365                 return attributeMap;
1366             if (symbolType == SHADER_SYMBOL_TYPE_VARYING)
1367                 return varyingMap;
1368             return uniformMap;
1369         }
1370     };
1371
1372     typedef HashMap<Platform3DObject, ShaderSourceEntry> ShaderSourceMap;
1373     ShaderSourceMap m_shaderSourceMap;
1374
1375     struct ActiveShaderSymbolCounts {
1376         Vector<GC3Dint> filteredToActualAttributeIndexMap;
1377         Vector<GC3Dint> filteredToActualUniformIndexMap;
1378
1379         ActiveShaderSymbolCounts()
1380         {
1381         }
1382
1383         GC3Dint countForType(GC3Denum activeType)
1384         {
1385             ASSERT(activeType == ACTIVE_ATTRIBUTES || activeType == ACTIVE_UNIFORMS);
1386             if (activeType == ACTIVE_ATTRIBUTES)
1387                 return filteredToActualAttributeIndexMap.size();
1388
1389             return filteredToActualUniformIndexMap.size();
1390         }
1391     };
1392     typedef HashMap<Platform3DObject, ActiveShaderSymbolCounts> ShaderProgramSymbolCountMap;
1393     ShaderProgramSymbolCountMap m_shaderProgramSymbolCountMap;
1394
1395     typedef HashMap<String, String> HashedSymbolMap;
1396     HashedSymbolMap m_possiblyUnusedAttributeMap;
1397
1398     String mappedSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
1399     String mappedSymbolName(Platform3DObject shaders[2], size_t count, const String& name);
1400     String originalSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
1401
1402     ANGLEWebKitBridge m_compiler;
1403
1404     std::unique_ptr<ShaderNameHash> nameHashMapForShaders;
1405
1406 #if ((PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN)) && USE(OPENGL_ES_2))
1407     friend class Extensions3DOpenGLES;
1408     std::unique_ptr<Extensions3DOpenGLES> m_extensions;
1409 #else
1410     friend class Extensions3DOpenGL;
1411     std::unique_ptr<Extensions3DOpenGL> m_extensions;
1412 #endif
1413     friend class Extensions3DOpenGLCommon;
1414
1415     Attributes m_attrs;
1416     RenderStyle m_renderStyle;
1417     Vector<Vector<float>> m_vertexArray;
1418
1419     GC3Duint m_texture;
1420     GC3Duint m_compositorTexture;
1421     GC3Duint m_fbo;
1422 #if USE(COORDINATED_GRAPHICS_THREADED)
1423     GC3Duint m_compositorFBO;
1424 #endif
1425
1426     GC3Duint m_depthBuffer;
1427     GC3Duint m_stencilBuffer;
1428     GC3Duint m_depthStencilBuffer;
1429
1430     bool m_layerComposited;
1431     GC3Duint m_internalColorFormat;
1432
1433     struct GraphicsContext3DState {
1434         GraphicsContext3DState()
1435             : boundFBO(0)
1436             , activeTexture(GraphicsContext3D::TEXTURE0)
1437             , boundTexture0(0)
1438         { }
1439
1440         GC3Duint boundFBO;
1441         GC3Denum activeTexture;
1442         GC3Duint boundTexture0;
1443     };
1444
1445     GraphicsContext3DState m_state;
1446
1447     // For multisampling
1448     GC3Duint m_multisampleFBO;
1449     GC3Duint m_multisampleDepthStencilBuffer;
1450     GC3Duint m_multisampleColorBuffer;
1451
1452     // Errors raised by synthesizeGLError().
1453     ListHashSet<GC3Denum> m_syntheticErrors;
1454
1455     friend class GraphicsContext3DPrivate;
1456     std::unique_ptr<GraphicsContext3DPrivate> m_private;
1457     
1458     WebGLRenderingContextBase* m_webglContext;
1459 };
1460
1461 } // namespace WebCore
1462
1463 #endif // GraphicsContext3D_h