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