OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * 1. Redistributions of source code must retain the above copyright | |
8 * notice, this list of conditions and the following disclaimer. | |
9 * 2. Redistributions in binary form must reproduce the above copyright | |
10 * notice, this list of conditions and the following disclaimer in the | |
11 * documentation and/or other materials provided with the distribution. | |
12 * | |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 */ | |
25 | |
26 #ifndef SKY_ENGINE_CORE_HTML_CANVAS_WEBGLRENDERINGCONTEXTBASE_H_ | |
27 #define SKY_ENGINE_CORE_HTML_CANVAS_WEBGLRENDERINGCONTEXTBASE_H_ | |
28 | |
29 #include "sky/engine/bindings/nullable.h" | |
30 #include "sky/engine/core/dom/ActiveDOMObject.h" | |
31 #include "sky/engine/core/html/canvas/CanvasRenderingContext.h" | |
32 #include "sky/engine/core/html/canvas/WebGLExtensionName.h" | |
33 #include "sky/engine/core/html/canvas/WebGLGetInfo.h" | |
34 #include "sky/engine/core/page/Page.h" | |
35 #include "sky/engine/core/rendering/RenderBoxModelObject.h" | |
36 #include "sky/engine/platform/Timer.h" | |
37 #include "sky/engine/platform/graphics/GraphicsTypes3D.h" | |
38 #include "sky/engine/platform/graphics/ImageBuffer.h" | |
39 #include "sky/engine/platform/graphics/gpu/DrawingBuffer.h" | |
40 #include "sky/engine/platform/graphics/gpu/Extensions3DUtil.h" | |
41 #include "sky/engine/platform/graphics/gpu/WebGLImageConversion.h" | |
42 #include "sky/engine/public/platform/WebGraphicsContext3D.h" | |
43 #include "sky/engine/wtf/Float32Array.h" | |
44 #include "sky/engine/wtf/Int32Array.h" | |
45 #include "sky/engine/wtf/OwnPtr.h" | |
46 #include "sky/engine/wtf/text/WTFString.h" | |
47 | |
48 namespace blink { | |
49 class WebLayer; | |
50 } | |
51 | |
52 namespace blink { | |
53 | |
54 class ANGLEInstancedArrays; | |
55 class EXTBlendMinMax; | |
56 class EXTFragDepth; | |
57 class EXTShaderTextureLOD; | |
58 class EXTTextureFilterAnisotropic; | |
59 class ExceptionState; | |
60 class HTMLImageElement; | |
61 class ImageBuffer; | |
62 class ImageData; | |
63 class IntSize; | |
64 class OESElementIndexUint; | |
65 class OESStandardDerivatives; | |
66 class OESTextureFloat; | |
67 class OESTextureFloatLinear; | |
68 class OESTextureHalfFloat; | |
69 class OESTextureHalfFloatLinear; | |
70 class OESVertexArrayObject; | |
71 class WebGLActiveInfo; | |
72 class WebGLBuffer; | |
73 class WebGLCompressedTextureATC; | |
74 class WebGLCompressedTextureETC1; | |
75 class WebGLCompressedTexturePVRTC; | |
76 class WebGLCompressedTextureS3TC; | |
77 class WebGLContextAttributes; | |
78 class WebGLContextGroup; | |
79 class WebGLContextObject; | |
80 class WebGLDebugRendererInfo; | |
81 class WebGLDebugShaders; | |
82 class WebGLDepthTexture; | |
83 class WebGLDrawBuffers; | |
84 class WebGLExtension; | |
85 class WebGLFramebuffer; | |
86 class WebGLLoseContext; | |
87 class WebGLObject; | |
88 class WebGLProgram; | |
89 class WebGLRenderbuffer; | |
90 class WebGLShader; | |
91 class WebGLShaderPrecisionFormat; | |
92 class WebGLSharedObject; | |
93 class WebGLSharedWebGraphicsContext3D; | |
94 class WebGLTexture; | |
95 class WebGLUniformLocation; | |
96 class WebGLVertexArrayObjectOES; | |
97 | |
98 class WebGLRenderingContextLostCallback; | |
99 class WebGLRenderingContextErrorMessageCallback; | |
100 | |
101 class WebGLRenderingContextBase: public CanvasRenderingContext, public ActiveDOM
Object, public Page::MultisamplingChangedObserver { | |
102 public: | |
103 virtual ~WebGLRenderingContextBase(); | |
104 | |
105 virtual unsigned version() const = 0; | |
106 virtual String contextName() const = 0; | |
107 virtual void registerContextExtensions() = 0; | |
108 | |
109 static unsigned getWebGLVersion(const CanvasRenderingContext*); | |
110 | |
111 int drawingBufferWidth() const; | |
112 int drawingBufferHeight() const; | |
113 | |
114 void activeTexture(GLenum texture); | |
115 void attachShader(WebGLProgram*, WebGLShader*); | |
116 void bindAttribLocation(WebGLProgram*, GLuint index, const String& name); | |
117 void bindBuffer(GLenum target, WebGLBuffer*); | |
118 void bindFramebuffer(GLenum target, WebGLFramebuffer*); | |
119 void bindRenderbuffer(GLenum target, WebGLRenderbuffer*); | |
120 void bindTexture(GLenum target, WebGLTexture*); | |
121 void blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); | |
122 void blendEquation(GLenum mode); | |
123 void blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha); | |
124 void blendFunc(GLenum sfactor, GLenum dfactor); | |
125 void blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum
dstAlpha); | |
126 | |
127 void bufferData(GLenum target, long long size, GLenum usage); | |
128 void bufferData(GLenum target, ArrayBuffer* data, GLenum usage); | |
129 void bufferData(GLenum target, ArrayBufferView* data, GLenum usage); | |
130 void bufferSubData(GLenum target, long long offset, ArrayBuffer* data); | |
131 void bufferSubData(GLenum target, long long offset, ArrayBufferView* data); | |
132 | |
133 GLenum checkFramebufferStatus(GLenum target); | |
134 void clear(GLbitfield mask); | |
135 void clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); | |
136 void clearDepth(GLfloat); | |
137 void clearStencil(GLint); | |
138 void colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alp
ha); | |
139 void compileShader(WebGLShader*); | |
140 | |
141 void compressedTexImage2D(GLenum target, GLint level, GLenum internalformat,
GLsizei width, GLsizei height, GLint border, ArrayBufferView* data); | |
142 void compressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLin
t yoffset, GLsizei width, GLsizei height, GLenum format, ArrayBufferView* data); | |
143 | |
144 void copyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint
x, GLint y, GLsizei width, GLsizei height, GLint border); | |
145 void copyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoff
set, GLint x, GLint y, GLsizei width, GLsizei height); | |
146 | |
147 PassRefPtr<WebGLBuffer> createBuffer(); | |
148 PassRefPtr<WebGLFramebuffer> createFramebuffer(); | |
149 PassRefPtr<WebGLProgram> createProgram(); | |
150 PassRefPtr<WebGLRenderbuffer> createRenderbuffer(); | |
151 PassRefPtr<WebGLShader> createShader(GLenum type); | |
152 PassRefPtr<WebGLTexture> createTexture(); | |
153 | |
154 void cullFace(GLenum mode); | |
155 | |
156 void deleteBuffer(WebGLBuffer*); | |
157 void deleteFramebuffer(WebGLFramebuffer*); | |
158 void deleteProgram(WebGLProgram*); | |
159 void deleteRenderbuffer(WebGLRenderbuffer*); | |
160 void deleteShader(WebGLShader*); | |
161 void deleteTexture(WebGLTexture*); | |
162 | |
163 void depthFunc(GLenum); | |
164 void depthMask(GLboolean); | |
165 void depthRange(GLfloat zNear, GLfloat zFar); | |
166 void detachShader(WebGLProgram*, WebGLShader*); | |
167 void disable(GLenum cap); | |
168 void disableVertexAttribArray(GLuint index); | |
169 void drawArrays(GLenum mode, GLint first, GLsizei count); | |
170 void drawElements(GLenum mode, GLsizei count, GLenum type, long long offset)
; | |
171 | |
172 void drawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsiz
ei primcount); | |
173 void drawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, lon
g long offset, GLsizei primcount); | |
174 | |
175 void enable(GLenum cap); | |
176 void enableVertexAttribArray(GLuint index); | |
177 void finish(); | |
178 void flush(); | |
179 void framebufferRenderbuffer(GLenum target, GLenum attachment, GLenum render
buffertarget, WebGLRenderbuffer*); | |
180 void framebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget
, WebGLTexture*, GLint level); | |
181 void frontFace(GLenum mode); | |
182 void generateMipmap(GLenum target); | |
183 | |
184 PassRefPtr<WebGLActiveInfo> getActiveAttrib(WebGLProgram*, GLuint index); | |
185 PassRefPtr<WebGLActiveInfo> getActiveUniform(WebGLProgram*, GLuint index); | |
186 bool getAttachedShaders(WebGLProgram*, Vector<RefPtr<WebGLShader> >&); | |
187 Nullable<Vector<RefPtr<WebGLShader> > > getAttachedShaders(WebGLProgram*); | |
188 GLint getAttribLocation(WebGLProgram*, const String& name); | |
189 WebGLGetInfo getBufferParameter(GLenum target, GLenum pname); | |
190 PassRefPtr<WebGLContextAttributes> getContextAttributes(); | |
191 GLenum getError(); | |
192 PassRefPtr<WebGLExtension> getExtension(const String& name); | |
193 WebGLGetInfo getFramebufferAttachmentParameter(GLenum target, GLenum attachm
ent, GLenum pname); | |
194 WebGLGetInfo getParameter(GLenum pname); | |
195 WebGLGetInfo getProgramParameter(WebGLProgram*, GLenum pname); | |
196 String getProgramInfoLog(WebGLProgram*); | |
197 WebGLGetInfo getRenderbufferParameter(GLenum target, GLenum pname); | |
198 WebGLGetInfo getShaderParameter(WebGLShader*, GLenum pname); | |
199 String getShaderInfoLog(WebGLShader*); | |
200 PassRefPtr<WebGLShaderPrecisionFormat> getShaderPrecisionFormat(GLenum shade
rType, GLenum precisionType); | |
201 String getShaderSource(WebGLShader*); | |
202 Nullable<Vector<String> > getSupportedExtensions(); | |
203 WebGLGetInfo getTexParameter(GLenum target, GLenum pname); | |
204 WebGLGetInfo getUniform(WebGLProgram*, const WebGLUniformLocation*); | |
205 PassRefPtr<WebGLUniformLocation> getUniformLocation(WebGLProgram*, const Str
ing&); | |
206 WebGLGetInfo getVertexAttrib(GLuint index, GLenum pname); | |
207 long long getVertexAttribOffset(GLuint index, GLenum pname); | |
208 | |
209 void hint(GLenum target, GLenum mode); | |
210 GLboolean isBuffer(WebGLBuffer*); | |
211 bool isContextLost() const; | |
212 GLboolean isEnabled(GLenum cap); | |
213 GLboolean isFramebuffer(WebGLFramebuffer*); | |
214 GLboolean isProgram(WebGLProgram*); | |
215 GLboolean isRenderbuffer(WebGLRenderbuffer*); | |
216 GLboolean isShader(WebGLShader*); | |
217 GLboolean isTexture(WebGLTexture*); | |
218 | |
219 void lineWidth(GLfloat); | |
220 void linkProgram(WebGLProgram*); | |
221 void pixelStorei(GLenum pname, GLint param); | |
222 void polygonOffset(GLfloat factor, GLfloat units); | |
223 void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum form
at, GLenum type, ArrayBufferView* pixels); | |
224 void renderbufferStorage(GLenum target, GLenum internalformat, GLsizei width
, GLsizei height); | |
225 void sampleCoverage(GLfloat value, GLboolean invert); | |
226 void scissor(GLint x, GLint y, GLsizei width, GLsizei height); | |
227 void shaderSource(WebGLShader*, const String&); | |
228 void stencilFunc(GLenum func, GLint ref, GLuint mask); | |
229 void stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask); | |
230 void stencilMask(GLuint); | |
231 void stencilMaskSeparate(GLenum face, GLuint mask); | |
232 void stencilOp(GLenum fail, GLenum zfail, GLenum zpass); | |
233 void stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
; | |
234 | |
235 void texImage2D(GLenum target, GLint level, GLenum internalformat, | |
236 GLsizei width, GLsizei height, GLint border, | |
237 GLenum format, GLenum type, ArrayBufferView*, ExceptionState&); | |
238 void texImage2D(GLenum target, GLint level, GLenum internalformat, | |
239 GLenum format, GLenum type, ImageData*, ExceptionState&); | |
240 void texImage2D(GLenum target, GLint level, GLenum internalformat, | |
241 GLenum format, GLenum type, HTMLImageElement*, ExceptionState&); | |
242 void texImage2D(GLenum target, GLint level, GLenum internalformat, | |
243 GLenum format, GLenum type, HTMLCanvasElement*, ExceptionState&); | |
244 | |
245 void texParameterf(GLenum target, GLenum pname, GLfloat param); | |
246 void texParameteri(GLenum target, GLenum pname, GLint param); | |
247 | |
248 void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, | |
249 GLsizei width, GLsizei height, | |
250 GLenum format, GLenum type, ArrayBufferView*, ExceptionState&); | |
251 void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, | |
252 GLenum format, GLenum type, ImageData*, ExceptionState&); | |
253 void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, | |
254 GLenum format, GLenum type, HTMLImageElement*, ExceptionState&); | |
255 void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, | |
256 GLenum format, GLenum type, HTMLCanvasElement*, ExceptionState&); | |
257 | |
258 void uniform1f(const WebGLUniformLocation*, GLfloat x); | |
259 void uniform1fv(const WebGLUniformLocation*, Float32Array* v); | |
260 void uniform1fv(const WebGLUniformLocation*, GLfloat* v, GLsizei); | |
261 void uniform1i(const WebGLUniformLocation*, GLint x); | |
262 void uniform1iv(const WebGLUniformLocation*, Int32Array* v); | |
263 void uniform1iv(const WebGLUniformLocation*, GLint* v, GLsizei); | |
264 void uniform2f(const WebGLUniformLocation*, GLfloat x, GLfloat y); | |
265 void uniform2fv(const WebGLUniformLocation*, Float32Array* v); | |
266 void uniform2fv(const WebGLUniformLocation*, GLfloat* v, GLsizei); | |
267 void uniform2i(const WebGLUniformLocation*, GLint x, GLint y); | |
268 void uniform2iv(const WebGLUniformLocation*, Int32Array* v); | |
269 void uniform2iv(const WebGLUniformLocation*, GLint* v, GLsizei); | |
270 void uniform3f(const WebGLUniformLocation*, GLfloat x, GLfloat y, GLfloat z)
; | |
271 void uniform3fv(const WebGLUniformLocation*, Float32Array* v); | |
272 void uniform3fv(const WebGLUniformLocation*, GLfloat* v, GLsizei); | |
273 void uniform3i(const WebGLUniformLocation*, GLint x, GLint y, GLint z); | |
274 void uniform3iv(const WebGLUniformLocation*, Int32Array* v); | |
275 void uniform3iv(const WebGLUniformLocation*, GLint* v, GLsizei); | |
276 void uniform4f(const WebGLUniformLocation*, GLfloat x, GLfloat y, GLfloat z,
GLfloat w); | |
277 void uniform4fv(const WebGLUniformLocation*, Float32Array* v); | |
278 void uniform4fv(const WebGLUniformLocation*, GLfloat* v, GLsizei); | |
279 void uniform4i(const WebGLUniformLocation*, GLint x, GLint y, GLint z, GLint
w); | |
280 void uniform4iv(const WebGLUniformLocation*, Int32Array* v); | |
281 void uniform4iv(const WebGLUniformLocation*, GLint* v, GLsizei); | |
282 void uniformMatrix2fv(const WebGLUniformLocation*, GLboolean transpose, Floa
t32Array* value); | |
283 void uniformMatrix2fv(const WebGLUniformLocation*, GLboolean transpose, GLfl
oat* value, GLsizei); | |
284 void uniformMatrix3fv(const WebGLUniformLocation*, GLboolean transpose, Floa
t32Array* value); | |
285 void uniformMatrix3fv(const WebGLUniformLocation*, GLboolean transpose, GLfl
oat* value, GLsizei); | |
286 void uniformMatrix4fv(const WebGLUniformLocation*, GLboolean transpose, Floa
t32Array* value); | |
287 void uniformMatrix4fv(const WebGLUniformLocation*, GLboolean transpose, GLfl
oat* value, GLsizei); | |
288 | |
289 void useProgram(WebGLProgram*); | |
290 void validateProgram(WebGLProgram*); | |
291 | |
292 void vertexAttrib1f(GLuint index, GLfloat x); | |
293 void vertexAttrib1fv(GLuint index, Float32Array* values); | |
294 void vertexAttrib1fv(GLuint index, GLfloat* values, GLsizei); | |
295 void vertexAttrib2f(GLuint index, GLfloat x, GLfloat y); | |
296 void vertexAttrib2fv(GLuint index, Float32Array* values); | |
297 void vertexAttrib2fv(GLuint index, GLfloat* values, GLsizei); | |
298 void vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z); | |
299 void vertexAttrib3fv(GLuint index, Float32Array* values); | |
300 void vertexAttrib3fv(GLuint index, GLfloat* values, GLsizei); | |
301 void vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w
); | |
302 void vertexAttrib4fv(GLuint index, Float32Array* values); | |
303 void vertexAttrib4fv(GLuint index, GLfloat* values, GLsizei); | |
304 void vertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean no
rmalized, | |
305 GLsizei stride, long long offset); | |
306 | |
307 void vertexAttribDivisorANGLE(GLuint index, GLuint divisor); | |
308 | |
309 void viewport(GLint x, GLint y, GLsizei width, GLsizei height); | |
310 | |
311 // WEBGL_lose_context support | |
312 enum LostContextMode { | |
313 NotLostContext, | |
314 | |
315 // Lost context occurred at the graphics system level. | |
316 RealLostContext, | |
317 | |
318 // Lost context provoked by WEBGL_lose_context. | |
319 WebGLLoseContextLostContext, | |
320 | |
321 // Lost context occurred due to internal implementation reasons. | |
322 SyntheticLostContext, | |
323 }; | |
324 enum AutoRecoveryMethod { | |
325 // Don't restore automatically. | |
326 Manual, | |
327 | |
328 // Restore when resources are available. | |
329 WhenAvailable, | |
330 | |
331 // Restore as soon as possible. | |
332 Auto | |
333 }; | |
334 void forceLostContext(LostContextMode, AutoRecoveryMethod); | |
335 void forceRestoreContext(); | |
336 void loseContextImpl(LostContextMode, AutoRecoveryMethod); | |
337 | |
338 blink::WebGraphicsContext3D* webContext() const { return drawingBuffer()->co
ntext(); } | |
339 WebGLContextGroup* contextGroup() const { return m_contextGroup.get(); } | |
340 Extensions3DUtil* extensionsUtil(); | |
341 | |
342 void reshape(int width, int height); | |
343 | |
344 void markLayerComposited(); | |
345 PassRefPtr<ImageData> paintRenderingResultsToImageData(); | |
346 | |
347 void removeSharedObject(WebGLSharedObject*); | |
348 void removeContextObject(WebGLContextObject*); | |
349 | |
350 unsigned maxVertexAttribs() const { return m_maxVertexAttribs; } | |
351 | |
352 // ActiveDOMObject notifications | |
353 virtual bool hasPendingActivity() const override; | |
354 virtual void stop() override; | |
355 | |
356 void setSavingImage(bool isSaving) { m_savingImage = isSaving; } | |
357 | |
358 class TextureUnitState { | |
359 ALLOW_ONLY_INLINE_ALLOCATION(); | |
360 public: | |
361 RefPtr<WebGLTexture> m_texture2DBinding; | |
362 RefPtr<WebGLTexture> m_textureCubeMapBinding; | |
363 }; | |
364 | |
365 protected: | |
366 friend class WebGLDrawBuffers; | |
367 friend class WebGLFramebuffer; | |
368 friend class WebGLObject; | |
369 friend class WebGLContextObject; | |
370 friend class OESVertexArrayObject; | |
371 friend class WebGLDebugShaders; | |
372 friend class WebGLCompressedTextureATC; | |
373 friend class WebGLCompressedTextureETC1; | |
374 friend class WebGLCompressedTexturePVRTC; | |
375 friend class WebGLCompressedTextureS3TC; | |
376 friend class WebGLRenderingContextErrorMessageCallback; | |
377 friend class WebGLVertexArrayObjectOES; | |
378 friend class ScopedTexture2DRestorer; | |
379 | |
380 WebGLRenderingContextBase(HTMLCanvasElement*, PassOwnPtr<blink::WebGraphicsC
ontext3D>, WebGLContextAttributes*); | |
381 PassRefPtr<DrawingBuffer> createDrawingBuffer(PassOwnPtr<blink::WebGraphicsC
ontext3D>); | |
382 void initializeNewContext(); | |
383 void setupFlags(); | |
384 | |
385 #if ENABLE(OILPAN) | |
386 PassRefPtr<WebGLSharedWebGraphicsContext3D> sharedWebGraphicsContext3D() con
st; | |
387 #endif | |
388 | |
389 // CanvasRenderingContext implementation. | |
390 virtual bool is3d() const override { return true; } | |
391 virtual bool isAccelerated() const override { return true; } | |
392 virtual void setIsHidden(bool) override; | |
393 virtual void paintRenderingResultsToCanvas() override; | |
394 virtual blink::WebLayer* platformLayer() const override; | |
395 | |
396 void addSharedObject(WebGLSharedObject*); | |
397 void addContextObject(WebGLContextObject*); | |
398 void detachAndRemoveAllObjects(); | |
399 | |
400 void destroyContext(); | |
401 void markContextChanged(ContentChangeType); | |
402 | |
403 // Query if the GL implementation is NPOT strict. | |
404 bool isGLES2NPOTStrict() { return m_isGLES2NPOTStrict; } | |
405 // Query if depth_stencil buffer is supported. | |
406 bool isDepthStencilSupported() { return m_isDepthStencilSupported; } | |
407 | |
408 // Helper to return the size in bytes of OpenGL data types | |
409 // like GL_FLOAT, GL_INT, etc. | |
410 unsigned sizeInBytes(GLenum type); | |
411 | |
412 // Check if each enabled vertex attribute is bound to a buffer. | |
413 bool validateRenderingState(const char*); | |
414 | |
415 bool validateWebGLObject(const char*, WebGLObject*); | |
416 | |
417 // Adds a compressed texture format. | |
418 void addCompressedTextureFormat(GLenum); | |
419 void removeAllCompressedTextureFormats(); | |
420 | |
421 PassRefPtr<Image> drawImageIntoBuffer(Image*, int width, int height, const c
har* functionName); | |
422 | |
423 WebGLRenderbuffer* ensureEmulatedStencilBuffer(GLenum target, WebGLRenderbuf
fer*); | |
424 | |
425 // Structure for rendering to a DrawingBuffer, instead of directly | |
426 // to the back-buffer of m_context. | |
427 #if ENABLE(OILPAN) | |
428 RefPtr<WebGLSharedWebGraphicsContext3D> m_sharedWebGraphicsContext3D; | |
429 #else | |
430 RefPtr<DrawingBuffer> m_drawingBuffer; | |
431 #endif | |
432 DrawingBuffer* drawingBuffer() const; | |
433 | |
434 RefPtr<WebGLContextGroup> m_contextGroup; | |
435 | |
436 LostContextMode m_contextLostMode; | |
437 AutoRecoveryMethod m_autoRecoveryMethod; | |
438 // Dispatches a context lost event once it is determined that one is needed. | |
439 // This is used for synthetic, WEBGL_lose_context and real context losses. F
or real ones, it's | |
440 // likely that there's no JavaScript on the stack, but that might be depende
nt | |
441 // on how exactly the platform discovers that the context was lost. For bett
er | |
442 // portability we always defer the dispatch of the event. | |
443 Timer<WebGLRenderingContextBase> m_dispatchContextLostEventTimer; | |
444 bool m_restoreAllowed; | |
445 Timer<WebGLRenderingContextBase> m_restoreTimer; | |
446 | |
447 bool m_needsUpdate; | |
448 bool m_markedCanvasDirty; | |
449 HashSet<RawPtr<WebGLContextObject> > m_contextObjects; | |
450 | |
451 OwnPtr<WebGLRenderingContextLostCallback> m_contextLostCallbackAdapter; | |
452 OwnPtr<WebGLRenderingContextErrorMessageCallback> m_errorMessageCallbackAdap
ter; | |
453 | |
454 // List of bound VBO's. Used to maintain info about sizes for ARRAY_BUFFER a
nd stored values for ELEMENT_ARRAY_BUFFER | |
455 RefPtr<WebGLBuffer> m_boundArrayBuffer; | |
456 | |
457 RefPtr<WebGLVertexArrayObjectOES> m_defaultVertexArrayObject; | |
458 RefPtr<WebGLVertexArrayObjectOES> m_boundVertexArrayObject; | |
459 void setBoundVertexArrayObject(PassRefPtr<WebGLVertexArrayObjectOES> arrayOb
ject) | |
460 { | |
461 if (arrayObject) | |
462 m_boundVertexArrayObject = arrayObject; | |
463 else | |
464 m_boundVertexArrayObject = m_defaultVertexArrayObject; | |
465 } | |
466 | |
467 class VertexAttribValue { | |
468 public: | |
469 VertexAttribValue() | |
470 { | |
471 initValue(); | |
472 } | |
473 | |
474 void initValue() | |
475 { | |
476 value[0] = 0.0f; | |
477 value[1] = 0.0f; | |
478 value[2] = 0.0f; | |
479 value[3] = 1.0f; | |
480 } | |
481 | |
482 GLfloat value[4]; | |
483 }; | |
484 Vector<VertexAttribValue> m_vertexAttribValue; | |
485 unsigned m_maxVertexAttribs; | |
486 RefPtr<WebGLBuffer> m_vertexAttrib0Buffer; | |
487 long m_vertexAttrib0BufferSize; | |
488 GLfloat m_vertexAttrib0BufferValue[4]; | |
489 bool m_forceAttrib0BufferRefill; | |
490 bool m_vertexAttrib0UsedBefore; | |
491 | |
492 RefPtr<WebGLProgram> m_currentProgram; | |
493 RefPtr<WebGLFramebuffer> m_framebufferBinding; | |
494 RefPtr<WebGLRenderbuffer> m_renderbufferBinding; | |
495 | |
496 Vector<TextureUnitState> m_textureUnits; | |
497 unsigned long m_activeTextureUnit; | |
498 | |
499 RefPtr<WebGLTexture> m_blackTexture2D; | |
500 RefPtr<WebGLTexture> m_blackTextureCubeMap; | |
501 | |
502 Vector<GLenum> m_compressedTextureFormats; | |
503 | |
504 // Fixed-size cache of reusable image buffers for video texImage2D calls. | |
505 class LRUImageBufferCache { | |
506 public: | |
507 LRUImageBufferCache(int capacity); | |
508 // The pointer returned is owned by the image buffer map. | |
509 ImageBuffer* imageBuffer(const IntSize& size); | |
510 private: | |
511 void bubbleToFront(int idx); | |
512 OwnPtr<OwnPtr<ImageBuffer>[]> m_buffers; | |
513 int m_capacity; | |
514 }; | |
515 LRUImageBufferCache m_generatedImageCache; | |
516 | |
517 GLint m_maxTextureSize; | |
518 GLint m_maxCubeMapTextureSize; | |
519 GLint m_maxRenderbufferSize; | |
520 GLint m_maxViewportDims[2]; | |
521 GLint m_maxTextureLevel; | |
522 GLint m_maxCubeMapTextureLevel; | |
523 | |
524 GLint m_maxDrawBuffers; | |
525 GLint m_maxColorAttachments; | |
526 GLenum m_backDrawBuffer; | |
527 bool m_drawBuffersWebGLRequirementsChecked; | |
528 bool m_drawBuffersSupported; | |
529 | |
530 GLint m_packAlignment; | |
531 GLint m_unpackAlignment; | |
532 bool m_unpackFlipY; | |
533 bool m_unpackPremultiplyAlpha; | |
534 GLenum m_unpackColorspaceConversion; | |
535 RefPtr<WebGLContextAttributes> m_requestedAttributes; | |
536 | |
537 bool m_layerCleared; | |
538 GLfloat m_clearColor[4]; | |
539 bool m_scissorEnabled; | |
540 GLfloat m_clearDepth; | |
541 GLint m_clearStencil; | |
542 GLboolean m_colorMask[4]; | |
543 GLboolean m_depthMask; | |
544 | |
545 bool m_stencilEnabled; | |
546 GLuint m_stencilMask, m_stencilMaskBack; | |
547 GLint m_stencilFuncRef, m_stencilFuncRefBack; // Note that these are the use
r specified values, not the internal clamped value. | |
548 GLuint m_stencilFuncMask, m_stencilFuncMaskBack; | |
549 | |
550 bool m_isGLES2NPOTStrict; | |
551 bool m_isDepthStencilSupported; | |
552 | |
553 bool m_synthesizedErrorsToConsole; | |
554 int m_numGLErrorsToConsoleAllowed; | |
555 | |
556 bool m_multisamplingAllowed; | |
557 bool m_multisamplingObserverRegistered; | |
558 | |
559 unsigned long m_onePlusMaxNonDefaultTextureUnit; | |
560 | |
561 OwnPtr<Extensions3DUtil> m_extensionsUtil; | |
562 | |
563 bool m_savingImage; | |
564 | |
565 enum ExtensionFlags { | |
566 ApprovedExtension = 0x00, | |
567 // Extension that is behind the draft extensions runtime flag: | |
568 DraftExtension = 0x01, | |
569 }; | |
570 | |
571 class ExtensionTracker { | |
572 public: | |
573 ExtensionTracker(ExtensionFlags flags, const char* const* prefixes) | |
574 : m_draft(flags & DraftExtension) | |
575 , m_prefixes(prefixes) | |
576 { | |
577 } | |
578 | |
579 #if !ENABLE(OILPAN) | |
580 virtual ~ExtensionTracker() | |
581 { | |
582 } | |
583 #endif | |
584 | |
585 bool draft() const | |
586 { | |
587 return m_draft; | |
588 } | |
589 | |
590 const char* const* prefixes() const; | |
591 bool matchesNameWithPrefixes(const String&) const; | |
592 | |
593 virtual PassRefPtr<WebGLExtension> getExtension(WebGLRenderingContextBas
e*) = 0; | |
594 virtual bool supported(WebGLRenderingContextBase*) const = 0; | |
595 virtual const char* extensionName() const = 0; | |
596 virtual void loseExtension() = 0; | |
597 | |
598 private: | |
599 bool m_draft; | |
600 const char* const* m_prefixes; | |
601 }; | |
602 | |
603 template <typename T> | |
604 class TypedExtensionTracker final : public ExtensionTracker { | |
605 public: | |
606 static PassOwnPtr<TypedExtensionTracker<T> > create(RefPtr<T>& extension
Field, ExtensionFlags flags, const char* const* prefixes) | |
607 { | |
608 return adoptPtr(new TypedExtensionTracker<T>(extensionField, flags,
prefixes)); | |
609 } | |
610 | |
611 #if !ENABLE(OILPAN) | |
612 virtual ~TypedExtensionTracker() | |
613 { | |
614 if (m_extension) { | |
615 m_extension->lose(true); | |
616 m_extension = nullptr; | |
617 } | |
618 } | |
619 #endif | |
620 | |
621 virtual PassRefPtr<WebGLExtension> getExtension(WebGLRenderingContextBas
e* context) override | |
622 { | |
623 if (!m_extension) { | |
624 m_extension = T::create(context); | |
625 m_extensionField = m_extension; | |
626 } | |
627 | |
628 return m_extension; | |
629 } | |
630 | |
631 virtual bool supported(WebGLRenderingContextBase* context) const overrid
e | |
632 { | |
633 return T::supported(context); | |
634 } | |
635 | |
636 virtual const char* extensionName() const override | |
637 { | |
638 return T::extensionName(); | |
639 } | |
640 | |
641 virtual void loseExtension() override | |
642 { | |
643 if (m_extension) { | |
644 m_extension->lose(false); | |
645 if (m_extension->isLost()) | |
646 m_extension = nullptr; | |
647 } | |
648 } | |
649 | |
650 private: | |
651 TypedExtensionTracker(RefPtr<T>& extensionField, ExtensionFlags flags, c
onst char* const* prefixes) | |
652 : ExtensionTracker(flags, prefixes) | |
653 , m_extensionField(extensionField) | |
654 { | |
655 } | |
656 | |
657 RefPtr<T>& m_extensionField; | |
658 // ExtensionTracker holds it's own reference to the extension to ensure | |
659 // that it is not deleted before this object's destructor is called | |
660 RefPtr<T> m_extension; | |
661 }; | |
662 | |
663 bool m_extensionEnabled[WebGLExtensionNameCount]; | |
664 Vector<OwnPtr<ExtensionTracker> > m_extensions; | |
665 | |
666 template <typename T> | |
667 void registerExtension(RefPtr<T>& extensionPtr, ExtensionFlags flags = Appro
vedExtension, const char* const* prefixes = 0) | |
668 { | |
669 m_extensions.append(TypedExtensionTracker<T>::create(extensionPtr, flags
, prefixes)); | |
670 } | |
671 | |
672 bool extensionSupportedAndAllowed(const ExtensionTracker*); | |
673 | |
674 inline bool extensionEnabled(WebGLExtensionName name) | |
675 { | |
676 return m_extensionEnabled[name]; | |
677 } | |
678 | |
679 // Errors raised by synthesizeGLError() while the context is lost. | |
680 Vector<GLenum> m_lostContextErrors; | |
681 | |
682 // Helpers for getParameter and others | |
683 WebGLGetInfo getBooleanParameter(GLenum); | |
684 WebGLGetInfo getBooleanArrayParameter(GLenum); | |
685 WebGLGetInfo getFloatParameter(GLenum); | |
686 WebGLGetInfo getIntParameter(GLenum); | |
687 WebGLGetInfo getUnsignedIntParameter(GLenum); | |
688 WebGLGetInfo getWebGLFloatArrayParameter(GLenum); | |
689 WebGLGetInfo getWebGLIntArrayParameter(GLenum); | |
690 | |
691 // Clear the backbuffer if it was composited since the last operation. | |
692 // clearMask is set to the bitfield of any clear that would happen anyway at
this time | |
693 // and the function returns true if that clear is now unnecessary. | |
694 bool clearIfComposited(GLbitfield clearMask = 0); | |
695 | |
696 // Helper to restore state that clearing the framebuffer may destroy. | |
697 void restoreStateAfterClear(); | |
698 | |
699 // Convert texture internal format. | |
700 GLenum convertTexInternalFormat(GLenum internalformat, GLenum type); | |
701 | |
702 void texImage2DBase(GLenum target, GLint level, GLenum internalformat, GLsiz
ei width, GLsizei height, GLint border, GLenum format, GLenum type, const void*
pixels, ExceptionState&); | |
703 void texImage2DImpl(GLenum target, GLint level, GLenum internalformat, GLenu
m format, GLenum type, Image*, WebGLImageConversion::ImageHtmlDomSource, bool fl
ipY, bool premultiplyAlpha, ExceptionState&); | |
704 void texSubImage2DBase(GLenum target, GLint level, GLint xoffset, GLint yoff
set, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixe
ls, ExceptionState&); | |
705 void texSubImage2DImpl(GLenum target, GLint level, GLint xoffset, GLint yoff
set, GLenum format, GLenum type, Image*, WebGLImageConversion::ImageHtmlDomSourc
e, bool flipY, bool premultiplyAlpha, ExceptionState&); | |
706 | |
707 void handleTextureCompleteness(const char*, bool); | |
708 void createFallbackBlackTextures1x1(); | |
709 | |
710 // Helper function for copyTex{Sub}Image, check whether the internalformat | |
711 // and the color buffer format of the current bound framebuffer combination | |
712 // is valid. | |
713 bool isTexInternalFormatColorBufferCombinationValid(GLenum texInternalFormat
, GLenum colorBufferFormat); | |
714 | |
715 // Helper function to get the bound framebuffer's color buffer format. | |
716 GLenum boundFramebufferColorFormat(); | |
717 | |
718 // Helper function to verify limits on the length of uniform and attribute l
ocations. | |
719 bool validateLocationLength(const char* functionName, const String&); | |
720 | |
721 // Helper function to check if size is non-negative. | |
722 // Generate GL error and return false for negative inputs; otherwise, return
true. | |
723 bool validateSize(const char* functionName, GLint x, GLint y); | |
724 | |
725 // Helper function to check if all characters in the string belong to the | |
726 // ASCII subset as defined in GLSL ES 1.0 spec section 3.1. | |
727 bool validateString(const char* functionName, const String&); | |
728 | |
729 // Helper function to check target and texture bound to the target. | |
730 // Generate GL errors and return 0 if target is invalid or texture bound is | |
731 // null. Otherwise, return the texture bound to the target. | |
732 WebGLTexture* validateTextureBinding(const char* functionName, GLenum target
, bool useSixEnumsForCubeMap); | |
733 | |
734 // Helper function to check input format/type for functions {copy}Tex{Sub}Im
age. | |
735 // Generates GL error and returns false if parameters are invalid. | |
736 bool validateTexFuncFormatAndType(const char* functionName, GLenum format, G
Lenum type, GLint level); | |
737 | |
738 // Helper function to check input level for functions {copy}Tex{Sub}Image. | |
739 // Generates GL error and returns false if level is invalid. | |
740 bool validateTexFuncLevel(const char* functionName, GLenum target, GLint lev
el); | |
741 | |
742 // Helper function to check if a 64-bit value is non-negative and can fit in
to a 32-bit integer. | |
743 // Generates GL error and returns false if not. | |
744 bool validateValueFitNonNegInt32(const char* functionName, const char* param
Name, long long value); | |
745 | |
746 enum TexFuncValidationFunctionType { | |
747 NotTexSubImage2D, | |
748 TexSubImage2D, | |
749 }; | |
750 | |
751 enum TexFuncValidationSourceType { | |
752 SourceArrayBufferView, | |
753 SourceImageData, | |
754 SourceHTMLImageElement, | |
755 SourceHTMLCanvasElement, | |
756 }; | |
757 | |
758 // Helper function for tex{Sub}Image2D to check if the input format/type/lev
el/target/width/height/border/xoffset/yoffset are valid. | |
759 // Otherwise, it would return quickly without doing other work. | |
760 bool validateTexFunc(const char* functionName, TexFuncValidationFunctionType
, TexFuncValidationSourceType, GLenum target, GLint level, GLenum internalformat
, GLsizei width, | |
761 GLsizei height, GLint border, GLenum format, GLenum type, GLint xoffset,
GLint yoffset); | |
762 | |
763 // Helper function to check input width and height for functions {copy, comp
ressed}Tex{Sub}Image. | |
764 // Generates GL error and returns false if width or height is invalid. | |
765 bool validateTexFuncDimensions(const char* functionName, TexFuncValidationFu
nctionType, GLenum target, GLint level, GLsizei width, GLsizei height); | |
766 | |
767 // Helper function to check input parameters for functions {copy}Tex{Sub}Ima
ge. | |
768 // Generates GL error and returns false if parameters are invalid. | |
769 bool validateTexFuncParameters(const char* functionName, TexFuncValidationFu
nctionType, GLenum target, GLint level, GLenum internalformat, GLsizei width, GL
sizei height, GLint border, GLenum format, GLenum type); | |
770 | |
771 enum NullDisposition { | |
772 NullAllowed, | |
773 NullNotAllowed | |
774 }; | |
775 | |
776 // Helper function to validate that the given ArrayBufferView | |
777 // is of the correct type and contains enough data for the texImage call. | |
778 // Generates GL error and returns false if parameters are invalid. | |
779 bool validateTexFuncData(const char* functionName, GLint level, GLsizei widt
h, GLsizei height, GLenum format, GLenum type, ArrayBufferView* pixels, NullDisp
osition); | |
780 | |
781 // Helper function to validate a given texture format is settable as in | |
782 // you can supply data to texImage2D, or call texImage2D, copyTexImage2D and | |
783 // copyTexSubImage2D. | |
784 // Generates GL error and returns false if the format is not settable. | |
785 bool validateSettableTexFormat(const char* functionName, GLenum format); | |
786 | |
787 // Helper function to validate compressed texture data is correct size | |
788 // for the given format and dimensions. | |
789 bool validateCompressedTexFuncData(const char* functionName, GLsizei width,
GLsizei height, GLenum format, ArrayBufferView* pixels); | |
790 | |
791 // Helper function for validating compressed texture formats. | |
792 bool validateCompressedTexFormat(GLenum format); | |
793 | |
794 // Helper function to validate compressed texture dimensions are valid for | |
795 // the given format. | |
796 bool validateCompressedTexDimensions(const char* functionName, TexFuncValida
tionFunctionType, GLenum target, GLint level, GLsizei width, GLsizei height, GLe
num format); | |
797 | |
798 // Helper function to validate compressed texture dimensions are valid for | |
799 // the given format. | |
800 bool validateCompressedTexSubDimensions(const char* functionName, GLenum tar
get, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, G
Lenum format, WebGLTexture*); | |
801 | |
802 // Helper function to validate mode for draw{Arrays/Elements}. | |
803 bool validateDrawMode(const char* functionName, GLenum); | |
804 | |
805 // Helper function to validate if front/back stencilMask and stencilFunc set
tings are the same. | |
806 bool validateStencilSettings(const char* functionName); | |
807 | |
808 // Helper function to validate stencil or depth func. | |
809 bool validateStencilOrDepthFunc(const char* functionName, GLenum); | |
810 | |
811 // Helper function for texParameterf and texParameteri. | |
812 void texParameter(GLenum target, GLenum pname, GLfloat parami, GLint paramf,
bool isFloat); | |
813 | |
814 // Helper function to print GL errors to console. | |
815 void printGLErrorToConsole(const String&); | |
816 | |
817 // Helper function to print warnings to console. Currently | |
818 // used only to warn about use of obsolete functions. | |
819 void printWarningToConsole(const String&); | |
820 | |
821 // Helper function to validate input parameters for framebuffer functions. | |
822 // Generate GL error if parameters are illegal. | |
823 bool validateFramebufferFuncParameters(const char* functionName, GLenum targ
et, GLenum attachment); | |
824 | |
825 // Helper function to validate blend equation mode. | |
826 bool validateBlendEquation(const char* functionName, GLenum); | |
827 | |
828 // Helper function to validate blend func factors. | |
829 bool validateBlendFuncFactors(const char* functionName, GLenum src, GLenum d
st); | |
830 | |
831 // Helper function to validate a GL capability. | |
832 bool validateCapability(const char* functionName, GLenum); | |
833 | |
834 // Helper function to validate input parameters for uniform functions. | |
835 bool validateUniformParameters(const char* functionName, const WebGLUniformL
ocation*, Float32Array*, GLsizei mod); | |
836 bool validateUniformParameters(const char* functionName, const WebGLUniformL
ocation*, Int32Array*, GLsizei mod); | |
837 bool validateUniformParameters(const char* functionName, const WebGLUniformL
ocation*, void*, GLsizei, GLsizei mod); | |
838 bool validateUniformMatrixParameters(const char* functionName, const WebGLUn
iformLocation*, GLboolean transpose, Float32Array*, GLsizei mod); | |
839 bool validateUniformMatrixParameters(const char* functionName, const WebGLUn
iformLocation*, GLboolean transpose, void*, GLsizei, GLsizei mod); | |
840 | |
841 // Helper function to validate the target for bufferData. | |
842 // Return the current bound buffer to target, or 0 if the target is invalid. | |
843 WebGLBuffer* validateBufferDataTarget(const char* functionName, GLenum targe
t); | |
844 | |
845 // Helper function for tex{Sub}Image2D to make sure image is ready and would
n't taint Origin. | |
846 bool validateHTMLImageElement(const char* functionName, HTMLImageElement*, E
xceptionState&); | |
847 | |
848 // Helper function for tex{Sub}Image2D to make sure canvas is ready and woul
dn't taint Origin. | |
849 bool validateHTMLCanvasElement(const char* functionName, HTMLCanvasElement*,
ExceptionState&); | |
850 | |
851 // Helper function to validate drawArrays(Instanced) calls | |
852 bool validateDrawArrays(const char* functionName, GLenum mode, GLint first,
GLsizei count); | |
853 | |
854 // Helper function to validate drawElements(Instanced) calls | |
855 bool validateDrawElements(const char* functionName, GLenum mode, GLsizei cou
nt, GLenum type, long long offset); | |
856 | |
857 // Helper function to validate draw*Instanced calls | |
858 bool validateDrawInstanced(const char* functionName, GLsizei primcount); | |
859 | |
860 // Helper functions for vertexAttribNf{v}. | |
861 void vertexAttribfImpl(const char* functionName, GLuint index, GLsizei expec
tedSize, GLfloat, GLfloat, GLfloat, GLfloat); | |
862 void vertexAttribfvImpl(const char* functionName, GLuint index, Float32Array
*, GLsizei expectedSize); | |
863 void vertexAttribfvImpl(const char* functionName, GLuint index, GLfloat*, GL
sizei, GLsizei expectedSize); | |
864 | |
865 // Helper functions to bufferData() and bufferSubData(). | |
866 void bufferDataImpl(GLenum target, long long size, const void* data, GLenum
usage); | |
867 void bufferSubDataImpl(GLenum target, long long offset, GLsizeiptr size, con
st void* data); | |
868 | |
869 // Helper function for delete* (deleteBuffer, deleteProgram, etc) functions. | |
870 // Return false if caller should return without further processing. | |
871 bool deleteObject(WebGLObject*); | |
872 | |
873 // Helper function for bind* (bindBuffer, bindTexture, etc) and useProgram. | |
874 // If the object has already been deleted, set deleted to true upon return. | |
875 // Return false if caller should return without further processing. | |
876 bool checkObjectToBeBound(const char* functionName, WebGLObject*, bool& dele
ted); | |
877 | |
878 void dispatchContextLostEvent(Timer<WebGLRenderingContextBase>*); | |
879 // Helper for restoration after context lost. | |
880 void maybeRestoreContext(Timer<WebGLRenderingContextBase>*); | |
881 | |
882 enum ConsoleDisplayPreference { | |
883 DisplayInConsole, | |
884 DontDisplayInConsole | |
885 }; | |
886 | |
887 // Wrapper for WebGraphicsContext3D::synthesizeGLError that sends a message | |
888 // to the JavaScript console. | |
889 void synthesizeGLError(GLenum, const char* functionName, const char* descrip
tion, ConsoleDisplayPreference = DisplayInConsole); | |
890 void emitGLWarning(const char* function, const char* reason); | |
891 | |
892 String ensureNotNull(const String&) const; | |
893 | |
894 // Enable or disable stencil test based on user setting and | |
895 // whether the current FBO has a stencil buffer. | |
896 void applyStencilTest(); | |
897 | |
898 // Helper for enabling or disabling a capability. | |
899 void enableOrDisable(GLenum capability, bool enable); | |
900 | |
901 // Clamp the width and height to GL_MAX_VIEWPORT_DIMS. | |
902 IntSize clampedCanvasSize(); | |
903 | |
904 // First time called, if EXT_draw_buffers is supported, query the value; oth
erwise return 0. | |
905 // Later, return the cached value. | |
906 GLint maxDrawBuffers(); | |
907 GLint maxColorAttachments(); | |
908 | |
909 void setBackDrawBuffer(GLenum); | |
910 | |
911 void restoreCurrentFramebuffer(); | |
912 void restoreCurrentTexture2D(); | |
913 | |
914 virtual void multisamplingChanged(bool) override; | |
915 | |
916 void findNewMaxNonDefaultTextureUnit(); | |
917 | |
918 friend class WebGLStateRestorer; | |
919 friend class WebGLRenderingContextEvictionManager; | |
920 | |
921 static Vector<WebGLRenderingContextBase*>& activeContexts(); | |
922 static Vector<WebGLRenderingContextBase*>& forciblyEvictedContexts(); | |
923 | |
924 static void activateContext(WebGLRenderingContextBase*); | |
925 static void deactivateContext(WebGLRenderingContextBase*); | |
926 static void addToEvictedList(WebGLRenderingContextBase*); | |
927 static void removeFromEvictedList(WebGLRenderingContextBase*); | |
928 static void willDestroyContext(WebGLRenderingContextBase*); | |
929 static void forciblyLoseOldestContext(const String& reason); | |
930 // Return the least recently used context's position in the active context v
ector. | |
931 // If the vector is empty, return the maximum allowed active context number. | |
932 static size_t oldestContextIndex(); | |
933 static IntSize oldestContextSize(); | |
934 }; | |
935 | |
936 DEFINE_TYPE_CASTS(WebGLRenderingContextBase, CanvasRenderingContext, context, co
ntext->is3d(), context.is3d()); | |
937 | |
938 } // namespace blink | |
939 | |
940 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::WebGLRenderingContextB
ase::TextureUnitState); | |
941 | |
942 #endif // SKY_ENGINE_CORE_HTML_CANVAS_WEBGLRENDERINGCONTEXTBASE_H_ | |
OLD | NEW |