#ifndef WebGLRenderingContextBase_h
#define WebGLRenderingContextBase_h
#include "core/dom/ActiveDOMObject.h"
#include "core/html/canvas/CanvasRenderingContext.h"
#include "core/html/canvas/WebGLExtensionName.h"
#include "core/html/canvas/WebGLGetInfo.h"
#include "core/page/Page.h"
#include "core/rendering/RenderBoxModelObject.h"
#include "platform/Timer.h"
#include "platform/graphics/GraphicsTypes3D.h"
#include "platform/graphics/ImageBuffer.h"
#include "platform/graphics/gpu/Extensions3DUtil.h"
#include "platform/graphics/gpu/WebGLImageConversion.h"
#include "public/platform/WebGraphicsContext3D.h"
#include "wtf/Float32Array.h"
#include "wtf/Int32Array.h"
#include "wtf/OwnPtr.h"
#include "wtf/text/WTFString.h"
namespace blink {
class WebLayer;
}
namespace WebCore {
class ANGLEInstancedArrays;
class DrawingBuffer;
class EXTFragDepth;
class EXTTextureFilterAnisotropic;
class ExceptionState;
class HTMLImageElement;
class HTMLVideoElement;
class ImageBuffer;
class ImageData;
class IntSize;
class OESElementIndexUint;
class OESStandardDerivatives;
class OESTextureFloat;
class OESTextureFloatLinear;
class OESTextureHalfFloat;
class OESTextureHalfFloatLinear;
class OESVertexArrayObject;
class WebGLActiveInfo;
class WebGLBuffer;
class WebGLCompressedTextureATC;
class WebGLCompressedTexturePVRTC;
class WebGLCompressedTextureS3TC;
class WebGLContextAttributes;
class WebGLContextGroup;
class WebGLContextObject;
class WebGLDebugRendererInfo;
class WebGLDebugShaders;
class WebGLDepthTexture;
class WebGLDrawBuffers;
class WebGLExtension;
class WebGLFramebuffer;
class WebGLLoseContext;
class WebGLObject;
class WebGLProgram;
class WebGLRenderbuffer;
class WebGLShader;
class WebGLShaderPrecisionFormat;
class WebGLSharedObject;
class WebGLTexture;
class WebGLUniformLocation;
class WebGLVertexArrayObjectOES;
class WebGLRenderingContextLostCallback;
class WebGLRenderingContextErrorMessageCallback;
class WebGLRenderingContextBase: public CanvasRenderingContext, public ActiveDOMObject, private Page::MultisamplingChangedObserver {
public:
virtual ~WebGLRenderingContextBase();
virtual bool is3d() const OVERRIDE { return true; }
virtual bool isAccelerated() const OVERRIDE { return true; }
virtual unsigned version() const = 0;
virtual String contextName() const = 0;
virtual void registerContextExtensions() = 0;
static unsigned getWebGLVersion(const CanvasRenderingContext*);
int drawingBufferWidth() const;
int drawingBufferHeight() const;
void activeTexture(GLenum texture);
void attachShader(WebGLProgram*, WebGLShader*);
void bindAttribLocation(WebGLProgram*, GLuint index, const String& name);
void bindBuffer(GLenum target, WebGLBuffer*);
void bindFramebuffer(GLenum target, WebGLFramebuffer*);
void bindRenderbuffer(GLenum target, WebGLRenderbuffer*);
void bindTexture(GLenum target, WebGLTexture*);
void blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
void blendEquation(GLenum mode);
void blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha);
void blendFunc(GLenum sfactor, GLenum dfactor);
void blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
void bufferData(GLenum target, long long size, GLenum usage);
void bufferData(GLenum target, ArrayBuffer* data, GLenum usage);
void bufferData(GLenum target, ArrayBufferView* data, GLenum usage);
void bufferSubData(GLenum target, long long offset, ArrayBuffer* data);
void bufferSubData(GLenum target, long long offset, ArrayBufferView* data);
GLenum checkFramebufferStatus(GLenum target);
void clear(GLbitfield mask);
void clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
void clearDepth(GLfloat);
void clearStencil(GLint);
void colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
void compileShader(WebGLShader*);
void compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, ArrayBufferView* data);
void compressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, ArrayBufferView* data);
void copyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
void copyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
PassRefPtr<WebGLBuffer> createBuffer();
PassRefPtr<WebGLFramebuffer> createFramebuffer();
PassRefPtr<WebGLProgram> createProgram();
PassRefPtr<WebGLRenderbuffer> createRenderbuffer();
PassRefPtr<WebGLShader> createShader(GLenum type);
PassRefPtr<WebGLTexture> createTexture();
void cullFace(GLenum mode);
void deleteBuffer(WebGLBuffer*);
void deleteFramebuffer(WebGLFramebuffer*);
void deleteProgram(WebGLProgram*);
void deleteRenderbuffer(WebGLRenderbuffer*);
void deleteShader(WebGLShader*);
void deleteTexture(WebGLTexture*);
void depthFunc(GLenum);
void depthMask(GLboolean);
void depthRange(GLfloat zNear, GLfloat zFar);
void detachShader(WebGLProgram*, WebGLShader*);
void disable(GLenum cap);
void disableVertexAttribArray(GLuint index);
void drawArrays(GLenum mode, GLint first, GLsizei count);
void drawElements(GLenum mode, GLsizei count, GLenum type, long long offset);
void drawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount);
void drawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei primcount);
void enable(GLenum cap);
void enableVertexAttribArray(GLuint index);
void finish();
void flush();
void framebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, WebGLRenderbuffer*);
void framebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, WebGLTexture*, GLint level);
void frontFace(GLenum mode);
void generateMipmap(GLenum target);
PassRefPtr<WebGLActiveInfo> getActiveAttrib(WebGLProgram*, GLuint index);
PassRefPtr<WebGLActiveInfo> getActiveUniform(WebGLProgram*, GLuint index);
bool getAttachedShaders(WebGLProgram*, Vector<RefPtr<WebGLShader> >&);
GLint getAttribLocation(WebGLProgram*, const String& name);
WebGLGetInfo getBufferParameter(GLenum target, GLenum pname);
PassRefPtr<WebGLContextAttributes> getContextAttributes();
GLenum getError();
PassRefPtr<WebGLExtension> getExtension(const String& name);
WebGLGetInfo getFramebufferAttachmentParameter(GLenum target, GLenum attachment, GLenum pname);
WebGLGetInfo getParameter(GLenum pname);
WebGLGetInfo getProgramParameter(WebGLProgram*, GLenum pname);
String getProgramInfoLog(WebGLProgram*);
WebGLGetInfo getRenderbufferParameter(GLenum target, GLenum pname);
WebGLGetInfo getShaderParameter(WebGLShader*, GLenum pname);
String getShaderInfoLog(WebGLShader*);
PassRefPtr<WebGLShaderPrecisionFormat> getShaderPrecisionFormat(GLenum shaderType, GLenum precisionType);
String getShaderSource(WebGLShader*);
Vector<String> getSupportedExtensions();
WebGLGetInfo getTexParameter(GLenum target, GLenum pname);
WebGLGetInfo getUniform(WebGLProgram*, const WebGLUniformLocation*);
PassRefPtr<WebGLUniformLocation> getUniformLocation(WebGLProgram*, const String&);
WebGLGetInfo getVertexAttrib(GLuint index, GLenum pname);
long long getVertexAttribOffset(GLuint index, GLenum pname);
void hint(GLenum target, GLenum mode);
GLboolean isBuffer(WebGLBuffer*);
bool isContextLost();
GLboolean isEnabled(GLenum cap);
GLboolean isFramebuffer(WebGLFramebuffer*);
GLboolean isProgram(WebGLProgram*);
GLboolean isRenderbuffer(WebGLRenderbuffer*);
GLboolean isShader(WebGLShader*);
GLboolean isTexture(WebGLTexture*);
void lineWidth(GLfloat);
void linkProgram(WebGLProgram*);
void pixelStorei(GLenum pname, GLint param);
void polygonOffset(GLfloat factor, GLfloat units);
void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, ArrayBufferView* pixels);
void renderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
void sampleCoverage(GLfloat value, GLboolean invert);
void scissor(GLint x, GLint y, GLsizei width, GLsizei height);
void shaderSource(WebGLShader*, const String&);
void stencilFunc(GLenum func, GLint ref, GLuint mask);
void stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
void stencilMask(GLuint);
void stencilMaskSeparate(GLenum face, GLuint mask);
void stencilOp(GLenum fail, GLenum zfail, GLenum zpass);
void stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
void texImage2D(GLenum target, GLint level, GLenum internalformat,
GLsizei width, GLsizei height, GLint border,
GLenum format, GLenum type, ArrayBufferView*, ExceptionState&);
void texImage2D(GLenum target, GLint level, GLenum internalformat,
GLenum format, GLenum type, ImageData*, ExceptionState&);
void texImage2D(GLenum target, GLint level, GLenum internalformat,
GLenum format, GLenum type, HTMLImageElement*, ExceptionState&);
void texImage2D(GLenum target, GLint level, GLenum internalformat,
GLenum format, GLenum type, HTMLCanvasElement*, ExceptionState&);
void texImage2D(GLenum target, GLint level, GLenum internalformat,
GLenum format, GLenum type, HTMLVideoElement*, ExceptionState&);
void texParameterf(GLenum target, GLenum pname, GLfloat param);
void texParameteri(GLenum target, GLenum pname, GLint param);
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height,
GLenum format, GLenum type, ArrayBufferView*, ExceptionState&);
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLenum format, GLenum type, ImageData*, ExceptionState&);
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLenum format, GLenum type, HTMLImageElement*, ExceptionState&);
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLenum format, GLenum type, HTMLCanvasElement*, ExceptionState&);
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLenum format, GLenum type, HTMLVideoElement*, ExceptionState&);
void uniform1f(const WebGLUniformLocation*, GLfloat x);
void uniform1fv(const WebGLUniformLocation*, Float32Array* v);
void uniform1fv(const WebGLUniformLocation*, GLfloat* v, GLsizei);
void uniform1i(const WebGLUniformLocation*, GLint x);
void uniform1iv(const WebGLUniformLocation*, Int32Array* v);
void uniform1iv(const WebGLUniformLocation*, GLint* v, GLsizei);
void uniform2f(const WebGLUniformLocation*, GLfloat x, GLfloat y);
void uniform2fv(const WebGLUniformLocation*, Float32Array* v);
void uniform2fv(const WebGLUniformLocation*, GLfloat* v, GLsizei);
void uniform2i(const WebGLUniformLocation*, GLint x, GLint y);
void uniform2iv(const WebGLUniformLocation*, Int32Array* v);
void uniform2iv(const WebGLUniformLocation*, GLint* v, GLsizei);
void uniform3f(const WebGLUniformLocation*, GLfloat x, GLfloat y, GLfloat z);
void uniform3fv(const WebGLUniformLocation*, Float32Array* v);
void uniform3fv(const WebGLUniformLocation*, GLfloat* v, GLsizei);
void uniform3i(const WebGLUniformLocation*, GLint x, GLint y, GLint z);
void uniform3iv(const WebGLUniformLocation*, Int32Array* v);
void uniform3iv(const WebGLUniformLocation*, GLint* v, GLsizei);
void uniform4f(const WebGLUniformLocation*, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
void uniform4fv(const WebGLUniformLocation*, Float32Array* v);
void uniform4fv(const WebGLUniformLocation*, GLfloat* v, GLsizei);
void uniform4i(const WebGLUniformLocation*, GLint x, GLint y, GLint z, GLint w);
void uniform4iv(const WebGLUniformLocation*, Int32Array* v);
void uniform4iv(const WebGLUniformLocation*, GLint* v, GLsizei);
void uniformMatrix2fv(const WebGLUniformLocation*, GLboolean transpose, Float32Array* value);
void uniformMatrix2fv(const WebGLUniformLocation*, GLboolean transpose, GLfloat* value, GLsizei);
void uniformMatrix3fv(const WebGLUniformLocation*, GLboolean transpose, Float32Array* value);
void uniformMatrix3fv(const WebGLUniformLocation*, GLboolean transpose, GLfloat* value, GLsizei);
void uniformMatrix4fv(const WebGLUniformLocation*, GLboolean transpose, Float32Array* value);
void uniformMatrix4fv(const WebGLUniformLocation*, GLboolean transpose, GLfloat* value, GLsizei);
void useProgram(WebGLProgram*);
void validateProgram(WebGLProgram*);
void vertexAttrib1f(GLuint index, GLfloat x);
void vertexAttrib1fv(GLuint index, Float32Array* values);
void vertexAttrib1fv(GLuint index, GLfloat* values, GLsizei);
void vertexAttrib2f(GLuint index, GLfloat x, GLfloat y);
void vertexAttrib2fv(GLuint index, Float32Array* values);
void vertexAttrib2fv(GLuint index, GLfloat* values, GLsizei);
void vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z);
void vertexAttrib3fv(GLuint index, Float32Array* values);
void vertexAttrib3fv(GLuint index, GLfloat* values, GLsizei);
void vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
void vertexAttrib4fv(GLuint index, Float32Array* values);
void vertexAttrib4fv(GLuint index, GLfloat* values, GLsizei);
void vertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized,
GLsizei stride, long long offset);
void vertexAttribDivisorANGLE(GLuint index, GLuint divisor);
void viewport(GLint x, GLint y, GLsizei width, GLsizei height);
enum LostContextMode {
RealLostContext,
SyntheticLostContext,
AutoRecoverSyntheticLostContext
};
void forceLostContext(LostContextMode);
void forceRestoreContext();
void loseContextImpl(LostContextMode);
blink::WebGraphicsContext3D* webGraphicsContext3D() const { return m_context.get(); }
WebGLContextGroup* contextGroup() const { return m_contextGroup.get(); }
virtual blink::WebLayer* platformLayer() const OVERRIDE;
Extensions3DUtil* extensionsUtil();
void reshape(int width, int height);
void markLayerComposited();
virtual void paintRenderingResultsToCanvas() OVERRIDE;
PassRefPtrWillBeRawPtr<ImageData> paintRenderingResultsToImageData();
void removeSharedObject(WebGLSharedObject*);
void removeContextObject(WebGLContextObject*);
unsigned maxVertexAttribs() const { return m_maxVertexAttribs; }
virtual bool hasPendingActivity() const OVERRIDE;
virtual void stop() OVERRIDE;
protected:
friend class WebGLDrawBuffers;
friend class WebGLFramebuffer;
friend class WebGLObject;
friend class OESVertexArrayObject;
friend class WebGLDebugShaders;
friend class WebGLCompressedTextureATC;
friend class WebGLCompressedTexturePVRTC;
friend class WebGLCompressedTextureS3TC;
friend class WebGLRenderingContextErrorMessageCallback;
friend class WebGLVertexArrayObjectOES;
friend class ScopedTexture2DRestorer;
WebGLRenderingContextBase(HTMLCanvasElement*, PassOwnPtr<blink::WebGraphicsContext3D>, WebGLContextAttributes*);
void initializeNewContext();
void setupFlags();
void addSharedObject(WebGLSharedObject*);
void addContextObject(WebGLContextObject*);
void detachAndRemoveAllObjects();
void destroyContext();
void markContextChanged(ContentChangeType);
bool isGLES2NPOTStrict() { return m_isGLES2NPOTStrict; }
bool isDepthStencilSupported() { return m_isDepthStencilSupported; }
unsigned sizeInBytes(GLenum type);
bool validateRenderingState(const char*);
bool validateWebGLObject(const char*, WebGLObject*);
void addCompressedTextureFormat(GLenum);
void removeAllCompressedTextureFormats();
PassRefPtr<Image> drawImageIntoBuffer(Image*, int width, int height, const char* functionName);
PassRefPtr<Image> videoFrameToImage(HTMLVideoElement*, BackingStoreCopy);
WebGLRenderbuffer* ensureEmulatedStencilBuffer(GLenum target, WebGLRenderbuffer*);
OwnPtr<blink::WebGraphicsContext3D> m_context;
RefPtr<WebGLContextGroup> m_contextGroup;
RefPtr<DrawingBuffer> m_drawingBuffer;
Timer<WebGLRenderingContextBase> m_dispatchContextLostEventTimer;
bool m_restoreAllowed;
Timer<WebGLRenderingContextBase> m_restoreTimer;
bool m_needsUpdate;
bool m_markedCanvasDirty;
HashSet<WebGLContextObject*> m_contextObjects;
OwnPtr<WebGLRenderingContextLostCallback> m_contextLostCallbackAdapter;
OwnPtr<WebGLRenderingContextErrorMessageCallback> m_errorMessageCallbackAdapter;
RefPtr<WebGLBuffer> m_boundArrayBuffer;
RefPtr<WebGLVertexArrayObjectOES> m_defaultVertexArrayObject;
RefPtr<WebGLVertexArrayObjectOES> m_boundVertexArrayObject;
void setBoundVertexArrayObject(PassRefPtr<WebGLVertexArrayObjectOES> arrayObject)
{
if (arrayObject)
m_boundVertexArrayObject = arrayObject;
else
m_boundVertexArrayObject = m_defaultVertexArrayObject;
}
class VertexAttribValue {
public:
VertexAttribValue()
{
initValue();
}
void initValue()
{
value[0] = 0.0f;
value[1] = 0.0f;
value[2] = 0.0f;
value[3] = 1.0f;
}
GLfloat value[4];
};
Vector<VertexAttribValue> m_vertexAttribValue;
unsigned m_maxVertexAttribs;
RefPtr<WebGLBuffer> m_vertexAttrib0Buffer;
long m_vertexAttrib0BufferSize;
GLfloat m_vertexAttrib0BufferValue[4];
bool m_forceAttrib0BufferRefill;
bool m_vertexAttrib0UsedBefore;
RefPtr<WebGLProgram> m_currentProgram;
RefPtr<WebGLFramebuffer> m_framebufferBinding;
RefPtr<WebGLRenderbuffer> m_renderbufferBinding;
class TextureUnitState {
public:
RefPtr<WebGLTexture> m_texture2DBinding;
RefPtr<WebGLTexture> m_textureCubeMapBinding;
};
Vector<TextureUnitState> m_textureUnits;
unsigned long m_activeTextureUnit;
RefPtr<WebGLTexture> m_blackTexture2D;
RefPtr<WebGLTexture> m_blackTextureCubeMap;
Vector<GLenum> m_compressedTextureFormats;
class LRUImageBufferCache {
public:
LRUImageBufferCache(int capacity);
ImageBuffer* imageBuffer(const IntSize& size);
private:
void bubbleToFront(int idx);
OwnPtr<OwnPtr<ImageBuffer>[]> m_buffers;
int m_capacity;
};
LRUImageBufferCache m_generatedImageCache;
GLint m_maxTextureSize;
GLint m_maxCubeMapTextureSize;
GLint m_maxRenderbufferSize;
GLint m_maxViewportDims[2];
GLint m_maxTextureLevel;
GLint m_maxCubeMapTextureLevel;
GLint m_maxDrawBuffers;
GLint m_maxColorAttachments;
GLenum m_backDrawBuffer;
bool m_drawBuffersWebGLRequirementsChecked;
bool m_drawBuffersSupported;
GLint m_packAlignment;
GLint m_unpackAlignment;
bool m_unpackFlipY;
bool m_unpackPremultiplyAlpha;
GLenum m_unpackColorspaceConversion;
bool m_contextLost;
LostContextMode m_contextLostMode;
RefPtr<WebGLContextAttributes> m_requestedAttributes;
bool m_layerCleared;
GLfloat m_clearColor[4];
bool m_scissorEnabled;
GLfloat m_clearDepth;
GLint m_clearStencil;
GLboolean m_colorMask[4];
GLboolean m_depthMask;
bool m_stencilEnabled;
GLuint m_stencilMask, m_stencilMaskBack;
GLint m_stencilFuncRef, m_stencilFuncRefBack;
GLuint m_stencilFuncMask, m_stencilFuncMaskBack;
bool m_isGLES2NPOTStrict;
bool m_isDepthStencilSupported;
bool m_synthesizedErrorsToConsole;
int m_numGLErrorsToConsoleAllowed;
bool m_multisamplingAllowed;
bool m_multisamplingObserverRegistered;
GLuint m_onePlusMaxEnabledAttribIndex;
unsigned long m_onePlusMaxNonDefaultTextureUnit;
OwnPtr<Extensions3DUtil> m_extensionsUtil;
enum ExtensionFlags {
ApprovedExtension = 0x00,
DraftExtension = 0x01,
PrivilegedExtension = 0x02,
EnabledDraftExtension = 0x04,
WebGLDebugRendererInfoExtension = 0x08,
};
class ExtensionTracker {
public:
ExtensionTracker(ExtensionFlags flags, const char* const* prefixes)
: m_privileged(flags & PrivilegedExtension)
, m_draft(flags & DraftExtension)
, m_webglDebugRendererInfo(flags & WebGLDebugRendererInfoExtension)
, m_prefixes(prefixes)
{
}
virtual ~ExtensionTracker()
{
}
bool privileged() const
{
return m_privileged;
}
bool draft() const
{
return m_draft;
}
bool webglDebugRendererInfo() const
{
return m_webglDebugRendererInfo;
}
const char* const* prefixes() const;
bool matchesNameWithPrefixes(const String&) const;
virtual PassRefPtr<WebGLExtension> getExtension(WebGLRenderingContextBase*) = 0;
virtual bool supported(WebGLRenderingContextBase*) const = 0;
virtual const char* extensionName() const = 0;
virtual void loseExtension() = 0;
private:
bool m_privileged;
bool m_draft;
bool m_webglDebugRendererInfo;
const char* const* m_prefixes;
};
template <typename T>
class TypedExtensionTracker FINAL : public ExtensionTracker {
public:
TypedExtensionTracker(RefPtr<T>& extensionField, ExtensionFlags flags, const char* const* prefixes)
: ExtensionTracker(flags, prefixes)
, m_extensionField(extensionField)
, m_extension(nullptr)
{
}
virtual ~TypedExtensionTracker()
{
if (m_extension) {
m_extension->lose(true);
m_extension = nullptr;
}
}
virtual PassRefPtr<WebGLExtension> getExtension(WebGLRenderingContextBase* context) OVERRIDE
{
if (!m_extension) {
m_extension = T::create(context);
m_extensionField = m_extension;
}
return m_extension;
}
virtual bool supported(WebGLRenderingContextBase* context) const OVERRIDE
{
return T::supported(context);
}
virtual const char* extensionName() const OVERRIDE
{
return T::extensionName();
}
virtual void loseExtension() OVERRIDE
{
if (m_extension) {
m_extension->lose(false);
if (m_extension->isLost())
m_extension = nullptr;
}
}
private:
RefPtr<T>& m_extensionField;
RefPtr<T> m_extension;
};
bool m_extensionEnabled[WebGLExtensionNameCount];
Vector<ExtensionTracker*> m_extensions;
template <typename T>
void registerExtension(RefPtr<T>& extensionPtr, ExtensionFlags flags = ApprovedExtension, const char* const* prefixes = 0)
{
m_extensions.append(new TypedExtensionTracker<T>(extensionPtr, flags, prefixes));
}
bool extensionSupportedAndAllowed(const ExtensionTracker*);
inline bool extensionEnabled(WebGLExtensionName name)
{
return m_extensionEnabled[name];
}
Vector<GLenum> m_lostContextErrors;
WebGLGetInfo getBooleanParameter(GLenum);
WebGLGetInfo getBooleanArrayParameter(GLenum);
WebGLGetInfo getFloatParameter(GLenum);
WebGLGetInfo getIntParameter(GLenum);
WebGLGetInfo getUnsignedIntParameter(GLenum);
WebGLGetInfo getWebGLFloatArrayParameter(GLenum);
WebGLGetInfo getWebGLIntArrayParameter(GLenum);
bool clearIfComposited(GLbitfield clearMask = 0);
void restoreStateAfterClear();
GLenum convertTexInternalFormat(GLenum internalformat, GLenum type);
void texImage2DBase(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels, ExceptionState&);
void texImage2DImpl(GLenum target, GLint level, GLenum internalformat, GLenum format, GLenum type, Image*, WebGLImageConversion::ImageHtmlDomSource, bool flipY, bool premultiplyAlpha, ExceptionState&);
void texSubImage2DBase(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels, ExceptionState&);
void texSubImage2DImpl(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLenum format, GLenum type, Image*, WebGLImageConversion::ImageHtmlDomSource, bool flipY, bool premultiplyAlpha, ExceptionState&);
void handleTextureCompleteness(const char*, bool);
void createFallbackBlackTextures1x1();
bool isTexInternalFormatColorBufferCombinationValid(GLenum texInternalFormat, GLenum colorBufferFormat);
GLenum boundFramebufferColorFormat();
bool validateLocationLength(const char* functionName, const String&);
bool validateSize(const char* functionName, GLint x, GLint y);
bool validateString(const char* functionName, const String&);
WebGLTexture* validateTextureBinding(const char* functionName, GLenum target, bool useSixEnumsForCubeMap);
bool validateTexFuncFormatAndType(const char* functionName, GLenum format, GLenum type, GLint level);
bool validateTexFuncLevel(const char* functionName, GLenum target, GLint level);
enum TexFuncValidationFunctionType {
NotTexSubImage2D,
TexSubImage2D,
};
enum TexFuncValidationSourceType {
SourceArrayBufferView,
SourceImageData,
SourceHTMLImageElement,
SourceHTMLCanvasElement,
SourceHTMLVideoElement,
};
bool validateTexFunc(const char* functionName, TexFuncValidationFunctionType, TexFuncValidationSourceType, GLenum target, GLint level, GLenum internalformat, GLsizei width,
GLsizei height, GLint border, GLenum format, GLenum type, GLint xoffset, GLint yoffset);
bool validateTexFuncDimensions(const char* functionName, TexFuncValidationFunctionType, GLenum target, GLint level, GLsizei width, GLsizei height);
bool validateTexFuncParameters(const char* functionName, TexFuncValidationFunctionType, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type);
enum NullDisposition {
NullAllowed,
NullNotAllowed
};
bool validateTexFuncData(const char* functionName, GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, ArrayBufferView* pixels, NullDisposition);
bool validateSettableTexFormat(const char* functionName, GLenum format);
bool validateCompressedTexFuncData(const char* functionName, GLsizei width, GLsizei height, GLenum format, ArrayBufferView* pixels);
bool validateCompressedTexFormat(GLenum format);
bool validateCompressedTexDimensions(const char* functionName, TexFuncValidationFunctionType, GLenum target, GLint level, GLsizei width, GLsizei height, GLenum format);
bool validateCompressedTexSubDimensions(const char* functionName, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, WebGLTexture*);
bool validateDrawMode(const char* functionName, GLenum);
bool validateStencilSettings(const char* functionName);
bool validateStencilOrDepthFunc(const char* functionName, GLenum);
void texParameter(GLenum target, GLenum pname, GLfloat parami, GLint paramf, bool isFloat);
void printGLErrorToConsole(const String&);
void printWarningToConsole(const String&);
bool validateFramebufferFuncParameters(const char* functionName, GLenum target, GLenum attachment);
bool validateBlendEquation(const char* functionName, GLenum);
bool validateBlendFuncFactors(const char* functionName, GLenum src, GLenum dst);
bool validateCapability(const char* functionName, GLenum);
bool validateUniformParameters(const char* functionName, const WebGLUniformLocation*, Float32Array*, GLsizei mod);
bool validateUniformParameters(const char* functionName, const WebGLUniformLocation*, Int32Array*, GLsizei mod);
bool validateUniformParameters(const char* functionName, const WebGLUniformLocation*, void*, GLsizei, GLsizei mod);
bool validateUniformMatrixParameters(const char* functionName, const WebGLUniformLocation*, GLboolean transpose, Float32Array*, GLsizei mod);
bool validateUniformMatrixParameters(const char* functionName, const WebGLUniformLocation*, GLboolean transpose, void*, GLsizei, GLsizei mod);
WebGLBuffer* validateBufferDataParameters(const char* functionName, GLenum target, GLenum usage);
bool validateHTMLImageElement(const char* functionName, HTMLImageElement*, ExceptionState&);
bool validateHTMLCanvasElement(const char* functionName, HTMLCanvasElement*, ExceptionState&);
bool validateHTMLVideoElement(const char* functionName, HTMLVideoElement*, ExceptionState&);
bool validateDrawArrays(const char* functionName, GLenum mode, GLint first, GLsizei count);
bool validateDrawElements(const char* functionName, GLenum mode, GLsizei count, GLenum type, long long offset);
bool validateDrawInstanced(const char* functionName, GLsizei primcount);
void vertexAttribfImpl(const char* functionName, GLuint index, GLsizei expectedSize, GLfloat, GLfloat, GLfloat, GLfloat);
void vertexAttribfvImpl(const char* functionName, GLuint index, Float32Array*, GLsizei expectedSize);
void vertexAttribfvImpl(const char* functionName, GLuint index, GLfloat*, GLsizei, GLsizei expectedSize);
bool deleteObject(WebGLObject*);
bool checkObjectToBeBound(const char* functionName, WebGLObject*, bool& deleted);
void dispatchContextLostEvent(Timer<WebGLRenderingContextBase>*);
void maybeRestoreContext(Timer<WebGLRenderingContextBase>*);
bool allowPrivilegedExtensions() const;
bool allowWebGLDebugRendererInfo() const;
enum ConsoleDisplayPreference {
DisplayInConsole,
DontDisplayInConsole
};
void synthesizeGLError(GLenum, const char* functionName, const char* description, ConsoleDisplayPreference = DisplayInConsole);
void emitGLWarning(const char* function, const char* reason);
String ensureNotNull(const String&) const;
void applyStencilTest();
void enableOrDisable(GLenum capability, bool enable);
IntSize clampedCanvasSize();
GLint maxDrawBuffers();
GLint maxColorAttachments();
void setBackDrawBuffer(GLenum);
void restoreCurrentFramebuffer();
void restoreCurrentTexture2D();
virtual void multisamplingChanged(bool) OVERRIDE;
void findNewMaxEnabledAttribIndex();
void findNewMaxNonDefaultTextureUnit();
friend class WebGLStateRestorer;
friend class WebGLRenderingContextEvictionManager;
static Vector<WebGLRenderingContextBase*>& activeContexts();
static Vector<WebGLRenderingContextBase*>& forciblyEvictedContexts();
static void activateContext(WebGLRenderingContextBase*);
static void deactivateContext(WebGLRenderingContextBase*, bool addToInactiveList);
static void willDestroyContext(WebGLRenderingContextBase*);
static void forciblyLoseOldestContext(const String& reason);
static size_t oldestContextIndex();
static IntSize oldestContextSize();
};
DEFINE_TYPE_CASTS(WebGLRenderingContextBase, CanvasRenderingContext, context, context->is3d(), context.is3d());
}
#endif