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