Bug 911879 - Give WebGLContext.h a good round of removing unneeded inline method bodies - r=jgilbert
authorBenoit Jacob <bjacob@mozilla.com>
Wed, 04 Sep 2013 08:14:50 -0400
changeset 158360 b8a27424be7fdba315c337a207ffc39af934e602
parent 158359 cafd5d260e660cd249a7f52929b3f5fb359b829e
child 158361 5c04fad82d85d30b88b11a72fab787b91d188d29
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs911879
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 911879 - Give WebGLContext.h a good round of removing unneeded inline method bodies - r=jgilbert
content/canvas/src/WebGLContext.h
content/canvas/src/WebGLContextGL.cpp
content/canvas/src/WebGLContextLossTimer.cpp
content/canvas/src/WebGLContextUtils.cpp
content/canvas/src/moz.build
--- a/content/canvas/src/WebGLContext.h
+++ b/content/canvas/src/WebGLContext.h
@@ -185,46 +185,40 @@ public:
 
     void SynthesizeGLError(GLenum err);
     void SynthesizeGLError(GLenum err, const char *fmt, ...);
 
     void ErrorInvalidEnum(const char *fmt = 0, ...);
     void ErrorInvalidOperation(const char *fmt = 0, ...);
     void ErrorInvalidValue(const char *fmt = 0, ...);
     void ErrorInvalidFramebufferOperation(const char *fmt = 0, ...);
-    void ErrorInvalidEnumInfo(const char *info, GLenum enumvalue) {
-        return ErrorInvalidEnum("%s: invalid enum value 0x%x", info, enumvalue);
-    }
+    void ErrorInvalidEnumInfo(const char *info, GLenum enumvalue);
     void ErrorOutOfMemory(const char *fmt = 0, ...);
 
     const char *ErrorName(GLenum error);
     bool IsTextureFormatCompressed(GLenum format);
 
     void DummyFramebufferOperation(const char *info);
 
-    WebGLTexture *activeBoundTextureForTarget(GLenum target) {
+    WebGLTexture *activeBoundTextureForTarget(GLenum target) const {
         return target == LOCAL_GL_TEXTURE_2D ? mBound2DTextures[mActiveTexture]
                                              : mBoundCubeMapTextures[mActiveTexture];
     }
 
     already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
                                                  CanvasLayer *aOldLayer,
                                                  LayerManager *aManager) MOZ_OVERRIDE;
 
     // Note that 'clean' here refers to its invalidation state, not the
     // contents of the buffer.
     void MarkContextClean() MOZ_OVERRIDE { mInvalidated = false; }
 
-    gl::GLContext* GL() const {
-        return gl;
-    }
+    gl::GLContext* GL() const { return gl; }
 
-    bool IsPremultAlpha() const {
-        return mOptions.premultipliedAlpha;
-    }
+    bool IsPremultAlpha() const { return mOptions.premultipliedAlpha; }
 
     bool PresentScreenBuffer();
 
     // a number that increments every time we have an event that causes
     // all context resources to be lost.
     uint32_t Generation() { return mGeneration.value(); }
 
     const WebGLRectangleObject *FramebufferRectangleObject() const;
@@ -235,101 +229,45 @@ public:
     // amount of work it does.
     // It only clears the buffers we specify, and can reset its state without
     // first having to query anything, as WebGL knows its state at all times.
     void ForceClearFramebufferWithDefaultValues(GLbitfield mask, const bool colorAttachmentsMask[sMaxColorAttachments]);
 
     // Calls ForceClearFramebufferWithDefaultValues() for the Context's 'screen'.
     void ClearScreen();
 
-    // checks for GL errors, clears any pending GL error, stores the current GL error in currentGLError,
+    // checks for GL errors, clears any pending GL error, stores the current GL error in currentGLError (if not nullptr),
     // and copies it into mWebGLError if it doesn't already have an error set
-    void UpdateWebGLErrorAndClearGLError(GLenum *currentGLError) {
-        // get and clear GL error in ALL cases
-        *currentGLError = gl->GetAndClearError();
-        // only store in mWebGLError if is hasn't already recorded an error
-        if (!mWebGLError)
-            mWebGLError = *currentGLError;
-    }
-    
-    // checks for GL errors, clears any pending GL error,
-    // and stores the current GL error into mWebGLError if it doesn't already have an error set
-    void UpdateWebGLErrorAndClearGLError() {
-        GLenum currentGLError;
-        UpdateWebGLErrorAndClearGLError(&currentGLError);
-    }
-    
-    bool MinCapabilityMode() const {
-        return mMinCapability;
-    }
+    void UpdateWebGLErrorAndClearGLError(GLenum *currentGLError = nullptr);
+
+    bool MinCapabilityMode() const { return mMinCapability; }
 
     void RobustnessTimerCallback(nsITimer* timer);
