Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(729)

Unified Diff: Source/core/html/canvas/WebGLRenderingContextBase.h

Issue 24096029: Moved the majority of WebGL functionality into WebGLRenderingContextBase (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Revamped extension testing, added featureLevel Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/canvas/WebGLRenderingContextBase.h
diff --git a/Source/core/html/canvas/WebGLRenderingContext.h b/Source/core/html/canvas/WebGLRenderingContextBase.h
similarity index 90%
copy from Source/core/html/canvas/WebGLRenderingContext.h
copy to Source/core/html/canvas/WebGLRenderingContextBase.h
index 386bb3746753dc6d29f93c024b5de2dfb5822d63..36b813e56c9f31a0a04f260c4a1cf3f3888a3680 100644
--- a/Source/core/html/canvas/WebGLRenderingContext.h
+++ b/Source/core/html/canvas/WebGLRenderingContextBase.h
@@ -23,11 +23,12 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef WebGLRenderingContext_h
-#define WebGLRenderingContext_h
+#ifndef WebGLRenderingContextBase_h
+#define WebGLRenderingContextBase_h
#include "core/dom/ActiveDOMObject.h"
#include "core/html/canvas/CanvasRenderingContext.h"
+#include "core/html/canvas/WebGLExtensionNames.h"
#include "core/html/canvas/WebGLGetInfo.h"
#include "core/page/Page.h"
#include "core/platform/Timer.h"
@@ -85,14 +86,15 @@ class WebGLTexture;
class WebGLUniformLocation;
class WebGLVertexArrayObjectOES;
-class WebGLRenderingContext : public CanvasRenderingContext, public ActiveDOMObject, private Page::MultisamplingChangedObserver {
+class WebGLRenderingContextBase : public CanvasRenderingContext, public ActiveDOMObject, private Page::MultisamplingChangedObserver {
public:
- static PassOwnPtr<WebGLRenderingContext> create(HTMLCanvasElement*, WebGLContextAttributes*);
- virtual ~WebGLRenderingContext();
+ virtual ~WebGLRenderingContextBase();
virtual bool is3d() const { return true; }
virtual bool isAccelerated() const { return true; }
+ virtual void registerContextExtensions() = 0;
+
int drawingBufferWidth() const;
int drawingBufferHeight() const;
@@ -124,9 +126,9 @@ public:
void compileShader(WebGLShader*);
void compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width,
- GC3Dsizei height, GC3Dint border, ArrayBufferView* data);
+ GC3Dsizei height, GC3Dint border, ArrayBufferView* data);
void compressedTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset,
- GC3Dsizei width, GC3Dsizei height, GC3Denum format, ArrayBufferView* data);
+ GC3Dsizei width, GC3Dsizei height, GC3Denum format, ArrayBufferView* data);
void copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border);
void copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height);
@@ -332,7 +334,7 @@ public:
virtual bool hasPendingActivity() const;
virtual void stop();
- private:
+protected:
friend class WebGLDrawBuffers;
friend class WebGLFramebuffer;
friend class WebGLObject;
@@ -344,7 +346,7 @@ public:
friend class WebGLRenderingContextErrorMessageCallback;
friend class WebGLVertexArrayObjectOES;
- WebGLRenderingContext(HTMLCanvasElement*, PassRefPtr<GraphicsContext3D>, GraphicsContext3D::Attributes, GraphicsContext3D::Attributes);
+ WebGLRenderingContextBase(const String&, unsigned featureLevel, HTMLCanvasElement*, PassRefPtr<GraphicsContext3D>, GraphicsContext3D::Attributes, GraphicsContext3D::Attributes);
void initializeNewContext();
void setupFlags();
@@ -362,7 +364,7 @@ public:
// Helper to return the size in bytes of OpenGL data types
// like GL_FLOAT, GL_INT, etc.
- unsigned int sizeInBytes(GC3Denum type);
+ unsigned sizeInBytes(GC3Denum type);
// Check if each enabled vertex attribute is bound to a buffer.
bool validateRenderingState();
@@ -377,6 +379,8 @@ public:
WebGLRenderbuffer* ensureEmulatedStencilBuffer(GC3Denum target, WebGLRenderbuffer*);
+ const String m_contextName;
+ unsigned m_featureLevel;
RefPtr<GraphicsContext3D> m_context;
RefPtr<WebGLContextGroup> m_contextGroup;
@@ -389,9 +393,9 @@ public:
// likely that there's no JavaScript on the stack, but that might be dependent
// on how exactly the platform discovers that the context was lost. For better
// portability we always defer the dispatch of the event.
- Timer<WebGLRenderingContext> m_dispatchContextLostEventTimer;
+ Timer<WebGLRenderingContextBase> m_dispatchContextLostEventTimer;
bool m_restoreAllowed;
- Timer<WebGLRenderingContext> m_restoreTimer;
+ Timer<WebGLRenderingContextBase> m_restoreTimer;
bool m_needsUpdate;
bool m_markedCanvasDirty;
@@ -456,7 +460,7 @@ public:
public:
LRUImageBufferCache(int capacity);
// The pointer returned is owned by the image buffer map.
- ImageBuffer* imageBuffer(const IntSize& size);
+ ImageBuffer* imageBuffer(const IntSize&);
private:
void bubbleToFront(int idx);
OwnArrayPtr<OwnPtr<ImageBuffer> > m_buffers;
@@ -512,26 +516,6 @@ public:
GC3Duint m_onePlusMaxEnabledAttribIndex;
unsigned long m_onePlusMaxNonDefaultTextureUnit;
- // Enabled extension objects.
- RefPtr<ANGLEInstancedArrays> m_angleInstancedArrays;
- RefPtr<EXTFragDepth> m_extFragDepth;
- RefPtr<EXTTextureFilterAnisotropic> m_extTextureFilterAnisotropic;
- RefPtr<OESTextureFloat> m_oesTextureFloat;
- RefPtr<OESTextureFloatLinear> m_oesTextureFloatLinear;
- RefPtr<OESTextureHalfFloat> m_oesTextureHalfFloat;
- RefPtr<OESTextureHalfFloatLinear> m_oesTextureHalfFloatLinear;
- RefPtr<OESStandardDerivatives> m_oesStandardDerivatives;
- RefPtr<OESVertexArrayObject> m_oesVertexArrayObject;
- RefPtr<OESElementIndexUint> m_oesElementIndexUint;
- RefPtr<WebGLLoseContext> m_webglLoseContext;
- RefPtr<WebGLDebugRendererInfo> m_webglDebugRendererInfo;
- RefPtr<WebGLDebugShaders> m_webglDebugShaders;
- RefPtr<WebGLDrawBuffers> m_webglDrawBuffers;
- RefPtr<WebGLCompressedTextureATC> m_webglCompressedTextureATC;
- RefPtr<WebGLCompressedTexturePVRTC> m_webglCompressedTexturePVRTC;
- RefPtr<WebGLCompressedTextureS3TC> m_webglCompressedTextureS3TC;
- RefPtr<WebGLDepthTexture> m_webglDepthTexture;
-
enum ExtensionFlags {
ApprovedExtension = 0x00,
DraftExtension = 0x01,
@@ -570,8 +554,8 @@ public:
bool matchesNameWithPrefixes(const String&) const;
- virtual PassRefPtr<WebGLExtension> getExtension(WebGLRenderingContext*) const = 0;
- virtual bool supported(WebGLRenderingContext*) const = 0;
+ virtual PassRefPtr<WebGLExtension> getExtension(WebGLRenderingContextBase*) = 0;
+ virtual bool supported(WebGLRenderingContextBase*) const = 0;
virtual const char* getExtensionName() const = 0;
virtual void loseExtension() = 0;
@@ -588,26 +572,29 @@ public:
TypedExtensionTracker(RefPtr<T>& extensionField, ExtensionFlags flags, const char** prefixes)
: ExtensionTracker(flags, prefixes)
, m_extensionField(extensionField)
+ , m_extension(0)
{
}
~TypedExtensionTracker()
{
- if (m_extensionField) {
- m_extensionField->lose(true);
- m_extensionField = 0;
+ if (m_extension) {
+ m_extension->lose(true);
+ m_extension = 0;
}
}
- virtual PassRefPtr<WebGLExtension> getExtension(WebGLRenderingContext* context) const
+ virtual PassRefPtr<WebGLExtension> getExtension(WebGLRenderingContextBase* context)
{
- if (!m_extensionField)
- m_extensionField = T::create(context);
+ if (!m_extension) {
+ m_extension = T::create(context);
+ m_extensionField = m_extension;
+ }
- return m_extensionField;
+ return m_extension;
}
- virtual bool supported(WebGLRenderingContext* context) const
+ virtual bool supported(WebGLRenderingContextBase* context) const
{
return T::supported(context);
}
@@ -619,17 +606,21 @@ public:
virtual void loseExtension()
{
- if (m_extensionField) {
- m_extensionField->lose(false);
- if (m_extensionField->isLost())
- m_extensionField = 0;
+ if (m_extension) {
+ m_extension->lose(false);
+ if (m_extension->isLost())
+ m_extension = 0;
}
}
private:
RefPtr<T>& m_extensionField;
+ // ExtensionTracker holds it's own reference to the extension to ensure
+ // that it is not deleted before this object's destructor is called
+ RefPtr<T> m_extension;
};
+ bool m_extensionEnabled[WebGLExtensionNameCount];
Vector<ExtensionTracker*> m_extensions;
template <typename T>
@@ -638,8 +629,13 @@ public:
m_extensions.append(new TypedExtensionTracker<T>(extensionPtr, flags, prefixes));
}
+ inline bool extensionEnabled(WebGLExtensionName name)
bajones 2013/09/24 00:12:01 It turns out that every single use of the WebGL ex
+ {
+ return m_extensionEnabled[name];
+ }
+
// Errors raised by synthesizeGLError() while the context is lost.
- Vector<GC3Denum> lost_context_errors_;
+ Vector<GC3Denum> m_lostContextErrors;
// Helpers for getParameter and others
WebGLGetInfo getBooleanParameter(GC3Denum);
@@ -669,8 +665,7 @@ public:
// Helper function for copyTex{Sub}Image, check whether the internalformat
// and the color buffer format of the current bound framebuffer combination
// is valid.
- bool isTexInternalFormatColorBufferCombinationValid(GC3Denum texInternalFormat,
- GC3Denum colorBufferFormat);
+ bool isTexInternalFormatColorBufferCombinationValid(GC3Denum texInternalFormat, GC3Denum colorBufferFormat);
// Helper function to get the bound framebuffer's color buffer format.
GC3Denum getBoundFramebufferColorFormat();
@@ -694,7 +689,7 @@ public:
// Helper function to check target and texture bound to the target.
// Generate GL errors and return 0 if target is invalid or texture bound is
- // null. Otherwise, return the texture bound to the target.
+ // null. Otherwise, return the texture bound to the target.
WebGLTexture* validateTextureBinding(const char* functionName, GC3Denum target, bool useSixEnumsForCubeMap);
// Helper function to check input format/type for functions {copy}Tex{Sub}Image.
@@ -731,11 +726,11 @@ public:
// Helper function to check input parameters for functions {copy}Tex{Sub}Image.
// Generates GL error and returns false if parameters are invalid.
bool validateTexFuncParameters(const char* functionName,
- TexFuncValidationFunctionType,
- GC3Denum target, GC3Dint level,
- GC3Denum internalformat,
- GC3Dsizei width, GC3Dsizei height, GC3Dint border,
- GC3Denum format, GC3Denum type);
+ TexFuncValidationFunctionType,
+ GC3Denum target, GC3Dint level,
+ GC3Denum internalformat,
+ GC3Dsizei width, GC3Dsizei height, GC3Dint border,
+ GC3Denum format, GC3Denum type);
enum NullDisposition {
NullAllowed,
@@ -746,10 +741,10 @@ public:
// is of the correct type and contains enough data for the texImage call.
// Generates GL error and returns false if parameters are invalid.
bool validateTexFuncData(const char* functionName, GC3Dint level,
- GC3Dsizei width, GC3Dsizei height,
- GC3Denum format, GC3Denum type,
- ArrayBufferView* pixels,
- NullDisposition);
+ GC3Dsizei width, GC3Dsizei height,
+ GC3Denum format, GC3Denum type,
+ ArrayBufferView* pixels,
+ NullDisposition);
// Helper function to validate a given texture format is settable as in
// you can supply data to texImage2D, or call texImage2D, copyTexImage2D and
@@ -760,8 +755,8 @@ public:
// Helper function to validate compressed texture data is correct size
// for the given format and dimensions.
bool validateCompressedTexFuncData(const char* functionName,
- GC3Dsizei width, GC3Dsizei height,
- GC3Denum format, ArrayBufferView* pixels);
+ GC3Dsizei width, GC3Dsizei height,
+ GC3Denum format, ArrayBufferView* pixels);
// Helper function for validating compressed texture formats.
bool validateCompressedTexFormat(GC3Denum format);
@@ -773,7 +768,7 @@ public:
// Helper function to validate compressed texture dimensions are valid for
// the given format.
bool validateCompressedTexSubDimensions(const char* functionName, GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset,
- GC3Dsizei width, GC3Dsizei height, GC3Denum format, WebGLTexture*);
+ GC3Dsizei width, GC3Dsizei height, GC3Denum format, WebGLTexture*);
// Helper function to validate mode for draw{Arrays/Elements}.
bool validateDrawMode(const char* functionName, GC3Denum);
@@ -850,9 +845,9 @@ public:
// Return false if caller should return without further processing.
bool checkObjectToBeBound(const char* functionName, WebGLObject*, bool& deleted);
- void dispatchContextLostEvent(Timer<WebGLRenderingContext>*);
+ void dispatchContextLostEvent(Timer<WebGLRenderingContextBase>*);
// Helper for restoration after context lost.
- void maybeRestoreContext(Timer<WebGLRenderingContext>*);
+ void maybeRestoreContext(Timer<WebGLRenderingContextBase>*);
// Determine if we are running privileged code in the browser, for example,
// a Safari or Chrome extension.
@@ -898,14 +893,16 @@ public:
friend class WebGLStateRestorer;
friend class WebGLRenderingContextEvictionManager;
- static Vector<WebGLRenderingContext*>& activeContexts();
- static Vector<WebGLRenderingContext*>& forciblyEvictedContexts();
+ static Vector<WebGLRenderingContextBase*>& activeContexts();
+ static Vector<WebGLRenderingContextBase*>& forciblyEvictedContexts();
- static void activateContext(WebGLRenderingContext*);
- static void deactivateContext(WebGLRenderingContext*, bool addToInactiveList);
- static void willDestroyContext(WebGLRenderingContext*);
+ static void activateContext(WebGLRenderingContextBase*);
+ static void deactivateContext(WebGLRenderingContextBase*, bool addToInactiveList);
+ static void willDestroyContext(WebGLRenderingContextBase*);
static void forciblyLoseOldestContext(const String& reason);
static IntSize oldestContextSize();
+
+ static GraphicsContext3D::Attributes adjustAttributes(const GraphicsContext3D::Attributes&, Settings*);
};
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698