зеркало из https://github.com/mozilla/gecko-dev.git
Bug 816168 - Split out WebGLRenderbuffer into separate files - r=bjacob
This commit is contained in:
Родитель
6ed2dcdd5a
Коммит
f5c8d6a9a8
|
@ -9,6 +9,7 @@
|
|||
#include "WebGLElementArrayCache.h"
|
||||
#include "WebGLObjectModel.h"
|
||||
#include "WebGLBuffer.h"
|
||||
#include "WebGLRenderbuffer.h"
|
||||
#include "WebGLVertexAttribData.h"
|
||||
#include "WebGLShaderPrecisionFormat.h"
|
||||
#include <stdarg.h>
|
||||
|
@ -74,9 +75,7 @@ class WebGLProgram;
|
|||
class WebGLShader;
|
||||
class WebGLFramebuffer;
|
||||
class WebGLUniformLocation;
|
||||
class WebGLRenderbuffer;
|
||||
class WebGLMemoryPressureObserver;
|
||||
class WebGLRectangleObject;
|
||||
class WebGLContextBoundObject;
|
||||
class WebGLActiveInfo;
|
||||
class WebGLExtensionBase;
|
||||
|
@ -151,47 +150,6 @@ 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();
|
||||
|
@ -2142,99 +2100,6 @@ protected:
|
|||
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
|
||||
{
|
||||
|
|
|
@ -283,6 +283,47 @@ protected:
|
|||
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>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* 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;
|
||||
|
@ -13,6 +14,56 @@ 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)
|
||||
|
|
|
@ -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
|
Загрузка…
Ссылка в новой задаче