2 * Copyright (C) 2009 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef GraphicsContext3D_h
27 #define GraphicsContext3D_h
30 #include "GraphicsLayer.h"
31 #include "GraphicsTypes3D.h"
32 #include "PlatformString.h"
33 #include <wtf/HashMap.h>
34 #include <wtf/ListHashSet.h>
35 #include <wtf/Noncopyable.h>
36 #include <wtf/RefCounted.h>
38 // FIXME: Find a better way to avoid the name confliction for NO_ERROR.
39 #if ((PLATFORM(CHROMIUM) && OS(WINDOWS)) || PLATFORM(WIN) || (PLATFORM(QT) && OS(WINDOWS)))
42 // This define is from the X11 headers, but it's used below, so we must undefine it.
46 #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT)
47 #include "ANGLEWebKitBridge.h"
51 #include <OpenGL/OpenGL.h>
52 #include <wtf/RetainPtr.h>
54 OBJC_CLASS WebGLLayer;
64 #elif PLATFORM(GTK) || PLATFORM(EFL)
65 typedef unsigned int GLuint;
69 typedef CGLContextObj PlatformGraphicsContext3D;
72 typedef QOpenGLContext* PlatformGraphicsContext3D;
73 typedef QSurface* PlatformGraphicsSurface3D;
75 typedef QGLContext* PlatformGraphicsContext3D;
76 typedef QGLWidget* PlatformGraphicsSurface3D;
79 typedef void* PlatformGraphicsContext3D;
82 #if PLATFORM(CHROMIUM) && USE(SKIA)
86 // These are currently the same among all implementations.
87 const PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
88 const Platform3DObject NullPlatform3DObject = 0;
91 #include <CoreGraphics/CGContext.h>
97 #if USE(OPENGL_ES_2) && !OS(TIZEN)
98 class Extensions3DOpenGLES;
100 class Extensions3DOpenGL;
103 class Extensions3DQt;
112 class PlatformContextCairo;
113 #elif PLATFORM(BLACKBERRY)
114 class GraphicsContext;
123 // FIXME: ideally this would be used on all platforms.
124 #if PLATFORM(CHROMIUM) || PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
125 class GraphicsContext3DInternal;
128 class GraphicsContext3D : public RefCounted<GraphicsContext3D> {
131 DEPTH_BUFFER_BIT = 0x00000100,
132 STENCIL_BUFFER_BIT = 0x00000400,
133 COLOR_BUFFER_BIT = 0x00004000,
139 TRIANGLE_STRIP = 0x0005,
140 TRIANGLE_FAN = 0x0006,
144 ONE_MINUS_SRC_COLOR = 0x0301,
146 ONE_MINUS_SRC_ALPHA = 0x0303,
148 ONE_MINUS_DST_ALPHA = 0x0305,
150 ONE_MINUS_DST_COLOR = 0x0307,
151 SRC_ALPHA_SATURATE = 0x0308,
153 BLEND_EQUATION = 0x8009,
154 BLEND_EQUATION_RGB = 0x8009,
155 BLEND_EQUATION_ALPHA = 0x883D,
156 FUNC_SUBTRACT = 0x800A,
157 FUNC_REVERSE_SUBTRACT = 0x800B,
158 BLEND_DST_RGB = 0x80C8,
159 BLEND_SRC_RGB = 0x80C9,
160 BLEND_DST_ALPHA = 0x80CA,
161 BLEND_SRC_ALPHA = 0x80CB,
162 CONSTANT_COLOR = 0x8001,
163 ONE_MINUS_CONSTANT_COLOR = 0x8002,
164 CONSTANT_ALPHA = 0x8003,
165 ONE_MINUS_CONSTANT_ALPHA = 0x8004,
166 BLEND_COLOR = 0x8005,
167 ARRAY_BUFFER = 0x8892,
168 ELEMENT_ARRAY_BUFFER = 0x8893,
169 ARRAY_BUFFER_BINDING = 0x8894,
170 ELEMENT_ARRAY_BUFFER_BINDING = 0x8895,
171 STREAM_DRAW = 0x88E0,
172 STATIC_DRAW = 0x88E4,
173 DYNAMIC_DRAW = 0x88E8,
174 BUFFER_SIZE = 0x8764,
175 BUFFER_USAGE = 0x8765,
176 CURRENT_VERTEX_ATTRIB = 0x8626,
179 FRONT_AND_BACK = 0x0408,
184 STENCIL_TEST = 0x0B90,
186 SCISSOR_TEST = 0x0C11,
187 POLYGON_OFFSET_FILL = 0x8037,
188 SAMPLE_ALPHA_TO_COVERAGE = 0x809E,
189 SAMPLE_COVERAGE = 0x80A0,
191 INVALID_ENUM = 0x0500,
192 INVALID_VALUE = 0x0501,
193 INVALID_OPERATION = 0x0502,
194 OUT_OF_MEMORY = 0x0505,
198 ALIASED_POINT_SIZE_RANGE = 0x846D,
199 ALIASED_LINE_WIDTH_RANGE = 0x846E,
200 CULL_FACE_MODE = 0x0B45,
202 DEPTH_RANGE = 0x0B70,
203 DEPTH_WRITEMASK = 0x0B72,
204 DEPTH_CLEAR_VALUE = 0x0B73,
206 STENCIL_CLEAR_VALUE = 0x0B91,
207 STENCIL_FUNC = 0x0B92,
208 STENCIL_FAIL = 0x0B94,
209 STENCIL_PASS_DEPTH_FAIL = 0x0B95,
210 STENCIL_PASS_DEPTH_PASS = 0x0B96,
211 STENCIL_REF = 0x0B97,
212 STENCIL_VALUE_MASK = 0x0B93,
213 STENCIL_WRITEMASK = 0x0B98,
214 STENCIL_BACK_FUNC = 0x8800,
215 STENCIL_BACK_FAIL = 0x8801,
216 STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802,
217 STENCIL_BACK_PASS_DEPTH_PASS = 0x8803,
218 STENCIL_BACK_REF = 0x8CA3,
219 STENCIL_BACK_VALUE_MASK = 0x8CA4,
220 STENCIL_BACK_WRITEMASK = 0x8CA5,
222 SCISSOR_BOX = 0x0C10,
223 COLOR_CLEAR_VALUE = 0x0C22,
224 COLOR_WRITEMASK = 0x0C23,
225 UNPACK_ALIGNMENT = 0x0CF5,
226 PACK_ALIGNMENT = 0x0D05,
227 MAX_TEXTURE_SIZE = 0x0D33,
228 MAX_VIEWPORT_DIMS = 0x0D3A,
229 SUBPIXEL_BITS = 0x0D50,
235 STENCIL_BITS = 0x0D57,
236 POLYGON_OFFSET_UNITS = 0x2A00,
237 POLYGON_OFFSET_FACTOR = 0x8038,
238 TEXTURE_BINDING_2D = 0x8069,
239 SAMPLE_BUFFERS = 0x80A8,
241 SAMPLE_COVERAGE_VALUE = 0x80AA,
242 SAMPLE_COVERAGE_INVERT = 0x80AB,
243 NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2,
244 COMPRESSED_TEXTURE_FORMATS = 0x86A3,
248 GENERATE_MIPMAP_HINT = 0x8192,
250 UNSIGNED_BYTE = 0x1401,
252 UNSIGNED_SHORT = 0x1403,
254 UNSIGNED_INT = 0x1405,
257 DEPTH_COMPONENT = 0x1902,
262 LUMINANCE_ALPHA = 0x190A,
263 UNSIGNED_SHORT_4_4_4_4 = 0x8033,
264 UNSIGNED_SHORT_5_5_5_1 = 0x8034,
265 UNSIGNED_SHORT_5_6_5 = 0x8363,
266 FRAGMENT_SHADER = 0x8B30,
267 VERTEX_SHADER = 0x8B31,
268 MAX_VERTEX_ATTRIBS = 0x8869,
269 MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB,
270 MAX_VARYING_VECTORS = 0x8DFC,
271 MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D,
272 MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C,
273 MAX_TEXTURE_IMAGE_UNITS = 0x8872,
274 MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD,
275 SHADER_TYPE = 0x8B4F,
276 DELETE_STATUS = 0x8B80,
277 LINK_STATUS = 0x8B82,
278 VALIDATE_STATUS = 0x8B83,
279 ATTACHED_SHADERS = 0x8B85,
280 ACTIVE_UNIFORMS = 0x8B86,
281 ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
282 ACTIVE_ATTRIBUTES = 0x8B89,
283 ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
284 SHADING_LANGUAGE_VERSION = 0x8B8C,
285 CURRENT_PROGRAM = 0x8B8D,
307 NEAREST_MIPMAP_NEAREST = 0x2700,
308 LINEAR_MIPMAP_NEAREST = 0x2701,
309 NEAREST_MIPMAP_LINEAR = 0x2702,
310 LINEAR_MIPMAP_LINEAR = 0x2703,
311 TEXTURE_MAG_FILTER = 0x2800,
312 TEXTURE_MIN_FILTER = 0x2801,
313 TEXTURE_WRAP_S = 0x2802,
314 TEXTURE_WRAP_T = 0x2803,
316 TEXTURE_CUBE_MAP = 0x8513,
317 TEXTURE_BINDING_CUBE_MAP = 0x8514,
318 TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515,
319 TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516,
320 TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517,
321 TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518,
322 TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519,
323 TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A,
324 MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C,
357 ACTIVE_TEXTURE = 0x84E0,
359 CLAMP_TO_EDGE = 0x812F,
360 MIRRORED_REPEAT = 0x8370,
375 SAMPLER_CUBE = 0x8B60,
376 VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622,
377 VERTEX_ATTRIB_ARRAY_SIZE = 0x8623,
378 VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624,
379 VERTEX_ATTRIB_ARRAY_TYPE = 0x8625,
380 VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A,
381 VERTEX_ATTRIB_ARRAY_POINTER = 0x8645,
382 VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F,
383 COMPILE_STATUS = 0x8B81,
384 INFO_LOG_LENGTH = 0x8B84,
385 SHADER_SOURCE_LENGTH = 0x8B88,
386 SHADER_COMPILER = 0x8DFA,
387 SHADER_BINARY_FORMATS = 0x8DF8,
388 NUM_SHADER_BINARY_FORMATS = 0x8DF9,
390 MEDIUM_FLOAT = 0x8DF1,
395 FRAMEBUFFER = 0x8D40,
396 RENDERBUFFER = 0x8D41,
400 DEPTH_COMPONENT16 = 0x81A5,
401 STENCIL_INDEX = 0x1901,
402 STENCIL_INDEX8 = 0x8D48,
403 DEPTH_STENCIL = 0x84F9,
404 UNSIGNED_INT_24_8 = 0x84FA,
405 RENDERBUFFER_WIDTH = 0x8D42,
406 RENDERBUFFER_HEIGHT = 0x8D43,
407 RENDERBUFFER_INTERNAL_FORMAT = 0x8D44,
408 RENDERBUFFER_RED_SIZE = 0x8D50,
409 RENDERBUFFER_GREEN_SIZE = 0x8D51,
410 RENDERBUFFER_BLUE_SIZE = 0x8D52,
411 RENDERBUFFER_ALPHA_SIZE = 0x8D53,
412 RENDERBUFFER_DEPTH_SIZE = 0x8D54,
413 RENDERBUFFER_STENCIL_SIZE = 0x8D55,
414 FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0,
415 FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1,
416 FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2,
417 FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3,
418 COLOR_ATTACHMENT0 = 0x8CE0,
419 DEPTH_ATTACHMENT = 0x8D00,
420 STENCIL_ATTACHMENT = 0x8D20,
421 DEPTH_STENCIL_ATTACHMENT = 0x821A,
423 FRAMEBUFFER_COMPLETE = 0x8CD5,
424 FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6,
425 FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7,
426 FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9,
427 FRAMEBUFFER_UNSUPPORTED = 0x8CDD,
428 FRAMEBUFFER_BINDING = 0x8CA6,
429 RENDERBUFFER_BINDING = 0x8CA7,
430 MAX_RENDERBUFFER_SIZE = 0x84E8,
431 INVALID_FRAMEBUFFER_OPERATION = 0x0506,
433 // WebGL-specific enums
434 UNPACK_FLIP_Y_WEBGL = 0x9240,
435 UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241,
436 CONTEXT_LOST_WEBGL = 0x9242,
437 UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
438 BROWSER_DEFAULT_WEBGL = 0x9244
441 // Context creation attributes.
448 , premultipliedAlpha(true)
449 , preserveDrawingBuffer(false)
450 , noExtensions(false)
451 , shareResources(true)
452 , preferDiscreteGPU(false)
460 bool premultipliedAlpha;
461 bool preserveDrawingBuffer;
464 bool preferDiscreteGPU;
469 RenderDirectlyToHostWindow
472 class ContextLostCallback {
474 virtual void onContextLost() = 0;
475 virtual ~ContextLostCallback() {}
478 class ErrorMessageCallback {
480 virtual void onErrorMessage(const String& message, GC3Dint id) = 0;
481 virtual ~ErrorMessageCallback() { }
484 void setContextLostCallback(PassOwnPtr<ContextLostCallback>);
485 void setErrorMessageCallback(PassOwnPtr<ErrorMessageCallback>);
487 static PassRefPtr<GraphicsContext3D> create(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
488 ~GraphicsContext3D();
491 PlatformGraphicsContext3D platformGraphicsContext3D() const { return m_contextObj; }
492 Platform3DObject platformTexture() const { return m_compositorTexture; }
493 CALayer* platformLayer() const { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); }
494 #elif PLATFORM(CHROMIUM)
495 PlatformGraphicsContext3D platformGraphicsContext3D() const;
496 Platform3DObject platformTexture() const;
498 GrContext* grContext();
500 #if USE(ACCELERATED_COMPOSITING)
501 PlatformLayer* platformLayer() const;
504 PlatformGraphicsContext3D platformGraphicsContext3D();
505 Platform3DObject platformTexture() const;
506 #if USE(ACCELERATED_COMPOSITING)
507 PlatformLayer* platformLayer() const;
510 PlatformGraphicsContext3D platformGraphicsContext3D();
511 Platform3DObject platformTexture() const { return m_texture; }
512 #if USE(ACCELERATED_COMPOSITING)
513 PlatformLayer* platformLayer() const;
516 PlatformGraphicsContext3D platformGraphicsContext3D();
517 Platform3DObject platformTexture() const;
518 #if USE(ACCELERATED_COMPOSITING)
519 PlatformLayer* platformLayer() const;
522 PlatformGraphicsContext3D platformGraphicsContext3D() const { return NullPlatformGraphicsContext3D; }
523 Platform3DObject platformTexture() const { return NullPlatform3DObject; }
524 #if USE(ACCELERATED_COMPOSITING)
525 PlatformLayer* platformLayer() const { return 0; }
528 bool makeContextCurrent();
530 #if PLATFORM(MAC) || PLATFORM(CHROMIUM) || PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL)
531 // With multisampling on, blit from multisampleFBO to regular FBO.
532 void prepareTexture();
535 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0.
536 // Return true if no GL error is synthesized.
537 // By default, alignment is 4, the OpenGL default setting.
538 bool texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint alignment = 4);
540 bool isGLES2Compliant() const;
542 //----------------------------------------------------------------------
543 // Helpers for texture uploading and pixel readback.
546 // Computes the components per pixel and bytes per component
547 // for the given format and type combination. Returns false if
548 // either was an invalid enum.
549 static bool computeFormatAndTypeParameters(GC3Denum format,
551 unsigned int* componentsPerPixel,
552 unsigned int* bytesPerComponent);
554 // Computes the image size in bytes. If paddingInBytes is not null, padding
555 // is also calculated in return. Returns NO_ERROR if succeed, otherwise
556 // return the suggested GL error indicating the cause of the failure:
557 // INVALID_VALUE if width/height is negative or overflow happens.
558 // INVALID_ENUM if format/type is illegal.
559 static GC3Denum computeImageSizeInBytes(GC3Denum format,
564 unsigned int* imageSizeInBytes,
565 unsigned int* paddingInBytes);
567 // Extracts the contents of the given Image into the passed Vector,
568 // packing the pixel data according to the given format and type,
569 // and obeying the flipY, premultiplyAlpha, and ignoreGammaAndColorProfile
570 // flags. Returns true upon success.
571 static bool extractImageData(Image*,
575 bool premultiplyAlpha,
576 bool ignoreGammaAndColorProfile,
577 Vector<uint8_t>& data);
579 // Extracts the contents of the given ImageData into the passed Vector,
580 // packing the pixel data according to the given format and type,
581 // and obeying the flipY and premultiplyAlpha flags. Returns true
583 static bool extractImageData(ImageData*,
587 bool premultiplyAlpha,
588 Vector<uint8_t>& data);
590 // Helper function which extracts the user-supplied texture
591 // data, applying the flipY and premultiplyAlpha parameters.
592 // If the data is not tightly packed according to the passed
593 // unpackAlignment, the output data will be tightly packed.
594 // Returns true if successful, false if any error occurred.
595 static bool extractTextureData(unsigned int width, unsigned int height,
596 GC3Denum format, GC3Denum type,
597 unsigned int unpackAlignment,
598 bool flipY, bool premultiplyAlpha,
600 Vector<uint8_t>& data);
602 // Flips the given image data vertically, in-place.
603 static void flipVertically(void* imageData,
606 unsigned int bytesPerPixel,
607 unsigned int unpackAlignment);
609 // Attempt to enumerate all possible native image formats to
610 // reduce the amount of temporary allocations during texture
611 // uploading. This enum must be public because it is accessed
612 // by non-member functions.
613 enum SourceDataFormat {
614 SourceFormatRGBA8 = 0,
615 SourceFormatRGBA16Little,
616 SourceFormatRGBA16Big,
619 SourceFormatRGB16Little,
620 SourceFormatRGB16Big,
624 SourceFormatBGRA16Little,
625 SourceFormatBGRA16Big,
627 SourceFormatARGB16Little,
628 SourceFormatARGB16Big,
630 SourceFormatRGBA5551,
631 SourceFormatRGBA4444,
634 SourceFormatR16Little,
638 SourceFormatRA16Little,
642 SourceFormatAR16Little,
645 SourceFormatA16Little,
648 SourceFormatNumFormats
651 //----------------------------------------------------------------------
652 // Entry points for WebGL.
655 void activeTexture(GC3Denum texture);
656 void attachShader(Platform3DObject program, Platform3DObject shader);
657 void bindAttribLocation(Platform3DObject, GC3Duint index, const String& name);
658 void bindBuffer(GC3Denum target, Platform3DObject);
659 void bindFramebuffer(GC3Denum target, Platform3DObject);
660 void bindRenderbuffer(GC3Denum target, Platform3DObject);
661 void bindTexture(GC3Denum target, Platform3DObject);
662 void blendColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
663 void blendEquation(GC3Denum mode);
664 void blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha);
665 void blendFunc(GC3Denum sfactor, GC3Denum dfactor);
666 void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha);
668 void bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage);
669 void bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage);
670 void bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data);
672 GC3Denum checkFramebufferStatus(GC3Denum target);
673 void clear(GC3Dbitfield mask);
674 void clearColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
675 void clearDepth(GC3Dclampf depth);
676 void clearStencil(GC3Dint s);
677 void colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dboolean blue, GC3Dboolean alpha);
678 void compileShader(Platform3DObject);
680 void compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Dsizei imageSize, const void* data);
681 void compressedTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Dsizei imageSize, const void* data);
682 void copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border);
683 void copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
684 void cullFace(GC3Denum mode);
685 void depthFunc(GC3Denum func);
686 void depthMask(GC3Dboolean flag);
687 void depthRange(GC3Dclampf zNear, GC3Dclampf zFar);
688 void detachShader(Platform3DObject, Platform3DObject);
689 void disable(GC3Denum cap);
690 void disableVertexAttribArray(GC3Duint index);
691 void drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count);
692 void drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset);
694 void enable(GC3Denum cap);
695 void enableVertexAttribArray(GC3Duint index);
698 void framebufferRenderbuffer(GC3Denum target, GC3Denum attachment, GC3Denum renderbuffertarget, Platform3DObject);
699 void framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum textarget, Platform3DObject, GC3Dint level);
700 void frontFace(GC3Denum mode);
701 void generateMipmap(GC3Denum target);
703 bool getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo&);
704 bool getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo&);
705 void getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders);
706 GC3Dint getAttribLocation(Platform3DObject, const String& name);
707 void getBooleanv(GC3Denum pname, GC3Dboolean* value);
708 void getBufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
709 Attributes getContextAttributes();
711 void getFloatv(GC3Denum pname, GC3Dfloat* value);
712 void getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum pname, GC3Dint* value);
713 void getIntegerv(GC3Denum pname, GC3Dint* value);
714 void getProgramiv(Platform3DObject program, GC3Denum pname, GC3Dint* value);
715 String getProgramInfoLog(Platform3DObject);
716 void getRenderbufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
717 void getShaderiv(Platform3DObject, GC3Denum pname, GC3Dint* value);
718 String getShaderInfoLog(Platform3DObject);
719 void getShaderPrecisionFormat(GC3Denum shaderType, GC3Denum precisionType, GC3Dint* range, GC3Dint* precision);
720 String getShaderSource(Platform3DObject);
721 String getString(GC3Denum name);
722 void getTexParameterfv(GC3Denum target, GC3Denum pname, GC3Dfloat* value);
723 void getTexParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
724 void getUniformfv(Platform3DObject program, GC3Dint location, GC3Dfloat* value);
725 void getUniformiv(Platform3DObject program, GC3Dint location, GC3Dint* value);
726 GC3Dint getUniformLocation(Platform3DObject, const String& name);
727 void getVertexAttribfv(GC3Duint index, GC3Denum pname, GC3Dfloat* value);
728 void getVertexAttribiv(GC3Duint index, GC3Denum pname, GC3Dint* value);
729 GC3Dsizeiptr getVertexAttribOffset(GC3Duint index, GC3Denum pname);
731 void hint(GC3Denum target, GC3Denum mode);
732 GC3Dboolean isBuffer(Platform3DObject);
733 GC3Dboolean isEnabled(GC3Denum cap);
734 GC3Dboolean isFramebuffer(Platform3DObject);
735 GC3Dboolean isProgram(Platform3DObject);
736 GC3Dboolean isRenderbuffer(Platform3DObject);
737 GC3Dboolean isShader(Platform3DObject);
738 GC3Dboolean isTexture(Platform3DObject);
739 void lineWidth(GC3Dfloat);
740 void linkProgram(Platform3DObject);
741 void pixelStorei(GC3Denum pname, GC3Dint param);
742 void polygonOffset(GC3Dfloat factor, GC3Dfloat units);
744 void readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data);
746 void releaseShaderCompiler();
748 void renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height);
749 void sampleCoverage(GC3Dclampf value, GC3Dboolean invert);
750 void scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
751 void shaderSource(Platform3DObject, const String& string);
752 void stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask);
753 void stencilFuncSeparate(GC3Denum face, GC3Denum func, GC3Dint ref, GC3Duint mask);
754 void stencilMask(GC3Duint mask);
755 void stencilMaskSeparate(GC3Denum face, GC3Duint mask);
756 void stencilOp(GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
757 void stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
759 bool texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels);
760 void texParameterf(GC3Denum target, GC3Denum pname, GC3Dfloat param);
761 void texParameteri(GC3Denum target, GC3Denum pname, GC3Dint param);
762 void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels);
764 void uniform1f(GC3Dint location, GC3Dfloat x);
765 void uniform1fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
766 void uniform1i(GC3Dint location, GC3Dint x);
767 void uniform1iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
768 void uniform2f(GC3Dint location, GC3Dfloat x, GC3Dfloat y);
769 void uniform2fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
770 void uniform2i(GC3Dint location, GC3Dint x, GC3Dint y);
771 void uniform2iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
772 void uniform3f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
773 void uniform3fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
774 void uniform3i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z);
775 void uniform3iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
776 void uniform4f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
777 void uniform4fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v);
778 void uniform4i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w);
779 void uniform4iv(GC3Dint location, GC3Dsizei, GC3Dint* v);
780 void uniformMatrix2fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
781 void uniformMatrix3fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
782 void uniformMatrix4fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value);
784 void useProgram(Platform3DObject);
785 void validateProgram(Platform3DObject);
787 void vertexAttrib1f(GC3Duint index, GC3Dfloat x);
788 void vertexAttrib1fv(GC3Duint index, GC3Dfloat* values);
789 void vertexAttrib2f(GC3Duint index, GC3Dfloat x, GC3Dfloat y);
790 void vertexAttrib2fv(GC3Duint index, GC3Dfloat* values);
791 void vertexAttrib3f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
792 void vertexAttrib3fv(GC3Duint index, GC3Dfloat* values);
793 void vertexAttrib4f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
794 void vertexAttrib4fv(GC3Duint index, GC3Dfloat* values);
795 void vertexAttribPointer(GC3Duint index, GC3Dint size, GC3Denum type, GC3Dboolean normalized,
796 GC3Dsizei stride, GC3Dintptr offset);
798 void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
800 void reshape(int width, int height);
803 void modifySurface(Evas_Object* evas);
807 static void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
808 int canvasWidth, int canvasHeight, CGContextRef);
809 #elif PLATFORM(GTK) || PLATFORM(EFL)
810 void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
811 int canvasWidth, int canvasHeight, PlatformContextCairo* context);
813 void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
814 int canvasWidth, int canvasHeight, QPainter* context);
815 #elif PLATFORM(BLACKBERRY)
816 void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
817 int canvasWidth, int canvasHeight, GraphicsContext*);
820 void markContextChanged();
821 void markLayerComposited();
822 bool layerComposited() const;
824 void paintRenderingResultsToCanvas(ImageBuffer*, DrawingBuffer*);
825 PassRefPtr<ImageData> paintRenderingResultsToImageData(DrawingBuffer*);
826 bool paintCompositedResultsToCanvas(ImageBuffer*);
829 void readRenderingResults(unsigned char* pixels, int pixelsSize);
832 // Support for buffer creation and deletion
833 Platform3DObject createBuffer();
834 Platform3DObject createFramebuffer();
835 Platform3DObject createProgram();
836 Platform3DObject createRenderbuffer();
837 Platform3DObject createShader(GC3Denum);
838 Platform3DObject createTexture();
840 void deleteBuffer(Platform3DObject);
841 void deleteFramebuffer(Platform3DObject);
842 void deleteProgram(Platform3DObject);
843 void deleteRenderbuffer(Platform3DObject);
844 void deleteShader(Platform3DObject);
845 void deleteTexture(Platform3DObject);
847 // Synthesizes an OpenGL error which will be returned from a
848 // later call to getError. This is used to emulate OpenGL ES
849 // 2.0 behavior on the desktop and to enforce additional error
850 // checking mandated by WebGL.
852 // Per the behavior of glGetError, this stores at most one
853 // instance of any given error, and returns them from calls to
854 // getError in the order they were added.
855 void synthesizeGLError(GC3Denum error);
857 // Support for extensions. Returns a non-null object, though not
858 // all methods it contains may necessarily be supported on the
859 // current hardware. Must call Extensions3D::supports() to
861 Extensions3D* getExtensions();
863 IntSize getInternalFramebufferSize() const;
865 static unsigned getClearBitsByAttachmentType(GC3Denum);
866 static unsigned getClearBitsByFormat(GC3Denum);
875 ChannelRGB = ChannelRed | ChannelGreen | ChannelBlue,
876 ChannelRGBA = ChannelRGB | ChannelAlpha,
879 static unsigned getChannelBitsByFormat(GC3Denum);
882 GraphicsContext3D(Attributes attrs, HostWindow* hostWindow, bool renderDirectlyToHostWindow);
884 // Each platform must provide an implementation of this method.
886 // Gets the data for the given Image into outputVector in the
887 // format specified by the (OpenGL-style) format and type
888 // arguments. Despite the fact that the outputVector contains
889 // uint8_t, if the format and type specify packed pixels, then
890 // it will essentially contain uint16_t after the extraction
893 // If premultiplyAlpha is true, the alpha channel, if any,
894 // will be multiplied into the color channels during the
895 // extraction process. This premultiplication occurs before
896 // any packing of pixel data.
898 // If ignoreGammaAndColorProfile is true, gamma correction and ICC
899 // profile won't be applied.
901 // No vertical flip of the image data is performed by this
903 static bool getImageData(Image*,
906 bool premultiplyAlpha,
907 bool ignoreGammaAndColorProfile,
908 Vector<uint8_t>& outputVector);
910 // Possible alpha operations that may need to occur during
911 // pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must
915 AlphaDoPremultiply = 1,
916 AlphaDoUnmultiply = 2
919 // Helper for getImageData which implements packing of pixel
920 // data into the specified OpenGL destination format and type.
921 // A sourceUnpackAlignment of zero indicates that the source
922 // data is tightly packed. Non-zero values may take a slow path.
923 // Destination data will have no gaps between rows.
924 static bool packPixels(const uint8_t* sourceData,
925 SourceDataFormat sourceDataFormat,
928 unsigned int sourceUnpackAlignment,
929 unsigned int destinationFormat,
930 unsigned int destinationType,
932 void* destinationData);
934 #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT)
935 // Take into account the user's requested context creation attributes,
936 // in particular stencil and antialias, and determine which could or
937 // could not be honored based on the capabilities of the OpenGL
939 void validateDepthStencil(const char* packedDepthStencilExtension);
940 void validateAttributes();
942 // Read rendering results into a pixel array with the same format as the
944 void readRenderingResults(unsigned char* pixels, int pixelsSize);
945 void readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels);
948 #if PLATFORM(BLACKBERRY)
949 void logFrameBufferStatus(int line);
950 void readPixelsIMG(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data);
953 bool reshapeFBOs(const IntSize&);
954 void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
955 #if PLATFORM(QT) && USE(GRAPHICS_SURFACE) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
956 void createGraphicsSurfaces(const IntSize&);
959 int m_currentWidth, m_currentHeight;
960 bool isResourceSafe();
963 CGLContextObj m_contextObj;
964 RetainPtr<WebGLLayer> m_webGLLayer;
965 #elif PLATFORM(BLACKBERRY)
966 #if USE(ACCELERATED_COMPOSITING)
967 RefPtr<PlatformLayer> m_compositingLayer;
972 #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT)
978 HashMap<Platform3DObject, ShaderSourceEntry> m_shaderSourceMap;
980 ANGLEWebKitBridge m_compiler;
983 #if PLATFORM(BLACKBERRY) || (PLATFORM(QT) && defined(QT_OPENGL_ES_2))
984 friend class Extensions3DOpenGLES;
985 OwnPtr<Extensions3DOpenGLES> m_extensions;
986 #elif !PLATFORM(CHROMIUM) && !OS(TIZEN)
987 friend class Extensions3DOpenGL;
988 OwnPtr<Extensions3DOpenGL> m_extensions;
990 friend class Extensions3DOpenGLCommon;
993 Vector<Vector<float> > m_vertexArray;
996 #if !PLATFORM(BLACKBERRY)
997 GC3Duint m_compositorTexture;
1001 #if !PLATFORM(BLACKBERRY)
1002 GC3Duint m_depthBuffer;
1003 GC3Duint m_stencilBuffer;
1005 GC3Duint m_depthStencilBuffer;
1007 bool m_layerComposited;
1008 GC3Duint m_internalColorFormat;
1010 // For tracking which FBO/texture is bound
1011 GC3Duint m_boundFBO;
1012 GC3Denum m_activeTexture;
1013 GC3Duint m_boundTexture0;
1015 // For multisampling
1016 GC3Duint m_multisampleFBO;
1017 GC3Duint m_multisampleDepthStencilBuffer;
1018 GC3Duint m_multisampleColorBuffer;
1020 // Errors raised by synthesizeGLError().
1021 ListHashSet<GC3Denum> m_syntheticErrors;
1023 #if PLATFORM(BLACKBERRY)
1024 bool m_isImaginationHardware;
1028 friend class GraphicsContext3DInternal;
1029 OwnPtr<GraphicsContext3DInternal> m_internal;
1032 #if !PLATFORM(BLACKBERRY) && !OS(TIZEN)
1033 friend class GraphicsContext3DPrivate;
1034 OwnPtr<GraphicsContext3DPrivate> m_private;
1036 bool systemAllowsMultisamplingOnATICards() const;
1039 } // namespace WebCore
1041 #endif // GraphicsContext3D_h