-
-    static void RobustnessTimerCallbackStatic(nsITimer* timer, void *thisPointer) {
-        static_cast<WebGLContext*>(thisPointer)->RobustnessTimerCallback(timer);
-    }
-
-    void SetupContextLossTimer() {
-        // If the timer was already running, don't restart it here. Instead,
-        // wait until the previous call is done, then fire it one more time.
-        // This is an optimization to prevent unnecessary cross-communication
-        // between threads.
-        if (mContextLossTimerRunning) {
-            mDrawSinceContextLossTimerSet = true;
-            return;
-        }
-
-        mContextRestorer->InitWithFuncCallback(RobustnessTimerCallbackStatic,
-                                               static_cast<void*>(this),
-                                               1000,
-                                               nsITimer::TYPE_ONE_SHOT);
-        mContextLossTimerRunning = true;
-        mDrawSinceContextLossTimerSet = false;
-    }
-
-    void TerminateContextLossTimer() {
-        if (mContextLossTimerRunning) {
-            mContextRestorer->Cancel();
-            mContextLossTimerRunning = false;
-        }
-    }
+    static void RobustnessTimerCallbackStatic(nsITimer* timer, void *thisPointer);
+    void SetupContextLossTimer();
+    void TerminateContextLossTimer();
 
     // WebIDL WebGLRenderingContext API
-    dom::HTMLCanvasElement* GetCanvas() const {
-        return mCanvasElement;
-    }
-    GLsizei DrawingBufferWidth() const {
-        if (IsContextLost())
-            return 0;
-        return mWidth;
-    }
-    GLsizei DrawingBufferHeight() const {
-        if (IsContextLost())
-            return 0;
-        return mHeight;
-    }
+    dom::HTMLCanvasElement* GetCanvas() const { return mCanvasElement; }
+    GLsizei DrawingBufferWidth() const { return IsContextLost() ? 0 : mWidth; }
+    GLsizei DrawingBufferHeight() const { return IsContextLost() ? 0 : mHeight; }
 
     void GetContextAttributes(dom::Nullable<dom::WebGLContextAttributesInitializer>& retval);
     bool IsContextLost() const { return mContextStatus != ContextNotLost; }
     void GetSupportedExtensions(JSContext *cx, dom::Nullable< nsTArray<nsString> > &retval);
     JSObject* GetExtension(JSContext* cx, const nsAString& aName, ErrorResult& rv);
     void ActiveTexture(GLenum texture);
     void AttachShader(WebGLProgram* program, WebGLShader* shader);
     void BindAttribLocation(WebGLProgram* program, GLuint location,
                             const nsAString& name);
     void BindFramebuffer(GLenum target, WebGLFramebuffer* wfb);
     void BindRenderbuffer(GLenum target, WebGLRenderbuffer* wrb);
     void BindTexture(GLenum target, WebGLTexture *tex);
     void BindVertexArray(WebGLVertexArray *vao);
-    void BlendColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a) {
-        if (IsContextLost())
-            return;
-        MakeContextCurrent();
-        gl->fBlendColor(r, g, b, a);
-    }
+    void BlendColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
     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);
     GLenum CheckFramebufferStatus(GLenum target);
     void Clear(GLbitfield mask);
     void ClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
@@ -365,28 +303,18 @@ public:
     void DeleteShader(WebGLShader *shader);
     void DeleteVertexArray(WebGLVertexArray *vao);
     void DeleteTexture(WebGLTexture *tex);
     void DepthFunc(GLenum func);
     void DepthMask(WebGLboolean b);
     void DepthRange(GLclampf zNear, GLclampf zFar);
     void DetachShader(WebGLProgram *program, WebGLShader *shader);
     void DrawBuffers(const dom::Sequence<GLenum>& buffers);
