123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190 |
- /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
- /* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
- #ifndef WEBGLCONTEXT_H_
- #define WEBGLCONTEXT_H_
- #include <stdarg.h>
- #include "GLContextTypes.h"
- #include "GLDefs.h"
- #include "mozilla/Attributes.h"
- #include "mozilla/CheckedInt.h"
- #include "mozilla/dom/BindingDeclarations.h"
- #include "mozilla/dom/HTMLCanvasElement.h"
- #include "mozilla/dom/TypedArray.h"
- #include "mozilla/EnumeratedArray.h"
- #include "mozilla/ErrorResult.h"
- #include "mozilla/gfx/2D.h"
- #include "mozilla/LinkedList.h"
- #include "mozilla/UniquePtr.h"
- #include "mozilla/WeakPtr.h"
- #include "nsCycleCollectionNoteChild.h"
- #include "nsICanvasRenderingContextInternal.h"
- #include "nsLayoutUtils.h"
- #include "nsTArray.h"
- #include "nsWrapperCache.h"
- #include "SurfaceTypes.h"
- #include "ScopedGLHelpers.h"
- #include "TexUnpackBlob.h"
- // Local
- #include "WebGLContextLossHandler.h"
- #include "WebGLContextUnchecked.h"
- #include "WebGLFormats.h"
- #include "WebGLObjectModel.h"
- #include "WebGLStrongTypes.h"
- #include "WebGLTexture.h"
- // Generated
- #include "nsIDOMEventListener.h"
- #include "nsIDOMWebGLRenderingContext.h"
- #include "nsICanvasRenderingContextInternal.h"
- #include "nsIObserver.h"
- #include "mozilla/dom/HTMLCanvasElement.h"
- #include "nsWrapperCache.h"
- #include "nsLayoutUtils.h"
- #include "mozilla/dom/WebGLRenderingContextBinding.h"
- #include "mozilla/dom/WebGL2RenderingContextBinding.h"
- class nsIDocShell;
- /*
- * Minimum value constants defined in 6.2 State Tables of OpenGL ES - 2.0.25
- * https://bugzilla.mozilla.org/show_bug.cgi?id=686732
- *
- * Exceptions: some of the following values are set to higher values than in the spec because
- * the values in the spec are ridiculously low. They are explicitly marked below
- */
- #define MINVALUE_GL_MAX_TEXTURE_SIZE 1024 // Different from the spec, which sets it to 64 on page 162
- #define MINVALUE_GL_MAX_CUBE_MAP_TEXTURE_SIZE 512 // Different from the spec, which sets it to 16 on page 162
- #define MINVALUE_GL_MAX_VERTEX_ATTRIBS 8 // Page 164
- #define MINVALUE_GL_MAX_FRAGMENT_UNIFORM_VECTORS 16 // Page 164
- #define MINVALUE_GL_MAX_VERTEX_UNIFORM_VECTORS 128 // Page 164
- #define MINVALUE_GL_MAX_VARYING_VECTORS 8 // Page 164
- #define MINVALUE_GL_MAX_TEXTURE_IMAGE_UNITS 8 // Page 164
- #define MINVALUE_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0 // Page 164
- #define MINVALUE_GL_MAX_RENDERBUFFER_SIZE 1024 // Different from the spec, which sets it to 1 on page 164
- #define MINVALUE_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 8 // Page 164
- /*
- * Minimum value constants define in 6.2 State Tables of OpenGL ES - 3.0.4
- */
- #define MINVALUE_GL_MAX_3D_TEXTURE_SIZE 256
- #define MINVALUE_GL_MAX_ARRAY_TEXTURE_LAYERS 256
- /*
- * 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
- namespace mozilla {
- class ScopedCopyTexImageSource;
- class ScopedResolveTexturesForDraw;
- class ScopedUnpackReset;
- class WebGLActiveInfo;
- class WebGLBuffer;
- class WebGLExtensionBase;
- class WebGLFramebuffer;
- class WebGLProgram;
- class WebGLQuery;
- class WebGLRenderbuffer;
- class WebGLSampler;
- class WebGLShader;
- class WebGLShaderPrecisionFormat;
- class WebGLSync;
- class WebGLTexture;
- class WebGLTransformFeedback;
- class WebGLUniformLocation;
- class WebGLVertexArray;
- namespace dom {
- class Element;
- class ImageData;
- class OwningHTMLCanvasElementOrOffscreenCanvas;
- struct WebGLContextAttributes;
- template<typename> struct Nullable;
- } // namespace dom
- namespace gfx {
- class SourceSurface;
- class VRLayerChild;
- } // namespace gfx
- namespace webgl {
- struct LinkedProgramInfo;
- class ShaderValidator;
- class TexUnpackBlob;
- struct UniformInfo;
- struct UniformBlockInfo;
- } // namespace webgl
- WebGLTexelFormat GetWebGLTexelFormat(TexInternalFormat format);
- void AssertUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint shadow);
- struct WebGLContextOptions
- {
- // these are defaults
- WebGLContextOptions();
- bool operator==(const WebGLContextOptions& other) const {
- return
- alpha == other.alpha &&
- depth == other.depth &&
- stencil == other.stencil &&
- premultipliedAlpha == other.premultipliedAlpha &&
- antialias == other.antialias &&
- preserveDrawingBuffer == other.preserveDrawingBuffer;
- }
- bool operator!=(const WebGLContextOptions& other) const {
- return !operator==(other);
- }
- bool alpha;
- bool depth;
- bool stencil;
- bool premultipliedAlpha;
- bool antialias;
- bool preserveDrawingBuffer;
- bool failIfMajorPerformanceCaveat;
- };
- // From WebGLContextUtils
- TexTarget TexImageTargetToTexTarget(TexImageTarget texImageTarget);
- struct WebGLIntOrFloat {
- const enum {
- Int,
- Float,
- Uint
- } mType;
- union {
- GLint i;
- GLfloat f;
- GLuint u;
- } 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); }
- };
- struct IndexedBufferBinding
- {
- WebGLRefPtr<WebGLBuffer> mBufferBinding;
- uint64_t mRangeStart;
- uint64_t mRangeSize;
- IndexedBufferBinding();
- uint64_t ByteCount() const;
- };
- ////
- 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;
- }
- };
- ////////////////////////////////////
- struct TexImageSource
- {
- const dom::ArrayBufferView* mView;
- GLuint mViewElemOffset;
- GLuint mViewElemLengthOverride;
- const WebGLsizeiptr* mPboOffset;
- const dom::ImageBitmap* mImageBitmap;
- const dom::ImageData* mImageData;
- const dom::Element* mDomElem;
- ErrorResult* mOut_error;
- protected:
- TexImageSource() {
- memset(this, 0, sizeof(*this));
- }
- };
- ////
- struct TexImageSourceAdapter final : public TexImageSource
- {
- TexImageSourceAdapter(const dom::Nullable<dom::ArrayBufferView>* maybeView,
- ErrorResult*)
- {
- if (!maybeView->IsNull()) {
- mView = &(maybeView->Value());
- }
- }
- TexImageSourceAdapter(const dom::ArrayBufferView* view, ErrorResult*) {
- mView = view;
- }
- TexImageSourceAdapter(const dom::ArrayBufferView* view, GLuint viewElemOffset,
- GLuint viewElemLengthOverride = 0)
- {
- mView = view;
- mViewElemOffset = viewElemOffset;
- mViewElemLengthOverride = viewElemLengthOverride;
- }
- TexImageSourceAdapter(const WebGLsizeiptr* pboOffset, GLuint ignored1, GLuint ignored2 = 0) {
- mPboOffset = pboOffset;
- }
- TexImageSourceAdapter(const WebGLsizeiptr* pboOffset, ErrorResult* ignored) {
- mPboOffset = pboOffset;
- }
- TexImageSourceAdapter(const dom::ImageBitmap* imageBitmap, ErrorResult* out_error) {
- mImageBitmap = imageBitmap;
- mOut_error = out_error;
- }
- TexImageSourceAdapter(const dom::ImageData* imageData, ErrorResult*) {
- mImageData = imageData;
- }
- TexImageSourceAdapter(const dom::Element* domElem, ErrorResult* const out_error) {
- mDomElem = domElem;
- mOut_error = out_error;
- }
- };
- ////////////////////////////////////////////////////////////////////////////////
- class WebGLContext
- : public nsIDOMWebGLRenderingContext
- , public nsICanvasRenderingContextInternal
- , public nsSupportsWeakReference
- , public WebGLContextUnchecked
- , public WebGLRectangleObject
- , public nsWrapperCache
- , public SupportsWeakPtr<WebGLContext>
- {
- friend class ScopedDrawHelper;
- friend class ScopedDrawWithTransformFeedback;
- friend class ScopedFBRebinder;
- friend class WebGL2Context;
- friend class WebGLContextUserData;
- friend class WebGLExtensionCompressedTextureATC;
- friend class WebGLExtensionCompressedTextureES3;
- friend class WebGLExtensionCompressedTextureETC1;
- friend class WebGLExtensionCompressedTexturePVRTC;
- friend class WebGLExtensionCompressedTextureS3TC;
- friend class WebGLExtensionDepthTexture;
- friend class WebGLExtensionDisjointTimerQuery;
- friend class WebGLExtensionDrawBuffers;
- friend class WebGLExtensionLoseContext;
- friend class WebGLExtensionVertexArray;
- friend class WebGLMemoryTracker;
- friend struct webgl::UniformBlockInfo;
- enum {
- UNPACK_FLIP_Y_WEBGL = 0x9240,
- UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241,
- CONTEXT_LOST_WEBGL = 0x9242,
- UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
- BROWSER_DEFAULT_WEBGL = 0x9244,
- UNMASKED_VENDOR_WEBGL = 0x9245,
- UNMASKED_RENDERER_WEBGL = 0x9246
- };
- static const uint32_t kMinMaxColorAttachments;
- static const uint32_t kMinMaxDrawBuffers;
- public:
- WebGLContext();
- protected:
- virtual ~WebGLContext();
- public:
- NS_DECL_CYCLE_COLLECTING_ISUPPORTS
- NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(WebGLContext,
- nsIDOMWebGLRenderingContext)
- MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLContext)
- virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override = 0;
- NS_DECL_NSIDOMWEBGLRENDERINGCONTEXT
- virtual void OnVisibilityChange() override;
- virtual void OnMemoryPressure() override;
- // nsICanvasRenderingContextInternal
- virtual int32_t GetWidth() const override;
- virtual int32_t GetHeight() const override;
- NS_IMETHOD SetDimensions(int32_t width, int32_t height) override;
- NS_IMETHOD InitializeWithDrawTarget(nsIDocShell*,
- NotNull<gfx::DrawTarget*>) override
- {
- return NS_ERROR_NOT_IMPLEMENTED;
- }
- NS_IMETHOD Reset() override {
- /* (InitializeWithSurface) */
- return NS_ERROR_NOT_IMPLEMENTED;
- }
- virtual UniquePtr<uint8_t[]> GetImageBuffer(int32_t* out_format) override;
- NS_IMETHOD GetInputStream(const char* mimeType,
- const char16_t* encoderOptions,
- nsIInputStream** out_stream) override;
- already_AddRefed<mozilla::gfx::SourceSurface>
- GetSurfaceSnapshot(bool* out_premultAlpha) override;
- NS_IMETHOD SetIsOpaque(bool) override { return NS_OK; };
- bool GetIsOpaque() override { return false; }
- NS_IMETHOD SetContextOptions(JSContext* cx,
- JS::Handle<JS::Value> options,
- ErrorResult& aRvForDictionaryInit) override;
- NS_IMETHOD SetIsIPC(bool) override {
- return NS_ERROR_NOT_IMPLEMENTED;
- }
- /**
- * 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.
- */
- virtual void DidRefresh() override;
- NS_IMETHOD Redraw(const gfxRect&) override {
- return NS_ERROR_NOT_IMPLEMENTED;
- }
- void SynthesizeGLError(GLenum err);
- void SynthesizeGLError(GLenum err, const char* fmt, ...);
- void ErrorInvalidEnum(const char* fmt = 0, ...);
- void ErrorInvalidOperation(const char* fmt = 0, ...);
- void ErrorInvalidValue(const char* fmt = 0, ...);
- void ErrorInvalidFramebufferOperation(const char* fmt = 0, ...);
- void ErrorInvalidEnumInfo(const char* info, GLenum enumValue);
- void ErrorInvalidEnumInfo(const char* info, const char* funcName,
- GLenum enumValue);
- void ErrorOutOfMemory(const char* fmt = 0, ...);
- void ErrorImplementationBug(const char* fmt = 0, ...);
- void ErrorInvalidEnumArg(const char* funcName, const char* argName, GLenum val);
- const char* ErrorName(GLenum error);
- /**
- * 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.
- * Returns hex formatted version of glenum if glenum is unknown.
- */
- static void EnumName(GLenum val, nsCString* out_name);
- void DummyReadFramebufferOperation(const char* funcName);
- WebGLTexture* ActiveBoundTextureForTarget(const TexTarget texTarget) const {
- switch (texTarget.get()) {
- 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];
- case LOCAL_GL_TEXTURE_2D_ARRAY:
- return mBound2DArrayTextures[mActiveTexture];
- default:
- MOZ_CRASH("GFX: bad target");
- }
- }
- /* 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.
- */
- WebGLTexture*
- ActiveBoundTextureForTexImageTarget(const TexImageTarget texImgTarget) const
- {
- const TexTarget texTarget = TexImageTargetToTexTarget(texImgTarget);
- return ActiveBoundTextureForTarget(texTarget);
- }
- void InvalidateResolveCacheForTextureWithTexUnit(const GLuint);
- already_AddRefed<Layer>
- GetCanvasLayer(nsDisplayListBuilder* builder, Layer* oldLayer,
- LayerManager* manager,
- bool aMirror = false) override;
- // Note that 'clean' here refers to its invalidation state, not the
- // contents of the buffer.
- void MarkContextClean() override { mInvalidated = false; }
- void MarkContextCleanForFrameCapture() override { mCapturedFrameInvalidated = false; }
- bool IsContextCleanForFrameCapture() override { return !mCapturedFrameInvalidated; }
- gl::GLContext* GL() const { return gl; }
- bool IsPremultAlpha() const { return mOptions.premultipliedAlpha; }
- bool IsPreservingDrawingBuffer() const { return mOptions.preserveDrawingBuffer; }
- bool PresentScreenBuffer();
- // Prepare the context for capture before compositing
- void BeginComposition();
- // Clean up the context after captured for compositing
- void EndComposition();
- // a number that increments every time we have an event that causes
- // all context resources to be lost.
- uint32_t Generation() const { return mGeneration.value(); }
- // This is similar to GLContext::ClearSafely, but tries to minimize the
- // amount of work it does.
- // It only clears the buffers we specify, and can reset its state without
- // first having to query anything, as WebGL knows its state at all times.
- void ForceClearFramebufferWithDefaultValues(GLbitfield bufferBits, bool fakeNoAlpha);
- // Calls ForceClearFramebufferWithDefaultValues() for the Context's 'screen'.
- void ClearScreen();
- void ClearBackbufferIfNeeded();
- bool MinCapabilityMode() const { return mMinCapability; }
- void RunContextLossTimer();
- void UpdateContextLossStatus();
- void EnqueueUpdateContextLossStatus();
- bool TryToRestoreContext();
- void AssertCachedBindings();
- void AssertCachedGlobalState();
- dom::HTMLCanvasElement* GetCanvas() const { return mCanvasElement; }
- // WebIDL WebGLRenderingContext API
- void Commit();
- void GetCanvas(Nullable<dom::OwningHTMLCanvasElementOrOffscreenCanvas>& retval);
- GLsizei DrawingBufferWidth() const { return IsContextLost() ? 0 : mWidth; }
- GLsizei DrawingBufferHeight() const {
- return IsContextLost() ? 0 : mHeight;
- }
- layers::LayersBackend GetCompositorBackendType() const;
- void
- GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& retval);
- bool IsContextLost() const { return mContextStatus != ContextNotLost; }
- void GetSupportedExtensions(dom::Nullable< nsTArray<nsString> >& retval,
- dom::CallerType callerType);
- void GetExtension(JSContext* cx, const nsAString& name,
- JS::MutableHandle<JSObject*> retval,
- dom::CallerType callerType, ErrorResult& rv);
- void AttachShader(WebGLProgram& prog, WebGLShader& shader);
- void BindAttribLocation(WebGLProgram& prog, GLuint location,
- const nsAString& name);
- void BindFramebuffer(GLenum target, WebGLFramebuffer* fb);
- void BindRenderbuffer(GLenum target, WebGLRenderbuffer* fb);
- void BindVertexArray(WebGLVertexArray* vao);
- void BlendColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
- 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);
- void ColorMask(WebGLboolean r, WebGLboolean g, WebGLboolean b, WebGLboolean a);
- void CompileShader(WebGLShader& shader);
- void CompileShaderANGLE(WebGLShader* shader);
- void CompileShaderBypass(WebGLShader* shader, const nsCString& shaderSource);
- already_AddRefed<WebGLFramebuffer> CreateFramebuffer();
- already_AddRefed<WebGLProgram> CreateProgram();
- already_AddRefed<WebGLRenderbuffer> CreateRenderbuffer();
- already_AddRefed<WebGLShader> CreateShader(GLenum type);
- already_AddRefed<WebGLVertexArray> CreateVertexArray();
- void CullFace(GLenum face);
- void DeleteFramebuffer(WebGLFramebuffer* fb);
- void DeleteProgram(WebGLProgram* prog);
- void DeleteRenderbuffer(WebGLRenderbuffer* rb);
- void DeleteShader(WebGLShader* shader);
- void DeleteVertexArray(WebGLVertexArray* vao);
- void DepthFunc(GLenum func);
- void DepthMask(WebGLboolean b);
- void DepthRange(GLclampf zNear, GLclampf zFar);
- void DetachShader(WebGLProgram& prog, const WebGLShader& shader);
- void DrawBuffers(const dom::Sequence<GLenum>& buffers);
- void Flush();
- void Finish();
- void FramebufferRenderbuffer(GLenum target, GLenum attachment,
- GLenum rbTarget, WebGLRenderbuffer* rb);
- void FramebufferTexture2D(GLenum target, GLenum attachment,
- GLenum texImageTarget, WebGLTexture* tex,
- GLint level);
- void FrontFace(GLenum mode);
- already_AddRefed<WebGLActiveInfo> GetActiveAttrib(const WebGLProgram& prog,
- GLuint index);
- already_AddRefed<WebGLActiveInfo> GetActiveUniform(const WebGLProgram& prog,
- GLuint index);
- void
- GetAttachedShaders(const WebGLProgram& prog,
- dom::Nullable<nsTArray<RefPtr<WebGLShader>>>& retval);
- GLint GetAttribLocation(const WebGLProgram& prog, const nsAString& name);
- JS::Value GetBufferParameter(GLenum target, GLenum pname);
- void GetBufferParameter(JSContext*, GLenum target, GLenum pname,
- JS::MutableHandle<JS::Value> retval)
- {
- retval.set(GetBufferParameter(target, pname));
- }
- GLenum GetError();
- virtual JS::Value GetFramebufferAttachmentParameter(JSContext* cx, GLenum target,
- GLenum attachment, GLenum pname,
- ErrorResult& rv);
- void GetFramebufferAttachmentParameter(JSContext* cx, GLenum target,
- GLenum attachment, GLenum pname,
- JS::MutableHandle<JS::Value> retval,
- ErrorResult& rv)
- {
- retval.set(GetFramebufferAttachmentParameter(cx, target, attachment,
- pname, rv));
- }
- JS::Value GetProgramParameter(const WebGLProgram& prog, GLenum pname);
- void GetProgramParameter(JSContext*, const WebGLProgram& prog, GLenum pname,
- JS::MutableHandle<JS::Value> retval)
- {
- retval.set(GetProgramParameter(prog, pname));
- }
- void GetProgramInfoLog(const WebGLProgram& prog, nsACString& retval);
- void GetProgramInfoLog(const WebGLProgram& prog, nsAString& retval);
- JS::Value GetRenderbufferParameter(GLenum target, GLenum pname);
- void GetRenderbufferParameter(JSContext*, GLenum target, GLenum pname,
- JS::MutableHandle<JS::Value> retval)
- {
- retval.set(GetRenderbufferParameter(target, pname));
- }
- JS::Value GetShaderParameter(const WebGLShader& shader, GLenum pname);
- void GetShaderParameter(JSContext*, const WebGLShader& shader, GLenum pname,
- JS::MutableHandle<JS::Value> retval)
- {
- retval.set(GetShaderParameter(shader, pname));
- }
- already_AddRefed<WebGLShaderPrecisionFormat>
- GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype);
- void GetShaderInfoLog(const WebGLShader& shader, nsACString& retval);
- void GetShaderInfoLog(const WebGLShader& shader, nsAString& retval);
- void GetShaderSource(const WebGLShader& shader, nsAString& retval);
- JS::Value GetUniform(JSContext* cx, const WebGLProgram& prog,
- const WebGLUniformLocation& loc);
- void GetUniform(JSContext* cx, const WebGLProgram& prog,
- const WebGLUniformLocation& loc,
- JS::MutableHandle<JS::Value> retval)
- {
- retval.set(GetUniform(cx, prog, loc));
- }
- already_AddRefed<WebGLUniformLocation>
- GetUniformLocation(const WebGLProgram& prog, const nsAString& name);
- void Hint(GLenum target, GLenum mode);
- 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);
- void LineWidth(GLfloat width);
- void LinkProgram(WebGLProgram& prog);
- void PixelStorei(GLenum pname, GLint param);
- void PolygonOffset(GLfloat factor, GLfloat units);
- ////
- webgl::PackingInfo
- ValidImplementationColorReadPI(const webgl::FormatUsageInfo* usage) const;
- protected:
- bool ReadPixels_SharedPrecheck(ErrorResult* const out_error);
- 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,
- GLenum destType, void* dest, uint32_t dataLen,
- uint32_t rowStride);
- public:
- void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
- GLenum type, const dom::Nullable<dom::ArrayBufferView>& maybeView,
- ErrorResult& rv)
- {
- const char funcName[] = "readPixels";
- if (maybeView.IsNull()) {
- ErrorInvalidValue("%s: `pixels` must not be null.", funcName);
- return;
- }
- ReadPixels(x, y, width, height, format, type, maybeView.Value(), 0, rv);
- }
- void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
- GLenum type, WebGLsizeiptr offset, ErrorResult& out_error);
- void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
- GLenum type, const dom::ArrayBufferView& dstData, GLuint dstOffset,
- ErrorResult& out_error);
- ////
- void RenderbufferStorage(GLenum target, GLenum internalFormat,
- GLsizei width, GLsizei height);
- protected:
- void RenderbufferStorage_base(const char* funcName, GLenum target,
- GLsizei samples, GLenum internalformat,
- GLsizei width, GLsizei height);
- public:
- void SampleCoverage(GLclampf value, WebGLboolean invert);
- void Scissor(GLint x, GLint y, GLsizei width, GLsizei height);
- void ShaderSource(WebGLShader& shader, const nsAString& source);
- void StencilFunc(GLenum func, GLint ref, GLuint mask);
- void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
- void StencilMask(GLuint mask);
- void StencilMaskSeparate(GLenum face, GLuint mask);
- void StencilOp(GLenum sfail, GLenum dpfail, GLenum dppass);
- void StencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail,
- GLenum dppass);
- //////
- void 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);
- void Uniform1i(WebGLUniformLocation* loc, GLint x);
- void Uniform2i(WebGLUniformLocation* loc, GLint x, GLint y);
- void Uniform3i(WebGLUniformLocation* loc, GLint x, GLint y, GLint z);
- void Uniform4i(WebGLUniformLocation* loc, GLint x, GLint y, GLint z, GLint w);
- 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);
- //////////////////////////
- typedef dom::Float32ArrayOrUnrestrictedFloatSequence Float32ListU;
- typedef dom::Int32ArrayOrLongSequence Int32ListU;
- typedef dom::Uint32ArrayOrUnsignedLongSequence Uint32ListU;
- protected:
- template<typename elemT, typename viewT>
- struct Arr {
- 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())
- { }
- 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());
- }
- 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());
- }
- };
- typedef Arr<GLfloat, dom::Float32Array> Float32Arr;
- typedef Arr<GLint, dom::Int32Array> Int32Arr;
- typedef Arr<GLuint, dom::Uint32Array> Uint32Arr;
- ////////////////
- void UniformNfv(const char* funcName, uint8_t N, WebGLUniformLocation* loc,
- 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);
- void UniformMatrixAxBfv(const char* funcName, uint8_t A, uint8_t B,
- WebGLUniformLocation* loc, bool transpose,
- const Float32Arr& arr, GLuint elemOffset,
- GLuint elemCountOverride);
- ////////////////
- public:
- #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
- //////
- #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
- //////
- #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
- ////////////////////////////////////
- void UseProgram(WebGLProgram* prog);
- bool ValidateAttribArraySetter(const char* name, uint32_t count,
- uint32_t arrayLength);
- bool ValidateUniformLocation(WebGLUniformLocation* loc, const char* funcName);
- bool ValidateUniformSetter(WebGLUniformLocation* loc, uint8_t setterSize,
- GLenum setterType, const char* funcName);
- bool ValidateUniformArraySetter(WebGLUniformLocation* loc,
- uint8_t setterElemSize, GLenum setterType,
- uint32_t setterArraySize, const char* funcName,
- uint32_t* out_numElementsToUpload);
- bool ValidateUniformMatrixArraySetter(WebGLUniformLocation* loc,
- uint8_t setterCols,
- uint8_t setterRows,
- GLenum setterType,
- uint32_t setterArraySize,
- bool setterTranspose,
- const char* funcName,
- uint32_t* out_numElementsToUpload);
- void ValidateProgram(const WebGLProgram& prog);
- bool ValidateUniformLocation(const char* info, WebGLUniformLocation* loc);
- bool ValidateSamplerUniformSetter(const char* info,
- WebGLUniformLocation* loc, GLint value);
- void Viewport(GLint x, GLint y, GLsizei width, GLsizei height);
- // -----------------------------------------------------------------------------
- // WEBGL_lose_context
- public:
- void LoseContext();
- void RestoreContext();
- // -----------------------------------------------------------------------------
- // Buffer Objects (WebGLContextBuffers.cpp)
- void BindBuffer(GLenum target, WebGLBuffer* buffer);
- void BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buf);
- void BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buf,
- WebGLintptr offset, WebGLsizeiptr size);
- private:
- void BufferDataImpl(GLenum target, size_t dataLen, const uint8_t* data, GLenum usage);
- public:
- void BufferData(GLenum target, WebGLsizeiptr size, GLenum usage);
- void BufferData(GLenum target, const dom::Nullable<dom::ArrayBuffer>& maybeSrc,
- GLenum usage);
- void BufferData(GLenum target, const dom::ArrayBufferView& srcData, GLenum usage,
- GLuint srcElemOffset = 0, GLuint srcElemCountOverride = 0);
- private:
- void BufferSubDataImpl(GLenum target, WebGLsizeiptr dstByteOffset,
- size_t srcDataLen, const uint8_t* srcData);
- public:
- void BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
- const dom::ArrayBufferView& src, GLuint srcElemOffset = 0,
- GLuint srcElemCountOverride = 0);
- void BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
- const dom::ArrayBuffer& src);
- void BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
- const dom::SharedArrayBuffer& src);
- already_AddRefed<WebGLBuffer> CreateBuffer();
- void DeleteBuffer(WebGLBuffer* buf);
- bool IsBuffer(WebGLBuffer* buf);
- protected:
- // bound buffer state
- WebGLRefPtr<WebGLBuffer> mBoundArrayBuffer;
- WebGLRefPtr<WebGLBuffer> mBoundCopyReadBuffer;
- WebGLRefPtr<WebGLBuffer> mBoundCopyWriteBuffer;
- WebGLRefPtr<WebGLBuffer> mBoundPixelPackBuffer;
- WebGLRefPtr<WebGLBuffer> mBoundPixelUnpackBuffer;
- WebGLRefPtr<WebGLBuffer> mBoundUniformBuffer;
- std::vector<IndexedBufferBinding> mIndexedUniformBufferBindings;
- WebGLRefPtr<WebGLBuffer>& GetBufferSlotByTarget(GLenum target);
- WebGLRefPtr<WebGLBuffer>& GetBufferSlotByTargetIndexed(GLenum target,
- GLuint index);
- // -----------------------------------------------------------------------------
- // Queries (WebGL2ContextQueries.cpp)
- protected:
- 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);
- void BeginQuery(GLenum target, WebGLQuery& query, const char* funcName = nullptr);
- void EndQuery(GLenum target, const char* funcName = nullptr);
- void GetQuery(JSContext* cx, GLenum target, GLenum pname,
- JS::MutableHandleValue retval, const char* funcName = nullptr);
- void GetQueryParameter(JSContext* cx, const WebGLQuery& query, GLenum pname,
- JS::MutableHandleValue retval, const char* funcName = nullptr);
- // -----------------------------------------------------------------------------
- // State and State Requests (WebGLContextState.cpp)
- public:
- void Disable(GLenum cap);
- void Enable(GLenum cap);
- bool GetStencilBits(GLint* const out_stencilBits);
- bool GetChannelBits(const char* funcName, GLenum pname, GLint* const out_val);
- virtual JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv);
- void GetParameter(JSContext* cx, GLenum pname,
- JS::MutableHandle<JS::Value> retval, ErrorResult& rv)
- {
- retval.set(GetParameter(cx, pname, rv));
- }
- void GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index,
- JS::MutableHandle<JS::Value> retval);
- bool IsEnabled(GLenum cap);
- private:
- // State tracking slots
- realGLboolean mDitherEnabled;
- realGLboolean mRasterizerDiscardEnabled;
- realGLboolean mScissorTestEnabled;
- realGLboolean mDepthTestEnabled;
- realGLboolean mStencilTestEnabled;
- GLenum mGenerateMipmapHint;
- bool ValidateCapabilityEnum(GLenum cap, const char* info);
- realGLboolean* GetStateTrackingSlot(GLenum cap);
- // -----------------------------------------------------------------------------
- // 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) {
- TexParameter_base(texTarget, pname, FloatOrInt(param));
- }
- void TexParameteri(GLenum texTarget, GLenum pname, GLint param) {
- TexParameter_base(texTarget, pname, FloatOrInt(param));
- }
- protected:
- JS::Value GetTexParameter(GLenum texTarget, GLenum pname);
- void TexParameter_base(GLenum texTarget, GLenum pname, const FloatOrInt& param);
- virtual bool IsTexParamValid(GLenum pname) const;
- ////////////////////////////////////
- public:
- template<typename T>
- void CompressedTexImage2D(GLenum target, GLint level, GLenum internalFormat,
- GLsizei width, GLsizei height, GLint border,
- const T& anySrc, GLuint viewElemOffset = 0,
- GLuint viewElemLengthOverride = 0)
- {
- const char funcName[] = "compressedTexImage2D";
- const uint8_t funcDims = 2;
- const GLsizei depth = 1;
- const TexImageSourceAdapter src(&anySrc, viewElemOffset, viewElemLengthOverride);
- CompressedTexImage(funcName, funcDims, target, level, internalFormat, width,
- height, depth, border, src);
- }
- template<typename T>
- void CompressedTexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
- GLsizei width, GLsizei height, GLenum unpackFormat,
- const T& anySrc, GLuint viewElemOffset = 0,
- GLuint viewElemLengthOverride = 0)
- {
- const char funcName[] = "compressedTexSubImage2D";
- const uint8_t funcDims = 2;
- const GLint zOffset = 0;
- const GLsizei depth = 1;
- const TexImageSourceAdapter src(&anySrc, viewElemOffset, viewElemLengthOverride);
- CompressedTexSubImage(funcName, funcDims, target, level, xOffset, yOffset,
- zOffset, width, height, depth, unpackFormat, src);
- }
- protected:
- void CompressedTexImage(const char* funcName, uint8_t funcDims, GLenum target,
- GLint level, GLenum internalFormat, GLsizei width,
- GLsizei height, GLsizei depth, GLint border,
- const TexImageSource& src);
- void CompressedTexSubImage(const char* funcName, uint8_t funcDims, GLenum target,
- GLint level, GLint xOffset, GLint yOffset, GLint zOffset,
- GLsizei width, GLsizei height, GLsizei depth,
- GLenum unpackFormat, const TexImageSource& src);
- ////////////////////////////////////
- public:
- void CopyTexImage2D(GLenum target, GLint level, GLenum internalFormat, GLint x,
- GLint y, GLsizei width, GLsizei height, GLint border);
- void CopyTexSubImage2D(GLenum target, GLint level, GLint xOffset,
- GLint yOffset, GLint x, GLint y, GLsizei width,
- GLsizei height)
- {
- 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);
- }
- 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);
- ////////////////////////////////////
- // TexImage
- // Implicit width/height uploads
- public:
- template<typename T>
- void TexImage2D(GLenum target, GLint level, GLenum internalFormat,
- GLenum unpackFormat, GLenum unpackType, const T& src,
- ErrorResult& out_error)
- {
- GLsizei width = 0;
- GLsizei height = 0;
- GLint border = 0;
- TexImage2D(target, level, internalFormat, width, height, border, unpackFormat,
- unpackType, src, out_error);
- }
- 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);
- }
- ////
- 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)
- {
- const TexImageSourceAdapter src(&anySrc, &out_error);
- TexImage2D(target, level, internalFormat, width, height, border, unpackFormat,
- unpackType, src);
- }
- 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&)
- {
- const TexImageSourceAdapter src(&view, viewElemOffset);
- TexImage2D(target, level, internalFormat, width, height, border, unpackFormat,
- unpackType, src);
- }
- 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);
- ////
- public:
- template<typename T>
- void TexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
- GLsizei width, GLsizei height, GLenum unpackFormat,
- GLenum unpackType, const T& anySrc, ErrorResult& out_error)
- {
- const TexImageSourceAdapter src(&anySrc, &out_error);
- TexSubImage2D(target, level, xOffset, yOffset, width, height, unpackFormat,
- unpackType, src);
- }
- 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&)
- {
- const TexImageSourceAdapter src(&view, viewElemOffset);
- TexSubImage2D(target, level, xOffset, yOffset, width, height, unpackFormat,
- unpackType, src);
- }
- protected:
- void TexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
- GLsizei width, GLsizei height, GLenum unpackFormat,
- 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);
- }
- 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);
- ////////////////////////////////////
- // WebGLTextureUpload.cpp
- public:
- UniquePtr<webgl::TexUnpackBlob>
- From(const char* funcName, TexImageTarget target, GLsizei rawWidth, GLsizei rawHeight,
- GLsizei rawDepth, GLint border, const TexImageSource& src,
- dom::Uint8ClampedArray* const scopedArr);
- protected:
- 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);
- bool ValidateUnpackInfo(const char* funcName, bool usePBOs, GLenum format,
- GLenum type, webgl::PackingInfo* const out);
- 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,
- const TexImageSource& src);
- // -----------------------------------------------------------------------------
- // Vertices Feature (WebGLContextVertices.cpp)
- GLenum mPrimRestartTypeBytes;
- public:
- void DrawArrays(GLenum mode, GLint first, GLsizei count);
- void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count,
- GLsizei primcount);
- void DrawElements(GLenum mode, GLsizei count, GLenum type,
- WebGLintptr byteOffset, const char* funcName = nullptr);
- void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
- WebGLintptr byteOffset, GLsizei primcount);
- void EnableVertexAttribArray(GLuint index);
- void DisableVertexAttribArray(GLuint index);
- JS::Value GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
- ErrorResult& rv);
- void GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
- JS::MutableHandle<JS::Value> retval, ErrorResult& rv)
- {
- retval.set(GetVertexAttrib(cx, index, pname, rv));
- }
- WebGLsizeiptr GetVertexAttribOffset(GLuint index, GLenum pname);
- ////
- void VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w,
- const char* funcName = nullptr);
- ////
- void VertexAttrib1f(GLuint index, GLfloat x) {
- VertexAttrib4f(index, x, 0, 0, 1, "vertexAttrib1f");
- }
- void VertexAttrib2f(GLuint index, GLfloat x, GLfloat y) {
- VertexAttrib4f(index, x, y, 0, 1, "vertexAttrib2f");
- }
- void VertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) {
- VertexAttrib4f(index, x, y, z, 1, "vertexAttrib3f");
- }
- ////
- 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);
- }
- 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);
- }
- 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);
- }
- 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);
- }
- ////
- void VertexAttribPointer(GLuint index, GLint size, GLenum type,
- WebGLboolean normalized, GLsizei stride,
- WebGLintptr byteOffset);
- void VertexAttribDivisor(GLuint index, GLuint divisor);
- private:
- // Cache the max number of vertices and instances that can be read from
- // bound VBOs (result of ValidateBuffers).
- bool mBufferFetchingIsVerified;
- bool mBufferFetchingHasPerVertex;
- uint32_t mMaxFetchedVertices;
- uint32_t mMaxFetchedInstances;
- bool mBufferFetch_IsAttrib0Active;
- bool DrawArrays_check(const char* funcName, GLenum mode, GLint first,
- GLsizei vertCount, GLsizei instanceCount);
- bool DrawElements_check(const char* funcName, GLenum mode, GLsizei vertCount,
- GLenum type, WebGLintptr byteOffset,
- GLsizei instanceCount);
- bool DrawInstanced_check(const char* info);
- void Draw_cleanup(const char* funcName);
- 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);
- bool ValidateBufferFetching(const char* info);
- bool BindArrayAttribToLocation0(WebGLProgram* prog);
- // -----------------------------------------------------------------------------
- // PROTECTED
- protected:
- WebGLVertexAttrib0Status WhatDoesVertexAttrib0Need() const;
- bool DoFakeVertexAttrib0(const char* funcName, GLuint vertexCount);
- void UndoFakeVertexAttrib0();
- inline void InvalidateBufferFetching()
- {
- mBufferFetchingIsVerified = false;
- mBufferFetchingHasPerVertex = false;
- mMaxFetchedVertices = 0;
- mMaxFetchedInstances = 0;
- }
- CheckedUint32 mGeneration;
- WebGLContextOptions mOptions;
- bool mInvalidated;
- bool mCapturedFrameInvalidated;
- bool mResetLayer;
- bool mLayerIsMirror;
- bool mOptionsFrozen;
- bool mMinCapability;
- bool mDisableExtensions;
- bool mIsMesa;
- bool mLoseContextOnMemoryPressure;
- bool mCanLoseContextInForeground;
- bool mRestoreWhenVisible;
- bool mShouldPresent;
- bool mBackbufferNeedsClear;
- bool mDisableFragHighP;
- template<typename WebGLObjectType>
- void DeleteWebGLObjectsArray(nsTArray<WebGLObjectType>& array);
- GLuint mActiveTexture;
- GLenum mDefaultFB_DrawBuffer0;
- // glGetError sources:
- bool mEmitContextLostErrorOnce;
- GLenum mWebGLError;
- GLenum mUnderlyingGLError;
- GLenum GetAndFlushUnderlyingGLErrors();
- bool mBypassShaderValidation;
- webgl::ShaderValidator* CreateShaderValidator(GLenum shaderType) const;
- // some GL constants
- uint32_t mGLMaxVertexAttribs;
- int32_t mGLMaxTextureUnits;
- int32_t mGLMaxTextureImageUnits;
- int32_t mGLMaxVertexTextureImageUnits;
- int32_t mGLMaxVaryingVectors;
- int32_t mGLMaxFragmentUniformVectors;
- int32_t mGLMaxVertexUniformVectors;
- uint32_t mGLMaxTransformFeedbackSeparateAttribs;
- GLuint mGLMaxUniformBufferBindings;
- // What is supported:
- uint32_t mGLMaxColorAttachments;
- uint32_t mGLMaxDrawBuffers;
- // What we're allowing:
- uint32_t mImplMaxColorAttachments;
- uint32_t mImplMaxDrawBuffers;
- uint32_t mImplMaxViewportDims[2];
- public:
- GLenum LastColorAttachmentEnum() const {
- return LOCAL_GL_COLOR_ATTACHMENT0 + mImplMaxColorAttachments - 1;
- }
- const decltype(mOptions)& Options() const { return mOptions; }
- protected:
- // Texture sizes are often not actually the GL values. Let's be explicit that these
- // are implementation limits.
- uint32_t mImplMaxTextureSize;
- uint32_t mImplMaxCubeMapTextureSize;
- uint32_t mImplMax3DTextureSize;
- uint32_t mImplMaxArrayTextureLayers;
- uint32_t mImplMaxRenderbufferSize;
- public:
- GLuint MaxVertexAttribs() const {
- return mGLMaxVertexAttribs;
- }
- GLuint GLMaxTextureUnits() const {
- return mGLMaxTextureUnits;
- }
- bool IsFormatValidForFB(TexInternalFormat format) const;
- protected:
- // 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.
- // 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.
- ContextNotLost,
- // 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
- };
- // -------------------------------------------------------------------------
- // WebGL extensions (implemented in WebGLContextExtensions.cpp)
- typedef EnumeratedArray<WebGLExtensionID, WebGLExtensionID::Max,
- RefPtr<WebGLExtensionBase>> ExtensionsArrayType;
- ExtensionsArrayType mExtensions;
- // enable an extension. the extension should not be enabled before.
- void EnableExtension(WebGLExtensionID ext);
- // Enable an extension if it's supported. Return the extension on success.
- WebGLExtensionBase* EnableSupportedExtension(dom::CallerType callerType,
- WebGLExtensionID ext);
- public:
- // returns true if the extension has been enabled by calling getExtension.
- bool IsExtensionEnabled(WebGLExtensionID ext) const;
- protected:
- // returns true if the extension is supported for this caller type (this decides what getSupportedExtensions exposes)
- bool IsExtensionSupported(dom::CallerType callerType,
- WebGLExtensionID ext) const;
- bool IsExtensionSupported(WebGLExtensionID ext) const;
- static const char* GetExtensionString(WebGLExtensionID ext);
- nsTArray<GLenum> mCompressedTextureFormats;
- // -------------------------------------------------------------------------
- // WebGL 2 specifics (implemented in WebGL2Context.cpp)
- public:
- virtual bool IsWebGL2() const = 0;
- struct FailureReason {
- nsCString key; // For reporting.
- nsCString info;
- FailureReason() { }
- template<typename A, typename B>
- FailureReason(const A& _key, const B& _info)
- : key(nsCString(_key))
- , info(nsCString(_info))
- { }
- };
- protected:
- bool InitWebGL2(FailureReason* const out_failReason);
- bool CreateAndInitGL(bool forceEnabled,
- std::vector<FailureReason>* const out_failReasons);
- bool ResizeBackbuffer(uint32_t width, uint32_t height);
- typedef already_AddRefed<gl::GLContext> FnCreateGL_T(const gl::SurfaceCaps& caps,
- gl::CreateContextFlags flags,
- WebGLContext* webgl,
- std::vector<FailureReason>* const out_failReasons);
- bool CreateAndInitGLWith(FnCreateGL_T fnCreateGL, const gl::SurfaceCaps& baseCaps,
- gl::CreateContextFlags flags,
- std::vector<FailureReason>* const out_failReasons);
- void ThrowEvent_WebGLContextCreationError(const nsACString& text);
- // -------------------------------------------------------------------------
- // Validation functions (implemented in WebGLContextValidate.cpp)
- bool InitAndValidateGL(FailureReason* const out_failReason);
- bool ValidateBlendEquationEnum(GLenum cap, const char* info);
- bool ValidateBlendFuncDstEnum(GLenum mode, const char* info);
- bool ValidateBlendFuncSrcEnum(GLenum mode, const char* info);
- bool ValidateBlendFuncEnumsCompatibility(GLenum sfactor, GLenum dfactor,
- const char* info);
- bool 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);
- 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);
- bool ValidateStencilParamsForDrawCall();
- bool ValidateCopyTexImage(TexInternalFormat srcFormat, TexInternalFormat dstformat,
- WebGLTexImageFunc func, WebGLTexDimensions dims);
- bool ValidateTexImage(TexImageTarget texImageTarget,
- GLint level, GLenum internalFormat,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint width, GLint height, GLint depth,
- GLint border, GLenum format, GLenum type,
- WebGLTexImageFunc func, WebGLTexDimensions dims);
- bool ValidateTexImageFormat(GLenum internalFormat, WebGLTexImageFunc func,
- WebGLTexDimensions dims);
- bool ValidateTexImageType(GLenum type, WebGLTexImageFunc func,
- WebGLTexDimensions dims);
- bool ValidateTexImageFormatAndType(GLenum format, GLenum type,
- WebGLTexImageFunc func,
- WebGLTexDimensions dims);
- bool ValidateCompTexImageInternalFormat(GLenum format,
- WebGLTexImageFunc func,
- WebGLTexDimensions dims);
- bool ValidateCopyTexImageInternalFormat(GLenum format,
- WebGLTexImageFunc func,
- WebGLTexDimensions dims);
- bool ValidateTexImageSize(TexImageTarget texImageTarget, GLint level,
- GLint width, GLint height, GLint depth,
- 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,
- WebGLTexDimensions dims);
- bool ValidateCompTexImageSize(GLint level, GLenum internalFormat,
- GLint xoffset, GLint yoffset, GLsizei width,
- GLsizei height, GLsizei levelWidth,
- GLsizei levelHeight, WebGLTexImageFunc func,
- WebGLTexDimensions dims);
- bool ValidateCompTexImageDataSize(GLint level, GLenum internalFormat,
- GLsizei width, GLsizei height,
- uint32_t byteLength,
- WebGLTexImageFunc func,
- WebGLTexDimensions dims);
- bool ValidateUniformLocationForProgram(WebGLUniformLocation* location,
- WebGLProgram* program,
- const char* funcName);
- bool ValidateCurFBForRead(const char* funcName,
- const webgl::FormatUsageInfo** const out_format,
- uint32_t* const out_width, uint32_t* const out_height);
- bool HasDrawBuffers() const {
- return IsWebGL2() ||
- IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers);
- }
- WebGLRefPtr<WebGLBuffer>* ValidateBufferSlot(const char* funcName, GLenum target);
- public:
- WebGLBuffer* ValidateBufferSelection(const char* funcName, GLenum target);
- protected:
- 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;
- }
- public:
- 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;
- }
- bool ValidateArrayBufferView(const char* funcName, const dom::ArrayBufferView& view,
- GLuint elemOffset, GLuint elemCountOverride,
- uint8_t** const out_bytes, size_t* const out_byteLen);
- protected:
- ////
- void Invalidate();
- void DestroyResourcesAndContext();
- void MakeContextCurrent() const;
- // helpers
- bool ConvertImage(size_t width, size_t height, size_t srcStride,
- size_t dstStride, const uint8_t* src, uint8_t* dst,
- WebGLTexelFormat srcFormat, bool srcPremultiplied,
- WebGLTexelFormat dstFormat, bool dstPremultiplied,
- size_t dstTexelSize);
- //////
- public:
- 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;
- }
- return true;
- }
- bool ValidateObject(const char* funcName, const WebGLDeletableObject& object,
- bool isShaderOrProgram = false)
- {
- if (!ValidateObjectAllowDeleted(funcName, object))
- return false;
- 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.",
- funcName);
- return false;
- }
- } else {
- if (object.IsDeleteRequested()) {
- ErrorInvalidOperation("%s: Object argument cannot have been marked for"
- " deletion.",
- funcName);
- return false;
- }
- }
- return true;
- }
- ////
- bool ValidateObject(const char* funcName, const WebGLProgram& object);
- bool ValidateObject(const char* funcName, const WebGLShader& object);
- ////
- 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;
- }
- ////
- private:
- // -------------------------------------------------------------------------
- // Context customization points
- virtual WebGLVertexArray* CreateVertexArrayImpl();
- virtual bool ValidateAttribPointerType(bool integerMode, GLenum type, uint32_t* alignment, const char* info) = 0;
- virtual bool ValidateUniformMatrixTranspose(bool transpose, const char* info) = 0;
- public:
- void ForceLoseContext(bool simulateLoss = false);
- protected:
- void ForceRestoreContext();
- nsTArray<WebGLRefPtr<WebGLTexture> > mBound2DTextures;
- nsTArray<WebGLRefPtr<WebGLTexture> > mBoundCubeMapTextures;
- nsTArray<WebGLRefPtr<WebGLTexture> > mBound3DTextures;
- nsTArray<WebGLRefPtr<WebGLTexture> > mBound2DArrayTextures;
- nsTArray<WebGLRefPtr<WebGLSampler> > mBoundSamplers;
- void ResolveTexturesForDraw() const;
- WebGLRefPtr<WebGLProgram> mCurrentProgram;
- RefPtr<const webgl::LinkedProgramInfo> mActiveProgramLinkInfo;
- bool ValidateFramebufferTarget(GLenum target, const char* const info);
- 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);
- WebGLRefPtr<WebGLFramebuffer> mBoundDrawFramebuffer;
- WebGLRefPtr<WebGLFramebuffer> mBoundReadFramebuffer;
- WebGLRefPtr<WebGLRenderbuffer> mBoundRenderbuffer;
- WebGLRefPtr<WebGLTransformFeedback> mBoundTransformFeedback;
- WebGLRefPtr<WebGLVertexArray> mBoundVertexArray;
- LinkedList<WebGLBuffer> mBuffers;
- LinkedList<WebGLFramebuffer> mFramebuffers;
- LinkedList<WebGLProgram> mPrograms;
- LinkedList<WebGLQuery> mQueries;
- LinkedList<WebGLRenderbuffer> mRenderbuffers;
- LinkedList<WebGLSampler> mSamplers;
- LinkedList<WebGLShader> mShaders;
- LinkedList<WebGLSync> mSyncs;
- LinkedList<WebGLTexture> mTextures;
- LinkedList<WebGLTransformFeedback> mTransformFeedbacks;
- LinkedList<WebGLVertexArray> mVertexArrays;
- WebGLRefPtr<WebGLTransformFeedback> mDefaultTransformFeedback;
- WebGLRefPtr<WebGLVertexArray> mDefaultVertexArray;
- // PixelStore parameters
- 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);
- bool ValidatePackSize(const char* funcName, uint32_t width, uint32_t height,
- uint8_t bytesPerPixel, uint32_t* const out_rowStride,
- uint32_t* const out_endOffset);
- GLenum mPixelStore_ColorspaceConversion;
- bool mPixelStore_FlipY;
- bool mPixelStore_PremultiplyAlpha;
- ////////////////////////////////////
- class FakeBlackTexture {
- public:
- static UniquePtr<FakeBlackTexture> Create(gl::GLContext* gl,
- TexTarget target,
- FakeBlackType type);
- gl::GLContext* const mGL;
- const GLuint mGLName;
- ~FakeBlackTexture();
- protected:
- explicit FakeBlackTexture(gl::GLContext* gl);
- };
- 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;
- bool BindFakeBlack(uint32_t texUnit, TexTarget target, FakeBlackType fakeBlack);
- ////////////////////////////////////
- protected:
- GLuint mEmptyTFO;
- // Generic Vertex Attributes
- // 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];
- GLuint mFakeVertexAttrib0BufferObject;
- size_t mFakeVertexAttrib0BufferObjectSize;
- bool mFakeVertexAttrib0DataDefined;
- uint8_t mFakeVertexAttrib0Data[sizeof(float) * 4];
- JSObject* GetVertexAttribFloat32Array(JSContext* cx, GLuint index);
- JSObject* GetVertexAttribInt32Array(JSContext* cx, GLuint index);
- JSObject* GetVertexAttribUint32Array(JSContext* cx, GLuint index);
- GLint mStencilRefFront;
- GLint mStencilRefBack;
- GLuint mStencilValueMaskFront;
- GLuint mStencilValueMaskBack;
- GLuint mStencilWriteMaskFront;
- GLuint mStencilWriteMaskBack;
- realGLboolean mColorWriteMask[4];
- realGLboolean mDepthWriteMask;
- GLfloat mColorClearValue[4];
- GLint mStencilClearValue;
- GLfloat mDepthClearValue;
- GLint mViewportX;
- GLint mViewportY;
- GLsizei mViewportWidth;
- GLsizei mViewportHeight;
- bool mAlreadyWarnedAboutViewportLargerThanDest;
- GLfloat mLineWidth;
- WebGLContextLossHandler mContextLossHandler;
- bool mAllowContextRestore;
- bool mLastLossWasSimulated;
- ContextStatus mContextStatus;
- bool mContextLostErrorSet;
- // Used for some hardware (particularly Tegra 2 and 4) that likes to
- // be Flushed while doing hundreds of draw calls.
- int mDrawCallsSinceLastFlush;
- int mAlreadyGeneratedWarnings;
- int mMaxWarnings;
- bool mAlreadyWarnedAboutFakeVertexAttrib0;
- bool ShouldGenerateWarnings() const;
- uint64_t mLastUseIndex;
- bool mNeedsFakeNoAlpha;
- bool mNeedsFakeNoDepth;
- bool mNeedsFakeNoStencil;
- bool mNeedsEmulatedLoneDepthStencil;
- const bool mAllowFBInvalidation;
- bool Has64BitTimestamps() const;
- struct ScopedDrawCallWrapper final {
- WebGLContext& mWebGL;
- const bool mFakeNoAlpha;
- const bool mFakeNoDepth;
- const bool mFakeNoStencil;
- static bool ShouldFakeNoAlpha(WebGLContext& webgl) {
- // We should only be doing this if we're about to draw to the backbuffer, but
- // the backbuffer needs to have this fake-no-alpha workaround.
- return !webgl.mBoundDrawFramebuffer &&
- webgl.mNeedsFakeNoAlpha &&
- webgl.mColorWriteMask[3] != false;
- }
- static bool ShouldFakeNoDepth(WebGLContext& webgl) {
- // We should only be doing this if we're about to draw to the backbuffer.
- return !webgl.mBoundDrawFramebuffer &&
- webgl.mNeedsFakeNoDepth &&
- webgl.mDepthTestEnabled;
- }
- static bool HasDepthButNoStencil(const WebGLFramebuffer* fb);
- static bool ShouldFakeNoStencil(WebGLContext& webgl) {
- if (!webgl.mStencilTestEnabled)
- return false;
- if (!webgl.mBoundDrawFramebuffer) {
- if (webgl.mNeedsFakeNoStencil)
- return true;
- if (webgl.mNeedsEmulatedLoneDepthStencil &&
- webgl.mOptions.depth && !webgl.mOptions.stencil)
- {
- return true;
- }
- return false;
- }
- if (webgl.mNeedsEmulatedLoneDepthStencil &&
- HasDepthButNoStencil(webgl.mBoundDrawFramebuffer))
- {
- return true;
- }
- return false;
- }
- ////
- explicit ScopedDrawCallWrapper(WebGLContext& webgl);
- ~ScopedDrawCallWrapper();
- };
- void OnBeforeReadCall();
- void LoseOldestWebGLContextIfLimitExceeded();
- void UpdateLastUseIndex();
- template <typename WebGLObjectType>
- JS::Value WebGLObjectAsJSValue(JSContext* cx, const WebGLObjectType*,
- ErrorResult& rv) const;
- template <typename WebGLObjectType>
- JSObject* WebGLObjectAsJSObject(JSContext* cx, const WebGLObjectType*,
- ErrorResult& rv) const;
- public:
- // console logging helpers
- void GenerateWarning(const char* fmt, ...);
- void GenerateWarning(const char* fmt, va_list ap);
- public:
- UniquePtr<webgl::FormatUsageAuthority> mFormatUsage;
- virtual UniquePtr<webgl::FormatUsageAuthority>
- CreateFormatUsage(gl::GLContext* gl) const = 0;
- const decltype(mBound2DTextures)* TexListForElemType(GLenum elemType) const;
- // Friend list
- friend class ScopedCopyTexImageSource;
- friend class ScopedResolveTexturesForDraw;
- friend class ScopedUnpackReset;
- friend class webgl::TexUnpackBlob;
- friend class webgl::TexUnpackBytes;
- friend class webgl::TexUnpackImage;
- friend class webgl::TexUnpackSurface;
- friend struct webgl::UniformInfo;
- friend class WebGLTexture;
- friend class WebGLFBAttachPoint;
- friend class WebGLFramebuffer;
- friend class WebGLRenderbuffer;
- friend class WebGLProgram;
- friend class WebGLQuery;
- friend class WebGLBuffer;
- friend class WebGLSampler;
- friend class WebGLShader;
- friend class WebGLSync;
- friend class WebGLTransformFeedback;
- friend class WebGLUniformLocation;
- friend class WebGLVertexArray;
- friend class WebGLVertexArrayFake;
- friend class WebGLVertexArrayGL;
- };
- // used by DOM bindings in conjunction with GetParentObject
- inline nsISupports*
- ToSupports(WebGLContext* webgl)
- {
- return static_cast<nsIDOMWebGLRenderingContext*>(webgl);
- }
- // 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;
- }
- bool
- ValidateTexTarget(WebGLContext* webgl, const char* funcName, uint8_t funcDims,
- GLenum rawTexTarget, TexTarget* const out_texTarget,
- WebGLTexture** const out_tex);
- bool
- ValidateTexImageTarget(WebGLContext* webgl, const char* funcName, uint8_t funcDims,
- GLenum rawTexImageTarget, TexImageTarget* const out_texImageTarget,
- WebGLTexture** const out_tex);
- class UniqueBuffer
- {
- // Like UniquePtr<>, but for void* and malloc/calloc/free.
- void* mBuffer;
- public:
- UniqueBuffer()
- : mBuffer(nullptr)
- { }
- MOZ_IMPLICIT UniqueBuffer(void* buffer)
- : mBuffer(buffer)
- { }
- ~UniqueBuffer() {
- free(mBuffer);
- }
- UniqueBuffer(UniqueBuffer&& other) {
- this->mBuffer = other.mBuffer;
- other.mBuffer = nullptr;
- }
- UniqueBuffer& operator =(UniqueBuffer&& other) {
- free(this->mBuffer);
- this->mBuffer = other.mBuffer;
- other.mBuffer = nullptr;
- return *this;
- }
- UniqueBuffer& operator =(void* newBuffer) {
- free(this->mBuffer);
- this->mBuffer = newBuffer;
- return *this;
- }
- explicit operator bool() const { return bool(mBuffer); }
- void* get() const { return mBuffer; }
- UniqueBuffer(const UniqueBuffer& other) = delete; // construct using Move()!
- void operator =(const UniqueBuffer& other) = delete; // assign using Move()!
- };
- class ScopedUnpackReset final
- : public gl::ScopedGLWrapper<ScopedUnpackReset>
- {
- friend struct gl::ScopedGLWrapper<ScopedUnpackReset>;
- private:
- WebGLContext* const mWebGL;
- public:
- explicit ScopedUnpackReset(WebGLContext* webgl);
- 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:
- void UnwrapImpl();
- };
- 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();
- };
- ////
- bool
- Intersect(int32_t srcSize, int32_t read0, int32_t readSize, int32_t* out_intRead0,
- int32_t* out_intWrite0, int32_t* out_intSize);
- ////
- void
- ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
- const std::vector<IndexedBufferBinding>& field,
- const char* name, uint32_t flags = 0);
- void
- ImplCycleCollectionUnlink(std::vector<IndexedBufferBinding>& field);
- } // namespace mozilla
- #endif
|