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