-    void Flush() {
-        if (IsContextLost())
-            return;
-        MakeContextCurrent();
-        gl->fFlush();
-    }
-    void Finish() {
-        if (IsContextLost())
-            return;
-        MakeContextCurrent();
-        gl->fFinish();
-    }
+    void Flush();
+    void Finish();
     void FramebufferRenderbuffer(GLenum target, GLenum attachment,
                                  GLenum rbtarget, WebGLRenderbuffer *wrb);
     void FramebufferTexture2D(GLenum target, GLenum attachment,
                               GLenum textarget, WebGLTexture *tobj,
                               GLint level);
     void FrontFace(GLenum mode);
     void GenerateMipmap(GLenum target);
     already_AddRefed<WebGLActiveInfo> GetActiveAttrib(WebGLProgram *prog,
@@ -440,42 +368,27 @@ public:
       GetUniformLocation(WebGLProgram *prog, const nsAString& name);
     void Hint(GLenum target, GLenum mode);
     bool IsFramebuffer(WebGLFramebuffer *fb);
     bool IsProgram(WebGLProgram *prog);
     bool IsRenderbuffer(WebGLRenderbuffer *rb);
     bool IsShader(WebGLShader *shader);
     bool IsTexture(WebGLTexture *tex);
     bool IsVertexArray(WebGLVertexArray *vao);
-    void LineWidth(GLfloat width) {
-        if (IsContextLost())
-            return;
-        MakeContextCurrent();
-        gl->fLineWidth(width);
-    }
+    void LineWidth(GLfloat width);
     void LinkProgram(WebGLProgram *program);
     void PixelStorei(GLenum pname, GLint param);
-    void PolygonOffset(GLfloat factor, GLfloat units) {
-        if (IsContextLost())
-            return;
-        MakeContextCurrent();
-        gl->fPolygonOffset(factor, units);
-    }
+    void PolygonOffset(GLfloat factor, GLfloat units);
     void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
                     GLenum format, GLenum type,
                     const Nullable<dom::ArrayBufferView> &pixels,
                     ErrorResult& rv);
     void RenderbufferStorage(GLenum target, GLenum internalformat,
                              GLsizei width, GLsizei height);
-    void SampleCoverage(GLclampf value, WebGLboolean invert) {
-        if (IsContextLost())
-            return;
-        MakeContextCurrent();
-        gl->fSampleCoverage(value, invert);
-    }
+    void SampleCoverage(GLclampf value, WebGLboolean invert);
     void Scissor(GLint x, GLint y, GLsizei width, GLsizei height);
     void ShaderSource(WebGLShader *shader, const nsAString& source);
     void StencilFunc(GLenum func, GLint ref, GLuint mask);
     void StencilFuncSeparate(GLenum face, GLenum func, GLint ref,
                              GLuint mask);
     void StencilMask(GLuint mask);
     void StencilMaskSeparate(GLenum face, GLuint mask);
     void StencilOp(GLenum sfail, GLenum dpfail, GLenum dppass);
@@ -1199,23 +1112,17 @@ protected:
     // Used for some hardware (particularly Tegra 2 and 4) that likes to
     // be Flushed while doing hundreds of draw calls.
     int mDrawCallsSinceLastFlush;
 
     int mAlreadyGeneratedWarnings;
     int mMaxWarnings;
     bool mAlreadyWarnedAboutFakeVertexAttrib0;
 
-    bool ShouldGenerateWarnings() const {
-        if (mMaxWarnings == -1) {
-            return true;
-        }
-
-        return mAlreadyGeneratedWarnings < mMaxWarnings;
-    }
+    bool ShouldGenerateWarnings() const;
 
     uint64_t mLastUseIndex;
 
     void LoseOldestWebGLContextIfLimitExceeded();
     void UpdateLastUseIndex();
 
     template <typename WebGLObjectType>
     JS::Value WebGLObjectAsJSValue(JSContext *cx, const WebGLObjectType *, ErrorResult& rv) const;
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -4188,8 +4188,56 @@ WebGLContext::ReattachTextureToAnyFrameb
             framebuffer->FramebufferTexture2D(
               LOCAL_GL_FRAMEBUFFER, LOCAL_GL_DEPTH_STENCIL_ATTACHMENT,
               tex->Target(), tex, level);
         }
     }
 
     BindFramebuffer(LOCAL_GL_FRAMEBUFFER, curFB);
 }
