2012-03-16 02:50:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2009-09-02 17:47:49 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
|
2009-09-17 23:01:12 -07:00
|
|
|
* Mark Steele <mwsteele@gmail.com>
|
2009-09-02 17:47:49 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef WEBGLCONTEXT_H_
|
|
|
|
#define WEBGLCONTEXT_H_
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2010-06-10 10:45:00 -07:00
|
|
|
#include <vector>
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
|
2010-11-16 20:33:04 -08:00
|
|
|
#include "nsIDOMWebGLRenderingContext.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
2010-05-17 21:04:22 -07:00
|
|
|
#include "nsHTMLCanvasElement.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsIDOMHTMLElement.h"
|
2011-07-07 17:01:12 -07:00
|
|
|
#include "nsIMemoryReporter.h"
|
2012-02-19 19:58:08 -08:00
|
|
|
#include "nsIJSNativeInitializer.h"
|
2011-12-02 23:52:35 -08:00
|
|
|
#include "nsContentUtils.h"
|
2012-03-26 11:59:04 -07:00
|
|
|
#include "nsWrapperCache.h"
|
2012-04-21 13:48:22 -07:00
|
|
|
#include "nsIObserver.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
#include "GLContextProvider.h"
|
2010-05-17 21:04:22 -07:00
|
|
|
#include "Layers.h"
|
2010-01-22 18:29:49 -08:00
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
#include "CheckedInt.h"
|
2012-03-02 12:42:49 -08:00
|
|
|
#include "nsDataHashtable.h"
|
2010-07-03 15:32:19 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
#include "mozilla/dom/ImageData.h"
|
|
|
|
|
2012-02-29 12:49:55 -08:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "ForceDiscreteGPUHelperCGL.h"
|
|
|
|
#endif
|
|
|
|
|
2012-04-16 12:56:12 -07:00
|
|
|
#include "angle/ShaderLang.h"
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
|
|
|
#include "mozilla/dom/Nullable.h"
|
2012-05-05 18:15:11 -07:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2011-10-13 05:09:22 -07:00
|
|
|
/*
|
|
|
|
* Minimum value constants defined in 6.2 State Tables of OpenGL ES - 2.0.25
|
|
|
|
* https://bugzilla.mozilla.org/show_bug.cgi?id=686732
|
|
|
|
*
|
|
|
|
* Exceptions: some of the following values are set to higher values than in the spec because
|
|
|
|
* the values in the spec are ridiculously low. They are explicitly marked below
|
|
|
|
*/
|
|
|
|
#define MINVALUE_GL_MAX_TEXTURE_SIZE 1024 // Different from the spec, which sets it to 64 on page 162
|
|
|
|
#define MINVALUE_GL_MAX_CUBE_MAP_TEXTURE_SIZE 512 // Different from the spec, which sets it to 16 on page 162
|
|
|
|
#define MINVALUE_GL_MAX_VERTEX_ATTRIBS 8 // Page 164
|
|
|
|
#define MINVALUE_GL_MAX_FRAGMENT_UNIFORM_VECTORS 16 // Page 164
|
|
|
|
#define MINVALUE_GL_MAX_VERTEX_UNIFORM_VECTORS 128 // Page 164
|
|
|
|
#define MINVALUE_GL_MAX_VARYING_VECTORS 8 // Page 164
|
|
|
|
#define MINVALUE_GL_MAX_TEXTURE_IMAGE_UNITS 8 // Page 164
|
|
|
|
#define MINVALUE_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0 // Page 164
|
|
|
|
#define MINVALUE_GL_MAX_RENDERBUFFER_SIZE 1024 // Different from the spec, which sets it to 1 on page 164
|
|
|
|
#define MINVALUE_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 8 // Page 164
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
class nsIDocShell;
|
2010-11-16 20:33:03 -08:00
|
|
|
class nsIPropertyBag;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class WebGLTexture;
|
|
|
|
class WebGLBuffer;
|
|
|
|
class WebGLProgram;
|
|
|
|
class WebGLShader;
|
|
|
|
class WebGLFramebuffer;
|
|
|
|
class WebGLRenderbuffer;
|
2010-06-01 23:09:19 -07:00
|
|
|
class WebGLUniformLocation;
|
2011-09-30 21:45:50 -07:00
|
|
|
class WebGLExtension;
|
2012-04-21 13:48:22 -07:00
|
|
|
class WebGLContext;
|
2011-12-30 23:15:59 -08:00
|
|
|
struct WebGLVertexAttribData;
|
2012-04-21 13:48:22 -07:00
|
|
|
class WebGLMemoryPressureObserver;
|
2012-01-24 13:12:31 -08:00
|
|
|
class WebGLRectangleObject;
|
2010-06-10 10:45:00 -07:00
|
|
|
class WebGLContextBoundObject;
|
2012-05-04 09:38:44 -07:00
|
|
|
class WebGLActiveInfo;
|
|
|
|
class WebGLShaderPrecisionFormat;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
enum FakeBlackStatus { DoNotNeedFakeBlack, DoNeedFakeBlack, DontKnowIfNeedFakeBlack };
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
struct VertexAttrib0Status {
|
|
|
|
enum { Default, EmulatedUninitializedArray, EmulatedInitializedArray };
|
|
|
|
};
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
struct BackbufferClearingStatus {
|
|
|
|
enum { NotClearedSinceLastPresented, ClearedToDefaultValues, HasBeenDrawnTo };
|
|
|
|
};
|
|
|
|
|
2012-05-07 11:04:10 -07:00
|
|
|
struct WebGLTexelFormat {
|
|
|
|
enum { Generic, Auto, RGBA8, RGB8, RGBX8, BGRA8, BGR8, BGRX8, RGBA5551, RGBA4444, RGB565, R8, RA8, A8,
|
|
|
|
RGBA32F, RGB32F, A32F, R32F, RA32F };
|
2010-10-15 14:50:15 -07:00
|
|
|
};
|
|
|
|
|
2012-05-07 11:04:10 -07:00
|
|
|
struct WebGLTexelPremultiplicationOp {
|
|
|
|
enum { Generic, None, Premultiply, Unmultiply };
|
|
|
|
};
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2012-05-07 11:04:10 -07:00
|
|
|
int GetWebGLTexelFormat(GLenum format, GLenum type);
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2012-04-03 16:42:06 -07:00
|
|
|
// Zero is not an integer power of two.
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool is_pot_assuming_nonnegative(WebGLsizei x)
|
2010-08-23 14:03:53 -07:00
|
|
|
{
|
2012-04-03 16:42:06 -07:00
|
|
|
return x && (x & (x-1)) == 0;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
/* Each WebGL object class WebGLFoo wants to:
|
|
|
|
* - inherit WebGLRefCountedObject<WebGLFoo>
|
|
|
|
* - implement a Delete() method
|
|
|
|
* - have its destructor call DeleteOnce()
|
|
|
|
*
|
|
|
|
* This base class provides two features to WebGL object types:
|
|
|
|
* 1. support for OpenGL object reference counting
|
|
|
|
* 2. support for OpenGL deletion statuses
|
|
|
|
*
|
|
|
|
***** 1. OpenGL object reference counting *****
|
|
|
|
*
|
|
|
|
* WebGL objects such as WebGLTexture's really have two different refcounts:
|
|
|
|
* the XPCOM refcount, that is directly exposed to JavaScript, and the OpenGL
|
|
|
|
* refcount.
|
|
|
|
*
|
|
|
|
* For example, when in JavaScript one does: var newname = existingTexture;
|
|
|
|
* that increments the XPCOM refcount, but doesn't affect the OpenGL refcount.
|
|
|
|
* When one attaches the texture to a framebuffer object, that does increment
|
|
|
|
* its OpenGL refcount (and also its XPCOM refcount, to prevent the regular
|
|
|
|
* XPCOM refcounting mechanism from destroying objects prematurely).
|
|
|
|
*
|
|
|
|
* The actual OpenGL refcount is opaque to us (it's internal to the OpenGL
|
|
|
|
* implementation) but is affects the WebGL semantics that we have to implement:
|
|
|
|
* for example, a WebGLTexture that is attached to a WebGLFramebuffer must not
|
|
|
|
* be actually deleted, even if deleteTexture has been called on it, and even
|
|
|
|
* if JavaScript doesn't have references to it anymore. We can't just rely on
|
|
|
|
* OpenGL to keep alive the underlying OpenGL texture for us, for a variety of
|
|
|
|
* reasons, most importantly: we'd need to know when OpenGL objects are actually
|
|
|
|
* deleted, and OpenGL doesn't notify us about that, so we would have to query
|
|
|
|
* status very often with glIsXxx calls which isn't practical.
|
|
|
|
*
|
|
|
|
* This means that we have to keep track of the OpenGL refcount ourselves,
|
|
|
|
* in addition to the XPCOM refcount.
|
|
|
|
*
|
|
|
|
* This class implements such a refcount, see the mWebGLRefCnt
|
|
|
|
* member. In order to avoid name clashes (with regular XPCOM refcounting)
|
|
|
|
* in the derived class, we prefix members with 'WebGL', whence the names
|
|
|
|
* WebGLAddRef, WebGLRelease, etc.
|
|
|
|
*
|
|
|
|
* In practice, WebGLAddRef and WebGLRelease are only called from the
|
|
|
|
* WebGLRefPtr class.
|
|
|
|
*
|
|
|
|
***** 2. OpenGL deletion statuses *****
|
|
|
|
*
|
|
|
|
* In OpenGL, an object can go through 3 different deletion statuses during its
|
|
|
|
* lifetime, which correspond to the 3 enum values for DeletionStatus in this class:
|
|
|
|
* - the Default status, which it has from its creation to when the
|
|
|
|
* suitable glDeleteXxx function is called on it;
|
|
|
|
* - the DeleteRequested status, which is has from when the suitable glDeleteXxx
|
|
|
|
* function is called on it to when it is no longer referenced by other OpenGL
|
|
|
|
* objects. For example, a texture that is attached to a non-current FBO
|
|
|
|
* will enter that status when glDeleteTexture is called on it. For objects
|
|
|
|
* with that status, GL_DELETE_STATUS queries return true, but glIsXxx
|
|
|
|
* functions still return true.
|
|
|
|
* - the Deleted status, which is the status of objects on which the
|
|
|
|
* suitable glDeleteXxx function has been called, and that are not referenced
|
|
|
|
* by other OpenGL objects.
|
|
|
|
*
|
|
|
|
* This state is stored in the mDeletionStatus member of this class.
|
|
|
|
*
|
|
|
|
* When the GL refcount hits zero, if the status is DeleteRequested then we call
|
|
|
|
* the Delete() method on the derived class and the status becomes Deleted. This is
|
|
|
|
* what the MaybeDelete() function does.
|
|
|
|
*
|
|
|
|
* The DeleteOnce() function implemented here is a helper to ensure that we don't
|
|
|
|
* call Delete() twice on the same object. Since the derived class' destructor
|
|
|
|
* needs to call DeleteOnce() which calls Delete(), we can't allow either to be
|
|
|
|
* virtual. Strictly speaking, we could let them be virtual if the derived class
|
|
|
|
* were final, but that would be impossible to enforce and would lead to strange
|
|
|
|
* bugs if it were subclassed.
|
|
|
|
*
|
|
|
|
* This WebGLRefCountedObject class takes the Derived type
|
|
|
|
* as template parameter, as a means to allow DeleteOnce to call Delete()
|
|
|
|
* on the Derived class, without either method being virtual. This is a common
|
|
|
|
* C++ pattern known as the "curiously recursive template pattern (CRTP)".
|
|
|
|
*/
|
|
|
|
template<typename Derived>
|
|
|
|
class WebGLRefCountedObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum DeletionStatus { Default, DeleteRequested, Deleted };
|
|
|
|
|
|
|
|
WebGLRefCountedObject()
|
|
|
|
: mDeletionStatus(Default)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~WebGLRefCountedObject() {
|
|
|
|
NS_ABORT_IF_FALSE(mWebGLRefCnt == 0, "destroying WebGL object still referenced by other WebGL objects");
|
|
|
|
NS_ABORT_IF_FALSE(mDeletionStatus == Deleted, "Derived class destructor must call DeleteOnce()");
|
|
|
|
}
|
|
|
|
|
|
|
|
// called by WebGLRefPtr
|
|
|
|
void WebGLAddRef() {
|
|
|
|
++mWebGLRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
// called by WebGLRefPtr
|
|
|
|
void WebGLRelease() {
|
|
|
|
NS_ABORT_IF_FALSE(mWebGLRefCnt > 0, "releasing WebGL object with WebGL refcnt already zero");
|
|
|
|
--mWebGLRefCnt;
|
|
|
|
MaybeDelete();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is the function that WebGL.deleteXxx() functions want to call
|
|
|
|
void RequestDelete() {
|
|
|
|
if (mDeletionStatus == Default)
|
|
|
|
mDeletionStatus = DeleteRequested;
|
|
|
|
MaybeDelete();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDeleted() const {
|
|
|
|
return mDeletionStatus == Deleted;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDeleteRequested() const {
|
|
|
|
return mDeletionStatus != Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteOnce() {
|
|
|
|
if (mDeletionStatus != Deleted) {
|
|
|
|
static_cast<Derived*>(this)->Delete();
|
|
|
|
mDeletionStatus = Deleted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void MaybeDelete() {
|
|
|
|
if (mWebGLRefCnt == 0 &&
|
|
|
|
mDeletionStatus == DeleteRequested)
|
|
|
|
{
|
|
|
|
DeleteOnce();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsAutoRefCnt mWebGLRefCnt;
|
|
|
|
DeletionStatus mDeletionStatus;
|
|
|
|
};
|
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
/* This WebGLRefPtr class is meant to be used for references between WebGL objects.
|
|
|
|
* For example, a WebGLProgram holds WebGLRefPtr's to the WebGLShader's attached
|
|
|
|
* to it.
|
|
|
|
*
|
|
|
|
* Why the need for a separate refptr class? The only special thing that WebGLRefPtr
|
|
|
|
* does is that it increments and decrements the WebGL refcount of
|
|
|
|
* WebGLRefCountedObject's, in addition to incrementing and decrementing the
|
|
|
|
* usual XPCOM refcount.
|
|
|
|
*
|
|
|
|
* This means that by using a WebGLRefPtr instead of a nsRefPtr, you ensure that
|
|
|
|
* the WebGL refcount is incremented, which means that the object will be kept
|
|
|
|
* alive by this reference even if the matching webgl.deleteXxx() function is
|
|
|
|
* called on it.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
class WebGLRefPtr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebGLRefPtr()
|
|
|
|
: mRawPtr(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
WebGLRefPtr(const WebGLRefPtr<T>& aSmartPtr)
|
|
|
|
: mRawPtr(aSmartPtr.mRawPtr)
|
|
|
|
{
|
|
|
|
AddRefOnPtr(mRawPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLRefPtr(T *aRawPtr)
|
|
|
|
: mRawPtr(aRawPtr)
|
|
|
|
{
|
|
|
|
AddRefOnPtr(mRawPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
~WebGLRefPtr() {
|
|
|
|
ReleasePtr(mRawPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLRefPtr<T>&
|
|
|
|
operator=(const WebGLRefPtr<T>& rhs)
|
|
|
|
{
|
|
|
|
assign_with_AddRef(rhs.mRawPtr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLRefPtr<T>&
|
|
|
|
operator=(T* rhs)
|
|
|
|
{
|
|
|
|
assign_with_AddRef(rhs);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* get() const {
|
|
|
|
return static_cast<T*>(mRawPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
operator T*() const {
|
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
|
|
|
T* operator->() const {
|
|
|
|
NS_ABORT_IF_FALSE(mRawPtr != 0, "You can't dereference a NULL WebGLRefPtr with operator->()!");
|
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
|
|
|
T& operator*() const {
|
|
|
|
NS_ABORT_IF_FALSE(mRawPtr != 0, "You can't dereference a NULL WebGLRefPtr with operator*()!");
|
|
|
|
return *get();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
static void AddRefOnPtr(T* rawPtr) {
|
|
|
|
if (rawPtr) {
|
|
|
|
rawPtr->WebGLAddRef();
|
|
|
|
rawPtr->AddRef();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReleasePtr(T* rawPtr) {
|
|
|
|
if (rawPtr) {
|
|
|
|
rawPtr->WebGLRelease(); // must be done first before Release(), as Release() might actually destroy the object
|
|
|
|
rawPtr->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void assign_with_AddRef(T* rawPtr) {
|
|
|
|
AddRefOnPtr(rawPtr);
|
|
|
|
assign_assuming_AddRef(rawPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void assign_assuming_AddRef(T* newPtr) {
|
|
|
|
T* oldPtr = mRawPtr;
|
|
|
|
mRawPtr = newPtr;
|
|
|
|
ReleasePtr(oldPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
T *mRawPtr;
|
|
|
|
};
|
|
|
|
|
2011-12-04 11:15:43 -08:00
|
|
|
typedef PRUint64 WebGLMonotonicHandle;
|
|
|
|
|
|
|
|
/* WebGLFastArray offers a fast array for the use case where all what one needs is to append
|
|
|
|
* and remove elements. Removal is fast because the array is always kept sorted with respect
|
|
|
|
* to "monotonic handles". Appending an element returns such a "monotonic handle" which the
|
|
|
|
* user needs to keep for future use for when it will want to remove the element.
|
|
|
|
*/
|
|
|
|
template<typename ElementType>
|
|
|
|
class WebGLFastArray
|
|
|
|
{
|
|
|
|
struct Entry {
|
|
|
|
ElementType mElement;
|
|
|
|
WebGLMonotonicHandle mMonotonicHandle;
|
|
|
|
|
|
|
|
Entry(ElementType elem, WebGLMonotonicHandle monotonicHandle)
|
|
|
|
: mElement(elem), mMonotonicHandle(monotonicHandle)
|
|
|
|
{}
|
|
|
|
|
|
|
|
struct Comparator {
|
|
|
|
bool Equals(const Entry& a, const Entry& b) const {
|
|
|
|
return a.mMonotonicHandle == b.mMonotonicHandle;
|
|
|
|
}
|
|
|
|
bool LessThan(const Entry& a, const Entry& b) const {
|
|
|
|
return a.mMonotonicHandle < b.mMonotonicHandle;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
WebGLFastArray()
|
|
|
|
: mCurrentMonotonicHandle(0) // CheckedInt already does it, this is just defensive coding
|
|
|
|
{}
|
|
|
|
|
|
|
|
ElementType operator[](size_t index) const {
|
|
|
|
return mArray[index].mElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Length() const {
|
|
|
|
return mArray.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
ElementType Last() const {
|
|
|
|
return operator[](Length() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLMonotonicHandle AppendElement(ElementType elem)
|
|
|
|
{
|
|
|
|
WebGLMonotonicHandle monotonicHandle = NextMonotonicHandle();
|
|
|
|
mArray.AppendElement(Entry(elem, monotonicHandle));
|
|
|
|
return monotonicHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveElement(WebGLMonotonicHandle monotonicHandle)
|
|
|
|
{
|
|
|
|
mArray.RemoveElementSorted(Entry(ElementType(), monotonicHandle),
|
|
|
|
typename Entry::Comparator());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
WebGLMonotonicHandle NextMonotonicHandle() {
|
|
|
|
++mCurrentMonotonicHandle;
|
|
|
|
if (!mCurrentMonotonicHandle.valid())
|
|
|
|
NS_RUNTIMEABORT("ran out of monotonic ids!");
|
|
|
|
return mCurrentMonotonicHandle.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<Entry> mArray;
|
|
|
|
CheckedInt<WebGLMonotonicHandle> mCurrentMonotonicHandle;
|
|
|
|
};
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
// 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;
|
|
|
|
};
|
|
|
|
|
2010-11-16 20:33:03 -08:00
|
|
|
struct WebGLContextOptions {
|
|
|
|
// these are defaults
|
|
|
|
WebGLContextOptions()
|
|
|
|
: alpha(true), depth(true), stencil(false),
|
2011-10-19 12:09:57 -07:00
|
|
|
premultipliedAlpha(true), antialias(true),
|
2011-05-20 12:53:53 -07:00
|
|
|
preserveDrawingBuffer(false)
|
2010-11-16 20:33:03 -08:00
|
|
|
{ }
|
|
|
|
|
|
|
|
bool operator==(const WebGLContextOptions& other) const {
|
|
|
|
return
|
|
|
|
alpha == other.alpha &&
|
|
|
|
depth == other.depth &&
|
|
|
|
stencil == other.stencil &&
|
|
|
|
premultipliedAlpha == other.premultipliedAlpha &&
|
2011-05-20 12:53:53 -07:00
|
|
|
antialias == other.antialias &&
|
|
|
|
preserveDrawingBuffer == other.preserveDrawingBuffer;
|
2010-11-16 20:33:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const WebGLContextOptions& other) const {
|
2011-05-20 12:53:53 -07:00
|
|
|
return !operator==(other);
|
2010-11-16 20:33:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool alpha;
|
|
|
|
bool depth;
|
|
|
|
bool stencil;
|
|
|
|
bool premultipliedAlpha;
|
2011-05-20 12:53:53 -07:00
|
|
|
bool antialias;
|
|
|
|
bool preserveDrawingBuffer;
|
2010-11-16 20:33:03 -08:00
|
|
|
};
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
class WebGLContext :
|
2010-11-16 20:33:04 -08:00
|
|
|
public nsIDOMWebGLRenderingContext,
|
2009-09-02 17:47:49 -07:00
|
|
|
public nsICanvasRenderingContextInternal,
|
2011-10-26 13:00:44 -07:00
|
|
|
public nsSupportsWeakReference,
|
2012-01-24 13:12:31 -08:00
|
|
|
public nsITimerCallback,
|
2012-05-04 09:36:40 -07:00
|
|
|
public WebGLRectangleObject,
|
|
|
|
public nsWrapperCache
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-02-19 19:58:08 -08:00
|
|
|
friend class WebGLMemoryMultiReporterWrapper;
|
2011-10-26 13:00:44 -07:00
|
|
|
friend class WebGLExtensionLoseContext;
|
2011-10-31 14:14:12 -07:00
|
|
|
friend class WebGLContextUserData;
|
2012-04-21 13:48:22 -07:00
|
|
|
friend class WebGLMemoryPressureObserver;
|
2011-07-07 17:01:12 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
public:
|
|
|
|
WebGLContext();
|
|
|
|
virtual ~WebGLContext();
|
|
|
|
|
2010-06-15 14:38:05 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
|
2012-05-04 09:36:40 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(WebGLContext,
|
|
|
|
nsIDOMWebGLRenderingContext)
|
|
|
|
|
|
|
|
nsINode* GetParentObject() {
|
|
|
|
return HTMLCanvasElement();
|
|
|
|
}
|
2010-06-15 14:38:05 -07:00
|
|
|
|
2010-11-16 20:33:04 -08:00
|
|
|
NS_DECL_NSIDOMWEBGLRENDERINGCONTEXT
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-10-26 13:00:44 -07:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
// nsICanvasRenderingContextInternal
|
2010-05-17 21:04:22 -07:00
|
|
|
NS_IMETHOD SetCanvasElement(nsHTMLCanvasElement* aParentCanvas);
|
2012-05-04 09:38:44 -07:00
|
|
|
nsHTMLCanvasElement* HTMLCanvasElement() const {
|
2012-03-26 11:59:04 -07:00
|
|
|
return static_cast<nsHTMLCanvasElement*>(mCanvasElement.get());
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHOD SetDimensions(PRInt32 width, PRInt32 height);
|
|
|
|
NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, PRInt32 width, PRInt32 height)
|
|
|
|
{ return NS_ERROR_NOT_IMPLEMENTED; }
|
2010-08-19 08:22:46 -07:00
|
|
|
NS_IMETHOD Reset()
|
|
|
|
{ /* (InitializeWithSurface) */ return NS_ERROR_NOT_IMPLEMENTED; }
|
2012-03-23 15:10:50 -07:00
|
|
|
NS_IMETHOD Render(gfxContext *ctx,
|
|
|
|
gfxPattern::GraphicsFilter f,
|
|
|
|
PRUint32 aFlags = RenderFlagPremultAlpha);
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHOD GetInputStream(const char* aMimeType,
|
|
|
|
const PRUnichar* aEncoderOptions,
|
|
|
|
nsIInputStream **aStream);
|
|
|
|
NS_IMETHOD GetThebesSurface(gfxASurface **surface);
|
2011-06-24 10:41:18 -07:00
|
|
|
mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetSurfaceSnapshot()
|
|
|
|
{ return nsnull; }
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD SetIsOpaque(bool b) { return NS_OK; };
|
2010-11-16 20:33:03 -08:00
|
|
|
NS_IMETHOD SetContextOptions(nsIPropertyBag *aOptions);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD SetIsIPC(bool b) { return NS_ERROR_NOT_IMPLEMENTED; }
|
2009-10-29 10:58:31 -07:00
|
|
|
NS_IMETHOD Redraw(const gfxRect&) { return NS_ERROR_NOT_IMPLEMENTED; }
|
2010-03-24 03:47:18 -07:00
|
|
|
NS_IMETHOD Swap(mozilla::ipc::Shmem& aBack,
|
|
|
|
PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h)
|
|
|
|
{ return NS_ERROR_NOT_IMPLEMENTED; }
|
2010-06-04 06:58:22 -07:00
|
|
|
NS_IMETHOD Swap(PRUint32 nativeID,
|
|
|
|
PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h)
|
|
|
|
{ return NS_ERROR_NOT_IMPLEMENTED; }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-10-26 13:00:44 -07:00
|
|
|
bool LoseContext();
|
|
|
|
bool RestoreContext();
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void SynthesizeGLError(WebGLenum err);
|
|
|
|
void SynthesizeGLError(WebGLenum err, const char *fmt, ...);
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
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, PRUint32 enumvalue) {
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnum("%s: invalid enum value 0x%x", info, enumvalue);
|
2010-06-30 08:49:59 -07:00
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
void ErrorOutOfMemory(const char *fmt = 0, ...);
|
2012-01-24 13:12:31 -08:00
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
const char *ErrorName(GLenum error);
|
2012-04-03 16:42:06 -07:00
|
|
|
bool IsTextureFormatCompressed(GLenum format);
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void DummyFramebufferOperation(const char *info);
|
2012-01-24 13:12:31 -08:00
|
|
|
|
2010-08-23 14:03:35 -07:00
|
|
|
WebGLTexture *activeBoundTextureForTarget(WebGLenum target) {
|
|
|
|
return target == LOCAL_GL_TEXTURE_2D ? mBound2DTextures[mActiveTexture]
|
|
|
|
: mBoundCubeMapTextures[mActiveTexture];
|
|
|
|
}
|
|
|
|
|
2011-03-27 16:59:47 -07:00
|
|
|
already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
CanvasLayer *aOldLayer,
|
2010-07-15 14:07:46 -07:00
|
|
|
LayerManager *aManager);
|
2011-10-17 07:59:28 -07:00
|
|
|
void MarkContextClean() { mInvalidated = false; }
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
// a number that increments every time we have an event that causes
|
|
|
|
// all context resources to be lost.
|
2010-07-03 15:32:19 -07:00
|
|
|
PRUint32 Generation() { return mGeneration.value(); }
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
const WebGLRectangleObject *FramebufferRectangleObject() const;
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
// this is similar to GLContext::ClearSafely, but is more comprehensive
|
|
|
|
// (takes care of scissor, stencil write mask, dithering, viewport...)
|
|
|
|
// WebGL has more complex needs than GLContext as content controls GL state.
|
|
|
|
void ForceClearFramebufferWithDefaultValues(PRUint32 mask, const nsIntRect& viewportRect);
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
// if the preserveDrawingBuffer context option is false, we need to clear the back buffer
|
|
|
|
// after it's been presented to the compositor. This function does that if needed.
|
|
|
|
// See section 2.2 in the WebGL spec.
|
|
|
|
void EnsureBackbufferClearedAsNeeded();
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
// checks for GL errors, clears any pending GL error, stores the current GL error in currentGLError,
|
|
|
|
// 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(¤tGLError);
|
|
|
|
}
|
2011-10-13 05:09:22 -07:00
|
|
|
|
|
|
|
bool MinCapabilityMode() const {
|
|
|
|
return mMinCapability;
|
|
|
|
}
|
2011-07-07 17:01:16 -07:00
|
|
|
|
2012-04-21 13:48:22 -07:00
|
|
|
void SetupContextLossTimer() {
|
2011-11-18 19:57:29 -08:00
|
|
|
// 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.
|
2012-04-21 13:48:22 -07:00
|
|
|
if (mContextLossTimerRunning) {
|
|
|
|
mDrawSinceContextLossTimerSet = true;
|
2011-11-18 19:57:29 -08:00
|
|
|
return;
|
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
|
|
|
mContextRestorer->InitWithCallback(static_cast<nsITimerCallback*>(this),
|
|
|
|
PR_MillisecondsToInterval(1000),
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2012-04-21 13:48:22 -07:00
|
|
|
mContextLossTimerRunning = true;
|
|
|
|
mDrawSinceContextLossTimerSet = false;
|
2011-11-18 19:57:29 -08:00
|
|
|
}
|
|
|
|
|
2012-04-21 13:48:22 -07:00
|
|
|
void TerminateContextLossTimer() {
|
|
|
|
if (mContextLossTimerRunning) {
|
2011-11-18 19:57:29 -08:00
|
|
|
mContextRestorer->Cancel();
|
2012-04-21 13:48:22 -07:00
|
|
|
mContextLossTimerRunning = false;
|
2011-11-18 19:57:29 -08:00
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
// WebIDL WebGLRenderingContext API
|
|
|
|
nsHTMLCanvasElement* GetCanvas() const {
|
|
|
|
return HTMLCanvasElement();
|
|
|
|
}
|
|
|
|
WebGLsizei GetDrawingBufferWidth() const {
|
|
|
|
if (!IsContextStable())
|
|
|
|
return 0;
|
|
|
|
return mWidth;
|
|
|
|
}
|
|
|
|
WebGLsizei GetDrawingBufferHeight() const {
|
|
|
|
if (!IsContextStable())
|
|
|
|
return 0;
|
|
|
|
return mHeight;
|
|
|
|
}
|
|
|
|
|
2012-05-05 18:15:11 -07:00
|
|
|
JSObject *GetContextAttributes(ErrorResult &rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
bool IsContextLost() const { return !IsContextStable(); }
|
|
|
|
void GetSupportedExtensions(dom::Nullable< nsTArray<nsString> > &retval);
|
|
|
|
nsIWebGLExtension* GetExtension(const nsAString& aName);
|
|
|
|
void ActiveTexture(WebGLenum texture);
|
|
|
|
void AttachShader(WebGLProgram* program, WebGLShader* shader);
|
|
|
|
void BindAttribLocation(WebGLProgram* program, WebGLuint location,
|
|
|
|
const nsAString& name);
|
|
|
|
void BindBuffer(WebGLenum target, WebGLBuffer* buf);
|
|
|
|
void BindFramebuffer(WebGLenum target, WebGLFramebuffer* wfb);
|
|
|
|
void BindRenderbuffer(WebGLenum target, WebGLRenderbuffer* wrb);
|
|
|
|
void BindTexture(WebGLenum target, WebGLTexture *tex);
|
|
|
|
void BlendColor(WebGLclampf r, WebGLclampf g, WebGLclampf b, WebGLclampf a) {
|
|
|
|
if (!IsContextStable())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBlendColor(r, g, b, a);
|
|
|
|
}
|
|
|
|
void BlendEquation(WebGLenum mode);
|
|
|
|
void BlendEquationSeparate(WebGLenum modeRGB, WebGLenum modeAlpha);
|
|
|
|
void BlendFunc(WebGLenum sfactor, WebGLenum dfactor);
|
|
|
|
void BlendFuncSeparate(WebGLenum srcRGB, WebGLenum dstRGB,
|
|
|
|
WebGLenum srcAlpha, WebGLenum dstAlpha);
|
|
|
|
void BufferData(WebGLenum target, WebGLsizeiptr size, WebGLenum usage);
|
|
|
|
void BufferData(WebGLenum target, dom::ArrayBufferView &data,
|
|
|
|
WebGLenum usage);
|
|
|
|
void BufferData(WebGLenum target, dom::ArrayBuffer *data, WebGLenum usage);
|
|
|
|
void BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
|
|
|
|
dom::ArrayBufferView &data);
|
|
|
|
void BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
|
|
|
|
dom::ArrayBuffer *data);
|
|
|
|
WebGLenum CheckFramebufferStatus(WebGLenum target);
|
|
|
|
void Clear(WebGLbitfield mask);
|
|
|
|
void ClearColor(WebGLclampf r, WebGLclampf g, WebGLclampf b, WebGLclampf a);
|
|
|
|
void ClearDepth(WebGLclampf v);
|
|
|
|
void ClearStencil(WebGLint v);
|
|
|
|
void ColorMask(WebGLboolean r, WebGLboolean g, WebGLboolean b, WebGLboolean a);
|
|
|
|
void CompileShader(WebGLShader *shader);
|
|
|
|
void CompressedTexImage2D(WebGLenum target, WebGLint level,
|
|
|
|
WebGLenum internalformat, WebGLsizei width,
|
|
|
|
WebGLsizei height, WebGLint border,
|
|
|
|
dom::ArrayBufferView& view);
|
|
|
|
void CompressedTexSubImage2D(WebGLenum target, WebGLint level,
|
|
|
|
WebGLint xoffset, WebGLint yoffset,
|
|
|
|
WebGLsizei width, WebGLsizei height,
|
|
|
|
WebGLenum format, dom::ArrayBufferView& view);
|
|
|
|
void CopyTexImage2D(WebGLenum target, WebGLint level,
|
|
|
|
WebGLenum internalformat, WebGLint x, WebGLint y,
|
|
|
|
WebGLsizei width, WebGLsizei height, WebGLint border);
|
|
|
|
void CopyTexSubImage2D(WebGLenum target, WebGLint level, WebGLint xoffset,
|
|
|
|
WebGLint yoffset, WebGLint x, WebGLint y,
|
|
|
|
WebGLsizei width, WebGLsizei height);
|
|
|
|
already_AddRefed<WebGLBuffer> CreateBuffer();
|
|
|
|
already_AddRefed<WebGLFramebuffer> CreateFramebuffer();
|
|
|
|
already_AddRefed<WebGLProgram> CreateProgram();
|
|
|
|
already_AddRefed<WebGLRenderbuffer> CreateRenderbuffer();
|
|
|
|
already_AddRefed<WebGLTexture> CreateTexture();
|
|
|
|
already_AddRefed<WebGLShader> CreateShader(WebGLenum type);
|
|
|
|
void CullFace(WebGLenum face);
|
|
|
|
void DeleteBuffer(WebGLBuffer *buf);
|
|
|
|
void DeleteFramebuffer(WebGLFramebuffer *fbuf);
|
|
|
|
void DeleteProgram(WebGLProgram *prog);
|
|
|
|
void DeleteRenderbuffer(WebGLRenderbuffer *rbuf);
|
|
|
|
void DeleteShader(WebGLShader *shader);
|
|
|
|
void DeleteTexture(WebGLTexture *tex);
|
|
|
|
void DepthFunc(WebGLenum func);
|
|
|
|
void DepthMask(WebGLboolean b);
|
|
|
|
void DepthRange(WebGLclampf zNear, WebGLclampf zFar);
|
|
|
|
void DetachShader(WebGLProgram *program, WebGLShader *shader);
|
|
|
|
void Disable(WebGLenum cap);
|
|
|
|
void DisableVertexAttribArray(WebGLuint index);
|
|
|
|
void DrawArrays(GLenum mode, WebGLint first, WebGLsizei count);
|
|
|
|
void DrawElements(WebGLenum mode, WebGLsizei count, WebGLenum type,
|
|
|
|
WebGLintptr byteOffset);
|
|
|
|
void Enable(WebGLenum cap);
|
|
|
|
void EnableVertexAttribArray(WebGLuint index);
|
|
|
|
void Flush() {
|
|
|
|
if (!IsContextStable())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fFlush();
|
|
|
|
}
|
|
|
|
void Finish() {
|
|
|
|
if (!IsContextStable())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fFinish();
|
|
|
|
}
|
|
|
|
void FramebufferRenderbuffer(WebGLenum target, WebGLenum attachment,
|
|
|
|
WebGLenum rbtarget, WebGLRenderbuffer *wrb);
|
|
|
|
void FramebufferTexture2D(WebGLenum target, WebGLenum attachment,
|
|
|
|
WebGLenum textarget, WebGLTexture *tobj,
|
|
|
|
WebGLint level);
|
|
|
|
void FrontFace(WebGLenum mode);
|
|
|
|
void GenerateMipmap(WebGLenum target);
|
|
|
|
already_AddRefed<WebGLActiveInfo> GetActiveAttrib(WebGLProgram *prog,
|
|
|
|
WebGLuint index);
|
|
|
|
already_AddRefed<WebGLActiveInfo> GetActiveUniform(WebGLProgram *prog,
|
|
|
|
WebGLuint index);
|
|
|
|
void GetAttachedShaders(WebGLProgram* prog,
|
|
|
|
dom::Nullable< nsTArray<WebGLShader*> > &retval);
|
|
|
|
WebGLint GetAttribLocation(WebGLProgram* prog, const nsAString& name);
|
|
|
|
JS::Value GetBufferParameter(WebGLenum target, WebGLenum pname);
|
2012-05-05 18:15:11 -07:00
|
|
|
JS::Value GetParameter(JSContext* cx, WebGLenum pname, ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLenum GetError();
|
|
|
|
JS::Value GetFramebufferAttachmentParameter(JSContext* cx,
|
|
|
|
WebGLenum target,
|
|
|
|
WebGLenum attachment,
|
|
|
|
WebGLenum pname,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value GetProgramParameter(WebGLProgram *prog, WebGLenum pname);
|
2012-05-05 18:15:11 -07:00
|
|
|
void GetProgramInfoLog(WebGLProgram *prog, nsAString& retval, ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value GetRenderbufferParameter(WebGLenum target, WebGLenum pname);
|
|
|
|
JS::Value GetShaderParameter(WebGLShader *shader, WebGLenum pname);
|
|
|
|
already_AddRefed<WebGLShaderPrecisionFormat>
|
|
|
|
GetShaderPrecisionFormat(WebGLenum shadertype, WebGLenum precisiontype);
|
2012-05-05 18:15:11 -07:00
|
|
|
void GetShaderInfoLog(WebGLShader *shader, nsAString& retval, ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
void GetShaderSource(WebGLShader *shader, nsAString& retval);
|
|
|
|
JS::Value GetTexParameter(WebGLenum target, WebGLenum pname);
|
|
|
|
JS::Value GetUniform(JSContext* cx, WebGLProgram *prog,
|
2012-05-05 18:15:11 -07:00
|
|
|
WebGLUniformLocation *location, ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLUniformLocation>
|
|
|
|
GetUniformLocation(WebGLProgram *prog, const nsAString& name);
|
|
|
|
JS::Value GetVertexAttrib(JSContext* cx, WebGLuint index, WebGLenum pname,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLsizeiptr GetVertexAttribOffset(WebGLuint index, WebGLenum pname);
|
|
|
|
void Hint(WebGLenum target, WebGLenum mode);
|
|
|
|
bool IsBuffer(WebGLBuffer *buffer);
|
|
|
|
bool IsEnabled(WebGLenum cap);
|
|
|
|
bool IsFramebuffer(WebGLFramebuffer *fb);
|
|
|
|
bool IsProgram(WebGLProgram *prog);
|
|
|
|
bool IsRenderbuffer(WebGLRenderbuffer *rb);
|
|
|
|
bool IsShader(WebGLShader *shader);
|
|
|
|
bool IsTexture(WebGLTexture *tex);
|
|
|
|
void LineWidth(WebGLfloat width) {
|
|
|
|
if (!IsContextStable())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fLineWidth(width);
|
|
|
|
}
|
2012-05-05 18:15:11 -07:00
|
|
|
void LinkProgram(WebGLProgram *program, ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
void PixelStorei(WebGLenum pname, WebGLint param);
|
|
|
|
void PolygonOffset(WebGLfloat factor, WebGLfloat units) {
|
|
|
|
if (!IsContextStable())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fPolygonOffset(factor, units);
|
|
|
|
}
|
|
|
|
void ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height,
|
|
|
|
WebGLenum format, WebGLenum type,
|
2012-05-05 18:15:11 -07:00
|
|
|
dom::ArrayBufferView* pixels, ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
void RenderbufferStorage(WebGLenum target, WebGLenum internalformat,
|
|
|
|
WebGLsizei width, WebGLsizei height);
|
|
|
|
void SampleCoverage(WebGLclampf value, WebGLboolean invert) {
|
|
|
|
if (!IsContextStable())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fSampleCoverage(value, invert);
|
|
|
|
}
|
|
|
|
void Scissor(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height);
|
|
|
|
void ShaderSource(WebGLShader *shader, const nsAString& source);
|
|
|
|
void StencilFunc(WebGLenum func, WebGLint ref, WebGLuint mask);
|
|
|
|
void StencilFuncSeparate(WebGLenum face, WebGLenum func, WebGLint ref,
|
|
|
|
WebGLuint mask);
|
|
|
|
void StencilMask(WebGLuint mask);
|
|
|
|
void StencilMaskSeparate(WebGLenum face, WebGLuint mask);
|
|
|
|
void StencilOp(WebGLenum sfail, WebGLenum dpfail, WebGLenum dppass);
|
|
|
|
void StencilOpSeparate(WebGLenum face, WebGLenum sfail, WebGLenum dpfail,
|
|
|
|
WebGLenum dppass);
|
|
|
|
void TexImage2D(JSContext* cx, WebGLenum target, WebGLint level,
|
|
|
|
WebGLenum internalformat, WebGLsizei width,
|
|
|
|
WebGLsizei height, WebGLint border, WebGLenum format,
|
2012-05-05 18:15:11 -07:00
|
|
|
WebGLenum type, dom::ArrayBufferView *pixels,
|
|
|
|
ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
void TexImage2D(JSContext* cx, WebGLenum target, WebGLint level,
|
|
|
|
WebGLenum internalformat, WebGLenum format, WebGLenum type,
|
2012-05-05 18:15:11 -07:00
|
|
|
dom::ImageData* pixels, ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
void TexImage2D(JSContext* /* unused */, WebGLenum target, WebGLint level,
|
|
|
|
WebGLenum internalformat, WebGLenum format, WebGLenum type,
|
2012-05-05 18:15:11 -07:00
|
|
|
dom::Element* elt, ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
void TexParameterf(WebGLenum target, WebGLenum pname, WebGLfloat param) {
|
|
|
|
TexParameter_base(target, pname, nsnull, ¶m);
|
|
|
|
}
|
|
|
|
void TexParameteri(WebGLenum target, WebGLenum pname, WebGLint param) {
|
|
|
|
TexParameter_base(target, pname, ¶m, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TexSubImage2D(JSContext* cx, WebGLenum target, WebGLint level,
|
|
|
|
WebGLint xoffset, WebGLint yoffset,
|
|
|
|
WebGLsizei width, WebGLsizei height, WebGLenum format,
|
|
|
|
WebGLenum type, dom::ArrayBufferView* pixels,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
void TexSubImage2D(JSContext* cx, WebGLenum target, WebGLint level,
|
|
|
|
WebGLint xoffset, WebGLint yoffset, WebGLenum format,
|
2012-05-05 18:15:11 -07:00
|
|
|
WebGLenum type, dom::ImageData* pixels, ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
void TexSubImage2D(JSContext* /* unused */, WebGLenum target, WebGLint level,
|
|
|
|
WebGLint xoffset, WebGLint yoffset, WebGLenum format,
|
2012-05-05 18:15:11 -07:00
|
|
|
WebGLenum type, dom::Element* elt, ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void Uniform1i(WebGLUniformLocation* location, WebGLint x);
|
|
|
|
void Uniform2i(WebGLUniformLocation* location, WebGLint x, WebGLint y);
|
|
|
|
void Uniform3i(WebGLUniformLocation* location, WebGLint x, WebGLint y,
|
|
|
|
WebGLint z);
|
|
|
|
void Uniform4i(WebGLUniformLocation* location, WebGLint x, WebGLint y,
|
|
|
|
WebGLint z, WebGLint w);
|
|
|
|
|
|
|
|
void Uniform1f(WebGLUniformLocation* location, WebGLfloat x);
|
|
|
|
void Uniform2f(WebGLUniformLocation* location, WebGLfloat x, WebGLfloat y);
|
|
|
|
void Uniform3f(WebGLUniformLocation* location, WebGLfloat x, WebGLfloat y,
|
|
|
|
WebGLfloat z);
|
|
|
|
void Uniform4f(WebGLUniformLocation* location, WebGLfloat x, WebGLfloat y,
|
|
|
|
WebGLfloat z, WebGLfloat w);
|
|
|
|
|
|
|
|
void Uniform1iv(WebGLUniformLocation* location, dom::Int32Array& arr) {
|
|
|
|
Uniform1iv_base(location, arr.mLength, arr.mData);
|
|
|
|
}
|
|
|
|
void Uniform1iv(WebGLUniformLocation* location, nsTArray<WebGLint>& arr) {
|
|
|
|
Uniform1iv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform1iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
|
|
|
WebGLint* data);
|
|
|
|
|
|
|
|
void Uniform2iv(WebGLUniformLocation* location, dom::Int32Array& arr) {
|
|
|
|
Uniform2iv_base(location, arr.mLength, arr.mData);
|
|
|
|
}
|
|
|
|
void Uniform2iv(WebGLUniformLocation* location, nsTArray<WebGLint>& arr) {
|
|
|
|
Uniform2iv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform2iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
|
|
|
WebGLint* data);
|
|
|
|
|
|
|
|
void Uniform3iv(WebGLUniformLocation* location, dom::Int32Array& arr) {
|
|
|
|
Uniform3iv_base(location, arr.mLength, arr.mData);
|
|
|
|
}
|
|
|
|
void Uniform3iv(WebGLUniformLocation* location, nsTArray<WebGLint>& arr) {
|
|
|
|
Uniform3iv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform3iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
|
|
|
WebGLint* data);
|
|
|
|
|
|
|
|
void Uniform4iv(WebGLUniformLocation* location, dom::Int32Array& arr) {
|
|
|
|
Uniform4iv_base(location, arr.mLength, arr.mData);
|
|
|
|
}
|
|
|
|
void Uniform4iv(WebGLUniformLocation* location, nsTArray<WebGLint>& arr) {
|
|
|
|
Uniform4iv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform4iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
|
|
|
WebGLint* data);
|
|
|
|
|
|
|
|
void Uniform1fv(WebGLUniformLocation* location, dom::Float32Array& arr) {
|
|
|
|
Uniform1fv_base(location, arr.mLength, arr.mData);
|
|
|
|
}
|
|
|
|
void Uniform1fv(WebGLUniformLocation* location, nsTArray<WebGLfloat>& arr) {
|
|
|
|
Uniform1fv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform1fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
|
|
|
WebGLfloat* data);
|
|
|
|
|
|
|
|
void Uniform2fv(WebGLUniformLocation* location, dom::Float32Array& arr) {
|
|
|
|
Uniform2fv_base(location, arr.mLength, arr.mData);
|
|
|
|
}
|
|
|
|
void Uniform2fv(WebGLUniformLocation* location, nsTArray<WebGLfloat>& arr) {
|
|
|
|
Uniform2fv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform2fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
|
|
|
WebGLfloat* data);
|
|
|
|
|
|
|
|
void Uniform3fv(WebGLUniformLocation* location, dom::Float32Array& arr) {
|
|
|
|
Uniform3fv_base(location, arr.mLength, arr.mData);
|
|
|
|
}
|
|
|
|
void Uniform3fv(WebGLUniformLocation* location, nsTArray<WebGLfloat>& arr) {
|
|
|
|
Uniform3fv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform3fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
|
|
|
WebGLfloat* data);
|
|
|
|
|
|
|
|
void Uniform4fv(WebGLUniformLocation* location, dom::Float32Array& arr) {
|
|
|
|
Uniform4fv_base(location, arr.mLength, arr.mData);
|
|
|
|
}
|
|
|
|
void Uniform4fv(WebGLUniformLocation* location, nsTArray<WebGLfloat>& arr) {
|
|
|
|
Uniform4fv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform4fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
|
|
|
WebGLfloat* data);
|
|
|
|
|
|
|
|
void UniformMatrix2fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
|
|
|
dom::Float32Array &value) {
|
|
|
|
UniformMatrix2fv_base(location, transpose, value.mLength, value.mData);
|
|
|
|
}
|
|
|
|
void UniformMatrix2fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
|
|
|
nsTArray<float> &value) {
|
|
|
|
UniformMatrix2fv_base(location, transpose, value.Length(),
|
|
|
|
value.Elements());
|
|
|
|
}
|
|
|
|
void UniformMatrix2fv_base(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose, uint32_t arrayLength,
|
|
|
|
float* data);
|
|
|
|
|
|
|
|
void UniformMatrix3fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
|
|
|
dom::Float32Array &value) {
|
|
|
|
UniformMatrix3fv_base(location, transpose, value.mLength, value.mData);
|
|
|
|
}
|
|
|
|
void UniformMatrix3fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
|
|
|
nsTArray<float> &value) {
|
|
|
|
UniformMatrix3fv_base(location, transpose, value.Length(),
|
|
|
|
value.Elements());
|
|
|
|
}
|
|
|
|
void UniformMatrix3fv_base(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose, uint32_t arrayLength,
|
|
|
|
float* data);
|
|
|
|
|
|
|
|
void UniformMatrix4fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
|
|
|
dom::Float32Array &value) {
|
|
|
|
UniformMatrix4fv_base(location, transpose, value.mLength, value.mData);
|
|
|
|
}
|
|
|
|
void UniformMatrix4fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
|
|
|
nsTArray<float> &value) {
|
|
|
|
UniformMatrix4fv_base(location, transpose, value.Length(),
|
|
|
|
value.Elements());
|
|
|
|
}
|
|
|
|
void UniformMatrix4fv_base(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose, uint32_t arrayLength,
|
|
|
|
float* data);
|
|
|
|
|
|
|
|
void UseProgram(WebGLProgram *prog);
|
|
|
|
void ValidateProgram(WebGLProgram *prog);
|
|
|
|
|
|
|
|
void VertexAttrib1f(WebGLuint index, WebGLfloat x0);
|
|
|
|
void VertexAttrib2f(WebGLuint index, WebGLfloat x0, WebGLfloat x1);
|
|
|
|
void VertexAttrib3f(WebGLuint index, WebGLfloat x0, WebGLfloat x1,
|
|
|
|
WebGLfloat x2);
|
|
|
|
void VertexAttrib4f(WebGLuint index, WebGLfloat x0, WebGLfloat x1,
|
|
|
|
WebGLfloat x2, WebGLfloat x3);
|
|
|
|
|
|
|
|
void VertexAttrib1fv(WebGLuint idx, dom::Float32Array &arr) {
|
|
|
|
VertexAttrib1fv_base(idx, arr.mLength, arr.mData);
|
|
|
|
}
|
|
|
|
void VertexAttrib1fv(WebGLuint idx, nsTArray<WebGLfloat>& arr) {
|
|
|
|
VertexAttrib1fv_base(idx, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void VertexAttrib1fv_base(WebGLuint idx, uint32_t arrayLength,
|
|
|
|
WebGLfloat* ptr);
|
|
|
|
|
|
|
|
void VertexAttrib2fv(WebGLuint idx, dom::Float32Array &arr) {
|
|
|
|
VertexAttrib2fv_base(idx, arr.mLength, arr.mData);
|
|
|
|
}
|
|
|
|
void VertexAttrib2fv(WebGLuint idx, nsTArray<WebGLfloat>& arr) {
|
|
|
|
VertexAttrib2fv_base(idx, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void VertexAttrib2fv_base(WebGLuint idx, uint32_t arrayLength,
|
|
|
|
WebGLfloat* ptr);
|
|
|
|
|
|
|
|
void VertexAttrib3fv(WebGLuint idx, dom::Float32Array &arr) {
|
|
|
|
VertexAttrib3fv_base(idx, arr.mLength, arr.mData);
|
|
|
|
}
|
|
|
|
void VertexAttrib3fv(WebGLuint idx, nsTArray<WebGLfloat>& arr) {
|
|
|
|
VertexAttrib3fv_base(idx, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void VertexAttrib3fv_base(WebGLuint idx, uint32_t arrayLength,
|
|
|
|
WebGLfloat* ptr);
|
|
|
|
|
|
|
|
void VertexAttrib4fv(WebGLuint idx, dom::Float32Array &arr) {
|
|
|
|
VertexAttrib4fv_base(idx, arr.mLength, arr.mData);
|
|
|
|
}
|
|
|
|
void VertexAttrib4fv(WebGLuint idx, nsTArray<WebGLfloat>& arr) {
|
|
|
|
VertexAttrib4fv_base(idx, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void VertexAttrib4fv_base(WebGLuint idx, uint32_t arrayLength,
|
|
|
|
WebGLfloat* ptr);
|
|
|
|
|
|
|
|
void VertexAttribPointer(WebGLuint index, WebGLint size, WebGLenum type,
|
|
|
|
WebGLboolean normalized, WebGLsizei stride,
|
|
|
|
WebGLintptr byteOffset);
|
|
|
|
void Viewport(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height);
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
protected:
|
2010-08-23 14:03:53 -07:00
|
|
|
void SetDontKnowIfNeedFakeBlack() {
|
|
|
|
mFakeBlackStatus = DontKnowIfNeedFakeBlack;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool NeedFakeBlack();
|
2010-08-23 14:03:53 -07:00
|
|
|
void BindFakeBlackTextures();
|
|
|
|
void UnbindFakeBlackTextures();
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
int WhatDoesVertexAttrib0Need();
|
2011-09-21 23:55:10 -07:00
|
|
|
bool DoFakeVertexAttrib0(WebGLuint vertexCount);
|
2010-09-02 07:34:08 -07:00
|
|
|
void UndoFakeVertexAttrib0();
|
2011-02-24 14:17:34 -08:00
|
|
|
void InvalidateFakeVertexAttrib0();
|
2010-09-02 07:34:08 -07:00
|
|
|
|
2011-09-01 12:28:34 -07:00
|
|
|
static CheckedUint32 GetImageSize(WebGLsizei height,
|
|
|
|
WebGLsizei width,
|
|
|
|
PRUint32 pixelSize,
|
|
|
|
PRUint32 alignment);
|
|
|
|
|
|
|
|
// Returns x rounded to the next highest multiple of y.
|
|
|
|
static CheckedUint32 RoundedToNextMultipleOf(CheckedUint32 x, CheckedUint32 y) {
|
|
|
|
return ((x + y - 1) / y) * y;
|
|
|
|
}
|
|
|
|
|
2010-06-15 14:38:05 -07:00
|
|
|
nsCOMPtr<nsIDOMHTMLCanvasElement> mCanvasElement;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
nsRefPtr<gl::GLContext> gl;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
CheckedUint32 mGeneration;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-11-16 20:33:03 -08:00
|
|
|
WebGLContextOptions mOptions;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mInvalidated;
|
|
|
|
bool mResetLayer;
|
|
|
|
bool mVerbose;
|
|
|
|
bool mOptionsFrozen;
|
2011-10-13 05:09:22 -07:00
|
|
|
bool mMinCapability;
|
|
|
|
bool mDisableExtensions;
|
2011-11-18 19:57:29 -08:00
|
|
|
bool mHasRobustness;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:43 -08:00
|
|
|
template<typename WebGLObjectType>
|
|
|
|
void DeleteWebGLObjectsArray(nsTArray<WebGLObjectType>& array);
|
|
|
|
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint mActiveTexture;
|
2011-07-07 17:01:16 -07:00
|
|
|
WebGLenum mWebGLError;
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2010-07-14 20:52:34 -07:00
|
|
|
// whether shader validation is supported
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mShaderValidation;
|
2010-07-14 20:52:34 -07:00
|
|
|
|
|
|
|
// some GL constants
|
2010-08-23 14:03:35 -07:00
|
|
|
PRInt32 mGLMaxVertexAttribs;
|
|
|
|
PRInt32 mGLMaxTextureUnits;
|
|
|
|
PRInt32 mGLMaxTextureSize;
|
|
|
|
PRInt32 mGLMaxCubeMapTextureSize;
|
|
|
|
PRInt32 mGLMaxTextureImageUnits;
|
|
|
|
PRInt32 mGLMaxVertexTextureImageUnits;
|
|
|
|
PRInt32 mGLMaxVaryingVectors;
|
|
|
|
PRInt32 mGLMaxFragmentUniformVectors;
|
|
|
|
PRInt32 mGLMaxVertexUniformVectors;
|
2010-07-14 20:52:34 -07:00
|
|
|
|
2012-01-04 13:12:03 -08:00
|
|
|
// Represents current status, or state, of the context. That is, is it lost
|
|
|
|
// or stable and what part of the context lost process are we currently at.
|
|
|
|
// This is used to support the WebGL spec's asyncronous nature in handling
|
|
|
|
// context loss.
|
|
|
|
enum ContextStatus {
|
|
|
|
// The context is stable; there either are none or we don't know of any.
|
|
|
|
ContextStable,
|
|
|
|
// The context has been lost, but we have not yet sent an event to the
|
|
|
|
// script informing it of this.
|
|
|
|
ContextLostAwaitingEvent,
|
|
|
|
// The context has been lost, and we have sent the script an event
|
|
|
|
// informing it of this.
|
|
|
|
ContextLost,
|
|
|
|
// The context is lost, an event has been sent to the script, and the
|
|
|
|
// script correctly handled the event. We are waiting for the context to
|
|
|
|
// be restored.
|
|
|
|
ContextLostAwaitingRestore
|
|
|
|
};
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
// extensions
|
|
|
|
enum WebGLExtensionID {
|
|
|
|
WebGL_OES_texture_float,
|
2011-09-30 21:45:50 -07:00
|
|
|
WebGL_OES_standard_derivatives,
|
2012-02-23 05:43:57 -08:00
|
|
|
WebGL_EXT_texture_filter_anisotropic,
|
2012-01-04 13:12:03 -08:00
|
|
|
WebGL_MOZ_WEBGL_lose_context,
|
2011-05-20 12:53:53 -07:00
|
|
|
WebGLExtensionID_Max
|
|
|
|
};
|
2012-03-26 12:02:43 -07:00
|
|
|
nsAutoTArray<nsRefPtr<WebGLExtension>, WebGLExtensionID_Max> mEnabledExtensions;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsExtensionEnabled(WebGLExtensionID ext) const {
|
2011-05-20 12:53:53 -07:00
|
|
|
NS_ABORT_IF_FALSE(ext >= 0 && ext < WebGLExtensionID_Max, "bogus index!");
|
2011-05-20 12:53:53 -07:00
|
|
|
return mEnabledExtensions[ext] != nsnull;
|
|
|
|
}
|
2011-08-15 12:53:02 -07:00
|
|
|
bool IsExtensionSupported(WebGLExtensionID ei);
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool InitAndValidateGL();
|
|
|
|
bool ValidateBuffers(PRInt32* maxAllowedCount, const char *info);
|
|
|
|
bool ValidateCapabilityEnum(WebGLenum cap, const char *info);
|
|
|
|
bool ValidateBlendEquationEnum(WebGLenum cap, const char *info);
|
|
|
|
bool ValidateBlendFuncDstEnum(WebGLenum mode, const char *info);
|
|
|
|
bool ValidateBlendFuncSrcEnum(WebGLenum mode, const char *info);
|
|
|
|
bool ValidateBlendFuncEnumsCompatibility(WebGLenum sfactor, WebGLenum dfactor, const char *info);
|
|
|
|
bool ValidateTextureTargetEnum(WebGLenum target, const char *info);
|
|
|
|
bool ValidateComparisonEnum(WebGLenum target, const char *info);
|
|
|
|
bool ValidateStencilOpEnum(WebGLenum action, const char *info);
|
|
|
|
bool ValidateFaceEnum(WebGLenum face, const char *info);
|
|
|
|
bool ValidateBufferUsageEnum(WebGLenum target, const char *info);
|
|
|
|
bool ValidateTexFormatAndType(WebGLenum format, WebGLenum type, int jsArrayType,
|
2010-06-30 08:49:59 -07:00
|
|
|
PRUint32 *texelSize, const char *info);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ValidateDrawModeEnum(WebGLenum mode, const char *info);
|
|
|
|
bool ValidateAttribIndex(WebGLuint index, const char *info);
|
|
|
|
bool ValidateStencilParamsForDrawCall();
|
2011-07-07 17:01:12 -07:00
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
bool ValidateGLSLVariableName(const nsAString& name, const char *info);
|
|
|
|
bool ValidateGLSLCharacter(PRUnichar c);
|
|
|
|
bool ValidateGLSLString(const nsAString& string, const char *info);
|
2011-07-28 14:12:31 -07:00
|
|
|
|
2011-07-07 17:01:12 -07:00
|
|
|
static PRUint32 GetTexelSize(WebGLenum format, WebGLenum type);
|
2010-06-30 08:48:30 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
void Invalidate();
|
2010-07-18 22:01:14 -07:00
|
|
|
void DestroyResourcesAndContext();
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
void MakeContextCurrent() { gl->MakeCurrent(); }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
// helpers
|
2012-05-04 09:38:44 -07:00
|
|
|
void TexImage2D_base(WebGLenum target, WebGLint level, WebGLenum internalformat,
|
|
|
|
WebGLsizei width, WebGLsizei height, WebGLsizei srcStrideOrZero, WebGLint border,
|
|
|
|
WebGLenum format, WebGLenum type,
|
|
|
|
void *data, PRUint32 byteLength,
|
|
|
|
int jsArrayType,
|
2012-05-07 11:04:10 -07:00
|
|
|
int srcFormat, bool srcPremultiplied);
|
2012-05-04 09:38:44 -07:00
|
|
|
void TexSubImage2D_base(WebGLenum target, WebGLint level,
|
|
|
|
WebGLint xoffset, WebGLint yoffset,
|
|
|
|
WebGLsizei width, WebGLsizei height, WebGLsizei srcStrideOrZero,
|
|
|
|
WebGLenum format, WebGLenum type,
|
|
|
|
void *pixels, PRUint32 byteLength,
|
|
|
|
int jsArrayType,
|
2012-05-07 11:04:10 -07:00
|
|
|
int srcFormat, bool srcPremultiplied);
|
2012-05-04 09:38:44 -07:00
|
|
|
void TexParameter_base(WebGLenum target, WebGLenum pname,
|
|
|
|
WebGLint *intParamPtr, WebGLfloat *floatParamPtr);
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
void ConvertImage(size_t width, size_t height, size_t srcStride, size_t dstStride,
|
2010-10-15 14:50:15 -07:00
|
|
|
const PRUint8*src, PRUint8 *dst,
|
2012-05-07 11:04:10 -07:00
|
|
|
int srcFormat, bool srcPremultiplied,
|
|
|
|
int dstFormat, bool dstPremultiplied,
|
2010-10-15 14:50:15 -07:00
|
|
|
size_t dstTexelSize);
|
|
|
|
|
2012-03-11 00:54:24 -08:00
|
|
|
nsresult DOMElementToImageSurface(dom::Element* imageOrCanvas,
|
2010-01-22 13:34:25 -08:00
|
|
|
gfxImageSurface **imageOut,
|
2012-05-07 11:04:10 -07:00
|
|
|
int *format);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void CopyTexSubImage2D_base(WebGLenum target,
|
|
|
|
WebGLint level,
|
|
|
|
WebGLenum internalformat,
|
|
|
|
WebGLint xoffset,
|
|
|
|
WebGLint yoffset,
|
|
|
|
WebGLint x,
|
|
|
|
WebGLint y,
|
|
|
|
WebGLsizei width,
|
|
|
|
WebGLsizei height,
|
|
|
|
bool sub);
|
|
|
|
|
|
|
|
// Returns false if aObject is null or not valid
|
|
|
|
template<class ObjectType>
|
|
|
|
bool ValidateObject(const char* info, ObjectType *aObject);
|
|
|
|
// Returns false if aObject is not valid. Considers null to be valid.
|
|
|
|
template<class ObjectType>
|
|
|
|
bool ValidateObjectAllowNull(const char* info, ObjectType *aObject);
|
|
|
|
// Returns false if aObject is not valid, but considers deleted
|
|
|
|
// objects and null objects valid.
|
|
|
|
template<class ObjectType>
|
|
|
|
bool ValidateObjectAllowDeletedOrNull(const char* info, ObjectType *aObject);
|
|
|
|
// Returns false if aObject is null or not valid, but considers deleted
|
|
|
|
// objects valid.
|
|
|
|
template<class ObjectType>
|
|
|
|
bool ValidateObjectAllowDeleted(const char* info, ObjectType *aObject);
|
|
|
|
private:
|
|
|
|
// Like ValidateObject, but only for cases when aObject is known
|
|
|
|
// to not be null already.
|
|
|
|
template<class ObjectType>
|
|
|
|
bool ValidateObjectAssumeNonNull(const char* info, ObjectType *aObject);
|
2010-06-04 12:03:37 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
protected:
|
2011-02-24 14:17:34 -08:00
|
|
|
PRInt32 MaxTextureSizeForTarget(WebGLenum target) const {
|
|
|
|
return target == LOCAL_GL_TEXTURE_2D ? mGLMaxTextureSize : mGLMaxCubeMapTextureSize;
|
|
|
|
}
|
2011-07-07 17:01:16 -07:00
|
|
|
|
|
|
|
/** like glBufferData but if the call may change the buffer size, checks any GL error generated
|
|
|
|
* by this glBufferData call and returns it */
|
|
|
|
GLenum CheckedBufferData(GLenum target,
|
|
|
|
GLsizeiptr size,
|
|
|
|
const GLvoid *data,
|
|
|
|
GLenum usage);
|
2011-07-07 17:01:16 -07:00
|
|
|
/** like glTexImage2D but if the call may change the texture size, checks any GL error generated
|
|
|
|
* by this glTexImage2D call and returns it */
|
|
|
|
GLenum CheckedTexImage2D(GLenum target,
|
|
|
|
GLint level,
|
|
|
|
GLenum internalFormat,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
|
|
|
GLint border,
|
|
|
|
GLenum format,
|
|
|
|
GLenum type,
|
|
|
|
const GLvoid *data);
|
2010-06-04 12:03:37 -07:00
|
|
|
|
2011-10-26 13:00:44 -07:00
|
|
|
void MaybeRestoreContext();
|
2012-05-05 06:28:25 -07:00
|
|
|
bool IsContextStable() const {
|
|
|
|
return mContextStatus == ContextStable;
|
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
void ForceLoseContext();
|
|
|
|
void ForceRestoreContext();
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
// the buffers bound to the current program's attribs
|
|
|
|
nsTArray<WebGLVertexAttribData> mAttribBuffers;
|
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
nsTArray<WebGLRefPtr<WebGLTexture> > mBound2DTextures;
|
|
|
|
nsTArray<WebGLRefPtr<WebGLTexture> > mBoundCubeMapTextures;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLRefPtr<WebGLBuffer> mBoundArrayBuffer;
|
|
|
|
WebGLRefPtr<WebGLBuffer> mBoundElementArrayBuffer;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLRefPtr<WebGLProgram> mCurrentProgram;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-11-05 12:57:58 -07:00
|
|
|
PRUint32 mMaxFramebufferColorAttachments;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLRefPtr<WebGLFramebuffer> mBoundFramebuffer;
|
|
|
|
WebGLRefPtr<WebGLRenderbuffer> mBoundRenderbuffer;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLFastArray<WebGLTexture*> mTextures;
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLFastArray<WebGLBuffer*> mBuffers;
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLFastArray<WebGLProgram*> mPrograms;
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLFastArray<WebGLShader*> mShaders;
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLFastArray<WebGLRenderbuffer*> mRenderbuffers;
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLFastArray<WebGLFramebuffer*> mFramebuffers;
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLFastArray<WebGLUniformLocation*> mUniformLocations;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
// PixelStore parameters
|
2010-12-06 03:34:35 -08:00
|
|
|
PRUint32 mPixelStorePackAlignment, mPixelStoreUnpackAlignment, mPixelStoreColorspaceConversion;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mPixelStoreFlipY, mPixelStorePremultiplyAlpha;
|
2010-06-15 08:59:39 -07:00
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
FakeBlackStatus mFakeBlackStatus;
|
|
|
|
|
|
|
|
WebGLuint mBlackTexture2D, mBlackTextureCubeMap;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mBlackTexturesAreInitialized;
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2010-09-02 07:34:08 -07:00
|
|
|
WebGLfloat mVertexAttrib0Vector[4];
|
2011-02-24 14:17:34 -08:00
|
|
|
WebGLfloat mFakeVertexAttrib0BufferObjectVector[4];
|
|
|
|
size_t mFakeVertexAttrib0BufferObjectSize;
|
|
|
|
GLuint mFakeVertexAttrib0BufferObject;
|
|
|
|
int mFakeVertexAttrib0BufferStatus;
|
2010-09-02 07:34:08 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
WebGLint mStencilRefFront, mStencilRefBack;
|
|
|
|
WebGLuint mStencilValueMaskFront, mStencilValueMaskBack,
|
|
|
|
mStencilWriteMaskFront, mStencilWriteMaskBack;
|
2011-05-20 12:53:53 -07:00
|
|
|
realGLboolean mColorWriteMask[4];
|
|
|
|
realGLboolean mDepthWriteMask;
|
|
|
|
realGLboolean mScissorTestEnabled;
|
|
|
|
realGLboolean mDitherEnabled;
|
|
|
|
WebGLfloat mColorClearValue[4];
|
|
|
|
WebGLint mStencilClearValue;
|
|
|
|
WebGLfloat mDepthClearValue;
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
int mBackbufferClearingStatus;
|
|
|
|
|
2011-10-26 13:00:44 -07:00
|
|
|
nsCOMPtr<nsITimer> mContextRestorer;
|
|
|
|
bool mAllowRestore;
|
2012-04-21 13:48:22 -07:00
|
|
|
bool mContextLossTimerRunning;
|
|
|
|
bool mDrawSinceContextLossTimerSet;
|
2012-01-04 13:12:03 -08:00
|
|
|
ContextStatus mContextStatus;
|
|
|
|
bool mContextLostErrorSet;
|
2012-02-29 12:49:55 -08:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// see bug 713305. This RAII helper guarantees that we're on the discrete GPU, during its lifetime
|
|
|
|
// Debouncing note: we don't want to switch GPUs too frequently, so try to not create and destroy
|
|
|
|
// these objects at high frequency. Having WebGLContext's hold one such object seems fine,
|
|
|
|
// because WebGLContext objects only go away during GC, which shouldn't happen too frequently.
|
|
|
|
// If in the future GC becomes much more frequent, we may have to revisit then (maybe use a timer).
|
|
|
|
ForceDiscreteGPUHelperCGL mForceDiscreteGPUHelper;
|
|
|
|
#endif
|
|
|
|
|
2012-04-21 13:48:22 -07:00
|
|
|
nsRefPtr<WebGLMemoryPressureObserver> mMemoryPressureObserver;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-05-19 13:46:08 -07:00
|
|
|
public:
|
2009-09-02 17:47:49 -07:00
|
|
|
// console logging helpers
|
2010-09-13 08:40:01 -07:00
|
|
|
static void LogMessage(const char *fmt, ...);
|
2010-05-15 06:55:45 -07:00
|
|
|
static void LogMessage(const char *fmt, va_list ap);
|
2010-09-13 08:40:01 -07:00
|
|
|
void LogMessageIfVerbose(const char *fmt, ...);
|
2010-10-15 14:50:15 -07:00
|
|
|
void LogMessageIfVerbose(const char *fmt, va_list ap);
|
2010-08-23 14:03:53 -07:00
|
|
|
|
|
|
|
friend class WebGLTexture;
|
2010-11-05 12:57:58 -07:00
|
|
|
friend class WebGLFramebuffer;
|
2011-12-04 11:15:42 -08:00
|
|
|
friend class WebGLRenderbuffer;
|
2011-11-03 07:50:40 -07:00
|
|
|
friend class WebGLProgram;
|
2011-12-04 11:15:42 -08:00
|
|
|
friend class WebGLBuffer;
|
|
|
|
friend class WebGLShader;
|
2011-12-04 11:15:43 -08:00
|
|
|
friend class WebGLUniformLocation;
|
2009-09-02 17:47:49 -07:00
|
|
|
};
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
// This class is a mixin for objects that are tied to a specific
|
|
|
|
// context (which is to say, all of them). They provide initialization
|
|
|
|
// as well as comparison with the current context.
|
|
|
|
class WebGLContextBoundObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebGLContextBoundObject(WebGLContext *context) {
|
|
|
|
mContext = context;
|
|
|
|
mContextGeneration = context->Generation();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsCompatibleWithContext(WebGLContext *other) {
|
2010-06-04 12:03:37 -07:00
|
|
|
return mContext == other &&
|
|
|
|
mContextGeneration == other->Generation();
|
|
|
|
}
|
|
|
|
|
2012-03-26 11:59:04 -07:00
|
|
|
WebGLContext *Context() const { return mContext; }
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
protected:
|
|
|
|
WebGLContext *mContext;
|
|
|
|
PRUint32 mContextGeneration;
|
2010-05-15 05:07:30 -07:00
|
|
|
};
|
|
|
|
|
2011-12-04 11:15:43 -08:00
|
|
|
struct WebGLVertexAttribData {
|
|
|
|
// note that these initial values are what GL initializes vertex attribs to
|
|
|
|
WebGLVertexAttribData()
|
|
|
|
: buf(0), stride(0), size(4), byteOffset(0),
|
|
|
|
type(LOCAL_GL_FLOAT), enabled(false), normalized(false)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
WebGLRefPtr<WebGLBuffer> buf;
|
|
|
|
WebGLuint stride;
|
|
|
|
WebGLuint size;
|
|
|
|
GLuint byteOffset;
|
|
|
|
GLenum type;
|
|
|
|
bool enabled;
|
|
|
|
bool normalized;
|
|
|
|
|
|
|
|
GLuint componentSize() const {
|
|
|
|
switch(type) {
|
|
|
|
case LOCAL_GL_BYTE:
|
|
|
|
return sizeof(GLbyte);
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
return sizeof(GLubyte);
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_SHORT:
|
|
|
|
return sizeof(GLshort);
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
|
|
|
return sizeof(GLushort);
|
|
|
|
break;
|
|
|
|
// XXX case LOCAL_GL_FIXED:
|
|
|
|
case LOCAL_GL_FLOAT:
|
|
|
|
return sizeof(GLfloat);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Should never get here!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GLuint actualStride() const {
|
|
|
|
if (stride) return stride;
|
|
|
|
return size * componentSize();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
// NOTE: When this class is switched to new DOM bindings, update the
|
|
|
|
// (then-slow) WrapObject calls in GetParameter and GetVertexAttrib.
|
2012-02-16 05:24:18 -08:00
|
|
|
class WebGLBuffer MOZ_FINAL
|
2011-12-04 11:15:42 -08:00
|
|
|
: public nsIWebGLBuffer
|
|
|
|
, public WebGLRefCountedObject<WebGLBuffer>
|
|
|
|
, public WebGLContextBoundObject
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLBuffer(WebGLContext *context)
|
|
|
|
: WebGLContextBoundObject(context)
|
|
|
|
, mHasEverBeenBound(false)
|
|
|
|
, mByteLength(0)
|
|
|
|
, mTarget(LOCAL_GL_NONE)
|
|
|
|
, mData(nsnull)
|
|
|
|
{
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fGenBuffers(1, &mGLName);
|
2011-12-04 11:15:43 -08:00
|
|
|
mMonotonicHandle = mContext->mBuffers.AppendElement(this);
|
2011-12-04 11:15:42 -08:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-01 23:09:18 -07:00
|
|
|
~WebGLBuffer() {
|
2011-12-04 11:15:42 -08:00
|
|
|
DeleteOnce();
|
2010-06-01 23:09:18 -07:00
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
void Delete() {
|
2011-12-04 11:15:42 -08:00
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDeleteBuffers(1, &mGLName);
|
2010-06-01 23:09:18 -07:00
|
|
|
free(mData);
|
|
|
|
mData = nsnull;
|
2010-01-22 13:34:25 -08:00
|
|
|
mByteLength = 0;
|
2011-12-04 11:15:43 -08:00
|
|
|
mContext->mBuffers.RemoveElement(mMonotonicHandle);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2012-02-19 19:58:08 -08:00
|
|
|
size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const {
|
|
|
|
return aMallocSizeOf(this) + aMallocSizeOf(mData);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasEverBeenBound() { return mHasEverBeenBound; }
|
|
|
|
void SetHasEverBeenBound(bool x) { mHasEverBeenBound = x; }
|
2011-12-04 11:15:42 -08:00
|
|
|
GLuint GLName() const { return mGLName; }
|
2010-06-01 23:09:18 -07:00
|
|
|
GLuint ByteLength() const { return mByteLength; }
|
|
|
|
GLenum Target() const { return mTarget; }
|
|
|
|
const void *Data() const { return mData; }
|
|
|
|
|
|
|
|
void SetByteLength(GLuint byteLength) { mByteLength = byteLength; }
|
|
|
|
void SetTarget(GLenum target) { mTarget = target; }
|
|
|
|
|
|
|
|
// element array buffers are the only buffers for which we need to keep a copy of the data.
|
|
|
|
// this method assumes that the byte length has previously been set by calling SetByteLength.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool CopyDataIfElementArray(const void* data) {
|
2010-06-01 23:09:18 -07:00
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
mData = realloc(mData, mByteLength);
|
2011-09-09 15:00:20 -07:00
|
|
|
if (!mData) {
|
|
|
|
mByteLength = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-09-09 15:00:20 -07:00
|
|
|
}
|
2010-06-01 23:09:18 -07:00
|
|
|
memcpy(mData, data, mByteLength);
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-01 23:09:18 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-01 23:09:18 -07:00
|
|
|
// same comments as for CopyElementArrayData
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ZeroDataIfElementArray() {
|
2010-06-01 23:09:18 -07:00
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
mData = realloc(mData, mByteLength);
|
2011-09-09 15:00:20 -07:00
|
|
|
if (!mData) {
|
|
|
|
mByteLength = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-09-09 15:00:20 -07:00
|
|
|
}
|
2010-06-01 23:09:18 -07:00
|
|
|
memset(mData, 0, mByteLength);
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-01 23:09:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// same comments as for CopyElementArrayData
|
|
|
|
void CopySubDataIfElementArray(GLuint byteOffset, GLuint byteLength, const void* data) {
|
2011-09-09 15:00:20 -07:00
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER && mByteLength) {
|
2010-06-01 23:09:18 -07:00
|
|
|
memcpy((void*) (size_t(mData)+byteOffset), data, byteLength);
|
|
|
|
}
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-01 23:09:18 -07:00
|
|
|
// this method too is only for element array buffers. It returns the maximum value in the part of
|
|
|
|
// the buffer starting at given offset, consisting of given count of elements. The type T is the type
|
|
|
|
// to interprete the array elements as, must be GLushort or GLubyte.
|
|
|
|
template<typename T>
|
2011-01-25 19:19:46 -08:00
|
|
|
PRInt32 FindMaxElementInSubArray(GLuint count, GLuint byteOffset)
|
2010-06-01 23:09:18 -07:00
|
|
|
{
|
|
|
|
const T* start = reinterpret_cast<T*>(reinterpret_cast<size_t>(mData) + byteOffset);
|
|
|
|
const T* stop = start + count;
|
|
|
|
T result = 0;
|
|
|
|
for(const T* ptr = start; ptr != stop; ++ptr) {
|
|
|
|
if (*ptr > result) result = *ptr;
|
|
|
|
}
|
|
|
|
return result;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2011-01-25 19:19:46 -08:00
|
|
|
void InvalidateCachedMaxElements() {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasCachedMaxUbyteElement = false;
|
|
|
|
mHasCachedMaxUshortElement = false;
|
2011-01-25 19:19:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 FindMaxUbyteElement() {
|
|
|
|
if (mHasCachedMaxUbyteElement) {
|
|
|
|
return mCachedMaxUbyteElement;
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasCachedMaxUbyteElement = true;
|
2011-01-25 19:19:46 -08:00
|
|
|
mCachedMaxUbyteElement = FindMaxElementInSubArray<GLubyte>(mByteLength, 0);
|
|
|
|
return mCachedMaxUbyteElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 FindMaxUshortElement() {
|
|
|
|
if (mHasCachedMaxUshortElement) {
|
|
|
|
return mCachedMaxUshortElement;
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasCachedMaxUshortElement = true;
|
2012-04-09 19:51:29 -07:00
|
|
|
mCachedMaxUshortElement = FindMaxElementInSubArray<GLushort>(mByteLength>>1, 0);
|
2011-01-25 19:19:46 -08:00
|
|
|
return mCachedMaxUshortElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBGLBUFFER
|
2011-12-04 11:15:42 -08:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
protected:
|
2011-12-04 11:15:42 -08:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLuint mGLName;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHasEverBeenBound;
|
2010-06-01 23:09:18 -07:00
|
|
|
GLuint mByteLength;
|
|
|
|
GLenum mTarget;
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLMonotonicHandle mMonotonicHandle;
|
2011-01-25 19:19:46 -08:00
|
|
|
|
|
|
|
PRUint8 mCachedMaxUbyteElement;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHasCachedMaxUbyteElement;
|
2011-01-25 19:19:46 -08:00
|
|
|
PRUint16 mCachedMaxUshortElement;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHasCachedMaxUshortElement;
|
2011-02-11 15:11:30 -08:00
|
|
|
|
2010-06-01 23:09:18 -07:00
|
|
|
void* mData; // in the case of an Element Array Buffer, we keep a copy.
|
2009-09-02 17:47:49 -07:00
|
|
|
};
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
// NOTE: When this class is switched to new DOM bindings, update the (then-slow)
|
|
|
|
// WrapObject calls in GetParameter and GetFramebufferAttachmentParameter.
|
2012-02-16 05:24:18 -08:00
|
|
|
class WebGLTexture MOZ_FINAL
|
2011-12-04 11:15:42 -08:00
|
|
|
: public nsIWebGLTexture
|
|
|
|
, public WebGLRefCountedObject<WebGLTexture>
|
|
|
|
, public WebGLContextBoundObject
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLTexture(WebGLContext *context)
|
|
|
|
: WebGLContextBoundObject(context)
|
|
|
|
, mHasEverBeenBound(false)
|
|
|
|
, mTarget(0)
|
|
|
|
, mMinFilter(LOCAL_GL_NEAREST_MIPMAP_LINEAR)
|
|
|
|
, mMagFilter(LOCAL_GL_LINEAR)
|
|
|
|
, mWrapS(LOCAL_GL_REPEAT)
|
|
|
|
, mWrapT(LOCAL_GL_REPEAT)
|
|
|
|
, mFacesCount(0)
|
|
|
|
, mMaxLevelWithCustomImages(0)
|
|
|
|
, mHaveGeneratedMipmap(false)
|
|
|
|
, mFakeBlackStatus(DoNotNeedFakeBlack)
|
2010-12-06 03:34:35 -08:00
|
|
|
{
|
2011-12-04 11:15:42 -08:00
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fGenTextures(1, &mGLName);
|
2011-12-04 11:15:43 -08:00
|
|
|
mMonotonicHandle = mContext->mTextures.AppendElement(this);
|
2011-12-04 11:15:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
~WebGLTexture() {
|
|
|
|
DeleteOnce();
|
2010-12-06 03:34:35 -08:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
void Delete() {
|
2011-12-04 11:15:42 -08:00
|
|
|
mImageInfos.Clear();
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDeleteTextures(1, &mGLName);
|
2011-12-04 11:15:43 -08:00
|
|
|
mContext->mTextures.RemoveElement(mMonotonicHandle);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasEverBeenBound() { return mHasEverBeenBound; }
|
|
|
|
void SetHasEverBeenBound(bool x) { mHasEverBeenBound = x; }
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLuint GLName() { return mGLName; }
|
2011-12-04 11:15:42 -08:00
|
|
|
GLenum Target() const { return mTarget; }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBGLTEXTURE
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
protected:
|
2011-12-04 11:15:42 -08:00
|
|
|
|
2010-11-16 20:33:03 -08:00
|
|
|
friend class WebGLContext;
|
|
|
|
friend class WebGLFramebuffer;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHasEverBeenBound;
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLuint mGLName;
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2010-11-16 20:33:03 -08:00
|
|
|
// we store information about the various images that are part of
|
|
|
|
// this texture (cubemap faces, mipmap levels)
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
public:
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
class ImageInfo : public WebGLRectangleObject {
|
|
|
|
public:
|
2012-04-03 16:42:06 -07:00
|
|
|
ImageInfo()
|
|
|
|
: mFormat(0)
|
|
|
|
, mType(0)
|
|
|
|
, mIsDefined(false)
|
|
|
|
{}
|
|
|
|
|
2011-07-07 17:01:17 -07:00
|
|
|
ImageInfo(WebGLsizei width, WebGLsizei height,
|
|
|
|
WebGLenum format, WebGLenum type)
|
2012-04-03 16:42:06 -07:00
|
|
|
: WebGLRectangleObject(width, height)
|
|
|
|
, mFormat(format)
|
|
|
|
, mType(type)
|
|
|
|
, mIsDefined(true)
|
|
|
|
{}
|
2011-07-07 17:01:17 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool operator==(const ImageInfo& a) const {
|
2012-04-03 16:42:06 -07:00
|
|
|
return mIsDefined == a.mIsDefined &&
|
|
|
|
mWidth == a.mWidth &&
|
|
|
|
mHeight == a.mHeight &&
|
|
|
|
mFormat == a.mFormat &&
|
|
|
|
mType == a.mType;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
bool operator!=(const ImageInfo& a) const {
|
2010-08-23 14:03:53 -07:00
|
|
|
return !(*this == a);
|
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsSquare() const {
|
2010-08-23 14:03:53 -07:00
|
|
|
return mWidth == mHeight;
|
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsPositive() const {
|
2010-08-23 14:03:53 -07:00
|
|
|
return mWidth > 0 && mHeight > 0;
|
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsPowerOfTwo() const {
|
2010-08-23 14:03:53 -07:00
|
|
|
return is_pot_assuming_nonnegative(mWidth) &&
|
|
|
|
is_pot_assuming_nonnegative(mHeight); // negative sizes should never happen (caught in texImage2D...)
|
|
|
|
}
|
2011-07-07 17:01:12 -07:00
|
|
|
PRInt64 MemoryUsage() const {
|
|
|
|
if (!mIsDefined)
|
|
|
|
return 0;
|
|
|
|
PRInt64 texelSize = WebGLContext::GetTexelSize(mFormat, mType);
|
|
|
|
return PRInt64(mWidth) * PRInt64(mHeight) * texelSize;
|
|
|
|
}
|
2012-01-24 13:12:31 -08:00
|
|
|
WebGLenum Format() const { return mFormat; }
|
|
|
|
WebGLenum Type() const { return mType; }
|
|
|
|
protected:
|
2010-08-23 14:03:53 -07:00
|
|
|
WebGLenum mFormat, mType;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsDefined;
|
2012-01-24 13:12:31 -08:00
|
|
|
|
|
|
|
friend class WebGLTexture;
|
2010-08-23 14:03:53 -07:00
|
|
|
};
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
ImageInfo& ImageInfoAt(size_t level, size_t face = 0) {
|
2010-08-23 14:03:53 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (face >= mFacesCount)
|
|
|
|
NS_ERROR("wrong face index, must be 0 for TEXTURE_2D and at most 5 for cube maps");
|
|
|
|
#endif
|
|
|
|
// no need to check level as a wrong value would be caught by ElementAt().
|
|
|
|
return mImageInfos.ElementAt(level * mFacesCount + face);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ImageInfo& ImageInfoAt(size_t level, size_t face) const {
|
|
|
|
return const_cast<WebGLTexture*>(this)->ImageInfoAt(level, face);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasImageInfoAt(size_t level, size_t face) const {
|
2011-11-28 11:30:28 -08:00
|
|
|
CheckedUint32 checked_index = CheckedUint32(level) * mFacesCount + face;
|
|
|
|
return checked_index.valid() &&
|
|
|
|
checked_index.value() < mImageInfos.Length() &&
|
|
|
|
ImageInfoAt(level, face).mIsDefined;
|
2011-02-24 14:17:34 -08:00
|
|
|
}
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
static size_t FaceForTarget(WebGLenum target) {
|
|
|
|
return target == LOCAL_GL_TEXTURE_2D ? 0 : target - LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X;
|
|
|
|
}
|
|
|
|
|
2011-07-07 17:01:12 -07:00
|
|
|
PRInt64 MemoryUsage() const {
|
2011-12-04 11:15:43 -08:00
|
|
|
if (IsDeleted())
|
|
|
|
return 0;
|
2011-07-07 17:01:12 -07:00
|
|
|
PRInt64 result = 0;
|
|
|
|
for(size_t face = 0; face < mFacesCount; face++) {
|
|
|
|
if (mHaveGeneratedMipmap) {
|
|
|
|
// Each mipmap level is 1/4 the size of the previous level
|
|
|
|
// 1 + x + x^2 + ... = 1/(1-x)
|
|
|
|
// for x = 1/4, we get 1/(1-1/4) = 4/3
|
|
|
|
result += ImageInfoAt(0, face).MemoryUsage() * 4 / 3;
|
|
|
|
} else {
|
|
|
|
for(size_t level = 0; level <= mMaxLevelWithCustomImages; level++)
|
|
|
|
result += ImageInfoAt(level, face).MemoryUsage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
protected:
|
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
WebGLenum mTarget;
|
|
|
|
WebGLenum mMinFilter, mMagFilter, mWrapS, mWrapT;
|
|
|
|
|
|
|
|
size_t mFacesCount, mMaxLevelWithCustomImages;
|
|
|
|
nsTArray<ImageInfo> mImageInfos;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHaveGeneratedMipmap;
|
2010-08-23 14:03:53 -07:00
|
|
|
FakeBlackStatus mFakeBlackStatus;
|
|
|
|
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLMonotonicHandle mMonotonicHandle;
|
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
void EnsureMaxLevelWithCustomImagesAtLeast(size_t aMaxLevelWithCustomImages) {
|
2011-06-02 05:56:50 -07:00
|
|
|
mMaxLevelWithCustomImages = NS_MAX(mMaxLevelWithCustomImages, aMaxLevelWithCustomImages);
|
2010-08-23 14:03:53 -07:00
|
|
|
mImageInfos.EnsureLengthAtLeast((mMaxLevelWithCustomImages + 1) * mFacesCount);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool CheckFloatTextureFilterParams() const {
|
2011-05-20 12:53:53 -07:00
|
|
|
// Without OES_texture_float_linear, only NEAREST and NEAREST_MIMPAMP_NEAREST are supported
|
|
|
|
return (mMagFilter == LOCAL_GL_NEAREST) &&
|
|
|
|
(mMinFilter == LOCAL_GL_NEAREST || mMinFilter == LOCAL_GL_NEAREST_MIPMAP_NEAREST);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AreBothWrapModesClampToEdge() const {
|
2010-08-23 14:03:53 -07:00
|
|
|
return mWrapS == LOCAL_GL_CLAMP_TO_EDGE && mWrapT == LOCAL_GL_CLAMP_TO_EDGE;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool DoesTexture2DMipmapHaveAllLevelsConsistentlyDefined(size_t face) const {
|
2010-08-23 14:03:53 -07:00
|
|
|
if (mHaveGeneratedMipmap)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-23 14:03:53 -07:00
|
|
|
|
|
|
|
ImageInfo expected = ImageInfoAt(0, face);
|
|
|
|
|
|
|
|
// checks if custom level>0 images are all defined up to the highest level defined
|
|
|
|
// and have the expected dimensions
|
|
|
|
for (size_t level = 0; level <= mMaxLevelWithCustomImages; ++level) {
|
|
|
|
const ImageInfo& actual = ImageInfoAt(level, face);
|
|
|
|
if (actual != expected)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-06-02 05:56:50 -07:00
|
|
|
expected.mWidth = NS_MAX(1, expected.mWidth >> 1);
|
|
|
|
expected.mHeight = NS_MAX(1, expected.mHeight >> 1);
|
2010-08-23 14:03:53 -07:00
|
|
|
|
|
|
|
// if the current level has size 1x1, we can stop here: the spec doesn't seem to forbid the existence
|
|
|
|
// of extra useless levels.
|
|
|
|
if (actual.mWidth == 1 && actual.mHeight == 1)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we're here, we've exhausted all levels without finding a 1x1 image
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
void SetDontKnowIfNeedFakeBlack() {
|
|
|
|
mFakeBlackStatus = DontKnowIfNeedFakeBlack;
|
|
|
|
mContext->SetDontKnowIfNeedFakeBlack();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bind(WebGLenum aTarget) {
|
|
|
|
// this function should only be called by bindTexture().
|
|
|
|
// it assumes that the GL context is already current.
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool firstTimeThisTextureIsBound = !mHasEverBeenBound;
|
2010-08-23 14:03:53 -07:00
|
|
|
|
|
|
|
if (!firstTimeThisTextureIsBound && aTarget != mTarget) {
|
|
|
|
mContext->ErrorInvalidOperation("bindTexture: this texture has already been bound to a different target");
|
|
|
|
// very important to return here before modifying texture state! This was the place when I lost a whole day figuring
|
|
|
|
// very strange 'invalid write' crashes.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTarget = aTarget;
|
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
mContext->gl->fBindTexture(mTarget, mGLName);
|
2010-08-23 14:03:53 -07:00
|
|
|
|
|
|
|
if (firstTimeThisTextureIsBound) {
|
|
|
|
mFacesCount = (mTarget == LOCAL_GL_TEXTURE_2D) ? 1 : 6;
|
|
|
|
EnsureMaxLevelWithCustomImagesAtLeast(0);
|
|
|
|
SetDontKnowIfNeedFakeBlack();
|
|
|
|
|
|
|
|
// thanks to the WebKit people for finding this out: GL_TEXTURE_WRAP_R is not
|
|
|
|
// present in GLES 2, but is present in GL and it seems as if for cube maps
|
|
|
|
// we need to set it to GL_CLAMP_TO_EDGE to get the expected GLES behavior.
|
|
|
|
if (mTarget == LOCAL_GL_TEXTURE_CUBE_MAP && !mContext->gl->IsGLES2())
|
|
|
|
mContext->gl->fTexParameteri(mTarget, LOCAL_GL_TEXTURE_WRAP_R, LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
2011-02-11 15:11:30 -08:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasEverBeenBound = true;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetImageInfo(WebGLenum aTarget, WebGLint aLevel,
|
|
|
|
WebGLsizei aWidth, WebGLsizei aHeight,
|
2011-07-07 17:01:17 -07:00
|
|
|
WebGLenum aFormat, WebGLenum aType)
|
2011-02-24 14:17:34 -08:00
|
|
|
{
|
|
|
|
if ( (aTarget == LOCAL_GL_TEXTURE_2D) != (mTarget == LOCAL_GL_TEXTURE_2D) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
size_t face = FaceForTarget(aTarget);
|
2010-08-23 14:03:53 -07:00
|
|
|
|
|
|
|
EnsureMaxLevelWithCustomImagesAtLeast(aLevel);
|
|
|
|
|
2011-07-07 17:01:17 -07:00
|
|
|
ImageInfoAt(aLevel, face) = ImageInfo(aWidth, aHeight, aFormat, aType);
|
2010-08-23 14:03:53 -07:00
|
|
|
|
|
|
|
if (aLevel > 0)
|
|
|
|
SetCustomMipmap();
|
|
|
|
|
|
|
|
SetDontKnowIfNeedFakeBlack();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMinFilter(WebGLenum aMinFilter) {
|
|
|
|
mMinFilter = aMinFilter;
|
|
|
|
SetDontKnowIfNeedFakeBlack();
|
|
|
|
}
|
|
|
|
void SetMagFilter(WebGLenum aMagFilter) {
|
|
|
|
mMagFilter = aMagFilter;
|
|
|
|
SetDontKnowIfNeedFakeBlack();
|
|
|
|
}
|
|
|
|
void SetWrapS(WebGLenum aWrapS) {
|
|
|
|
mWrapS = aWrapS;
|
|
|
|
SetDontKnowIfNeedFakeBlack();
|
|
|
|
}
|
|
|
|
void SetWrapT(WebGLenum aWrapT) {
|
|
|
|
mWrapT = aWrapT;
|
|
|
|
SetDontKnowIfNeedFakeBlack();
|
|
|
|
}
|
2011-09-09 15:00:20 -07:00
|
|
|
WebGLenum MinFilter() const { return mMinFilter; }
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool DoesMinFilterRequireMipmap() const {
|
2011-09-09 15:00:20 -07:00
|
|
|
return !(mMinFilter == LOCAL_GL_NEAREST || mMinFilter == LOCAL_GL_LINEAR);
|
|
|
|
}
|
2010-08-23 14:03:53 -07:00
|
|
|
|
|
|
|
void SetGeneratedMipmap() {
|
|
|
|
if (!mHaveGeneratedMipmap) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHaveGeneratedMipmap = true;
|
2010-08-23 14:03:53 -07:00
|
|
|
SetDontKnowIfNeedFakeBlack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCustomMipmap() {
|
|
|
|
if (mHaveGeneratedMipmap) {
|
|
|
|
// if we were in GeneratedMipmap mode and are now switching to CustomMipmap mode,
|
|
|
|
// we need to compute now all the mipmap image info.
|
|
|
|
|
|
|
|
// since we were in GeneratedMipmap mode, we know that the level 0 images all have the same info,
|
|
|
|
// and are power-of-two.
|
|
|
|
ImageInfo imageInfo = ImageInfoAt(0, 0);
|
|
|
|
NS_ASSERTION(imageInfo.IsPowerOfTwo(), "this texture is NPOT, so how could GenerateMipmap() ever accept it?");
|
|
|
|
|
2011-06-02 05:56:50 -07:00
|
|
|
WebGLsizei size = NS_MAX(imageInfo.mWidth, imageInfo.mHeight);
|
2010-08-23 14:03:53 -07:00
|
|
|
|
|
|
|
// so, the size is a power of two, let's find its log in base 2.
|
|
|
|
size_t maxLevel = 0;
|
|
|
|
for (WebGLsizei n = size; n > 1; n >>= 1)
|
|
|
|
++maxLevel;
|
|
|
|
|
|
|
|
EnsureMaxLevelWithCustomImagesAtLeast(maxLevel);
|
|
|
|
|
|
|
|
for (size_t level = 1; level <= maxLevel; ++level) {
|
|
|
|
// again, since the sizes are powers of two, no need for any max(1,x) computation
|
|
|
|
imageInfo.mWidth >>= 1;
|
|
|
|
imageInfo.mHeight >>= 1;
|
|
|
|
for(size_t face = 0; face < mFacesCount; ++face)
|
|
|
|
ImageInfoAt(level, face) = imageInfo;
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
mHaveGeneratedMipmap = false;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsFirstImagePowerOfTwo() const {
|
2010-09-02 07:29:41 -07:00
|
|
|
return ImageInfoAt(0, 0).IsPowerOfTwo();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AreAllLevel0ImageInfosEqual() const {
|
2010-09-02 07:29:41 -07:00
|
|
|
for (size_t face = 1; face < mFacesCount; ++face) {
|
|
|
|
if (ImageInfoAt(0, face) != ImageInfoAt(0, 0))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsMipmapTexture2DComplete() const {
|
2010-08-23 14:03:53 -07:00
|
|
|
if (mTarget != LOCAL_GL_TEXTURE_2D)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-09-02 07:29:41 -07:00
|
|
|
if (!ImageInfoAt(0, 0).IsPositive())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-23 14:03:53 -07:00
|
|
|
if (mHaveGeneratedMipmap)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-23 14:03:53 -07:00
|
|
|
return DoesTexture2DMipmapHaveAllLevelsConsistentlyDefined(0);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsCubeComplete() const {
|
2010-08-23 14:03:53 -07:00
|
|
|
if (mTarget != LOCAL_GL_TEXTURE_CUBE_MAP)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-23 14:03:53 -07:00
|
|
|
const ImageInfo &first = ImageInfoAt(0, 0);
|
|
|
|
if (!first.IsPositive() || !first.IsSquare())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-09-02 07:29:41 -07:00
|
|
|
return AreAllLevel0ImageInfosEqual();
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsMipmapCubeComplete() const {
|
2010-08-23 14:03:53 -07:00
|
|
|
if (!IsCubeComplete()) // in particular, this checks that this is a cube map
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-23 14:03:53 -07:00
|
|
|
for (size_t face = 0; face < mFacesCount; ++face) {
|
|
|
|
if (!DoesTexture2DMipmapHaveAllLevelsConsistentlyDefined(face))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool NeedFakeBlack() {
|
2010-08-23 14:03:53 -07:00
|
|
|
// handle this case first, it's the generic case
|
|
|
|
if (mFakeBlackStatus == DoNotNeedFakeBlack)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-23 14:03:53 -07:00
|
|
|
|
|
|
|
if (mFakeBlackStatus == DontKnowIfNeedFakeBlack) {
|
|
|
|
// Determine if the texture needs to be faked as a black texture.
|
|
|
|
// See 3.8.2 Shader Execution in the OpenGL ES 2.0.24 spec.
|
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
for (size_t face = 0; face < mFacesCount; ++face) {
|
2010-12-06 03:34:35 -08:00
|
|
|
if (!ImageInfoAt(0, face).mIsDefined) {
|
|
|
|
// In case of undefined texture image, we don't print any message because this is a very common
|
|
|
|
// and often legitimate case, for example when doing asynchronous texture loading.
|
|
|
|
// An extreme case of this is the photowall google demo.
|
|
|
|
// Exiting early here allows us to avoid making noise on valid webgl code.
|
|
|
|
mFakeBlackStatus = DoNeedFakeBlack;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-10-15 14:50:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-02 07:29:41 -07:00
|
|
|
const char *msg_rendering_as_black
|
|
|
|
= "A texture is going to be rendered as if it were black, as per the OpenGL ES 2.0.24 spec section 3.8.2, "
|
|
|
|
"because it";
|
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
if (mTarget == LOCAL_GL_TEXTURE_2D)
|
|
|
|
{
|
|
|
|
if (DoesMinFilterRequireMipmap())
|
|
|
|
{
|
2010-09-02 07:29:41 -07:00
|
|
|
if (!IsMipmapTexture2DComplete()) {
|
2010-09-13 08:40:01 -07:00
|
|
|
mContext->LogMessageIfVerbose
|
|
|
|
("%s is a 2D texture, with a minification filter requiring a mipmap, "
|
|
|
|
"and is not mipmap complete (as defined in section 3.7.10).", msg_rendering_as_black);
|
2010-09-02 07:29:41 -07:00
|
|
|
mFakeBlackStatus = DoNeedFakeBlack;
|
2011-05-20 12:53:53 -07:00
|
|
|
} else if (!ImageInfoAt(0).IsPowerOfTwo()) {
|
2010-09-13 08:40:01 -07:00
|
|
|
mContext->LogMessageIfVerbose
|
|
|
|
("%s is a 2D texture, with a minification filter requiring a mipmap, "
|
|
|
|
"and either its width or height is not a power of two.", msg_rendering_as_black);
|
2010-08-23 14:03:53 -07:00
|
|
|
mFakeBlackStatus = DoNeedFakeBlack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // no mipmap required
|
|
|
|
{
|
2011-05-20 12:53:53 -07:00
|
|
|
if (!ImageInfoAt(0).IsPositive()) {
|
2010-09-13 08:40:01 -07:00
|
|
|
mContext->LogMessageIfVerbose
|
|
|
|
("%s is a 2D texture and its width or height is equal to zero.",
|
|
|
|
msg_rendering_as_black);
|
2010-09-02 07:29:41 -07:00
|
|
|
mFakeBlackStatus = DoNeedFakeBlack;
|
2011-05-20 12:53:53 -07:00
|
|
|
} else if (!AreBothWrapModesClampToEdge() && !ImageInfoAt(0).IsPowerOfTwo()) {
|
2010-09-13 08:40:01 -07:00
|
|
|
mContext->LogMessageIfVerbose
|
|
|
|
("%s is a 2D texture, with a minification filter not requiring a mipmap, "
|
|
|
|
"with its width or height not a power of two, and with a wrap mode "
|
|
|
|
"different from CLAMP_TO_EDGE.", msg_rendering_as_black);
|
2010-08-23 14:03:53 -07:00
|
|
|
mFakeBlackStatus = DoNeedFakeBlack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-02 07:29:41 -07:00
|
|
|
else // cube map
|
2010-08-23 14:03:53 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool areAllLevel0ImagesPOT = true;
|
2010-08-23 14:03:53 -07:00
|
|
|
for (size_t face = 0; face < mFacesCount; ++face)
|
|
|
|
areAllLevel0ImagesPOT &= ImageInfoAt(0, face).IsPowerOfTwo();
|
|
|
|
|
|
|
|
if (DoesMinFilterRequireMipmap())
|
|
|
|
{
|
2010-09-02 07:29:41 -07:00
|
|
|
if (!IsMipmapCubeComplete()) {
|
2010-09-13 08:40:01 -07:00
|
|
|
mContext->LogMessageIfVerbose("%s is a cube map texture, with a minification filter requiring a mipmap, "
|
2010-09-02 07:29:41 -07:00
|
|
|
"and is not mipmap cube complete (as defined in section 3.7.10).",
|
|
|
|
msg_rendering_as_black);
|
|
|
|
mFakeBlackStatus = DoNeedFakeBlack;
|
|
|
|
} else if (!areAllLevel0ImagesPOT) {
|
2010-09-13 08:40:01 -07:00
|
|
|
mContext->LogMessageIfVerbose("%s is a cube map texture, with a minification filter requiring a mipmap, "
|
2010-09-02 07:29:41 -07:00
|
|
|
"and either the width or the height of some level 0 image is not a power of two.",
|
|
|
|
msg_rendering_as_black);
|
2010-08-23 14:03:53 -07:00
|
|
|
mFakeBlackStatus = DoNeedFakeBlack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // no mipmap required
|
|
|
|
{
|
2010-09-02 07:29:41 -07:00
|
|
|
if (!IsCubeComplete()) {
|
2010-09-13 08:40:01 -07:00
|
|
|
mContext->LogMessageIfVerbose("%s is a cube map texture, with a minification filter not requiring a mipmap, "
|
2010-09-02 07:29:41 -07:00
|
|
|
"and is not cube complete (as defined in section 3.7.10).",
|
|
|
|
msg_rendering_as_black);
|
|
|
|
mFakeBlackStatus = DoNeedFakeBlack;
|
|
|
|
} else if (!AreBothWrapModesClampToEdge() && !areAllLevel0ImagesPOT) {
|
2010-09-13 08:40:01 -07:00
|
|
|
mContext->LogMessageIfVerbose("%s is a cube map texture, with a minification filter not requiring a mipmap, "
|
2010-09-02 07:29:41 -07:00
|
|
|
"with some level 0 image having width or height not a power of two, and with a wrap mode "
|
|
|
|
"different from CLAMP_TO_EDGE.", msg_rendering_as_black);
|
2010-08-23 14:03:53 -07:00
|
|
|
mFakeBlackStatus = DoNeedFakeBlack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// we have exhausted all cases where we do need fakeblack, so if the status is still unknown,
|
|
|
|
// that means that we do NOT need it.
|
|
|
|
if (mFakeBlackStatus == DontKnowIfNeedFakeBlack)
|
|
|
|
mFakeBlackStatus = DoNotNeedFakeBlack;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mFakeBlackStatus == DoNeedFakeBlack;
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
};
|
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
struct WebGLMappedIdentifier {
|
|
|
|
nsCString original, mapped; // ASCII strings
|
|
|
|
WebGLMappedIdentifier(const nsACString& o, const nsACString& m) : original(o), mapped(m) {}
|
|
|
|
};
|
|
|
|
|
2012-04-16 12:56:12 -07:00
|
|
|
struct WebGLUniformInfo {
|
|
|
|
PRUint32 arraySize;
|
|
|
|
bool isArray;
|
|
|
|
ShDataType type;
|
|
|
|
|
|
|
|
WebGLUniformInfo(PRUint32 s = 0, bool a = false, ShDataType t = SH_NONE)
|
|
|
|
: arraySize(s), isArray(a), type(t) {}
|
|
|
|
|
|
|
|
int ElementSize() const {
|
|
|
|
switch (type) {
|
|
|
|
case SH_INT:
|
|
|
|
case SH_FLOAT:
|
|
|
|
case SH_BOOL:
|
|
|
|
case SH_SAMPLER_2D:
|
|
|
|
case SH_SAMPLER_CUBE:
|
|
|
|
return 1;
|
|
|
|
case SH_INT_VEC2:
|
|
|
|
case SH_FLOAT_VEC2:
|
|
|
|
case SH_BOOL_VEC2:
|
|
|
|
return 2;
|
|
|
|
case SH_INT_VEC3:
|
|
|
|
case SH_FLOAT_VEC3:
|
|
|
|
case SH_BOOL_VEC3:
|
|
|
|
return 3;
|
|
|
|
case SH_INT_VEC4:
|
|
|
|
case SH_FLOAT_VEC4:
|
|
|
|
case SH_BOOL_VEC4:
|
|
|
|
case SH_FLOAT_MAT2:
|
|
|
|
return 4;
|
|
|
|
case SH_FLOAT_MAT3:
|
|
|
|
return 9;
|
|
|
|
case SH_FLOAT_MAT4:
|
|
|
|
return 16;
|
|
|
|
default:
|
|
|
|
NS_ABORT(); // should never get here
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-16 05:24:18 -08:00
|
|
|
class WebGLShader MOZ_FINAL
|
2011-12-04 11:15:42 -08:00
|
|
|
: public nsIWebGLShader
|
|
|
|
, public WebGLRefCountedObject<WebGLShader>
|
|
|
|
, public WebGLContextBoundObject
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-03-02 12:42:49 -08:00
|
|
|
friend class WebGLContext;
|
|
|
|
friend class WebGLProgram;
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
public:
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLShader(WebGLContext *context, WebGLenum stype)
|
|
|
|
: WebGLContextBoundObject(context)
|
|
|
|
, mType(stype)
|
|
|
|
, mNeedsTranslation(true)
|
2012-03-02 12:42:49 -08:00
|
|
|
, mAttribMaxNameLength(0)
|
2011-12-04 11:15:42 -08:00
|
|
|
{
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mGLName = mContext->gl->fCreateShader(mType);
|
2011-12-04 11:15:43 -08:00
|
|
|
mMonotonicHandle = mContext->mShaders.AppendElement(this);
|
2011-11-03 07:50:40 -07:00
|
|
|
}
|
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
~WebGLShader() {
|
|
|
|
DeleteOnce();
|
2011-11-03 07:50:40 -07:00
|
|
|
}
|
2012-02-19 19:58:08 -08:00
|
|
|
|
|
|
|
size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) {
|
|
|
|
return aMallocSizeOf(this) +
|
|
|
|
mSource.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
|
|
|
|
mTranslationLog.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
}
|
2011-11-03 07:50:40 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
void Delete() {
|
2011-12-04 11:15:42 -08:00
|
|
|
mSource.Truncate();
|
|
|
|
mTranslationLog.Truncate();
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDeleteShader(mGLName);
|
2011-12-04 11:15:43 -08:00
|
|
|
mContext->mShaders.RemoveElement(mMonotonicHandle);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2010-06-04 12:03:37 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLuint GLName() { return mGLName; }
|
2010-06-04 12:03:33 -07:00
|
|
|
WebGLenum ShaderType() { return mType; }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
void SetSource(const nsAString& src) {
|
2010-07-14 20:52:34 -07:00
|
|
|
// XXX do some quick gzip here maybe -- getting this will be very rare
|
|
|
|
mSource.Assign(src);
|
|
|
|
}
|
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
const nsString& Source() const { return mSource; }
|
2010-07-14 20:52:34 -07:00
|
|
|
|
|
|
|
void SetNeedsTranslation() { mNeedsTranslation = true; }
|
|
|
|
bool NeedsTranslation() const { return mNeedsTranslation; }
|
|
|
|
|
|
|
|
void SetTranslationSuccess() {
|
2011-10-17 07:59:28 -07:00
|
|
|
mTranslationLog.SetIsVoid(true);
|
2010-07-14 20:52:34 -07:00
|
|
|
mNeedsTranslation = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetTranslationFailure(const nsCString& msg) {
|
2011-09-07 14:17:44 -07:00
|
|
|
mTranslationLog.Assign(msg);
|
2010-07-14 20:52:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsCString& TranslationLog() const { return mTranslationLog; }
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_DECL_ISUPPORTS
|
2010-06-04 12:03:33 -07:00
|
|
|
NS_DECL_NSIWEBGLSHADER
|
2011-12-04 11:15:42 -08:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
protected:
|
2011-12-04 11:15:42 -08:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLuint mGLName;
|
2010-06-04 12:03:33 -07:00
|
|
|
WebGLenum mType;
|
2011-09-07 14:17:44 -07:00
|
|
|
nsString mSource;
|
2012-03-02 12:42:49 -08:00
|
|
|
nsCString mTranslationLog; // The translation log should contain only ASCII characters
|
2010-07-14 20:52:34 -07:00
|
|
|
bool mNeedsTranslation;
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLMonotonicHandle mMonotonicHandle;
|
2012-03-02 12:42:49 -08:00
|
|
|
nsTArray<WebGLMappedIdentifier> mAttributes;
|
|
|
|
nsTArray<WebGLMappedIdentifier> mUniforms;
|
2012-04-16 12:56:12 -07:00
|
|
|
nsTArray<WebGLUniformInfo> mUniformInfos;
|
2012-03-02 12:42:49 -08:00
|
|
|
int mAttribMaxNameLength;
|
2009-09-02 17:47:49 -07:00
|
|
|
};
|
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
/** Takes an ASCII string like "foo[i]", turns it into "foo" and returns "[i]" in bracketPart
|
|
|
|
*
|
|
|
|
* \param string input/output: the string to split, becomes the string without the bracket part
|
|
|
|
* \param bracketPart output: gets the bracket part.
|
|
|
|
*
|
|
|
|
* Notice that if there are multiple brackets like "foo[i].bar[j]", only the last bracket is split.
|
|
|
|
*/
|
|
|
|
static bool SplitLastSquareBracket(nsACString& string, nsCString& bracketPart)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(bracketPart.Length() == 0, "SplitLastSquareBracket must be called with empty bracketPart string");
|
|
|
|
char *string_start = string.BeginWriting();
|
|
|
|
char *s = string_start + string.Length() - 1;
|
|
|
|
|
|
|
|
if (*s != ']')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
while (*s != '[' && s != string_start)
|
|
|
|
s--;
|
|
|
|
|
|
|
|
if (*s != '[')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bracketPart.Assign(s);
|
|
|
|
*s = 0;
|
|
|
|
string.EndWriting();
|
|
|
|
string.SetLength(s - string_start);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-16 12:56:12 -07:00
|
|
|
typedef nsDataHashtable<nsCStringHashKey, nsCString> CStringMap;
|
|
|
|
typedef nsDataHashtable<nsCStringHashKey, WebGLUniformInfo> CStringToUniformInfoMap;
|
2012-03-02 12:42:49 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
// NOTE: When this class is switched to new DOM bindings, update the
|
|
|
|
// (then-slow) WrapObject call in GetParameter.
|
2012-02-16 05:24:18 -08:00
|
|
|
class WebGLProgram MOZ_FINAL
|
2011-12-04 11:15:42 -08:00
|
|
|
: public nsIWebGLProgram
|
|
|
|
, public WebGLRefCountedObject<WebGLProgram>
|
|
|
|
, public WebGLContextBoundObject
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLProgram(WebGLContext *context)
|
|
|
|
: WebGLContextBoundObject(context)
|
|
|
|
, mLinkStatus(false)
|
|
|
|
, mGeneration(0)
|
|
|
|
, mAttribMaxNameLength(0)
|
2010-06-08 14:25:27 -07:00
|
|
|
{
|
2011-12-04 11:15:42 -08:00
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mGLName = mContext->gl->fCreateProgram();
|
2011-12-04 11:15:43 -08:00
|
|
|
mMonotonicHandle = mContext->mPrograms.AppendElement(this);
|
2010-06-08 14:25:27 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
~WebGLProgram() {
|
|
|
|
DeleteOnce();
|
2011-11-03 07:50:40 -07:00
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
void Delete() {
|
2011-11-03 07:50:40 -07:00
|
|
|
DetachShaders();
|
2011-12-04 11:15:42 -08:00
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDeleteProgram(mGLName);
|
2011-12-04 11:15:43 -08:00
|
|
|
mContext->mPrograms.RemoveElement(mMonotonicHandle);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2010-06-04 12:03:33 -07:00
|
|
|
|
2011-01-05 13:08:53 -08:00
|
|
|
void DetachShaders() {
|
|
|
|
mAttachedShaders.Clear();
|
|
|
|
}
|
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLuint GLName() { return mGLName; }
|
2011-12-04 11:15:42 -08:00
|
|
|
const nsTArray<WebGLRefPtr<WebGLShader> >& AttachedShaders() const { return mAttachedShaders; }
|
2011-09-28 23:19:26 -07:00
|
|
|
bool LinkStatus() { return mLinkStatus; }
|
2010-07-03 15:32:19 -07:00
|
|
|
PRUint32 Generation() const { return mGeneration.value(); }
|
2011-09-28 23:19:26 -07:00
|
|
|
void SetLinkStatus(bool val) { mLinkStatus = val; }
|
2010-06-04 12:03:33 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ContainsShader(WebGLShader *shader) {
|
2010-06-04 12:03:33 -07:00
|
|
|
return mAttachedShaders.Contains(shader);
|
|
|
|
}
|
|
|
|
|
|
|
|
// return true if the shader wasn't already attached
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AttachShader(WebGLShader *shader) {
|
2010-06-04 12:03:33 -07:00
|
|
|
if (ContainsShader(shader))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-04 12:03:33 -07:00
|
|
|
mAttachedShaders.AppendElement(shader);
|
2011-12-04 11:15:42 -08:00
|
|
|
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fAttachShader(GLName(), shader->GLName());
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-04 12:03:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// return true if the shader was found and removed
|
2011-09-28 23:19:26 -07:00
|
|
|
bool DetachShader(WebGLShader *shader) {
|
2011-12-04 11:15:42 -08:00
|
|
|
if (!mAttachedShaders.RemoveElement(shader))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDetachShader(GLName(), shader->GLName());
|
|
|
|
|
|
|
|
return true;
|
2010-06-04 12:03:33 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasAttachedShaderOfType(GLenum shaderType) {
|
2010-06-04 12:03:33 -07:00
|
|
|
for (PRUint32 i = 0; i < mAttachedShaders.Length(); ++i) {
|
2011-05-06 11:44:23 -07:00
|
|
|
if (mAttachedShaders[i] && mAttachedShaders[i]->ShaderType() == shaderType) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-11-16 20:33:04 -08:00
|
|
|
}
|
2010-06-04 12:03:33 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-04 12:03:33 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasBothShaderTypesAttached() {
|
2010-11-16 20:33:04 -08:00
|
|
|
return
|
|
|
|
HasAttachedShaderOfType(LOCAL_GL_VERTEX_SHADER) &&
|
|
|
|
HasAttachedShaderOfType(LOCAL_GL_FRAGMENT_SHADER);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool NextGeneration()
|
2010-06-08 14:25:27 -07:00
|
|
|
{
|
2010-07-03 15:32:19 -07:00
|
|
|
if (!(mGeneration+1).valid())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false; // must exit without changing mGeneration
|
2010-07-03 15:32:19 -07:00
|
|
|
++mGeneration;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-08 14:25:27 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
/* Called only after LinkProgram */
|
2012-03-02 12:42:49 -08:00
|
|
|
bool UpdateInfo();
|
2010-06-10 10:45:00 -07:00
|
|
|
|
|
|
|
/* Getters for cached program info */
|
|
|
|
bool IsAttribInUse(unsigned i) const { return mAttribsInUse[i]; }
|
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
/* Maps identifier |name| to the mapped identifier |*mappedName|
|
|
|
|
* Both are ASCII strings.
|
|
|
|
*/
|
|
|
|
void MapIdentifier(const nsACString& name, nsCString *mappedName) {
|
|
|
|
if (!mIdentifierMap) {
|
|
|
|
// if the identifier map doesn't exist yet, build it now
|
2012-04-16 12:56:12 -07:00
|
|
|
mIdentifierMap = new CStringMap;
|
2012-03-02 12:42:49 -08:00
|
|
|
mIdentifierMap->Init();
|
|
|
|
for (size_t i = 0; i < mAttachedShaders.Length(); i++) {
|
|
|
|
for (size_t j = 0; j < mAttachedShaders[i]->mAttributes.Length(); j++) {
|
|
|
|
const WebGLMappedIdentifier& attrib = mAttachedShaders[i]->mAttributes[j];
|
|
|
|
mIdentifierMap->Put(attrib.original, attrib.mapped);
|
|
|
|
}
|
|
|
|
for (size_t j = 0; j < mAttachedShaders[i]->mUniforms.Length(); j++) {
|
|
|
|
const WebGLMappedIdentifier& uniform = mAttachedShaders[i]->mUniforms[j];
|
|
|
|
mIdentifierMap->Put(uniform.original, uniform.mapped);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString mutableName(name);
|
|
|
|
nsCString bracketPart;
|
|
|
|
bool hadBracketPart = SplitLastSquareBracket(mutableName, bracketPart);
|
|
|
|
if (hadBracketPart)
|
|
|
|
mutableName.AppendLiteral("[0]");
|
|
|
|
|
|
|
|
if (mIdentifierMap->Get(mutableName, mappedName)) {
|
|
|
|
if (hadBracketPart) {
|
|
|
|
nsCString mappedBracketPart;
|
|
|
|
bool mappedHadBracketPart = SplitLastSquareBracket(*mappedName, mappedBracketPart);
|
|
|
|
if (mappedHadBracketPart)
|
|
|
|
mappedName->Append(bracketPart);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// not found? We might be in the situation we have a uniform array name and the GL's glGetActiveUniform
|
|
|
|
// returned its name without [0], as is allowed by desktop GL but not in ES. Let's then try with [0].
|
|
|
|
mutableName.AppendLiteral("[0]");
|
|
|
|
if (mIdentifierMap->Get(mutableName, mappedName))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// not found? return name unchanged. This case happens e.g. on bad user input, or when
|
|
|
|
// we're not using identifier mapping, or if we didn't store an identifier in the map because
|
|
|
|
// e.g. its mapping is trivial (as happens for short identifiers)
|
|
|
|
mappedName->Assign(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Un-maps mapped identifier |name| to the original identifier |*reverseMappedName|
|
|
|
|
* Both are ASCII strings.
|
|
|
|
*/
|
|
|
|
void ReverseMapIdentifier(const nsACString& name, nsCString *reverseMappedName) {
|
|
|
|
if (!mIdentifierReverseMap) {
|
|
|
|
// if the identifier reverse map doesn't exist yet, build it now
|
2012-04-16 12:56:12 -07:00
|
|
|
mIdentifierReverseMap = new CStringMap;
|
2012-03-02 12:42:49 -08:00
|
|
|
mIdentifierReverseMap->Init();
|
|
|
|
for (size_t i = 0; i < mAttachedShaders.Length(); i++) {
|
|
|
|
for (size_t j = 0; j < mAttachedShaders[i]->mAttributes.Length(); j++) {
|
|
|
|
const WebGLMappedIdentifier& attrib = mAttachedShaders[i]->mAttributes[j];
|
|
|
|
mIdentifierReverseMap->Put(attrib.mapped, attrib.original);
|
|
|
|
}
|
|
|
|
for (size_t j = 0; j < mAttachedShaders[i]->mUniforms.Length(); j++) {
|
|
|
|
const WebGLMappedIdentifier& uniform = mAttachedShaders[i]->mUniforms[j];
|
|
|
|
mIdentifierReverseMap->Put(uniform.mapped, uniform.original);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString mutableName(name);
|
|
|
|
nsCString bracketPart;
|
|
|
|
bool hadBracketPart = SplitLastSquareBracket(mutableName, bracketPart);
|
|
|
|
if (hadBracketPart)
|
|
|
|
mutableName.AppendLiteral("[0]");
|
|
|
|
|
|
|
|
if (mIdentifierReverseMap->Get(mutableName, reverseMappedName)) {
|
|
|
|
if (hadBracketPart) {
|
|
|
|
nsCString reverseMappedBracketPart;
|
|
|
|
bool reverseMappedHadBracketPart = SplitLastSquareBracket(*reverseMappedName, reverseMappedBracketPart);
|
|
|
|
if (reverseMappedHadBracketPart)
|
|
|
|
reverseMappedName->Append(bracketPart);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// not found? We might be in the situation we have a uniform array name and the GL's glGetActiveUniform
|
|
|
|
// returned its name without [0], as is allowed by desktop GL but not in ES. Let's then try with [0].
|
|
|
|
mutableName.AppendLiteral("[0]");
|
|
|
|
if (mIdentifierReverseMap->Get(mutableName, reverseMappedName))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// not found? return name unchanged. This case happens e.g. on bad user input, or when
|
|
|
|
// we're not using identifier mapping, or if we didn't store an identifier in the map because
|
|
|
|
// e.g. its mapping is trivial (as happens for short identifiers)
|
|
|
|
reverseMappedName->Assign(name);
|
|
|
|
}
|
|
|
|
|
2012-04-16 12:56:12 -07:00
|
|
|
/* Returns the uniform array size (or 1 if the uniform is not an array) of
|
|
|
|
* the uniform with given mapped identifier.
|
|
|
|
*
|
|
|
|
* Note: the input string |name| is the mapped identifier, not the original identifier.
|
|
|
|
*/
|
|
|
|
WebGLUniformInfo GetUniformInfoForMappedIdentifier(const nsACString& name) {
|
|
|
|
if (!mUniformInfoMap) {
|
|
|
|
// if the identifier-to-array-size map doesn't exist yet, build it now
|
|
|
|
mUniformInfoMap = new CStringToUniformInfoMap;
|
|
|
|
mUniformInfoMap->Init();
|
|
|
|
for (size_t i = 0; i < mAttachedShaders.Length(); i++) {
|
|
|
|
for (size_t j = 0; j < mAttachedShaders[i]->mUniforms.Length(); j++) {
|
|
|
|
const WebGLMappedIdentifier& uniform = mAttachedShaders[i]->mUniforms[j];
|
|
|
|
const WebGLUniformInfo& info = mAttachedShaders[i]->mUniformInfos[j];
|
|
|
|
mUniformInfoMap->Put(uniform.mapped, info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString mutableName(name);
|
|
|
|
nsCString bracketPart;
|
|
|
|
bool hadBracketPart = SplitLastSquareBracket(mutableName, bracketPart);
|
|
|
|
// if there is a bracket, we're either an array or an entry in an array.
|
|
|
|
if (hadBracketPart)
|
|
|
|
mutableName.AppendLiteral("[0]");
|
|
|
|
|
|
|
|
WebGLUniformInfo info;
|
|
|
|
mUniformInfoMap->Get(mutableName, &info);
|
|
|
|
// we don't check if that Get failed, as if it did, it left info with default values
|
|
|
|
|
|
|
|
// if there is a bracket and it's not [0], then we're not an array, we're just an entry in an array
|
|
|
|
if (hadBracketPart && !bracketPart.EqualsLiteral("[0]")) {
|
|
|
|
info.isArray = false;
|
|
|
|
info.arraySize = 1;
|
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_DECL_ISUPPORTS
|
2010-06-04 12:03:33 -07:00
|
|
|
NS_DECL_NSIWEBGLPROGRAM
|
2011-12-04 11:15:42 -08:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
protected:
|
2011-12-04 11:15:42 -08:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLuint mGLName;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mLinkStatus;
|
2011-01-05 13:08:53 -08:00
|
|
|
// attached shaders of the program object
|
2011-12-04 11:15:42 -08:00
|
|
|
nsTArray<WebGLRefPtr<WebGLShader> > mAttachedShaders;
|
2010-07-03 15:32:19 -07:00
|
|
|
CheckedUint32 mGeneration;
|
2011-01-05 13:08:53 -08:00
|
|
|
|
|
|
|
// post-link data
|
2010-06-10 10:45:00 -07:00
|
|
|
std::vector<bool> mAttribsInUse;
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLMonotonicHandle mMonotonicHandle;
|
2012-04-16 12:56:12 -07:00
|
|
|
nsAutoPtr<CStringMap> mIdentifierMap, mIdentifierReverseMap;
|
|
|
|
nsAutoPtr<CStringToUniformInfoMap> mUniformInfoMap;
|
2012-03-02 12:42:49 -08:00
|
|
|
int mAttribMaxNameLength;
|
2009-09-02 17:47:49 -07:00
|
|
|
};
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
// NOTE: When this class is switched to new DOM bindings, update the (then-slow)
|
|
|
|
// WrapObject calls in GetParameter and GetFramebufferAttachmentParameter.
|
2012-02-16 05:24:18 -08:00
|
|
|
class WebGLRenderbuffer MOZ_FINAL
|
2011-12-04 11:15:42 -08:00
|
|
|
: public nsIWebGLRenderbuffer
|
|
|
|
, public WebGLRefCountedObject<WebGLRenderbuffer>
|
|
|
|
, public WebGLRectangleObject
|
|
|
|
, public WebGLContextBoundObject
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLRenderbuffer(WebGLContext *context)
|
|
|
|
: WebGLContextBoundObject(context)
|
|
|
|
, mInternalFormat(0)
|
|
|
|
, mInternalFormatForGL(0)
|
|
|
|
, mHasEverBeenBound(false)
|
|
|
|
, mInitialized(false)
|
|
|
|
{
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fGenRenderbuffers(1, &mGLName);
|
2011-12-04 11:15:43 -08:00
|
|
|
mMonotonicHandle = mContext->mRenderbuffers.AppendElement(this);
|
2011-12-04 11:15:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
~WebGLRenderbuffer() {
|
|
|
|
DeleteOnce();
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
void Delete() {
|
2011-12-04 11:15:42 -08:00
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDeleteRenderbuffers(1, &mGLName);
|
2011-12-04 11:15:43 -08:00
|
|
|
mContext->mRenderbuffers.RemoveElement(mMonotonicHandle);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2011-12-04 11:15:42 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasEverBeenBound() { return mHasEverBeenBound; }
|
|
|
|
void SetHasEverBeenBound(bool x) { mHasEverBeenBound = x; }
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLuint GLName() const { return mGLName; }
|
2010-11-05 12:57:58 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Initialized() const { return mInitialized; }
|
|
|
|
void SetInitialized(bool aInitialized) { mInitialized = aInitialized; }
|
2010-11-05 12:57:58 -07:00
|
|
|
|
|
|
|
WebGLenum InternalFormat() const { return mInternalFormat; }
|
|
|
|
void SetInternalFormat(WebGLenum aInternalFormat) { mInternalFormat = aInternalFormat; }
|
2011-07-07 17:01:16 -07:00
|
|
|
|
|
|
|
WebGLenum InternalFormatForGL() const { return mInternalFormatForGL; }
|
|
|
|
void SetInternalFormatForGL(WebGLenum aInternalFormatForGL) { mInternalFormatForGL = aInternalFormatForGL; }
|
|
|
|
|
|
|
|
PRInt64 MemoryUsage() const {
|
2012-01-24 13:12:31 -08:00
|
|
|
PRInt64 pixels = PRInt64(Width()) * PRInt64(Height());
|
2011-07-07 17:01:16 -07:00
|
|
|
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;
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2010-11-05 12:57:58 -07:00
|
|
|
NS_DECL_NSIWEBGLRENDERBUFFER
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
protected:
|
2011-12-04 11:15:42 -08:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLuint mGLName;
|
2010-11-05 12:57:58 -07:00
|
|
|
WebGLenum mInternalFormat;
|
2011-07-07 17:01:16 -07:00
|
|
|
WebGLenum mInternalFormatForGL;
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLMonotonicHandle mMonotonicHandle;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHasEverBeenBound;
|
|
|
|
bool mInitialized;
|
2010-11-05 12:57:58 -07:00
|
|
|
|
|
|
|
friend class WebGLFramebuffer;
|
2009-09-02 17:47:49 -07:00
|
|
|
};
|
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
class WebGLFramebufferAttachment
|
|
|
|
{
|
2011-01-05 13:08:53 -08:00
|
|
|
// deleting a texture or renderbuffer immediately detaches it
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLRefPtr<WebGLTexture> mTexturePtr;
|
|
|
|
WebGLRefPtr<WebGLRenderbuffer> mRenderbufferPtr;
|
2010-12-06 03:34:35 -08:00
|
|
|
WebGLenum mAttachmentPoint;
|
2011-01-05 13:08:53 -08:00
|
|
|
WebGLint mTextureLevel;
|
|
|
|
WebGLenum mTextureCubeMapFace;
|
2010-12-06 03:34:35 -08:00
|
|
|
|
|
|
|
public:
|
|
|
|
WebGLFramebufferAttachment(WebGLenum aAttachmentPoint)
|
|
|
|
: mAttachmentPoint(aAttachmentPoint)
|
|
|
|
{}
|
|
|
|
|
2011-12-04 11:15:43 -08:00
|
|
|
bool IsDefined() const {
|
|
|
|
return Texture() || Renderbuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDeleteRequested() const {
|
|
|
|
return Texture() ? Texture()->IsDeleteRequested()
|
|
|
|
: Renderbuffer() ? Renderbuffer()->IsDeleteRequested()
|
|
|
|
: false;
|
2010-12-06 03:34:35 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasAlpha() const {
|
2010-12-06 03:34:35 -08:00
|
|
|
WebGLenum format = 0;
|
2012-01-24 13:12:31 -08:00
|
|
|
if (Texture() && Texture()->HasImageInfoAt(mTextureLevel, mTextureCubeMapFace))
|
|
|
|
format = Texture()->ImageInfoAt(mTextureLevel, mTextureCubeMapFace).Format();
|
2011-12-04 11:15:43 -08:00
|
|
|
else if (Renderbuffer())
|
2012-01-24 13:12:31 -08:00
|
|
|
format = Renderbuffer()->InternalFormat();
|
2010-12-06 03:34:35 -08:00
|
|
|
return format == LOCAL_GL_RGBA ||
|
|
|
|
format == LOCAL_GL_LUMINANCE_ALPHA ||
|
|
|
|
format == LOCAL_GL_ALPHA ||
|
|
|
|
format == LOCAL_GL_RGBA4 ||
|
|
|
|
format == LOCAL_GL_RGB5_A1;
|
|
|
|
}
|
|
|
|
|
2011-01-05 13:08:53 -08:00
|
|
|
void SetTexture(WebGLTexture *tex, WebGLint level, WebGLenum face) {
|
2010-12-06 03:34:35 -08:00
|
|
|
mTexturePtr = tex;
|
|
|
|
mRenderbufferPtr = nsnull;
|
2011-01-05 13:08:53 -08:00
|
|
|
mTextureLevel = level;
|
|
|
|
mTextureCubeMapFace = face;
|
2010-12-06 03:34:35 -08:00
|
|
|
}
|
|
|
|
void SetRenderbuffer(WebGLRenderbuffer *rb) {
|
|
|
|
mTexturePtr = nsnull;
|
|
|
|
mRenderbufferPtr = rb;
|
|
|
|
}
|
2012-01-24 13:12:31 -08:00
|
|
|
const WebGLTexture *Texture() const {
|
|
|
|
return mTexturePtr;
|
|
|
|
}
|
|
|
|
WebGLTexture *Texture() {
|
|
|
|
return mTexturePtr;
|
2010-12-06 03:34:35 -08:00
|
|
|
}
|
2012-01-24 13:12:31 -08:00
|
|
|
const WebGLRenderbuffer *Renderbuffer() const {
|
|
|
|
return mRenderbufferPtr;
|
|
|
|
}
|
|
|
|
WebGLRenderbuffer *Renderbuffer() {
|
|
|
|
return mRenderbufferPtr;
|
2010-12-06 03:34:35 -08:00
|
|
|
}
|
2011-01-05 13:08:53 -08:00
|
|
|
WebGLint TextureLevel() const {
|
|
|
|
return mTextureLevel;
|
|
|
|
}
|
|
|
|
WebGLenum TextureCubeMapFace() const {
|
|
|
|
return mTextureCubeMapFace;
|
|
|
|
}
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasUninitializedRenderbuffer() const {
|
2010-12-06 03:34:35 -08:00
|
|
|
return mRenderbufferPtr && !mRenderbufferPtr->Initialized();
|
|
|
|
}
|
2011-12-04 11:15:43 -08:00
|
|
|
|
|
|
|
void Reset() {
|
|
|
|
mTexturePtr = nsnull;
|
|
|
|
mRenderbufferPtr = nsnull;
|
|
|
|
}
|
2012-01-24 13:12:31 -08:00
|
|
|
|
|
|
|
const WebGLRectangleObject* RectangleObject() const {
|
|
|
|
if (Texture() && Texture()->HasImageInfoAt(mTextureLevel, mTextureCubeMapFace))
|
|
|
|
return &Texture()->ImageInfoAt(mTextureLevel, mTextureCubeMapFace);
|
|
|
|
else if (Renderbuffer())
|
|
|
|
return Renderbuffer();
|
|
|
|
else
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
bool HasSameDimensionsAs(const WebGLFramebufferAttachment& other) const {
|
|
|
|
const WebGLRectangleObject *thisRect = RectangleObject();
|
|
|
|
const WebGLRectangleObject *otherRect = other.RectangleObject();
|
|
|
|
return thisRect &&
|
|
|
|
otherRect &&
|
|
|
|
thisRect->HasSameDimensionsAs(*otherRect);
|
|
|
|
}
|
2012-01-24 13:12:31 -08:00
|
|
|
|
|
|
|
bool IsComplete() const {
|
|
|
|
const WebGLRectangleObject *thisRect = RectangleObject();
|
|
|
|
|
|
|
|
if (!thisRect ||
|
|
|
|
!thisRect->Width() ||
|
|
|
|
!thisRect->Height())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (mTexturePtr)
|
|
|
|
return mAttachmentPoint == LOCAL_GL_COLOR_ATTACHMENT0;
|
|
|
|
|
|
|
|
if (mRenderbufferPtr) {
|
|
|
|
WebGLenum format = mRenderbufferPtr->InternalFormat();
|
|
|
|
switch (mAttachmentPoint) {
|
|
|
|
case LOCAL_GL_COLOR_ATTACHMENT0:
|
|
|
|
return format == LOCAL_GL_RGB565 ||
|
|
|
|
format == LOCAL_GL_RGB5_A1 ||
|
|
|
|
format == LOCAL_GL_RGBA4;
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
|
|
|
return format == LOCAL_GL_DEPTH_COMPONENT16;
|
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
|
|
|
return format == LOCAL_GL_STENCIL_INDEX8;
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
|
|
|
|
return format == LOCAL_GL_DEPTH_STENCIL;
|
|
|
|
default:
|
|
|
|
NS_ABORT(); // should have been validated earlier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT(); // should never get there
|
|
|
|
return false;
|
|
|
|
}
|
2010-12-06 03:34:35 -08:00
|
|
|
};
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
// NOTE: When this class is switched to new DOM bindings, update the
|
|
|
|
// (then-slow) WrapObject call in GetParameter.
|
2012-02-16 05:24:18 -08:00
|
|
|
class WebGLFramebuffer MOZ_FINAL
|
2011-12-04 11:15:42 -08:00
|
|
|
: public nsIWebGLFramebuffer
|
|
|
|
, public WebGLRefCountedObject<WebGLFramebuffer>
|
|
|
|
, public WebGLContextBoundObject
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLFramebuffer(WebGLContext *context)
|
|
|
|
: WebGLContextBoundObject(context)
|
|
|
|
, mHasEverBeenBound(false)
|
|
|
|
, mColorAttachment(LOCAL_GL_COLOR_ATTACHMENT0)
|
|
|
|
, mDepthAttachment(LOCAL_GL_DEPTH_ATTACHMENT)
|
|
|
|
, mStencilAttachment(LOCAL_GL_STENCIL_ATTACHMENT)
|
|
|
|
, mDepthStencilAttachment(LOCAL_GL_DEPTH_STENCIL_ATTACHMENT)
|
|
|
|
{
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fGenFramebuffers(1, &mGLName);
|
2011-12-04 11:15:43 -08:00
|
|
|
mMonotonicHandle = mContext->mFramebuffers.AppendElement(this);
|
2011-12-04 11:15:42 -08:00
|
|
|
}
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
~WebGLFramebuffer() {
|
|
|
|
DeleteOnce();
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
void Delete() {
|
2011-12-04 11:15:42 -08:00
|
|
|
mColorAttachment.Reset();
|
|
|
|
mDepthAttachment.Reset();
|
|
|
|
mStencilAttachment.Reset();
|
|
|
|
mDepthStencilAttachment.Reset();
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDeleteFramebuffers(1, &mGLName);
|
2011-12-04 11:15:43 -08:00
|
|
|
mContext->mFramebuffers.RemoveElement(mMonotonicHandle);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2011-12-04 11:15:42 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasEverBeenBound() { return mHasEverBeenBound; }
|
|
|
|
void SetHasEverBeenBound(bool x) { mHasEverBeenBound = x; }
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLuint GLName() { return mGLName; }
|
2011-12-04 11:15:42 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void FramebufferRenderbuffer(WebGLenum target,
|
|
|
|
WebGLenum attachment,
|
|
|
|
WebGLenum rbtarget,
|
|
|
|
WebGLRenderbuffer *wrb)
|
2010-11-05 12:57:58 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!mContext->ValidateObjectAllowNull("framebufferRenderbuffer: renderbuffer", wrb))
|
2010-11-05 12:57:58 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-11-05 12:57:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (target != LOCAL_GL_FRAMEBUFFER)
|
|
|
|
return mContext->ErrorInvalidEnumInfo("framebufferRenderbuffer: target", target);
|
|
|
|
|
|
|
|
if (rbtarget != LOCAL_GL_RENDERBUFFER)
|
|
|
|
return mContext->ErrorInvalidEnumInfo("framebufferRenderbuffer: renderbuffer target:", rbtarget);
|
|
|
|
|
|
|
|
switch (attachment) {
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
2010-12-06 03:34:35 -08:00
|
|
|
mDepthAttachment.SetRenderbuffer(wrb);
|
2010-11-05 12:57:58 -07:00
|
|
|
break;
|
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
2010-12-06 03:34:35 -08:00
|
|
|
mStencilAttachment.SetRenderbuffer(wrb);
|
2010-11-05 12:57:58 -07:00
|
|
|
break;
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
|
2010-12-06 03:34:35 -08:00
|
|
|
mDepthStencilAttachment.SetRenderbuffer(wrb);
|
2010-11-05 12:57:58 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// finish checking that the 'attachment' parameter is among the allowed values
|
2010-12-06 03:34:35 -08:00
|
|
|
if (attachment != LOCAL_GL_COLOR_ATTACHMENT0)
|
2010-11-05 12:57:58 -07:00
|
|
|
return mContext->ErrorInvalidEnumInfo("framebufferRenderbuffer: attachment", attachment);
|
2011-07-07 17:01:16 -07:00
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
mColorAttachment.SetRenderbuffer(wrb);
|
2010-11-05 12:57:58 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mContext->MakeContextCurrent();
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint renderbuffername = wrb ? wrb->GLName() : 0;
|
2011-01-05 13:08:53 -08:00
|
|
|
if (attachment == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
|
|
|
mContext->gl->fFramebufferRenderbuffer(target, LOCAL_GL_DEPTH_ATTACHMENT, rbtarget, renderbuffername);
|
|
|
|
mContext->gl->fFramebufferRenderbuffer(target, LOCAL_GL_STENCIL_ATTACHMENT, rbtarget, renderbuffername);
|
|
|
|
} else {
|
|
|
|
mContext->gl->fFramebufferRenderbuffer(target, attachment, rbtarget, renderbuffername);
|
|
|
|
}
|
2010-11-05 12:57:58 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void FramebufferTexture2D(WebGLenum target,
|
|
|
|
WebGLenum attachment,
|
|
|
|
WebGLenum textarget,
|
|
|
|
WebGLTexture *wtex,
|
|
|
|
WebGLint level)
|
2010-11-05 12:57:58 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!mContext->ValidateObjectAllowNull("framebufferTexture2D: texture",
|
|
|
|
wtex))
|
2010-11-05 12:57:58 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-11-05 12:57:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (target != LOCAL_GL_FRAMEBUFFER)
|
|
|
|
return mContext->ErrorInvalidEnumInfo("framebufferTexture2D: target", target);
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
if (textarget != LOCAL_GL_TEXTURE_2D &&
|
2010-11-05 12:57:58 -07:00
|
|
|
(textarget < LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
|
2011-07-07 17:01:16 -07:00
|
|
|
textarget > LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))
|
2010-11-05 12:57:58 -07:00
|
|
|
return mContext->ErrorInvalidEnumInfo("framebufferTexture2D: invalid texture target", textarget);
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
if (level != 0)
|
2010-11-05 12:57:58 -07:00
|
|
|
return mContext->ErrorInvalidValue("framebufferTexture2D: level must be 0");
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
size_t face = WebGLTexture::FaceForTarget(textarget);
|
2010-11-05 12:57:58 -07:00
|
|
|
switch (attachment) {
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
2011-01-05 13:08:53 -08:00
|
|
|
mDepthAttachment.SetTexture(wtex, level, face);
|
2010-12-06 03:34:35 -08:00
|
|
|
break;
|
2010-11-05 12:57:58 -07:00
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
2011-01-05 13:08:53 -08:00
|
|
|
mStencilAttachment.SetTexture(wtex, level, face);
|
2010-12-06 03:34:35 -08:00
|
|
|
break;
|
2010-11-05 12:57:58 -07:00
|
|
|
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
|
2011-01-05 13:08:53 -08:00
|
|
|
mDepthStencilAttachment.SetTexture(wtex, level, face);
|
2010-11-05 12:57:58 -07:00
|
|
|
break;
|
|
|
|
default:
|
2010-12-06 03:34:35 -08:00
|
|
|
if (attachment != LOCAL_GL_COLOR_ATTACHMENT0)
|
2010-11-05 12:57:58 -07:00
|
|
|
return mContext->ErrorInvalidEnumInfo("framebufferTexture2D: attachment", attachment);
|
2010-11-16 20:33:03 -08:00
|
|
|
|
2011-01-05 13:08:53 -08:00
|
|
|
mColorAttachment.SetTexture(wtex, level, face);
|
2010-11-05 12:57:58 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mContext->MakeContextCurrent();
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint texturename = wtex ? wtex->GLName() : 0;
|
2011-01-05 13:08:53 -08:00
|
|
|
if (attachment == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
|
|
|
mContext->gl->fFramebufferTexture2D(target, LOCAL_GL_DEPTH_ATTACHMENT, textarget, texturename, level);
|
|
|
|
mContext->gl->fFramebufferTexture2D(target, LOCAL_GL_STENCIL_ATTACHMENT, textarget, texturename, level);
|
|
|
|
} else {
|
|
|
|
mContext->gl->fFramebufferTexture2D(target, attachment, textarget, texturename, level);
|
|
|
|
}
|
2010-11-05 12:57:58 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-11-05 12:57:58 -07:00
|
|
|
}
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
bool HasIncompleteAttachment() const {
|
|
|
|
return (mColorAttachment.IsDefined() && !mColorAttachment.IsComplete()) ||
|
|
|
|
(mDepthAttachment.IsDefined() && !mDepthAttachment.IsComplete()) ||
|
|
|
|
(mStencilAttachment.IsDefined() && !mStencilAttachment.IsComplete()) ||
|
|
|
|
(mDepthStencilAttachment.IsDefined() && !mDepthStencilAttachment.IsComplete());
|
2010-11-05 12:57:58 -07:00
|
|
|
}
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
bool HasDepthStencilConflict() const {
|
|
|
|
return int(mDepthAttachment.IsDefined()) +
|
|
|
|
int(mStencilAttachment.IsDefined()) +
|
|
|
|
int(mDepthStencilAttachment.IsDefined()) >= 2;
|
|
|
|
}
|
2011-12-04 11:15:43 -08:00
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
bool HasAttachmentsOfMismatchedDimensions() const {
|
|
|
|
return (mDepthAttachment.IsDefined() && !mDepthAttachment.HasSameDimensionsAs(mColorAttachment)) ||
|
|
|
|
(mStencilAttachment.IsDefined() && !mStencilAttachment.HasSameDimensionsAs(mColorAttachment)) ||
|
|
|
|
(mDepthStencilAttachment.IsDefined() && !mDepthStencilAttachment.HasSameDimensionsAs(mColorAttachment));
|
2010-11-05 12:57:58 -07:00
|
|
|
}
|
|
|
|
|
2011-01-05 13:08:53 -08:00
|
|
|
const WebGLFramebufferAttachment& ColorAttachment() const {
|
|
|
|
return mColorAttachment;
|
|
|
|
}
|
|
|
|
|
|
|
|
const WebGLFramebufferAttachment& DepthAttachment() const {
|
|
|
|
return mDepthAttachment;
|
|
|
|
}
|
|
|
|
|
|
|
|
const WebGLFramebufferAttachment& StencilAttachment() const {
|
|
|
|
return mStencilAttachment;
|
|
|
|
}
|
|
|
|
|
|
|
|
const WebGLFramebufferAttachment& DepthStencilAttachment() const {
|
|
|
|
return mDepthStencilAttachment;
|
|
|
|
}
|
|
|
|
|
|
|
|
const WebGLFramebufferAttachment& GetAttachment(WebGLenum attachment) const {
|
|
|
|
if (attachment == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT)
|
|
|
|
return mDepthStencilAttachment;
|
|
|
|
if (attachment == LOCAL_GL_DEPTH_ATTACHMENT)
|
|
|
|
return mDepthAttachment;
|
|
|
|
if (attachment == LOCAL_GL_STENCIL_ATTACHMENT)
|
|
|
|
return mStencilAttachment;
|
|
|
|
|
|
|
|
NS_ASSERTION(attachment == LOCAL_GL_COLOR_ATTACHMENT0, "bad attachment!");
|
2010-12-06 03:34:35 -08:00
|
|
|
return mColorAttachment;
|
2010-11-16 20:33:03 -08:00
|
|
|
}
|
|
|
|
|
2011-12-04 11:15:43 -08:00
|
|
|
void DetachTexture(const WebGLTexture *tex) {
|
|
|
|
if (mColorAttachment.Texture() == tex)
|
|
|
|
FramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0, LOCAL_GL_TEXTURE_2D, nsnull, 0);
|
|
|
|
if (mDepthAttachment.Texture() == tex)
|
|
|
|
FramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_DEPTH_ATTACHMENT, LOCAL_GL_TEXTURE_2D, nsnull, 0);
|
|
|
|
if (mStencilAttachment.Texture() == tex)
|
|
|
|
FramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_STENCIL_ATTACHMENT, LOCAL_GL_TEXTURE_2D, nsnull, 0);
|
|
|
|
if (mDepthStencilAttachment.Texture() == tex)
|
|
|
|
FramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_DEPTH_STENCIL_ATTACHMENT, LOCAL_GL_TEXTURE_2D, nsnull, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DetachRenderbuffer(const WebGLRenderbuffer *rb) {
|
|
|
|
if (mColorAttachment.Renderbuffer() == rb)
|
|
|
|
FramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0, LOCAL_GL_RENDERBUFFER, nsnull);
|
|
|
|
if (mDepthAttachment.Renderbuffer() == rb)
|
|
|
|
FramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_DEPTH_ATTACHMENT, LOCAL_GL_RENDERBUFFER, nsnull);
|
|
|
|
if (mStencilAttachment.Renderbuffer() == rb)
|
|
|
|
FramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_STENCIL_ATTACHMENT, LOCAL_GL_RENDERBUFFER, nsnull);
|
|
|
|
if (mDepthStencilAttachment.Renderbuffer() == rb)
|
|
|
|
FramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_DEPTH_STENCIL_ATTACHMENT, LOCAL_GL_RENDERBUFFER, nsnull);
|
|
|
|
}
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
const WebGLRectangleObject *RectangleObject() {
|
|
|
|
return mColorAttachment.RectangleObject();
|
|
|
|
}
|
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBGLFRAMEBUFFER
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
bool CheckAndInitializeRenderbuffers()
|
2010-11-05 12:57:58 -07:00
|
|
|
{
|
2012-01-24 13:12:31 -08:00
|
|
|
// enforce WebGL section 6.5 which is WebGL-specific, hence OpenGL itself would not
|
|
|
|
// generate the INVALID_FRAMEBUFFER_OPERATION that we need here
|
|
|
|
if (HasDepthStencilConflict())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!mColorAttachment.HasUninitializedRenderbuffer() &&
|
|
|
|
!mDepthAttachment.HasUninitializedRenderbuffer() &&
|
|
|
|
!mStencilAttachment.HasUninitializedRenderbuffer() &&
|
|
|
|
!mDepthStencilAttachment.HasUninitializedRenderbuffer())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// ensure INVALID_FRAMEBUFFER_OPERATION in zero-size case
|
|
|
|
const WebGLRectangleObject *rect = mColorAttachment.RectangleObject();
|
|
|
|
if (!rect ||
|
|
|
|
!rect->Width() ||
|
|
|
|
!rect->Height())
|
|
|
|
return false;
|
|
|
|
|
2010-11-05 12:57:58 -07:00
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
WebGLenum status;
|
|
|
|
mContext->CheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER, &status);
|
|
|
|
if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE)
|
|
|
|
return false;
|
2010-11-05 12:57:58 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
PRUint32 mask = 0;
|
2010-11-05 12:57:58 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (mColorAttachment.HasUninitializedRenderbuffer())
|
|
|
|
mask |= LOCAL_GL_COLOR_BUFFER_BIT;
|
2010-11-05 12:57:58 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (mDepthAttachment.HasUninitializedRenderbuffer() ||
|
|
|
|
mDepthStencilAttachment.HasUninitializedRenderbuffer())
|
|
|
|
{
|
|
|
|
mask |= LOCAL_GL_DEPTH_BUFFER_BIT;
|
2010-11-05 12:57:58 -07:00
|
|
|
}
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (mStencilAttachment.HasUninitializedRenderbuffer() ||
|
|
|
|
mDepthStencilAttachment.HasUninitializedRenderbuffer())
|
|
|
|
{
|
|
|
|
mask |= LOCAL_GL_STENCIL_BUFFER_BIT;
|
2010-11-05 12:57:58 -07:00
|
|
|
}
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
mContext->ForceClearFramebufferWithDefaultValues(mask, nsIntRect(0, 0, rect->Width(), rect->Height()));
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (mColorAttachment.HasUninitializedRenderbuffer())
|
2011-10-17 07:59:28 -07:00
|
|
|
mColorAttachment.Renderbuffer()->SetInitialized(true);
|
2010-11-05 12:57:58 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (mDepthAttachment.HasUninitializedRenderbuffer())
|
2011-10-17 07:59:28 -07:00
|
|
|
mDepthAttachment.Renderbuffer()->SetInitialized(true);
|
2010-11-05 12:57:58 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (mStencilAttachment.HasUninitializedRenderbuffer())
|
2011-10-17 07:59:28 -07:00
|
|
|
mStencilAttachment.Renderbuffer()->SetInitialized(true);
|
2010-11-05 12:57:58 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (mDepthStencilAttachment.HasUninitializedRenderbuffer())
|
2011-10-17 07:59:28 -07:00
|
|
|
mDepthStencilAttachment.Renderbuffer()->SetInitialized(true);
|
2012-01-24 13:12:31 -08:00
|
|
|
|
|
|
|
return true;
|
2010-11-05 12:57:58 -07:00
|
|
|
}
|
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
WebGLuint mGLName;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHasEverBeenBound;
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2010-11-05 12:57:58 -07:00
|
|
|
// we only store pointers to attached renderbuffers, not to attached textures, because
|
|
|
|
// we will only need to initialize renderbuffers. Textures are already initialized.
|
2010-12-06 03:34:35 -08:00
|
|
|
WebGLFramebufferAttachment mColorAttachment,
|
|
|
|
mDepthAttachment,
|
|
|
|
mStencilAttachment,
|
|
|
|
mDepthStencilAttachment;
|
2011-12-04 11:15:43 -08:00
|
|
|
|
|
|
|
WebGLMonotonicHandle mMonotonicHandle;
|
2009-09-02 17:47:49 -07:00
|
|
|
};
|
|
|
|
|
2012-02-16 05:24:18 -08:00
|
|
|
class WebGLUniformLocation MOZ_FINAL
|
2011-12-04 11:15:42 -08:00
|
|
|
: public nsIWebGLUniformLocation
|
|
|
|
, public WebGLContextBoundObject
|
2011-12-04 11:15:43 -08:00
|
|
|
, public WebGLRefCountedObject<WebGLUniformLocation>
|
2010-06-01 23:09:19 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-04-16 12:56:12 -07:00
|
|
|
WebGLUniformLocation(WebGLContext *context, WebGLProgram *program, GLint location, const WebGLUniformInfo& info)
|
2011-12-04 11:15:42 -08:00
|
|
|
: WebGLContextBoundObject(context)
|
|
|
|
, mProgram(program)
|
|
|
|
, mProgramGeneration(program->Generation())
|
|
|
|
, mLocation(location)
|
2012-04-16 12:56:12 -07:00
|
|
|
, mInfo(info)
|
2011-12-04 11:15:43 -08:00
|
|
|
{
|
2012-04-16 12:56:12 -07:00
|
|
|
mElementSize = info.ElementSize();
|
2011-12-04 11:15:43 -08:00
|
|
|
mMonotonicHandle = mContext->mUniformLocations.AppendElement(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~WebGLUniformLocation() {
|
|
|
|
DeleteOnce();
|
|
|
|
}
|
2010-06-01 23:09:19 -07:00
|
|
|
|
2011-12-04 11:15:43 -08:00
|
|
|
void Delete() {
|
|
|
|
mProgram = nsnull;
|
|
|
|
mContext->mUniformLocations.RemoveElement(mMonotonicHandle);
|
|
|
|
}
|
2010-06-01 23:09:19 -07:00
|
|
|
|
2012-04-16 12:56:12 -07:00
|
|
|
const WebGLUniformInfo &Info() const { return mInfo; }
|
|
|
|
|
2010-06-01 23:09:19 -07:00
|
|
|
WebGLProgram *Program() const { return mProgram; }
|
|
|
|
GLint Location() const { return mLocation; }
|
2010-07-03 15:32:19 -07:00
|
|
|
PRUint32 ProgramGeneration() const { return mProgramGeneration; }
|
2012-04-16 12:56:12 -07:00
|
|
|
int ElementSize() const { return mElementSize; }
|
2010-06-01 23:09:19 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBGLUNIFORMLOCATION
|
|
|
|
protected:
|
2011-12-04 11:15:43 -08:00
|
|
|
// nsRefPtr, not WebGLRefPtr, so that we don't prevent the program from being explicitly deleted.
|
|
|
|
// we just want to avoid having a dangling pointer.
|
|
|
|
nsRefPtr<WebGLProgram> mProgram;
|
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
PRUint32 mProgramGeneration;
|
2010-06-01 23:09:19 -07:00
|
|
|
GLint mLocation;
|
2012-04-16 12:56:12 -07:00
|
|
|
WebGLUniformInfo mInfo;
|
|
|
|
int mElementSize;
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLMonotonicHandle mMonotonicHandle;
|
2011-12-04 11:15:42 -08:00
|
|
|
friend class WebGLProgram;
|
2010-06-01 23:09:19 -07:00
|
|
|
};
|
|
|
|
|
2012-02-16 05:24:18 -08:00
|
|
|
class WebGLActiveInfo MOZ_FINAL
|
2011-12-04 11:15:42 -08:00
|
|
|
: public nsIWebGLActiveInfo
|
2010-08-23 14:03:49 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-03-02 12:42:49 -08:00
|
|
|
WebGLActiveInfo(WebGLint size, WebGLenum type, const nsACString& name) :
|
2010-08-23 14:03:49 -07:00
|
|
|
mSize(size),
|
2012-03-02 12:42:49 -08:00
|
|
|
mType(type),
|
|
|
|
mName(NS_ConvertASCIItoUTF16(name))
|
|
|
|
{}
|
2010-08-23 14:03:49 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBGLACTIVEINFO
|
|
|
|
protected:
|
|
|
|
WebGLint mSize;
|
|
|
|
WebGLenum mType;
|
|
|
|
nsString mName;
|
|
|
|
};
|
|
|
|
|
2012-02-16 05:24:18 -08:00
|
|
|
class WebGLShaderPrecisionFormat MOZ_FINAL
|
2011-12-16 13:11:59 -08:00
|
|
|
: public nsIWebGLShaderPrecisionFormat
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebGLShaderPrecisionFormat(WebGLint rangeMin, WebGLint rangeMax, WebGLint precision) :
|
|
|
|
mRangeMin(rangeMin),
|
|
|
|
mRangeMax(rangeMax),
|
|
|
|
mPrecision(precision)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBGLSHADERPRECISIONFORMAT
|
|
|
|
|
|
|
|
protected:
|
|
|
|
WebGLint mRangeMin;
|
|
|
|
WebGLint mRangeMax;
|
|
|
|
WebGLint mPrecision;
|
|
|
|
};
|
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
class WebGLExtension
|
|
|
|
: public nsIWebGLExtension
|
|
|
|
, public WebGLContextBoundObject
|
2012-03-26 11:59:04 -07:00
|
|
|
, public nsWrapperCache
|
2011-05-20 12:53:53 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebGLExtension(WebGLContext *baseContext)
|
2011-05-20 12:53:53 -07:00
|
|
|
: WebGLContextBoundObject(baseContext)
|
|
|
|
{}
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2012-03-26 11:59:04 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WebGLExtension)
|
2011-05-20 12:53:53 -07:00
|
|
|
NS_DECL_NSIWEBGLEXTENSION
|
2012-03-26 11:59:04 -07:00
|
|
|
|
2012-02-15 04:26:14 -08:00
|
|
|
virtual ~WebGLExtension() {}
|
2011-05-20 12:53:53 -07:00
|
|
|
};
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
inline const WebGLRectangleObject *WebGLContext::FramebufferRectangleObject() const {
|
|
|
|
return mBoundFramebuffer ? mBoundFramebuffer->RectangleObject()
|
|
|
|
: static_cast<const WebGLRectangleObject*>(this);
|
|
|
|
}
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
/**
|
|
|
|
** Template implementations
|
|
|
|
**/
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
template<class ObjectType>
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::ValidateObjectAllowDeletedOrNull(const char* info,
|
|
|
|
ObjectType *aObject)
|
2010-06-04 12:03:37 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
if (aObject && !aObject->IsCompatibleWithContext(this)) {
|
|
|
|
ErrorInvalidOperation("%s: object from different WebGL context "
|
|
|
|
"(or older generation of this one) "
|
|
|
|
"passed as argument", info);
|
|
|
|
return false;
|
2010-06-04 12:03:37 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return true;
|
|
|
|
}
|
2010-06-04 12:03:37 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
template<class ObjectType>
|
|
|
|
inline bool
|
|
|
|
WebGLContext::ValidateObjectAssumeNonNull(const char* info, ObjectType *aObject)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aObject);
|
2010-06-04 12:03:37 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull(info, aObject))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-04 12:03:37 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (aObject->IsDeleted()) {
|
|
|
|
ErrorInvalidValue("%s: deleted object passed as argument", info);
|
|
|
|
return false;
|
2010-06-04 12:03:37 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-04 12:03:37 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
template<class ObjectType>
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::ValidateObjectAllowNull(const char* info, ObjectType *aObject)
|
2010-06-04 12:03:37 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!aObject) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ValidateObjectAssumeNonNull(info, aObject);
|
2010-06-04 12:03:37 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
template<class ObjectType>
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::ValidateObjectAllowDeleted(const char* info, ObjectType *aObject)
|
2010-06-04 12:03:37 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!aObject) {
|
|
|
|
ErrorInvalidValue("%s: null object passed as argument", info);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ValidateObjectAllowDeletedOrNull(info, aObject);
|
2010-06-04 12:03:37 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
template<class ObjectType>
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::ValidateObject(const char* info, ObjectType *aObject)
|
2010-06-04 12:03:37 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!aObject) {
|
|
|
|
ErrorInvalidValue("%s: null object passed as argument", info);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ValidateObjectAssumeNonNull(info, aObject);
|
2010-06-04 12:03:37 -07:00
|
|
|
}
|
|
|
|
|
2012-02-19 19:58:08 -08:00
|
|
|
class WebGLMemoryMultiReporterWrapper
|
2011-07-07 17:01:12 -07:00
|
|
|
{
|
2012-02-19 19:58:08 -08:00
|
|
|
WebGLMemoryMultiReporterWrapper();
|
|
|
|
~WebGLMemoryMultiReporterWrapper();
|
|
|
|
static WebGLMemoryMultiReporterWrapper* sUniqueInstance;
|
2011-07-07 17:01:12 -07:00
|
|
|
|
2012-02-19 19:58:08 -08:00
|
|
|
// here we store plain pointers, not RefPtrs: we don't want the
|
|
|
|
// WebGLMemoryMultiReporterWrapper unique instance to keep alive all
|
2011-07-07 17:01:12 -07:00
|
|
|
// WebGLContexts ever created.
|
|
|
|
typedef nsTArray<const WebGLContext*> ContextsArrayType;
|
|
|
|
ContextsArrayType mContexts;
|
|
|
|
|
2012-02-19 19:58:08 -08:00
|
|
|
nsCOMPtr<nsIMemoryMultiReporter> mReporter;
|
|
|
|
|
|
|
|
static WebGLMemoryMultiReporterWrapper* UniqueInstance();
|
2011-07-07 17:01:12 -07:00
|
|
|
|
|
|
|
static ContextsArrayType & Contexts() { return UniqueInstance()->mContexts; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
static void AddWebGLContext(const WebGLContext* c) {
|
|
|
|
Contexts().AppendElement(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RemoveWebGLContext(const WebGLContext* c) {
|
|
|
|
ContextsArrayType & contexts = Contexts();
|
|
|
|
contexts.RemoveElement(c);
|
|
|
|
if (contexts.IsEmpty()) {
|
2012-02-19 19:58:08 -08:00
|
|
|
delete sUniqueInstance;
|
2011-07-07 17:01:12 -07:00
|
|
|
sUniqueInstance = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRInt64 GetTextureMemoryUsed() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
PRInt64 result = 0;
|
2011-12-04 11:15:43 -08:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i)
|
2012-02-19 19:58:08 -08:00
|
|
|
for (size_t j = 0; j < contexts[i]->mTextures.Length(); ++j)
|
|
|
|
result += contexts[i]->mTextures[j]->MemoryUsage();
|
2011-07-07 17:01:12 -07:00
|
|
|
return result;
|
|
|
|
}
|
2011-12-04 11:15:43 -08:00
|
|
|
|
2011-07-07 17:01:12 -07:00
|
|
|
static PRInt64 GetTextureCount() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
PRInt64 result = 0;
|
2011-12-04 11:15:43 -08:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i)
|
|
|
|
result += contexts[i]->mTextures.Length();
|
2011-07-07 17:01:12 -07:00
|
|
|
return result;
|
|
|
|
}
|
2011-12-04 11:15:43 -08:00
|
|
|
|
2011-07-07 17:01:15 -07:00
|
|
|
static PRInt64 GetBufferMemoryUsed() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
PRInt64 result = 0;
|
2011-12-04 11:15:43 -08:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i)
|
2012-02-19 19:58:08 -08:00
|
|
|
for (size_t j = 0; j < contexts[i]->mBuffers.Length(); ++j)
|
|
|
|
result += contexts[i]->mBuffers[j]->ByteLength();
|
2011-07-07 17:01:15 -07:00
|
|
|
return result;
|
|
|
|
}
|
2011-07-07 17:01:16 -07:00
|
|
|
|
2012-02-19 19:58:08 -08:00
|
|
|
static PRInt64 GetBufferCacheMemoryUsed();
|
2011-07-07 17:01:16 -07:00
|
|
|
|
2011-07-07 17:01:15 -07:00
|
|
|
static PRInt64 GetBufferCount() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
PRInt64 result = 0;
|
2011-12-04 11:15:43 -08:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i)
|
|
|
|
result += contexts[i]->mBuffers.Length();
|
2011-07-07 17:01:15 -07:00
|
|
|
return result;
|
|
|
|
}
|
2011-12-04 11:15:43 -08:00
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
static PRInt64 GetRenderbufferMemoryUsed() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
PRInt64 result = 0;
|
2011-12-04 11:15:43 -08:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i)
|
2012-02-19 19:58:08 -08:00
|
|
|
for (size_t j = 0; j < contexts[i]->mRenderbuffers.Length(); ++j)
|
|
|
|
result += contexts[i]->mRenderbuffers[j]->MemoryUsage();
|
2011-07-07 17:01:16 -07:00
|
|
|
return result;
|
|
|
|
}
|
2011-12-04 11:15:43 -08:00
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
static PRInt64 GetRenderbufferCount() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
PRInt64 result = 0;
|
2011-12-04 11:15:43 -08:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i)
|
|
|
|
result += contexts[i]->mRenderbuffers.Length();
|
2011-07-07 17:01:16 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-02-19 19:58:08 -08:00
|
|
|
static PRInt64 GetShaderSize();
|
2011-12-04 11:15:43 -08:00
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
static PRInt64 GetShaderCount() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
PRInt64 result = 0;
|
2011-12-04 11:15:43 -08:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i)
|
|
|
|
result += contexts[i]->mShaders.Length();
|
2011-07-07 17:01:16 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-07-07 17:01:12 -07:00
|
|
|
static PRInt64 GetContextCount() {
|
|
|
|
return Contexts().Length();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-21 13:48:22 -07:00
|
|
|
class WebGLMemoryPressureObserver MOZ_FINAL
|
|
|
|
: public nsIObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
WebGLMemoryPressureObserver(WebGLContext *context)
|
|
|
|
: mContext(context)
|
|
|
|
{}
|
|
|
|
|
|
|
|
private:
|
|
|
|
WebGLContext *mContext;
|
|
|
|
};
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|