2012-03-16 02:50:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
#ifndef WEBGLCONTEXT_H_
|
|
|
|
#define WEBGLCONTEXT_H_
|
|
|
|
|
2012-11-20 13:38:20 -08:00
|
|
|
#include "WebGLElementArrayCache.h"
|
|
|
|
#include "WebGLObjectModel.h"
|
2012-12-03 05:10:23 -08:00
|
|
|
#include "WebGLShader.h"
|
2012-11-20 13:38:20 -08:00
|
|
|
#include "WebGLBuffer.h"
|
2012-12-08 12:41:02 -08:00
|
|
|
#include "WebGLProgram.h"
|
2012-12-08 15:02:29 -08:00
|
|
|
#include "WebGLUniformLocation.h"
|
2012-12-09 03:58:41 -08:00
|
|
|
#include "WebGLFramebuffer.h"
|
2012-12-03 10:27:25 -08:00
|
|
|
#include "WebGLRenderbuffer.h"
|
2012-12-03 16:13:47 -08:00
|
|
|
#include "WebGLTexture.h"
|
2012-11-28 22:04:26 -08:00
|
|
|
#include "WebGLVertexAttribData.h"
|
2012-12-02 02:28:21 -08:00
|
|
|
#include "WebGLShaderPrecisionFormat.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2012-11-14 23:32:39 -08:00
|
|
|
#include "nsCycleCollectionNoteChild.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
#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"
|
2013-01-03 21:16:14 -08:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
#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"
|
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-01-22 18:29:49 -08:00
|
|
|
|
2012-05-29 11:44:31 -07:00
|
|
|
#include "mozilla/LinkedList.h"
|
2012-05-14 12:50:20 -07:00
|
|
|
#include "mozilla/CheckedInt.h"
|
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-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-24 22:08:22 -07:00
|
|
|
#include "mozilla/dom/BindingUtils.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
|
|
|
|
|
2010-11-16 20:33:03 -08:00
|
|
|
class nsIPropertyBag;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-04-21 13:48:22 -07:00
|
|
|
class WebGLMemoryPressureObserver;
|
2010-06-10 10:45:00 -07:00
|
|
|
class WebGLContextBoundObject;
|
2012-05-04 09:38:44 -07:00
|
|
|
class WebGLActiveInfo;
|
2012-10-03 14:13:05 -07:00
|
|
|
class WebGLExtensionBase;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-10-22 10:08:52 -07:00
|
|
|
namespace dom {
|
|
|
|
struct WebGLContextAttributes;
|
2012-11-30 15:30:05 -08:00
|
|
|
struct WebGLContextAttributesInitializer;
|
2012-10-22 10:08:52 -07:00
|
|
|
}
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
struct VertexAttrib0Status {
|
|
|
|
enum { Default, EmulatedUninitializedArray, EmulatedInitializedArray };
|
|
|
|
};
|
|
|
|
|
2012-05-07 10:05:32 -07:00
|
|
|
namespace WebGLTexelConversions {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The formats that may participate, either as source or destination formats,
|
|
|
|
* in WebGL texture conversions. This includes:
|
|
|
|
* - all the formats accepted by WebGL.texImage2D, e.g. RGBA4444
|
|
|
|
* - additional formats provided by extensions, e.g. RGB32F
|
|
|
|
* - additional source formats, depending on browser details, used when uploading
|
|
|
|
* textures from DOM elements. See gfxImageSurface::Format().
|
|
|
|
*/
|
|
|
|
enum WebGLTexelFormat
|
|
|
|
{
|
|
|
|
// dummy error code returned by GetWebGLTexelFormat in error cases,
|
|
|
|
// after assertion failure (so this never happens in debug builds)
|
|
|
|
BadFormat,
|
|
|
|
// dummy pseudo-format meaning "use the other format".
|
|
|
|
// For example, if SrcFormat=Auto and DstFormat=RGB8, then the source
|
|
|
|
// is implicitly treated as being RGB8 itself.
|
|
|
|
Auto,
|
|
|
|
// 1-channel formats
|
|
|
|
R8,
|
|
|
|
A8,
|
2012-08-13 18:17:55 -07:00
|
|
|
D16, // used for WEBGL_depth_texture extension
|
|
|
|
D32, // used for WEBGL_depth_texture extension
|
2012-05-07 10:05:32 -07:00
|
|
|
R32F, // used for OES_texture_float extension
|
|
|
|
A32F, // used for OES_texture_float extension
|
|
|
|
// 2-channel formats
|
|
|
|
RA8,
|
|
|
|
RA32F,
|
2012-08-13 18:17:55 -07:00
|
|
|
D24S8, // used for WEBGL_depth_texture extension
|
2012-05-07 10:05:32 -07:00
|
|
|
// 3-channel formats
|
|
|
|
RGB8,
|
|
|
|
BGRX8, // used for DOM elements. Source format only.
|
|
|
|
RGB565,
|
|
|
|
RGB32F, // used for OES_texture_float extension
|
|
|
|
// 4-channel formats
|
|
|
|
RGBA8,
|
|
|
|
BGRA8, // used for DOM elements
|
|
|
|
RGBA5551,
|
|
|
|
RGBA4444,
|
|
|
|
RGBA32F // used for OES_texture_float extension
|
2010-10-15 14:50:15 -07:00
|
|
|
};
|
|
|
|
|
2012-05-07 10:05:32 -07:00
|
|
|
} // end namespace WebGLTexelConversions
|
|
|
|
|
|
|
|
using WebGLTexelConversions::WebGLTexelFormat;
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelFormat GetWebGLTexelFormat(GLenum format, GLenum type);
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2010-11-16 20:33:03 -08:00
|
|
|
struct WebGLContextOptions {
|
|
|
|
// these are defaults
|
2012-08-01 11:58:44 -07:00
|
|
|
WebGLContextOptions();
|
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-05-04 09:36:40 -07:00
|
|
|
public WebGLRectangleObject,
|
|
|
|
public nsWrapperCache
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-09-25 05:49:28 -07:00
|
|
|
friend class WebGLContextUserData;
|
|
|
|
friend class WebGLMemoryPressureObserver;
|
2012-02-19 19:58:08 -08:00
|
|
|
friend class WebGLMemoryMultiReporterWrapper;
|
2011-10-26 13:00:44 -07:00
|
|
|
friend class WebGLExtensionLoseContext;
|
2012-05-08 10:29:31 -07:00
|
|
|
friend class WebGLExtensionCompressedTextureS3TC;
|
2012-09-25 05:49:28 -07:00
|
|
|
friend class WebGLExtensionCompressedTextureATC;
|
2012-09-25 05:49:28 -07:00
|
|
|
friend class WebGLExtensionCompressedTexturePVRTC;
|
2012-08-13 18:17:55 -07:00
|
|
|
friend class WebGLExtensionDepthTexture;
|
2011-07-07 17:01:12 -07:00
|
|
|
|
2012-09-20 00:55:36 -07:00
|
|
|
enum {
|
|
|
|
UNPACK_FLIP_Y_WEBGL = 0x9240,
|
|
|
|
UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241,
|
|
|
|
CONTEXT_LOST_WEBGL = 0x9242,
|
|
|
|
UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
|
2012-10-17 12:11:51 -07:00
|
|
|
BROWSER_DEFAULT_WEBGL = 0x9244,
|
|
|
|
UNMASKED_VENDOR_WEBGL = 0x9245,
|
|
|
|
UNMASKED_RENDERER_WEBGL = 0x9246
|
2012-09-20 00:55:36 -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)
|
|
|
|
|
2013-04-25 09:29:54 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx,
|
|
|
|
JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
|
2012-05-31 11:16:48 -07:00
|
|
|
|
2010-11-16 20:33:04 -08:00
|
|
|
NS_DECL_NSIDOMWEBGLRENDERINGCONTEXT
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
// nsICanvasRenderingContextInternal
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD SetDimensions(int32_t width, int32_t height);
|
|
|
|
NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height)
|
2009-09-02 17:47:49 -07:00
|
|
|
{ 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,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t 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()
|
2012-07-30 07:20:58 -07:00
|
|
|
{ return nullptr; }
|
2011-06-24 10:41:18 -07:00
|
|
|
|
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,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t x, int32_t y, int32_t w, int32_t h)
|
2010-03-24 03:47:18 -07:00
|
|
|
{ return NS_ERROR_NOT_IMPLEMENTED; }
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD Swap(uint32_t nativeID,
|
|
|
|
int32_t x, int32_t y, int32_t w, int32_t h)
|
2010-06-04 06:58:22 -07:00
|
|
|
{ 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, ...);
|
2012-05-23 09:07:01 -07:00
|
|
|
void ErrorInvalidEnumInfo(const char *info, WebGLenum 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);
|
2013-02-13 15:26:24 -08:00
|
|
|
|
|
|
|
// Note that 'clean' here refers to its invalidation state, not the
|
|
|
|
// contents of the buffer.
|
2011-10-17 07:59:28 -07:00
|
|
|
void MarkContextClean() { mInvalidated = false; }
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
gl::GLContext* GL() const {
|
|
|
|
return gl;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsPremultAlpha() const {
|
|
|
|
return mOptions.premultipliedAlpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PresentScreenBuffer();
|
|
|
|
|
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.
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t Generation() { return mGeneration.value(); }
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
const WebGLRectangleObject *FramebufferRectangleObject() const;
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// This is similar to GLContext::ClearSafely, but tries to minimize the
|
|
|
|
// amount of work it does.
|
|
|
|
// It only clears the buffers we specify, and can reset its state without
|
|
|
|
// first having to query anything, as WebGL knows its state at all times.
|
|
|
|
void ForceClearFramebufferWithDefaultValues(GLbitfield mask);
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// Calls ForceClearFramebufferWithDefaultValues() for the Context's 'screen'.
|
|
|
|
void ClearScreen();
|
2011-05-20 12:53:53 -07:00
|
|
|
|
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-10-23 09:21:23 -07:00
|
|
|
void RobustnessTimerCallback(nsITimer* timer);
|
|
|
|
|
|
|
|
static void RobustnessTimerCallbackStatic(nsITimer* timer, void *thisPointer) {
|
|
|
|
static_cast<WebGLContext*>(thisPointer)->RobustnessTimerCallback(timer);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2012-10-23 09:21:23 -07:00
|
|
|
|
|
|
|
mContextRestorer->InitWithFuncCallback(RobustnessTimerCallbackStatic,
|
|
|
|
static_cast<void*>(this),
|
2012-10-24 12:46:31 -07:00
|
|
|
1000,
|
2012-10-23 09:21:23 -07:00
|
|
|
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
|
2013-01-03 21:16:14 -08:00
|
|
|
dom::HTMLCanvasElement* GetCanvas() const {
|
2012-06-06 00:42:47 -07:00
|
|
|
return mCanvasElement;
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-09-11 12:08:24 -07:00
|
|
|
WebGLsizei DrawingBufferWidth() const {
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!IsContextStable())
|
|
|
|
return 0;
|
|
|
|
return mWidth;
|
|
|
|
}
|
2012-09-11 12:08:24 -07:00
|
|
|
WebGLsizei DrawingBufferHeight() const {
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!IsContextStable())
|
|
|
|
return 0;
|
|
|
|
return mHeight;
|
|
|
|
}
|
|
|
|
|
2012-11-30 15:30:05 -08:00
|
|
|
void GetContextAttributes(dom::Nullable<dom::WebGLContextAttributesInitializer>& retval);
|
2012-05-04 09:38:44 -07:00
|
|
|
bool IsContextLost() const { return !IsContextStable(); }
|
2012-10-17 12:11:51 -07:00
|
|
|
void GetSupportedExtensions(JSContext *cx, dom::Nullable< nsTArray<nsString> > &retval);
|
|
|
|
JSObject* GetExtension(JSContext* cx, const nsAString& aName, ErrorResult& rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
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-31 11:16:48 -07:00
|
|
|
JS::Value GetBufferParameter(JSContext* /* unused */, WebGLenum target,
|
|
|
|
WebGLenum pname) {
|
|
|
|
return GetBufferParameter(target, 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-31 11:16:48 -07:00
|
|
|
JS::Value GetProgramParameter(JSContext* /* unused */, WebGLProgram *prog,
|
|
|
|
WebGLenum pname) {
|
|
|
|
return GetProgramParameter(prog, pname);
|
|
|
|
}
|
2012-09-17 01:37:20 -07:00
|
|
|
void GetProgramInfoLog(WebGLProgram *prog, nsACString& retval);
|
|
|
|
void GetProgramInfoLog(WebGLProgram *prog, nsAString& retval);
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value GetRenderbufferParameter(WebGLenum target, WebGLenum pname);
|
2012-05-31 11:16:48 -07:00
|
|
|
JS::Value GetRenderbufferParameter(JSContext* /* unused */,
|
|
|
|
WebGLenum target, WebGLenum pname) {
|
|
|
|
return GetRenderbufferParameter(target, pname);
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value GetShaderParameter(WebGLShader *shader, WebGLenum pname);
|
2012-05-31 11:16:48 -07:00
|
|
|
JS::Value GetShaderParameter(JSContext* /* unused */, WebGLShader *shader,
|
|
|
|
WebGLenum pname) {
|
|
|
|
return GetShaderParameter(shader, pname);
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLShaderPrecisionFormat>
|
|
|
|
GetShaderPrecisionFormat(WebGLenum shadertype, WebGLenum precisiontype);
|
2012-09-17 01:37:20 -07:00
|
|
|
void GetShaderInfoLog(WebGLShader *shader, nsACString& retval);
|
|
|
|
void GetShaderInfoLog(WebGLShader *shader, nsAString& retval);
|
2012-05-04 09:38:44 -07:00
|
|
|
void GetShaderSource(WebGLShader *shader, nsAString& retval);
|
|
|
|
JS::Value GetTexParameter(WebGLenum target, WebGLenum pname);
|
2012-05-31 11:16:48 -07:00
|
|
|
JS::Value GetTexParameter(JSContext * /* unused */, WebGLenum target,
|
|
|
|
WebGLenum pname) {
|
|
|
|
return GetTexParameter(target, pname);
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
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-09-17 01:37:20 -07:00
|
|
|
void LinkProgram(WebGLProgram *program);
|
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);
|
2012-11-15 11:54:34 -08:00
|
|
|
void TexImage2D(WebGLenum target, WebGLint level,
|
2012-05-04 09:38:44 -07:00
|
|
|
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-11-15 11:54:34 -08:00
|
|
|
void TexImage2D(WebGLenum target, WebGLint level,
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLenum internalformat, WebGLenum format, WebGLenum type,
|
2012-05-05 18:15:11 -07:00
|
|
|
dom::ImageData* pixels, ErrorResult& rv);
|
2012-05-31 11:16:48 -07:00
|
|
|
// Allow whatever element types the bindings are willing to pass
|
|
|
|
// us in TexImage2D
|
|
|
|
template<class ElementType>
|
2012-11-15 11:54:34 -08:00
|
|
|
void TexImage2D(WebGLenum target, WebGLint level,
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLenum internalformat, WebGLenum format, WebGLenum type,
|
2012-12-31 10:48:55 -08:00
|
|
|
const ElementType& elt, ErrorResult& rv) {
|
2012-05-31 11:16:48 -07:00
|
|
|
if (!IsContextStable())
|
|
|
|
return;
|
|
|
|
nsRefPtr<gfxImageSurface> isurf;
|
|
|
|
WebGLTexelFormat srcFormat;
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult res = SurfaceFromElement(elt);
|
|
|
|
rv = SurfaceFromElementResultToImageSurface(res, getter_AddRefs(isurf),
|
|
|
|
&srcFormat);
|
|
|
|
if (rv.Failed())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint32_t byteLength = isurf->Stride() * isurf->Height();
|
|
|
|
return TexImage2D_base(target, level, internalformat,
|
|
|
|
isurf->Width(), isurf->Height(), isurf->Stride(),
|
|
|
|
0, format, type, isurf->Data(), byteLength,
|
|
|
|
-1, srcFormat, mPixelStorePremultiplyAlpha);
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
void TexParameterf(WebGLenum target, WebGLenum pname, WebGLfloat param) {
|
2012-07-30 07:20:58 -07:00
|
|
|
TexParameter_base(target, pname, nullptr, ¶m);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
void TexParameteri(WebGLenum target, WebGLenum pname, WebGLint param) {
|
2012-07-30 07:20:58 -07:00
|
|
|
TexParameter_base(target, pname, ¶m, nullptr);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
|
2012-11-15 11:54:34 -08:00
|
|
|
void TexSubImage2D(WebGLenum target, WebGLint level,
|
2012-05-04 09:38:44 -07:00
|
|
|
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-11-15 11:54:34 -08:00
|
|
|
void TexSubImage2D(WebGLenum target, WebGLint level,
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLint xoffset, WebGLint yoffset, WebGLenum format,
|
2012-05-05 18:15:11 -07:00
|
|
|
WebGLenum type, dom::ImageData* pixels, ErrorResult& rv);
|
2012-05-31 11:16:48 -07:00
|
|
|
// Allow whatever element types the bindings are willing to pass
|
|
|
|
// us in TexSubImage2D
|
|
|
|
template<class ElementType>
|
2012-11-15 11:54:34 -08:00
|
|
|
void TexSubImage2D(WebGLenum target, WebGLint level,
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLint xoffset, WebGLint yoffset, WebGLenum format,
|
2012-12-31 10:48:55 -08:00
|
|
|
WebGLenum type, const ElementType& elt, ErrorResult& rv) {
|
2012-05-31 11:16:48 -07:00
|
|
|
if (!IsContextStable())
|
|
|
|
return;
|
|
|
|
nsRefPtr<gfxImageSurface> isurf;
|
|
|
|
WebGLTexelFormat srcFormat;
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult res = SurfaceFromElement(elt);
|
|
|
|
rv = SurfaceFromElementResultToImageSurface(res, getter_AddRefs(isurf),
|
|
|
|
&srcFormat);
|
|
|
|
if (rv.Failed())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint32_t byteLength = isurf->Stride() * isurf->Height();
|
|
|
|
return TexSubImage2D_base(target, level, xoffset, yoffset,
|
|
|
|
isurf->Width(), isurf->Height(),
|
|
|
|
isurf->Stride(), format, type,
|
|
|
|
isurf->Data(), byteLength,
|
|
|
|
-1, srcFormat, mPixelStorePremultiplyAlpha);
|
|
|
|
|
|
|
|
}
|
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) {
|
2012-07-31 20:45:20 -07:00
|
|
|
Uniform1iv_base(location, arr.Length(), arr.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-05-24 22:08:22 -07:00
|
|
|
void Uniform1iv(WebGLUniformLocation* location,
|
|
|
|
const dom::Sequence<WebGLint>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform1iv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform1iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const WebGLint* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void Uniform2iv(WebGLUniformLocation* location, dom::Int32Array& arr) {
|
2012-07-31 20:45:20 -07:00
|
|
|
Uniform2iv_base(location, arr.Length(), arr.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-05-24 22:08:22 -07:00
|
|
|
void Uniform2iv(WebGLUniformLocation* location,
|
|
|
|
const dom::Sequence<WebGLint>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform2iv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform2iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const WebGLint* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void Uniform3iv(WebGLUniformLocation* location, dom::Int32Array& arr) {
|
2012-07-31 20:45:20 -07:00
|
|
|
Uniform3iv_base(location, arr.Length(), arr.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-05-24 22:08:22 -07:00
|
|
|
void Uniform3iv(WebGLUniformLocation* location,
|
|
|
|
const dom::Sequence<WebGLint>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform3iv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform3iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const WebGLint* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void Uniform4iv(WebGLUniformLocation* location, dom::Int32Array& arr) {
|
2012-07-31 20:45:20 -07:00
|
|
|
Uniform4iv_base(location, arr.Length(), arr.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-05-24 22:08:22 -07:00
|
|
|
void Uniform4iv(WebGLUniformLocation* location,
|
|
|
|
const dom::Sequence<WebGLint>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform4iv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform4iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const WebGLint* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void Uniform1fv(WebGLUniformLocation* location, dom::Float32Array& arr) {
|
2012-07-31 20:45:20 -07:00
|
|
|
Uniform1fv_base(location, arr.Length(), arr.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-05-24 22:08:22 -07:00
|
|
|
void Uniform1fv(WebGLUniformLocation* location,
|
|
|
|
const dom::Sequence<WebGLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform1fv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform1fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const WebGLfloat* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void Uniform2fv(WebGLUniformLocation* location, dom::Float32Array& arr) {
|
2012-07-31 20:45:20 -07:00
|
|
|
Uniform2fv_base(location, arr.Length(), arr.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-05-24 22:08:22 -07:00
|
|
|
void Uniform2fv(WebGLUniformLocation* location,
|
|
|
|
const dom::Sequence<WebGLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform2fv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform2fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const WebGLfloat* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void Uniform3fv(WebGLUniformLocation* location, dom::Float32Array& arr) {
|
2012-07-31 20:45:20 -07:00
|
|
|
Uniform3fv_base(location, arr.Length(), arr.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-05-24 22:08:22 -07:00
|
|
|
void Uniform3fv(WebGLUniformLocation* location,
|
|
|
|
const dom::Sequence<WebGLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform3fv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform3fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const WebGLfloat* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void Uniform4fv(WebGLUniformLocation* location, dom::Float32Array& arr) {
|
2012-07-31 20:45:20 -07:00
|
|
|
Uniform4fv_base(location, arr.Length(), arr.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-05-24 22:08:22 -07:00
|
|
|
void Uniform4fv(WebGLUniformLocation* location,
|
|
|
|
const dom::Sequence<WebGLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform4fv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform4fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const WebGLfloat* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void UniformMatrix2fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
|
|
|
dom::Float32Array &value) {
|
2012-07-31 20:45:20 -07:00
|
|
|
UniformMatrix2fv_base(location, transpose, value.Length(), value.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
void UniformMatrix2fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
2012-05-24 22:08:22 -07:00
|
|
|
const dom::Sequence<float> &value) {
|
2012-05-04 09:38:44 -07:00
|
|
|
UniformMatrix2fv_base(location, transpose, value.Length(),
|
|
|
|
value.Elements());
|
|
|
|
}
|
|
|
|
void UniformMatrix2fv_base(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const float* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void UniformMatrix3fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
|
|
|
dom::Float32Array &value) {
|
2012-07-31 20:45:20 -07:00
|
|
|
UniformMatrix3fv_base(location, transpose, value.Length(), value.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
void UniformMatrix3fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
2012-05-24 22:08:22 -07:00
|
|
|
const dom::Sequence<float> &value) {
|
2012-05-04 09:38:44 -07:00
|
|
|
UniformMatrix3fv_base(location, transpose, value.Length(),
|
|
|
|
value.Elements());
|
|
|
|
}
|
|
|
|
void UniformMatrix3fv_base(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const float* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void UniformMatrix4fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
|
|
|
dom::Float32Array &value) {
|
2012-07-31 20:45:20 -07:00
|
|
|
UniformMatrix4fv_base(location, transpose, value.Length(), value.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
void UniformMatrix4fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
2012-05-24 22:08:22 -07:00
|
|
|
const dom::Sequence<float> &value) {
|
2012-05-04 09:38:44 -07:00
|
|
|
UniformMatrix4fv_base(location, transpose, value.Length(),
|
|
|
|
value.Elements());
|
|
|
|
}
|
|
|
|
void UniformMatrix4fv_base(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const float* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void UseProgram(WebGLProgram *prog);
|
2012-10-16 05:17:01 -07:00
|
|
|
bool ValidateAttribArraySetter(const char* name, uint32_t cnt, uint32_t arrayLength);
|
|
|
|
bool ValidateUniformArraySetter(const char* name, uint32_t expectedElemSize, WebGLUniformLocation *location_object,
|
|
|
|
GLint& location, uint32_t& numElementsToUpload, uint32_t arrayLength);
|
|
|
|
bool ValidateUniformMatrixArraySetter(const char* name, int dim, WebGLUniformLocation *location_object,
|
|
|
|
GLint& location, uint32_t& numElementsToUpload, uint32_t arrayLength,
|
|
|
|
WebGLboolean aTranspose);
|
|
|
|
bool ValidateUniformSetter(const char* name, WebGLUniformLocation *location_object, GLint& location);
|
2012-05-04 09:38:44 -07:00
|
|
|
void ValidateProgram(WebGLProgram *prog);
|
2012-10-16 05:17:01 -07:00
|
|
|
bool ValidateUniformLocation(const char* info, WebGLUniformLocation *location_object);
|
2013-03-04 16:44:31 -08:00
|
|
|
bool ValidateSamplerUniformSetter(const char* info,
|
|
|
|
WebGLUniformLocation *location,
|
|
|
|
WebGLint value);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
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) {
|
2012-07-31 20:45:20 -07:00
|
|
|
VertexAttrib1fv_base(idx, arr.Length(), arr.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-05-24 22:08:22 -07:00
|
|
|
void VertexAttrib1fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
VertexAttrib1fv_base(idx, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void VertexAttrib1fv_base(WebGLuint idx, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const WebGLfloat* ptr);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void VertexAttrib2fv(WebGLuint idx, dom::Float32Array &arr) {
|
2012-07-31 20:45:20 -07:00
|
|
|
VertexAttrib2fv_base(idx, arr.Length(), arr.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-05-24 22:08:22 -07:00
|
|
|
void VertexAttrib2fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
VertexAttrib2fv_base(idx, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void VertexAttrib2fv_base(WebGLuint idx, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const WebGLfloat* ptr);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void VertexAttrib3fv(WebGLuint idx, dom::Float32Array &arr) {
|
2012-07-31 20:45:20 -07:00
|
|
|
VertexAttrib3fv_base(idx, arr.Length(), arr.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-05-24 22:08:22 -07:00
|
|
|
void VertexAttrib3fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
VertexAttrib3fv_base(idx, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void VertexAttrib3fv_base(WebGLuint idx, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const WebGLfloat* ptr);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void VertexAttrib4fv(WebGLuint idx, dom::Float32Array &arr) {
|
2012-07-31 20:45:20 -07:00
|
|
|
VertexAttrib4fv_base(idx, arr.Length(), arr.Data());
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-05-24 22:08:22 -07:00
|
|
|
void VertexAttrib4fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
VertexAttrib4fv_base(idx, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void VertexAttrib4fv_base(WebGLuint idx, uint32_t arrayLength,
|
2012-05-24 22:08:22 -07:00
|
|
|
const WebGLfloat* ptr);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
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,
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t pixelSize,
|
|
|
|
uint32_t alignment);
|
2011-09-01 12:28:34 -07:00
|
|
|
|
|
|
|
// Returns x rounded to the next highest multiple of y.
|
|
|
|
static CheckedUint32 RoundedToNextMultipleOf(CheckedUint32 x, CheckedUint32 y) {
|
|
|
|
return ((x + y - 1) / y) * y;
|
|
|
|
}
|
|
|
|
|
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 mOptionsFrozen;
|
2011-10-13 05:09:22 -07:00
|
|
|
bool mMinCapability;
|
|
|
|
bool mDisableExtensions;
|
2011-11-18 19:57:29 -08:00
|
|
|
bool mHasRobustness;
|
2012-08-09 19:30:17 -07:00
|
|
|
bool mIsMesa;
|
2012-12-07 18:00:42 -08:00
|
|
|
bool mLoseContextOnHeapMinimize;
|
2013-01-03 15:39:25 -08:00
|
|
|
bool mCanLoseContextInForeground;
|
2013-02-13 15:26:24 -08:00
|
|
|
bool mShouldPresent;
|
|
|
|
bool mIsScreenCleared;
|
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
|
2012-05-23 09:07:01 -07:00
|
|
|
int32_t mGLMaxVertexAttribs;
|
|
|
|
int32_t mGLMaxTextureUnits;
|
|
|
|
int32_t mGLMaxTextureSize;
|
|
|
|
int32_t mGLMaxCubeMapTextureSize;
|
2012-12-11 13:57:30 -08:00
|
|
|
int32_t mGLMaxRenderbufferSize;
|
2012-05-23 09:07:01 -07:00
|
|
|
int32_t mGLMaxTextureImageUnits;
|
|
|
|
int32_t mGLMaxVertexTextureImageUnits;
|
|
|
|
int32_t mGLMaxVaryingVectors;
|
|
|
|
int32_t mGLMaxFragmentUniformVectors;
|
|
|
|
int32_t mGLMaxVertexUniformVectors;
|
2010-07-14 20:52:34 -07:00
|
|
|
|
2012-09-11 11:54:39 -07:00
|
|
|
// Cache the max number of elements that can be read from bound VBOs
|
|
|
|
// (result of ValidateBuffers).
|
2012-11-19 07:49:51 -08:00
|
|
|
bool mMinInUseAttribArrayLengthCached;
|
|
|
|
uint32_t mMinInUseAttribArrayLength;
|
2012-09-11 11:54:39 -07:00
|
|
|
|
|
|
|
inline void InvalidateCachedMinInUseAttribArrayLength()
|
|
|
|
{
|
2012-11-19 07:49:51 -08:00
|
|
|
mMinInUseAttribArrayLengthCached = false;
|
|
|
|
mMinInUseAttribArrayLength = 0;
|
2012-09-11 11:54:39 -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 {
|
2012-06-15 22:12:30 -07:00
|
|
|
EXT_texture_filter_anisotropic,
|
2012-10-17 12:11:51 -07:00
|
|
|
OES_standard_derivatives,
|
|
|
|
OES_texture_float,
|
2012-09-25 05:49:28 -07:00
|
|
|
WEBGL_compressed_texture_atc,
|
2012-09-25 05:49:28 -07:00
|
|
|
WEBGL_compressed_texture_pvrtc,
|
2012-10-17 12:11:51 -07:00
|
|
|
WEBGL_compressed_texture_s3tc,
|
|
|
|
WEBGL_debug_renderer_info,
|
2012-08-13 18:17:55 -07:00
|
|
|
WEBGL_depth_texture,
|
2012-10-17 12:11:51 -07:00
|
|
|
WEBGL_lose_context,
|
2012-06-15 22:12:30 -07:00
|
|
|
WebGLExtensionID_unknown_extension
|
2011-05-20 12:53:53 -07:00
|
|
|
};
|
2012-10-03 14:13:05 -07:00
|
|
|
nsTArray<nsRefPtr<WebGLExtensionBase> > mExtensions;
|
2012-06-15 22:12:30 -07:00
|
|
|
|
|
|
|
// returns true if the extension has been enabled by calling getExtension.
|
2012-10-03 14:13:05 -07:00
|
|
|
bool IsExtensionEnabled(WebGLExtensionID ext) const;
|
2012-06-15 22:12:30 -07:00
|
|
|
|
2012-10-17 12:11:51 -07:00
|
|
|
// returns true if the extension is supported for this JSContext (this decides what getSupportedExtensions exposes)
|
|
|
|
bool IsExtensionSupported(JSContext *cx, WebGLExtensionID ext) const;
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2012-05-08 10:29:31 -07:00
|
|
|
nsTArray<WebGLenum> mCompressedTextureFormats;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool InitAndValidateGL();
|
2012-11-19 07:49:51 -08:00
|
|
|
bool ValidateBuffers(uint32_t *maxAllowedCount, const char *info);
|
2011-09-28 23:19:26 -07:00
|
|
|
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,
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t *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
|
|
|
|
2012-05-08 10:29:31 -07:00
|
|
|
bool ValidateTexImage2DTarget(WebGLenum target, WebGLsizei width, WebGLsizei height, const char* info);
|
2012-09-25 05:49:28 -07:00
|
|
|
bool ValidateCompressedTextureSize(WebGLenum target, WebGLint level, WebGLenum format, WebGLsizei width, WebGLsizei height, uint32_t byteLength, const char* info);
|
2012-05-08 10:29:31 -07:00
|
|
|
bool ValidateLevelWidthHeightForTarget(WebGLenum target, WebGLint level, WebGLsizei width, WebGLsizei height, const char* info);
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
static uint32_t GetBitsPerTexel(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,
|
2012-05-23 09:07:01 -07:00
|
|
|
void *data, uint32_t byteLength,
|
2012-05-04 09:38:44 -07:00
|
|
|
int jsArrayType,
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelFormat 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,
|
2012-05-23 09:07:01 -07:00
|
|
|
void *pixels, uint32_t byteLength,
|
2012-05-04 09:38:44 -07:00
|
|
|
int jsArrayType,
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelFormat 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,
|
2012-05-23 09:07:01 -07:00
|
|
|
const uint8_t* src, uint8_t *dst,
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelFormat srcFormat, bool srcPremultiplied,
|
|
|
|
WebGLTexelFormat dstFormat, bool dstPremultiplied,
|
2010-10-15 14:50:15 -07:00
|
|
|
size_t dstTexelSize);
|
|
|
|
|
2012-05-31 11:16:48 -07:00
|
|
|
template<class ElementType>
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult SurfaceFromElement(ElementType* aElement) {
|
|
|
|
MOZ_ASSERT(aElement);
|
|
|
|
uint32_t flags =
|
|
|
|
nsLayoutUtils::SFE_WANT_IMAGE_SURFACE;
|
|
|
|
|
|
|
|
if (mPixelStoreColorspaceConversion == LOCAL_GL_NONE)
|
|
|
|
flags |= nsLayoutUtils::SFE_NO_COLORSPACE_CONVERSION;
|
|
|
|
if (!mPixelStorePremultiplyAlpha)
|
|
|
|
flags |= nsLayoutUtils::SFE_NO_PREMULTIPLY_ALPHA;
|
|
|
|
return nsLayoutUtils::SurfaceFromElement(aElement, flags);
|
|
|
|
}
|
2012-12-31 10:48:55 -08:00
|
|
|
template<class ElementType>
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult SurfaceFromElement(const dom::NonNull<ElementType>& aElement) {
|
|
|
|
return SurfaceFromElement(aElement.get());
|
|
|
|
}
|
2012-05-31 11:16:48 -07:00
|
|
|
|
|
|
|
nsresult SurfaceFromElementResultToImageSurface(nsLayoutUtils::SurfaceFromElementResult& res,
|
|
|
|
gfxImageSurface **imageOut,
|
|
|
|
WebGLTexelFormat *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:
|
2012-05-23 09:07:01 -07:00
|
|
|
int32_t MaxTextureSizeForTarget(WebGLenum target) const {
|
2011-02-24 14:17:34 -08:00
|
|
|
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
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t 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
|
|
|
|
2012-05-29 11:44:31 -07:00
|
|
|
LinkedList<WebGLTexture> mTextures;
|
|
|
|
LinkedList<WebGLBuffer> mBuffers;
|
|
|
|
LinkedList<WebGLProgram> mPrograms;
|
|
|
|
LinkedList<WebGLShader> mShaders;
|
|
|
|
LinkedList<WebGLRenderbuffer> mRenderbuffers;
|
|
|
|
LinkedList<WebGLFramebuffer> mFramebuffers;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
// PixelStore parameters
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t 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-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
|
|
|
|
2012-05-29 11:44:31 -07:00
|
|
|
int mAlreadyGeneratedWarnings;
|
2012-07-25 09:13:45 -07:00
|
|
|
bool mAlreadyWarnedAboutFakeVertexAttrib0;
|
2012-05-29 11:44:31 -07:00
|
|
|
|
|
|
|
bool ShouldGenerateWarnings() const {
|
|
|
|
return mAlreadyGeneratedWarnings < 32;
|
|
|
|
}
|
2012-05-23 09:07:10 -07:00
|
|
|
|
2012-08-02 14:28:02 -07:00
|
|
|
uint64_t mLastUseIndex;
|
|
|
|
|
|
|
|
void LoseOldestWebGLContextIfLimitExceeded();
|
|
|
|
void UpdateLastUseIndex();
|
|
|
|
|
2012-10-04 13:35:54 -07:00
|
|
|
template <typename WebGLObjectType>
|
|
|
|
JS::Value WebGLObjectAsJSValue(JSContext *cx, const WebGLObjectType *, ErrorResult& rv) const;
|
|
|
|
template <typename WebGLObjectType>
|
|
|
|
JSObject* WebGLObjectAsJSObject(JSContext *cx, const WebGLObjectType *, ErrorResult& rv) const;
|
|
|
|
|
2012-12-11 13:57:30 -08:00
|
|
|
void ReattachTextureToAnyFramebufferToWorkAroundBugs(WebGLTexture *tex, WebGLint level);
|
|
|
|
|
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
|
2012-05-23 09:07:29 -07:00
|
|
|
void GenerateWarning(const char *fmt, ...);
|
|
|
|
void GenerateWarning(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
|
|
|
};
|
|
|
|
|
2012-10-03 14:13:05 -07:00
|
|
|
// used by DOM bindings in conjunction with GetParentObject
|
|
|
|
inline nsISupports*
|
|
|
|
ToSupports(WebGLContext* context)
|
|
|
|
{
|
2013-04-09 09:26:36 -07:00
|
|
|
return static_cast<nsIDOMWebGLRenderingContext*>(context);
|
2012-10-03 14:13:05 -07:00
|
|
|
}
|
|
|
|
|
2012-02-16 05:24:18 -08:00
|
|
|
class WebGLActiveInfo MOZ_FINAL
|
2012-10-09 11:39:49 -07:00
|
|
|
: public nsISupports
|
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
|
|
|
|
2012-10-09 11:39:49 -07:00
|
|
|
// WebIDL attributes
|
|
|
|
|
|
|
|
WebGLint Size() const {
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLenum Type() const {
|
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetName(nsString& retval) const {
|
|
|
|
retval = mName;
|
|
|
|
}
|
|
|
|
|
2013-04-25 09:29:54 -07:00
|
|
|
JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> scope);
|
2012-10-09 11:39:49 -07:00
|
|
|
|
2010-08-23 14:03:49 -07:00
|
|
|
NS_DECL_ISUPPORTS
|
2012-10-09 11:39:49 -07:00
|
|
|
|
2010-08-23 14:03:49 -07:00
|
|
|
protected:
|
|
|
|
WebGLint mSize;
|
|
|
|
WebGLenum mType;
|
|
|
|
nsString mName;
|
|
|
|
};
|
|
|
|
|
2011-12-16 13:11:59 -08: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-08-02 14:28:02 -07:00
|
|
|
|
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; }
|
|
|
|
|
2012-08-02 14:28:02 -07:00
|
|
|
friend class WebGLContext;
|
|
|
|
|
2011-07-07 17:01:12 -07:00
|
|
|
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;
|
2012-07-30 07:20:58 -07:00
|
|
|
sUniqueInstance = nullptr;
|
2011-07-07 17:01:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
static int64_t GetTextureMemoryUsed() {
|
2011-07-07 17:01:12 -07:00
|
|
|
const ContextsArrayType & contexts = Contexts();
|
2012-05-23 09:07:01 -07:00
|
|
|
int64_t result = 0;
|
2012-05-29 11:44:31 -07:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
|
|
|
for (const WebGLTexture *texture = contexts[i]->mTextures.getFirst();
|
|
|
|
texture;
|
|
|
|
texture = texture->getNext())
|
|
|
|
{
|
|
|
|
result += texture->MemoryUsage();
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 17:01:12 -07:00
|
|
|
return result;
|
|
|
|
}
|
2011-12-04 11:15:43 -08:00
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
static int64_t GetTextureCount() {
|
2011-07-07 17:01:12 -07:00
|
|
|
const ContextsArrayType & contexts = Contexts();
|
2012-05-23 09:07:01 -07:00
|
|
|
int64_t result = 0;
|
2012-05-29 11:44:31 -07:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
|
|
|
for (const WebGLTexture *texture = contexts[i]->mTextures.getFirst();
|
|
|
|
texture;
|
|
|
|
texture = texture->getNext())
|
|
|
|
{
|
|
|
|
result++;
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 17:01:12 -07:00
|
|
|
return result;
|
|
|
|
}
|
2011-12-04 11:15:43 -08:00
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
static int64_t GetBufferMemoryUsed() {
|
2011-07-07 17:01:15 -07:00
|
|
|
const ContextsArrayType & contexts = Contexts();
|
2012-05-23 09:07:01 -07:00
|
|
|
int64_t result = 0;
|
2012-05-29 11:44:31 -07:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
|
|
|
for (const WebGLBuffer *buffer = contexts[i]->mBuffers.getFirst();
|
|
|
|
buffer;
|
|
|
|
buffer = buffer->getNext())
|
|
|
|
{
|
|
|
|
result += buffer->ByteLength();
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 17:01:15 -07:00
|
|
|
return result;
|
|
|
|
}
|
2011-07-07 17:01:16 -07:00
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
static int64_t GetBufferCacheMemoryUsed();
|
2011-07-07 17:01:16 -07:00
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
static int64_t GetBufferCount() {
|
2011-07-07 17:01:15 -07:00
|
|
|
const ContextsArrayType & contexts = Contexts();
|
2012-05-23 09:07:01 -07:00
|
|
|
int64_t result = 0;
|
2012-05-29 11:44:31 -07:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
|
|
|
for (const WebGLBuffer *buffer = contexts[i]->mBuffers.getFirst();
|
|
|
|
buffer;
|
|
|
|
buffer = buffer->getNext())
|
|
|
|
{
|
|
|
|
result++;
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 17:01:15 -07:00
|
|
|
return result;
|
|
|
|
}
|
2011-12-04 11:15:43 -08:00
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
static int64_t GetRenderbufferMemoryUsed() {
|
2011-07-07 17:01:16 -07:00
|
|
|
const ContextsArrayType & contexts = Contexts();
|
2012-05-23 09:07:01 -07:00
|
|
|
int64_t result = 0;
|
2012-05-29 11:44:31 -07:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
|
|
|
for (const WebGLRenderbuffer *rb = contexts[i]->mRenderbuffers.getFirst();
|
|
|
|
rb;
|
|
|
|
rb = rb->getNext())
|
|
|
|
{
|
|
|
|
result += rb->MemoryUsage();
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 17:01:16 -07:00
|
|
|
return result;
|
|
|
|
}
|
2011-12-04 11:15:43 -08:00
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
static int64_t GetRenderbufferCount() {
|
2011-07-07 17:01:16 -07:00
|
|
|
const ContextsArrayType & contexts = Contexts();
|
2012-05-23 09:07:01 -07:00
|
|
|
int64_t result = 0;
|
2012-05-29 11:44:31 -07:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
|
|
|
for (const WebGLRenderbuffer *rb = contexts[i]->mRenderbuffers.getFirst();
|
|
|
|
rb;
|
|
|
|
rb = rb->getNext())
|
|
|
|
{
|
|
|
|
result++;
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 17:01:16 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
static int64_t GetShaderSize();
|
2011-12-04 11:15:43 -08:00
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
static int64_t GetShaderCount() {
|
2011-07-07 17:01:16 -07:00
|
|
|
const ContextsArrayType & contexts = Contexts();
|
2012-05-23 09:07:01 -07:00
|
|
|
int64_t result = 0;
|
2012-05-29 11:44:31 -07:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
|
|
|
for (const WebGLShader *shader = contexts[i]->mShaders.getFirst();
|
|
|
|
shader;
|
|
|
|
shader = shader->getNext())
|
|
|
|
{
|
|
|
|
result++;
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 17:01:16 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
static int64_t GetContextCount() {
|
2011-07-07 17:01:12 -07:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2012-11-14 23:32:39 -08:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
#endif
|