+
+void
+WebGLContext::BlendColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a) {
+    if (IsContextLost())
+        return;
+    MakeContextCurrent();
+    gl->fBlendColor(r, g, b, a);
+}
+
+void
+WebGLContext::Flush() {
+    if (IsContextLost())
+        return;
+    MakeContextCurrent();
+    gl->fFlush();
+}
+
+void
+WebGLContext::Finish() {
+    if (IsContextLost())
+        return;
+    MakeContextCurrent();
+    gl->fFinish();
+}
+
+void
+WebGLContext::LineWidth(GLfloat width) {
+    if (IsContextLost())
+        return;
+    MakeContextCurrent();
+    gl->fLineWidth(width);
+}
+
+void
+WebGLContext::PolygonOffset(GLfloat factor, GLfloat units) {
+    if (IsContextLost())
+        return;
+    MakeContextCurrent();
+    gl->fPolygonOffset(factor, units);
+}
+
+void
+WebGLContext::SampleCoverage(GLclampf value, WebGLboolean invert) {
+    if (IsContextLost())
+        return;
+    MakeContextCurrent();
+    gl->fSampleCoverage(value, invert);
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/content/canvas/src/WebGLContextLossTimer.cpp
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "WebGLContext.h"
+
+using namespace mozilla;
+
+/* static */ void
+WebGLContext::RobustnessTimerCallbackStatic(nsITimer* timer, void *thisPointer) {
+    static_cast<WebGLContext*>(thisPointer)->RobustnessTimerCallback(timer);
+}
+
+void
+WebGLContext::SetupContextLossTimer() {
+    // If the timer was already running, don't restart it here. Instead,
+    // wait until the previous call is done, then fire it one more time.
+    // This is an optimization to prevent unnecessary cross-communication
+    // between threads.
+    if (mContextLossTimerRunning) {
+        mDrawSinceContextLossTimerSet = true;
+        return;
+    }
+
+    mContextRestorer->InitWithFuncCallback(RobustnessTimerCallbackStatic,
+                                            static_cast<void*>(this),
+                                            1000,
+                                            nsITimer::TYPE_ONE_SHOT);
+    mContextLossTimerRunning = true;
+    mDrawSinceContextLossTimerSet = false;
+}
+
+void
+WebGLContext::TerminateContextLossTimer() {
+    if (mContextLossTimerRunning) {
+        mContextRestorer->Cancel();
+        mContextLossTimerRunning = false;
+    }
+}
--- a/content/canvas/src/WebGLContextUtils.cpp
+++ b/content/canvas/src/WebGLContextUtils.cpp
@@ -50,16 +50,26 @@ WebGLContext::GenerateWarning(const char
     JS_ReportWarning(cx, "WebGL: %s", buf);
     if (!ShouldGenerateWarnings()) {
         JS_ReportWarning(cx,
             "WebGL: No further warnings will be reported for this WebGL context "
             "(already reported %d warnings)", mAlreadyGeneratedWarnings);
     }
 }
 
+bool
+WebGLContext::ShouldGenerateWarnings() const
+{
+    if (mMaxWarnings == -1) {
+        return true;
+    }
+
+    return mAlreadyGeneratedWarnings < mMaxWarnings;
+}
+
 CheckedUint32
 WebGLContext::GetImageSize(GLsizei height, 
                            GLsizei width, 
                            uint32_t pixelSize,
                            uint32_t packOrUnpackAlignment)
 {
     CheckedUint32 checked_plainRowSize = CheckedUint32(width) * pixelSize;
 
@@ -107,16 +117,22 @@ WebGLContext::ErrorInvalidEnum(const cha
     va_start(va, fmt);
     GenerateWarning(fmt, va);
     va_end(va);
 
     return SynthesizeGLError(LOCAL_GL_INVALID_ENUM);
 }
 
 void
+WebGLContext::ErrorInvalidEnumInfo(const char *info, GLenum enumvalue)
+{
+    return ErrorInvalidEnum("%s: invalid enum value 0x%x", info, enumvalue);
+}
+
+void
 WebGLContext::ErrorInvalidOperation(const char *fmt, ...)
 {
     va_list va;
     va_start(va, fmt);
     GenerateWarning(fmt, va);
     va_end(va);
 
     return SynthesizeGLError(LOCAL_GL_INVALID_OPERATION);
@@ -203,8 +219,20 @@ WebGLContext::IsTextureFormatCompressed(
         case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
             return true;
     }
 
     NS_NOTREACHED("Invalid WebGL texture format?");
     NS_ABORT();
     return false;
 }
+
+void
+WebGLContext::UpdateWebGLErrorAndClearGLError(GLenum *currentGLError)
+{
+    // get and clear GL error in ALL cases
+    GLenum error = gl->GetAndClearError();
+    if (currentGLError)
+        *currentGLError = error;
+    // only store in mWebGLError if is hasn't already recorded an error
+    if (!mWebGLError)
+        mWebGLError = error;
+}
--- a/content/canvas/src/moz.build
+++ b/content/canvas/src/moz.build
@@ -28,16 +28,17 @@ if CONFIG['MOZ_WEBGL']:
     CPP_SOURCES += [
         'WebGLActiveInfo.cpp',
         'WebGLBuffer.cpp',
         'WebGL1Context.cpp',
         'WebGL2Context.cpp',
         'WebGLContext.cpp',
         'WebGLContextAsyncQueries.cpp',
         'WebGLContextBuffers.cpp',
+        'WebGLContextLossTimer.cpp',
         'WebGLContextGL.cpp',
         'WebGLContextUtils.cpp',
         'WebGLContextReporter.cpp',
         'WebGLContextState.cpp',
         'WebGLContextValidate.cpp',
         'WebGLContextExtensions.cpp',
         'WebGLContextFramebufferOperations.cpp',
         'WebGLContextVertexArray.cpp',