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