2012-03-16 13:50:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04: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-03 04:47:49 +04:00
|
|
|
|
|
|
|
#ifndef WEBGLCONTEXT_H_
|
|
|
|
#define WEBGLCONTEXT_H_
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2015-09-24 22:21:05 +03:00
|
|
|
#include "GLContextTypes.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "GLDefs.h"
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-01-06 19:49:03 +04:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2016-11-16 22:10:22 +03:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
|
|
|
#include "mozilla/dom/TypedArray.h"
|
2014-01-06 19:49:03 +04:00
|
|
|
#include "mozilla/EnumeratedArray.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-01-06 19:49:03 +04:00
|
|
|
#include "mozilla/LinkedList.h"
|
|
|
|
#include "mozilla/UniquePtr.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "nsCycleCollectionNoteChild.h"
|
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2015-09-24 22:21:05 +03:00
|
|
|
#include "SurfaceTypes.h"
|
2015-11-25 07:15:29 +03:00
|
|
|
#include "ScopedGLHelpers.h"
|
|
|
|
#include "TexUnpackBlob.h"
|
2014-01-06 19:49:03 +04:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "ForceDiscreteGPUHelperCGL.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Local
|
2017-10-21 01:40:12 +03:00
|
|
|
#include "CacheMap.h"
|
2016-06-16 20:01:44 +03:00
|
|
|
#include "WebGLContextLossHandler.h"
|
2014-10-27 02:40:37 +03:00
|
|
|
#include "WebGLContextUnchecked.h"
|
2015-07-11 02:34:45 +03:00
|
|
|
#include "WebGLFormats.h"
|
2012-11-21 01:38:20 +04:00
|
|
|
#include "WebGLObjectModel.h"
|
2014-09-19 03:14:22 +04:00
|
|
|
#include "WebGLStrongTypes.h"
|
2015-11-25 07:15:29 +03:00
|
|
|
#include "WebGLTexture.h"
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
// Generated
|
|
|
|
#include "nsIDOMEventListener.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
2012-04-22 00:48:22 +04:00
|
|
|
#include "nsIObserver.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2016-10-14 02:15:16 +03:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
|
|
|
#include "mozilla/dom/WebGL2RenderingContextBinding.h"
|
2013-08-22 10:34:54 +04:00
|
|
|
|
|
|
|
class nsIDocShell;
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2015-06-10 08:13:02 +03:00
|
|
|
/*
|
|
|
|
* WebGL-only GLenums
|
|
|
|
*/
|
|
|
|
#define LOCAL_GL_BROWSER_DEFAULT_WEBGL 0x9244
|
|
|
|
#define LOCAL_GL_CONTEXT_LOST_WEBGL 0x9242
|
|
|
|
#define LOCAL_GL_MAX_CLIENT_WAIT_TIMEOUT_WEBGL 0x9247
|
|
|
|
#define LOCAL_GL_UNPACK_COLORSPACE_CONVERSION_WEBGL 0x9243
|
|
|
|
#define LOCAL_GL_UNPACK_FLIP_Y_WEBGL 0x9240
|
|
|
|
#define LOCAL_GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL 0x9241
|
|
|
|
|
2009-09-03 04:47:49 +04:00
|
|
|
namespace mozilla {
|
2015-11-25 07:15:29 +03:00
|
|
|
class ScopedCopyTexImageSource;
|
2017-12-19 05:30:56 +03:00
|
|
|
class ScopedDrawCallWrapper;
|
2015-11-25 07:15:29 +03:00
|
|
|
class ScopedResolveTexturesForDraw;
|
|
|
|
class ScopedUnpackReset;
|
2012-05-04 20:38:44 +04:00
|
|
|
class WebGLActiveInfo;
|
2013-06-11 00:00:35 +04:00
|
|
|
class WebGLBuffer;
|
2014-11-14 07:03:50 +03:00
|
|
|
class WebGLExtensionBase;
|
|
|
|
class WebGLFramebuffer;
|
2013-06-11 00:00:35 +04:00
|
|
|
class WebGLProgram;
|
2013-08-07 01:23:46 +04:00
|
|
|
class WebGLQuery;
|
2013-06-11 00:00:35 +04:00
|
|
|
class WebGLRenderbuffer;
|
2014-10-27 02:40:37 +03:00
|
|
|
class WebGLSampler;
|
2014-11-14 07:03:50 +03:00
|
|
|
class WebGLShader;
|
2013-06-11 00:00:35 +04:00
|
|
|
class WebGLShaderPrecisionFormat;
|
2016-06-23 12:01:36 +03:00
|
|
|
class WebGLSync;
|
2013-06-11 00:00:35 +04:00
|
|
|
class WebGLTexture;
|
2014-11-26 05:00:06 +03:00
|
|
|
class WebGLTransformFeedback;
|
2014-11-14 07:03:50 +03:00
|
|
|
class WebGLUniformLocation;
|
2013-06-28 01:07:21 +04:00
|
|
|
class WebGLVertexArray;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2012-10-22 21:08:52 +04:00
|
|
|
namespace dom {
|
2014-07-08 22:52:00 +04:00
|
|
|
class Element;
|
2014-11-14 07:03:50 +03:00
|
|
|
class ImageData;
|
2015-10-12 06:21:03 +03:00
|
|
|
class OwningHTMLCanvasElementOrOffscreenCanvas;
|
2012-10-22 21:08:52 +04:00
|
|
|
struct WebGLContextAttributes;
|
2013-09-09 13:43:52 +04:00
|
|
|
template<typename> struct Nullable;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2012-10-22 21:08:52 +04:00
|
|
|
|
2013-10-02 01:01:19 +04:00
|
|
|
namespace gfx {
|
|
|
|
class SourceSurface;
|
2016-02-25 02:54:50 +03:00
|
|
|
class VRLayerChild;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
2013-10-02 01:01:19 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
namespace gl {
|
|
|
|
class MozFramebuffer;
|
|
|
|
} // namespace gl
|
|
|
|
|
2015-01-16 02:40:39 +03:00
|
|
|
namespace webgl {
|
2018-02-21 04:34:25 +03:00
|
|
|
class AvailabilityRunnable;
|
2015-01-16 02:40:39 +03:00
|
|
|
struct LinkedProgramInfo;
|
2015-07-15 03:37:28 +03:00
|
|
|
class ShaderValidator;
|
2015-11-25 07:15:29 +03:00
|
|
|
class TexUnpackBlob;
|
2016-07-14 22:04:31 +03:00
|
|
|
struct UniformInfo;
|
2016-09-10 07:02:54 +03:00
|
|
|
struct UniformBlockInfo;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace webgl
|
2015-01-16 02:40:39 +03:00
|
|
|
|
2014-10-08 03:52:58 +04:00
|
|
|
WebGLTexelFormat GetWebGLTexelFormat(TexInternalFormat format);
|
2010-10-16 01:50:15 +04:00
|
|
|
|
2014-05-22 06:03:09 +04:00
|
|
|
void AssertUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint shadow);
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
struct WebGLContextOptions
|
|
|
|
{
|
2010-11-17 07:33:03 +03:00
|
|
|
// these are defaults
|
2012-08-01 22:58:44 +04:00
|
|
|
WebGLContextOptions();
|
2010-11-17 07:33:03 +03:00
|
|
|
|
|
|
|
bool operator==(const WebGLContextOptions& other) const {
|
|
|
|
return
|
|
|
|
alpha == other.alpha &&
|
|
|
|
depth == other.depth &&
|
|
|
|
stencil == other.stencil &&
|
|
|
|
premultipliedAlpha == other.premultipliedAlpha &&
|
2011-05-20 23:53:53 +04:00
|
|
|
antialias == other.antialias &&
|
|
|
|
preserveDrawingBuffer == other.preserveDrawingBuffer;
|
2010-11-17 07:33:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const WebGLContextOptions& other) const {
|
2011-05-20 23:53:53 +04:00
|
|
|
return !operator==(other);
|
2010-11-17 07:33:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool alpha;
|
|
|
|
bool depth;
|
|
|
|
bool stencil;
|
|
|
|
bool premultipliedAlpha;
|
2011-05-20 23:53:53 +04:00
|
|
|
bool antialias;
|
|
|
|
bool preserveDrawingBuffer;
|
2015-05-21 18:51:49 +03:00
|
|
|
bool failIfMajorPerformanceCaveat;
|
2010-11-17 07:33:03 +03:00
|
|
|
};
|
|
|
|
|
2014-09-03 23:17:18 +04:00
|
|
|
// From WebGLContextUtils
|
2014-09-19 03:14:22 +04:00
|
|
|
TexTarget TexImageTargetToTexTarget(TexImageTarget texImageTarget);
|
2014-05-22 06:03:09 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
struct WebGLIntOrFloat {
|
|
|
|
const enum {
|
2014-10-27 02:40:37 +03:00
|
|
|
Int,
|
2014-06-24 04:56:21 +04:00
|
|
|
Float,
|
|
|
|
Uint
|
2014-10-27 02:40:37 +03:00
|
|
|
} mType;
|
2016-11-02 00:58:07 +03:00
|
|
|
|
2014-10-27 02:40:37 +03:00
|
|
|
union {
|
|
|
|
GLint i;
|
|
|
|
GLfloat f;
|
2014-06-24 04:56:21 +04:00
|
|
|
GLuint u;
|
2014-10-27 02:40:37 +03:00
|
|
|
} mValue;
|
|
|
|
|
|
|
|
explicit WebGLIntOrFloat(GLint i) : mType(Int) { mValue.i = i; }
|
|
|
|
explicit WebGLIntOrFloat(GLfloat f) : mType(Float) { mValue.f = f; }
|
|
|
|
|
|
|
|
GLint AsInt() const { return (mType == Int) ? mValue.i : NS_lroundf(mValue.f); }
|
|
|
|
GLfloat AsFloat() const { return (mType == Float) ? mValue.f : GLfloat(mValue.i); }
|
|
|
|
};
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
struct IndexedBufferBinding
|
|
|
|
{
|
|
|
|
WebGLRefPtr<WebGLBuffer> mBufferBinding;
|
|
|
|
uint64_t mRangeStart;
|
|
|
|
uint64_t mRangeSize;
|
|
|
|
|
|
|
|
IndexedBufferBinding();
|
|
|
|
|
|
|
|
uint64_t ByteCount() const;
|
|
|
|
};
|
|
|
|
|
2016-12-23 00:52:53 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
struct FloatOrInt final // For TexParameter[fi] and friends.
|
|
|
|
{
|
|
|
|
const bool isFloat;
|
|
|
|
const GLfloat f;
|
|
|
|
const GLint i;
|
|
|
|
|
|
|
|
explicit FloatOrInt(GLint x)
|
|
|
|
: isFloat(false)
|
|
|
|
, f(x)
|
|
|
|
, i(x)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
explicit FloatOrInt(GLfloat x)
|
|
|
|
: isFloat(true)
|
|
|
|
, f(x)
|
|
|
|
, i(roundf(x))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
FloatOrInt& operator =(const FloatOrInt& x) {
|
|
|
|
memcpy(this, &x, sizeof(x));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
////////////////////////////////////
|
|
|
|
|
|
|
|
struct TexImageSource
|
|
|
|
{
|
|
|
|
const dom::ArrayBufferView* mView;
|
|
|
|
GLuint mViewElemOffset;
|
2016-10-28 05:03:20 +03:00
|
|
|
GLuint mViewElemLengthOverride;
|
2016-10-21 04:03:40 +03:00
|
|
|
|
|
|
|
const WebGLsizeiptr* mPboOffset;
|
|
|
|
|
2016-12-21 01:59:51 +03:00
|
|
|
const dom::ImageBitmap* mImageBitmap;
|
2016-10-21 04:03:40 +03:00
|
|
|
const dom::ImageData* mImageData;
|
|
|
|
|
|
|
|
const dom::Element* mDomElem;
|
|
|
|
ErrorResult* mOut_error;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
TexImageSource() {
|
|
|
|
memset(this, 0, sizeof(*this));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
struct TexImageSourceAdapter final : public TexImageSource
|
|
|
|
{
|
2016-11-23 04:17:12 +03:00
|
|
|
TexImageSourceAdapter(const dom::Nullable<dom::ArrayBufferView>* maybeView,
|
2016-10-21 04:03:40 +03:00
|
|
|
ErrorResult*)
|
|
|
|
{
|
2016-11-23 04:17:12 +03:00
|
|
|
if (!maybeView->IsNull()) {
|
|
|
|
mView = &(maybeView->Value());
|
2016-10-21 04:03:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-23 04:17:12 +03:00
|
|
|
TexImageSourceAdapter(const dom::ArrayBufferView* view, ErrorResult*) {
|
|
|
|
mView = view;
|
2016-10-21 04:03:40 +03:00
|
|
|
}
|
|
|
|
|
2016-11-23 04:17:12 +03:00
|
|
|
TexImageSourceAdapter(const dom::ArrayBufferView* view, GLuint viewElemOffset,
|
2016-10-28 05:03:20 +03:00
|
|
|
GLuint viewElemLengthOverride = 0)
|
|
|
|
{
|
2016-11-23 04:17:12 +03:00
|
|
|
mView = view;
|
2016-10-21 04:03:40 +03:00
|
|
|
mViewElemOffset = viewElemOffset;
|
2016-10-28 05:03:20 +03:00
|
|
|
mViewElemLengthOverride = viewElemLengthOverride;
|
|
|
|
}
|
|
|
|
|
2016-11-23 04:17:12 +03:00
|
|
|
TexImageSourceAdapter(const WebGLsizeiptr* pboOffset, GLuint ignored1, GLuint ignored2 = 0) {
|
|
|
|
mPboOffset = pboOffset;
|
2016-10-21 04:03:40 +03:00
|
|
|
}
|
|
|
|
|
2016-11-23 04:17:12 +03:00
|
|
|
TexImageSourceAdapter(const WebGLsizeiptr* pboOffset, ErrorResult* ignored) {
|
|
|
|
mPboOffset = pboOffset;
|
2016-10-21 04:03:40 +03:00
|
|
|
}
|
|
|
|
|
2016-12-21 01:59:51 +03:00
|
|
|
TexImageSourceAdapter(const dom::ImageBitmap* imageBitmap, ErrorResult*) {
|
|
|
|
mImageBitmap = imageBitmap;
|
|
|
|
}
|
|
|
|
|
2016-11-23 04:17:12 +03:00
|
|
|
TexImageSourceAdapter(const dom::ImageData* imageData, ErrorResult*) {
|
|
|
|
mImageData = imageData;
|
2016-10-21 04:03:40 +03:00
|
|
|
}
|
|
|
|
|
2016-11-23 04:17:12 +03:00
|
|
|
TexImageSourceAdapter(const dom::Element* domElem, ErrorResult* const out_error) {
|
|
|
|
mDomElem = domElem;
|
2016-10-21 04:03:40 +03:00
|
|
|
mOut_error = out_error;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-21 04:34:25 +03:00
|
|
|
// --
|
|
|
|
|
|
|
|
namespace webgl {
|
|
|
|
class AvailabilityRunnable final : public Runnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const RefPtr<WebGLContext> mWebGL; // Prevent CC
|
|
|
|
std::vector<RefPtr<WebGLQuery>> mQueries;
|
|
|
|
std::vector<RefPtr<WebGLSync>> mSyncs;
|
|
|
|
|
|
|
|
explicit AvailabilityRunnable(WebGLContext* webgl);
|
|
|
|
~AvailabilityRunnable();
|
|
|
|
|
|
|
|
NS_IMETHOD Run() override;
|
|
|
|
};
|
|
|
|
} // namespace webgl
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
class WebGLContext
|
2018-02-26 22:36:04 +03:00
|
|
|
: public nsICanvasRenderingContextInternal
|
2014-11-14 07:03:50 +03:00
|
|
|
, public nsSupportsWeakReference
|
|
|
|
, public WebGLContextUnchecked
|
|
|
|
, public nsWrapperCache
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2017-12-19 05:30:56 +03:00
|
|
|
friend class ScopedDrawCallWrapper;
|
2016-09-10 07:02:54 +03:00
|
|
|
friend class ScopedDrawHelper;
|
|
|
|
friend class ScopedDrawWithTransformFeedback;
|
2016-09-09 01:56:58 +03:00
|
|
|
friend class ScopedFBRebinder;
|
2014-06-24 04:56:21 +04:00
|
|
|
friend class WebGL2Context;
|
2012-09-25 16:49:28 +04:00
|
|
|
friend class WebGLContextUserData;
|
2016-11-23 05:59:35 +03:00
|
|
|
friend class WebGLExtensionCompressedTextureASTC;
|
2012-09-25 16:49:28 +04:00
|
|
|
friend class WebGLExtensionCompressedTextureATC;
|
2016-01-08 05:12:22 +03:00
|
|
|
friend class WebGLExtensionCompressedTextureES3;
|
2014-03-11 02:42:58 +04:00
|
|
|
friend class WebGLExtensionCompressedTextureETC1;
|
2012-09-25 16:49:28 +04:00
|
|
|
friend class WebGLExtensionCompressedTexturePVRTC;
|
2014-03-11 02:42:58 +04:00
|
|
|
friend class WebGLExtensionCompressedTextureS3TC;
|
2017-05-30 18:21:33 +03:00
|
|
|
friend class WebGLExtensionCompressedTextureS3TC_SRGB;
|
2012-08-14 05:17:55 +04:00
|
|
|
friend class WebGLExtensionDepthTexture;
|
2015-05-27 14:12:00 +03:00
|
|
|
friend class WebGLExtensionDisjointTimerQuery;
|
2013-06-22 03:44:17 +04:00
|
|
|
friend class WebGLExtensionDrawBuffers;
|
2014-03-11 02:42:58 +04:00
|
|
|
friend class WebGLExtensionLoseContext;
|
2013-06-28 01:07:21 +04:00
|
|
|
friend class WebGLExtensionVertexArray;
|
2014-03-11 02:42:58 +04:00
|
|
|
friend class WebGLMemoryTracker;
|
2018-02-21 04:34:25 +03:00
|
|
|
friend class webgl::AvailabilityRunnable;
|
2017-10-21 01:40:12 +03:00
|
|
|
friend struct webgl::LinkedProgramInfo;
|
2016-09-10 07:02:54 +03:00
|
|
|
friend struct webgl::UniformBlockInfo;
|
2011-07-08 04:01:12 +04:00
|
|
|
|
2012-09-20 11:55:36 +04:00
|
|
|
enum {
|
|
|
|
UNPACK_FLIP_Y_WEBGL = 0x9240,
|
|
|
|
UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241,
|
2017-04-11 12:15:25 +03:00
|
|
|
// We throw InvalidOperation in TexImage if we fail to use GPU fast-path
|
|
|
|
// for texture copy when it is set to true, only for debug purpose.
|
|
|
|
UNPACK_REQUIRE_FASTPATH = 0x10001,
|
2012-09-20 11:55:36 +04:00
|
|
|
CONTEXT_LOST_WEBGL = 0x9242,
|
|
|
|
UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
|
2012-10-17 23:11:51 +04:00
|
|
|
BROWSER_DEFAULT_WEBGL = 0x9244,
|
|
|
|
UNMASKED_VENDOR_WEBGL = 0x9245,
|
|
|
|
UNMASKED_RENDERER_WEBGL = 0x9246
|
2012-09-20 11:55:36 +04:00
|
|
|
};
|
|
|
|
|
2017-01-12 04:10:48 +03:00
|
|
|
const uint32_t mMaxPerfWarnings;
|
|
|
|
mutable uint64_t mNumPerfWarnings;
|
|
|
|
const uint32_t mMaxAcceptableFBStatusInvals;
|
|
|
|
|
2017-12-15 20:47:29 +03:00
|
|
|
uint64_t mNextFenceId = 1;
|
|
|
|
uint64_t mCompletedFenceId = 0;
|
|
|
|
|
2009-09-03 04:47:49 +04:00
|
|
|
public:
|
|
|
|
WebGLContext();
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
protected:
|
|
|
|
virtual ~WebGLContext();
|
|
|
|
|
|
|
|
public:
|
2010-06-16 01:38:05 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
|
2012-05-04 20:36:40 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(WebGLContext,
|
2018-02-26 22:36:04 +03:00
|
|
|
nsICanvasRenderingContextInternal)
|
2012-05-04 20:36:40 +04:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override = 0;
|
2012-05-31 22:16:48 +04:00
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
virtual void OnVisibilityChange() override;
|
|
|
|
virtual void OnMemoryPressure() override;
|
|
|
|
|
2009-09-03 04:47:49 +04:00
|
|
|
// nsICanvasRenderingContextInternal
|
2017-12-22 04:14:54 +03:00
|
|
|
virtual int32_t GetWidth() override { return DrawingBufferWidth("get width"); }
|
|
|
|
virtual int32_t GetHeight() override { return DrawingBufferHeight("get height"); }
|
2015-10-02 10:18:26 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD SetDimensions(int32_t width, int32_t height) override;
|
2016-08-23 11:41:21 +03:00
|
|
|
NS_IMETHOD InitializeWithDrawTarget(nsIDocShell*,
|
|
|
|
NotNull<gfx::DrawTarget*>) override
|
2014-11-14 07:03:50 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Reset() override {
|
2014-11-14 07:03:50 +03:00
|
|
|
/* (InitializeWithSurface) */
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2015-10-26 21:31:12 +03:00
|
|
|
virtual UniquePtr<uint8_t[]> GetImageBuffer(int32_t* out_format) override;
|
2014-11-14 07:03:50 +03:00
|
|
|
NS_IMETHOD GetInputStream(const char* mimeType,
|
|
|
|
const char16_t* encoderOptions,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIInputStream** out_stream) override;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2017-04-12 12:55:23 +03:00
|
|
|
virtual already_AddRefed<mozilla::gfx::SourceSurface>
|
|
|
|
GetSurfaceSnapshot(gfxAlphaType* out_alphaType) override;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2017-06-09 22:15:42 +03:00
|
|
|
virtual void SetIsOpaque(bool) override {};
|
2017-12-22 04:42:52 +03:00
|
|
|
bool GetIsOpaque() override { return !mOptions.alpha; }
|
2014-11-14 07:03:50 +03:00
|
|
|
NS_IMETHOD SetContextOptions(JSContext* cx,
|
2015-10-18 14:14:22 +03:00
|
|
|
JS::Handle<JS::Value> options,
|
|
|
|
ErrorResult& aRvForDictionaryInit) override;
|
2010-11-17 07:33:03 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD SetIsIPC(bool) override {
|
2014-11-14 07:03:50 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2014-09-10 05:40:51 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An abstract base class to be implemented by callers wanting to be notified
|
|
|
|
* that a refresh has occurred. Callers must ensure an observer is removed
|
|
|
|
* before it is destroyed.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DidRefresh() override;
|
2014-09-10 05:40:51 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Redraw(const gfxRect&) override {
|
2014-11-14 07:03:50 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
void SynthesizeGLError(GLenum err) const;
|
|
|
|
void SynthesizeGLError(GLenum err, const char* fmt, ...) const MOZ_FORMAT_PRINTF(3, 4);
|
2010-05-15 17:55:45 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
void ErrorInvalidEnum(const char* fmt = 0, ...) const MOZ_FORMAT_PRINTF(2, 3);
|
|
|
|
void ErrorInvalidOperation(const char* fmt = 0, ...) const MOZ_FORMAT_PRINTF(2, 3);
|
|
|
|
void ErrorInvalidValue(const char* fmt = 0, ...) const MOZ_FORMAT_PRINTF(2, 3);
|
|
|
|
void ErrorInvalidFramebufferOperation(const char* fmt = 0, ...) const MOZ_FORMAT_PRINTF(2, 3);
|
|
|
|
void ErrorInvalidEnumInfo(const char* info, GLenum enumValue) const;
|
2015-02-19 03:57:05 +03:00
|
|
|
void ErrorInvalidEnumInfo(const char* info, const char* funcName,
|
2017-12-19 05:30:56 +03:00
|
|
|
GLenum enumValue) const;
|
|
|
|
void ErrorOutOfMemory(const char* fmt = 0, ...) const MOZ_FORMAT_PRINTF(2, 3);
|
|
|
|
void ErrorImplementationBug(const char* fmt = 0, ...) const MOZ_FORMAT_PRINTF(2, 3);
|
2012-01-25 01:12:31 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
void ErrorInvalidEnumArg(const char* funcName, const char* argName, GLenum val) const;
|
2016-12-22 06:42:07 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
static const char* ErrorName(GLenum error);
|
2014-06-03 00:30:00 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return displayable name for GLenum.
|
|
|
|
* This version is like gl::GLenumToStr but with out the GL_ prefix to
|
|
|
|
* keep consistency with how errors are reported from WebGL.
|
2016-12-22 06:42:07 +03:00
|
|
|
* Returns hex formatted version of glenum if glenum is unknown.
|
2014-06-03 00:30:00 +04:00
|
|
|
*/
|
2016-12-22 06:42:07 +03:00
|
|
|
static void EnumName(GLenum val, nsCString* out_name);
|
2014-06-03 00:30:00 +04:00
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
void DummyReadFramebufferOperation(const char* funcName);
|
2012-01-25 01:12:31 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLTexture* ActiveBoundTextureForTarget(const TexTarget texTarget) const {
|
2014-10-14 03:42:20 +04:00
|
|
|
switch (texTarget.get()) {
|
2014-11-14 07:03:50 +03:00
|
|
|
case LOCAL_GL_TEXTURE_2D:
|
|
|
|
return mBound2DTextures[mActiveTexture];
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP:
|
|
|
|
return mBoundCubeMapTextures[mActiveTexture];
|
|
|
|
case LOCAL_GL_TEXTURE_3D:
|
|
|
|
return mBound3DTextures[mActiveTexture];
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_TEXTURE_2D_ARRAY:
|
|
|
|
return mBound2DArrayTextures[mActiveTexture];
|
2014-11-14 07:03:50 +03:00
|
|
|
default:
|
2016-05-13 23:34:41 +03:00
|
|
|
MOZ_CRASH("GFX: bad target");
|
2014-10-14 03:42:20 +04:00
|
|
|
}
|
2014-09-03 23:17:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Use this function when you have the texture image target, for example:
|
|
|
|
* GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP_[POSITIVE|NEGATIVE]_[X|Y|Z], and
|
|
|
|
* not the actual texture binding target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
|
|
|
|
*/
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLTexture*
|
|
|
|
ActiveBoundTextureForTexImageTarget(const TexImageTarget texImgTarget) const
|
|
|
|
{
|
2014-09-19 03:14:22 +04:00
|
|
|
const TexTarget texTarget = TexImageTargetToTexTarget(texImgTarget);
|
2014-11-14 07:03:50 +03:00
|
|
|
return ActiveBoundTextureForTarget(texTarget);
|
2010-08-24 01:03:35 +04:00
|
|
|
}
|
|
|
|
|
2016-01-21 09:49:41 +03:00
|
|
|
void InvalidateResolveCacheForTextureWithTexUnit(const GLuint);
|
|
|
|
|
2015-12-18 09:52:17 +03:00
|
|
|
already_AddRefed<Layer>
|
|
|
|
GetCanvasLayer(nsDisplayListBuilder* builder, Layer* oldLayer,
|
2017-09-16 01:06:56 +03:00
|
|
|
LayerManager* manager) override;
|
2017-10-28 13:07:27 +03:00
|
|
|
|
|
|
|
bool
|
|
|
|
UpdateWebRenderCanvasData(nsDisplayListBuilder* aBuilder,
|
|
|
|
WebRenderCanvasData* aCanvasData) override;
|
|
|
|
|
2017-08-18 10:13:29 +03:00
|
|
|
bool
|
2017-08-03 08:55:14 +03:00
|
|
|
InitializeCanvasRenderer(nsDisplayListBuilder* aBuilder,
|
2017-09-16 01:06:56 +03:00
|
|
|
CanvasRenderer* aRenderer) override;
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
// Note that 'clean' here refers to its invalidation state, not the
|
|
|
|
// contents of the buffer.
|
2015-03-21 19:28:04 +03:00
|
|
|
void MarkContextClean() override { mInvalidated = false; }
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2015-09-17 06:37:05 +03:00
|
|
|
void MarkContextCleanForFrameCapture() override { mCapturedFrameInvalidated = false; }
|
|
|
|
|
|
|
|
bool IsContextCleanForFrameCapture() override { return !mCapturedFrameInvalidated; }
|
|
|
|
|
2013-09-04 16:14:50 +04:00
|
|
|
gl::GLContext* GL() const { return gl; }
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2013-09-04 16:14:50 +04:00
|
|
|
bool IsPremultAlpha() const { return mOptions.premultipliedAlpha; }
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2015-05-13 09:04:41 +03:00
|
|
|
bool IsPreservingDrawingBuffer() const { return mOptions.preserveDrawingBuffer; }
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
bool PresentScreenBuffer();
|
|
|
|
|
2016-08-20 00:44:37 +03:00
|
|
|
// Prepare the context for capture before compositing
|
|
|
|
void BeginComposition();
|
|
|
|
// Clean up the context after captured for compositing
|
|
|
|
void EndComposition();
|
|
|
|
|
2010-06-04 23:03:37 +04:00
|
|
|
// a number that increments every time we have an event that causes
|
|
|
|
// all context resources to be lost.
|
2016-10-04 04:33:52 +03:00
|
|
|
uint32_t Generation() const { return mGeneration.value(); }
|
2010-08-24 01:03:53 +04:00
|
|
|
|
2013-02-14 03:26:24 +04: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.
|
2017-12-19 05:30:56 +03:00
|
|
|
void ForceClearFramebufferWithDefaultValues(GLbitfield bufferBits,
|
|
|
|
bool fakeNoAlpha) const;
|
2011-05-20 23:53:53 +04:00
|
|
|
|
2014-08-22 20:55:00 +04:00
|
|
|
void RunContextLossTimer();
|
2014-06-03 01:40:15 +04:00
|
|
|
void UpdateContextLossStatus();
|
|
|
|
void EnqueueUpdateContextLossStatus();
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2014-06-03 01:40:15 +04:00
|
|
|
bool TryToRestoreContext();
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
void AssertCachedBindings() const;
|
|
|
|
void AssertCachedGlobalState() const;
|
2014-05-22 06:03:09 +04:00
|
|
|
|
2015-10-05 18:28:25 +03:00
|
|
|
dom::HTMLCanvasElement* GetCanvas() const { return mCanvasElement; }
|
2017-08-23 17:39:40 +03:00
|
|
|
nsIDocument* GetOwnerDoc() const;
|
2015-10-12 06:21:03 +03:00
|
|
|
|
|
|
|
// WebIDL WebGLRenderingContext API
|
|
|
|
void Commit();
|
|
|
|
void GetCanvas(Nullable<dom::OwningHTMLCanvasElementOrOffscreenCanvas>& retval);
|
2017-12-19 05:30:56 +03:00
|
|
|
private:
|
2017-12-22 04:14:54 +03:00
|
|
|
gfx::IntSize DrawingBufferSize(const char* funcName);
|
2017-12-19 05:30:56 +03:00
|
|
|
public:
|
2017-12-22 04:14:54 +03:00
|
|
|
GLsizei DrawingBufferWidth(const char* const funcName = "drawingBufferWidth") {
|
|
|
|
return DrawingBufferSize(funcName).width;
|
|
|
|
}
|
|
|
|
GLsizei DrawingBufferHeight(const char* const funcName = "drawingBufferHeight") {
|
|
|
|
return DrawingBufferSize(funcName).height;
|
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2015-08-18 01:10:12 +03:00
|
|
|
layers::LayersBackend GetCompositorBackendType() const;
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
void
|
|
|
|
GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& retval);
|
2013-09-04 16:14:44 +04:00
|
|
|
|
|
|
|
bool IsContextLost() const { return mContextStatus != ContextNotLost; }
|
2016-11-16 22:10:22 +03:00
|
|
|
void GetSupportedExtensions(dom::Nullable< nsTArray<nsString> >& retval,
|
|
|
|
dom::CallerType callerType);
|
2014-11-14 07:03:50 +03:00
|
|
|
void GetExtension(JSContext* cx, const nsAString& name,
|
2016-11-16 22:10:22 +03:00
|
|
|
JS::MutableHandle<JSObject*> retval,
|
|
|
|
dom::CallerType callerType, ErrorResult& rv);
|
2016-11-02 00:58:07 +03:00
|
|
|
void AttachShader(WebGLProgram& prog, WebGLShader& shader);
|
|
|
|
void BindAttribLocation(WebGLProgram& prog, GLuint location,
|
2012-05-04 20:38:44 +04:00
|
|
|
const nsAString& name);
|
2014-11-14 07:03:50 +03:00
|
|
|
void BindFramebuffer(GLenum target, WebGLFramebuffer* fb);
|
|
|
|
void BindRenderbuffer(GLenum target, WebGLRenderbuffer* fb);
|
|
|
|
void BindVertexArray(WebGLVertexArray* vao);
|
2013-09-04 16:14:50 +04:00
|
|
|
void BlendColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
|
2013-09-04 16:14:43 +04: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 20:38:44 +04:00
|
|
|
void ColorMask(WebGLboolean r, WebGLboolean g, WebGLboolean b, WebGLboolean a);
|
2016-11-02 00:58:07 +03:00
|
|
|
void CompileShader(WebGLShader& shader);
|
2015-01-16 02:40:39 +03:00
|
|
|
void CompileShaderANGLE(WebGLShader* shader);
|
|
|
|
void CompileShaderBypass(WebGLShader* shader, const nsCString& shaderSource);
|
2012-05-04 20:38:44 +04:00
|
|
|
already_AddRefed<WebGLFramebuffer> CreateFramebuffer();
|
|
|
|
already_AddRefed<WebGLProgram> CreateProgram();
|
|
|
|
already_AddRefed<WebGLRenderbuffer> CreateRenderbuffer();
|
2013-09-04 16:14:43 +04:00
|
|
|
already_AddRefed<WebGLShader> CreateShader(GLenum type);
|
2013-06-28 01:07:21 +04:00
|
|
|
already_AddRefed<WebGLVertexArray> CreateVertexArray();
|
2013-09-04 16:14:43 +04:00
|
|
|
void CullFace(GLenum face);
|
2014-11-14 07:03:50 +03:00
|
|
|
void DeleteFramebuffer(WebGLFramebuffer* fb);
|
|
|
|
void DeleteProgram(WebGLProgram* prog);
|
|
|
|
void DeleteRenderbuffer(WebGLRenderbuffer* rb);
|
|
|
|
void DeleteShader(WebGLShader* shader);
|
|
|
|
void DeleteVertexArray(WebGLVertexArray* vao);
|
2013-09-04 16:14:43 +04:00
|
|
|
void DepthFunc(GLenum func);
|
2012-05-04 20:38:44 +04:00
|
|
|
void DepthMask(WebGLboolean b);
|
2013-09-04 16:14:43 +04:00
|
|
|
void DepthRange(GLclampf zNear, GLclampf zFar);
|
2016-11-02 00:58:07 +03:00
|
|
|
void DetachShader(WebGLProgram& prog, const WebGLShader& shader);
|
2013-07-17 20:13:38 +04:00
|
|
|
void DrawBuffers(const dom::Sequence<GLenum>& buffers);
|
2013-09-04 16:14:50 +04:00
|
|
|
void Flush();
|
|
|
|
void Finish();
|
2013-09-04 16:14:43 +04:00
|
|
|
void FramebufferRenderbuffer(GLenum target, GLenum attachment,
|
2014-11-14 07:03:50 +03:00
|
|
|
GLenum rbTarget, WebGLRenderbuffer* rb);
|
2013-09-04 16:14:43 +04:00
|
|
|
void FramebufferTexture2D(GLenum target, GLenum attachment,
|
2014-11-14 07:03:50 +03:00
|
|
|
GLenum texImageTarget, WebGLTexture* tex,
|
2013-09-04 16:14:43 +04:00
|
|
|
GLint level);
|
2014-09-25 19:21:33 +04:00
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
void FrontFace(GLenum mode);
|
2016-11-02 00:58:07 +03:00
|
|
|
already_AddRefed<WebGLActiveInfo> GetActiveAttrib(const WebGLProgram& prog,
|
2013-09-04 16:14:43 +04:00
|
|
|
GLuint index);
|
2016-11-02 00:58:07 +03:00
|
|
|
already_AddRefed<WebGLActiveInfo> GetActiveUniform(const WebGLProgram& prog,
|
2013-09-04 16:14:43 +04:00
|
|
|
GLuint index);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
GetAttachedShaders(const WebGLProgram& prog,
|
2015-10-18 08:24:48 +03:00
|
|
|
dom::Nullable<nsTArray<RefPtr<WebGLShader>>>& retval);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
GLint GetAttribLocation(const WebGLProgram& prog, const nsAString& name);
|
2013-09-04 16:14:43 +04:00
|
|
|
JS::Value GetBufferParameter(GLenum target, GLenum pname);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
void GetBufferParameter(JSContext*, GLenum target, GLenum pname,
|
|
|
|
JS::MutableHandle<JS::Value> retval)
|
|
|
|
{
|
2014-06-12 00:26:52 +04:00
|
|
|
retval.set(GetBufferParameter(target, pname));
|
2012-05-31 22:16:48 +04:00
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
GLenum GetError();
|
2015-08-06 09:31:00 +03:00
|
|
|
virtual JS::Value GetFramebufferAttachmentParameter(JSContext* cx, GLenum target,
|
|
|
|
GLenum attachment, GLenum pname,
|
|
|
|
ErrorResult& rv);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
void GetFramebufferAttachmentParameter(JSContext* cx, GLenum target,
|
|
|
|
GLenum attachment, GLenum pname,
|
2014-06-12 00:26:52 +04:00
|
|
|
JS::MutableHandle<JS::Value> retval,
|
2014-11-14 07:03:50 +03:00
|
|
|
ErrorResult& rv)
|
|
|
|
{
|
2014-06-12 00:26:52 +04:00
|
|
|
retval.set(GetFramebufferAttachmentParameter(cx, target, attachment,
|
|
|
|
pname, rv));
|
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
JS::Value GetProgramParameter(const WebGLProgram& prog, GLenum pname);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
void GetProgramParameter(JSContext*, const WebGLProgram& prog, GLenum pname,
|
2014-11-14 07:03:50 +03:00
|
|
|
JS::MutableHandle<JS::Value> retval)
|
|
|
|
{
|
2014-06-12 00:26:52 +04:00
|
|
|
retval.set(GetProgramParameter(prog, pname));
|
2012-05-31 22:16:48 +04:00
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
void GetProgramInfoLog(const WebGLProgram& prog, nsACString& retval);
|
|
|
|
void GetProgramInfoLog(const WebGLProgram& prog, nsAString& retval);
|
2013-09-04 16:14:43 +04:00
|
|
|
JS::Value GetRenderbufferParameter(GLenum target, GLenum pname);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
void GetRenderbufferParameter(JSContext*, GLenum target, GLenum pname,
|
|
|
|
JS::MutableHandle<JS::Value> retval)
|
|
|
|
{
|
2014-06-12 00:26:52 +04:00
|
|
|
retval.set(GetRenderbufferParameter(target, pname));
|
2012-05-31 22:16:48 +04:00
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
JS::Value GetShaderParameter(const WebGLShader& shader, GLenum pname);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
void GetShaderParameter(JSContext*, const WebGLShader& shader, GLenum pname,
|
2014-11-14 07:03:50 +03:00
|
|
|
JS::MutableHandle<JS::Value> retval)
|
|
|
|
{
|
2014-06-12 00:26:52 +04:00
|
|
|
retval.set(GetShaderParameter(shader, pname));
|
2012-05-31 22:16:48 +04:00
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
already_AddRefed<WebGLShaderPrecisionFormat>
|
2014-11-14 07:03:50 +03:00
|
|
|
GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype);
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
void GetShaderInfoLog(const WebGLShader& shader, nsACString& retval);
|
|
|
|
void GetShaderInfoLog(const WebGLShader& shader, nsAString& retval);
|
|
|
|
void GetShaderSource(const WebGLShader& shader, nsAString& retval);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
JS::Value GetUniform(JSContext* cx, const WebGLProgram& prog,
|
|
|
|
const WebGLUniformLocation& loc);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
void GetUniform(JSContext* cx, const WebGLProgram& prog,
|
|
|
|
const WebGLUniformLocation& loc,
|
2014-11-14 07:03:50 +03:00
|
|
|
JS::MutableHandle<JS::Value> retval)
|
|
|
|
{
|
|
|
|
retval.set(GetUniform(cx, prog, loc));
|
2014-06-12 00:26:52 +04:00
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
already_AddRefed<WebGLUniformLocation>
|
2016-11-02 00:58:07 +03:00
|
|
|
GetUniformLocation(const WebGLProgram& prog, const nsAString& name);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
void Hint(GLenum target, GLenum mode);
|
2016-11-30 05:30:28 +03:00
|
|
|
bool IsFramebuffer(const WebGLFramebuffer* fb);
|
|
|
|
bool IsProgram(const WebGLProgram* prog);
|
|
|
|
bool IsRenderbuffer(const WebGLRenderbuffer* rb);
|
|
|
|
bool IsShader(const WebGLShader* shader);
|
|
|
|
bool IsVertexArray(const WebGLVertexArray* vao);
|
2013-09-04 16:14:50 +04:00
|
|
|
void LineWidth(GLfloat width);
|
2016-11-02 00:58:07 +03:00
|
|
|
void LinkProgram(WebGLProgram& prog);
|
2013-09-04 16:14:43 +04:00
|
|
|
void PixelStorei(GLenum pname, GLint param);
|
2013-09-04 16:14:50 +04:00
|
|
|
void PolygonOffset(GLfloat factor, GLfloat units);
|
2016-02-25 02:54:50 +03:00
|
|
|
|
|
|
|
already_AddRefed<layers::SharedSurfaceTextureClient> GetVRFrame();
|
2016-12-23 04:08:35 +03:00
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
webgl::PackingInfo
|
|
|
|
ValidImplementationColorReadPI(const webgl::FormatUsageInfo* usage) const;
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
protected:
|
2017-02-01 23:43:37 +03:00
|
|
|
bool ReadPixels_SharedPrecheck(dom::CallerType aCallerType,
|
|
|
|
ErrorResult& out_error);
|
2016-07-05 06:35:20 +03:00
|
|
|
void ReadPixelsImpl(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
|
|
|
|
GLenum type, void* data, uint32_t dataLen);
|
|
|
|
bool DoReadPixelsAndConvert(const webgl::FormatInfo* srcFormat, GLint x, GLint y,
|
|
|
|
GLsizei width, GLsizei height, GLenum format,
|
2016-06-16 17:30:47 +03:00
|
|
|
GLenum destType, void* dest, uint32_t dataLen,
|
|
|
|
uint32_t rowStride);
|
2015-11-25 07:15:29 +03:00
|
|
|
public:
|
2016-08-10 03:16:09 +03:00
|
|
|
void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
|
|
|
|
GLenum type, const dom::Nullable<dom::ArrayBufferView>& maybeView,
|
2017-02-01 23:43:37 +03:00
|
|
|
dom::CallerType aCallerType, ErrorResult& rv)
|
2016-08-10 03:16:09 +03:00
|
|
|
{
|
|
|
|
const char funcName[] = "readPixels";
|
|
|
|
if (maybeView.IsNull()) {
|
|
|
|
ErrorInvalidValue("%s: `pixels` must not be null.", funcName);
|
|
|
|
return;
|
|
|
|
}
|
2017-02-01 23:43:37 +03:00
|
|
|
ReadPixels(x, y, width, height, format, type, maybeView.Value(), 0,
|
|
|
|
aCallerType, rv);
|
2016-08-10 03:16:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
|
2017-02-01 23:43:37 +03:00
|
|
|
GLenum type, WebGLsizeiptr offset,
|
|
|
|
dom::CallerType, ErrorResult& out_error);
|
2016-10-11 01:34:18 +03:00
|
|
|
|
|
|
|
void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
|
|
|
|
GLenum type, const dom::ArrayBufferView& dstData, GLuint dstOffset,
|
2017-02-01 23:43:37 +03:00
|
|
|
dom::CallerType, ErrorResult& out_error);
|
2016-10-11 01:34:18 +03:00
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
////
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
void RenderbufferStorage(GLenum target, GLenum internalFormat,
|
2013-09-04 16:14:43 +04:00
|
|
|
GLsizei width, GLsizei height);
|
2015-02-19 03:57:05 +03:00
|
|
|
protected:
|
|
|
|
void RenderbufferStorage_base(const char* funcName, GLenum target,
|
|
|
|
GLsizei samples, GLenum internalformat,
|
|
|
|
GLsizei width, GLsizei height);
|
|
|
|
public:
|
2013-09-04 16:14:50 +04:00
|
|
|
void SampleCoverage(GLclampf value, WebGLboolean invert);
|
2013-09-04 16:14:43 +04:00
|
|
|
void Scissor(GLint x, GLint y, GLsizei width, GLsizei height);
|
2016-11-02 00:58:07 +03:00
|
|
|
void ShaderSource(WebGLShader& shader, const nsAString& source);
|
2013-09-04 16:14:43 +04:00
|
|
|
void StencilFunc(GLenum func, GLint ref, GLuint mask);
|
2014-11-14 07:03:50 +03:00
|
|
|
void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
|
2013-09-04 16:14:43 +04:00
|
|
|
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);
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
//////
|
|
|
|
|
2016-10-14 02:15:16 +03:00
|
|
|
void Uniform1f(WebGLUniformLocation* loc, GLfloat x);
|
|
|
|
void Uniform2f(WebGLUniformLocation* loc, GLfloat x, GLfloat y);
|
|
|
|
void Uniform3f(WebGLUniformLocation* loc, GLfloat x, GLfloat y, GLfloat z);
|
|
|
|
void Uniform4f(WebGLUniformLocation* loc, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
|
|
|
|
|
2014-10-24 02:10:57 +04:00
|
|
|
void Uniform1i(WebGLUniformLocation* loc, GLint x);
|
|
|
|
void Uniform2i(WebGLUniformLocation* loc, GLint x, GLint y);
|
|
|
|
void Uniform3i(WebGLUniformLocation* loc, GLint x, GLint y, GLint z);
|
2016-07-14 22:13:47 +03:00
|
|
|
void Uniform4i(WebGLUniformLocation* loc, GLint x, GLint y, GLint z, GLint w);
|
2014-10-24 02:10:57 +04:00
|
|
|
|
2016-10-14 02:15:16 +03:00
|
|
|
void Uniform1ui(WebGLUniformLocation* loc, GLuint v0);
|
|
|
|
void Uniform2ui(WebGLUniformLocation* loc, GLuint v0, GLuint v1);
|
|
|
|
void Uniform3ui(WebGLUniformLocation* loc, GLuint v0, GLuint v1, GLuint v2);
|
|
|
|
void Uniform4ui(WebGLUniformLocation* loc, GLuint v0, GLuint v1, GLuint v2,
|
|
|
|
GLuint v3);
|
2014-10-24 02:10:57 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
//////////////////////////
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2016-10-14 02:15:16 +03:00
|
|
|
typedef dom::Float32ArrayOrUnrestrictedFloatSequence Float32ListU;
|
|
|
|
typedef dom::Int32ArrayOrLongSequence Int32ListU;
|
|
|
|
typedef dom::Uint32ArrayOrUnsignedLongSequence Uint32ListU;
|
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
protected:
|
2016-10-14 02:15:16 +03:00
|
|
|
template<typename elemT, typename viewT>
|
2016-07-14 22:13:47 +03:00
|
|
|
struct Arr {
|
2016-10-14 02:15:16 +03:00
|
|
|
const size_t elemCount;
|
|
|
|
const elemT* const elemBytes;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static size_t ComputeAndReturnLength(const viewT& view) {
|
|
|
|
view.ComputeLengthAndData();
|
|
|
|
return view.LengthAllowShared();
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit Arr(const viewT& view)
|
|
|
|
: elemCount(ComputeAndReturnLength(view))
|
|
|
|
, elemBytes(view.DataAllowShared())
|
|
|
|
{ }
|
2016-07-14 22:13:47 +03:00
|
|
|
|
2016-10-14 02:15:16 +03:00
|
|
|
explicit Arr(const dom::Sequence<elemT>& seq)
|
|
|
|
: elemCount(seq.Length())
|
|
|
|
, elemBytes(seq.Elements())
|
|
|
|
{ }
|
|
|
|
|
|
|
|
Arr(size_t _elemCount, const elemT* _elemBytes)
|
|
|
|
: elemCount(_elemCount)
|
|
|
|
, elemBytes(_elemBytes)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
static Arr From(const Float32ListU& list) {
|
|
|
|
if (list.IsFloat32Array())
|
|
|
|
return Arr(list.GetAsFloat32Array());
|
|
|
|
|
|
|
|
return Arr(list.GetAsUnrestrictedFloatSequence());
|
2016-07-14 22:13:47 +03:00
|
|
|
}
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2016-10-14 02:15:16 +03:00
|
|
|
static Arr From(const Int32ListU& list) {
|
|
|
|
if (list.IsInt32Array())
|
|
|
|
return Arr(list.GetAsInt32Array());
|
|
|
|
|
|
|
|
return Arr(list.GetAsLongSequence());
|
|
|
|
}
|
|
|
|
|
|
|
|
static Arr From(const Uint32ListU& list) {
|
|
|
|
if (list.IsUint32Array())
|
|
|
|
return Arr(list.GetAsUint32Array());
|
|
|
|
|
|
|
|
return Arr(list.GetAsUnsignedLongSequence());
|
2016-07-14 22:13:47 +03:00
|
|
|
}
|
|
|
|
};
|
2014-01-23 07:59:33 +04:00
|
|
|
|
2016-10-14 02:15:16 +03:00
|
|
|
typedef Arr<GLfloat, dom::Float32Array> Float32Arr;
|
|
|
|
typedef Arr<GLint, dom::Int32Array> Int32Arr;
|
|
|
|
typedef Arr<GLuint, dom::Uint32Array> Uint32Arr;
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
////////////////
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
void UniformNfv(const char* funcName, uint8_t N, WebGLUniformLocation* loc,
|
2016-10-14 02:15:16 +03:00
|
|
|
const Float32Arr& arr, GLuint elemOffset, GLuint elemCountOverride);
|
|
|
|
void UniformNiv(const char* funcName, uint8_t N, WebGLUniformLocation* loc,
|
|
|
|
const Int32Arr& arr, GLuint elemOffset, GLuint elemCountOverride);
|
|
|
|
void UniformNuiv(const char* funcName, uint8_t N, WebGLUniformLocation* loc,
|
|
|
|
const Uint32Arr& arr, GLuint elemOffset, GLuint elemCountOverride);
|
2016-07-14 22:13:47 +03:00
|
|
|
|
|
|
|
void UniformMatrixAxBfv(const char* funcName, uint8_t A, uint8_t B,
|
|
|
|
WebGLUniformLocation* loc, bool transpose,
|
2016-10-14 02:15:16 +03:00
|
|
|
const Float32Arr& arr, GLuint elemOffset,
|
|
|
|
GLuint elemCountOverride);
|
2016-07-14 22:13:47 +03:00
|
|
|
|
|
|
|
////////////////
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
public:
|
2016-10-14 02:15:16 +03:00
|
|
|
#define FOO(N) \
|
|
|
|
void Uniform ## N ## fv(WebGLUniformLocation* loc, const Float32ListU& list, \
|
|
|
|
GLuint elemOffset = 0, GLuint elemCountOverride = 0) \
|
|
|
|
{ \
|
|
|
|
UniformNfv("uniform" #N "fv", N, loc, Float32Arr::From(list), elemOffset, \
|
|
|
|
elemCountOverride); \
|
|
|
|
}
|
|
|
|
|
|
|
|
FOO(1)
|
|
|
|
FOO(2)
|
|
|
|
FOO(3)
|
|
|
|
FOO(4)
|
|
|
|
|
|
|
|
#undef FOO
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
//////
|
|
|
|
|
2016-10-14 02:15:16 +03:00
|
|
|
#define FOO(N) \
|
|
|
|
void Uniform ## N ## iv(WebGLUniformLocation* loc, const Int32ListU& list, \
|
|
|
|
GLuint elemOffset = 0, GLuint elemCountOverride = 0) \
|
|
|
|
{ \
|
|
|
|
UniformNiv("uniform" #N "iv", N, loc, Int32Arr::From(list), elemOffset, \
|
|
|
|
elemCountOverride); \
|
|
|
|
}
|
|
|
|
|
|
|
|
FOO(1)
|
|
|
|
FOO(2)
|
|
|
|
FOO(3)
|
|
|
|
FOO(4)
|
|
|
|
|
|
|
|
#undef FOO
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
//////
|
|
|
|
|
2016-10-14 02:15:16 +03:00
|
|
|
#define FOO(N) \
|
|
|
|
void Uniform ## N ## uiv(WebGLUniformLocation* loc, const Uint32ListU& list, \
|
|
|
|
GLuint elemOffset = 0, GLuint elemCountOverride = 0) \
|
|
|
|
{ \
|
|
|
|
UniformNuiv("uniform" #N "uiv", N, loc, Uint32Arr::From(list), elemOffset, \
|
|
|
|
elemCountOverride); \
|
|
|
|
}
|
|
|
|
|
|
|
|
FOO(1)
|
|
|
|
FOO(2)
|
|
|
|
FOO(3)
|
|
|
|
FOO(4)
|
|
|
|
|
|
|
|
#undef FOO
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
|
|
|
#define FOO(X,A,B) \
|
|
|
|
void UniformMatrix ## X ## fv(WebGLUniformLocation* loc, bool transpose, \
|
|
|
|
const Float32ListU& list, GLuint elemOffset = 0, \
|
|
|
|
GLuint elemCountOverride = 0) \
|
|
|
|
{ \
|
|
|
|
UniformMatrixAxBfv("uniformMatrix" #X "fv", A, B, loc, transpose, \
|
|
|
|
Float32Arr::From(list), elemOffset, elemCountOverride); \
|
|
|
|
}
|
|
|
|
|
|
|
|
FOO(2,2,2)
|
|
|
|
FOO(2x3,2,3)
|
|
|
|
FOO(2x4,2,4)
|
|
|
|
|
|
|
|
FOO(3x2,3,2)
|
|
|
|
FOO(3,3,3)
|
|
|
|
FOO(3x4,3,4)
|
|
|
|
|
|
|
|
FOO(4x2,4,2)
|
|
|
|
FOO(4x3,4,3)
|
|
|
|
FOO(4,4,4)
|
|
|
|
|
|
|
|
#undef FOO
|
2016-07-14 22:13:47 +03:00
|
|
|
|
|
|
|
////////////////////////////////////
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
void UseProgram(WebGLProgram* prog);
|
2015-01-16 02:40:39 +03:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
bool ValidateAttribArraySetter(const char* name, uint32_t count,
|
|
|
|
uint32_t arrayLength);
|
2015-01-16 02:40:39 +03:00
|
|
|
bool ValidateUniformLocation(WebGLUniformLocation* loc, const char* funcName);
|
2014-10-24 02:10:57 +04:00
|
|
|
bool ValidateUniformSetter(WebGLUniformLocation* loc, uint8_t setterSize,
|
2016-07-14 22:13:47 +03:00
|
|
|
GLenum setterType, const char* funcName);
|
2014-10-24 02:10:57 +04:00
|
|
|
bool ValidateUniformArraySetter(WebGLUniformLocation* loc,
|
|
|
|
uint8_t setterElemSize, GLenum setterType,
|
2016-07-14 22:13:47 +03:00
|
|
|
uint32_t setterArraySize, const char* funcName,
|
|
|
|
uint32_t* out_numElementsToUpload);
|
2014-10-24 02:10:57 +04:00
|
|
|
bool ValidateUniformMatrixArraySetter(WebGLUniformLocation* loc,
|
2015-03-23 04:29:32 +03:00
|
|
|
uint8_t setterCols,
|
|
|
|
uint8_t setterRows,
|
|
|
|
GLenum setterType,
|
2016-07-14 22:13:47 +03:00
|
|
|
uint32_t setterArraySize,
|
2014-10-24 02:10:57 +04:00
|
|
|
bool setterTranspose,
|
2016-07-14 22:13:47 +03:00
|
|
|
const char* funcName,
|
|
|
|
uint32_t* out_numElementsToUpload);
|
2016-11-02 00:58:07 +03:00
|
|
|
void ValidateProgram(const WebGLProgram& prog);
|
2014-11-14 07:03:50 +03:00
|
|
|
bool ValidateUniformLocation(const char* info, WebGLUniformLocation* loc);
|
2013-03-05 04:44:31 +04:00
|
|
|
bool ValidateSamplerUniformSetter(const char* info,
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLUniformLocation* loc, GLint value);
|
2013-09-04 16:14:43 +04:00
|
|
|
void Viewport(GLint x, GLint y, GLsizei width, GLsizei height);
|
2014-06-03 01:40:15 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// WEBGL_lose_context
|
|
|
|
public:
|
|
|
|
void LoseContext();
|
|
|
|
void RestoreContext();
|
2013-08-07 04:05:51 +04:00
|
|
|
|
2013-08-20 19:36:19 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Buffer Objects (WebGLContextBuffers.cpp)
|
2014-12-05 10:04:55 +03:00
|
|
|
void BindBuffer(GLenum target, WebGLBuffer* buffer);
|
2014-11-14 07:03:50 +03:00
|
|
|
void BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buf);
|
|
|
|
void BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buf,
|
2013-08-20 19:36:20 +04:00
|
|
|
WebGLintptr offset, WebGLsizeiptr size);
|
2014-12-05 10:04:55 +03:00
|
|
|
|
|
|
|
private:
|
2016-10-12 01:40:34 +03:00
|
|
|
void BufferDataImpl(GLenum target, size_t dataLen, const uint8_t* data, GLenum usage);
|
2014-12-05 10:04:55 +03:00
|
|
|
|
|
|
|
public:
|
2013-09-04 16:14:43 +04:00
|
|
|
void BufferData(GLenum target, WebGLsizeiptr size, GLenum usage);
|
2016-11-02 00:58:07 +03:00
|
|
|
void BufferData(GLenum target, const dom::Nullable<dom::ArrayBuffer>& maybeSrc,
|
|
|
|
GLenum usage);
|
2016-10-12 01:40:34 +03:00
|
|
|
void BufferData(GLenum target, const dom::ArrayBufferView& srcData, GLenum usage,
|
|
|
|
GLuint srcElemOffset = 0, GLuint srcElemCountOverride = 0);
|
2014-12-05 10:04:55 +03:00
|
|
|
|
|
|
|
private:
|
2016-10-12 01:40:34 +03:00
|
|
|
void BufferSubDataImpl(GLenum target, WebGLsizeiptr dstByteOffset,
|
|
|
|
size_t srcDataLen, const uint8_t* srcData);
|
2014-12-05 10:04:55 +03:00
|
|
|
|
|
|
|
public:
|
2016-10-12 01:40:34 +03:00
|
|
|
void BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
|
|
|
|
const dom::ArrayBufferView& src, GLuint srcElemOffset = 0,
|
|
|
|
GLuint srcElemCountOverride = 0);
|
|
|
|
void BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
|
2016-11-02 00:58:07 +03:00
|
|
|
const dom::ArrayBuffer& src);
|
2016-10-12 01:40:34 +03:00
|
|
|
void BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
|
|
|
|
const dom::SharedArrayBuffer& src);
|
|
|
|
|
2013-08-20 19:36:19 +04:00
|
|
|
already_AddRefed<WebGLBuffer> CreateBuffer();
|
2014-11-14 07:03:50 +03:00
|
|
|
void DeleteBuffer(WebGLBuffer* buf);
|
|
|
|
bool IsBuffer(WebGLBuffer* buf);
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2014-11-26 05:00:06 +03:00
|
|
|
protected:
|
|
|
|
// bound buffer state
|
2013-08-20 19:36:19 +04:00
|
|
|
WebGLRefPtr<WebGLBuffer> mBoundArrayBuffer;
|
2014-12-05 10:04:55 +03:00
|
|
|
WebGLRefPtr<WebGLBuffer> mBoundCopyReadBuffer;
|
|
|
|
WebGLRefPtr<WebGLBuffer> mBoundCopyWriteBuffer;
|
|
|
|
WebGLRefPtr<WebGLBuffer> mBoundPixelPackBuffer;
|
|
|
|
WebGLRefPtr<WebGLBuffer> mBoundPixelUnpackBuffer;
|
|
|
|
WebGLRefPtr<WebGLBuffer> mBoundUniformBuffer;
|
2013-08-20 19:36:20 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
std::vector<IndexedBufferBinding> mIndexedUniformBufferBindings;
|
2014-11-26 05:00:06 +03:00
|
|
|
|
2014-12-05 10:04:55 +03:00
|
|
|
WebGLRefPtr<WebGLBuffer>& GetBufferSlotByTarget(GLenum target);
|
|
|
|
WebGLRefPtr<WebGLBuffer>& GetBufferSlotByTargetIndexed(GLenum target,
|
2014-11-26 05:00:06 +03:00
|
|
|
GLuint index);
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2014-11-03 08:35:04 +03:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Queries (WebGL2ContextQueries.cpp)
|
|
|
|
protected:
|
2016-10-04 04:33:52 +03:00
|
|
|
WebGLRefPtr<WebGLQuery> mQuerySlot_SamplesPassed;
|
|
|
|
WebGLRefPtr<WebGLQuery> mQuerySlot_TFPrimsWritten;
|
|
|
|
WebGLRefPtr<WebGLQuery> mQuerySlot_TimeElapsed;
|
|
|
|
|
|
|
|
WebGLRefPtr<WebGLQuery>*
|
|
|
|
ValidateQuerySlotByTarget(const char* funcName, GLenum target);
|
|
|
|
|
|
|
|
public:
|
|
|
|
already_AddRefed<WebGLQuery> CreateQuery(const char* funcName = nullptr);
|
|
|
|
void DeleteQuery(WebGLQuery* query, const char* funcName = nullptr);
|
|
|
|
bool IsQuery(const WebGLQuery* query, const char* funcName = nullptr);
|
2016-11-02 00:58:07 +03:00
|
|
|
void BeginQuery(GLenum target, WebGLQuery& query, const char* funcName = nullptr);
|
2016-10-04 04:33:52 +03:00
|
|
|
void EndQuery(GLenum target, const char* funcName = nullptr);
|
|
|
|
void GetQuery(JSContext* cx, GLenum target, GLenum pname,
|
|
|
|
JS::MutableHandleValue retval, const char* funcName = nullptr);
|
2016-11-02 00:58:07 +03:00
|
|
|
void GetQueryParameter(JSContext* cx, const WebGLQuery& query, GLenum pname,
|
2016-10-04 04:33:52 +03:00
|
|
|
JS::MutableHandleValue retval, const char* funcName = nullptr);
|
2014-11-03 08:35:04 +03:00
|
|
|
|
|
|
|
|
2013-08-16 04:43:47 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// State and State Requests (WebGLContextState.cpp)
|
2017-12-21 04:58:27 +03:00
|
|
|
private:
|
|
|
|
void SetEnabled(const char* funcName, GLenum cap, bool enabled);
|
2013-08-16 04:43:47 +04:00
|
|
|
public:
|
2017-12-21 04:58:27 +03:00
|
|
|
void Disable(GLenum cap) { SetEnabled("disabled", cap, false); }
|
|
|
|
void Enable(GLenum cap) { SetEnabled("enabled", cap, true); }
|
2017-12-19 05:30:56 +03:00
|
|
|
bool GetStencilBits(GLint* const out_stencilBits) const;
|
2016-01-23 05:00:54 +03:00
|
|
|
bool GetChannelBits(const char* funcName, GLenum pname, GLint* const out_val);
|
2015-06-05 06:26:34 +03:00
|
|
|
virtual JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void GetParameter(JSContext* cx, GLenum pname,
|
2014-11-14 07:03:50 +03:00
|
|
|
JS::MutableHandle<JS::Value> retval, ErrorResult& rv)
|
|
|
|
{
|
2014-06-12 00:26:52 +04:00
|
|
|
retval.set(GetParameter(cx, pname, rv));
|
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index,
|
|
|
|
JS::MutableHandle<JS::Value> retval);
|
2013-09-04 16:14:43 +04:00
|
|
|
bool IsEnabled(GLenum cap);
|
2013-08-16 04:43:47 +04:00
|
|
|
|
|
|
|
private:
|
2013-08-23 04:11:27 +04:00
|
|
|
// State tracking slots
|
|
|
|
realGLboolean mDitherEnabled;
|
2013-08-23 04:11:40 +04:00
|
|
|
realGLboolean mRasterizerDiscardEnabled;
|
2013-08-23 04:11:27 +04:00
|
|
|
realGLboolean mScissorTestEnabled;
|
2015-09-24 22:21:05 +03:00
|
|
|
realGLboolean mDepthTestEnabled;
|
2015-03-12 04:23:56 +03:00
|
|
|
realGLboolean mStencilTestEnabled;
|
2016-12-20 03:13:33 +03:00
|
|
|
GLenum mGenerateMipmapHint;
|
2013-08-23 04:11:27 +04:00
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
bool ValidateCapabilityEnum(GLenum cap, const char* info);
|
|
|
|
realGLboolean* GetStateTrackingSlot(GLenum cap);
|
2013-08-16 04:43:47 +04:00
|
|
|
|
2017-06-22 21:32:00 +03:00
|
|
|
// Allocation debugging variables
|
|
|
|
mutable uint64_t mDataAllocGLCallCount;
|
|
|
|
|
|
|
|
void OnDataAllocCall() const {
|
|
|
|
mDataAllocGLCallCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t GetNumGLDataAllocCalls() const {
|
|
|
|
return mDataAllocGLCallCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnEndOfFrame() const;
|
|
|
|
|
2015-08-04 00:34:46 +03:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Texture funcions (WebGLContextTextures.cpp)
|
|
|
|
public:
|
|
|
|
void ActiveTexture(GLenum texUnit);
|
|
|
|
void BindTexture(GLenum texTarget, WebGLTexture* tex);
|
|
|
|
already_AddRefed<WebGLTexture> CreateTexture();
|
|
|
|
void DeleteTexture(WebGLTexture* tex);
|
|
|
|
void GenerateMipmap(GLenum texTarget);
|
|
|
|
|
|
|
|
void GetTexParameter(JSContext*, GLenum texTarget, GLenum pname,
|
|
|
|
JS::MutableHandle<JS::Value> retval)
|
|
|
|
{
|
|
|
|
retval.set(GetTexParameter(texTarget, pname));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsTexture(WebGLTexture* tex);
|
|
|
|
|
|
|
|
void TexParameterf(GLenum texTarget, GLenum pname, GLfloat param) {
|
2016-12-23 00:52:53 +03:00
|
|
|
TexParameter_base(texTarget, pname, FloatOrInt(param));
|
2015-08-04 00:34:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TexParameteri(GLenum texTarget, GLenum pname, GLint param) {
|
2016-12-23 00:52:53 +03:00
|
|
|
TexParameter_base(texTarget, pname, FloatOrInt(param));
|
2015-08-04 00:34:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
JS::Value GetTexParameter(GLenum texTarget, GLenum pname);
|
2016-12-23 00:52:53 +03:00
|
|
|
void TexParameter_base(GLenum texTarget, GLenum pname, const FloatOrInt& param);
|
2015-08-04 00:34:46 +03:00
|
|
|
|
|
|
|
virtual bool IsTexParamValid(GLenum pname) const;
|
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
////////////////////////////////////
|
|
|
|
|
2015-08-04 00:34:46 +03:00
|
|
|
public:
|
2017-07-18 21:02:57 +03:00
|
|
|
void CompressedTexImage2D(GLenum target, GLint level, GLenum internalFormat,
|
|
|
|
GLsizei width, GLsizei height, GLint border,
|
|
|
|
GLsizei imageSize, WebGLsizeiptr offset)
|
|
|
|
{
|
|
|
|
const char funcName[] = "compressedTexImage2D";
|
|
|
|
const uint8_t funcDims = 2;
|
|
|
|
const GLsizei depth = 1;
|
|
|
|
const TexImageSourceAdapter src(&offset, 0, 0);
|
|
|
|
CompressedTexImage(funcName, funcDims, target, level, internalFormat, width,
|
|
|
|
height, depth, border, src, Some(imageSize));
|
|
|
|
}
|
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
template<typename T>
|
|
|
|
void CompressedTexImage2D(GLenum target, GLint level, GLenum internalFormat,
|
2015-08-04 00:34:46 +03:00
|
|
|
GLsizei width, GLsizei height, GLint border,
|
2016-10-28 05:03:20 +03:00
|
|
|
const T& anySrc, GLuint viewElemOffset = 0,
|
|
|
|
GLuint viewElemLengthOverride = 0)
|
2016-10-12 04:54:59 +03:00
|
|
|
{
|
2016-10-21 04:03:40 +03:00
|
|
|
const char funcName[] = "compressedTexImage2D";
|
|
|
|
const uint8_t funcDims = 2;
|
|
|
|
const GLsizei depth = 1;
|
2016-11-23 04:17:12 +03:00
|
|
|
const TexImageSourceAdapter src(&anySrc, viewElemOffset, viewElemLengthOverride);
|
2016-10-21 04:03:40 +03:00
|
|
|
CompressedTexImage(funcName, funcDims, target, level, internalFormat, width,
|
2017-07-18 21:02:57 +03:00
|
|
|
height, depth, border, src, Nothing());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompressedTexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
|
|
|
|
GLsizei width, GLsizei height, GLenum unpackFormat,
|
|
|
|
GLsizei imageSize, WebGLsizeiptr offset)
|
|
|
|
{
|
|
|
|
const char funcName[] = "compressedTexSubImage2D";
|
|
|
|
const uint8_t funcDims = 2;
|
|
|
|
const GLint zOffset = 0;
|
|
|
|
const GLsizei depth = 1;
|
|
|
|
const TexImageSourceAdapter src(&offset, 0, 0);
|
|
|
|
CompressedTexSubImage(funcName, funcDims, target, level, xOffset, yOffset,
|
|
|
|
zOffset, width, height, depth, unpackFormat, src, Some(imageSize));
|
2016-10-12 04:54:59 +03:00
|
|
|
}
|
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
template<typename T>
|
|
|
|
void CompressedTexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
|
|
|
|
GLsizei width, GLsizei height, GLenum unpackFormat,
|
2016-10-28 05:03:20 +03:00
|
|
|
const T& anySrc, GLuint viewElemOffset = 0,
|
|
|
|
GLuint viewElemLengthOverride = 0)
|
2016-10-14 02:13:50 +03:00
|
|
|
{
|
2016-10-21 04:03:40 +03:00
|
|
|
const char funcName[] = "compressedTexSubImage2D";
|
|
|
|
const uint8_t funcDims = 2;
|
|
|
|
const GLint zOffset = 0;
|
|
|
|
const GLsizei depth = 1;
|
2016-11-23 04:17:12 +03:00
|
|
|
const TexImageSourceAdapter src(&anySrc, viewElemOffset, viewElemLengthOverride);
|
2016-10-21 04:03:40 +03:00
|
|
|
CompressedTexSubImage(funcName, funcDims, target, level, xOffset, yOffset,
|
2017-07-18 21:02:57 +03:00
|
|
|
zOffset, width, height, depth, unpackFormat, src, Nothing());
|
2016-10-14 02:13:50 +03:00
|
|
|
}
|
2016-10-12 04:54:59 +03:00
|
|
|
|
2016-08-10 03:16:09 +03:00
|
|
|
protected:
|
2016-10-21 04:03:40 +03:00
|
|
|
void CompressedTexImage(const char* funcName, uint8_t funcDims, GLenum target,
|
|
|
|
GLint level, GLenum internalFormat, GLsizei width,
|
|
|
|
GLsizei height, GLsizei depth, GLint border,
|
2017-07-18 21:02:57 +03:00
|
|
|
const TexImageSource& src, const Maybe<GLsizei>& expectedImageSize);
|
2016-10-21 04:03:40 +03:00
|
|
|
void CompressedTexSubImage(const char* funcName, uint8_t funcDims, GLenum target,
|
|
|
|
GLint level, GLint xOffset, GLint yOffset, GLint zOffset,
|
|
|
|
GLsizei width, GLsizei height, GLsizei depth,
|
2017-07-18 21:02:57 +03:00
|
|
|
GLenum unpackFormat, const TexImageSource& src,
|
|
|
|
const Maybe<GLsizei>& expectedImageSize);
|
2016-10-21 04:03:40 +03:00
|
|
|
////////////////////////////////////
|
2016-10-14 02:13:50 +03:00
|
|
|
|
|
|
|
public:
|
2016-10-21 04:03:40 +03:00
|
|
|
void CopyTexImage2D(GLenum target, GLint level, GLenum internalFormat, GLint x,
|
|
|
|
GLint y, GLsizei width, GLsizei height, GLint border);
|
2016-08-10 03:16:09 +03:00
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
void CopyTexSubImage2D(GLenum target, GLint level, GLint xOffset,
|
|
|
|
GLint yOffset, GLint x, GLint y, GLsizei width,
|
|
|
|
GLsizei height)
|
|
|
|
{
|
|
|
|
const char funcName[] = "copyTexSubImage2D";
|
|
|
|
const uint8_t funcDims = 2;
|
|
|
|
const GLint zOffset = 0;
|
|
|
|
CopyTexSubImage(funcName, funcDims, target, level, xOffset, yOffset, zOffset,
|
|
|
|
x, y, width, height);
|
|
|
|
}
|
2015-08-04 00:34:46 +03:00
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
protected:
|
|
|
|
void CopyTexSubImage(const char* funcName, uint8_t funcDims, GLenum target,
|
|
|
|
GLint level, GLint xOffset, GLint yOffset, GLint zOffset,
|
|
|
|
GLint x, GLint y, GLsizei width, GLsizei height);
|
2016-08-10 03:16:09 +03:00
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
////////////////////////////////////
|
|
|
|
// TexImage
|
2016-10-14 02:13:50 +03:00
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
// Implicit width/height uploads
|
2016-08-10 03:16:09 +03:00
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
void TexImage2D(GLenum target, GLint level, GLenum internalFormat,
|
|
|
|
GLenum unpackFormat, GLenum unpackType, const T& src,
|
|
|
|
ErrorResult& out_error)
|
2015-08-04 00:34:46 +03:00
|
|
|
{
|
2016-10-21 04:03:40 +03:00
|
|
|
GLsizei width = 0;
|
|
|
|
GLsizei height = 0;
|
|
|
|
GLint border = 0;
|
|
|
|
TexImage2D(target, level, internalFormat, width, height, border, unpackFormat,
|
|
|
|
unpackType, src, out_error);
|
|
|
|
}
|
2016-10-12 04:54:59 +03:00
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
template<typename T>
|
|
|
|
void TexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
|
|
|
|
GLenum unpackFormat, GLenum unpackType, const T& src,
|
|
|
|
ErrorResult& out_error)
|
|
|
|
{
|
|
|
|
GLsizei width = 0;
|
|
|
|
GLsizei height = 0;
|
|
|
|
TexSubImage2D(target, level, xOffset, yOffset, width, height, unpackFormat,
|
|
|
|
unpackType, src, out_error);
|
|
|
|
}
|
2016-10-12 04:54:59 +03:00
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void TexImage2D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
|
|
|
|
GLsizei height, GLint border, GLenum unpackFormat, GLenum unpackType,
|
|
|
|
const T& anySrc, ErrorResult& out_error)
|
|
|
|
{
|
2016-11-23 04:17:12 +03:00
|
|
|
const TexImageSourceAdapter src(&anySrc, &out_error);
|
2016-10-21 04:03:40 +03:00
|
|
|
TexImage2D(target, level, internalFormat, width, height, border, unpackFormat,
|
|
|
|
unpackType, src);
|
2016-08-10 03:16:09 +03:00
|
|
|
}
|
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
void TexImage2D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
|
|
|
|
GLsizei height, GLint border, GLenum unpackFormat, GLenum unpackType,
|
|
|
|
const dom::ArrayBufferView& view, GLuint viewElemOffset,
|
|
|
|
ErrorResult&)
|
2016-08-10 03:16:09 +03:00
|
|
|
{
|
2016-11-23 04:17:12 +03:00
|
|
|
const TexImageSourceAdapter src(&view, viewElemOffset);
|
2016-10-21 04:03:40 +03:00
|
|
|
TexImage2D(target, level, internalFormat, width, height, border, unpackFormat,
|
|
|
|
unpackType, src);
|
2016-08-10 03:16:09 +03:00
|
|
|
}
|
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
protected:
|
|
|
|
void TexImage2D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
|
|
|
|
GLsizei height, GLint border, GLenum unpackFormat,
|
|
|
|
GLenum unpackType, const TexImageSource& src)
|
|
|
|
{
|
|
|
|
const char funcName[] = "texImage2D";
|
|
|
|
const uint8_t funcDims = 2;
|
|
|
|
const GLsizei depth = 1;
|
|
|
|
TexImage(funcName, funcDims, target, level, internalFormat, width, height, depth,
|
|
|
|
border, unpackFormat, unpackType, src);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TexImage(const char* funcName, uint8_t funcDims, GLenum target, GLint level,
|
|
|
|
GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth,
|
|
|
|
GLint border, GLenum unpackFormat, GLenum unpackType,
|
|
|
|
const TexImageSource& src);
|
|
|
|
|
2016-10-12 04:54:59 +03:00
|
|
|
////
|
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
void TexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
|
2016-10-12 04:54:59 +03:00
|
|
|
GLsizei width, GLsizei height, GLenum unpackFormat,
|
2016-10-21 04:03:40 +03:00
|
|
|
GLenum unpackType, const T& anySrc, ErrorResult& out_error)
|
2016-08-10 03:16:09 +03:00
|
|
|
{
|
2016-11-23 04:17:12 +03:00
|
|
|
const TexImageSourceAdapter src(&anySrc, &out_error);
|
2016-10-21 04:03:40 +03:00
|
|
|
TexSubImage2D(target, level, xOffset, yOffset, width, height, unpackFormat,
|
|
|
|
unpackType, src);
|
|
|
|
}
|
2016-10-12 04:54:59 +03:00
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
void TexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
|
|
|
|
GLsizei width, GLsizei height, GLenum unpackFormat,
|
|
|
|
GLenum unpackType, const dom::ArrayBufferView& view,
|
|
|
|
GLuint viewElemOffset, ErrorResult&)
|
|
|
|
{
|
2016-11-23 04:17:12 +03:00
|
|
|
const TexImageSourceAdapter src(&view, viewElemOffset);
|
2016-10-21 04:03:40 +03:00
|
|
|
TexSubImage2D(target, level, xOffset, yOffset, width, height, unpackFormat,
|
|
|
|
unpackType, src);
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
protected:
|
|
|
|
void TexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
|
2016-10-12 04:54:59 +03:00
|
|
|
GLsizei width, GLsizei height, GLenum unpackFormat,
|
2016-10-21 04:03:40 +03:00
|
|
|
GLenum unpackType, const TexImageSource& src)
|
|
|
|
{
|
|
|
|
const char funcName[] = "texSubImage2D";
|
|
|
|
const uint8_t funcDims = 2;
|
|
|
|
const GLint zOffset = 0;
|
|
|
|
const GLsizei depth = 1;
|
|
|
|
TexSubImage(funcName, funcDims, target, level, xOffset, yOffset, zOffset, width,
|
|
|
|
height, depth, unpackFormat, unpackType, src);
|
|
|
|
}
|
2016-10-12 04:54:59 +03:00
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
void TexSubImage(const char* funcName, uint8_t funcDims, GLenum target, GLint level,
|
|
|
|
GLint xOffset, GLint yOffset, GLint zOffset, GLsizei width,
|
|
|
|
GLsizei height, GLsizei depth, GLenum unpackFormat,
|
|
|
|
GLenum unpackType, const TexImageSource& src);
|
|
|
|
|
|
|
|
////////////////////////////////////
|
2015-11-25 07:15:29 +03:00
|
|
|
// WebGLTextureUpload.cpp
|
2016-06-22 20:28:11 +03:00
|
|
|
public:
|
2016-10-21 04:03:40 +03:00
|
|
|
UniquePtr<webgl::TexUnpackBlob>
|
|
|
|
From(const char* funcName, TexImageTarget target, GLsizei rawWidth, GLsizei rawHeight,
|
|
|
|
GLsizei rawDepth, GLint border, const TexImageSource& src,
|
|
|
|
dom::Uint8ClampedArray* const scopedArr);
|
2016-06-22 20:28:11 +03:00
|
|
|
|
|
|
|
protected:
|
2015-11-25 07:15:29 +03:00
|
|
|
bool ValidateTexImageSpecification(const char* funcName, uint8_t funcDims,
|
|
|
|
GLenum texImageTarget, GLint level,
|
|
|
|
GLsizei width, GLsizei height, GLsizei depth,
|
|
|
|
GLint border,
|
|
|
|
TexImageTarget* const out_target,
|
|
|
|
WebGLTexture** const out_texture,
|
|
|
|
WebGLTexture::ImageInfo** const out_imageInfo);
|
|
|
|
bool ValidateTexImageSelection(const char* funcName, uint8_t funcDims,
|
|
|
|
GLenum texImageTarget, GLint level, GLint xOffset,
|
|
|
|
GLint yOffset, GLint zOffset, GLsizei width,
|
|
|
|
GLsizei height, GLsizei depth,
|
|
|
|
TexImageTarget* const out_target,
|
|
|
|
WebGLTexture** const out_texture,
|
|
|
|
WebGLTexture::ImageInfo** const out_imageInfo);
|
2016-07-22 05:20:21 +03:00
|
|
|
bool ValidateUnpackInfo(const char* funcName, bool usePBOs, GLenum format,
|
|
|
|
GLenum type, webgl::PackingInfo* const out);
|
2016-06-22 20:28:11 +03:00
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
UniquePtr<webgl::TexUnpackBlob>
|
|
|
|
FromDomElem(const char* funcName, TexImageTarget target, uint32_t width,
|
|
|
|
uint32_t height, uint32_t depth, const dom::Element& elem,
|
|
|
|
ErrorResult* const out_error);
|
|
|
|
|
|
|
|
UniquePtr<webgl::TexUnpackBytes>
|
|
|
|
FromCompressed(const char* funcName, TexImageTarget target, GLsizei rawWidth,
|
|
|
|
GLsizei rawHeight, GLsizei rawDepth, GLint border,
|
2017-07-18 21:02:57 +03:00
|
|
|
const TexImageSource& src, const Maybe<GLsizei>& expectedImageSize);
|
2016-10-21 04:03:40 +03:00
|
|
|
|
2013-08-07 04:05:51 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Vertices Feature (WebGLContextVertices.cpp)
|
2016-07-27 06:05:45 +03:00
|
|
|
GLenum mPrimRestartTypeBytes;
|
|
|
|
|
2013-08-07 04:05:51 +04:00
|
|
|
public:
|
2017-12-15 01:10:30 +03:00
|
|
|
void DrawArrays(GLenum mode, GLint first, GLsizei count) {
|
|
|
|
DrawArraysInstanced(mode, first, count, 1, "drawArrays");
|
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
void DrawElements(GLenum mode, GLsizei count, GLenum type,
|
2017-12-15 01:10:30 +03:00
|
|
|
WebGLintptr byteOffset, const char* funcName = "drawElements")
|
|
|
|
{
|
|
|
|
DrawElementsInstanced(mode, count, type, byteOffset, 1, funcName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawArraysInstanced(GLenum mode, GLint first, GLsizei vertexCount,
|
|
|
|
GLsizei instanceCount,
|
|
|
|
const char* funcName = "drawArraysInstanced");
|
|
|
|
void DrawElementsInstanced(GLenum mode, GLsizei vertexCount, GLenum type,
|
|
|
|
WebGLintptr byteOffset, GLsizei instanceCount,
|
|
|
|
const char* funcName = "drawElementsInstanced");
|
2013-08-07 04:05:51 +04:00
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
void EnableVertexAttribArray(GLuint index);
|
|
|
|
void DisableVertexAttribArray(GLuint index);
|
2013-08-07 04:05:51 +04:00
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
JS::Value GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
|
2013-08-07 04:05:51 +04:00
|
|
|
ErrorResult& rv);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
|
2014-11-14 07:03:50 +03:00
|
|
|
JS::MutableHandle<JS::Value> retval, ErrorResult& rv)
|
|
|
|
{
|
2014-06-12 00:26:52 +04:00
|
|
|
retval.set(GetVertexAttrib(cx, index, pname, rv));
|
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLsizeiptr GetVertexAttribOffset(GLuint index, GLenum pname);
|
2013-08-07 04:05:51 +04:00
|
|
|
|
2016-12-22 06:42:07 +03:00
|
|
|
////
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2016-12-22 06:42:07 +03:00
|
|
|
void VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w,
|
|
|
|
const char* funcName = nullptr);
|
|
|
|
|
|
|
|
////
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2016-12-22 06:42:07 +03:00
|
|
|
void VertexAttrib1f(GLuint index, GLfloat x) {
|
|
|
|
VertexAttrib4f(index, x, 0, 0, 1, "vertexAttrib1f");
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
2016-12-22 06:42:07 +03:00
|
|
|
void VertexAttrib2f(GLuint index, GLfloat x, GLfloat y) {
|
|
|
|
VertexAttrib4f(index, x, y, 0, 1, "vertexAttrib2f");
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
2016-12-22 06:42:07 +03:00
|
|
|
void VertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) {
|
|
|
|
VertexAttrib4f(index, x, y, z, 1, "vertexAttrib3f");
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2016-12-22 06:42:07 +03:00
|
|
|
void VertexAttrib1fv(GLuint index, const Float32ListU& list) {
|
|
|
|
const char funcName[] = "vertexAttrib1fv";
|
|
|
|
const auto& arr = Float32Arr::From(list);
|
|
|
|
if (!ValidateAttribArraySetter(funcName, 1, arr.elemCount))
|
|
|
|
return;
|
|
|
|
|
|
|
|
VertexAttrib4f(index, arr.elemBytes[0], 0, 0, 1, funcName);
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
2016-12-22 06:42:07 +03:00
|
|
|
|
|
|
|
void VertexAttrib2fv(GLuint index, const Float32ListU& list) {
|
|
|
|
const char funcName[] = "vertexAttrib2fv";
|
|
|
|
const auto& arr = Float32Arr::From(list);
|
|
|
|
if (!ValidateAttribArraySetter(funcName, 2, arr.elemCount))
|
|
|
|
return;
|
|
|
|
|
|
|
|
VertexAttrib4f(index, arr.elemBytes[0], arr.elemBytes[1], 0, 1, funcName);
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
|
|
|
|
2016-12-22 06:42:07 +03:00
|
|
|
void VertexAttrib3fv(GLuint index, const Float32ListU& list) {
|
|
|
|
const char funcName[] = "vertexAttrib3fv";
|
|
|
|
const auto& arr = Float32Arr::From(list);
|
|
|
|
if (!ValidateAttribArraySetter(funcName, 3, arr.elemCount))
|
|
|
|
return;
|
|
|
|
|
|
|
|
VertexAttrib4f(index, arr.elemBytes[0], arr.elemBytes[1], arr.elemBytes[2], 1,
|
|
|
|
funcName);
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
2016-12-22 06:42:07 +03:00
|
|
|
|
|
|
|
void VertexAttrib4fv(GLuint index, const Float32ListU& list) {
|
|
|
|
const char funcName[] = "vertexAttrib4fv";
|
|
|
|
const auto& arr = Float32Arr::From(list);
|
|
|
|
if (!ValidateAttribArraySetter(funcName, 4, arr.elemCount))
|
|
|
|
return;
|
|
|
|
|
|
|
|
VertexAttrib4f(index, arr.elemBytes[0], arr.elemBytes[1], arr.elemBytes[2],
|
|
|
|
arr.elemBytes[3], funcName);
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
2013-08-07 04:05:51 +04:00
|
|
|
|
2016-12-22 06:42:07 +03:00
|
|
|
////
|
|
|
|
|
2017-01-12 02:57:29 +03:00
|
|
|
protected:
|
|
|
|
void VertexAttribAnyPointer(const char* funcName, bool isFuncInt, GLuint index,
|
|
|
|
GLint size, GLenum type, bool normalized, GLsizei stride,
|
|
|
|
WebGLintptr byteOffset);
|
|
|
|
|
|
|
|
public:
|
2013-09-04 16:14:43 +04:00
|
|
|
void VertexAttribPointer(GLuint index, GLint size, GLenum type,
|
|
|
|
WebGLboolean normalized, GLsizei stride,
|
2017-01-12 02:57:29 +03:00
|
|
|
WebGLintptr byteOffset)
|
|
|
|
{
|
|
|
|
const char funcName[] = "vertexAttribPointer";
|
|
|
|
const bool isFuncInt = false;
|
|
|
|
VertexAttribAnyPointer(funcName, isFuncInt, index, size, type, normalized, stride,
|
|
|
|
byteOffset);
|
|
|
|
}
|
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
void VertexAttribDivisor(GLuint index, GLuint divisor);
|
2013-07-26 04:38:58 +04:00
|
|
|
|
|
|
|
private:
|
2017-10-21 01:40:12 +03:00
|
|
|
bool DrawArrays_check(const char* funcName, GLint first, GLsizei vertCount,
|
|
|
|
GLsizei instanceCount, Maybe<uint32_t>* out_lastVert);
|
|
|
|
bool DrawElements_check(const char* funcName, GLsizei indexCount, GLenum type,
|
|
|
|
WebGLintptr byteOffset, GLsizei instanceCount,
|
|
|
|
Maybe<uint32_t>* out_lastVert);
|
2015-11-25 07:15:29 +03:00
|
|
|
void Draw_cleanup(const char* funcName);
|
2013-07-26 04:38:58 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
void VertexAttrib1fv_base(GLuint index, uint32_t arrayLength,
|
|
|
|
const GLfloat* ptr);
|
|
|
|
void VertexAttrib2fv_base(GLuint index, uint32_t arrayLength,
|
|
|
|
const GLfloat* ptr);
|
|
|
|
void VertexAttrib3fv_base(GLuint index, uint32_t arrayLength,
|
|
|
|
const GLfloat* ptr);
|
|
|
|
void VertexAttrib4fv_base(GLuint index, uint32_t arrayLength,
|
|
|
|
const GLfloat* ptr);
|
2013-08-07 04:05:51 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
bool BindArrayAttribToLocation0(WebGLProgram* prog);
|
2013-08-07 04:05:51 +04:00
|
|
|
|
2013-07-26 04:38:58 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// PROTECTED
|
2011-02-25 01:17:34 +03:00
|
|
|
protected:
|
2016-12-22 06:42:07 +03:00
|
|
|
WebGLVertexAttrib0Status WhatDoesVertexAttrib0Need() const;
|
|
|
|
bool DoFakeVertexAttrib0(const char* funcName, GLuint vertexCount);
|
2010-09-02 18:34:08 +04:00
|
|
|
void UndoFakeVertexAttrib0();
|
|
|
|
|
2010-07-04 02:32:19 +04:00
|
|
|
CheckedUint32 mGeneration;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2010-11-17 07:33:03 +03:00
|
|
|
WebGLContextOptions mOptions;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mInvalidated;
|
2015-09-17 06:37:05 +03:00
|
|
|
bool mCapturedFrameInvalidated;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mResetLayer;
|
|
|
|
bool mOptionsFrozen;
|
2011-10-13 16:09:22 +04:00
|
|
|
bool mDisableExtensions;
|
2012-08-10 06:30:17 +04:00
|
|
|
bool mIsMesa;
|
2014-06-23 03:16:00 +04:00
|
|
|
bool mLoseContextOnMemoryPressure;
|
2013-01-04 03:39:25 +04:00
|
|
|
bool mCanLoseContextInForeground;
|
2014-06-23 03:16:00 +04:00
|
|
|
bool mRestoreWhenVisible;
|
2013-02-14 03:26:24 +04:00
|
|
|
bool mShouldPresent;
|
2013-05-16 01:50:52 +04:00
|
|
|
bool mDisableFragHighP;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2011-12-04 23:15:43 +04:00
|
|
|
template<typename WebGLObjectType>
|
|
|
|
void DeleteWebGLObjectsArray(nsTArray<WebGLObjectType>& array);
|
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
GLuint mActiveTexture;
|
2015-11-25 07:15:29 +03:00
|
|
|
GLenum mDefaultFB_DrawBuffer0;
|
2017-12-19 05:30:56 +03:00
|
|
|
GLenum mDefaultFB_ReadBuffer;
|
2014-03-08 01:16:34 +04:00
|
|
|
|
|
|
|
// glGetError sources:
|
|
|
|
bool mEmitContextLostErrorOnce;
|
2017-12-19 05:30:56 +03:00
|
|
|
mutable GLenum mWebGLError;
|
|
|
|
mutable GLenum mUnderlyingGLError;
|
|
|
|
GLenum GetAndFlushUnderlyingGLErrors() const;
|
2010-05-15 17:55:45 +04:00
|
|
|
|
2015-01-16 02:40:39 +03:00
|
|
|
bool mBypassShaderValidation;
|
|
|
|
|
|
|
|
webgl::ShaderValidator* CreateShaderValidator(GLenum shaderType) const;
|
2010-07-15 07:52:34 +04:00
|
|
|
|
|
|
|
// some GL constants
|
2017-07-27 10:49:21 +03:00
|
|
|
uint32_t mGLMaxTextureUnits;
|
|
|
|
|
2016-12-22 06:42:07 +03:00
|
|
|
uint32_t mGLMaxVertexAttribs;
|
2017-07-27 10:49:21 +03:00
|
|
|
uint32_t mGLMaxFragmentUniformVectors;
|
|
|
|
uint32_t mGLMaxVertexUniformVectors;
|
|
|
|
uint32_t mGLMaxVaryingVectors;
|
|
|
|
|
|
|
|
uint32_t mGLMaxTransformFeedbackSeparateAttribs;
|
|
|
|
uint32_t mGLMaxUniformBufferBindings;
|
|
|
|
|
|
|
|
uint32_t mGLMaxVertexTextureImageUnits;
|
|
|
|
uint32_t mGLMaxFragmentTextureImageUnits;
|
|
|
|
uint32_t mGLMaxCombinedTextureImageUnits;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
uint32_t mGLMaxColorAttachments;
|
|
|
|
uint32_t mGLMaxDrawBuffers;
|
|
|
|
|
2017-07-27 10:48:58 +03:00
|
|
|
uint32_t mGLMaxViewportDims[2];
|
2017-01-10 22:15:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
public:
|
|
|
|
GLenum LastColorAttachmentEnum() const {
|
2017-07-27 10:48:58 +03:00
|
|
|
return LOCAL_GL_COLOR_ATTACHMENT0 + mGLMaxColorAttachments - 1;
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
const decltype(mOptions)& Options() const { return mOptions; }
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
protected:
|
|
|
|
|
|
|
|
// Texture sizes are often not actually the GL values. Let's be explicit that these
|
|
|
|
// are implementation limits.
|
2017-07-27 10:48:58 +03:00
|
|
|
uint32_t mGLMaxTextureSize;
|
|
|
|
uint32_t mGLMaxCubeMapTextureSize;
|
|
|
|
uint32_t mGLMax3DTextureSize;
|
|
|
|
uint32_t mGLMaxArrayTextureLayers;
|
|
|
|
uint32_t mGLMaxRenderbufferSize;
|
2010-07-15 07:52:34 +04:00
|
|
|
|
2014-10-24 02:10:57 +04:00
|
|
|
public:
|
|
|
|
GLuint MaxVertexAttribs() const {
|
|
|
|
return mGLMaxVertexAttribs;
|
|
|
|
}
|
|
|
|
|
2015-01-16 02:40:39 +03:00
|
|
|
GLuint GLMaxTextureUnits() const {
|
|
|
|
return mGLMaxTextureUnits;
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:49:46 +03:00
|
|
|
float mGLAliasedLineWidthRange[2];
|
|
|
|
float mGLAliasedPointSizeRange[2];
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
bool IsFormatValidForFB(TexInternalFormat format) const;
|
2014-11-22 02:04:08 +03:00
|
|
|
|
2014-10-24 02:10:57 +04:00
|
|
|
protected:
|
2013-09-04 16:14:44 +04: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-05 01:12:03 +04: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 16:14:44 +04:00
|
|
|
ContextNotLost,
|
2012-01-05 01:12:03 +04: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-27 01:12:53 +04:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// WebGL extensions (implemented in WebGLContextExtensions.cpp)
|
2014-11-14 07:03:50 +03:00
|
|
|
typedef EnumeratedArray<WebGLExtensionID, WebGLExtensionID::Max,
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebGLExtensionBase>> ExtensionsArrayType;
|
2014-04-26 06:34:07 +04:00
|
|
|
|
|
|
|
ExtensionsArrayType mExtensions;
|
2012-06-16 09:12:30 +04:00
|
|
|
|
2013-07-17 20:13:38 +04:00
|
|
|
// enable an extension. the extension should not be enabled before.
|
|
|
|
void EnableExtension(WebGLExtensionID ext);
|
|
|
|
|
2014-11-22 02:04:08 +03:00
|
|
|
// Enable an extension if it's supported. Return the extension on success.
|
2016-11-16 22:10:22 +03:00
|
|
|
WebGLExtensionBase* EnableSupportedExtension(dom::CallerType callerType,
|
2014-11-22 02:04:08 +03:00
|
|
|
WebGLExtensionID ext);
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
public:
|
2012-06-16 09:12:30 +04:00
|
|
|
// returns true if the extension has been enabled by calling getExtension.
|
2012-10-04 01:13:05 +04:00
|
|
|
bool IsExtensionEnabled(WebGLExtensionID ext) const;
|
2012-06-16 09:12:30 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
protected:
|
2016-11-16 22:10:22 +03:00
|
|
|
// returns true if the extension is supported for this caller type (this decides what getSupportedExtensions exposes)
|
|
|
|
bool IsExtensionSupported(dom::CallerType callerType,
|
|
|
|
WebGLExtensionID ext) const;
|
2013-07-17 20:13:38 +04:00
|
|
|
bool IsExtensionSupported(WebGLExtensionID ext) const;
|
2011-05-20 23:53:53 +04:00
|
|
|
|
2013-08-27 01:12:53 +04:00
|
|
|
static const char* GetExtensionString(WebGLExtensionID ext);
|
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
nsTArray<GLenum> mCompressedTextureFormats;
|
2012-05-08 21:29:31 +04:00
|
|
|
|
2013-08-27 01:12:54 +04:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// WebGL 2 specifics (implemented in WebGL2Context.cpp)
|
2015-02-13 06:00:41 +03:00
|
|
|
public:
|
2013-08-27 01:12:54 +04:00
|
|
|
virtual bool IsWebGL2() const = 0;
|
|
|
|
|
2016-06-21 06:28:57 +03:00
|
|
|
struct FailureReason {
|
|
|
|
nsCString key; // For reporting.
|
|
|
|
nsCString info;
|
2016-06-21 06:42:10 +03:00
|
|
|
|
|
|
|
FailureReason() { }
|
|
|
|
|
|
|
|
template<typename A, typename B>
|
|
|
|
FailureReason(const A& _key, const B& _info)
|
|
|
|
: key(nsCString(_key))
|
|
|
|
, info(nsCString(_info))
|
|
|
|
{ }
|
2016-06-21 06:28:57 +03:00
|
|
|
};
|
2016-06-21 06:42:10 +03:00
|
|
|
protected:
|
|
|
|
bool InitWebGL2(FailureReason* const out_failReason);
|
|
|
|
|
2016-06-21 06:28:57 +03:00
|
|
|
bool CreateAndInitGL(bool forceEnabled,
|
|
|
|
std::vector<FailureReason>* const out_failReasons);
|
|
|
|
|
2015-09-24 22:21:05 +03:00
|
|
|
typedef already_AddRefed<gl::GLContext> FnCreateGL_T(const gl::SurfaceCaps& caps,
|
|
|
|
gl::CreateContextFlags flags,
|
2016-05-12 02:45:43 +03:00
|
|
|
WebGLContext* webgl,
|
2016-06-21 06:28:57 +03:00
|
|
|
std::vector<FailureReason>* const out_failReasons);
|
2015-09-24 22:21:05 +03:00
|
|
|
|
|
|
|
bool CreateAndInitGLWith(FnCreateGL_T fnCreateGL, const gl::SurfaceCaps& baseCaps,
|
2016-05-12 02:45:43 +03:00
|
|
|
gl::CreateContextFlags flags,
|
2016-06-21 06:28:57 +03:00
|
|
|
std::vector<FailureReason>* const out_failReasons);
|
|
|
|
|
2016-05-12 02:45:43 +03:00
|
|
|
void ThrowEvent_WebGLContextCreationError(const nsACString& text);
|
2015-09-24 22:21:05 +03:00
|
|
|
|
2013-08-07 04:05:51 +04:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Validation functions (implemented in WebGLContextValidate.cpp)
|
2016-06-21 06:42:10 +03:00
|
|
|
bool InitAndValidateGL(FailureReason* const out_failReason);
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
bool ValidateBlendEquationEnum(GLenum cap, const char* info);
|
|
|
|
bool ValidateBlendFuncEnumsCompatibility(GLenum sfactor, GLenum dfactor,
|
|
|
|
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 ValidateTexInputData(GLenum type, js::Scalar::Type jsArrayType,
|
|
|
|
WebGLTexImageFunc func, WebGLTexDimensions dims);
|
|
|
|
bool ValidateDrawModeEnum(GLenum mode, const char* info);
|
2014-06-24 04:56:21 +04:00
|
|
|
bool ValidateAttribIndex(GLuint index, const char* info);
|
|
|
|
bool ValidateAttribPointer(bool integerMode, GLuint index, GLint size, GLenum type,
|
|
|
|
WebGLboolean normalized, GLsizei stride,
|
|
|
|
WebGLintptr byteOffset, const char* info);
|
2018-03-16 00:22:10 +03:00
|
|
|
bool ValidateStencilParamsForDrawCall();
|
2014-01-23 07:59:33 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
bool ValidateCopyTexImage(TexInternalFormat srcFormat, TexInternalFormat dstformat,
|
|
|
|
WebGLTexImageFunc func, WebGLTexDimensions dims);
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2014-10-14 03:42:15 +04:00
|
|
|
bool ValidateTexImage(TexImageTarget texImageTarget,
|
2014-09-23 21:48:27 +04:00
|
|
|
GLint level, GLenum internalFormat,
|
2014-02-21 05:20:28 +04:00
|
|
|
GLint xoffset, GLint yoffset, GLint zoffset,
|
|
|
|
GLint width, GLint height, GLint depth,
|
|
|
|
GLint border, GLenum format, GLenum type,
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLTexImageFunc func, WebGLTexDimensions dims);
|
|
|
|
bool ValidateTexImageFormat(GLenum internalFormat, WebGLTexImageFunc func,
|
2014-10-14 03:42:15 +04:00
|
|
|
WebGLTexDimensions dims);
|
2014-11-14 07:03:50 +03:00
|
|
|
bool ValidateTexImageType(GLenum type, WebGLTexImageFunc func,
|
2014-10-14 03:42:15 +04:00
|
|
|
WebGLTexDimensions dims);
|
2014-11-14 07:03:50 +03:00
|
|
|
bool ValidateTexImageFormatAndType(GLenum format, GLenum type,
|
2014-10-14 03:42:15 +04:00
|
|
|
WebGLTexImageFunc func,
|
|
|
|
WebGLTexDimensions dims);
|
2014-10-05 06:24:24 +04:00
|
|
|
bool ValidateCompTexImageInternalFormat(GLenum format,
|
2014-10-14 03:42:15 +04:00
|
|
|
WebGLTexImageFunc func,
|
|
|
|
WebGLTexDimensions dims);
|
2014-10-05 06:24:24 +04:00
|
|
|
bool ValidateCopyTexImageInternalFormat(GLenum format,
|
2014-10-14 03:42:15 +04:00
|
|
|
WebGLTexImageFunc func,
|
|
|
|
WebGLTexDimensions dims);
|
2014-11-14 07:03:50 +03:00
|
|
|
bool ValidateTexImageSize(TexImageTarget texImageTarget, GLint level,
|
2014-02-21 05:20:28 +04:00
|
|
|
GLint width, GLint height, GLint depth,
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLTexImageFunc func, WebGLTexDimensions dims);
|
|
|
|
bool ValidateTexSubImageSize(GLint x, GLint y, GLint z, GLsizei width,
|
|
|
|
GLsizei height, GLsizei depth,
|
|
|
|
GLsizei baseWidth, GLsizei baseHeight,
|
|
|
|
GLsizei baseDepth, WebGLTexImageFunc func,
|
2014-10-14 03:42:15 +04:00
|
|
|
WebGLTexDimensions dims);
|
2014-11-14 07:03:50 +03:00
|
|
|
bool ValidateCompTexImageSize(GLint level, GLenum internalFormat,
|
|
|
|
GLint xoffset, GLint yoffset, GLsizei width,
|
|
|
|
GLsizei height, GLsizei levelWidth,
|
|
|
|
GLsizei levelHeight, WebGLTexImageFunc func,
|
2014-10-14 03:42:15 +04:00
|
|
|
WebGLTexDimensions dims);
|
2014-11-14 07:03:50 +03:00
|
|
|
bool ValidateCompTexImageDataSize(GLint level, GLenum internalFormat,
|
2014-02-21 05:20:28 +04:00
|
|
|
GLsizei width, GLsizei height,
|
2014-10-14 03:42:15 +04:00
|
|
|
uint32_t byteLength,
|
|
|
|
WebGLTexImageFunc func,
|
|
|
|
WebGLTexDimensions dims);
|
2014-02-21 05:20:28 +04:00
|
|
|
|
2015-01-16 02:40:39 +03:00
|
|
|
bool ValidateUniformLocationForProgram(WebGLUniformLocation* location,
|
|
|
|
WebGLProgram* program,
|
|
|
|
const char* funcName);
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
bool HasDrawBuffers() const {
|
|
|
|
return IsWebGL2() ||
|
|
|
|
IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers);
|
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
WebGLRefPtr<WebGLBuffer>* ValidateBufferSlot(const char* funcName, GLenum target);
|
2016-11-18 04:50:38 +03:00
|
|
|
public:
|
2016-09-10 07:02:54 +03:00
|
|
|
WebGLBuffer* ValidateBufferSelection(const char* funcName, GLenum target);
|
2016-11-18 04:50:38 +03:00
|
|
|
protected:
|
2016-09-10 07:02:54 +03:00
|
|
|
IndexedBufferBinding* ValidateIndexedBufferSlot(const char* funcName, GLenum target,
|
|
|
|
GLuint index);
|
|
|
|
|
|
|
|
bool ValidateIndexedBufferBinding(const char* funcName, GLenum target, GLuint index,
|
|
|
|
WebGLRefPtr<WebGLBuffer>** const out_genericBinding,
|
|
|
|
IndexedBufferBinding** const out_indexedBinding);
|
|
|
|
|
|
|
|
bool ValidateNonNegative(const char* funcName, const char* argName, int64_t val) {
|
|
|
|
if (MOZ_UNLIKELY(val < 0)) {
|
|
|
|
ErrorInvalidValue("%s: `%s` must be non-negative.", funcName, argName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
public:
|
2016-11-02 00:58:07 +03:00
|
|
|
template<typename T>
|
|
|
|
bool ValidateNonNull(const char* funcName, const dom::Nullable<T>& maybe) {
|
|
|
|
if (maybe.IsNull()) {
|
|
|
|
ErrorInvalidValue("%s: `null` is invalid.", funcName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-12 01:39:23 +03:00
|
|
|
bool ValidateArrayBufferView(const char* funcName, const dom::ArrayBufferView& view,
|
|
|
|
GLuint elemOffset, GLuint elemCountOverride,
|
|
|
|
uint8_t** const out_bytes, size_t* const out_byteLen);
|
|
|
|
|
2016-10-21 04:03:40 +03:00
|
|
|
protected:
|
2016-10-12 01:39:23 +03:00
|
|
|
////
|
|
|
|
|
2009-09-03 04:47:49 +04:00
|
|
|
void Invalidate();
|
2010-07-19 09:01:14 +04:00
|
|
|
void DestroyResourcesAndContext();
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2010-01-23 00:34:25 +03:00
|
|
|
// helpers
|
2014-10-14 03:42:11 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
bool ConvertImage(size_t width, size_t height, size_t srcStride,
|
|
|
|
size_t dstStride, const uint8_t* src, uint8_t* dst,
|
2012-05-07 21:05:32 +04:00
|
|
|
WebGLTexelFormat srcFormat, bool srcPremultiplied,
|
|
|
|
WebGLTexelFormat dstFormat, bool dstPremultiplied,
|
2010-10-16 01:50:15 +04:00
|
|
|
size_t dstTexelSize);
|
|
|
|
|
2016-07-12 08:51:19 +03:00
|
|
|
//////
|
2016-11-02 00:58:07 +03:00
|
|
|
public:
|
2016-11-30 05:30:28 +03:00
|
|
|
bool ValidateObjectAllowDeleted(const char* funcName,
|
|
|
|
const WebGLContextBoundObject& object)
|
|
|
|
{
|
|
|
|
if (!object.IsCompatibleWithContext(this)) {
|
|
|
|
ErrorInvalidOperation("%s: Object from different WebGL context (or older"
|
|
|
|
" generation of this one) passed as argument.",
|
|
|
|
funcName);
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-02 00:58:07 +03:00
|
|
|
|
2016-12-01 02:27:20 +03:00
|
|
|
bool ValidateObject(const char* funcName, const WebGLDeletableObject& object,
|
|
|
|
bool isShaderOrProgram = false)
|
|
|
|
{
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObjectAllowDeleted(funcName, object))
|
|
|
|
return false;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2016-12-01 02:27:20 +03:00
|
|
|
if (isShaderOrProgram) {
|
|
|
|
/* GLES 3.0.5 p45:
|
|
|
|
* "Commands that accept shader or program object names will generate the
|
|
|
|
* error INVALID_VALUE if the provided name is not the name of either a
|
|
|
|
* shader or program object[.]"
|
|
|
|
* Further, shaders and programs appear to be different from other objects,
|
|
|
|
* in that their lifetimes are better defined. However, they also appear to
|
|
|
|
* allow use of objects marked for deletion, and only reject
|
|
|
|
* actually-destroyed objects.
|
|
|
|
*/
|
|
|
|
if (object.IsDeleted()) {
|
|
|
|
ErrorInvalidValue("%s: Shader or program object argument cannot have been"
|
|
|
|
" deleted.",
|
2016-11-30 05:30:28 +03:00
|
|
|
funcName);
|
2016-12-01 02:27:20 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (object.IsDeleteRequested()) {
|
|
|
|
ErrorInvalidOperation("%s: Object argument cannot have been marked for"
|
|
|
|
" deletion.",
|
|
|
|
funcName);
|
|
|
|
return false;
|
|
|
|
}
|
2016-11-30 05:30:28 +03:00
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
return true;
|
|
|
|
}
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
////
|
|
|
|
|
2016-12-01 02:27:20 +03:00
|
|
|
bool ValidateObject(const char* funcName, const WebGLProgram& object);
|
|
|
|
bool ValidateObject(const char* funcName, const WebGLShader& object);
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
bool ValidateIsObject(const char* funcName,
|
|
|
|
const WebGLDeletableObject* object) const
|
|
|
|
{
|
|
|
|
if (IsContextLost())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!object->IsCompatibleWithContext(this))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (object->IsDeleted())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ValidateDeleteObject(const char* funcName, const WebGLDeletableObject* object) {
|
|
|
|
if (IsContextLost())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeleted(funcName, *object))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (object->IsDeleteRequested())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
2010-06-04 23:03:37 +04:00
|
|
|
|
2014-06-24 04:56:21 +04:00
|
|
|
private:
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Context customization points
|
2015-06-01 09:49:47 +03:00
|
|
|
virtual WebGLVertexArray* CreateVertexArrayImpl();
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
public:
|
2014-11-14 07:03:50 +03:00
|
|
|
void ForceLoseContext(bool simulateLoss = false);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
protected:
|
2011-10-27 00:00:44 +04:00
|
|
|
void ForceRestoreContext();
|
|
|
|
|
2011-12-04 23:15:42 +04:00
|
|
|
nsTArray<WebGLRefPtr<WebGLTexture> > mBound2DTextures;
|
|
|
|
nsTArray<WebGLRefPtr<WebGLTexture> > mBoundCubeMapTextures;
|
2014-10-14 03:42:20 +04:00
|
|
|
nsTArray<WebGLRefPtr<WebGLTexture> > mBound3DTextures;
|
2015-11-25 07:15:29 +03:00
|
|
|
nsTArray<WebGLRefPtr<WebGLTexture> > mBound2DArrayTextures;
|
2015-06-09 03:18:19 +03:00
|
|
|
nsTArray<WebGLRefPtr<WebGLSampler> > mBoundSamplers;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2015-04-07 05:05:11 +03:00
|
|
|
void ResolveTexturesForDraw() const;
|
|
|
|
|
2011-12-04 23:15:42 +04:00
|
|
|
WebGLRefPtr<WebGLProgram> mCurrentProgram;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<const webgl::LinkedProgramInfo> mActiveProgramLinkInfo;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
bool ValidateFramebufferTarget(GLenum target, const char* const info);
|
2016-12-01 05:46:06 +03:00
|
|
|
bool ValidateInvalidateFramebuffer(const char* funcName, GLenum target,
|
|
|
|
const dom::Sequence<GLenum>& attachments,
|
|
|
|
ErrorResult* const out_rv,
|
|
|
|
std::vector<GLenum>* const scopedVector,
|
|
|
|
GLsizei* const out_glNumAttachments,
|
|
|
|
const GLenum** const out_glAttachments);
|
2015-01-13 02:05:21 +03:00
|
|
|
|
|
|
|
WebGLRefPtr<WebGLFramebuffer> mBoundDrawFramebuffer;
|
|
|
|
WebGLRefPtr<WebGLFramebuffer> mBoundReadFramebuffer;
|
2011-12-04 23:15:42 +04:00
|
|
|
WebGLRefPtr<WebGLRenderbuffer> mBoundRenderbuffer;
|
2014-11-26 05:00:06 +03:00
|
|
|
WebGLRefPtr<WebGLTransformFeedback> mBoundTransformFeedback;
|
2013-06-28 01:07:21 +04:00
|
|
|
WebGLRefPtr<WebGLVertexArray> mBoundVertexArray;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2012-05-29 22:44:31 +04:00
|
|
|
LinkedList<WebGLBuffer> mBuffers;
|
2016-06-03 11:18:56 +03:00
|
|
|
LinkedList<WebGLFramebuffer> mFramebuffers;
|
2012-05-29 22:44:31 +04:00
|
|
|
LinkedList<WebGLProgram> mPrograms;
|
2013-08-07 01:23:46 +04:00
|
|
|
LinkedList<WebGLQuery> mQueries;
|
2012-05-29 22:44:31 +04:00
|
|
|
LinkedList<WebGLRenderbuffer> mRenderbuffers;
|
2014-10-27 02:40:37 +03:00
|
|
|
LinkedList<WebGLSampler> mSamplers;
|
2016-06-03 11:18:56 +03:00
|
|
|
LinkedList<WebGLShader> mShaders;
|
2016-06-23 12:01:36 +03:00
|
|
|
LinkedList<WebGLSync> mSyncs;
|
2016-06-03 11:18:56 +03:00
|
|
|
LinkedList<WebGLTexture> mTextures;
|
2014-11-26 05:00:06 +03:00
|
|
|
LinkedList<WebGLTransformFeedback> mTransformFeedbacks;
|
2016-06-03 11:18:56 +03:00
|
|
|
LinkedList<WebGLVertexArray> mVertexArrays;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2014-11-26 05:00:06 +03:00
|
|
|
WebGLRefPtr<WebGLTransformFeedback> mDefaultTransformFeedback;
|
2014-12-05 10:04:55 +03:00
|
|
|
WebGLRefPtr<WebGLVertexArray> mDefaultVertexArray;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2010-10-16 01:50:15 +04:00
|
|
|
// PixelStore parameters
|
2015-11-25 07:15:29 +03:00
|
|
|
uint32_t mPixelStore_UnpackImageHeight;
|
|
|
|
uint32_t mPixelStore_UnpackSkipImages;
|
|
|
|
uint32_t mPixelStore_UnpackRowLength;
|
|
|
|
uint32_t mPixelStore_UnpackSkipRows;
|
|
|
|
uint32_t mPixelStore_UnpackSkipPixels;
|
|
|
|
uint32_t mPixelStore_UnpackAlignment;
|
|
|
|
uint32_t mPixelStore_PackRowLength;
|
|
|
|
uint32_t mPixelStore_PackSkipRows;
|
|
|
|
uint32_t mPixelStore_PackSkipPixels;
|
|
|
|
uint32_t mPixelStore_PackAlignment;
|
|
|
|
|
|
|
|
CheckedUint32 GetUnpackSize(bool isFunc3D, uint32_t width, uint32_t height,
|
|
|
|
uint32_t depth, uint8_t bytesPerPixel);
|
|
|
|
|
2016-07-05 00:40:38 +03:00
|
|
|
bool ValidatePackSize(const char* funcName, uint32_t width, uint32_t height,
|
|
|
|
uint8_t bytesPerPixel, uint32_t* const out_rowStride,
|
|
|
|
uint32_t* const out_endOffset);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
GLenum mPixelStore_ColorspaceConversion;
|
|
|
|
bool mPixelStore_FlipY;
|
|
|
|
bool mPixelStore_PremultiplyAlpha;
|
2017-04-11 12:15:25 +03:00
|
|
|
bool mPixelStore_RequireFastPath;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
////////////////////////////////////
|
2014-11-14 07:03:50 +03:00
|
|
|
class FakeBlackTexture {
|
2015-11-25 07:15:29 +03:00
|
|
|
public:
|
2016-07-27 04:42:09 +03:00
|
|
|
static UniquePtr<FakeBlackTexture> Create(gl::GLContext* gl,
|
|
|
|
TexTarget target,
|
|
|
|
FakeBlackType type);
|
2014-11-14 07:03:50 +03:00
|
|
|
gl::GLContext* const mGL;
|
2015-11-25 07:15:29 +03:00
|
|
|
const GLuint mGLName;
|
2013-10-11 17:16:43 +04:00
|
|
|
|
|
|
|
~FakeBlackTexture();
|
2016-07-27 04:42:09 +03:00
|
|
|
protected:
|
|
|
|
explicit FakeBlackTexture(gl::GLContext* gl);
|
2013-10-11 17:16:43 +04:00
|
|
|
};
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
UniquePtr<FakeBlackTexture> mFakeBlack_2D_0000;
|
|
|
|
UniquePtr<FakeBlackTexture> mFakeBlack_2D_0001;
|
|
|
|
UniquePtr<FakeBlackTexture> mFakeBlack_CubeMap_0000;
|
|
|
|
UniquePtr<FakeBlackTexture> mFakeBlack_CubeMap_0001;
|
|
|
|
UniquePtr<FakeBlackTexture> mFakeBlack_3D_0000;
|
|
|
|
UniquePtr<FakeBlackTexture> mFakeBlack_3D_0001;
|
|
|
|
UniquePtr<FakeBlackTexture> mFakeBlack_2D_Array_0000;
|
|
|
|
UniquePtr<FakeBlackTexture> mFakeBlack_2D_Array_0001;
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2016-07-27 04:42:09 +03:00
|
|
|
bool BindFakeBlack(uint32_t texUnit, TexTarget target, FakeBlackType fakeBlack);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
////////////////////////////////////
|
2010-08-24 01:03:53 +04:00
|
|
|
|
2016-11-18 04:50:38 +03:00
|
|
|
protected:
|
2016-12-29 11:08:39 +03:00
|
|
|
GLuint mEmptyTFO;
|
|
|
|
|
2015-07-20 10:56:17 +03:00
|
|
|
// Generic Vertex Attributes
|
2016-12-22 06:42:07 +03:00
|
|
|
// Though CURRENT_VERTEX_ATTRIB is listed under "Vertex Shader State" in the spec
|
|
|
|
// state tables, this isn't vertex shader /object/ state. This array is merely state
|
|
|
|
// useful to vertex shaders, but is global state.
|
|
|
|
UniquePtr<GLenum[]> mGenericVertexAttribTypes;
|
|
|
|
uint8_t mGenericVertexAttrib0Data[sizeof(float) * 4];
|
2017-10-21 01:40:12 +03:00
|
|
|
CacheMapInvalidator mGenericVertexAttribTypeInvalidator;
|
2016-12-22 06:42:07 +03:00
|
|
|
|
2011-02-25 01:17:34 +03:00
|
|
|
GLuint mFakeVertexAttrib0BufferObject;
|
2016-12-22 06:42:07 +03:00
|
|
|
size_t mFakeVertexAttrib0BufferObjectSize;
|
|
|
|
bool mFakeVertexAttrib0DataDefined;
|
|
|
|
uint8_t mFakeVertexAttrib0Data[sizeof(float) * 4];
|
2010-09-02 18:34:08 +04:00
|
|
|
|
2015-07-20 10:56:17 +03:00
|
|
|
JSObject* GetVertexAttribFloat32Array(JSContext* cx, GLuint index);
|
|
|
|
JSObject* GetVertexAttribInt32Array(JSContext* cx, GLuint index);
|
|
|
|
JSObject* GetVertexAttribUint32Array(JSContext* cx, GLuint index);
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
GLint mStencilRefFront;
|
|
|
|
GLint mStencilRefBack;
|
|
|
|
GLuint mStencilValueMaskFront;
|
|
|
|
GLuint mStencilValueMaskBack;
|
|
|
|
GLuint mStencilWriteMaskFront;
|
|
|
|
GLuint mStencilWriteMaskBack;
|
2017-12-19 05:30:56 +03:00
|
|
|
uint8_t mColorWriteMask; // bitmask
|
2011-05-20 23:53:53 +04:00
|
|
|
realGLboolean mDepthWriteMask;
|
2013-09-04 16:14:43 +04:00
|
|
|
GLfloat mColorClearValue[4];
|
|
|
|
GLint mStencilClearValue;
|
|
|
|
GLfloat mDepthClearValue;
|
2010-12-06 14:34:35 +03:00
|
|
|
|
2014-01-10 17:41:04 +04:00
|
|
|
GLint mViewportX;
|
|
|
|
GLint mViewportY;
|
|
|
|
GLsizei mViewportWidth;
|
|
|
|
GLsizei mViewportHeight;
|
|
|
|
bool mAlreadyWarnedAboutViewportLargerThanDest;
|
|
|
|
|
2016-09-28 06:54:46 +03:00
|
|
|
GLfloat mLineWidth;
|
|
|
|
|
2016-06-16 20:01:44 +03:00
|
|
|
WebGLContextLossHandler mContextLossHandler;
|
2014-06-03 01:40:15 +04:00
|
|
|
bool mAllowContextRestore;
|
|
|
|
bool mLastLossWasSimulated;
|
2012-01-05 01:12:03 +04:00
|
|
|
ContextStatus mContextStatus;
|
|
|
|
bool mContextLostErrorSet;
|
2012-03-01 00:49:55 +04:00
|
|
|
|
2013-05-22 11:05:38 +04:00
|
|
|
// Used for some hardware (particularly Tegra 2 and 4) that likes to
|
|
|
|
// be Flushed while doing hundreds of draw calls.
|
|
|
|
int mDrawCallsSinceLastFlush;
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
mutable int mAlreadyGeneratedWarnings;
|
2013-06-04 23:44:08 +04:00
|
|
|
int mMaxWarnings;
|
2012-07-25 20:13:45 +04:00
|
|
|
bool mAlreadyWarnedAboutFakeVertexAttrib0;
|
2012-05-29 22:44:31 +04:00
|
|
|
|
2013-09-04 16:14:50 +04:00
|
|
|
bool ShouldGenerateWarnings() const;
|
2012-05-23 20:07:10 +04:00
|
|
|
|
2017-01-12 04:10:48 +03:00
|
|
|
bool ShouldGeneratePerfWarnings() const {
|
|
|
|
return mNumPerfWarnings < mMaxPerfWarnings;
|
|
|
|
}
|
|
|
|
|
2012-08-03 01:28:02 +04:00
|
|
|
uint64_t mLastUseIndex;
|
|
|
|
|
2014-10-02 04:05:34 +04:00
|
|
|
bool mNeedsFakeNoAlpha;
|
2015-09-24 22:21:05 +03:00
|
|
|
bool mNeedsFakeNoDepth;
|
2015-03-12 04:23:56 +03:00
|
|
|
bool mNeedsFakeNoStencil;
|
2017-12-22 14:42:04 +03:00
|
|
|
bool mNeedsFakeNoStencil_UserFBs;
|
2017-12-19 05:30:56 +03:00
|
|
|
|
|
|
|
mutable uint8_t mDriverColorMask;
|
|
|
|
bool mDriverDepthTest;
|
|
|
|
bool mDriverStencilTest;
|
2014-10-02 04:05:34 +04:00
|
|
|
|
2017-02-10 07:31:36 +03:00
|
|
|
bool mNeedsIndexValidation;
|
|
|
|
|
2016-12-01 05:46:06 +03:00
|
|
|
const bool mAllowFBInvalidation;
|
|
|
|
|
2016-10-04 04:33:52 +03:00
|
|
|
bool Has64BitTimestamps() const;
|
2016-07-17 20:37:00 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
// --
|
2016-02-19 04:59:24 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
const uint8_t mMsaaSamples;
|
2017-12-22 04:14:54 +03:00
|
|
|
mutable gfx::IntSize mRequestedSize;
|
2017-12-19 05:30:56 +03:00
|
|
|
mutable UniquePtr<gl::MozFramebuffer> mDefaultFB;
|
|
|
|
mutable bool mDefaultFB_IsInvalid;
|
|
|
|
mutable UniquePtr<gl::MozFramebuffer> mResolvedDefaultFB;
|
2016-02-19 04:59:24 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
// --
|
2015-03-12 04:23:56 +03:00
|
|
|
|
2017-12-22 04:14:54 +03:00
|
|
|
bool EnsureDefaultFB(const char* funcName);
|
2017-12-19 05:30:56 +03:00
|
|
|
bool ValidateAndInitFB(const char* funcName, const WebGLFramebuffer* fb);
|
|
|
|
void DoBindFB(const WebGLFramebuffer* fb, GLenum target = LOCAL_GL_FRAMEBUFFER) const;
|
2014-10-02 04:05:34 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
bool BindCurFBForDraw(const char* funcName);
|
|
|
|
bool BindCurFBForColorRead(const char* funcName,
|
|
|
|
const webgl::FormatUsageInfo** out_format,
|
|
|
|
uint32_t* out_width, uint32_t* out_height);
|
2017-12-20 12:55:50 +03:00
|
|
|
void DoColorMask(uint8_t bitmask) const;
|
2017-12-19 05:30:56 +03:00
|
|
|
void BlitBackbufferToCurDriverFB() const;
|
|
|
|
bool BindDefaultFBForRead(const char* funcName);
|
2014-10-02 04:05:34 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
// --
|
2016-12-24 05:54:04 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
public:
|
2012-08-03 01:28:02 +04:00
|
|
|
void LoseOldestWebGLContextIfLimitExceeded();
|
|
|
|
void UpdateLastUseIndex();
|
|
|
|
|
2012-10-05 00:35:54 +04:00
|
|
|
template <typename WebGLObjectType>
|
2014-11-14 07:03:50 +03:00
|
|
|
JS::Value WebGLObjectAsJSValue(JSContext* cx, const WebGLObjectType*,
|
|
|
|
ErrorResult& rv) const;
|
2012-10-05 00:35:54 +04:00
|
|
|
template <typename WebGLObjectType>
|
2014-11-14 07:03:50 +03:00
|
|
|
JSObject* WebGLObjectAsJSObject(JSContext* cx, const WebGLObjectType*,
|
|
|
|
ErrorResult& rv) const;
|
2012-10-05 00:35:54 +04:00
|
|
|
|
2012-03-01 00:49:55 +04: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
|
|
|
|
|
2010-05-20 00:46:08 +04:00
|
|
|
public:
|
2009-09-03 04:47:49 +04:00
|
|
|
// console logging helpers
|
2017-12-19 05:30:56 +03:00
|
|
|
void GenerateWarning(const char* fmt, ...) const MOZ_FORMAT_PRINTF(2, 3);
|
|
|
|
void GenerateWarning(const char* fmt, va_list ap) const MOZ_FORMAT_PRINTF(2, 0);
|
2010-08-24 01:03:53 +04:00
|
|
|
|
2016-12-10 02:48:22 +03:00
|
|
|
void GeneratePerfWarning(const char* fmt, ...) const MOZ_FORMAT_PRINTF(2, 3);
|
2017-01-12 04:10:48 +03:00
|
|
|
|
2015-08-04 06:39:47 +03:00
|
|
|
public:
|
2015-07-11 02:34:45 +03:00
|
|
|
UniquePtr<webgl::FormatUsageAuthority> mFormatUsage;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
virtual UniquePtr<webgl::FormatUsageAuthority>
|
|
|
|
CreateFormatUsage(gl::GLContext* gl) const = 0;
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2016-07-14 22:04:31 +03:00
|
|
|
|
|
|
|
const decltype(mBound2DTextures)* TexListForElemType(GLenum elemType) const;
|
|
|
|
|
2017-07-27 10:48:58 +03:00
|
|
|
void UpdateMaxDrawBuffers();
|
|
|
|
|
2018-02-21 04:34:25 +03:00
|
|
|
// --
|
|
|
|
private:
|
|
|
|
webgl::AvailabilityRunnable* mAvailabilityRunnable = nullptr;
|
|
|
|
public:
|
|
|
|
webgl::AvailabilityRunnable* EnsureAvailabilityRunnable();
|
|
|
|
|
2015-07-11 02:34:45 +03:00
|
|
|
// Friend list
|
2015-11-25 07:15:29 +03:00
|
|
|
friend class ScopedCopyTexImageSource;
|
|
|
|
friend class ScopedResolveTexturesForDraw;
|
|
|
|
friend class ScopedUnpackReset;
|
|
|
|
friend class webgl::TexUnpackBlob;
|
|
|
|
friend class webgl::TexUnpackBytes;
|
2016-07-12 08:51:19 +03:00
|
|
|
friend class webgl::TexUnpackImage;
|
2015-11-25 07:15:29 +03:00
|
|
|
friend class webgl::TexUnpackSurface;
|
2016-07-14 22:04:31 +03:00
|
|
|
friend struct webgl::UniformInfo;
|
2010-08-24 01:03:53 +04:00
|
|
|
friend class WebGLTexture;
|
2015-11-25 07:15:29 +03:00
|
|
|
friend class WebGLFBAttachPoint;
|
2010-11-05 22:57:58 +03:00
|
|
|
friend class WebGLFramebuffer;
|
2011-12-04 23:15:42 +04:00
|
|
|
friend class WebGLRenderbuffer;
|
2011-11-03 18:50:40 +04:00
|
|
|
friend class WebGLProgram;
|
2013-08-07 01:23:46 +04:00
|
|
|
friend class WebGLQuery;
|
2011-12-04 23:15:42 +04:00
|
|
|
friend class WebGLBuffer;
|
2014-10-27 02:40:37 +03:00
|
|
|
friend class WebGLSampler;
|
2011-12-04 23:15:42 +04:00
|
|
|
friend class WebGLShader;
|
2014-06-18 08:25:53 +04:00
|
|
|
friend class WebGLSync;
|
2014-11-26 05:00:06 +03:00
|
|
|
friend class WebGLTransformFeedback;
|
2011-12-04 23:15:43 +04:00
|
|
|
friend class WebGLUniformLocation;
|
2013-06-28 01:07:21 +04:00
|
|
|
friend class WebGLVertexArray;
|
2014-06-06 03:38:27 +04:00
|
|
|
friend class WebGLVertexArrayFake;
|
|
|
|
friend class WebGLVertexArrayGL;
|
2009-09-03 04:47:49 +04:00
|
|
|
};
|
|
|
|
|
2012-10-04 01:13:05 +04:00
|
|
|
// used by DOM bindings in conjunction with GetParentObject
|
|
|
|
inline nsISupports*
|
2014-11-14 07:03:50 +03:00
|
|
|
ToSupports(WebGLContext* webgl)
|
2012-10-04 01:13:05 +04:00
|
|
|
{
|
2018-02-26 22:36:04 +03:00
|
|
|
return static_cast<nsICanvasRenderingContextInternal*>(webgl);
|
2012-10-04 01:13:05 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// Returns `value` rounded to the next highest multiple of `multiple`.
|
|
|
|
// AKA PadToAlignment, StrideForAlignment.
|
|
|
|
template<typename V, typename M>
|
|
|
|
V
|
|
|
|
RoundUpToMultipleOf(const V& value, const M& multiple)
|
|
|
|
{
|
|
|
|
return ((value + multiple - 1) / multiple) * multiple;
|
|
|
|
}
|
2015-02-25 01:09:09 +03:00
|
|
|
|
2015-08-04 00:34:46 +03:00
|
|
|
bool
|
2015-11-25 07:15:29 +03:00
|
|
|
ValidateTexTarget(WebGLContext* webgl, const char* funcName, uint8_t funcDims,
|
|
|
|
GLenum rawTexTarget, TexTarget* const out_texTarget,
|
|
|
|
WebGLTexture** const out_tex);
|
2015-08-04 00:34:46 +03:00
|
|
|
bool
|
2015-11-25 07:15:29 +03:00
|
|
|
ValidateTexImageTarget(WebGLContext* webgl, const char* funcName, uint8_t funcDims,
|
|
|
|
GLenum rawTexImageTarget, TexImageTarget* const out_texImageTarget,
|
2015-08-04 00:34:46 +03:00
|
|
|
WebGLTexture** const out_tex);
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
class ScopedUnpackReset final
|
2015-11-25 07:15:29 +03:00
|
|
|
: public gl::ScopedGLWrapper<ScopedUnpackReset>
|
|
|
|
{
|
|
|
|
friend struct gl::ScopedGLWrapper<ScopedUnpackReset>;
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
private:
|
2015-11-25 07:15:29 +03:00
|
|
|
WebGLContext* const mWebGL;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ScopedUnpackReset(WebGLContext* webgl);
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
private:
|
|
|
|
void UnwrapImpl();
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScopedFBRebinder final
|
|
|
|
: public gl::ScopedGLWrapper<ScopedFBRebinder>
|
|
|
|
{
|
|
|
|
friend struct gl::ScopedGLWrapper<ScopedFBRebinder>;
|
|
|
|
|
|
|
|
private:
|
|
|
|
WebGLContext* const mWebGL;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ScopedFBRebinder(WebGLContext* webgl)
|
|
|
|
: ScopedGLWrapper<ScopedFBRebinder>(webgl->gl)
|
|
|
|
, mWebGL(webgl)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
2015-11-25 07:15:29 +03:00
|
|
|
void UnwrapImpl();
|
|
|
|
};
|
2015-08-04 00:34:46 +03:00
|
|
|
|
2016-09-26 23:38:56 +03:00
|
|
|
class ScopedLazyBind final
|
|
|
|
: public gl::ScopedGLWrapper<ScopedLazyBind>
|
|
|
|
{
|
|
|
|
friend struct gl::ScopedGLWrapper<ScopedLazyBind>;
|
|
|
|
|
|
|
|
const GLenum mTarget;
|
|
|
|
const WebGLBuffer* const mBuf;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ScopedLazyBind(gl::GLContext* gl, GLenum target, const WebGLBuffer* buf);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void UnwrapImpl();
|
|
|
|
};
|
|
|
|
|
2016-10-12 01:39:23 +03:00
|
|
|
////
|
2015-10-14 08:48:19 +03:00
|
|
|
|
2017-02-28 02:24:14 +03:00
|
|
|
bool
|
|
|
|
Intersect(int32_t srcSize, int32_t read0, int32_t readSize, int32_t* out_intRead0,
|
|
|
|
int32_t* out_intWrite0, int32_t* out_intSize);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
uint64_t
|
|
|
|
AvailGroups(uint64_t totalAvailItems, uint64_t firstItemOffset, uint32_t groupSize,
|
|
|
|
uint32_t groupStride);
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
class ScopedDrawCallWrapper final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebGLContext& mWebGL;
|
|
|
|
|
|
|
|
explicit ScopedDrawCallWrapper(WebGLContext& webgl);
|
|
|
|
~ScopedDrawCallWrapper();
|
|
|
|
};
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
void
|
|
|
|
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
|
|
|
|
const std::vector<IndexedBufferBinding>& field,
|
|
|
|
const char* name, uint32_t flags = 0);
|
|
|
|
|
|
|
|
void
|
|
|
|
ImplCycleCollectionUnlink(std::vector<IndexedBufferBinding>& field);
|
|
|
|
|
2012-11-15 11:32:39 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2009-09-03 04:47:49 +04:00
|
|
|
#endif
|