[WinCairo] Compile error.
[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         SRGB8_ALPHA8 = 0x8C43,
508         COMPARE_REF_TO_TEXTURE = 0x884E,
509         RGBA32F = 0x8814,
510         RGB32F = 0x8815,
511         RGBA16F = 0x881A,
512         RGB16F = 0x881B,
513         VERTEX_ATTRIB_ARRAY_INTEGER = 0x88FD,
514         MAX_ARRAY_TEXTURE_LAYERS = 0x88FF,
515         MIN_PROGRAM_TEXEL_OFFSET = 0x8904,
516         MAX_PROGRAM_TEXEL_OFFSET = 0x8905,
517         MAX_VARYING_COMPONENTS = 0x8B4B,
518         TEXTURE_2D_ARRAY = 0x8C1A,
519         TEXTURE_BINDING_2D_ARRAY = 0x8C1D,
520         R11F_G11F_B10F = 0x8C3A,
521         UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B,
522         RGB9_E5 = 0x8C3D,
523         UNSIGNED_INT_5_9_9_9_REV = 0x8C3E,
524         TRANSFORM_FEEDBACK_BUFFER_MODE = 0x8C7F,
525         MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS = 0x8C80,
526         TRANSFORM_FEEDBACK_VARYINGS = 0x8C83,
527         TRANSFORM_FEEDBACK_BUFFER_START = 0x8C84,
528         TRANSFORM_FEEDBACK_BUFFER_SIZE = 0x8C85,
529         TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN = 0x8C88,
530         RASTERIZER_DISCARD = 0x8C89,
531         MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS = 0x8C8A,
532         MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 0x8C8B,
533         INTERLEAVED_ATTRIBS = 0x8C8C,
534         SEPARATE_ATTRIBS = 0x8C8D,
535         TRANSFORM_FEEDBACK_BUFFER = 0x8C8E,
536         TRANSFORM_FEEDBACK_BUFFER_BINDING = 0x8C8F,
537         RGBA32UI = 0x8D70,
538         RGB32UI = 0x8D71,
539         RGBA16UI = 0x8D76,
540         RGB16UI = 0x8D77,
541         RGBA8UI = 0x8D7C,
542         RGB8UI = 0x8D7D,
543         RGBA32I = 0x8D82,
544         RGB32I = 0x8D83,
545         RGBA16I = 0x8D88,
546         RGB16I = 0x8D89,
547         RGBA8I = 0x8D8E,
548         RGB8I = 0x8D8F,
549         RED_INTEGER = 0x8D94,
550         RGB_INTEGER = 0x8D98,
551         RGBA_INTEGER = 0x8D99,
552         SAMPLER_2D_ARRAY = 0x8DC1,
553         SAMPLER_2D_ARRAY_SHADOW = 0x8DC4,
554         SAMPLER_CUBE_SHADOW = 0x8DC5,
555         UNSIGNED_INT_VEC2 = 0x8DC6,
556         UNSIGNED_INT_VEC3 = 0x8DC7,
557         UNSIGNED_INT_VEC4 = 0x8DC8,
558         INT_SAMPLER_2D = 0x8DCA,
559         INT_SAMPLER_3D = 0x8DCB,
560         INT_SAMPLER_CUBE = 0x8DCC,
561         INT_SAMPLER_2D_ARRAY = 0x8DCF,
562         UNSIGNED_INT_SAMPLER_2D = 0x8DD2,
563         UNSIGNED_INT_SAMPLER_3D = 0x8DD3,
564         UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4,
565         UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7,
566         DEPTH_COMPONENT32F = 0x8CAC,
567         DEPTH32F_STENCIL8 = 0x8CAD,
568         FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD,
569         FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING = 0x8210,
570         FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE = 0x8211,
571         FRAMEBUFFER_ATTACHMENT_RED_SIZE = 0x8212,
572         FRAMEBUFFER_ATTACHMENT_GREEN_SIZE = 0x8213,
573         FRAMEBUFFER_ATTACHMENT_BLUE_SIZE = 0x8214,
574         FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE = 0x8215,
575         FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE = 0x8216,
576         FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE = 0x8217,
577         FRAMEBUFFER_DEFAULT = 0x8218,
578         DEPTH_STENCIL_ATTACHMENT = 0x821A,
579         DEPTH_STENCIL = 0x84F9,
580         UNSIGNED_INT_24_8 = 0x84FA,
581         DEPTH24_STENCIL8 = 0x88F0,
582         UNSIGNED_NORMALIZED = 0x8C17,
583         DRAW_FRAMEBUFFER_BINDING = 0x8CA6, /* Same as FRAMEBUFFER_BINDING */
584         READ_FRAMEBUFFER = 0x8CA8,
585         DRAW_FRAMEBUFFER = 0x8CA9,
586         READ_FRAMEBUFFER_BINDING = 0x8CAA,
587         RENDERBUFFER_SAMPLES = 0x8CAB,
588         FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER = 0x8CD4,
589         MAX_COLOR_ATTACHMENTS = 0x8CDF,
590         COLOR_ATTACHMENT1 = 0x8CE1,
591         COLOR_ATTACHMENT2 = 0x8CE2,
592         COLOR_ATTACHMENT3 = 0x8CE3,
593         COLOR_ATTACHMENT4 = 0x8CE4,
594         COLOR_ATTACHMENT5 = 0x8CE5,
595         COLOR_ATTACHMENT6 = 0x8CE6,
596         COLOR_ATTACHMENT7 = 0x8CE7,
597         COLOR_ATTACHMENT8 = 0x8CE8,
598         COLOR_ATTACHMENT9 = 0x8CE9,
599         COLOR_ATTACHMENT10 = 0x8CEA,
600         COLOR_ATTACHMENT11 = 0x8CEB,
601         COLOR_ATTACHMENT12 = 0x8CEC,
602         COLOR_ATTACHMENT13 = 0x8CED,
603         COLOR_ATTACHMENT14 = 0x8CEE,
604         COLOR_ATTACHMENT15 = 0x8CEF,
605         FRAMEBUFFER_INCOMPLETE_MULTISAMPLE = 0x8D56,
606         MAX_SAMPLES = 0x8D57,
607         HALF_FLOAT = 0x140B,
608         RG = 0x8227,
609         RG_INTEGER = 0x8228,
610         R8 = 0x8229,
611         RG8 = 0x822B,
612         R16F = 0x822D,
613         R32F = 0x822E,
614         RG16F = 0x822F,
615         RG32F = 0x8230,
616         R8I = 0x8231,
617         R8UI = 0x8232,
618         R16I = 0x8233,
619         R16UI = 0x8234,
620         R32I = 0x8235,
621         R32UI = 0x8236,
622         RG8I = 0x8237,
623         RG8UI = 0x8238,
624         RG16I = 0x8239,
625         RG16UI = 0x823A,
626         RG32I = 0x823B,
627         RG32UI = 0x823C,
628         VERTEX_ARRAY_BINDING = 0x85B5,
629         R8_SNORM = 0x8F94,
630         RG8_SNORM = 0x8F95,
631         RGB8_SNORM = 0x8F96,
632         RGBA8_SNORM = 0x8F97,
633         SIGNED_NORMALIZED = 0x8F9C,
634         COPY_READ_BUFFER = 0x8F36,
635         COPY_WRITE_BUFFER = 0x8F37,
636         COPY_READ_BUFFER_BINDING = 0x8F36, /* Same as COPY_READ_BUFFER */
637         COPY_WRITE_BUFFER_BINDING = 0x8F37, /* Same as COPY_WRITE_BUFFER */
638         UNIFORM_BUFFER = 0x8A11,
639         UNIFORM_BUFFER_BINDING = 0x8A28,
640         UNIFORM_BUFFER_START = 0x8A29,
641         UNIFORM_BUFFER_SIZE = 0x8A2A,
642         MAX_VERTEX_UNIFORM_BLOCKS = 0x8A2B,
643         MAX_FRAGMENT_UNIFORM_BLOCKS = 0x8A2D,
644         MAX_COMBINED_UNIFORM_BLOCKS = 0x8A2E,
645         MAX_UNIFORM_BUFFER_BINDINGS = 0x8A2F,
646         MAX_UNIFORM_BLOCK_SIZE = 0x8A30,
647         MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = 0x8A31,
648         MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = 0x8A33,
649         UNIFORM_BUFFER_OFFSET_ALIGNMENT = 0x8A34,
650         ACTIVE_UNIFORM_BLOCKS = 0x8A36,
651         UNIFORM_TYPE = 0x8A37,
652         UNIFORM_SIZE = 0x8A38,
653         UNIFORM_BLOCK_INDEX = 0x8A3A,
654         UNIFORM_OFFSET = 0x8A3B,
655         UNIFORM_ARRAY_STRIDE = 0x8A3C,
656         UNIFORM_MATRIX_STRIDE = 0x8A3D,
657         UNIFORM_IS_ROW_MAJOR = 0x8A3E,
658         UNIFORM_BLOCK_BINDING = 0x8A3F,
659         UNIFORM_BLOCK_DATA_SIZE = 0x8A40,
660         UNIFORM_BLOCK_ACTIVE_UNIFORMS = 0x8A42,
661         UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8A43,
662         UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER = 0x8A44,
663         UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8A46,
664         INVALID_INDEX = 0xFFFFFFFF,
665         MAX_VERTEX_OUTPUT_COMPONENTS = 0x9122,
666         MAX_FRAGMENT_INPUT_COMPONENTS = 0x9125,
667         MAX_SERVER_WAIT_TIMEOUT = 0x9111,
668         OBJECT_TYPE = 0x9112,
669         SYNC_CONDITION = 0x9113,
670         SYNC_STATUS = 0x9114,
671         SYNC_FLAGS = 0x9115,
672         SYNC_FENCE = 0x9116,
673         SYNC_GPU_COMMANDS_COMPLETE = 0x9117,
674         UNSIGNALED = 0x9118,
675         SIGNALED = 0x9119,
676         ALREADY_SIGNALED = 0x911A,
677         TIMEOUT_EXPIRED = 0x911B,
678         CONDITION_SATISFIED = 0x911C,
679 #if PLATFORM(WIN)
680         WAIT_FAILED_WIN = 0x911D,
681 #else
682         WAIT_FAILED = 0x911D,
683 #endif
684         SYNC_FLUSH_COMMANDS_BIT = 0x00000001,
685         VERTEX_ATTRIB_ARRAY_DIVISOR = 0x88FE,
686         ANY_SAMPLES_PASSED = 0x8C2F,
687         ANY_SAMPLES_PASSED_CONSERVATIVE = 0x8D6A,
688         SAMPLER_BINDING = 0x8919,
689         RGB10_A2UI = 0x906F,
690         TEXTURE_SWIZZLE_R = 0x8E42,
691         TEXTURE_SWIZZLE_G = 0x8E43,
692         TEXTURE_SWIZZLE_B = 0x8E44,
693         TEXTURE_SWIZZLE_A = 0x8E45,
694         GREEN = 0x1904,
695         BLUE = 0x1905,
696         INT_2_10_10_10_REV = 0x8D9F,
697         TRANSFORM_FEEDBACK = 0x8E22,
698         TRANSFORM_FEEDBACK_PAUSED = 0x8E23,
699         TRANSFORM_FEEDBACK_ACTIVE = 0x8E24,
700         TRANSFORM_FEEDBACK_BINDING = 0x8E25,
701         COMPRESSED_R11_EAC = 0x9270,
702         COMPRESSED_SIGNED_R11_EAC = 0x9271,
703         COMPRESSED_RG11_EAC = 0x9272,
704         COMPRESSED_SIGNED_RG11_EAC = 0x9273,
705         COMPRESSED_RGB8_ETC2 = 0x9274,
706         COMPRESSED_SRGB8_ETC2 = 0x9275,
707         COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276,
708         COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277,
709         COMPRESSED_RGBA8_ETC2_EAC = 0x9278,
710         COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279,
711         TEXTURE_IMMUTABLE_FORMAT = 0x912F,
712         MAX_ELEMENT_INDEX = 0x8D6B,
713         NUM_SAMPLE_COUNTS = 0x9380,
714         TEXTURE_IMMUTABLE_LEVELS = 0x82DF
715     };
716
717     // Context creation attributes.
718     struct Attributes {
719         Attributes()
720             : alpha(true)
721             , depth(true)
722             , stencil(false)
723             , antialias(true)
724             , premultipliedAlpha(true)
725             , preserveDrawingBuffer(false)
726             , noExtensions(false)
727             , shareResources(true)
728             , preferDiscreteGPU(false)
729             , forceSoftwareRenderer(false)
730             , devicePixelRatio(1)
731         {
732         }
733
734         bool alpha;
735         bool depth;
736         bool stencil;
737         bool antialias;
738         bool premultipliedAlpha;
739         bool preserveDrawingBuffer;
740         bool noExtensions;
741         bool shareResources;
742         bool preferDiscreteGPU;
743         bool forceSoftwareRenderer;
744         float devicePixelRatio;
745     };
746
747     enum RenderStyle {
748         RenderOffscreen,
749         RenderDirectlyToHostWindow,
750         RenderToCurrentGLContext
751     };
752
753     class ContextLostCallback {
754     public:
755         virtual void onContextLost() = 0;
756         virtual ~ContextLostCallback() {}
757     };
758
759     class ErrorMessageCallback {
760     public:
761         virtual void onErrorMessage(const String& message, GC3Dint id) = 0;
762         virtual ~ErrorMessageCallback() { }
763     };
764
765     void setContextLostCallback(std::unique_ptr<ContextLostCallback>);
766     void setErrorMessageCallback(std::unique_ptr<ErrorMessageCallback>);
767
768     static PassRefPtr<GraphicsContext3D> create(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
769     static PassRefPtr<GraphicsContext3D> createForCurrentGLContext();
770     ~GraphicsContext3D();
771
772 #if PLATFORM(COCOA)
773     PlatformGraphicsContext3D platformGraphicsContext3D() const { return m_contextObj; }
774     Platform3DObject platformTexture() const { return m_compositorTexture; }
775     CALayer* platformLayer() const { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); }
776 #else
777     PlatformGraphicsContext3D platformGraphicsContext3D();
778     Platform3DObject platformTexture() const;
779     PlatformLayer* platformLayer() const;
780 #endif
781
782     bool makeContextCurrent();
783     void setWebGLContext(WebGLRenderingContextBase* base) { m_webglContext = base; }
784
785     // With multisampling on, blit from multisampleFBO to regular FBO.
786     void prepareTexture();
787
788     // Equivalent to ::glTexImage2D(). Allows pixels==0 with no allocation.
789     void texImage2DDirect(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels);
790
791     // Helper to texImage2D with pixel==0 case: pixels are initialized to 0.
792     // Return true if no GL error is synthesized.
793     // By default, alignment is 4, the OpenGL default setting.
794     bool texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint alignment = 4);
795
796     bool isGLES2Compliant() const;
797
798     //----------------------------------------------------------------------
799     // Helpers for texture uploading and pixel readback.
800     //
801
802     // Computes the components per pixel and bytes per component
803     // for the given format and type combination. Returns false if
804     // either was an invalid enum.
805     static bool computeFormatAndTypeParameters(GC3Denum format,
806                                                GC3Denum type,
807                                                unsigned int* componentsPerPixel,
808                                                unsigned int* bytesPerComponent);
809
810     // Computes the image size in bytes. If paddingInBytes is not null, padding
811     // is also calculated in return. Returns NO_ERROR if succeed, otherwise
812     // return the suggested GL error indicating the cause of the failure:
813     //   INVALID_VALUE if width/height is negative or overflow happens.
814     //   INVALID_ENUM if format/type is illegal.
815     static GC3Denum computeImageSizeInBytes(GC3Denum format,
816                                      GC3Denum type,
817                                      GC3Dsizei width,
818                                      GC3Dsizei height,
819                                      GC3Dint alignment,
820                                      unsigned int* imageSizeInBytes,
821                                      unsigned int* paddingInBytes);
822
823     // Extracts the contents of the given ImageData into the passed Vector,
824     // packing the pixel data according to the given format and type,
825     // and obeying the flipY and premultiplyAlpha flags. Returns true
826     // upon success.
827     static bool extractImageData(ImageData*,
828                           GC3Denum format,
829                           GC3Denum type,
830                           bool flipY,
831                           bool premultiplyAlpha,
832                           Vector<uint8_t>& data);
833
834     // Helper function which extracts the user-supplied texture
835     // data, applying the flipY and premultiplyAlpha parameters.
836     // If the data is not tightly packed according to the passed
837     // unpackAlignment, the output data will be tightly packed.
838     // Returns true if successful, false if any error occurred.
839     static bool extractTextureData(unsigned int width, unsigned int height,
840                             GC3Denum format, GC3Denum type,
841                             unsigned int unpackAlignment,
842                             bool flipY, bool premultiplyAlpha,
843                             const void* pixels,
844                             Vector<uint8_t>& data);
845
846
847     // Attempt to enumerate all possible native image formats to
848     // reduce the amount of temporary allocations during texture
849     // uploading. This enum must be public because it is accessed
850     // by non-member functions.
851     enum DataFormat {
852         DataFormatRGBA8 = 0,
853         DataFormatRGBA16Little,
854         DataFormatRGBA16Big,
855         DataFormatRGBA16F,
856         DataFormatRGBA32F,
857         DataFormatRGB8,
858         DataFormatRGB16Little,
859         DataFormatRGB16Big,
860         DataFormatRGB16F,
861         DataFormatRGB32F,
862         DataFormatBGR8,
863         DataFormatBGRA8,
864         DataFormatBGRA16Little,
865         DataFormatBGRA16Big,
866         DataFormatARGB8,
867         DataFormatARGB16Little,
868         DataFormatARGB16Big,
869         DataFormatABGR8,
870         DataFormatRGBA5551,
871         DataFormatRGBA4444,
872         DataFormatRGB565,
873         DataFormatR8,
874         DataFormatR16Little,
875         DataFormatR16Big,
876         DataFormatR16F,
877         DataFormatR32F,
878         DataFormatRA8,
879         DataFormatRA16Little,
880         DataFormatRA16Big,
881         DataFormatRA16F,
882         DataFormatRA32F,
883         DataFormatAR8,
884         DataFormatAR16Little,
885         DataFormatAR16Big,
886         DataFormatA8,
887         DataFormatA16Little,
888         DataFormatA16Big,
889         DataFormatA16F,
890         DataFormatA32F,
891         DataFormatNumFormats
892     };
893
894     ALWAYS_INLINE static bool hasAlpha(DataFormat format)
895     {
896         return format == GraphicsContext3D::DataFormatA8
897             || format == GraphicsContext3D::DataFormatA16F
898             || format == GraphicsContext3D::DataFormatA32F
899             || format == GraphicsContext3D::DataFormatRA8
900             || format == GraphicsContext3D::DataFormatAR8
901             || format == GraphicsContext3D::DataFormatRA16F
902             || format == GraphicsContext3D::DataFormatRA32F
903             || format == GraphicsContext3D::DataFormatRGBA8
904             || format == GraphicsContext3D::DataFormatBGRA8
905             || format == GraphicsContext3D::DataFormatARGB8
906             || format == GraphicsContext3D::DataFormatABGR8
907             || format == GraphicsContext3D::DataFormatRGBA16F
908             || format == GraphicsContext3D::DataFormatRGBA32F
909             || format == GraphicsContext3D::DataFormatRGBA4444
910             || format == GraphicsContext3D::DataFormatRGBA5551;
911     }
912
913     ALWAYS_INLINE static bool hasColor(DataFormat format)
914     {
915         return format == GraphicsContext3D::DataFormatRGBA8
916             || format == GraphicsContext3D::DataFormatRGBA16F
917             || format == GraphicsContext3D::DataFormatRGBA32F
918             || format == GraphicsContext3D::DataFormatRGB8
919             || format == GraphicsContext3D::DataFormatRGB16F
920             || format == GraphicsContext3D::DataFormatRGB32F
921             || format == GraphicsContext3D::DataFormatBGR8
922             || format == GraphicsContext3D::DataFormatBGRA8
923             || format == GraphicsContext3D::DataFormatARGB8
924             || format == GraphicsContext3D::DataFormatABGR8
925             || format == GraphicsContext3D::DataFormatRGBA5551
926             || format == GraphicsContext3D::DataFormatRGBA4444
927             || format == GraphicsContext3D::DataFormatRGB565
928             || format == GraphicsContext3D::DataFormatR8
929             || format == GraphicsContext3D::DataFormatR16F
930             || format == GraphicsContext3D::DataFormatR32F
931             || format == GraphicsContext3D::DataFormatRA8
932             || format == GraphicsContext3D::DataFormatRA16F
933             || format == GraphicsContext3D::DataFormatRA32F
934             || format == GraphicsContext3D::DataFormatAR8;
935     }
936
937     // Check if the format is one of the formats from the ImageData or DOM elements.
938     // The formats from ImageData is always RGBA8.
939     // 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.
940     static ALWAYS_INLINE bool srcFormatComesFromDOMElementOrImageData(DataFormat SrcFormat)
941     {
942 #if USE(CG)
943 #if CPU(BIG_ENDIAN)
944     return SrcFormat == DataFormatRGBA8 || SrcFormat == DataFormatARGB8 || SrcFormat == DataFormatRGB8
945         || SrcFormat == DataFormatRA8 || SrcFormat == DataFormatAR8 || SrcFormat == DataFormatR8 || SrcFormat == DataFormatA8;
946 #else
947     // That LITTLE_ENDIAN case has more possible formats than BIG_ENDIAN case is because some decoded image data is actually big endian
948     // even on little endian architectures.
949     return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatABGR8 || SrcFormat == DataFormatBGR8
950         || SrcFormat == DataFormatRGBA8 || SrcFormat == DataFormatARGB8 || SrcFormat == DataFormatRGB8
951         || SrcFormat == DataFormatR8 || SrcFormat == DataFormatA8
952         || SrcFormat == DataFormatRA8 || SrcFormat == DataFormatAR8;
953 #endif
954 #else
955     return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatRGBA8;
956 #endif
957     }
958
959     //----------------------------------------------------------------------
960     // Entry points for WebGL.
961     //
962
963     void activeTexture(GC3Denum texture);
964     void attachShader(Platform3DObject program, Platform3DObject shader);
965     void bindAttribLocation(Platform3DObject, GC3Duint index, const String& name);
966     void bindBuffer(GC3Denum target, Platform3DObject);
967     void bindFramebuffer(GC3Denum target, Platform3DObject);
968     void bindRenderbuffer(GC3Denum target, Platform3DObject);
969     void bindTexture(GC3Denum target, Platform3DObject);
970     void blendColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
971     void blendEquation(GC3Denum mode);
972     void blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha);
973     void blendFunc(GC3Denum sfactor, GC3Denum dfactor);
974     void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha);
975
976     void bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage);
977     void bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage);
978     void bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data);
979
980     GC3Denum checkFramebufferStatus(GC3Denum target);
981     void clear(GC3Dbitfield mask);
982     void clearColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
983     void clearDepth(GC3Dclampf depth);
984     void clearStencil(GC3Dint s);
985     void colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dboolean blue, GC3Dboolean alpha);
986     void compileShader(Platform3DObject);
987
988     void compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Dsizei imageSize, const void* data);
989     void compressedTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Dsizei imageSize, const void* data);
990     void copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border);
991     void copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
992     void cullFace(GC3Denum mode);
993     void depthFunc(GC3Denum func);
994     void depthMask(GC3Dboolean flag);
995     void depthRange(GC3Dclampf zNear, GC3Dclampf zFar);
996     void detachShader(Platform3DObject, Platform3DObject);
997     void disable(GC3Denum cap);
998     void disableVertexAttribArray(GC3Duint index);
999     void drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count);
1000     void drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset);
1001
1002     void enable(GC3Denum cap);
1003     void enableVertexAttribArray(GC3Duint index);
1004     void finish();
1005     void flush();
1006     void framebufferRenderbuffer(GC3Denum target, GC3Denum attachment, GC3Denum renderbuffertarget, Platform3DObject);
1007     void framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum textarget, Platform3DObject, GC3Dint level);
1008     void frontFace(GC3Denum mode);
1009     void generateMipmap(GC3Denum target);
1010
1011     bool getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo&);
1012     bool getActiveAttribImpl(Platform3DObject program, GC3Duint index, ActiveInfo&);
1013     bool getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo&);
1014     bool getActiveUniformImpl(Platform3DObject program, GC3Duint index, ActiveInfo&);
1015     void getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders);
1016     GC3Dint getAttribLocation(Platform3DObject, const String& name);
1017     void getBooleanv(GC3Denum pname, GC3Dboolean* value);
1018     void getBufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
1019     Attributes getContextAttributes();
1020     GC3Denum getError();
1021     void getFloatv(GC3Denum pname, GC3Dfloat* value);
1022     void getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum pname, GC3Dint* value);
1023     void getIntegerv(GC3Denum pname, GC3Dint* value);
1024     void getInteger64v(GC3Denum pname, GC3Dint64* value);
1025     void getProgramiv(Platform3DObject program, GC3Denum pname, GC3Dint* value);
1026     void getNonBuiltInActiveSymbolCount(Platform3DObject program, GC3Denum pname, GC3Dint* value);
1027     String getProgramInfoLog(Platform3DObject);
1028     String getUnmangledInfoLog(Platform3DObject[2], GC3Dsizei, const String&);
1029     void getRenderbufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
1030     void getShaderiv(Platform3DObject, GC3Denum pname, GC3Dint* value);
1031     String getShaderInfoLog(Platform3DObject);
1032     void getShaderPrecisionFormat(GC3Denum shaderType, GC3Denum precisionType, GC3Dint* range, GC3Dint* precision);
1033     String getShaderSource(Platform3DObject);
1034     String getString(GC3Denum name);
1035     void getTexParameterfv(GC3Denum target, GC3Denum pname, GC3Dfloat* value);
1036     void getTexParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
1037     void getUniformfv(Platform3DObject program, GC3Dint location, GC3Dfloat* value);
1038     void getUniformiv(Platform3DObject program, GC3Dint location, GC3Dint* value);
1039     GC3Dint getUniformLocation(Platform3DObject, const String& name);
1040     void getVertexAttribfv(GC3Duint index, GC3Denum pname, GC3Dfloat* value);
1041     void getVertexAttribiv(GC3Duint index, GC3Denum pname, GC3Dint* value);
1042     GC3Dsizeiptr getVertexAttribOffset(GC3Duint index, GC3Denum pname);
1043
1044     void hint(GC3Denum target, GC3Denum mode);
1045     GC3Dboolean isBuffer(Platform3DObject);
1046     GC3Dboolean isEnabled(GC3Denum cap);
1047     GC3Dboolean isFramebuffer(Platform3DObject);
1048     GC3Dboolean isProgram(Platform3DObject);
1049     GC3Dboolean isRenderbuffer(Platform3DObject);
1050     GC3Dboolean isShader(Platform3DObject);
1051     GC3Dboolean isTexture(Platform3DObject);
1052     void lineWidth(GC3Dfloat);
1053     void linkProgram(Platform3DObject);
1054     void pixelStorei(GC3Denum pname, GC3Dint param);
1055     void polygonOffset(GC3Dfloat factor, GC3Dfloat units);
1056
1057     void readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data);
1058
1059     void releaseShaderCompiler();
1060
1061     void renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height);
1062     void sampleCoverage(GC3Dclampf value, GC3Dboolean invert);
1063     void scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
1064     void shaderSource(Platform3DObject, const String& string);
1065     void stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask);
1066     void stencilFuncSeparate(GC3Denum face, GC3Denum func, GC3Dint ref, GC3Duint mask);
1067     void stencilMask(GC3Duint mask);
1068     void stencilMaskSeparate(GC3Denum face, GC3Duint mask);
1069     void stencilOp(GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
1070     void stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
1071
1072     bool texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels);
1073     void texParameterf(GC3Denum target, GC3Denum pname, GC3Dfloat param);
1074     void texParameteri(GC3Denum target, GC3Denum pname, GC3Dint param);
1075     void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels);
1076
1077     void uniform1f(GC3Dint location, GC3Dfloat x);
1078     void uniform1fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
1079     void uniform1i(GC3Dint location, GC3Dint x);
1080     void uniform1iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
1081     void uniform2f(GC3Dint location, GC3Dfloat x, GC3Dfloat y);
1082     void uniform2fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
1083     void uniform2i(GC3Dint location, GC3Dint x, GC3Dint y);
1084     void uniform2iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
1085     void uniform3f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
1086     void uniform3fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
1087     void uniform3i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z);
1088     void uniform3iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
1089     void uniform4f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
1090     void uniform4fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
1091     void uniform4i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w);
1092     void uniform4iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
1093     void uniformMatrix2fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
1094     void uniformMatrix3fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
1095     void uniformMatrix4fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
1096
1097     void useProgram(Platform3DObject);
1098     void validateProgram(Platform3DObject);
1099     bool checkVaryingsPacking(Platform3DObject vertexShader, Platform3DObject fragmentShader) const;
1100     bool precisionsMatch(Platform3DObject vertexShader, Platform3DObject fragmentShader) const;
1101
1102     void vertexAttrib1f(GC3Duint index, GC3Dfloat x);
1103     void vertexAttrib1fv(GC3Duint index, GC3Dfloat* values);
1104     void vertexAttrib2f(GC3Duint index, GC3Dfloat x, GC3Dfloat y);
1105     void vertexAttrib2fv(GC3Duint index, GC3Dfloat* values);
1106     void vertexAttrib3f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
1107     void vertexAttrib3fv(GC3Duint index, GC3Dfloat* values);
1108     void vertexAttrib4f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
1109     void vertexAttrib4fv(GC3Duint index, GC3Dfloat* values);
1110     void vertexAttribPointer(GC3Duint index, GC3Dint size, GC3Denum type, GC3Dboolean normalized,
1111                              GC3Dsizei stride, GC3Dintptr offset);
1112
1113     void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
1114
1115     void reshape(int width, int height);
1116
1117     void drawArraysInstanced(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount);
1118     void drawElementsInstanced(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount);
1119     void vertexAttribDivisor(GC3Duint index, GC3Duint divisor);
1120
1121     // VertexArrayOject calls
1122     Platform3DObject createVertexArray();
1123     void deleteVertexArray(Platform3DObject);
1124     GC3Dboolean isVertexArray(Platform3DObject);
1125     void bindVertexArray(Platform3DObject);
1126
1127 #if PLATFORM(GTK) || PLATFORM(EFL) || USE(CAIRO)
1128     void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
1129                        int canvasWidth, int canvasHeight, PlatformContextCairo* context);
1130 #elif USE(CG)
1131     void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, GraphicsContext&);
1132 #endif
1133
1134     void markContextChanged();
1135     void markLayerComposited();
1136     bool layerComposited() const;
1137     void forceContextLost();
1138
1139     void paintRenderingResultsToCanvas(ImageBuffer*);
1140     PassRefPtr<ImageData> paintRenderingResultsToImageData();
1141     bool paintCompositedResultsToCanvas(ImageBuffer*);
1142
1143 #if PLATFORM(IOS)
1144     void endPaint();
1145 #endif
1146
1147     // Support for buffer creation and deletion
1148     Platform3DObject createBuffer();
1149     Platform3DObject createFramebuffer();
1150     Platform3DObject createProgram();
1151     Platform3DObject createRenderbuffer();
1152     Platform3DObject createShader(GC3Denum);
1153     Platform3DObject createTexture();
1154
1155     void deleteBuffer(Platform3DObject);
1156     void deleteFramebuffer(Platform3DObject);
1157     void deleteProgram(Platform3DObject);
1158     void deleteRenderbuffer(Platform3DObject);
1159     void deleteShader(Platform3DObject);
1160     void deleteTexture(Platform3DObject);
1161
1162     // Synthesizes an OpenGL error which will be returned from a
1163     // later call to getError. This is used to emulate OpenGL ES
1164     // 2.0 behavior on the desktop and to enforce additional error
1165     // checking mandated by WebGL.
1166     //
1167     // Per the behavior of glGetError, this stores at most one
1168     // instance of any given error, and returns them from calls to
1169     // getError in the order they were added.
1170     void synthesizeGLError(GC3Denum error);
1171
1172     // Read real OpenGL errors, and move them to the synthetic
1173     // error list. Return true if at least one error is moved.
1174     bool moveErrorsToSyntheticErrorList();
1175
1176     // Support for extensions. Returns a non-null object, though not
1177     // all methods it contains may necessarily be supported on the
1178     // current hardware. Must call Extensions3D::supports() to
1179     // determine this.
1180     Extensions3D* getExtensions();
1181
1182     IntSize getInternalFramebufferSize() const;
1183
1184     static unsigned getClearBitsByAttachmentType(GC3Denum);
1185     static unsigned getClearBitsByFormat(GC3Denum);
1186
1187     enum ChannelBits {
1188         ChannelRed = 1,
1189         ChannelGreen = 2,
1190         ChannelBlue = 4,
1191         ChannelAlpha = 8,
1192         ChannelDepth = 16,
1193         ChannelStencil = 32,
1194         ChannelRGB = ChannelRed | ChannelGreen | ChannelBlue,
1195         ChannelRGBA = ChannelRGB | ChannelAlpha,
1196     };
1197
1198     static unsigned getChannelBitsByFormat(GC3Denum);
1199
1200     // Possible alpha operations that may need to occur during
1201     // pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must
1202     // be removed.
1203     enum AlphaOp {
1204         AlphaDoNothing = 0,
1205         AlphaDoPremultiply = 1,
1206         AlphaDoUnmultiply = 2
1207     };
1208
1209     enum ImageHtmlDomSource {
1210         HtmlDomImage = 0,
1211         HtmlDomCanvas = 1,
1212         HtmlDomVideo = 2,
1213         HtmlDomNone = 3
1214     };
1215
1216     // Packs the contents of the given Image which is passed in |pixels| into the passed Vector
1217     // according to the given format and type, and obeying the flipY and AlphaOp flags.
1218     // Returns true upon success.
1219     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);
1220
1221     class ImageExtractor {
1222     public:
1223         ImageExtractor(Image*, ImageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
1224
1225         // Each platform must provide an implementation of this method to deallocate or release resources
1226         // associated with the image if needed.
1227         ~ImageExtractor();
1228
1229         bool extractSucceeded() { return m_extractSucceeded; }
1230         const void* imagePixelData() { return m_imagePixelData; }
1231         unsigned imageWidth() { return m_imageWidth; }
1232         unsigned imageHeight() { return m_imageHeight; }
1233         DataFormat imageSourceFormat() { return m_imageSourceFormat; }
1234         AlphaOp imageAlphaOp() { return m_alphaOp; }
1235         unsigned imageSourceUnpackAlignment() { return m_imageSourceUnpackAlignment; }
1236         ImageHtmlDomSource imageHtmlDomSource() { return m_imageHtmlDomSource; }
1237     private:
1238         // Each platform must provide an implementation of this method.
1239         // Extracts the image and keeps track of its status, such as width, height, Source Alignment, format and AlphaOp etc,
1240         // needs to lock the resources or relevant data if needed and returns true upon success
1241         bool extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
1242
1243 #if USE(CAIRO)
1244         ImageSource* m_decoder;
1245         RefPtr<cairo_surface_t> m_imageSurface;
1246 #elif USE(CG)
1247         CGImageRef m_cgImage;
1248         RetainPtr<CGImageRef> m_decodedImage;
1249         RetainPtr<CFDataRef> m_pixelData;
1250         std::unique_ptr<uint8_t[]> m_formalizedRGBA8Data;
1251 #endif
1252         Image* m_image;
1253         ImageHtmlDomSource m_imageHtmlDomSource;
1254         bool m_extractSucceeded;
1255         const void* m_imagePixelData;
1256         unsigned m_imageWidth;
1257         unsigned m_imageHeight;
1258         DataFormat m_imageSourceFormat;
1259         AlphaOp m_alphaOp;
1260         unsigned m_imageSourceUnpackAlignment;
1261     };
1262
1263 private:
1264     GraphicsContext3D(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
1265     static int numActiveContexts;
1266     static int GPUCheckCounter;
1267
1268     // Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel
1269     // data into the specified OpenGL destination format and type.
1270     // A sourceUnpackAlignment of zero indicates that the source
1271     // data is tightly packed. Non-zero values may take a slow path.
1272     // Destination data will have no gaps between rows.
1273     static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned destinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool flipY);
1274
1275     // Take into account the user's requested context creation attributes,
1276     // in particular stencil and antialias, and determine which could or
1277     // could not be honored based on the capabilities of the OpenGL
1278     // implementation.
1279     void validateDepthStencil(const char* packedDepthStencilExtension);
1280     void validateAttributes();
1281     
1282     // Call to make during draw calls to check on the GPU's status.
1283     void checkGPUStatusIfNecessary();
1284
1285     // Read rendering results into a pixel array with the same format as the
1286     // backbuffer.
1287     void readRenderingResults(unsigned char* pixels, int pixelsSize);
1288     void readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels);
1289
1290 #if PLATFORM(IOS)
1291     bool setRenderbufferStorageFromDrawable(GC3Dsizei width, GC3Dsizei height);
1292 #endif
1293
1294     bool reshapeFBOs(const IntSize&);
1295     void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
1296     void attachDepthAndStencilBufferIfNeeded(GLuint internalDepthStencilFormat, int width, int height);
1297 #if PLATFORM(EFL) && USE(GRAPHICS_SURFACE)
1298     void createGraphicsSurfaces(const IntSize&);
1299 #endif
1300
1301     int m_currentWidth, m_currentHeight;
1302     bool isResourceSafe();
1303
1304 #if PLATFORM(COCOA)
1305     RetainPtr<WebGLLayer> m_webGLLayer;
1306     PlatformGraphicsContext3D m_contextObj;
1307 #endif
1308
1309 #if PLATFORM(WIN) && USE(CA)
1310     RefPtr<PlatformCALayer> m_webGLLayer;
1311 #endif
1312
1313     struct SymbolInfo {
1314         SymbolInfo()
1315             : type(0)
1316             , size(0)
1317             , precision(GL_NONE) // Invalid precision.
1318             , staticUse(0)
1319         {
1320         }
1321
1322         SymbolInfo(GC3Denum type, int size, const String& mappedName, sh::GLenum precision, int staticUse)
1323             : type(type)
1324             , size(size)
1325             , mappedName(mappedName)
1326             , precision(precision)
1327             , staticUse(staticUse)
1328         {
1329         }
1330
1331         bool operator==(SymbolInfo& other) const
1332         {
1333             return type == other.type && size == other.size && mappedName == other.mappedName;
1334         }
1335
1336         GC3Denum type;
1337         int size;
1338         String mappedName;
1339         sh::GLenum precision;
1340         int staticUse;
1341     };
1342
1343     typedef HashMap<String, SymbolInfo> ShaderSymbolMap;
1344
1345     struct ShaderSourceEntry {
1346         GC3Denum type;
1347         String source;
1348         String translatedSource;
1349         String log;
1350         bool isValid;
1351         ShaderSymbolMap attributeMap;
1352         ShaderSymbolMap uniformMap;
1353         ShaderSymbolMap varyingMap;
1354         ShaderSourceEntry()
1355             : type(VERTEX_SHADER)
1356             , isValid(false)
1357         {
1358         }
1359         
1360         ShaderSymbolMap& symbolMap(enum ANGLEShaderSymbolType symbolType)
1361         {
1362             ASSERT(symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE || symbolType == SHADER_SYMBOL_TYPE_UNIFORM || symbolType == SHADER_SYMBOL_TYPE_VARYING);
1363             if (symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE)
1364                 return attributeMap;
1365             if (symbolType == SHADER_SYMBOL_TYPE_VARYING)
1366                 return varyingMap;
1367             return uniformMap;
1368         }
1369     };
1370
1371     typedef HashMap<Platform3DObject, ShaderSourceEntry> ShaderSourceMap;
1372     ShaderSourceMap m_shaderSourceMap;
1373
1374     struct ActiveShaderSymbolCounts {
1375         Vector<GC3Dint> filteredToActualAttributeIndexMap;
1376         Vector<GC3Dint> filteredToActualUniformIndexMap;
1377
1378         ActiveShaderSymbolCounts()
1379         {
1380         }
1381
1382         GC3Dint countForType(GC3Denum activeType)
1383         {
1384             ASSERT(activeType == ACTIVE_ATTRIBUTES || activeType == ACTIVE_UNIFORMS);
1385             if (activeType == ACTIVE_ATTRIBUTES)
1386                 return filteredToActualAttributeIndexMap.size();
1387
1388             return filteredToActualUniformIndexMap.size();
1389         }
1390     };
1391     typedef HashMap<Platform3DObject, ActiveShaderSymbolCounts> ShaderProgramSymbolCountMap;
1392     ShaderProgramSymbolCountMap m_shaderProgramSymbolCountMap;
1393
1394     typedef HashMap<String, String> HashedSymbolMap;
1395     HashedSymbolMap m_possiblyUnusedAttributeMap;
1396
1397     String mappedSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
1398     String mappedSymbolName(Platform3DObject shaders[2], size_t count, const String& name);
1399     String originalSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
1400
1401     ANGLEWebKitBridge m_compiler;
1402
1403     std::unique_ptr<ShaderNameHash> nameHashMapForShaders;
1404
1405 #if ((PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN)) && USE(OPENGL_ES_2))
1406     friend class Extensions3DOpenGLES;
1407     std::unique_ptr<Extensions3DOpenGLES> m_extensions;
1408 #else
1409     friend class Extensions3DOpenGL;
1410     std::unique_ptr<Extensions3DOpenGL> m_extensions;
1411 #endif
1412     friend class Extensions3DOpenGLCommon;
1413
1414     Attributes m_attrs;
1415     RenderStyle m_renderStyle;
1416     Vector<Vector<float>> m_vertexArray;
1417
1418     GC3Duint m_texture;
1419     GC3Duint m_compositorTexture;
1420     GC3Duint m_fbo;
1421 #if USE(COORDINATED_GRAPHICS_THREADED)
1422     GC3Duint m_compositorFBO;
1423 #endif
1424
1425     GC3Duint m_depthBuffer;
1426     GC3Duint m_stencilBuffer;
1427     GC3Duint m_depthStencilBuffer;
1428
1429     bool m_layerComposited;
1430     GC3Duint m_internalColorFormat;
1431
1432     struct GraphicsContext3DState {
1433         GraphicsContext3DState()
1434             : boundFBO(0)
1435             , activeTexture(GraphicsContext3D::TEXTURE0)
1436             , boundTexture0(0)
1437         { }
1438
1439         GC3Duint boundFBO;
1440         GC3Denum activeTexture;
1441         GC3Duint boundTexture0;
1442     };
1443
1444     GraphicsContext3DState m_state;
1445
1446     // For multisampling
1447     GC3Duint m_multisampleFBO;
1448     GC3Duint m_multisampleDepthStencilBuffer;
1449     GC3Duint m_multisampleColorBuffer;
1450
1451     // Errors raised by synthesizeGLError().
1452     ListHashSet<GC3Denum> m_syntheticErrors;
1453
1454     friend class GraphicsContext3DPrivate;
1455     std::unique_ptr<GraphicsContext3DPrivate> m_private;
1456     
1457     WebGLRenderingContextBase* m_webglContext;
1458 };
1459
1460 } // namespace WebCore
1461
1462 #endif // GraphicsContext3D_h