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