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