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_
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-06-10 13:00:35 -07:00
|
|
|
#include "GLDefs.h"
|
|
|
|
#include "WebGLActiveInfo.h"
|
2012-11-20 13:38:20 -08:00
|
|
|
#include "WebGLObjectModel.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "nsTArray.h"
|
2012-11-14 23:32:39 -08:00
|
|
|
#include "nsCycleCollectionNoteChild.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
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"
|
2012-03-26 11:59:04 -07:00
|
|
|
#include "nsWrapperCache.h"
|
2012-04-21 13:48:22 -07:00
|
|
|
#include "nsIObserver.h"
|
2013-10-21 14:23:33 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
#include "GLContextProvider.h"
|
2013-09-30 14:26:04 -07:00
|
|
|
#include "gfxImageSurface.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"
|
2013-10-11 06:16:43 -07:00
|
|
|
#include "mozilla/Scoped.h"
|
2012-05-04 09:38:44 -07:00
|
|
|
|
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"
|
2012-05-05 18:15:11 -07:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2013-08-21 23:34:54 -07:00
|
|
|
|
|
|
|
class nsIDocShell;
|
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
|
|
|
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;
|
2013-06-10 13:00:35 -07:00
|
|
|
class WebGLBuffer;
|
|
|
|
class WebGLVertexAttribData;
|
|
|
|
class WebGLShader;
|
|
|
|
class WebGLProgram;
|
2013-08-06 14:23:46 -07:00
|
|
|
class WebGLQuery;
|
2013-06-10 13:00:35 -07:00
|
|
|
class WebGLUniformLocation;
|
|
|
|
class WebGLFramebuffer;
|
|
|
|
class WebGLRenderbuffer;
|
|
|
|
class WebGLShaderPrecisionFormat;
|
|
|
|
class WebGLTexture;
|
2013-06-27 14:07:21 -07:00
|
|
|
class WebGLVertexArray;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-10-22 10:08:52 -07:00
|
|
|
namespace dom {
|
2013-08-22 22:17:11 -07:00
|
|
|
class ImageData;
|
|
|
|
|
2012-10-22 10:08:52 -07:00
|
|
|
struct WebGLContextAttributes;
|
2013-09-09 02:43:52 -07:00
|
|
|
template<typename> struct Nullable;
|
2012-10-22 10:08:52 -07:00
|
|
|
}
|
|
|
|
|
2013-10-01 14:01:19 -07:00
|
|
|
namespace gfx {
|
|
|
|
class SourceSurface;
|
|
|
|
}
|
|
|
|
|
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;
|
2013-11-27 17:05:00 -08:00
|
|
|
friend class WebGLMemoryReporterWrapper;
|
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;
|
2013-06-21 16:44:17 -07:00
|
|
|
friend class WebGLExtensionDrawBuffers;
|
2013-06-27 14:07:21 -07:00
|
|
|
friend class WebGLExtensionVertexArray;
|
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,
|
2013-07-16 07:32:24 -07:00
|
|
|
JS::Handle<JSObject*> scope) = 0;
|
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
|
2013-09-30 14:02:40 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
virtual int32_t GetWidth() const MOZ_OVERRIDE;
|
|
|
|
virtual int32_t GetHeight() const MOZ_OVERRIDE;
|
|
|
|
#endif
|
2013-05-29 13:43:41 -07:00
|
|
|
NS_IMETHOD SetDimensions(int32_t width, int32_t height) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height) MOZ_OVERRIDE
|
2009-09-02 17:47:49 -07:00
|
|
|
{ return NS_ERROR_NOT_IMPLEMENTED; }
|
2013-05-29 13:43:41 -07:00
|
|
|
NS_IMETHOD Reset() MOZ_OVERRIDE
|
2010-08-19 08:22:46 -07:00
|
|
|
{ /* (InitializeWithSurface) */ return NS_ERROR_NOT_IMPLEMENTED; }
|
2012-03-23 15:10:50 -07:00
|
|
|
NS_IMETHOD Render(gfxContext *ctx,
|
2013-10-01 14:01:19 -07:00
|
|
|
GraphicsFilter f,
|
2013-05-29 13:43:41 -07:00
|
|
|
uint32_t aFlags = RenderFlagPremultAlpha) MOZ_OVERRIDE;
|
2013-10-16 19:55:08 -07:00
|
|
|
virtual void GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat);
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHOD GetInputStream(const char* aMimeType,
|
|
|
|
const PRUnichar* aEncoderOptions,
|
2013-05-29 13:43:41 -07:00
|
|
|
nsIInputStream **aStream) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD GetThebesSurface(gfxASurface **surface) MOZ_OVERRIDE;
|
2013-10-01 14:01:19 -07:00
|
|
|
mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetSurfaceSnapshot() MOZ_OVERRIDE;
|
2011-06-24 10:41:18 -07:00
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
NS_IMETHOD SetIsOpaque(bool b) MOZ_OVERRIDE { return NS_OK; };
|
2013-06-07 11:42:12 -07:00
|
|
|
NS_IMETHOD SetContextOptions(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aOptions) MOZ_OVERRIDE;
|
2010-11-16 20:33:03 -08:00
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
NS_IMETHOD SetIsIPC(bool b) MOZ_OVERRIDE { 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();
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void SynthesizeGLError(GLenum err);
|
|
|
|
void SynthesizeGLError(GLenum 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, ...);
|
2013-09-04 05:14:50 -07:00
|
|
|
void ErrorInvalidEnumInfo(const char *info, GLenum enumvalue);
|
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
|
|
|
|
2013-09-04 05:14:50 -07:00
|
|
|
WebGLTexture *activeBoundTextureForTarget(GLenum target) const {
|
2010-08-23 14:03:35 -07:00
|
|
|
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,
|
2013-05-29 13:43:41 -07:00
|
|
|
LayerManager *aManager) MOZ_OVERRIDE;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
|
|
|
// Note that 'clean' here refers to its invalidation state, not the
|
|
|
|
// contents of the buffer.
|
2013-05-29 13:43:41 -07:00
|
|
|
void MarkContextClean() MOZ_OVERRIDE { mInvalidated = false; }
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2013-09-04 05:14:50 -07:00
|
|
|
gl::GLContext* GL() const { return gl; }
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2013-09-04 05:14:50 -07:00
|
|
|
bool IsPremultAlpha() const { return mOptions.premultipliedAlpha; }
|
2013-02-13 15:26:24 -08:00
|
|
|
|
|
|
|
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-07-02 14:30:20 -07:00
|
|
|
static const size_t sMaxColorAttachments = 16;
|
2013-06-21 16:44:17 -07:00
|
|
|
|
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.
|
2013-07-02 14:30:20 -07:00
|
|
|
void ForceClearFramebufferWithDefaultValues(GLbitfield mask, const bool colorAttachmentsMask[sMaxColorAttachments]);
|
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
|
|
|
|
2013-09-04 05:14:50 -07:00
|
|
|
// checks for GL errors, clears any pending GL error, stores the current GL error in currentGLError (if not nullptr),
|
2011-07-07 17:01:16 -07:00
|
|
|
// and copies it into mWebGLError if it doesn't already have an error set
|
2013-09-04 05:14:50 -07:00
|
|
|
void UpdateWebGLErrorAndClearGLError(GLenum *currentGLError = nullptr);
|
2011-07-07 17:01:16 -07:00
|
|
|
|
2013-09-04 05:14:50 -07:00
|
|
|
bool MinCapabilityMode() const { return mMinCapability; }
|
2012-10-23 09:21:23 -07:00
|
|
|
|
2013-09-04 05:14:50 -07:00
|
|
|
void RobustnessTimerCallback(nsITimer* timer);
|
|
|
|
static void RobustnessTimerCallbackStatic(nsITimer* timer, void *thisPointer);
|
|
|
|
void SetupContextLossTimer();
|
|
|
|
void TerminateContextLossTimer();
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
// WebIDL WebGLRenderingContext API
|
2013-09-04 05:14:50 -07:00
|
|
|
dom::HTMLCanvasElement* GetCanvas() const { return mCanvasElement; }
|
|
|
|
GLsizei DrawingBufferWidth() const { return IsContextLost() ? 0 : mWidth; }
|
|
|
|
GLsizei DrawingBufferHeight() const { return IsContextLost() ? 0 : mHeight; }
|
2013-09-04 05:14:44 -07:00
|
|
|
|
2013-10-09 09:05:22 -07:00
|
|
|
void GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& retval);
|
2013-09-04 05:14:44 -07:00
|
|
|
bool IsContextLost() const { return mContextStatus != ContextNotLost; }
|
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);
|
2013-09-04 05:14:43 -07:00
|
|
|
void ActiveTexture(GLenum texture);
|
2012-05-04 09:38:44 -07:00
|
|
|
void AttachShader(WebGLProgram* program, WebGLShader* shader);
|
2013-09-04 05:14:43 -07:00
|
|
|
void BindAttribLocation(WebGLProgram* program, GLuint location,
|
2012-05-04 09:38:44 -07:00
|
|
|
const nsAString& name);
|
2013-09-04 05:14:43 -07:00
|
|
|
void BindFramebuffer(GLenum target, WebGLFramebuffer* wfb);
|
|
|
|
void BindRenderbuffer(GLenum target, WebGLRenderbuffer* wrb);
|
|
|
|
void BindTexture(GLenum target, WebGLTexture *tex);
|
2013-06-27 14:07:21 -07:00
|
|
|
void BindVertexArray(WebGLVertexArray *vao);
|
2013-09-04 05:14:50 -07:00
|
|
|
void BlendColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
|
2013-09-04 05:14:43 -07:00
|
|
|
void BlendEquation(GLenum mode);
|
|
|
|
void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha);
|
|
|
|
void BlendFunc(GLenum sfactor, GLenum dfactor);
|
|
|
|
void BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB,
|
|
|
|
GLenum srcAlpha, GLenum dstAlpha);
|
|
|
|
GLenum CheckFramebufferStatus(GLenum target);
|
|
|
|
void Clear(GLbitfield mask);
|
|
|
|
void ClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
|
|
|
|
void ClearDepth(GLclampf v);
|
|
|
|
void ClearStencil(GLint v);
|
2012-05-04 09:38:44 -07:00
|
|
|
void ColorMask(WebGLboolean r, WebGLboolean g, WebGLboolean b, WebGLboolean a);
|
|
|
|
void CompileShader(WebGLShader *shader);
|
2013-09-04 05:14:43 -07:00
|
|
|
void CompressedTexImage2D(GLenum target, GLint level,
|
|
|
|
GLenum internalformat, GLsizei width,
|
|
|
|
GLsizei height, GLint border,
|
2013-08-05 10:40:01 -07:00
|
|
|
const dom::ArrayBufferView& view);
|
2013-09-04 05:14:43 -07:00
|
|
|
void CompressedTexSubImage2D(GLenum target, GLint level,
|
|
|
|
GLint xoffset, GLint yoffset,
|
|
|
|
GLsizei width, GLsizei height,
|
|
|
|
GLenum format,
|
2013-08-05 10:40:01 -07:00
|
|
|
const dom::ArrayBufferView& view);
|
2013-09-04 05:14:43 -07:00
|
|
|
void CopyTexImage2D(GLenum target, GLint level,
|
|
|
|
GLenum internalformat, GLint x, GLint y,
|
|
|
|
GLsizei width, GLsizei height, GLint border);
|
|
|
|
void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset,
|
|
|
|
GLint yoffset, GLint x, GLint y,
|
|
|
|
GLsizei width, GLsizei height);
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLFramebuffer> CreateFramebuffer();
|
|
|
|
already_AddRefed<WebGLProgram> CreateProgram();
|
|
|
|
already_AddRefed<WebGLRenderbuffer> CreateRenderbuffer();
|
|
|
|
already_AddRefed<WebGLTexture> CreateTexture();
|
2013-09-04 05:14:43 -07:00
|
|
|
already_AddRefed<WebGLShader> CreateShader(GLenum type);
|
2013-06-27 14:07:21 -07:00
|
|
|
already_AddRefed<WebGLVertexArray> CreateVertexArray();
|
2013-09-04 05:14:43 -07:00
|
|
|
void CullFace(GLenum face);
|
2012-05-04 09:38:44 -07:00
|
|
|
void DeleteFramebuffer(WebGLFramebuffer *fbuf);
|
|
|
|
void DeleteProgram(WebGLProgram *prog);
|
|
|
|
void DeleteRenderbuffer(WebGLRenderbuffer *rbuf);
|
|
|
|
void DeleteShader(WebGLShader *shader);
|
2013-06-27 14:07:21 -07:00
|
|
|
void DeleteVertexArray(WebGLVertexArray *vao);
|
2012-05-04 09:38:44 -07:00
|
|
|
void DeleteTexture(WebGLTexture *tex);
|
2013-09-04 05:14:43 -07:00
|
|
|
void DepthFunc(GLenum func);
|
2012-05-04 09:38:44 -07:00
|
|
|
void DepthMask(WebGLboolean b);
|
2013-09-04 05:14:43 -07:00
|
|
|
void DepthRange(GLclampf zNear, GLclampf zFar);
|
2012-05-04 09:38:44 -07:00
|
|
|
void DetachShader(WebGLProgram *program, WebGLShader *shader);
|
2013-07-17 09:13:38 -07:00
|
|
|
void DrawBuffers(const dom::Sequence<GLenum>& buffers);
|
2013-09-04 05:14:50 -07:00
|
|
|
void Flush();
|
|
|
|
void Finish();
|
2013-09-04 05:14:43 -07:00
|
|
|
void FramebufferRenderbuffer(GLenum target, GLenum attachment,
|
|
|
|
GLenum rbtarget, WebGLRenderbuffer *wrb);
|
|
|
|
void FramebufferTexture2D(GLenum target, GLenum attachment,
|
|
|
|
GLenum textarget, WebGLTexture *tobj,
|
|
|
|
GLint level);
|
|
|
|
void FrontFace(GLenum mode);
|
|
|
|
void GenerateMipmap(GLenum target);
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLActiveInfo> GetActiveAttrib(WebGLProgram *prog,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint index);
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLActiveInfo> GetActiveUniform(WebGLProgram *prog,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint index);
|
2012-05-04 09:38:44 -07:00
|
|
|
void GetAttachedShaders(WebGLProgram* prog,
|
|
|
|
dom::Nullable< nsTArray<WebGLShader*> > &retval);
|
2013-09-04 05:14:43 -07:00
|
|
|
GLint GetAttribLocation(WebGLProgram* prog, const nsAString& name);
|
|
|
|
JS::Value GetBufferParameter(GLenum target, GLenum pname);
|
|
|
|
JS::Value GetBufferParameter(JSContext* /* unused */, GLenum target,
|
|
|
|
GLenum pname) {
|
2012-05-31 11:16:48 -07:00
|
|
|
return GetBufferParameter(target, pname);
|
|
|
|
}
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum GetError();
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value GetFramebufferAttachmentParameter(JSContext* cx,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum target,
|
|
|
|
GLenum attachment,
|
|
|
|
GLenum pname,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv);
|
2013-09-04 05:14:43 -07:00
|
|
|
JS::Value GetProgramParameter(WebGLProgram *prog, GLenum pname);
|
2012-05-31 11:16:48 -07:00
|
|
|
JS::Value GetProgramParameter(JSContext* /* unused */, WebGLProgram *prog,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum pname) {
|
2012-05-31 11:16:48 -07:00
|
|
|
return GetProgramParameter(prog, pname);
|
|
|
|
}
|
2012-09-17 01:37:20 -07:00
|
|
|
void GetProgramInfoLog(WebGLProgram *prog, nsACString& retval);
|
|
|
|
void GetProgramInfoLog(WebGLProgram *prog, nsAString& retval);
|
2013-09-04 05:14:43 -07:00
|
|
|
JS::Value GetRenderbufferParameter(GLenum target, GLenum pname);
|
2012-05-31 11:16:48 -07:00
|
|
|
JS::Value GetRenderbufferParameter(JSContext* /* unused */,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum target, GLenum pname) {
|
2012-05-31 11:16:48 -07:00
|
|
|
return GetRenderbufferParameter(target, pname);
|
|
|
|
}
|
2013-09-04 05:14:43 -07:00
|
|
|
JS::Value GetShaderParameter(WebGLShader *shader, GLenum pname);
|
2012-05-31 11:16:48 -07:00
|
|
|
JS::Value GetShaderParameter(JSContext* /* unused */, WebGLShader *shader,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum pname) {
|
2012-05-31 11:16:48 -07:00
|
|
|
return GetShaderParameter(shader, pname);
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLShaderPrecisionFormat>
|
2013-09-04 05:14:43 -07:00
|
|
|
GetShaderPrecisionFormat(GLenum shadertype, GLenum 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);
|
2013-09-04 05:14:43 -07:00
|
|
|
JS::Value GetTexParameter(GLenum target, GLenum pname);
|
|
|
|
JS::Value GetTexParameter(JSContext * /* unused */, GLenum target,
|
|
|
|
GLenum pname) {
|
2012-05-31 11:16:48 -07:00
|
|
|
return GetTexParameter(target, pname);
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value GetUniform(JSContext* cx, WebGLProgram *prog,
|
2013-11-23 18:20:48 -08:00
|
|
|
WebGLUniformLocation *location);
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLUniformLocation>
|
|
|
|
GetUniformLocation(WebGLProgram *prog, const nsAString& name);
|
2013-09-04 05:14:43 -07:00
|
|
|
void Hint(GLenum target, GLenum mode);
|
2012-05-04 09:38:44 -07:00
|
|
|
bool IsFramebuffer(WebGLFramebuffer *fb);
|
|
|
|
bool IsProgram(WebGLProgram *prog);
|
|
|
|
bool IsRenderbuffer(WebGLRenderbuffer *rb);
|
|
|
|
bool IsShader(WebGLShader *shader);
|
|
|
|
bool IsTexture(WebGLTexture *tex);
|
2013-06-27 14:07:21 -07:00
|
|
|
bool IsVertexArray(WebGLVertexArray *vao);
|
2013-09-04 05:14:50 -07:00
|
|
|
void LineWidth(GLfloat width);
|
2012-09-17 01:37:20 -07:00
|
|
|
void LinkProgram(WebGLProgram *program);
|
2013-09-04 05:14:43 -07:00
|
|
|
void PixelStorei(GLenum pname, GLint param);
|
2013-09-04 05:14:50 -07:00
|
|
|
void PolygonOffset(GLfloat factor, GLfloat units);
|
2013-09-04 05:14:43 -07:00
|
|
|
void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
|
|
|
|
GLenum format, GLenum type,
|
2013-08-05 10:40:01 -07:00
|
|
|
const Nullable<dom::ArrayBufferView> &pixels,
|
|
|
|
ErrorResult& rv);
|
2013-09-04 05:14:43 -07:00
|
|
|
void RenderbufferStorage(GLenum target, GLenum internalformat,
|
|
|
|
GLsizei width, GLsizei height);
|
2013-09-04 05:14:50 -07:00
|
|
|
void SampleCoverage(GLclampf value, WebGLboolean invert);
|
2013-09-04 05:14:43 -07:00
|
|
|
void Scissor(GLint x, GLint y, GLsizei width, GLsizei height);
|
2012-05-04 09:38:44 -07:00
|
|
|
void ShaderSource(WebGLShader *shader, const nsAString& source);
|
2013-09-04 05:14:43 -07:00
|
|
|
void StencilFunc(GLenum func, GLint ref, GLuint mask);
|
|
|
|
void StencilFuncSeparate(GLenum face, GLenum func, GLint ref,
|
|
|
|
GLuint mask);
|
|
|
|
void StencilMask(GLuint mask);
|
|
|
|
void StencilMaskSeparate(GLenum face, GLuint mask);
|
|
|
|
void StencilOp(GLenum sfail, GLenum dpfail, GLenum dppass);
|
|
|
|
void StencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail,
|
|
|
|
GLenum dppass);
|
|
|
|
void TexImage2D(GLenum target, GLint level,
|
|
|
|
GLenum internalformat, GLsizei width,
|
|
|
|
GLsizei height, GLint border, GLenum format,
|
|
|
|
GLenum type,
|
2013-08-05 10:40:01 -07:00
|
|
|
const Nullable<dom::ArrayBufferView> &pixels,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv);
|
2013-09-04 05:14:43 -07:00
|
|
|
void TexImage2D(GLenum target, GLint level,
|
|
|
|
GLenum internalformat, GLenum format, GLenum 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>
|
2013-09-04 05:14:43 -07:00
|
|
|
void TexImage2D(GLenum target, GLint level,
|
|
|
|
GLenum internalformat, GLenum format, GLenum type,
|
2013-07-22 05:15:43 -07:00
|
|
|
ElementType& elt, ErrorResult& rv)
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-31 11:16:48 -07:00
|
|
|
return;
|
|
|
|
nsRefPtr<gfxImageSurface> isurf;
|
|
|
|
WebGLTexelFormat srcFormat;
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult res = SurfaceFromElement(elt);
|
|
|
|
rv = SurfaceFromElementResultToImageSurface(res, getter_AddRefs(isurf),
|
|
|
|
&srcFormat);
|
2013-11-23 18:20:48 -08:00
|
|
|
if (rv.Failed() || !isurf)
|
2012-05-31 11:16:48 -07:00
|
|
|
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);
|
|
|
|
}
|
2013-09-04 05:14:43 -07:00
|
|
|
void TexParameterf(GLenum target, GLenum pname, GLfloat param) {
|
2012-07-30 07:20:58 -07:00
|
|
|
TexParameter_base(target, pname, nullptr, ¶m);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2013-09-04 05:14:43 -07:00
|
|
|
void TexParameteri(GLenum target, GLenum pname, GLint param) {
|
2012-07-30 07:20:58 -07:00
|
|
|
TexParameter_base(target, pname, ¶m, nullptr);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void TexSubImage2D(GLenum target, GLint level,
|
|
|
|
GLint xoffset, GLint yoffset,
|
|
|
|
GLsizei width, GLsizei height, GLenum format,
|
|
|
|
GLenum type,
|
2013-08-05 10:40:01 -07:00
|
|
|
const Nullable<dom::ArrayBufferView> &pixels,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv);
|
2013-09-04 05:14:43 -07:00
|
|
|
void TexSubImage2D(GLenum target, GLint level,
|
|
|
|
GLint xoffset, GLint yoffset, GLenum format,
|
|
|
|
GLenum 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>
|
2013-09-04 05:14:43 -07:00
|
|
|
void TexSubImage2D(GLenum target, GLint level,
|
|
|
|
GLint xoffset, GLint yoffset, GLenum format,
|
|
|
|
GLenum type, ElementType& elt, ErrorResult& rv)
|
2013-07-22 05:15:43 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-31 11:16:48 -07:00
|
|
|
return;
|
|
|
|
nsRefPtr<gfxImageSurface> isurf;
|
|
|
|
WebGLTexelFormat srcFormat;
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult res = SurfaceFromElement(elt);
|
|
|
|
rv = SurfaceFromElementResultToImageSurface(res, getter_AddRefs(isurf),
|
|
|
|
&srcFormat);
|
2013-11-23 18:20:48 -08:00
|
|
|
if (rv.Failed() || !isurf)
|
2012-05-31 11:16:48 -07:00
|
|
|
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
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void Uniform1i(WebGLUniformLocation* location, GLint x);
|
|
|
|
void Uniform2i(WebGLUniformLocation* location, GLint x, GLint y);
|
|
|
|
void Uniform3i(WebGLUniformLocation* location, GLint x, GLint y,
|
|
|
|
GLint z);
|
|
|
|
void Uniform4i(WebGLUniformLocation* location, GLint x, GLint y,
|
|
|
|
GLint z, GLint w);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void Uniform1f(WebGLUniformLocation* location, GLfloat x);
|
|
|
|
void Uniform2f(WebGLUniformLocation* location, GLfloat x, GLfloat y);
|
|
|
|
void Uniform3f(WebGLUniformLocation* location, GLfloat x, GLfloat y,
|
|
|
|
GLfloat z);
|
|
|
|
void Uniform4f(WebGLUniformLocation* location, GLfloat x, GLfloat y,
|
|
|
|
GLfloat z, GLfloat w);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
void Uniform1iv(WebGLUniformLocation* location,
|
|
|
|
const 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,
|
2013-09-04 05:14:43 -07:00
|
|
|
const dom::Sequence<GLint>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform1iv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform1iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2013-09-04 05:14:43 -07:00
|
|
|
const GLint* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
void Uniform2iv(WebGLUniformLocation* location,
|
|
|
|
const 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,
|
2013-09-04 05:14:43 -07:00
|
|
|
const dom::Sequence<GLint>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform2iv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform2iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2013-09-04 05:14:43 -07:00
|
|
|
const GLint* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
void Uniform3iv(WebGLUniformLocation* location,
|
|
|
|
const 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,
|
2013-09-04 05:14:43 -07:00
|
|
|
const dom::Sequence<GLint>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform3iv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform3iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2013-09-04 05:14:43 -07:00
|
|
|
const GLint* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
void Uniform4iv(WebGLUniformLocation* location,
|
|
|
|
const 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,
|
2013-09-04 05:14:43 -07:00
|
|
|
const dom::Sequence<GLint>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform4iv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform4iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2013-09-04 05:14:43 -07:00
|
|
|
const GLint* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
void Uniform1fv(WebGLUniformLocation* location,
|
|
|
|
const 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,
|
2013-09-04 05:14:43 -07:00
|
|
|
const dom::Sequence<GLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform1fv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform1fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2013-09-04 05:14:43 -07:00
|
|
|
const GLfloat* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
void Uniform2fv(WebGLUniformLocation* location,
|
|
|
|
const 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,
|
2013-09-04 05:14:43 -07:00
|
|
|
const dom::Sequence<GLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform2fv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform2fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2013-09-04 05:14:43 -07:00
|
|
|
const GLfloat* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
void Uniform3fv(WebGLUniformLocation* location,
|
|
|
|
const 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,
|
2013-09-04 05:14:43 -07:00
|
|
|
const dom::Sequence<GLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform3fv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform3fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2013-09-04 05:14:43 -07:00
|
|
|
const GLfloat* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
void Uniform4fv(WebGLUniformLocation* location,
|
|
|
|
const 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,
|
2013-09-04 05:14:43 -07:00
|
|
|
const dom::Sequence<GLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
Uniform4fv_base(location, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
void Uniform4fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
|
2013-09-04 05:14:43 -07:00
|
|
|
const GLfloat* data);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void UniformMatrix2fv(WebGLUniformLocation* location,
|
|
|
|
WebGLboolean transpose,
|
2013-08-05 10:40:01 -07:00
|
|
|
const 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,
|
2013-08-05 10:40:01 -07:00
|
|
|
const 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,
|
2013-08-05 10:40:01 -07:00
|
|
|
const 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,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLint value);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void Viewport(GLint x, GLint y, GLsizei width, GLsizei height);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Asynchronous Queries (WebGLContextAsyncQueries.cpp)
|
|
|
|
public:
|
|
|
|
already_AddRefed<WebGLQuery> CreateQuery();
|
|
|
|
void DeleteQuery(WebGLQuery *query);
|
2013-09-04 05:14:43 -07:00
|
|
|
void BeginQuery(GLenum target, WebGLQuery *query);
|
|
|
|
void EndQuery(GLenum target);
|
2013-08-06 17:05:51 -07:00
|
|
|
bool IsQuery(WebGLQuery *query);
|
2013-09-04 05:14:43 -07:00
|
|
|
already_AddRefed<WebGLQuery> GetQuery(GLenum target, GLenum pname);
|
|
|
|
JS::Value GetQueryObject(JSContext* cx, WebGLQuery *query, GLenum pname);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
|
|
|
private:
|
2013-08-26 15:18:48 -07:00
|
|
|
// ANY_SAMPLES_PASSED(_CONSERVATIVE) slot
|
2013-08-21 18:11:03 -07:00
|
|
|
WebGLRefPtr<WebGLQuery> mActiveOcclusionQuery;
|
2013-08-26 15:18:48 -07:00
|
|
|
|
|
|
|
// LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN slot
|
2013-08-21 18:11:03 -07:00
|
|
|
WebGLRefPtr<WebGLQuery> mActiveTransformFeedbackQuery;
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLRefPtr<WebGLQuery>* GetQueryTargetSlot(GLenum target, const char* infos);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2013-08-20 08:36:19 -07:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Buffer Objects (WebGLContextBuffers.cpp)
|
|
|
|
public:
|
2013-09-04 05:14:43 -07:00
|
|
|
void BindBuffer(GLenum target, WebGLBuffer* buf);
|
|
|
|
void BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buffer);
|
|
|
|
void BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buffer,
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLintptr offset, WebGLsizeiptr size);
|
2013-09-04 05:14:43 -07:00
|
|
|
void BufferData(GLenum target, WebGLsizeiptr size, GLenum usage);
|
|
|
|
void BufferData(GLenum target, const dom::ArrayBufferView &data,
|
|
|
|
GLenum usage);
|
|
|
|
void BufferData(GLenum target,
|
2013-08-20 08:36:19 -07:00
|
|
|
const Nullable<dom::ArrayBuffer> &maybeData,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum usage);
|
|
|
|
void BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
|
2013-08-20 08:36:19 -07:00
|
|
|
const dom::ArrayBufferView &data);
|
2013-09-04 05:14:43 -07:00
|
|
|
void BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
|
2013-08-20 08:36:19 -07:00
|
|
|
const Nullable<dom::ArrayBuffer> &maybeData);
|
|
|
|
already_AddRefed<WebGLBuffer> CreateBuffer();
|
|
|
|
void DeleteBuffer(WebGLBuffer *buf);
|
|
|
|
bool IsBuffer(WebGLBuffer *buffer);
|
|
|
|
|
|
|
|
private:
|
2013-08-20 08:36:20 -07:00
|
|
|
// ARRAY_BUFFER slot
|
2013-08-20 08:36:19 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer> mBoundArrayBuffer;
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
// TRANSFORM_FEEDBACK_BUFFER slot
|
|
|
|
WebGLRefPtr<WebGLBuffer> mBoundTransformFeedbackBuffer;
|
|
|
|
|
|
|
|
// these two functions emit INVALID_ENUM for invalid `target`.
|
|
|
|
WebGLRefPtr<WebGLBuffer>* GetBufferSlotByTarget(GLenum target, const char* infos);
|
|
|
|
WebGLRefPtr<WebGLBuffer>* GetBufferSlotByTargetIndexed(GLenum target, GLuint index, const char* infos);
|
2013-09-04 05:14:43 -07:00
|
|
|
bool ValidateBufferUsageEnum(GLenum target, const char* infos);
|
2013-08-20 08:36:19 -07:00
|
|
|
|
2013-08-15 17:43:47 -07:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// State and State Requests (WebGLContextState.cpp)
|
|
|
|
public:
|
2013-09-04 05:14:43 -07:00
|
|
|
void Disable(GLenum cap);
|
|
|
|
void Enable(GLenum cap);
|
|
|
|
JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv);
|
|
|
|
JS::Value GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index);
|
|
|
|
bool IsEnabled(GLenum cap);
|
2013-08-15 17:43:47 -07:00
|
|
|
|
|
|
|
private:
|
2013-08-22 17:11:27 -07:00
|
|
|
// State tracking slots
|
|
|
|
realGLboolean mDitherEnabled;
|
2013-08-22 17:11:40 -07:00
|
|
|
realGLboolean mRasterizerDiscardEnabled;
|
2013-08-22 17:11:27 -07:00
|
|
|
realGLboolean mScissorTestEnabled;
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
bool ValidateCapabilityEnum(GLenum cap, const char* info);
|
|
|
|
realGLboolean* GetStateTrackingSlot(GLenum cap);
|
2013-08-15 17:43:47 -07:00
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Vertices Feature (WebGLContextVertices.cpp)
|
|
|
|
public:
|
2013-09-04 05:14:43 -07:00
|
|
|
void DrawArrays(GLenum mode, GLint first, GLsizei count);
|
|
|
|
void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount);
|
|
|
|
void DrawElements(GLenum mode, GLsizei count, GLenum type, WebGLintptr byteOffset);
|
|
|
|
void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
|
|
|
|
WebGLintptr byteOffset, GLsizei primcount);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void EnableVertexAttribArray(GLuint index);
|
|
|
|
void DisableVertexAttribArray(GLuint index);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
JS::Value GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
|
2013-08-06 17:05:51 -07:00
|
|
|
ErrorResult& rv);
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLsizeiptr GetVertexAttribOffset(GLuint index, GLenum pname);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void VertexAttrib1f(GLuint index, GLfloat x0);
|
|
|
|
void VertexAttrib2f(GLuint index, GLfloat x0, GLfloat x1);
|
|
|
|
void VertexAttrib3f(GLuint index, GLfloat x0, GLfloat x1,
|
|
|
|
GLfloat x2);
|
|
|
|
void VertexAttrib4f(GLuint index, GLfloat x0, GLfloat x1,
|
|
|
|
GLfloat x2, GLfloat x3);
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void VertexAttrib1fv(GLuint idx, const 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
|
|
|
}
|
2013-09-04 05:14:43 -07:00
|
|
|
void VertexAttrib1fv(GLuint idx, const dom::Sequence<GLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
VertexAttrib1fv_base(idx, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void VertexAttrib2fv(GLuint idx, const 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
|
|
|
}
|
2013-09-04 05:14:43 -07:00
|
|
|
void VertexAttrib2fv(GLuint idx, const dom::Sequence<GLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
VertexAttrib2fv_base(idx, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void VertexAttrib3fv(GLuint idx, const 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
|
|
|
}
|
2013-09-04 05:14:43 -07:00
|
|
|
void VertexAttrib3fv(GLuint idx, const dom::Sequence<GLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
VertexAttrib3fv_base(idx, arr.Length(), arr.Elements());
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void VertexAttrib4fv(GLuint idx, const 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
|
|
|
}
|
2013-09-04 05:14:43 -07:00
|
|
|
void VertexAttrib4fv(GLuint idx, const dom::Sequence<GLfloat>& arr) {
|
2012-05-04 09:38:44 -07:00
|
|
|
VertexAttrib4fv_base(idx, arr.Length(), arr.Elements());
|
|
|
|
}
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void VertexAttribPointer(GLuint index, GLint size, GLenum type,
|
|
|
|
WebGLboolean normalized, GLsizei stride,
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLintptr byteOffset);
|
2013-09-04 05:14:43 -07:00
|
|
|
void VertexAttribDivisor(GLuint index, GLuint divisor);
|
2013-07-25 17:38:58 -07:00
|
|
|
|
|
|
|
private:
|
2013-08-13 15:11:01 -07:00
|
|
|
// Cache the max number of vertices and instances that can be read from
|
|
|
|
// bound VBOs (result of ValidateBuffers).
|
|
|
|
bool mBufferFetchingIsVerified;
|
|
|
|
bool mBufferFetchingHasPerVertex;
|
|
|
|
uint32_t mMaxFetchedVertices;
|
|
|
|
uint32_t mMaxFetchedInstances;
|
|
|
|
|
|
|
|
inline void InvalidateBufferFetching()
|
|
|
|
{
|
|
|
|
mBufferFetchingIsVerified = false;
|
|
|
|
mBufferFetchingHasPerVertex = false;
|
|
|
|
mMaxFetchedVertices = 0;
|
|
|
|
mMaxFetchedInstances = 0;
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
bool DrawArrays_check(GLint first, GLsizei count, GLsizei primcount, const char* info);
|
|
|
|
bool DrawElements_check(GLsizei count, GLenum type, WebGLintptr byteOffset,
|
|
|
|
GLsizei primcount, const char* info);
|
2013-09-19 15:30:19 -07:00
|
|
|
bool DrawInstanced_check(const char* info);
|
2013-07-25 17:38:58 -07:00
|
|
|
void Draw_cleanup();
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void VertexAttrib1fv_base(GLuint idx, uint32_t arrayLength, const GLfloat* ptr);
|
|
|
|
void VertexAttrib2fv_base(GLuint idx, uint32_t arrayLength, const GLfloat* ptr);
|
|
|
|
void VertexAttrib3fv_base(GLuint idx, uint32_t arrayLength, const GLfloat* ptr);
|
|
|
|
void VertexAttrib4fv_base(GLuint idx, uint32_t arrayLength, const GLfloat* ptr);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
|
|
|
bool ValidateBufferFetching(const char *info);
|
2013-08-27 06:01:44 -07:00
|
|
|
bool BindArrayAttribToLocation0(WebGLProgram *program);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2013-07-25 17:38:58 -07:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// PROTECTED
|
2011-02-24 14:17:34 -08:00
|
|
|
protected:
|
2013-10-11 06:16:43 -07:00
|
|
|
void SetFakeBlackStatus(WebGLContextFakeBlackStatus x) {
|
|
|
|
mFakeBlackStatus = x;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
// Returns the current fake-black-status, except if it was Unknown,
|
|
|
|
// in which case this function resolves it first, so it never returns Unknown.
|
|
|
|
WebGLContextFakeBlackStatus ResolvedFakeBlackStatus();
|
2010-08-23 14:03:53 -07:00
|
|
|
|
|
|
|
void BindFakeBlackTextures();
|
|
|
|
void UnbindFakeBlackTextures();
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
WebGLVertexAttrib0Status WhatDoesVertexAttrib0Need();
|
2013-09-04 05:14:43 -07:00
|
|
|
bool DoFakeVertexAttrib0(GLuint 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
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
static CheckedUint32 GetImageSize(GLsizei height,
|
|
|
|
GLsizei 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;
|
2013-05-15 14:50:52 -07:00
|
|
|
bool mDisableFragHighP;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:43 -08:00
|
|
|
template<typename WebGLObjectType>
|
|
|
|
void DeleteWebGLObjectsArray(nsTArray<WebGLObjectType>& array);
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint mActiveTexture;
|
|
|
|
GLenum 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;
|
2013-06-21 16:44:17 -07:00
|
|
|
int32_t mGLMaxColorAttachments;
|
|
|
|
int32_t mGLMaxDrawBuffers;
|
2013-08-20 08:36:20 -07:00
|
|
|
uint32_t mGLMaxTransformFeedbackSeparateAttribs;
|
2010-07-14 20:52:34 -07:00
|
|
|
|
2013-09-04 05:14:44 -07:00
|
|
|
// Represents current status of the context with respect to context loss.
|
|
|
|
// That is, whether the context is lost, and what part of the context loss
|
|
|
|
// process we currently are at.
|
2012-01-04 13:12:03 -08:00
|
|
|
// 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.
|
2013-09-04 05:14:44 -07:00
|
|
|
ContextNotLost,
|
2012-01-04 13:12:03 -08:00
|
|
|
// 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
|
|
|
|
};
|
|
|
|
|
2013-08-26 14:12:53 -07:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// WebGL extensions (implemented in WebGLContextExtensions.cpp)
|
2011-05-20 12:53:53 -07:00
|
|
|
enum WebGLExtensionID {
|
2013-11-04 13:05:04 -08:00
|
|
|
EXT_sRGB,
|
2012-06-15 22:12:30 -07:00
|
|
|
EXT_texture_filter_anisotropic,
|
2013-05-13 06:22:30 -07:00
|
|
|
OES_element_index_uint,
|
2012-10-17 12:11:51 -07:00
|
|
|
OES_standard_derivatives,
|
|
|
|
OES_texture_float,
|
2013-06-10 13:00:52 -07:00
|
|
|
OES_texture_float_linear,
|
2013-06-27 14:07:21 -07:00
|
|
|
OES_vertex_array_object,
|
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,
|
2013-06-21 16:44:17 -07:00
|
|
|
WEBGL_draw_buffers,
|
2013-08-13 15:11:01 -07:00
|
|
|
ANGLE_instanced_arrays,
|
2013-08-26 14:12:53 -07:00
|
|
|
WebGLExtensionID_max,
|
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
|
|
|
|
2013-07-17 09:13:38 -07:00
|
|
|
// enable an extension. the extension should not be enabled before.
|
|
|
|
void EnableExtension(WebGLExtensionID ext);
|
|
|
|
|
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;
|
2013-07-17 09:13:38 -07:00
|
|
|
bool IsExtensionSupported(WebGLExtensionID ext) const;
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2013-08-26 14:12:53 -07:00
|
|
|
static const char* GetExtensionString(WebGLExtensionID ext);
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
nsTArray<GLenum> mCompressedTextureFormats;
|
2012-05-08 10:29:31 -07:00
|
|
|
|
2013-08-26 14:12:54 -07:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// WebGL 2 specifics (implemented in WebGL2Context.cpp)
|
|
|
|
|
|
|
|
virtual bool IsWebGL2() const = 0;
|
|
|
|
|
|
|
|
bool InitWebGL2();
|
|
|
|
|
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Validation functions (implemented in WebGLContextValidate.cpp)
|
2011-09-28 23:19:26 -07:00
|
|
|
bool InitAndValidateGL();
|
2013-09-04 05:14:43 -07:00
|
|
|
bool ValidateBlendEquationEnum(GLenum cap, const char *info);
|
|
|
|
bool ValidateBlendFuncDstEnum(GLenum mode, const char *info);
|
|
|
|
bool ValidateBlendFuncSrcEnum(GLenum mode, const char *info);
|
|
|
|
bool ValidateBlendFuncEnumsCompatibility(GLenum sfactor, GLenum dfactor, const char *info);
|
|
|
|
bool ValidateTextureTargetEnum(GLenum target, const char *info);
|
|
|
|
bool ValidateComparisonEnum(GLenum target, const char *info);
|
|
|
|
bool ValidateStencilOpEnum(GLenum action, const char *info);
|
|
|
|
bool ValidateFaceEnum(GLenum face, const char *info);
|
|
|
|
bool ValidateTexFormatAndType(GLenum format, GLenum type, int jsArrayType,
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t *texelSize, const char *info);
|
2013-09-04 05:14:43 -07:00
|
|
|
bool ValidateDrawModeEnum(GLenum mode, const char *info);
|
|
|
|
bool ValidateAttribIndex(GLuint index, const char *info);
|
2011-09-28 23:19:26 -07:00
|
|
|
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);
|
2013-11-04 13:05:04 -08:00
|
|
|
bool ValidateTexImage2DFormat(GLenum format, const char* info);
|
2013-09-04 05:14:43 -07:00
|
|
|
bool ValidateTexImage2DTarget(GLenum target, GLsizei width, GLsizei height, const char* info);
|
|
|
|
bool ValidateCompressedTextureSize(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, uint32_t byteLength, const char* info);
|
|
|
|
bool ValidateLevelWidthHeightForTarget(GLenum target, GLint level, GLsizei width, GLsizei height, const char* info);
|
2012-05-08 10:29:31 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
static uint32_t GetBitsPerTexel(GLenum format, GLenum 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
|
|
|
|
2013-09-04 05:14:52 -07:00
|
|
|
void MakeContextCurrent() const;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
// helpers
|
2013-09-04 05:14:43 -07:00
|
|
|
void TexImage2D_base(GLenum target, GLint level, GLenum internalformat,
|
|
|
|
GLsizei width, GLsizei height, GLsizei srcStrideOrZero, GLint border,
|
|
|
|
GLenum format, GLenum 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);
|
2013-09-04 05:14:43 -07:00
|
|
|
void TexSubImage2D_base(GLenum target, GLint level,
|
|
|
|
GLint xoffset, GLint yoffset,
|
|
|
|
GLsizei width, GLsizei height, GLsizei srcStrideOrZero,
|
|
|
|
GLenum format, GLenum 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);
|
2013-09-04 05:14:43 -07:00
|
|
|
void TexParameter_base(GLenum target, GLenum pname,
|
|
|
|
GLint *intParamPtr, GLfloat *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>
|
2013-07-22 05:15:43 -07:00
|
|
|
nsLayoutUtils::SurfaceFromElementResult SurfaceFromElement(ElementType& aElement)
|
|
|
|
{
|
|
|
|
return SurfaceFromElement(&aElement);
|
2012-12-31 10:48:55 -08:00
|
|
|
}
|
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
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void CopyTexSubImage2D_base(GLenum target,
|
|
|
|
GLint level,
|
|
|
|
GLenum internalformat,
|
|
|
|
GLint xoffset,
|
|
|
|
GLint yoffset,
|
|
|
|
GLint x,
|
|
|
|
GLint y,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
2012-05-04 09:38:44 -07:00
|
|
|
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:
|
2013-09-04 05:14:43 -07:00
|
|
|
int32_t MaxTextureSizeForTarget(GLenum 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();
|
|
|
|
void ForceLoseContext();
|
|
|
|
void ForceRestoreContext();
|
|
|
|
|
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<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;
|
2013-06-27 14:07:21 -07:00
|
|
|
WebGLRefPtr<WebGLVertexArray> mBoundVertexArray;
|
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;
|
2013-08-06 14:23:46 -07:00
|
|
|
LinkedList<WebGLQuery> mQueries;
|
2012-05-29 11:44:31 -07:00
|
|
|
LinkedList<WebGLShader> mShaders;
|
|
|
|
LinkedList<WebGLRenderbuffer> mRenderbuffers;
|
|
|
|
LinkedList<WebGLFramebuffer> mFramebuffers;
|
2013-06-27 14:07:21 -07:00
|
|
|
LinkedList<WebGLVertexArray> mVertexArrays;
|
|
|
|
|
|
|
|
WebGLRefPtr<WebGLVertexArray> mDefaultVertexArray;
|
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
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
WebGLContextFakeBlackStatus mFakeBlackStatus;
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
class FakeBlackTexture
|
|
|
|
{
|
|
|
|
gl::GLContext* mGL;
|
|
|
|
GLuint mGLName;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FakeBlackTexture(gl::GLContext* gl, GLenum target, GLenum format);
|
|
|
|
~FakeBlackTexture();
|
|
|
|
GLuint GLName() const { return mGLName; }
|
|
|
|
};
|
|
|
|
|
|
|
|
ScopedDeletePtr<FakeBlackTexture> mBlackOpaqueTexture2D,
|
|
|
|
mBlackOpaqueTextureCubeMap,
|
|
|
|
mBlackTransparentTexture2D,
|
|
|
|
mBlackTransparentTextureCubeMap;
|
|
|
|
|
|
|
|
void BindFakeBlackTexturesHelper(
|
|
|
|
GLenum target,
|
|
|
|
const nsTArray<WebGLRefPtr<WebGLTexture> >& boundTexturesArray,
|
|
|
|
ScopedDeletePtr<FakeBlackTexture> & opaqueTextureScopedPtr,
|
|
|
|
ScopedDeletePtr<FakeBlackTexture> & transparentTextureScopedPtr);
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLfloat mVertexAttrib0Vector[4];
|
|
|
|
GLfloat mFakeVertexAttrib0BufferObjectVector[4];
|
2011-02-24 14:17:34 -08:00
|
|
|
size_t mFakeVertexAttrib0BufferObjectSize;
|
|
|
|
GLuint mFakeVertexAttrib0BufferObject;
|
2013-10-11 06:16:43 -07:00
|
|
|
WebGLVertexAttrib0Status mFakeVertexAttrib0BufferStatus;
|
2010-09-02 07:34:08 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLint mStencilRefFront, mStencilRefBack;
|
|
|
|
GLuint mStencilValueMaskFront, mStencilValueMaskBack,
|
2011-05-20 12:53:53 -07:00
|
|
|
mStencilWriteMaskFront, mStencilWriteMaskBack;
|
2011-05-20 12:53:53 -07:00
|
|
|
realGLboolean mColorWriteMask[4];
|
|
|
|
realGLboolean mDepthWriteMask;
|
2013-09-04 05:14:43 -07:00
|
|
|
GLfloat mColorClearValue[4];
|
|
|
|
GLint mStencilClearValue;
|
|
|
|
GLfloat 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
|
|
|
|
2013-05-22 00:05:38 -07:00
|
|
|
// Used for some hardware (particularly Tegra 2 and 4) that likes to
|
|
|
|
// be Flushed while doing hundreds of draw calls.
|
|
|
|
int mDrawCallsSinceLastFlush;
|
|
|
|
|
2012-05-29 11:44:31 -07:00
|
|
|
int mAlreadyGeneratedWarnings;
|
2013-06-04 12:44:08 -07:00
|
|
|
int mMaxWarnings;
|
2012-07-25 09:13:45 -07:00
|
|
|
bool mAlreadyWarnedAboutFakeVertexAttrib0;
|
2012-05-29 11:44:31 -07:00
|
|
|
|
2013-09-04 05:14:50 -07:00
|
|
|
bool ShouldGenerateWarnings() const;
|
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;
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void ReattachTextureToAnyFramebufferToWorkAroundBugs(WebGLTexture *tex, GLint level);
|
2012-12-11 13:57:30 -08:00
|
|
|
|
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;
|
2013-08-06 14:23:46 -07:00
|
|
|
friend class WebGLQuery;
|
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;
|
2013-06-27 14:07:21 -07:00
|
|
|
friend class WebGLVertexArray;
|
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
|
|
|
}
|
|
|
|
|
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-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
|