blob: ab2cd654428cad39bd6f837858fc80d43f33e452 [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
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
Ben Murdoch02772c62013-07-26 10:21:05 +010023 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010024 */
25
26#ifndef WebGLRenderingContext_h
27#define WebGLRenderingContext_h
28
29#include "core/dom/ActiveDOMObject.h"
30#include "core/html/canvas/CanvasRenderingContext.h"
31#include "core/html/canvas/WebGLGetInfo.h"
Torne (Richard Coles)e5249552013-05-15 11:35:13 +010032#include "core/page/Page.h"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010033#include "core/platform/Timer.h"
34#include "core/platform/graphics/GraphicsContext3D.h"
35#include "core/platform/graphics/ImageBuffer.h"
36
Ben Murdoch591b9582013-07-10 11:41:44 +010037#include "wtf/Float32Array.h"
38#include "wtf/Int32Array.h"
39#include "wtf/OwnArrayPtr.h"
40#include "wtf/text/WTFString.h"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010041
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +010042namespace WebKit { class WebLayer; }
43
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010044namespace WebCore {
45
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +010046class ANGLEInstancedArrays;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010047class DrawingBuffer;
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010048class EXTFragDepth;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010049class EXTTextureFilterAnisotropic;
Ben Murdochdf957042013-08-06 11:01:27 +010050class ExceptionState;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010051class HTMLImageElement;
52class HTMLVideoElement;
53class ImageBuffer;
54class ImageData;
55class IntSize;
Ben Murdochdf957042013-08-06 11:01:27 +010056class OESElementIndexUint;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010057class OESStandardDerivatives;
58class OESTextureFloat;
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +010059class OESTextureFloatLinear;
Ben Murdochdf957042013-08-06 11:01:27 +010060class OESTextureHalfFloat;
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +010061class OESTextureHalfFloatLinear;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010062class OESVertexArrayObject;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010063class WebGLActiveInfo;
64class WebGLBuffer;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010065class WebGLCompressedTextureATC;
66class WebGLCompressedTexturePVRTC;
67class WebGLCompressedTextureS3TC;
68class WebGLContextAttributes;
Ben Murdochdf957042013-08-06 11:01:27 +010069class WebGLContextGroup;
70class WebGLContextObject;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010071class WebGLDebugRendererInfo;
72class WebGLDebugShaders;
73class WebGLDepthTexture;
Ben Murdochdf957042013-08-06 11:01:27 +010074class WebGLDrawBuffers;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010075class WebGLExtension;
76class WebGLFramebuffer;
77class WebGLLoseContext;
78class WebGLObject;
79class WebGLProgram;
80class WebGLRenderbuffer;
81class WebGLShader;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010082class WebGLShaderPrecisionFormat;
Ben Murdochdf957042013-08-06 11:01:27 +010083class WebGLSharedObject;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010084class WebGLTexture;
85class WebGLUniformLocation;
86class WebGLVertexArrayObjectOES;
87
Torne (Richard Coles)e5249552013-05-15 11:35:13 +010088class WebGLRenderingContext : public CanvasRenderingContext, public ActiveDOMObject, private Page::MultisamplingChangedObserver {
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010089public:
90 static PassOwnPtr<WebGLRenderingContext> create(HTMLCanvasElement*, WebGLContextAttributes*);
91 virtual ~WebGLRenderingContext();
92
93 virtual bool is3d() const { return true; }
94 virtual bool isAccelerated() const { return true; }
95
96 int drawingBufferWidth() const;
97 int drawingBufferHeight() const;
98
Ben Murdoch1fad5ca2013-08-07 11:05:11 +010099 void activeTexture(GC3Denum texture);
100 void attachShader(WebGLProgram*, WebGLShader*);
101 void bindAttribLocation(WebGLProgram*, GC3Duint index, const String& name);
102 void bindBuffer(GC3Denum target, WebGLBuffer*);
103 void bindFramebuffer(GC3Denum target, WebGLFramebuffer*);
104 void bindRenderbuffer(GC3Denum target, WebGLRenderbuffer*);
105 void bindTexture(GC3Denum target, WebGLTexture*);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100106 void blendColor(GC3Dfloat red, GC3Dfloat green, GC3Dfloat blue, GC3Dfloat alpha);
107 void blendEquation(GC3Denum mode);
108 void blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha);
109 void blendFunc(GC3Denum sfactor, GC3Denum dfactor);
110 void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha);
111
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100112 void bufferData(GC3Denum target, long long size, GC3Denum usage);
113 void bufferData(GC3Denum target, ArrayBuffer* data, GC3Denum usage);
114 void bufferData(GC3Denum target, ArrayBufferView* data, GC3Denum usage);
115 void bufferSubData(GC3Denum target, long long offset, ArrayBuffer* data);
116 void bufferSubData(GC3Denum target, long long offset, ArrayBufferView* data);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100117
118 GC3Denum checkFramebufferStatus(GC3Denum target);
119 void clear(GC3Dbitfield mask);
120 void clearColor(GC3Dfloat red, GC3Dfloat green, GC3Dfloat blue, GC3Dfloat alpha);
121 void clearDepth(GC3Dfloat);
122 void clearStencil(GC3Dint);
123 void colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dboolean blue, GC3Dboolean alpha);
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100124 void compileShader(WebGLShader*);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100125
126 void compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width,
127 GC3Dsizei height, GC3Dint border, ArrayBufferView* data);
128 void compressedTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset,
129 GC3Dsizei width, GC3Dsizei height, GC3Denum format, ArrayBufferView* data);
130
131 void copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border);
132 void copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
133
134 PassRefPtr<WebGLBuffer> createBuffer();
135 PassRefPtr<WebGLFramebuffer> createFramebuffer();
136 PassRefPtr<WebGLProgram> createProgram();
137 PassRefPtr<WebGLRenderbuffer> createRenderbuffer();
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100138 PassRefPtr<WebGLShader> createShader(GC3Denum type);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100139 PassRefPtr<WebGLTexture> createTexture();
140
141 void cullFace(GC3Denum mode);
142
143 void deleteBuffer(WebGLBuffer*);
144 void deleteFramebuffer(WebGLFramebuffer*);
145 void deleteProgram(WebGLProgram*);
146 void deleteRenderbuffer(WebGLRenderbuffer*);
147 void deleteShader(WebGLShader*);
148 void deleteTexture(WebGLTexture*);
149
150 void depthFunc(GC3Denum);
151 void depthMask(GC3Dboolean);
152 void depthRange(GC3Dfloat zNear, GC3Dfloat zFar);
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100153 void detachShader(WebGLProgram*, WebGLShader*);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100154 void disable(GC3Denum cap);
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100155 void disableVertexAttribArray(GC3Duint index);
156 void drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count);
157 void drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, long long offset);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100158
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100159 void drawArraysInstancedANGLE(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount);
160 void drawElementsInstancedANGLE(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount);
161
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100162 void enable(GC3Denum cap);
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100163 void enableVertexAttribArray(GC3Duint index);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100164 void finish();
165 void flush();
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100166 void framebufferRenderbuffer(GC3Denum target, GC3Denum attachment, GC3Denum renderbuffertarget, WebGLRenderbuffer*);
167 void framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum textarget, WebGLTexture*, GC3Dint level);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100168 void frontFace(GC3Denum mode);
169 void generateMipmap(GC3Denum target);
170
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100171 PassRefPtr<WebGLActiveInfo> getActiveAttrib(WebGLProgram*, GC3Duint index);
172 PassRefPtr<WebGLActiveInfo> getActiveUniform(WebGLProgram*, GC3Duint index);
173 bool getAttachedShaders(WebGLProgram*, Vector<RefPtr<WebGLShader> >&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100174 GC3Dint getAttribLocation(WebGLProgram*, const String& name);
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100175 WebGLGetInfo getBufferParameter(GC3Denum target, GC3Denum pname);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100176 PassRefPtr<WebGLContextAttributes> getContextAttributes();
177 GC3Denum getError();
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100178 PassRefPtr<WebGLExtension> getExtension(const String& name);
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100179 WebGLGetInfo getFramebufferAttachmentParameter(GC3Denum target, GC3Denum attachment, GC3Denum pname);
180 WebGLGetInfo getParameter(GC3Denum pname);
181 WebGLGetInfo getProgramParameter(WebGLProgram*, GC3Denum pname);
182 String getProgramInfoLog(WebGLProgram*);
183 WebGLGetInfo getRenderbufferParameter(GC3Denum target, GC3Denum pname);
184 WebGLGetInfo getShaderParameter(WebGLShader*, GC3Denum pname);
185 String getShaderInfoLog(WebGLShader*);
186 PassRefPtr<WebGLShaderPrecisionFormat> getShaderPrecisionFormat(GC3Denum shaderType, GC3Denum precisionType);
187 String getShaderSource(WebGLShader*);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100188 Vector<String> getSupportedExtensions();
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100189 WebGLGetInfo getTexParameter(GC3Denum target, GC3Denum pname);
190 WebGLGetInfo getUniform(WebGLProgram*, const WebGLUniformLocation*);
191 PassRefPtr<WebGLUniformLocation> getUniformLocation(WebGLProgram*, const String&);
192 WebGLGetInfo getVertexAttrib(GC3Duint index, GC3Denum pname);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100193 long long getVertexAttribOffset(GC3Duint index, GC3Denum pname);
194
195 void hint(GC3Denum target, GC3Denum mode);
196 GC3Dboolean isBuffer(WebGLBuffer*);
197 bool isContextLost();
198 GC3Dboolean isEnabled(GC3Denum cap);
199 GC3Dboolean isFramebuffer(WebGLFramebuffer*);
200 GC3Dboolean isProgram(WebGLProgram*);
201 GC3Dboolean isRenderbuffer(WebGLRenderbuffer*);
202 GC3Dboolean isShader(WebGLShader*);
203 GC3Dboolean isTexture(WebGLTexture*);
204
205 void lineWidth(GC3Dfloat);
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100206 void linkProgram(WebGLProgram*);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100207 void pixelStorei(GC3Denum pname, GC3Dint param);
208 void polygonOffset(GC3Dfloat factor, GC3Dfloat units);
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100209 void readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, ArrayBufferView* pixels);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100210 void renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height);
211 void sampleCoverage(GC3Dfloat value, GC3Dboolean invert);
212 void scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100213 void shaderSource(WebGLShader*, const String&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100214 void stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask);
215 void stencilFuncSeparate(GC3Denum face, GC3Denum func, GC3Dint ref, GC3Duint mask);
216 void stencilMask(GC3Duint);
217 void stencilMaskSeparate(GC3Denum face, GC3Duint mask);
218 void stencilOp(GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
219 void stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zfail, GC3Denum zpass);
220
221 void texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat,
Ben Murdochdf957042013-08-06 11:01:27 +0100222 GC3Dsizei width, GC3Dsizei height, GC3Dint border,
223 GC3Denum format, GC3Denum type, ArrayBufferView*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100224 void texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat,
Ben Murdochdf957042013-08-06 11:01:27 +0100225 GC3Denum format, GC3Denum type, ImageData*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100226 void texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat,
Ben Murdochdf957042013-08-06 11:01:27 +0100227 GC3Denum format, GC3Denum type, HTMLImageElement*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100228 void texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat,
Ben Murdochdf957042013-08-06 11:01:27 +0100229 GC3Denum format, GC3Denum type, HTMLCanvasElement*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100230 void texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat,
Ben Murdochdf957042013-08-06 11:01:27 +0100231 GC3Denum format, GC3Denum type, HTMLVideoElement*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100232
233 void texParameterf(GC3Denum target, GC3Denum pname, GC3Dfloat param);
234 void texParameteri(GC3Denum target, GC3Denum pname, GC3Dint param);
235
236 void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset,
Ben Murdochdf957042013-08-06 11:01:27 +0100237 GC3Dsizei width, GC3Dsizei height,
238 GC3Denum format, GC3Denum type, ArrayBufferView*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100239 void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset,
Ben Murdochdf957042013-08-06 11:01:27 +0100240 GC3Denum format, GC3Denum type, ImageData*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100241 void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset,
Ben Murdochdf957042013-08-06 11:01:27 +0100242 GC3Denum format, GC3Denum type, HTMLImageElement*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100243 void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset,
Ben Murdochdf957042013-08-06 11:01:27 +0100244 GC3Denum format, GC3Denum type, HTMLCanvasElement*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100245 void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset,
Ben Murdochdf957042013-08-06 11:01:27 +0100246 GC3Denum format, GC3Denum type, HTMLVideoElement*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100247
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100248 void uniform1f(const WebGLUniformLocation*, GC3Dfloat x);
249 void uniform1fv(const WebGLUniformLocation*, Float32Array* v);
250 void uniform1fv(const WebGLUniformLocation*, GC3Dfloat* v, GC3Dsizei);
251 void uniform1i(const WebGLUniformLocation*, GC3Dint x);
252 void uniform1iv(const WebGLUniformLocation*, Int32Array* v);
253 void uniform1iv(const WebGLUniformLocation*, GC3Dint* v, GC3Dsizei);
254 void uniform2f(const WebGLUniformLocation*, GC3Dfloat x, GC3Dfloat y);
255 void uniform2fv(const WebGLUniformLocation*, Float32Array* v);
256 void uniform2fv(const WebGLUniformLocation*, GC3Dfloat* v, GC3Dsizei);
257 void uniform2i(const WebGLUniformLocation*, GC3Dint x, GC3Dint y);
258 void uniform2iv(const WebGLUniformLocation*, Int32Array* v);
259 void uniform2iv(const WebGLUniformLocation*, GC3Dint* v, GC3Dsizei);
260 void uniform3f(const WebGLUniformLocation*, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
261 void uniform3fv(const WebGLUniformLocation*, Float32Array* v);
262 void uniform3fv(const WebGLUniformLocation*, GC3Dfloat* v, GC3Dsizei);
263 void uniform3i(const WebGLUniformLocation*, GC3Dint x, GC3Dint y, GC3Dint z);
264 void uniform3iv(const WebGLUniformLocation*, Int32Array* v);
265 void uniform3iv(const WebGLUniformLocation*, GC3Dint* v, GC3Dsizei);
266 void uniform4f(const WebGLUniformLocation*, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
267 void uniform4fv(const WebGLUniformLocation*, Float32Array* v);
268 void uniform4fv(const WebGLUniformLocation*, GC3Dfloat* v, GC3Dsizei);
269 void uniform4i(const WebGLUniformLocation*, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w);
270 void uniform4iv(const WebGLUniformLocation*, Int32Array* v);
271 void uniform4iv(const WebGLUniformLocation*, GC3Dint* v, GC3Dsizei);
272 void uniformMatrix2fv(const WebGLUniformLocation*, GC3Dboolean transpose, Float32Array* value);
273 void uniformMatrix2fv(const WebGLUniformLocation*, GC3Dboolean transpose, GC3Dfloat* value, GC3Dsizei);
274 void uniformMatrix3fv(const WebGLUniformLocation*, GC3Dboolean transpose, Float32Array* value);
275 void uniformMatrix3fv(const WebGLUniformLocation*, GC3Dboolean transpose, GC3Dfloat* value, GC3Dsizei);
276 void uniformMatrix4fv(const WebGLUniformLocation*, GC3Dboolean transpose, Float32Array* value);
277 void uniformMatrix4fv(const WebGLUniformLocation*, GC3Dboolean transpose, GC3Dfloat* value, GC3Dsizei);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100278
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100279 void useProgram(WebGLProgram*);
280 void validateProgram(WebGLProgram*);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100281
282 void vertexAttrib1f(GC3Duint index, GC3Dfloat x);
283 void vertexAttrib1fv(GC3Duint index, Float32Array* values);
Ben Murdochdf957042013-08-06 11:01:27 +0100284 void vertexAttrib1fv(GC3Duint index, GC3Dfloat* values, GC3Dsizei);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100285 void vertexAttrib2f(GC3Duint index, GC3Dfloat x, GC3Dfloat y);
286 void vertexAttrib2fv(GC3Duint index, Float32Array* values);
Ben Murdochdf957042013-08-06 11:01:27 +0100287 void vertexAttrib2fv(GC3Duint index, GC3Dfloat* values, GC3Dsizei);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100288 void vertexAttrib3f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z);
289 void vertexAttrib3fv(GC3Duint index, Float32Array* values);
Ben Murdochdf957042013-08-06 11:01:27 +0100290 void vertexAttrib3fv(GC3Duint index, GC3Dfloat* values, GC3Dsizei);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100291 void vertexAttrib4f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w);
292 void vertexAttrib4fv(GC3Duint index, Float32Array* values);
Ben Murdochdf957042013-08-06 11:01:27 +0100293 void vertexAttrib4fv(GC3Duint index, GC3Dfloat* values, GC3Dsizei);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100294 void vertexAttribPointer(GC3Duint index, GC3Dint size, GC3Denum type, GC3Dboolean normalized,
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100295 GC3Dsizei stride, long long offset);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100296
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100297 void vertexAttribDivisorANGLE(GC3Duint index, GC3Duint divisor);
298
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100299 void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
300
301 // WEBKIT_lose_context support
302 enum LostContextMode {
303 // Lost context occurred at the graphics system level.
304 RealLostContext,
305
306 // Lost context provoked by WEBKIT_lose_context.
Torne (Richard Coles)e5249552013-05-15 11:35:13 +0100307 SyntheticLostContext,
308
309 // A synthetic lost context that should attempt to recover automatically
310 AutoRecoverSyntheticLostContext
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100311 };
312 void forceLostContext(LostContextMode);
313 void forceRestoreContext();
314 void loseContextImpl(LostContextMode);
315
316 GraphicsContext3D* graphicsContext3D() const { return m_context.get(); }
317 WebGLContextGroup* contextGroup() const { return m_contextGroup.get(); }
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100318 virtual WebKit::WebLayer* platformLayer() const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100319
320 void reshape(int width, int height);
321
322 void markLayerComposited();
323 virtual void paintRenderingResultsToCanvas();
324 virtual PassRefPtr<ImageData> paintRenderingResultsToImageData();
325
326 void removeSharedObject(WebGLSharedObject*);
327 void removeContextObject(WebGLContextObject*);
Ben Murdoch02772c62013-07-26 10:21:05 +0100328
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +0100329 unsigned maxVertexAttribs() const { return m_maxVertexAttribs; }
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100330
331 // ActiveDOMObject notifications
332 virtual bool hasPendingActivity() const;
333 virtual void stop();
334
335 private:
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100336 friend class WebGLDrawBuffers;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100337 friend class WebGLFramebuffer;
338 friend class WebGLObject;
339 friend class OESVertexArrayObject;
340 friend class WebGLDebugShaders;
341 friend class WebGLCompressedTextureATC;
342 friend class WebGLCompressedTexturePVRTC;
343 friend class WebGLCompressedTextureS3TC;
344 friend class WebGLRenderingContextErrorMessageCallback;
345 friend class WebGLVertexArrayObjectOES;
346
Torne (Richard Coles)e5249552013-05-15 11:35:13 +0100347 WebGLRenderingContext(HTMLCanvasElement*, PassRefPtr<GraphicsContext3D>, GraphicsContext3D::Attributes, GraphicsContext3D::Attributes);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100348 void initializeNewContext();
349 void setupFlags();
350
351 void addSharedObject(WebGLSharedObject*);
352 void addContextObject(WebGLContextObject*);
353 void detachAndRemoveAllObjects();
354
355 void destroyGraphicsContext3D();
356 void markContextChanged();
357
358 // Query if the GL implementation is NPOT strict.
359 bool isGLES2NPOTStrict() { return m_isGLES2NPOTStrict; }
360 // Query if depth_stencil buffer is supported.
361 bool isDepthStencilSupported() { return m_isDepthStencilSupported; }
362
363 // Helper to return the size in bytes of OpenGL data types
364 // like GL_FLOAT, GL_INT, etc.
365 unsigned int sizeInBytes(GC3Denum type);
366
367 // Check if each enabled vertex attribute is bound to a buffer.
368 bool validateRenderingState();
369
370 bool validateWebGLObject(const char*, WebGLObject*);
371
372 // Adds a compressed texture format.
373 void addCompressedTextureFormat(GC3Denum);
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100374 void removeAllCompressedTextureFormats();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100375
Ben Murdoch1fad5ca2013-08-07 11:05:11 +0100376 PassRefPtr<Image> videoFrameToImage(HTMLVideoElement*, BackingStoreCopy);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100377
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100378 WebGLRenderbuffer* ensureEmulatedStencilBuffer(GC3Denum target, WebGLRenderbuffer*);
379
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100380 RefPtr<GraphicsContext3D> m_context;
381 RefPtr<WebGLContextGroup> m_contextGroup;
382
383 // Structure for rendering to a DrawingBuffer, instead of directly
384 // to the back-buffer of m_context.
385 RefPtr<DrawingBuffer> m_drawingBuffer;
386
387 // Dispatches a context lost event once it is determined that one is needed.
388 // This is used both for synthetic and real context losses. For real ones, it's
389 // likely that there's no JavaScript on the stack, but that might be dependent
390 // on how exactly the platform discovers that the context was lost. For better
391 // portability we always defer the dispatch of the event.
392 Timer<WebGLRenderingContext> m_dispatchContextLostEventTimer;
393 bool m_restoreAllowed;
394 Timer<WebGLRenderingContext> m_restoreTimer;
395
396 bool m_needsUpdate;
397 bool m_markedCanvasDirty;
398 HashSet<WebGLContextObject*> m_contextObjects;
399
400 // List of bound VBO's. Used to maintain info about sizes for ARRAY_BUFFER and stored values for ELEMENT_ARRAY_BUFFER
401 RefPtr<WebGLBuffer> m_boundArrayBuffer;
Ben Murdoch02772c62013-07-26 10:21:05 +0100402
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100403 RefPtr<WebGLVertexArrayObjectOES> m_defaultVertexArrayObject;
404 RefPtr<WebGLVertexArrayObjectOES> m_boundVertexArrayObject;
405 void setBoundVertexArrayObject(PassRefPtr<WebGLVertexArrayObjectOES> arrayObject)
406 {
407 if (arrayObject)
408 m_boundVertexArrayObject = arrayObject;
409 else
410 m_boundVertexArrayObject = m_defaultVertexArrayObject;
411 }
Ben Murdoch02772c62013-07-26 10:21:05 +0100412
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100413 class VertexAttribValue {
414 public:
415 VertexAttribValue()
416 {
417 initValue();
418 }
Ben Murdoch02772c62013-07-26 10:21:05 +0100419
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100420 void initValue()
421 {
422 value[0] = 0.0f;
423 value[1] = 0.0f;
424 value[2] = 0.0f;
425 value[3] = 1.0f;
426 }
Ben Murdoch02772c62013-07-26 10:21:05 +0100427
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100428 GC3Dfloat value[4];
429 };
430 Vector<VertexAttribValue> m_vertexAttribValue;
431 unsigned m_maxVertexAttribs;
432 RefPtr<WebGLBuffer> m_vertexAttrib0Buffer;
433 long m_vertexAttrib0BufferSize;
434 GC3Dfloat m_vertexAttrib0BufferValue[4];
435 bool m_forceAttrib0BufferRefill;
436 bool m_vertexAttrib0UsedBefore;
437
438 RefPtr<WebGLProgram> m_currentProgram;
439 RefPtr<WebGLFramebuffer> m_framebufferBinding;
440 RefPtr<WebGLRenderbuffer> m_renderbufferBinding;
441 class TextureUnitState {
442 public:
443 RefPtr<WebGLTexture> m_texture2DBinding;
444 RefPtr<WebGLTexture> m_textureCubeMapBinding;
445 };
446 Vector<TextureUnitState> m_textureUnits;
447 unsigned long m_activeTextureUnit;
448
449 RefPtr<WebGLTexture> m_blackTexture2D;
450 RefPtr<WebGLTexture> m_blackTextureCubeMap;
451
452 Vector<GC3Denum> m_compressedTextureFormats;
453
454 // Fixed-size cache of reusable image buffers for video texImage2D calls.
455 class LRUImageBufferCache {
456 public:
457 LRUImageBufferCache(int capacity);
458 // The pointer returned is owned by the image buffer map.
459 ImageBuffer* imageBuffer(const IntSize& size);
460 private:
461 void bubbleToFront(int idx);
462 OwnArrayPtr<OwnPtr<ImageBuffer> > m_buffers;
463 int m_capacity;
464 };
465 LRUImageBufferCache m_videoCache;
466
467 GC3Dint m_maxTextureSize;
468 GC3Dint m_maxCubeMapTextureSize;
469 GC3Dint m_maxRenderbufferSize;
470 GC3Dint m_maxViewportDims[2];
471 GC3Dint m_maxTextureLevel;
472 GC3Dint m_maxCubeMapTextureLevel;
473
474 GC3Dint m_maxDrawBuffers;
475 GC3Dint m_maxColorAttachments;
476 GC3Denum m_backDrawBuffer;
477 bool m_drawBuffersWebGLRequirementsChecked;
478 bool m_drawBuffersSupported;
479
480 GC3Dint m_packAlignment;
481 GC3Dint m_unpackAlignment;
482 bool m_unpackFlipY;
483 bool m_unpackPremultiplyAlpha;
484 GC3Denum m_unpackColorspaceConversion;
485 bool m_contextLost;
486 LostContextMode m_contextLostMode;
487 GraphicsContext3D::Attributes m_attributes;
Torne (Richard Coles)e5249552013-05-15 11:35:13 +0100488 GraphicsContext3D::Attributes m_requestedAttributes;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100489
490 bool m_layerCleared;
491 GC3Dfloat m_clearColor[4];
492 bool m_scissorEnabled;
493 GC3Dfloat m_clearDepth;
494 GC3Dint m_clearStencil;
495 GC3Dboolean m_colorMask[4];
496 GC3Dboolean m_depthMask;
497
498 bool m_stencilEnabled;
499 GC3Duint m_stencilMask, m_stencilMaskBack;
500 GC3Dint m_stencilFuncRef, m_stencilFuncRefBack; // Note that these are the user specified values, not the internal clamped value.
501 GC3Duint m_stencilFuncMask, m_stencilFuncMaskBack;
502
503 bool m_isGLES2NPOTStrict;
504 bool m_isDepthStencilSupported;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100505
506 bool m_synthesizedErrorsToConsole;
507 int m_numGLErrorsToConsoleAllowed;
508
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100509 bool m_multisamplingAllowed;
510 bool m_multisamplingObserverRegistered;
511
512 GC3Duint m_onePlusMaxEnabledAttribIndex;
513 unsigned long m_onePlusMaxNonDefaultTextureUnit;
514
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100515 // Enabled extension objects.
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100516 RefPtr<ANGLEInstancedArrays> m_angleInstancedArrays;
517 RefPtr<EXTFragDepth> m_extFragDepth;
518 RefPtr<EXTTextureFilterAnisotropic> m_extTextureFilterAnisotropic;
519 RefPtr<OESTextureFloat> m_oesTextureFloat;
520 RefPtr<OESTextureFloatLinear> m_oesTextureFloatLinear;
521 RefPtr<OESTextureHalfFloat> m_oesTextureHalfFloat;
522 RefPtr<OESTextureHalfFloatLinear> m_oesTextureHalfFloatLinear;
523 RefPtr<OESStandardDerivatives> m_oesStandardDerivatives;
524 RefPtr<OESVertexArrayObject> m_oesVertexArrayObject;
525 RefPtr<OESElementIndexUint> m_oesElementIndexUint;
526 RefPtr<WebGLLoseContext> m_webglLoseContext;
527 RefPtr<WebGLDebugRendererInfo> m_webglDebugRendererInfo;
528 RefPtr<WebGLDebugShaders> m_webglDebugShaders;
529 RefPtr<WebGLDrawBuffers> m_webglDrawBuffers;
530 RefPtr<WebGLCompressedTextureATC> m_webglCompressedTextureATC;
531 RefPtr<WebGLCompressedTexturePVRTC> m_webglCompressedTexturePVRTC;
532 RefPtr<WebGLCompressedTextureS3TC> m_webglCompressedTextureS3TC;
533 RefPtr<WebGLDepthTexture> m_webglDepthTexture;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100534
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100535 enum ExtensionFlags {
536 ApprovedExtension = 0x00,
537 DraftExtension = 0x01,
538 PrivilegedExtension = 0x02,
539 PrefixedExtension = 0x04,
540 };
541
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100542 class ExtensionTracker {
543 public:
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100544 ExtensionTracker(ExtensionFlags flags, const char** prefixes)
545 : m_privileged(flags & PrivilegedExtension)
546 , m_draft(flags & DraftExtension)
547 , m_prefixed(flags & PrefixedExtension)
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100548 , m_prefixes(prefixes)
549 {
550 }
551
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100552 virtual ~ExtensionTracker()
553 {
554 }
555
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +0100556 bool prefixed() const
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100557 {
558 return m_prefixed;
559 }
560
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +0100561 bool privileged() const
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100562 {
563 return m_privileged;
564 }
565
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +0100566 bool draft() const
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100567 {
568 return m_draft;
569 }
570
571 bool matchesNameWithPrefixes(const String&) const;
572
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100573 virtual PassRefPtr<WebGLExtension> getExtension(WebGLRenderingContext*) const = 0;
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100574 virtual bool supported(WebGLRenderingContext*) const = 0;
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +0100575 virtual const char* extensionName() const = 0;
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100576 virtual void loseExtension() = 0;
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100577
578 private:
579 bool m_privileged;
580 bool m_draft;
581 bool m_prefixed;
582 const char** m_prefixes;
583 };
584
585 template <typename T>
586 class TypedExtensionTracker : public ExtensionTracker {
587 public:
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100588 TypedExtensionTracker(RefPtr<T>& extensionField, ExtensionFlags flags, const char** prefixes)
589 : ExtensionTracker(flags, prefixes)
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100590 , m_extensionField(extensionField)
591 {
592 }
593
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100594 ~TypedExtensionTracker()
595 {
596 if (m_extensionField) {
597 m_extensionField->lose(true);
598 m_extensionField = 0;
599 }
600 }
601
602 virtual PassRefPtr<WebGLExtension> getExtension(WebGLRenderingContext* context) const
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100603 {
604 if (!m_extensionField)
605 m_extensionField = T::create(context);
606
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100607 return m_extensionField;
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100608 }
609
610 virtual bool supported(WebGLRenderingContext* context) const
611 {
612 return T::supported(context);
613 }
614
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +0100615 virtual const char* extensionName() const
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100616 {
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +0100617 return T::extensionName();
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100618 }
619
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100620 virtual void loseExtension()
621 {
622 if (m_extensionField) {
623 m_extensionField->lose(false);
624 if (m_extensionField->isLost())
625 m_extensionField = 0;
626 }
627 }
628
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100629 private:
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100630 RefPtr<T>& m_extensionField;
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100631 };
632
633 Vector<ExtensionTracker*> m_extensions;
634
635 template <typename T>
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100636 void registerExtension(RefPtr<T>& extensionPtr, ExtensionFlags flags = ApprovedExtension, const char** prefixes = 0)
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100637 {
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100638 m_extensions.append(new TypedExtensionTracker<T>(extensionPtr, flags, prefixes));
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100639 }
640
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100641 // Errors raised by synthesizeGLError() while the context is lost.
642 Vector<GC3Denum> lost_context_errors_;
643
644 // Helpers for getParameter and others
645 WebGLGetInfo getBooleanParameter(GC3Denum);
646 WebGLGetInfo getBooleanArrayParameter(GC3Denum);
647 WebGLGetInfo getFloatParameter(GC3Denum);
648 WebGLGetInfo getIntParameter(GC3Denum);
649 WebGLGetInfo getUnsignedIntParameter(GC3Denum);
650 WebGLGetInfo getWebGLFloatArrayParameter(GC3Denum);
651 WebGLGetInfo getWebGLIntArrayParameter(GC3Denum);
652
653 // Clear the backbuffer if it was composited since the last operation.
654 // clearMask is set to the bitfield of any clear that would happen anyway at this time
655 // and the function returns true if that clear is now unnecessary.
656 bool clearIfComposited(GC3Dbitfield clearMask = 0);
657
658 // Helper to restore state that clearing the framebuffer may destroy.
659 void restoreStateAfterClear();
660
Ben Murdochdf957042013-08-06 11:01:27 +0100661 void texImage2DBase(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels, ExceptionState&);
662 void texImage2DImpl(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Denum format, GC3Denum type, Image*, GraphicsContext3D::ImageHtmlDomSource, bool flipY, bool premultiplyAlpha, ExceptionState&);
663 void texSubImage2DBase(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels, ExceptionState&);
664 void texSubImage2DImpl(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Denum format, GC3Denum type, Image*, GraphicsContext3D::ImageHtmlDomSource, bool flipY, bool premultiplyAlpha, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100665
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +0100666 void handleTextureCompleteness(const char*, bool);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100667 void createFallbackBlackTextures1x1();
668
669 // Helper function for copyTex{Sub}Image, check whether the internalformat
670 // and the color buffer format of the current bound framebuffer combination
671 // is valid.
672 bool isTexInternalFormatColorBufferCombinationValid(GC3Denum texInternalFormat,
673 GC3Denum colorBufferFormat);
674
675 // Helper function to get the bound framebuffer's color buffer format.
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +0100676 GC3Denum boundFramebufferColorFormat();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100677
678 // Helper function to get the bound framebuffer's width.
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +0100679 int boundFramebufferWidth();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100680
681 // Helper function to get the bound framebuffer's height.
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +0100682 int boundFramebufferHeight();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100683
684 // Helper function to verify limits on the length of uniform and attribute locations.
685 bool validateLocationLength(const char* functionName, const String&);
686
687 // Helper function to check if size is non-negative.
688 // Generate GL error and return false for negative inputs; otherwise, return true.
689 bool validateSize(const char* functionName, GC3Dint x, GC3Dint y);
690
691 // Helper function to check if all characters in the string belong to the
692 // ASCII subset as defined in GLSL ES 1.0 spec section 3.1.
693 bool validateString(const char* functionName, const String&);
694
695 // Helper function to check target and texture bound to the target.
696 // Generate GL errors and return 0 if target is invalid or texture bound is
697 // null. Otherwise, return the texture bound to the target.
698 WebGLTexture* validateTextureBinding(const char* functionName, GC3Denum target, bool useSixEnumsForCubeMap);
699
700 // Helper function to check input format/type for functions {copy}Tex{Sub}Image.
701 // Generates GL error and returns false if parameters are invalid.
702 bool validateTexFuncFormatAndType(const char* functionName, GC3Denum format, GC3Denum type, GC3Dint level);
703
704 // Helper function to check input level for functions {copy}Tex{Sub}Image.
705 // Generates GL error and returns false if level is invalid.
706 bool validateTexFuncLevel(const char* functionName, GC3Denum target, GC3Dint level);
707
708 enum TexFuncValidationFunctionType {
709 NotTexSubImage2D,
710 TexSubImage2D,
711 };
712
713 enum TexFuncValidationSourceType {
714 SourceArrayBufferView,
715 SourceImageData,
716 SourceHTMLImageElement,
717 SourceHTMLCanvasElement,
718 SourceHTMLVideoElement,
719 };
720
721 // Helper function for tex{Sub}Image2D to check if the input format/type/level/target/width/height/border/xoffset/yoffset are valid.
722 // Otherwise, it would return quickly without doing other work.
723 bool validateTexFunc(const char* functionName, TexFuncValidationFunctionType, TexFuncValidationSourceType, GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width,
724 GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint xoffset, GC3Dint yoffset);
725
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100726 // Helper function to check input width and height for functions {copy, compressed}Tex{Sub}Image.
727 // Generates GL error and returns false if width or height is invalid.
728 bool validateTexFuncDimensions(const char* functionName, TexFuncValidationFunctionType,
729 GC3Denum target, GC3Dint level, GC3Dsizei width, GC3Dsizei height);
730
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100731 // Helper function to check input parameters for functions {copy}Tex{Sub}Image.
732 // Generates GL error and returns false if parameters are invalid.
733 bool validateTexFuncParameters(const char* functionName,
734 TexFuncValidationFunctionType,
735 GC3Denum target, GC3Dint level,
736 GC3Denum internalformat,
737 GC3Dsizei width, GC3Dsizei height, GC3Dint border,
738 GC3Denum format, GC3Denum type);
739
740 enum NullDisposition {
741 NullAllowed,
742 NullNotAllowed
743 };
744
745 // Helper function to validate that the given ArrayBufferView
746 // is of the correct type and contains enough data for the texImage call.
747 // Generates GL error and returns false if parameters are invalid.
748 bool validateTexFuncData(const char* functionName, GC3Dint level,
749 GC3Dsizei width, GC3Dsizei height,
750 GC3Denum format, GC3Denum type,
751 ArrayBufferView* pixels,
752 NullDisposition);
753
754 // Helper function to validate a given texture format is settable as in
755 // you can supply data to texImage2D, or call texImage2D, copyTexImage2D and
756 // copyTexSubImage2D.
757 // Generates GL error and returns false if the format is not settable.
758 bool validateSettableTexFormat(const char* functionName, GC3Denum format);
759
760 // Helper function to validate compressed texture data is correct size
761 // for the given format and dimensions.
762 bool validateCompressedTexFuncData(const char* functionName,
763 GC3Dsizei width, GC3Dsizei height,
764 GC3Denum format, ArrayBufferView* pixels);
765
766 // Helper function for validating compressed texture formats.
767 bool validateCompressedTexFormat(GC3Denum format);
768
769 // Helper function to validate compressed texture dimensions are valid for
770 // the given format.
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100771 bool validateCompressedTexDimensions(const char* functionName, TexFuncValidationFunctionType, GC3Denum target, GC3Dint level, GC3Dsizei width, GC3Dsizei height, GC3Denum format);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100772
773 // Helper function to validate compressed texture dimensions are valid for
774 // the given format.
775 bool validateCompressedTexSubDimensions(const char* functionName, GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset,
776 GC3Dsizei width, GC3Dsizei height, GC3Denum format, WebGLTexture*);
777
778 // Helper function to validate mode for draw{Arrays/Elements}.
779 bool validateDrawMode(const char* functionName, GC3Denum);
780
781 // Helper function to validate if front/back stencilMask and stencilFunc settings are the same.
782 bool validateStencilSettings(const char* functionName);
783
Torne (Richard Coles)f5e4ad52013-08-05 13:57:57 +0100784 // Helper function to validate stencil or depth func.
785 bool validateStencilOrDepthFunc(const char* functionName, GC3Denum);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100786
787 // Helper function for texParameterf and texParameteri.
788 void texParameter(GC3Denum target, GC3Denum pname, GC3Dfloat parami, GC3Dint paramf, bool isFloat);
789
790 // Helper function to print GL errors to console.
791 void printGLErrorToConsole(const String&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100792
793 // Helper function to print warnings to console. Currently
794 // used only to warn about use of obsolete functions.
795 void printWarningToConsole(const String&);
796
797 // Helper function to validate input parameters for framebuffer functions.
798 // Generate GL error if parameters are illegal.
799 bool validateFramebufferFuncParameters(const char* functionName, GC3Denum target, GC3Denum attachment);
800
801 // Helper function to validate blend equation mode.
802 bool validateBlendEquation(const char* functionName, GC3Denum);
803
804 // Helper function to validate blend func factors.
805 bool validateBlendFuncFactors(const char* functionName, GC3Denum src, GC3Denum dst);
806
807 // Helper function to validate a GL capability.
808 bool validateCapability(const char* functionName, GC3Denum);
809
810 // Helper function to validate input parameters for uniform functions.
811 bool validateUniformParameters(const char* functionName, const WebGLUniformLocation*, Float32Array*, GC3Dsizei mod);
812 bool validateUniformParameters(const char* functionName, const WebGLUniformLocation*, Int32Array*, GC3Dsizei mod);
813 bool validateUniformParameters(const char* functionName, const WebGLUniformLocation*, void*, GC3Dsizei, GC3Dsizei mod);
814 bool validateUniformMatrixParameters(const char* functionName, const WebGLUniformLocation*, GC3Dboolean transpose, Float32Array*, GC3Dsizei mod);
815 bool validateUniformMatrixParameters(const char* functionName, const WebGLUniformLocation*, GC3Dboolean transpose, void*, GC3Dsizei, GC3Dsizei mod);
816
817 // Helper function to validate parameters for bufferData.
818 // Return the current bound buffer to target, or 0 if parameters are invalid.
819 WebGLBuffer* validateBufferDataParameters(const char* functionName, GC3Denum target, GC3Denum usage);
820
821 // Helper function for tex{Sub}Image2D to make sure image is ready and wouldn't taint Origin.
Ben Murdochdf957042013-08-06 11:01:27 +0100822 bool validateHTMLImageElement(const char* functionName, HTMLImageElement*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100823
824 // Helper function for tex{Sub}Image2D to make sure canvas is ready and wouldn't taint Origin.
Ben Murdochdf957042013-08-06 11:01:27 +0100825 bool validateHTMLCanvasElement(const char* functionName, HTMLCanvasElement*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100826
827 // Helper function for tex{Sub}Image2D to make sure video is ready wouldn't taint Origin.
Ben Murdochdf957042013-08-06 11:01:27 +0100828 bool validateHTMLVideoElement(const char* functionName, HTMLVideoElement*, ExceptionState&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100829
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100830 // Helper function to validate drawArrays(Instanced) calls
831 bool validateDrawArrays(const char* functionName, GC3Denum mode, GC3Dint first, GC3Dsizei count);
832
833 // Helper function to validate drawElements(Instanced) calls
834 bool validateDrawElements(const char* functionName, GC3Denum mode, GC3Dsizei count, GC3Denum type, long long offset);
835
836 // Helper function to validate draw*Instanced calls
837 bool validateDrawInstanced(const char* functionName, GC3Dsizei primcount);
838
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100839 // Helper functions for vertexAttribNf{v}.
840 void vertexAttribfImpl(const char* functionName, GC3Duint index, GC3Dsizei expectedSize, GC3Dfloat, GC3Dfloat, GC3Dfloat, GC3Dfloat);
841 void vertexAttribfvImpl(const char* functionName, GC3Duint index, Float32Array*, GC3Dsizei expectedSize);
842 void vertexAttribfvImpl(const char* functionName, GC3Duint index, GC3Dfloat*, GC3Dsizei, GC3Dsizei expectedSize);
843
844 // Helper function for delete* (deleteBuffer, deleteProgram, etc) functions.
845 // Return false if caller should return without further processing.
846 bool deleteObject(WebGLObject*);
847
848 // Helper function for bind* (bindBuffer, bindTexture, etc) and useProgram.
849 // If the object has already been deleted, set deleted to true upon return.
850 // Return false if caller should return without further processing.
851 bool checkObjectToBeBound(const char* functionName, WebGLObject*, bool& deleted);
852
853 void dispatchContextLostEvent(Timer<WebGLRenderingContext>*);
854 // Helper for restoration after context lost.
855 void maybeRestoreContext(Timer<WebGLRenderingContext>*);
856
857 // Determine if we are running privileged code in the browser, for example,
858 // a Safari or Chrome extension.
859 bool allowPrivilegedExtensions() const;
860
861 enum ConsoleDisplayPreference {
862 DisplayInConsole,
863 DontDisplayInConsole
864 };
865
866 // Wrapper for GraphicsContext3D::synthesizeGLError that sends a message
867 // to the JavaScript console.
868 void synthesizeGLError(GC3Denum, const char* functionName, const char* description, ConsoleDisplayPreference = DisplayInConsole);
Ben Murdoche69819b2013-07-17 14:56:49 +0100869 void emitGLWarning(const char* function, const char* reason);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100870
871 String ensureNotNull(const String&) const;
872
873 // Enable or disable stencil test based on user setting and
874 // whether the current FBO has a stencil buffer.
875 void applyStencilTest();
876
877 // Helper for enabling or disabling a capability.
878 void enableOrDisable(GC3Denum capability, bool enable);
879
880 // Clamp the width and height to GL_MAX_VIEWPORT_DIMS.
881 IntSize clampedCanvasSize();
882
883 // First time called, if EXT_draw_buffers is supported, query the value; otherwise return 0.
884 // Later, return the cached value.
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +0100885 GC3Dint maxDrawBuffers();
886 GC3Dint maxColorAttachments();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100887
888 void setBackDrawBuffer(GC3Denum);
889
890 void restoreCurrentFramebuffer();
891 void restoreCurrentTexture2D();
892
Torne (Richard Coles)e5249552013-05-15 11:35:13 +0100893 virtual void multisamplingChanged(bool);
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100894
895 void findNewMaxEnabledAttribIndex();
896 void findNewMaxNonDefaultTextureUnit();
Torne (Richard Coles)e5249552013-05-15 11:35:13 +0100897
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100898 friend class WebGLStateRestorer;
899 friend class WebGLRenderingContextEvictionManager;
900
901 static Vector<WebGLRenderingContext*>& activeContexts();
902 static Vector<WebGLRenderingContext*>& forciblyEvictedContexts();
903
904 static void activateContext(WebGLRenderingContext*);
905 static void deactivateContext(WebGLRenderingContext*, bool addToInactiveList);
906 static void willDestroyContext(WebGLRenderingContext*);
907 static void forciblyLoseOldestContext(const String& reason);
Torne (Richard Coles)9bbd2f52013-09-19 22:37:05 +0100908 // Return the least recently used context's position in the active context vector.
909 // If the vector is empty, return the maximum allowed active context number.
910 static size_t oldestContextIndex();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100911 static IntSize oldestContextSize();
912};
913
914} // namespace WebCore
915
916#endif