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