author | Saurabh Anand <saurabhanandiit@gmail.com> |
Mon, 03 Dec 2012 23:57:25 +0530 (2012-12-03) | |
changeset 114840 | b8b88df64dba01b77d415d6134e119210d75eb30 |
parent 114839 | 357731870ae51320ba2934189ae17f793e1396c4 |
child 114841 | ef5d80327785b28df0bd778acc86f4987ba5a678 |
push id | 23947 |
push user | emorley@mozilla.com |
push date | Tue, 04 Dec 2012 14:54:11 +0000 (2012-12-04) |
treeherder | mozilla-central@0035f77045bc [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | bjacob |
bugs | 816168 |
milestone | 20.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
|
--- a/content/canvas/src/WebGLContext.h +++ b/content/canvas/src/WebGLContext.h @@ -4,16 +4,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef WEBGLCONTEXT_H_ #define WEBGLCONTEXT_H_ #include "WebGLElementArrayCache.h" #include "WebGLObjectModel.h" #include "WebGLBuffer.h" +#include "WebGLRenderbuffer.h" #include "WebGLVertexAttribData.h" #include "WebGLShaderPrecisionFormat.h" #include <stdarg.h> #include <vector> #include "nsTArray.h" #include "nsDataHashtable.h" #include "nsHashKeys.h" @@ -69,19 +70,17 @@ class nsIPropertyBag; namespace mozilla { class WebGLTexture; class WebGLProgram; class WebGLShader; class WebGLFramebuffer; class WebGLUniformLocation; -class WebGLRenderbuffer; class WebGLMemoryPressureObserver; -class WebGLRectangleObject; class WebGLContextBoundObject; class WebGLActiveInfo; class WebGLExtensionBase; namespace dom { struct WebGLContextAttributes; struct WebGLContextAttributesInitializer; } @@ -146,57 +145,16 @@ using WebGLTexelConversions::WebGLTexelF WebGLTexelFormat GetWebGLTexelFormat(GLenum format, GLenum type); // Zero is not an integer power of two. inline bool is_pot_assuming_nonnegative(WebGLsizei x) { return x && (x & (x-1)) == 0; } -// this class is a mixin for GL objects that have dimensions -// that we need to track. -class WebGLRectangleObject -{ -public: - WebGLRectangleObject() - : mWidth(0), mHeight(0) { } - - WebGLRectangleObject(WebGLsizei width, WebGLsizei height) - : mWidth(width), mHeight(height) { } - - WebGLsizei Width() const { return mWidth; } - void width(WebGLsizei value) { mWidth = value; } - - WebGLsizei Height() const { return mHeight; } - void height(WebGLsizei value) { mHeight = value; } - - void setDimensions(WebGLsizei width, WebGLsizei height) { - mWidth = width; - mHeight = height; - } - - void setDimensions(WebGLRectangleObject *rect) { - if (rect) { - mWidth = rect->Width(); - mHeight = rect->Height(); - } else { - mWidth = 0; - mHeight = 0; - } - } - - bool HasSameDimensionsAs(const WebGLRectangleObject& other) const { - return Width() == other.Width() && Height() == other.Height(); - } - -protected: - WebGLsizei mWidth; - WebGLsizei mHeight; -}; - struct WebGLContextOptions { // these are defaults WebGLContextOptions(); bool operator==(const WebGLContextOptions& other) const { return alpha == other.alpha && depth == other.depth && @@ -2137,109 +2095,16 @@ protected: // post-link data std::vector<bool> mAttribsInUse; nsAutoPtr<CStringMap> mIdentifierMap, mIdentifierReverseMap; nsAutoPtr<CStringToUniformInfoMap> mUniformInfoMap; int mAttribMaxNameLength; }; -class WebGLRenderbuffer MOZ_FINAL - : public nsISupports - , public WebGLRefCountedObject<WebGLRenderbuffer> - , public LinkedListElement<WebGLRenderbuffer> - , public WebGLRectangleObject - , public WebGLContextBoundObject - , public nsWrapperCache -{ -public: - WebGLRenderbuffer(WebGLContext *context) - : WebGLContextBoundObject(context) - , mInternalFormat(0) - , mInternalFormatForGL(0) - , mHasEverBeenBound(false) - , mInitialized(false) - { - SetIsDOMBinding(); - mContext->MakeContextCurrent(); - mContext->gl->fGenRenderbuffers(1, &mGLName); - mContext->mRenderbuffers.insertBack(this); - } - - ~WebGLRenderbuffer() { - DeleteOnce(); - } - - void Delete() { - mContext->MakeContextCurrent(); - mContext->gl->fDeleteRenderbuffers(1, &mGLName); - LinkedListElement<WebGLRenderbuffer>::removeFrom(mContext->mRenderbuffers); - } - - bool HasEverBeenBound() { return mHasEverBeenBound; } - void SetHasEverBeenBound(bool x) { mHasEverBeenBound = x; } - WebGLuint GLName() const { return mGLName; } - - bool Initialized() const { return mInitialized; } - void SetInitialized(bool aInitialized) { mInitialized = aInitialized; } - - WebGLenum InternalFormat() const { return mInternalFormat; } - void SetInternalFormat(WebGLenum aInternalFormat) { mInternalFormat = aInternalFormat; } - - WebGLenum InternalFormatForGL() const { return mInternalFormatForGL; } - void SetInternalFormatForGL(WebGLenum aInternalFormatForGL) { mInternalFormatForGL = aInternalFormatForGL; } - - int64_t MemoryUsage() const { - int64_t pixels = int64_t(Width()) * int64_t(Height()); - - // If there is no defined format, we're not taking up any memory - if (!mInternalFormatForGL) { - return 0; - } - - switch (mInternalFormatForGL) { - case LOCAL_GL_STENCIL_INDEX8: - return pixels; - case LOCAL_GL_RGBA4: - case LOCAL_GL_RGB5_A1: - case LOCAL_GL_RGB565: - case LOCAL_GL_DEPTH_COMPONENT16: - return 2 * pixels; - case LOCAL_GL_RGB8: - case LOCAL_GL_DEPTH_COMPONENT24: - return 3*pixels; - case LOCAL_GL_RGBA8: - case LOCAL_GL_DEPTH24_STENCIL8: - return 4*pixels; - default: - break; - } - NS_ABORT(); - return 0; - } - - WebGLContext *GetParentObject() const { - return Context(); - } - - virtual JSObject* WrapObject(JSContext *cx, JSObject *scope, bool *triedToWrap); - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WebGLRenderbuffer) - -protected: - - WebGLuint mGLName; - WebGLenum mInternalFormat; - WebGLenum mInternalFormatForGL; - bool mHasEverBeenBound; - bool mInitialized; - - friend class WebGLFramebuffer; -}; class WebGLFramebufferAttachment { // deleting a texture or renderbuffer immediately detaches it WebGLRefPtr<WebGLTexture> mTexturePtr; WebGLRefPtr<WebGLRenderbuffer> mRenderbufferPtr; WebGLenum mAttachmentPoint; WebGLint mTextureLevel;
--- a/content/canvas/src/WebGLObjectModel.h +++ b/content/canvas/src/WebGLObjectModel.h @@ -278,16 +278,57 @@ public: WebGLContext *Context() const { return mContext; } protected: WebGLContext *mContext; uint32_t mContextGeneration; }; +// this class is a mixin for GL objects that have dimensions +// that we need to track. +class WebGLRectangleObject +{ +public: + WebGLRectangleObject() + : mWidth(0), mHeight(0) { } + + WebGLRectangleObject(WebGLsizei width, WebGLsizei height) + : mWidth(width), mHeight(height) { } + + WebGLsizei Width() const { return mWidth; } + void width(WebGLsizei value) { mWidth = value; } + + WebGLsizei Height() const { return mHeight; } + void height(WebGLsizei value) { mHeight = value; } + + void setDimensions(WebGLsizei width, WebGLsizei height) { + mWidth = width; + mHeight = height; + } + + void setDimensions(WebGLRectangleObject *rect) { + if (rect) { + mWidth = rect->Width(); + mHeight = rect->Height(); + } else { + mWidth = 0; + mHeight = 0; + } + } + + bool HasSameDimensionsAs(const WebGLRectangleObject& other) const { + return Width() == other.Width() && Height() == other.Height(); + } + +protected: + WebGLsizei mWidth; + WebGLsizei mHeight; +}; + }// namespace mozilla template <typename T> inline void ImplCycleCollectionUnlink(mozilla::WebGLRefPtr<T>& aField) { aField = nullptr; }
--- a/content/canvas/src/WebGLRenderbuffer.cpp +++ b/content/canvas/src/WebGLRenderbuffer.cpp @@ -1,23 +1,74 @@ /* -*- 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" +#include "WebGLRenderbuffer.h" #include "mozilla/dom/WebGLRenderingContextBinding.h" using namespace mozilla; JSObject* WebGLRenderbuffer::WrapObject(JSContext *cx, JSObject *scope, bool *triedToWrap) { return dom::WebGLRenderbufferBinding::Wrap(cx, scope, this, triedToWrap); } +WebGLRenderbuffer::WebGLRenderbuffer(WebGLContext *context) + : WebGLContextBoundObject(context) + , mInternalFormat(0) + , mInternalFormatForGL(0) + , mHasEverBeenBound(false) + , mInitialized(false) +{ + SetIsDOMBinding(); + mContext->MakeContextCurrent(); + mContext->gl->fGenRenderbuffers(1, &mGLName); + mContext->mRenderbuffers.insertBack(this); +} + +void +WebGLRenderbuffer::Delete() { + mContext->MakeContextCurrent(); + mContext->gl->fDeleteRenderbuffers(1, &mGLName); + LinkedListElement<WebGLRenderbuffer>::removeFrom(mContext->mRenderbuffers); +} + +int64_t +WebGLRenderbuffer::MemoryUsage() const { + int64_t pixels = int64_t(Width()) * int64_t(Height()); + + // If there is no defined format, we're not taking up any memory + if (!mInternalFormatForGL) { + return 0; + } + + switch (mInternalFormatForGL) { + case LOCAL_GL_STENCIL_INDEX8: + return pixels; + case LOCAL_GL_RGBA4: + case LOCAL_GL_RGB5_A1: + case LOCAL_GL_RGB565: + case LOCAL_GL_DEPTH_COMPONENT16: + return 2 * pixels; + case LOCAL_GL_RGB8: + case LOCAL_GL_DEPTH_COMPONENT24: + return 3*pixels; + case LOCAL_GL_RGBA8: + case LOCAL_GL_DEPTH24_STENCIL8: + return 4*pixels; + default: + break; + } + NS_ABORT(); + return 0; +} + NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLRenderbuffer) NS_IMPL_CYCLE_COLLECTING_ADDREF(WebGLRenderbuffer) NS_IMPL_CYCLE_COLLECTING_RELEASE(WebGLRenderbuffer) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebGLRenderbuffer) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_INTERFACE_MAP_ENTRY(nsISupports)
new file mode 100644 --- /dev/null +++ b/content/canvas/src/WebGLRenderbuffer.h @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; 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/. */ + +#ifndef WEBGLRENDERBUFFER_H_ +#define WEBGLRENDERBUFFER_H_ + +#include "WebGLObjectModel.h" + +#include "nsWrapperCache.h" + +#include "mozilla/LinkedList.h" + +namespace mozilla { + +class WebGLRenderbuffer MOZ_FINAL + : public nsISupports + , public WebGLRefCountedObject<WebGLRenderbuffer> + , public LinkedListElement<WebGLRenderbuffer> + , public WebGLRectangleObject + , public WebGLContextBoundObject + , public nsWrapperCache +{ +public: + WebGLRenderbuffer(WebGLContext *context); + + ~WebGLRenderbuffer() { + DeleteOnce(); + } + + void Delete(); + + bool HasEverBeenBound() { return mHasEverBeenBound; } + void SetHasEverBeenBound(bool x) { mHasEverBeenBound = x; } + WebGLuint GLName() const { return mGLName; } + + bool Initialized() const { return mInitialized; } + void SetInitialized(bool aInitialized) { mInitialized = aInitialized; } + + WebGLenum InternalFormat() const { return mInternalFormat; } + void SetInternalFormat(WebGLenum aInternalFormat) { mInternalFormat = aInternalFormat; } + + WebGLenum InternalFormatForGL() const { return mInternalFormatForGL; } + void SetInternalFormatForGL(WebGLenum aInternalFormatForGL) { mInternalFormatForGL = aInternalFormatForGL; } + + int64_t MemoryUsage() const; + + WebGLContext *GetParentObject() const { + return Context(); + } + + virtual JSObject* WrapObject(JSContext *cx, JSObject *scope, bool *triedToWrap); + + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WebGLRenderbuffer) + +protected: + + WebGLuint mGLName; + WebGLenum mInternalFormat; + WebGLenum mInternalFormatForGL; + bool mHasEverBeenBound; + bool mInitialized; + + friend class WebGLFramebuffer; +}; +} // namespace mozilla + +#endif