[EFL][WK2] Enable WebGL
[WebKit-https.git] / Source / WebCore / platform / graphics / GraphicsContext3D.h
1 /*
2  * Copyright (C) 2009 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 COMPUTER, 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 COMPUTER, 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 "IntRect.h"
30 #include "GraphicsTypes3D.h"
31 #include "PlatformLayer.h"
32 #include <wtf/HashMap.h>
33 #include <wtf/ListHashSet.h>
34 #include <wtf/Noncopyable.h>
35 #include <wtf/RefCounted.h>
36 #include <wtf/text/WTFString.h>
37
38 // FIXME: Find a better way to avoid the name confliction for NO_ERROR.
39 #if ((PLATFORM(CHROMIUM) && OS(WINDOWS)) || PLATFORM(WIN) || (PLATFORM(QT) && OS(WINDOWS)))
40 #undef NO_ERROR
41 #elif PLATFORM(GTK)
42 // This define is from the X11 headers, but it's used below, so we must undefine it.
43 #undef VERSION
44 #endif
45
46 #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(BLACKBERRY)
47 #include "ANGLEWebKitBridge.h"
48 #endif
49
50 #if PLATFORM(MAC)
51 #include <OpenGL/OpenGL.h>
52 #include <wtf/RetainPtr.h>
53 OBJC_CLASS CALayer;
54 OBJC_CLASS WebGLLayer;
55 #elif PLATFORM(QT)
56 QT_BEGIN_NAMESPACE
57 class QPainter;
58 class QRect;
59 class QGLWidget;
60 class QGLContext;
61 class QOpenGLContext;
62 class QSurface;
63 QT_END_NAMESPACE
64 #elif PLATFORM(GTK) || PLATFORM(EFL)
65 typedef unsigned int GLuint;
66 #endif
67
68 #if PLATFORM(MAC)
69 typedef CGLContextObj PlatformGraphicsContext3D;
70 #elif PLATFORM(QT)
71 typedef QOpenGLContext* PlatformGraphicsContext3D;
72 typedef QSurface* PlatformGraphicsSurface3D;
73 #else
74 typedef void* PlatformGraphicsContext3D;
75 typedef void* PlatformGraphicsSurface3D;
76 #endif
77
78 #if (PLATFORM(CHROMIUM) || PLATFORM(BLACKBERRY)) && USE(SKIA)
79 class GrContext;
80 #endif
81
82 // These are currently the same among all implementations.
83 const PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
84 const Platform3DObject NullPlatform3DObject = 0;
85
86 #if USE(CG)
87 #include <CoreGraphics/CGContext.h>
88 #endif
89
90 namespace WebCore {
91 class DrawingBuffer;
92 class Extensions3D;
93 #if USE(OPENGL_ES_2)
94 class Extensions3DOpenGLES;
95 #else
96 class Extensions3DOpenGL;
97 #endif
98 #if PLATFORM(QT)
99 class Extensions3DQt;
100 #endif
101 class HostWindow;
102 class Image;
103 class ImageBuffer;
104 class ImageData;
105 class IntRect;
106 class IntSize;
107 #if USE(CAIRO)
108 class PlatformContextCairo;
109 #elif PLATFORM(BLACKBERRY)
110 class GraphicsContext;
111 #endif
112
113 struct ActiveInfo {
114     String name;
115     GC3Denum type;
116     GC3Dint size;
117 };
118
119 class GraphicsContext3DPrivate;
120
121 class GraphicsContext3D : public RefCounted<GraphicsContext3D> {
122 public:
123     enum {
124         DEPTH_BUFFER_BIT = 0x00000100,
125         STENCIL_BUFFER_BIT = 0x00000400,
126         COLOR_BUFFER_BIT = 0x00004000,
127         POINTS = 0x0000,
128         LINES = 0x0001,
129         LINE_LOOP = 0x0002,
130         LINE_STRIP = 0x0003,
131         TRIANGLES = 0x0004,
132         TRIANGLE_STRIP = 0x0005,
133         TRIANGLE_FAN = 0x0006,
134         ZERO = 0,
135         ONE = 1,
136         SRC_COLOR = 0x0300,
137         ONE_MINUS_SRC_COLOR = 0x0301,
138         SRC_ALPHA = 0x0302,
139         ONE_MINUS_SRC_ALPHA = 0x0303,
140         DST_ALPHA = 0x0304,
141         ONE_MINUS_DST_ALPHA = 0x0305,
142         DST_COLOR = 0x0306,
143         ONE_MINUS_DST_COLOR = 0x0307,
144         SRC_ALPHA_SATURATE = 0x0308,
145         FUNC_ADD = 0x8006,
146         BLEND_EQUATION = 0x8009,
147         BLEND_EQUATION_RGB = 0x8009,
148         BLEND_EQUATION_ALPHA = 0x883D,
149         FUNC_SUBTRACT = 0x800A,
150         FUNC_REVERSE_SUBTRACT = 0x800B,
151         BLEND_DST_RGB = 0x80C8,
152         BLEND_SRC_RGB = 0x80C9,
153         BLEND_DST_ALPHA = 0x80CA,
154         BLEND_SRC_ALPHA = 0x80CB,
155         CONSTANT_COLOR = 0x8001,
156         ONE_MINUS_CONSTANT_COLOR = 0x8002,
157         CONSTANT_ALPHA = 0x8003,
158         ONE_MINUS_CONSTANT_ALPHA = 0x8004,
159         BLEND_COLOR = 0x8005,
160         ARRAY_BUFFER = 0x8892,
161         ELEMENT_ARRAY_BUFFER = 0x8893,
162         ARRAY_BUFFER_BINDING = 0x8894,
163         ELEMENT_ARRAY_BUFFER_BINDING = 0x8895,
164         STREAM_DRAW = 0x88E0,
165         STATIC_DRAW = 0x88E4,
166         DYNAMIC_DRAW = 0x88E8,
167         BUFFER_SIZE = 0x8764,
168         BUFFER_USAGE = 0x8765,
169         CURRENT_VERTEX_ATTRIB = 0x8626,
170         FRONT = 0x0404,
171         BACK = 0x0405,
172         FRONT_AND_BACK = 0x0408,
173         TEXTURE_2D = 0x0DE1,
174         CULL_FACE = 0x0B44,
175         BLEND = 0x0BE2,
176         DITHER = 0x0BD0,
177         STENCIL_TEST = 0x0B90,
178         DEPTH_TEST = 0x0B71,
179         SCISSOR_TEST = 0x0C11,
180         POLYGON_OFFSET_FILL = 0x8037,
181         SAMPLE_ALPHA_TO_COVERAGE = 0x809E,
182         SAMPLE_COVERAGE = 0x80A0,
183         NO_ERROR = 0,
184         INVALID_ENUM = 0x0500,
185         INVALID_VALUE = 0x0501,
186         INVALID_OPERATION = 0x0502,
187         OUT_OF_MEMORY = 0x0505,
188         CW = 0x0900,
189         CCW = 0x0901,
190         LINE_WIDTH = 0x0B21,
191         ALIASED_POINT_SIZE_RANGE = 0x846D,
192         ALIASED_LINE_WIDTH_RANGE = 0x846E,
193         CULL_FACE_MODE = 0x0B45,
194         FRONT_FACE = 0x0B46,
195         DEPTH_RANGE = 0x0B70,
196         DEPTH_WRITEMASK = 0x0B72,
197         DEPTH_CLEAR_VALUE = 0x0B73,
198         DEPTH_FUNC = 0x0B74,
199         STENCIL_CLEAR_VALUE = 0x0B91,
200         STENCIL_FUNC = 0x0B92,
201         STENCIL_FAIL = 0x0B94,
202         STENCIL_PASS_DEPTH_FAIL = 0x0B95,
203         STENCIL_PASS_DEPTH_PASS = 0x0B96,
204         STENCIL_REF = 0x0B97,
205         STENCIL_VALUE_MASK = 0x0B93,
206         STENCIL_WRITEMASK = 0x0B98,
207         STENCIL_BACK_FUNC = 0x8800,
208         STENCIL_BACK_FAIL = 0x8801,
209         STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802,
210         STENCIL_BACK_PASS_DEPTH_PASS = 0x8803,
211         STENCIL_BACK_REF = 0x8CA3,
212         STENCIL_BACK_VALUE_MASK = 0x8CA4,
213         STENCIL_BACK_WRITEMASK = 0x8CA5,
214         VIEWPORT = 0x0BA2,
215         SCISSOR_BOX = 0x0C10,
216         COLOR_CLEAR_VALUE = 0x0C22,
217         COLOR_WRITEMASK = 0x0C23,
218         UNPACK_ALIGNMENT = 0x0CF5,
219         PACK_ALIGNMENT = 0x0D05,
220         MAX_TEXTURE_SIZE = 0x0D33,
221         MAX_VIEWPORT_DIMS = 0x0D3A,
222         SUBPIXEL_BITS = 0x0D50,
223         RED_BITS = 0x0D52,
224         GREEN_BITS = 0x0D53,
225         BLUE_BITS = 0x0D54,
226         ALPHA_BITS = 0x0D55,
227         DEPTH_BITS = 0x0D56,
228         STENCIL_BITS = 0x0D57,
229         POLYGON_OFFSET_UNITS = 0x2A00,
230         POLYGON_OFFSET_FACTOR = 0x8038,
231         TEXTURE_BINDING_2D = 0x8069,
232         SAMPLE_BUFFERS = 0x80A8,
233         SAMPLES = 0x80A9,
234         SAMPLE_COVERAGE_VALUE = 0x80AA,
235         SAMPLE_COVERAGE_INVERT = 0x80AB,
236         NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2,
237         COMPRESSED_TEXTURE_FORMATS = 0x86A3,
238         DONT_CARE = 0x1100,
239         FASTEST = 0x1101,
240         NICEST = 0x1102,
241         GENERATE_MIPMAP_HINT = 0x8192,
242         BYTE = 0x1400,
243         UNSIGNED_BYTE = 0x1401,
244         SHORT = 0x1402,
245         UNSIGNED_SHORT = 0x1403,
246         INT = 0x1404,
247         UNSIGNED_INT = 0x1405,
248         FLOAT = 0x1406,
249         FIXED = 0x140C,
250         DEPTH_COMPONENT = 0x1902,
251         ALPHA = 0x1906,
252         RGB = 0x1907,
253         RGBA = 0x1908,
254         BGRA = 0x80E1,
255         LUMINANCE = 0x1909,
256         LUMINANCE_ALPHA = 0x190A,
257         UNSIGNED_SHORT_4_4_4_4 = 0x8033,
258         UNSIGNED_SHORT_5_5_5_1 = 0x8034,
259         UNSIGNED_SHORT_5_6_5 = 0x8363,
260         FRAGMENT_SHADER = 0x8B30,
261         VERTEX_SHADER = 0x8B31,
262         MAX_VERTEX_ATTRIBS = 0x8869,
263         MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB,
264         MAX_VARYING_VECTORS = 0x8DFC,
265         MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D,
266         MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C,
267         MAX_TEXTURE_IMAGE_UNITS = 0x8872,
268         MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD,
269         SHADER_TYPE = 0x8B4F,
270         DELETE_STATUS = 0x8B80,
271         LINK_STATUS = 0x8B82,
272         VALIDATE_STATUS = 0x8B83,
273         ATTACHED_SHADERS = 0x8B85,
274         ACTIVE_UNIFORMS = 0x8B86,
275         ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
276         ACTIVE_ATTRIBUTES = 0x8B89,
277         ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
278         SHADING_LANGUAGE_VERSION = 0x8B8C,
279         CURRENT_PROGRAM = 0x8B8D,
280         NEVER = 0x0200,
281         LESS = 0x0201,
282         EQUAL = 0x0202,
283         LEQUAL = 0x0203,
284         GREATER = 0x0204,
285         NOTEQUAL = 0x0205,
286         GEQUAL = 0x0206,
287         ALWAYS = 0x0207,
288         KEEP = 0x1E00,
289         REPLACE = 0x1E01,
290         INCR = 0x1E02,
291         DECR = 0x1E03,
292         INVERT = 0x150A,
293         INCR_WRAP = 0x8507,
294         DECR_WRAP = 0x8508,
295         VENDOR = 0x1F00,
296         RENDERER = 0x1F01,
297         VERSION = 0x1F02,
298         EXTENSIONS = 0x1F03,
299         NEAREST = 0x2600,
300         LINEAR = 0x2601,
301         NEAREST_MIPMAP_NEAREST = 0x2700,
302         LINEAR_MIPMAP_NEAREST = 0x2701,
303         NEAREST_MIPMAP_LINEAR = 0x2702,
304         LINEAR_MIPMAP_LINEAR = 0x2703,
305         TEXTURE_MAG_FILTER = 0x2800,
306         TEXTURE_MIN_FILTER = 0x2801,
307         TEXTURE_WRAP_S = 0x2802,
308         TEXTURE_WRAP_T = 0x2803,
309         TEXTURE = 0x1702,
310         TEXTURE_CUBE_MAP = 0x8513,
311         TEXTURE_BINDING_CUBE_MAP = 0x8514,
312         TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515,
313         TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516,
314         TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517,
315         TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518,
316         TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519,
317         TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A,
318         MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C,
319         TEXTURE0 = 0x84C0,
320         TEXTURE1 = 0x84C1,
321         TEXTURE2 = 0x84C2,
322         TEXTURE3 = 0x84C3,
323         TEXTURE4 = 0x84C4,
324         TEXTURE5 = 0x84C5,
325         TEXTURE6 = 0x84C6,
326         TEXTURE7 = 0x84C7,
327         TEXTURE8 = 0x84C8,
328         TEXTURE9 = 0x84C9,
329         TEXTURE10 = 0x84CA,
330         TEXTURE11 = 0x84CB,
331         TEXTURE12 = 0x84CC,
332         TEXTURE13 = 0x84CD,
333         TEXTURE14 = 0x84CE,
334         TEXTURE15 = 0x84CF,
335         TEXTURE16 = 0x84D0,
336         TEXTURE17 = 0x84D1,
337         TEXTURE18 = 0x84D2,
338         TEXTURE19 = 0x84D3,
339         TEXTURE20 = 0x84D4,
340         TEXTURE21 = 0x84D5,
341         TEXTURE22 = 0x84D6,
342         TEXTURE23 = 0x84D7,
343         TEXTURE24 = 0x84D8,
344         TEXTURE25 = 0x84D9,
345         TEXTURE26 = 0x84DA,
346         TEXTURE27 = 0x84DB,
347         TEXTURE28 = 0x84DC,
348         TEXTURE29 = 0x84DD,
349         TEXTURE30 = 0x84DE,
350         TEXTURE31 = 0x84DF,
351         ACTIVE_TEXTURE = 0x84E0,
352         REPEAT = 0x2901,
353         CLAMP_TO_EDGE = 0x812F,
354         MIRRORED_REPEAT = 0x8370,
355         FLOAT_VEC2 = 0x8B50,
356         FLOAT_VEC3 = 0x8B51,
357         FLOAT_VEC4 = 0x8B52,
358         INT_VEC2 = 0x8B53,
359         INT_VEC3 = 0x8B54,
360         INT_VEC4 = 0x8B55,
361         BOOL = 0x8B56,
362         BOOL_VEC2 = 0x8B57,
363         BOOL_VEC3 = 0x8B58,
364         BOOL_VEC4 = 0x8B59,
365         FLOAT_MAT2 = 0x8B5A,
366         FLOAT_MAT3 = 0x8B5B,
367         FLOAT_MAT4 = 0x8B5C,
368         SAMPLER_2D = 0x8B5E,
369         SAMPLER_CUBE = 0x8B60,
370         VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622,
371         VERTEX_ATTRIB_ARRAY_SIZE = 0x8623,
372         VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624,
373         VERTEX_ATTRIB_ARRAY_TYPE = 0x8625,
374         VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A,
375         VERTEX_ATTRIB_ARRAY_POINTER = 0x8645,
376         VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F,
377         COMPILE_STATUS = 0x8B81,
378         INFO_LOG_LENGTH = 0x8B84,
379         SHADER_SOURCE_LENGTH = 0x8B88,
380         SHADER_COMPILER = 0x8DFA,
381         SHADER_BINARY_FORMATS = 0x8DF8,
382         NUM_SHADER_BINARY_FORMATS = 0x8DF9,
383         LOW_FLOAT = 0x8DF0,
384         MEDIUM_FLOAT = 0x8DF1,
385         HIGH_FLOAT = 0x8DF2,
386         LOW_INT = 0x8DF3,
387         MEDIUM_INT = 0x8DF4,
388         HIGH_INT = 0x8DF5,
389         FRAMEBUFFER = 0x8D40,
390         RENDERBUFFER = 0x8D41,
391         RGBA4 = 0x8056,
392         RGB5_A1 = 0x8057,
393         RGB565 = 0x8D62,
394         DEPTH_COMPONENT16 = 0x81A5,
395         STENCIL_INDEX = 0x1901,
396         STENCIL_INDEX8 = 0x8D48,
397         DEPTH_STENCIL = 0x84F9,
398         UNSIGNED_INT_24_8 = 0x84FA,
399         DEPTH24_STENCIL8 = 0x88F0,
400         RENDERBUFFER_WIDTH = 0x8D42,
401         RENDERBUFFER_HEIGHT = 0x8D43,
402         RENDERBUFFER_INTERNAL_FORMAT = 0x8D44,
403         RENDERBUFFER_RED_SIZE = 0x8D50,
404         RENDERBUFFER_GREEN_SIZE = 0x8D51,
405         RENDERBUFFER_BLUE_SIZE = 0x8D52,
406         RENDERBUFFER_ALPHA_SIZE = 0x8D53,
407         RENDERBUFFER_DEPTH_SIZE = 0x8D54,
408         RENDERBUFFER_STENCIL_SIZE = 0x8D55,
409         FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0,
410         FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1,
411         FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2,
412         FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3,
413         COLOR_ATTACHMENT0 = 0x8CE0,
414         DEPTH_ATTACHMENT = 0x8D00,
415         STENCIL_ATTACHMENT = 0x8D20,
416         DEPTH_STENCIL_ATTACHMENT = 0x821A,
417         NONE = 0,
418         FRAMEBUFFER_COMPLETE = 0x8CD5,
419         FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6,
420         FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7,
421         FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9,
422         FRAMEBUFFER_UNSUPPORTED = 0x8CDD,
423         FRAMEBUFFER_BINDING = 0x8CA6,
424         RENDERBUFFER_BINDING = 0x8CA7,
425         MAX_RENDERBUFFER_SIZE = 0x84E8,
426         INVALID_FRAMEBUFFER_OPERATION = 0x0506,
427
428         // WebGL-specific enums
429         UNPACK_FLIP_Y_WEBGL = 0x9240,
430         UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241,
431         CONTEXT_LOST_WEBGL = 0x9242,
432         UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
433         BROWSER_DEFAULT_WEBGL = 0x9244
434     };
435
436     // Context creation attributes.
437     struct Attributes {
438         Attributes()
439             : alpha(true)
440             , depth(true)
441             , stencil(false)
442             , antialias(true)
443             , premultipliedAlpha(true)
444             , preserveDrawingBuffer(false)
445             , noExtensions(false)
446             , shareResources(true)
447             , preferDiscreteGPU(false)
448         {
449         }
450
451         bool alpha;
452         bool depth;
453         bool stencil;
454         bool antialias;
455         bool premultipliedAlpha;
456         bool preserveDrawingBuffer;
457         bool noExtensions;
458         bool shareResources;
459         bool preferDiscreteGPU;
460     };
461
462     enum RenderStyle {
463         RenderOffscreen,
464         RenderDirectlyToHostWindow,
465         RenderToCurrentGLContext
466     };
467
468     class ContextLostCallback {
469     public:
470         virtual void onContextLost() = 0;
471         virtual ~ContextLostCallback() {}
472     };
473
474     class ErrorMessageCallback {
475     public:
476         virtual void onErrorMessage(const String& message, GC3Dint id) = 0;
477         virtual ~ErrorMessageCallback() { }
478     };
479
480     void setContextLostCallback(PassOwnPtr<ContextLostCallback>);
481     void setErrorMessageCallback(PassOwnPtr<ErrorMessageCallback>);
482
483     static PassRefPtr<GraphicsContext3D> create(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
484     static PassRefPtr<GraphicsContext3D> createForCurrentGLContext();
485     ~GraphicsContext3D();
486
487 #if PLATFORM(MAC)
488     PlatformGraphicsContext3D platformGraphicsContext3D() const { return m_contextObj; }
489     Platform3DObject platformTexture() const { return m_compositorTexture; }
490     CALayer* platformLayer() const { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); }
491 #elif PLATFORM(CHROMIUM) || PLATFORM(BLACKBERRY)
492     PlatformGraphicsContext3D platformGraphicsContext3D() const;
493     Platform3DObject platformTexture() const;
494 #if USE(SKIA)
495     GrContext* grContext();
496 #endif
497 #if USE(ACCELERATED_COMPOSITING)
498     PlatformLayer* platformLayer() const;
499 #endif
500 #elif PLATFORM(QT)
501     PlatformGraphicsContext3D platformGraphicsContext3D();
502     Platform3DObject platformTexture() const;
503 #if USE(ACCELERATED_COMPOSITING)
504     PlatformLayer* platformLayer() const;
505 #endif
506 #elif PLATFORM(GTK)
507     PlatformGraphicsContext3D platformGraphicsContext3D();
508     Platform3DObject platformTexture() const { return m_texture; }
509 #if USE(ACCELERATED_COMPOSITING)
510     PlatformLayer* platformLayer() const;
511 #endif
512 #elif PLATFORM(EFL)
513     PlatformGraphicsContext3D platformGraphicsContext3D();
514     Platform3DObject platformTexture() const { return m_texture; }
515 #if USE(ACCELERATED_COMPOSITING)
516     PlatformLayer* platformLayer() const;
517 #endif
518 #else
519     PlatformGraphicsContext3D platformGraphicsContext3D() const { return NullPlatformGraphicsContext3D; }
520     Platform3DObject platformTexture() const { return NullPlatform3DObject; }
521 #if USE(ACCELERATED_COMPOSITING)
522     PlatformLayer* platformLayer() const { return 0; }
523 #endif
524 #endif
525     bool makeContextCurrent();
526
527 #if PLATFORM(MAC) || PLATFORM(CHROMIUM) || PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(BLACKBERRY)
528     // With multisampling on, blit from multisampleFBO to regular FBO.
529     void prepareTexture();
530 #endif
531
532     // Equivalent to ::glTexImage2D(). Allows pixels==0 with no allocation.
533     void texImage2DDirect(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels);
534
535     // Helper to texImage2D with pixel==0 case: pixels are initialized to 0.
536     // Return true if no GL error is synthesized.
537     // By default, alignment is 4, the OpenGL default setting.
538     bool texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint alignment = 4);
539
540     bool isGLES2Compliant() const;
541
542     //----------------------------------------------------------------------
543     // Helpers for texture uploading and pixel readback.
544     //
545
546     // Computes the components per pixel and bytes per component
547     // for the given format and type combination. Returns false if
548     // either was an invalid enum.
549     static bool computeFormatAndTypeParameters(GC3Denum format,
550                                                GC3Denum type,
551                                                unsigned int* componentsPerPixel,
552                                                unsigned int* bytesPerComponent);
553
554     // Computes the image size in bytes. If paddingInBytes is not null, padding
555     // is also calculated in return. Returns NO_ERROR if succeed, otherwise
556     // return the suggested GL error indicating the cause of the failure:
557     //   INVALID_VALUE if width/height is negative or overflow happens.
558     //   INVALID_ENUM if format/type is illegal.
559     static GC3Denum computeImageSizeInBytes(GC3Denum format,
560                                      GC3Denum type,
561                                      GC3Dsizei width,
562                                      GC3Dsizei height,
563                                      GC3Dint alignment,
564                                      unsigned int* imageSizeInBytes,
565                                      unsigned int* paddingInBytes);
566
567     // Extracts the contents of the given Image into the passed Vector,
568     // packing the pixel data according to the given format and type,
569     // and obeying the flipY, premultiplyAlpha, and ignoreGammaAndColorProfile
570     // flags. Returns true upon success.
571     static bool extractImageData(Image*,
572                           GC3Denum format,
573                           GC3Denum type,
574                           bool flipY,
575                           bool premultiplyAlpha,
576                           bool ignoreGammaAndColorProfile,
577                           Vector<uint8_t>& data);
578
579     // Extracts the contents of the given ImageData into the passed Vector,
580     // packing the pixel data according to the given format and type,
581     // and obeying the flipY and premultiplyAlpha flags. Returns true
582     // upon success.
583     static bool extractImageData(ImageData*,
584                           GC3Denum format,
585                           GC3Denum type,
586                           bool flipY,
587                           bool premultiplyAlpha,
588                           Vector<uint8_t>& data);
589
590     // Helper function which extracts the user-supplied texture
591     // data, applying the flipY and premultiplyAlpha parameters.
592     // If the data is not tightly packed according to the passed
593     // unpackAlignment, the output data will be tightly packed.
594     // Returns true if successful, false if any error occurred.
595     static bool extractTextureData(unsigned int width, unsigned int height,
596                             GC3Denum format, GC3Denum type,
597                             unsigned int unpackAlignment,
598                             bool flipY, bool premultiplyAlpha,
599                             const void* pixels,
600                             Vector<uint8_t>& data);
601
602     // Flips the given image data vertically, in-place.
603     static void flipVertically(void* imageData,
604                         unsigned int width,
605                         unsigned int height,
606                         unsigned int bytesPerPixel,
607                         unsigned int unpackAlignment);
608
609     // Attempt to enumerate all possible native image formats to
610     // reduce the amount of temporary allocations during texture
611     // uploading. This enum must be public because it is accessed
612     // by non-member functions.
613     enum SourceDataFormat {
614         SourceFormatRGBA8 = 0,
615         SourceFormatRGBA16Little,
616         SourceFormatRGBA16Big,
617         SourceFormatRGBA32F,
618         SourceFormatRGB8,
619         SourceFormatRGB16Little,
620         SourceFormatRGB16Big,
621         SourceFormatRGB32F,
622         SourceFormatBGR8,
623         SourceFormatBGRA8,
624         SourceFormatBGRA16Little,
625         SourceFormatBGRA16Big,
626         SourceFormatARGB8,
627         SourceFormatARGB16Little,
628         SourceFormatARGB16Big,
629         SourceFormatABGR8,
630         SourceFormatRGBA5551,
631         SourceFormatRGBA4444,
632         SourceFormatRGB565,
633         SourceFormatR8,
634         SourceFormatR16Little,
635         SourceFormatR16Big,
636         SourceFormatR32F,
637         SourceFormatRA8,
638         SourceFormatRA16Little,
639         SourceFormatRA16Big,
640         SourceFormatRA32F,
641         SourceFormatAR8,
642         SourceFormatAR16Little,
643         SourceFormatAR16Big,
644         SourceFormatA8,
645         SourceFormatA16Little,
646         SourceFormatA16Big,
647         SourceFormatA32F,
648         SourceFormatNumFormats
649     };
650
651     //----------------------------------------------------------------------
652     // Entry points for WebGL.
653     //
654
655     void activeTexture(GC3Denum texture);
656     void attachShader(Platform3DObject program, Platform3DObject shader);
657     void bindAttribLocation(Platform3DObject, GC3Duint index, const String& name);
658     void bindBuffer(GC3Denum target, Platform3DObject);
659     void bindFramebuffer(GC3Denum target, Platform3DObject);
660     void bindRenderbuffer(GC3Denum target, Platform3DObject);
661     void bindTexture(GC3Denum target, Platform3DObject);
662     void blendColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
663     void blendEquation(GC3Denum mode);
664     void blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha);
665     void blendFunc(GC3Denum sfactor, GC3Denum dfactor);
666     void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha);
667
668     void bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage);
669     void bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage);
670     void bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data);
671
672     GC3Denum checkFramebufferStatus(GC3Denum target);
673     void clear(GC3Dbitfield mask);
674     void clearColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
675     void clearDepth(GC3Dclampf depth);
676     void clearStencil(GC3Dint s);
677     void colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dboolean blue, GC3Dboolean alpha);
678     void compileShader(Platform3DObject);
679
680     void compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Dsizei imageSize, const void* data);
681     void compressedTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Dsizei imageSize, const void* data);
682     void copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border);
683     void copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
684     void cullFace(GC3Denum mode);
685     void depthFunc(GC3Denum func);
686     void depthMask(GC3Dboolean flag);
687     void depthRange(GC3Dclampf zNear, GC3Dclampf zFar);
688     void detachShader(Platform3DObject, Platform3DObject);
689     void disable(GC3Denum cap);
690     void disableVertexAttribArray(GC3Duint index);
691     void drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count);
692     void drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset);
693
694     void enable(GC3Denum cap);
695     void enableVertexAttribArray(GC3Duint index);
696     void finish();
697     void flush();
698     void framebufferRenderbuffer(GC3Denum target, GC3Denum attachment, GC3Denum renderbuffertarget, Platform3DObject);
699     void framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum textarget, Platform3DObject, GC3Dint level);
700     void frontFace(GC3Denum mode);
701     void generateMipmap(GC3Denum target);
702
703     bool getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo&);
704     bool getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo&);
705     void getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders);
706     GC3Dint getAttribLocation(Platform3DObject, const String& name);
707     void getBooleanv(GC3Denum pname, GC3Dboolean* value);
708     void getBufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
709     Attributes getContextAttributes();
710     GC3Denum getError();
711     void getFloatv(GC3Denum pname, GC3Dfloat* value);
712     void getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum pname, GC3Dint* value);
713     void getIntegerv(GC3Denum pname, GC3Dint* value);
714     void getProgramiv(Platform3DObject program, GC3Denum pname, GC3Dint* value);
715     String getProgramInfoLog(Platform3DObject);
716     void getRenderbufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
717     void getShaderiv(Platform3DObject, GC3Denum pname, GC3Dint* value);
718     String getShaderInfoLog(Platform3DObject);
719     void getShaderPrecisionFormat(GC3Denum shaderType, GC3Denum precisionType, GC3Dint* range, GC3Dint* precision);
720     String getShaderSource(Platform3DObject);
721     String getString(GC3Denum name);
722     void getTexParameterfv(GC3Denum target, GC3Denum pname, GC3Dfloat* value);
723     void getTexParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
724     void getUniformfv(Platform3DObject program, GC3Dint location, GC3Dfloat* value);
725     void getUniformiv(Platform3DObject program, GC3Dint location, GC3Dint* value);
726     GC3Dint getUniformLocation(Platform3DObject, const String& name);
727     void getVertexAttribfv(GC3Duint index, GC3Denum pname, GC3Dfloat* value);
728     void getVertexAttribiv(GC3Duint index, GC3Denum pname, GC3Dint* value);
729     GC3Dsizeiptr getVertexAttribOffset(GC3Duint index, GC3Denum pname);
730
731     void hint(GC3Denum target, GC3Denum mode);
732     GC3Dboolean isBuffer(Platform3DObject);
733     GC3Dboolean isEnabled(GC3Denum cap);
734     GC3Dboolean isFramebuffer(Platform3DObject);
735     GC3Dboolean isProgram(Platform3DObject);
736     GC3Dboolean isRenderbuffer(Platform3DObject);
737     GC3Dboolean isShader(Platform3DObject);
738     GC3Dboolean isTexture(Platform3DObject);
739     void lineWidth(GC3Dfloat);
740     void linkProgram(Platform3DObject);
741     void pixelStorei(GC3Denum pname, GC3Dint param);
742     void polygonOffset(GC3Dfloat factor, GC3Dfloat units);
743
744     void readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data);
745
746     void releaseShaderCompiler();
747
748     void renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height);
749     void sampleCoverage(GC3Dclampf value, GC3Dboolean invert);
750     void scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
751     void shaderSource(Platform3DObject, const String& string);
752     void stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask);
753     void stencilFuncSeparate(GC3Denum face, GC3Denum func, GC3Dint ref, GC3Duint mask);
754     void stencilMask(GC3Duint mask);
755     void stencilMaskSeparate(GC3Denum face, GC3Duint mask);
756     void stencilOp(GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
757     void stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
758
759     bool texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels);
760     void texParameterf(GC3Denum target, GC3Denum pname, GC3Dfloat param);
761     void texParameteri(GC3Denum target, GC3Denum pname, GC3Dint param);
762     void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels);
763
764     void uniform1f(GC3Dint location, GC3Dfloat x);
765     void uniform1fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
766     void uniform1i(GC3Dint location, GC3Dint x);
767     void uniform1iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
768     void uniform2f(GC3Dint location, GC3Dfloat x, GC3Dfloat y);
769     void uniform2fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
770     void uniform2i(GC3Dint location, GC3Dint x, GC3Dint y);
771     void uniform2iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
772     void uniform3f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
773     void uniform3fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
774     void uniform3i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z);
775     void uniform3iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
776     void uniform4f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
777     void uniform4fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
778     void uniform4i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w);
779     void uniform4iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
780     void uniformMatrix2fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
781     void uniformMatrix3fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
782     void uniformMatrix4fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
783
784     void useProgram(Platform3DObject);
785     void validateProgram(Platform3DObject);
786
787     void vertexAttrib1f(GC3Duint index, GC3Dfloat x);
788     void vertexAttrib1fv(GC3Duint index, GC3Dfloat* values);
789     void vertexAttrib2f(GC3Duint index, GC3Dfloat x, GC3Dfloat y);
790     void vertexAttrib2fv(GC3Duint index, GC3Dfloat* values);
791     void vertexAttrib3f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
792     void vertexAttrib3fv(GC3Duint index, GC3Dfloat* values);
793     void vertexAttrib4f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
794     void vertexAttrib4fv(GC3Duint index, GC3Dfloat* values);
795     void vertexAttribPointer(GC3Duint index, GC3Dint size, GC3Denum type, GC3Dboolean normalized,
796                              GC3Dsizei stride, GC3Dintptr offset);
797
798     void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
799
800     void reshape(int width, int height);
801
802 #if USE(CG)
803     static void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
804                               int canvasWidth, int canvasHeight, CGContextRef);
805 #elif PLATFORM(GTK) || PLATFORM(EFL)
806     void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
807                        int canvasWidth, int canvasHeight, PlatformContextCairo* context);
808 #elif PLATFORM(QT)
809     void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
810                        int canvasWidth, int canvasHeight, QPainter* context);
811 #elif PLATFORM(BLACKBERRY)
812     void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
813                        int canvasWidth, int canvasHeight, GraphicsContext*);
814 #endif
815
816     void markContextChanged();
817     void markLayerComposited();
818     bool layerComposited() const;
819
820     void paintRenderingResultsToCanvas(ImageBuffer*, DrawingBuffer*);
821     PassRefPtr<ImageData> paintRenderingResultsToImageData(DrawingBuffer*);
822     bool paintCompositedResultsToCanvas(ImageBuffer*);
823
824 #if PLATFORM(BLACKBERRY)
825     bool paintsIntoCanvasBuffer() const;
826 #endif
827
828     // Support for buffer creation and deletion
829     Platform3DObject createBuffer();
830     Platform3DObject createFramebuffer();
831     Platform3DObject createProgram();
832     Platform3DObject createRenderbuffer();
833     Platform3DObject createShader(GC3Denum);
834     Platform3DObject createTexture();
835
836     void deleteBuffer(Platform3DObject);
837     void deleteFramebuffer(Platform3DObject);
838     void deleteProgram(Platform3DObject);
839     void deleteRenderbuffer(Platform3DObject);
840     void deleteShader(Platform3DObject);
841     void deleteTexture(Platform3DObject);
842
843     // Synthesizes an OpenGL error which will be returned from a
844     // later call to getError. This is used to emulate OpenGL ES
845     // 2.0 behavior on the desktop and to enforce additional error
846     // checking mandated by WebGL.
847     //
848     // Per the behavior of glGetError, this stores at most one
849     // instance of any given error, and returns them from calls to
850     // getError in the order they were added.
851     void synthesizeGLError(GC3Denum error);
852
853     // Support for extensions. Returns a non-null object, though not
854     // all methods it contains may necessarily be supported on the
855     // current hardware. Must call Extensions3D::supports() to
856     // determine this.
857     Extensions3D* getExtensions();
858
859     IntSize getInternalFramebufferSize() const;
860
861     static unsigned getClearBitsByAttachmentType(GC3Denum);
862     static unsigned getClearBitsByFormat(GC3Denum);
863
864     enum ChannelBits {
865         ChannelRed = 1,
866         ChannelGreen = 2,
867         ChannelBlue = 4,
868         ChannelAlpha = 8,
869         ChannelDepth = 16,
870         ChannelStencil = 32,
871         ChannelRGB = ChannelRed | ChannelGreen | ChannelBlue,
872         ChannelRGBA = ChannelRGB | ChannelAlpha,
873     };
874
875     static unsigned getChannelBitsByFormat(GC3Denum);
876
877   private:
878     GraphicsContext3D(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
879
880     // Each platform must provide an implementation of this method.
881     //
882     // Gets the data for the given Image into outputVector in the
883     // format specified by the (OpenGL-style) format and type
884     // arguments. Despite the fact that the outputVector contains
885     // uint8_t, if the format and type specify packed pixels, then
886     // it will essentially contain uint16_t after the extraction
887     // process.
888     //
889     // If premultiplyAlpha is true, the alpha channel, if any,
890     // will be multiplied into the color channels during the
891     // extraction process. This premultiplication occurs before
892     // any packing of pixel data.
893     //
894     // If ignoreGammaAndColorProfile is true, gamma correction and ICC
895     // profile won't be applied.
896     //
897     // No vertical flip of the image data is performed by this
898     // method.
899     static bool getImageData(Image*,
900                       GC3Denum format,
901                       GC3Denum type,
902                       bool premultiplyAlpha,
903                       bool ignoreGammaAndColorProfile,
904                       Vector<uint8_t>& outputVector);
905
906     // Possible alpha operations that may need to occur during
907     // pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must
908     // be removed.
909     enum AlphaOp {
910         AlphaDoNothing = 0,
911         AlphaDoPremultiply = 1,
912         AlphaDoUnmultiply = 2
913     };
914
915     // Helper for getImageData which implements packing of pixel
916     // data into the specified OpenGL destination format and type.
917     // A sourceUnpackAlignment of zero indicates that the source
918     // data is tightly packed. Non-zero values may take a slow path.
919     // Destination data will have no gaps between rows.
920     static bool packPixels(const uint8_t* sourceData,
921                     SourceDataFormat sourceDataFormat,
922                     unsigned int width,
923                     unsigned int height,
924                     unsigned int sourceUnpackAlignment,
925                     unsigned int destinationFormat,
926                     unsigned int destinationType,
927                     AlphaOp alphaOp,
928                     void* destinationData);
929
930 #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(BLACKBERRY)
931     // Take into account the user's requested context creation attributes,
932     // in particular stencil and antialias, and determine which could or
933     // could not be honored based on the capabilities of the OpenGL
934     // implementation.
935     void validateDepthStencil(const char* packedDepthStencilExtension);
936     void validateAttributes();
937
938     // Read rendering results into a pixel array with the same format as the
939     // backbuffer.
940     void readRenderingResults(unsigned char* pixels, int pixelsSize);
941     void readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels);
942 #endif
943
944 #if PLATFORM(BLACKBERRY)
945     void logFrameBufferStatus(int line);
946     void readPixelsIMG(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data);
947 #endif
948
949     bool reshapeFBOs(const IntSize&);
950     void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
951 #if (PLATFORM(QT) || PLATFORM(EFL)) && USE(GRAPHICS_SURFACE)
952     void createGraphicsSurfaces(const IntSize&);
953 #endif
954
955     int m_currentWidth, m_currentHeight;
956     bool isResourceSafe();
957
958 #if PLATFORM(MAC)
959     CGLContextObj m_contextObj;
960     RetainPtr<WebGLLayer> m_webGLLayer;
961 #elif PLATFORM(BLACKBERRY)
962 #if USE(ACCELERATED_COMPOSITING)
963     RefPtr<PlatformLayer> m_compositingLayer;
964 #endif
965     void* m_context;
966 #endif
967
968 #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(BLACKBERRY)
969     struct SymbolInfo {
970         SymbolInfo()
971             : type(0)
972             , size(0)
973         {
974         }
975
976         SymbolInfo(GC3Denum type, int size, const String& mappedName)
977             : type(type)
978             , size(size)
979             , mappedName(mappedName)
980         {
981         }
982
983         bool operator==(SymbolInfo& other) const
984         {
985             return type == other.type && size == other.size && mappedName == other.mappedName;
986         }
987
988         GC3Denum type;
989         int size;
990         String mappedName;
991     };
992
993     typedef HashMap<String, SymbolInfo> ShaderSymbolMap;
994
995     struct ShaderSourceEntry {
996         GC3Denum type;
997         String source;
998         String translatedSource;
999         String log;
1000         bool isValid;
1001         ShaderSymbolMap attributeMap;
1002         ShaderSymbolMap uniformMap;
1003         ShaderSourceEntry()
1004             : type(VERTEX_SHADER)
1005             , isValid(false)
1006         {
1007         }
1008         
1009         ShaderSymbolMap& symbolMap(ANGLEShaderSymbolType symbolType)
1010         {
1011             ASSERT(symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE || symbolType == SHADER_SYMBOL_TYPE_UNIFORM);
1012             if (symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE)
1013                 return attributeMap;
1014             return uniformMap;
1015         }
1016     };
1017
1018     typedef HashMap<Platform3DObject, ShaderSourceEntry> ShaderSourceMap;
1019     ShaderSourceMap m_shaderSourceMap;
1020
1021     String mappedSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
1022     String originalSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
1023
1024     ANGLEWebKitBridge m_compiler;
1025 #endif
1026
1027 #if PLATFORM(BLACKBERRY) || (PLATFORM(QT) && defined(QT_OPENGL_ES_2)) || (PLATFORM(GTK) && USE(OPENGL_ES_2))
1028     friend class Extensions3DOpenGLES;
1029     OwnPtr<Extensions3DOpenGLES> m_extensions;
1030 #elif !PLATFORM(CHROMIUM)
1031     friend class Extensions3DOpenGL;
1032     OwnPtr<Extensions3DOpenGL> m_extensions;
1033 #endif
1034     friend class Extensions3DOpenGLCommon;
1035
1036     Attributes m_attrs;
1037     RenderStyle m_renderStyle;
1038     Vector<Vector<float> > m_vertexArray;
1039
1040     GC3Duint m_texture;
1041 #if !PLATFORM(BLACKBERRY)
1042     GC3Duint m_compositorTexture;
1043 #endif
1044     GC3Duint m_fbo;
1045
1046 #if !PLATFORM(BLACKBERRY)
1047     GC3Duint m_depthBuffer;
1048     GC3Duint m_stencilBuffer;
1049 #endif
1050     GC3Duint m_depthStencilBuffer;
1051
1052     bool m_layerComposited;
1053     GC3Duint m_internalColorFormat;
1054
1055     // For tracking which FBO/texture is bound
1056     GC3Duint m_boundFBO;
1057     GC3Denum m_activeTexture;
1058     GC3Duint m_boundTexture0;
1059
1060     // For multisampling
1061     GC3Duint m_multisampleFBO;
1062     GC3Duint m_multisampleDepthStencilBuffer;
1063     GC3Duint m_multisampleColorBuffer;
1064
1065     // Errors raised by synthesizeGLError().
1066     ListHashSet<GC3Denum> m_syntheticErrors;
1067
1068 #if PLATFORM(BLACKBERRY)
1069     bool m_isImaginationHardware;
1070 #endif
1071
1072 #if !PLATFORM(BLACKBERRY)
1073     friend class GraphicsContext3DPrivate;
1074     OwnPtr<GraphicsContext3DPrivate> m_private;
1075 #endif
1076 };
1077
1078 } // namespace WebCore
1079
1080 #endif // GraphicsContext3D_h