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"
34 #include <wtf/HashMap.h>
35 #include <wtf/ListHashSet.h>
36 #include <wtf/Noncopyable.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>
66 typedef unsigned int GLuint;
70 typedef CGLContextObj PlatformGraphicsContext3D;
72 typedef void* PlatformGraphicsContext3D;
75 #if PLATFORM(CHROMIUM) && USE(SKIA)
79 // These are currently the same among all implementations.
80 const PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
81 const Platform3DObject NullPlatform3DObject = 0;
84 #include <CoreGraphics/CGContext.h>
88 class CanvasRenderingContext;
91 #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT)
92 class Extensions3DOpenGL;
102 class PlatformContextCairo;
111 class GraphicsContext3DPrivate;
113 class GraphicsContext3D : public RefCounted<GraphicsContext3D> {
116 DEPTH_BUFFER_BIT = 0x00000100,
117 STENCIL_BUFFER_BIT = 0x00000400,
118 COLOR_BUFFER_BIT = 0x00004000,
124 TRIANGLE_STRIP = 0x0005,
125 TRIANGLE_FAN = 0x0006,
129 ONE_MINUS_SRC_COLOR = 0x0301,
131 ONE_MINUS_SRC_ALPHA = 0x0303,
133 ONE_MINUS_DST_ALPHA = 0x0305,
135 ONE_MINUS_DST_COLOR = 0x0307,
136 SRC_ALPHA_SATURATE = 0x0308,
138 BLEND_EQUATION = 0x8009,
139 BLEND_EQUATION_RGB = 0x8009,
140 BLEND_EQUATION_ALPHA = 0x883D,
141 FUNC_SUBTRACT = 0x800A,
142 FUNC_REVERSE_SUBTRACT = 0x800B,
143 BLEND_DST_RGB = 0x80C8,
144 BLEND_SRC_RGB = 0x80C9,
145 BLEND_DST_ALPHA = 0x80CA,
146 BLEND_SRC_ALPHA = 0x80CB,
147 CONSTANT_COLOR = 0x8001,
148 ONE_MINUS_CONSTANT_COLOR = 0x8002,
149 CONSTANT_ALPHA = 0x8003,
150 ONE_MINUS_CONSTANT_ALPHA = 0x8004,
151 BLEND_COLOR = 0x8005,
152 ARRAY_BUFFER = 0x8892,
153 ELEMENT_ARRAY_BUFFER = 0x8893,
154 ARRAY_BUFFER_BINDING = 0x8894,
155 ELEMENT_ARRAY_BUFFER_BINDING = 0x8895,
156 STREAM_DRAW = 0x88E0,
157 STATIC_DRAW = 0x88E4,
158 DYNAMIC_DRAW = 0x88E8,
159 BUFFER_SIZE = 0x8764,
160 BUFFER_USAGE = 0x8765,
161 CURRENT_VERTEX_ATTRIB = 0x8626,
164 FRONT_AND_BACK = 0x0408,
169 STENCIL_TEST = 0x0B90,
171 SCISSOR_TEST = 0x0C11,
172 POLYGON_OFFSET_FILL = 0x8037,
173 SAMPLE_ALPHA_TO_COVERAGE = 0x809E,
174 SAMPLE_COVERAGE = 0x80A0,
176 INVALID_ENUM = 0x0500,
177 INVALID_VALUE = 0x0501,
178 INVALID_OPERATION = 0x0502,
179 OUT_OF_MEMORY = 0x0505,
183 ALIASED_POINT_SIZE_RANGE = 0x846D,
184 ALIASED_LINE_WIDTH_RANGE = 0x846E,
185 CULL_FACE_MODE = 0x0B45,
187 DEPTH_RANGE = 0x0B70,
188 DEPTH_WRITEMASK = 0x0B72,
189 DEPTH_CLEAR_VALUE = 0x0B73,
191 STENCIL_CLEAR_VALUE = 0x0B91,
192 STENCIL_FUNC = 0x0B92,
193 STENCIL_FAIL = 0x0B94,
194 STENCIL_PASS_DEPTH_FAIL = 0x0B95,
195 STENCIL_PASS_DEPTH_PASS = 0x0B96,
196 STENCIL_REF = 0x0B97,
197 STENCIL_VALUE_MASK = 0x0B93,
198 STENCIL_WRITEMASK = 0x0B98,
199 STENCIL_BACK_FUNC = 0x8800,
200 STENCIL_BACK_FAIL = 0x8801,
201 STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802,
202 STENCIL_BACK_PASS_DEPTH_PASS = 0x8803,
203 STENCIL_BACK_REF = 0x8CA3,
204 STENCIL_BACK_VALUE_MASK = 0x8CA4,
205 STENCIL_BACK_WRITEMASK = 0x8CA5,
207 SCISSOR_BOX = 0x0C10,
208 COLOR_CLEAR_VALUE = 0x0C22,
209 COLOR_WRITEMASK = 0x0C23,
210 UNPACK_ALIGNMENT = 0x0CF5,
211 PACK_ALIGNMENT = 0x0D05,
212 MAX_TEXTURE_SIZE = 0x0D33,
213 MAX_VIEWPORT_DIMS = 0x0D3A,
214 SUBPIXEL_BITS = 0x0D50,
220 STENCIL_BITS = 0x0D57,
221 POLYGON_OFFSET_UNITS = 0x2A00,
222 POLYGON_OFFSET_FACTOR = 0x8038,
223 TEXTURE_BINDING_2D = 0x8069,
224 SAMPLE_BUFFERS = 0x80A8,
226 SAMPLE_COVERAGE_VALUE = 0x80AA,
227 SAMPLE_COVERAGE_INVERT = 0x80AB,
228 NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2,
229 COMPRESSED_TEXTURE_FORMATS = 0x86A3,
233 GENERATE_MIPMAP_HINT = 0x8192,
235 UNSIGNED_BYTE = 0x1401,
237 UNSIGNED_SHORT = 0x1403,
239 UNSIGNED_INT = 0x1405,
242 DEPTH_COMPONENT = 0x1902,
247 LUMINANCE_ALPHA = 0x190A,
248 UNSIGNED_SHORT_4_4_4_4 = 0x8033,
249 UNSIGNED_SHORT_5_5_5_1 = 0x8034,
250 UNSIGNED_SHORT_5_6_5 = 0x8363,
251 FRAGMENT_SHADER = 0x8B30,
252 VERTEX_SHADER = 0x8B31,
253 MAX_VERTEX_ATTRIBS = 0x8869,
254 MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB,
255 MAX_VARYING_VECTORS = 0x8DFC,
256 MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D,
257 MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C,
258 MAX_TEXTURE_IMAGE_UNITS = 0x8872,
259 MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD,
260 SHADER_TYPE = 0x8B4F,
261 DELETE_STATUS = 0x8B80,
262 LINK_STATUS = 0x8B82,
263 VALIDATE_STATUS = 0x8B83,
264 ATTACHED_SHADERS = 0x8B85,
265 ACTIVE_UNIFORMS = 0x8B86,
266 ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
267 ACTIVE_ATTRIBUTES = 0x8B89,
268 ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
269 SHADING_LANGUAGE_VERSION = 0x8B8C,
270 CURRENT_PROGRAM = 0x8B8D,
292 NEAREST_MIPMAP_NEAREST = 0x2700,
293 LINEAR_MIPMAP_NEAREST = 0x2701,
294 NEAREST_MIPMAP_LINEAR = 0x2702,
295 LINEAR_MIPMAP_LINEAR = 0x2703,
296 TEXTURE_MAG_FILTER = 0x2800,
297 TEXTURE_MIN_FILTER = 0x2801,
298 TEXTURE_WRAP_S = 0x2802,
299 TEXTURE_WRAP_T = 0x2803,
301 TEXTURE_CUBE_MAP = 0x8513,
302 TEXTURE_BINDING_CUBE_MAP = 0x8514,
303 TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515,
304 TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516,
305 TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517,
306 TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518,
307 TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519,
308 TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A,
309 MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C,
342 ACTIVE_TEXTURE = 0x84E0,
344 CLAMP_TO_EDGE = 0x812F,
345 MIRRORED_REPEAT = 0x8370,
360 SAMPLER_CUBE = 0x8B60,
361 VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622,
362 VERTEX_ATTRIB_ARRAY_SIZE = 0x8623,
363 VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624,
364 VERTEX_ATTRIB_ARRAY_TYPE = 0x8625,
365 VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A,
366 VERTEX_ATTRIB_ARRAY_POINTER = 0x8645,
367 VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F,
368 COMPILE_STATUS = 0x8B81,
369 INFO_LOG_LENGTH = 0x8B84,
370 SHADER_SOURCE_LENGTH = 0x8B88,
371 SHADER_COMPILER = 0x8DFA,
372 SHADER_BINARY_FORMATS = 0x8DF8,
373 NUM_SHADER_BINARY_FORMATS = 0x8DF9,
375 MEDIUM_FLOAT = 0x8DF1,
380 FRAMEBUFFER = 0x8D40,
381 RENDERBUFFER = 0x8D41,
385 DEPTH_COMPONENT16 = 0x81A5,
386 STENCIL_INDEX = 0x1901,
387 STENCIL_INDEX8 = 0x8D48,
388 DEPTH_STENCIL = 0x84F9,
389 RENDERBUFFER_WIDTH = 0x8D42,
390 RENDERBUFFER_HEIGHT = 0x8D43,
391 RENDERBUFFER_INTERNAL_FORMAT = 0x8D44,
392 RENDERBUFFER_RED_SIZE = 0x8D50,
393 RENDERBUFFER_GREEN_SIZE = 0x8D51,
394 RENDERBUFFER_BLUE_SIZE = 0x8D52,
395 RENDERBUFFER_ALPHA_SIZE = 0x8D53,
396 RENDERBUFFER_DEPTH_SIZE = 0x8D54,
397 RENDERBUFFER_STENCIL_SIZE = 0x8D55,
398 FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0,
399 FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1,
400 FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2,
401 FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3,
402 COLOR_ATTACHMENT0 = 0x8CE0,
403 DEPTH_ATTACHMENT = 0x8D00,
404 STENCIL_ATTACHMENT = 0x8D20,
405 DEPTH_STENCIL_ATTACHMENT = 0x821A,
407 FRAMEBUFFER_COMPLETE = 0x8CD5,
408 FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6,
409 FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7,
410 FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9,
411 FRAMEBUFFER_UNSUPPORTED = 0x8CDD,
412 FRAMEBUFFER_BINDING = 0x8CA6,
413 RENDERBUFFER_BINDING = 0x8CA7,
414 MAX_RENDERBUFFER_SIZE = 0x84E8,
415 INVALID_FRAMEBUFFER_OPERATION = 0x0506,
417 // WebGL-specific enums
418 UNPACK_FLIP_Y_WEBGL = 0x9240,
419 UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241,
420 CONTEXT_LOST_WEBGL = 0x9242,
421 UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
422 BROWSER_DEFAULT_WEBGL = 0x9244
425 // Context creation attributes.
432 , premultipliedAlpha(true)
433 , canRecoverFromContextLoss(true)
434 , preserveDrawingBuffer(false)
435 , noExtensions(false)
436 , shareResources(true)
444 bool premultipliedAlpha;
445 bool canRecoverFromContextLoss;
446 bool preserveDrawingBuffer;
453 RenderDirectlyToHostWindow
456 class ContextLostCallback {
458 virtual void onContextLost() = 0;
459 virtual ~ContextLostCallback() {}
462 void setContextLostCallback(PassOwnPtr<ContextLostCallback>);
464 static PassRefPtr<GraphicsContext3D> create(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
465 ~GraphicsContext3D();
468 PlatformGraphicsContext3D platformGraphicsContext3D() const { return m_contextObj; }
469 Platform3DObject platformTexture() const { return m_compositorTexture; }
470 CALayer* platformLayer() const { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); }
471 #elif PLATFORM(CHROMIUM)
472 PlatformGraphicsContext3D platformGraphicsContext3D() const;
473 Platform3DObject platformTexture() const;
475 GrContext* grContext();
477 #if USE(ACCELERATED_COMPOSITING)
478 PlatformLayer* platformLayer() const;
481 PlatformGraphicsContext3D platformGraphicsContext3D();
482 Platform3DObject platformTexture() const;
483 #if USE(ACCELERATED_COMPOSITING)
484 PlatformLayer* platformLayer() const;
487 PlatformGraphicsContext3D platformGraphicsContext3D();
488 Platform3DObject platformTexture() const { return m_texture; }
490 PlatformGraphicsContext3D platformGraphicsContext3D() const;
491 #if USE(ACCELERATED_COMPOSITING)
492 PlatformLayer* platformLayer() const;
495 PlatformGraphicsContext3D platformGraphicsContext3D() const { return NullPlatformGraphicsContext3D; }
496 Platform3DObject platformTexture() const { return NullPlatform3DObject; }
497 #if USE(ACCELERATED_COMPOSITING)
498 PlatformLayer* platformLayer() const { return 0; }
501 void makeContextCurrent();
503 PassRefPtr<DrawingBuffer> createDrawingBuffer(const IntSize& = IntSize());
505 #if PLATFORM(MAC) || PLATFORM(CHROMIUM) || PLATFORM(GTK) || PLATFORM(QT)
506 // With multisampling on, blit from multisampleFBO to regular FBO.
507 void prepareTexture();
510 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0.
511 // Return true if no GL error is synthesized.
512 // By default, alignment is 4, the OpenGL default setting.
513 bool texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint alignment = 4);
515 bool isGLES2Compliant() const;
517 //----------------------------------------------------------------------
518 // Helpers for texture uploading and pixel readback.
521 // Computes the components per pixel and bytes per component
522 // for the given format and type combination. Returns false if
523 // either was an invalid enum.
524 static bool computeFormatAndTypeParameters(GC3Denum format,
526 unsigned int* componentsPerPixel,
527 unsigned int* bytesPerComponent);
529 // Computes the image size in bytes. If paddingInBytes is not null, padding
530 // is also calculated in return. Returns NO_ERROR if succeed, otherwise
531 // return the suggested GL error indicating the cause of the failure:
532 // INVALID_VALUE if width/height is negative or overflow happens.
533 // INVALID_ENUM if format/type is illegal.
534 GC3Denum computeImageSizeInBytes(GC3Denum format,
539 unsigned int* imageSizeInBytes,
540 unsigned int* paddingInBytes);
542 // Extracts the contents of the given Image into the passed Vector,
543 // packing the pixel data according to the given format and type,
544 // and obeying the flipY, premultiplyAlpha, and ignoreGammaAndColorProfile
545 // flags. Returns true upon success.
546 bool extractImageData(Image* image,
550 bool premultiplyAlpha,
551 bool ignoreGammaAndColorProfile,
552 Vector<uint8_t>& data);
554 // Extracts the contents of the given ImageData into the passed Vector,
555 // packing the pixel data according to the given format and type,
556 // and obeying the flipY and premultiplyAlpha flags. Returns true
558 bool extractImageData(ImageData*,
562 bool premultiplyAlpha,
563 Vector<uint8_t>& data);
565 // Helper function which extracts the user-supplied texture
566 // data, applying the flipY and premultiplyAlpha parameters.
567 // If the data is not tightly packed according to the passed
568 // unpackAlignment, the output data will be tightly packed.
569 // Returns true if successful, false if any error occurred.
570 bool extractTextureData(unsigned int width, unsigned int height,
571 GC3Denum format, GC3Denum type,
572 unsigned int unpackAlignment,
573 bool flipY, bool premultiplyAlpha,
575 Vector<uint8_t>& data);
577 // Flips the given image data vertically, in-place.
578 void flipVertically(void* imageData,
581 unsigned int bytesPerPixel,
582 unsigned int unpackAlignment);
584 // Attempt to enumerate all possible native image formats to
585 // reduce the amount of temporary allocations during texture
586 // uploading. This enum must be public because it is accessed
587 // by non-member functions.
588 enum SourceDataFormat {
589 SourceFormatRGBA8 = 0,
590 SourceFormatRGBA16Little,
591 SourceFormatRGBA16Big,
594 SourceFormatRGB16Little,
595 SourceFormatRGB16Big,
599 SourceFormatBGRA16Little,
600 SourceFormatBGRA16Big,
602 SourceFormatARGB16Little,
603 SourceFormatARGB16Big,
605 SourceFormatRGBA5551,
606 SourceFormatRGBA4444,
609 SourceFormatR16Little,
613 SourceFormatRA16Little,
617 SourceFormatAR16Little,
620 SourceFormatA16Little,
623 SourceFormatNumFormats
626 //----------------------------------------------------------------------
627 // Entry points for WebGL.
630 void activeTexture(GC3Denum texture);
631 void attachShader(Platform3DObject program, Platform3DObject shader);
632 void bindAttribLocation(Platform3DObject, GC3Duint index, const String& name);
633 void bindBuffer(GC3Denum target, Platform3DObject);
634 void bindFramebuffer(GC3Denum target, Platform3DObject);
635 void bindRenderbuffer(GC3Denum target, Platform3DObject);
636 void bindTexture(GC3Denum target, Platform3DObject);
637 void blendColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
638 void blendEquation(GC3Denum mode);
639 void blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha);
640 void blendFunc(GC3Denum sfactor, GC3Denum dfactor);
641 void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha);
643 void bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage);
644 void bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage);
645 void bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data);
647 GC3Denum checkFramebufferStatus(GC3Denum target);
648 void clear(GC3Dbitfield mask);
649 void clearColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
650 void clearDepth(GC3Dclampf depth);
651 void clearStencil(GC3Dint s);
652 void colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dboolean blue, GC3Dboolean alpha);
653 void compileShader(Platform3DObject);
655 // void compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Dsizei imageSize, const void* data);
656 // void compressedTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Dsizei imageSize, const void* data);
658 void copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border);
659 void copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
660 void cullFace(GC3Denum mode);
661 void depthFunc(GC3Denum func);
662 void depthMask(GC3Dboolean flag);
663 void depthRange(GC3Dclampf zNear, GC3Dclampf zFar);
664 void detachShader(Platform3DObject, Platform3DObject);
665 void disable(GC3Denum cap);
666 void disableVertexAttribArray(GC3Duint index);
667 void drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count);
668 void drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset);
670 void enable(GC3Denum cap);
671 void enableVertexAttribArray(GC3Duint index);
674 void framebufferRenderbuffer(GC3Denum target, GC3Denum attachment, GC3Denum renderbuffertarget, Platform3DObject);
675 void framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum textarget, Platform3DObject, GC3Dint level);
676 void frontFace(GC3Denum mode);
677 void generateMipmap(GC3Denum target);
679 bool getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo&);
680 bool getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo&);
681 void getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders);
682 GC3Dint getAttribLocation(Platform3DObject, const String& name);
683 void getBooleanv(GC3Denum pname, GC3Dboolean* value);
684 void getBufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
685 Attributes getContextAttributes();
687 void getFloatv(GC3Denum pname, GC3Dfloat* value);
688 void getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum pname, GC3Dint* value);
689 void getIntegerv(GC3Denum pname, GC3Dint* value);
690 void getProgramiv(Platform3DObject program, GC3Denum pname, GC3Dint* value);
691 String getProgramInfoLog(Platform3DObject);
692 void getRenderbufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
693 void getShaderiv(Platform3DObject, GC3Denum pname, GC3Dint* value);
694 String getShaderInfoLog(Platform3DObject);
697 // void glGetShaderPrecisionFormat (GC3Denum shadertype, GC3Denum precisiontype, GC3Dint* range, GC3Dint* precision);
699 String getShaderSource(Platform3DObject);
700 String getString(GC3Denum name);
701 void getTexParameterfv(GC3Denum target, GC3Denum pname, GC3Dfloat* value);
702 void getTexParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
703 void getUniformfv(Platform3DObject program, GC3Dint location, GC3Dfloat* value);
704 void getUniformiv(Platform3DObject program, GC3Dint location, GC3Dint* value);
705 GC3Dint getUniformLocation(Platform3DObject, const String& name);
706 void getVertexAttribfv(GC3Duint index, GC3Denum pname, GC3Dfloat* value);
707 void getVertexAttribiv(GC3Duint index, GC3Denum pname, GC3Dint* value);
708 GC3Dsizeiptr getVertexAttribOffset(GC3Duint index, GC3Denum pname);
710 void hint(GC3Denum target, GC3Denum mode);
711 GC3Dboolean isBuffer(Platform3DObject);
712 GC3Dboolean isEnabled(GC3Denum cap);
713 GC3Dboolean isFramebuffer(Platform3DObject);
714 GC3Dboolean isProgram(Platform3DObject);
715 GC3Dboolean isRenderbuffer(Platform3DObject);
716 GC3Dboolean isShader(Platform3DObject);
717 GC3Dboolean isTexture(Platform3DObject);
718 void lineWidth(GC3Dfloat);
719 void linkProgram(Platform3DObject);
720 void pixelStorei(GC3Denum pname, GC3Dint param);
721 void polygonOffset(GC3Dfloat factor, GC3Dfloat units);
723 void readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data);
725 void releaseShaderCompiler();
727 void renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height);
728 void sampleCoverage(GC3Dclampf value, GC3Dboolean invert);
729 void scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
730 void shaderSource(Platform3DObject, const String& string);
731 void stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask);
732 void stencilFuncSeparate(GC3Denum face, GC3Denum func, GC3Dint ref, GC3Duint mask);
733 void stencilMask(GC3Duint mask);
734 void stencilMaskSeparate(GC3Denum face, GC3Duint mask);
735 void stencilOp(GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
736 void stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
738 bool texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels);
739 void texParameterf(GC3Denum target, GC3Denum pname, GC3Dfloat param);
740 void texParameteri(GC3Denum target, GC3Denum pname, GC3Dint param);
741 void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels);
743 // FIXME: change the argument orders to match OpenGL's.
744 void uniform1f(GC3Dint location, GC3Dfloat x);
745 void uniform1fv(GC3Dint location, GC3Dfloat* v, GC3Dsizei size);
746 void uniform1i(GC3Dint location, GC3Dint x);
747 void uniform1iv(GC3Dint location, GC3Dint* v, GC3Dsizei size);
748 void uniform2f(GC3Dint location, GC3Dfloat x, float y);
749 void uniform2fv(GC3Dint location, GC3Dfloat* v, GC3Dsizei size);
750 void uniform2i(GC3Dint location, GC3Dint x, GC3Dint y);
751 void uniform2iv(GC3Dint location, GC3Dint* v, GC3Dsizei size);
752 void uniform3f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
753 void uniform3fv(GC3Dint location, GC3Dfloat* v, GC3Dsizei size);
754 void uniform3i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z);
755 void uniform3iv(GC3Dint location, GC3Dint* v, GC3Dsizei size);
756 void uniform4f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
757 void uniform4fv(GC3Dint location, GC3Dfloat* v, GC3Dsizei size);
758 void uniform4i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w);
759 void uniform4iv(GC3Dint location, GC3Dint* v, GC3Dsizei size);
760 void uniformMatrix2fv(GC3Dint location, GC3Dboolean transpose, GC3Dfloat* value, GC3Dsizei size);
761 void uniformMatrix3fv(GC3Dint location, GC3Dboolean transpose, GC3Dfloat* value, GC3Dsizei size);
762 void uniformMatrix4fv(GC3Dint location, GC3Dboolean transpose, GC3Dfloat* value, GC3Dsizei size);
764 void useProgram(Platform3DObject);
765 void validateProgram(Platform3DObject);
767 void vertexAttrib1f(GC3Duint index, GC3Dfloat x);
768 void vertexAttrib1fv(GC3Duint index, GC3Dfloat* values);
769 void vertexAttrib2f(GC3Duint index, GC3Dfloat x, GC3Dfloat y);
770 void vertexAttrib2fv(GC3Duint index, GC3Dfloat* values);
771 void vertexAttrib3f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
772 void vertexAttrib3fv(GC3Duint index, GC3Dfloat* values);
773 void vertexAttrib4f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
774 void vertexAttrib4fv(GC3Duint index, GC3Dfloat* values);
775 void vertexAttribPointer(GC3Duint index, GC3Dint size, GC3Denum type, GC3Dboolean normalized,
776 GC3Dsizei stride, GC3Dintptr offset);
778 void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
780 void reshape(int width, int height);
783 static void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
784 int canvasWidth, int canvasHeight, CGContextRef);
786 void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
787 int canvasWidth, int canvasHeight, PlatformContextCairo* context);
790 void markContextChanged();
791 void markLayerComposited();
792 bool layerComposited() const;
794 void paintRenderingResultsToCanvas(CanvasRenderingContext*);
795 PassRefPtr<ImageData> paintRenderingResultsToImageData();
796 bool paintCompositedResultsToCanvas(CanvasRenderingContext*);
799 bool paintsIntoCanvasBuffer() const { return true; }
800 #elif PLATFORM(CHROMIUM)
801 bool paintsIntoCanvasBuffer() const;
803 bool paintsIntoCanvasBuffer() const { return true; }
805 bool paintsIntoCanvasBuffer() const { return false; }
808 // Support for buffer creation and deletion
809 Platform3DObject createBuffer();
810 Platform3DObject createFramebuffer();
811 Platform3DObject createProgram();
812 Platform3DObject createRenderbuffer();
813 Platform3DObject createShader(GC3Denum);
814 Platform3DObject createTexture();
816 void deleteBuffer(Platform3DObject);
817 void deleteFramebuffer(Platform3DObject);
818 void deleteProgram(Platform3DObject);
819 void deleteRenderbuffer(Platform3DObject);
820 void deleteShader(Platform3DObject);
821 void deleteTexture(Platform3DObject);
823 // Synthesizes an OpenGL error which will be returned from a
824 // later call to getError. This is used to emulate OpenGL ES
825 // 2.0 behavior on the desktop and to enforce additional error
826 // checking mandated by WebGL.
828 // Per the behavior of glGetError, this stores at most one
829 // instance of any given error, and returns them from calls to
830 // getError in the order they were added.
831 void synthesizeGLError(GC3Denum error);
833 // Support for extensions. Returns a non-null object, though not
834 // all methods it contains may necessarily be supported on the
835 // current hardware. Must call Extensions3D::supports() to
837 Extensions3D* getExtensions();
839 IntSize getInternalFramebufferSize() const;
842 GraphicsContext3D(Attributes attrs, HostWindow* hostWindow, bool renderDirectlyToHostWindow);
844 // Each platform must provide an implementation of this method.
846 // Gets the data for the given Image into outputVector in the
847 // format specified by the (OpenGL-style) format and type
848 // arguments. Despite the fact that the outputVector contains
849 // uint8_t, if the format and type specify packed pixels, then
850 // it will essentially contain uint16_t after the extraction
853 // If premultiplyAlpha is true, the alpha channel, if any,
854 // will be multiplied into the color channels during the
855 // extraction process. This premultiplication occurs before
856 // any packing of pixel data.
858 // If ignoreGammaAndColorProfile is true, gamma correction and ICC
859 // profile won't be applied.
861 // No vertical flip of the image data is performed by this
863 bool getImageData(Image* image,
866 bool premultiplyAlpha,
867 bool ignoreGammaAndColorProfile,
868 Vector<uint8_t>& outputVector);
870 // Possible alpha operations that may need to occur during
871 // pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must
875 AlphaDoPremultiply = 1,
876 AlphaDoUnmultiply = 2
879 // Helper for getImageData which implements packing of pixel
880 // data into the specified OpenGL destination format and type.
881 // A sourceUnpackAlignment of zero indicates that the source
882 // data is tightly packed. Non-zero values may take a slow path.
883 // Destination data will have no gaps between rows.
884 bool packPixels(const uint8_t* sourceData,
885 SourceDataFormat sourceDataFormat,
888 unsigned int sourceUnpackAlignment,
889 unsigned int destinationFormat,
890 unsigned int destinationType,
892 void* destinationData);
894 #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT)
895 // Take into account the user's requested context creation attributes,
896 // in particular stencil and antialias, and determine which could or
897 // could not be honored based on the capabilities of the OpenGL
899 void validateAttributes();
901 // Read rendering results into a pixel array with the same format as the
903 void readRenderingResults(unsigned char* pixels, int pixelsSize);
906 int m_currentWidth, m_currentHeight;
907 bool isResourceSafe();
910 CGLContextObj m_contextObj;
911 RetainPtr<WebGLLayer> m_webGLLayer;
914 #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT)
920 HashMap<Platform3DObject, ShaderSourceEntry> m_shaderSourceMap;
922 ANGLEWebKitBridge m_compiler;
923 #if PLATFORM(QT) && defined(QT_OPENGL_ES_2)
924 friend class Extensions3DQt;
925 OwnPtr<Extensions3DQt> m_extensions;
927 friend class Extensions3DOpenGL;
928 OwnPtr<Extensions3DOpenGL> m_extensions;
932 Vector<Vector<float> > m_vertexArray;
934 GC3Duint m_texture, m_compositorTexture;
936 GC3Duint m_depthStencilBuffer;
937 bool m_layerComposited;
938 GC3Duint m_internalColorFormat;
940 // For tracking which FBO/texture is bound
942 GC3Denum m_activeTexture;
943 GC3Duint m_boundTexture0;
946 GC3Duint m_multisampleFBO;
947 GC3Duint m_multisampleDepthStencilBuffer;
948 GC3Duint m_multisampleColorBuffer;
950 // Errors raised by synthesizeGLError().
951 ListHashSet<GC3Denum> m_syntheticErrors;
954 friend class GraphicsContext3DPrivate;
955 OwnPtr<GraphicsContext3DPrivate> m_private;
958 } // namespace WebCore
960 #endif // GraphicsContext3D_h