1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef WEBGLCONTEXT_H_
7 #define WEBGLCONTEXT_H_
12 #include "GLContextTypes.h"
14 #include "GLScreenBuffer.h"
15 #include "js/ScalarType.h" // js::Scalar::Type
16 #include "mozilla/Attributes.h"
17 #include "mozilla/CheckedInt.h"
18 #include "mozilla/dom/BindingDeclarations.h"
19 #include "mozilla/dom/HTMLCanvasElement.h"
20 #include "mozilla/dom/Nullable.h"
21 #include "mozilla/dom/TypedArray.h"
22 #include "mozilla/EnumeratedArray.h"
23 #include "mozilla/gfx/2D.h"
24 #include "mozilla/Mutex.h"
25 #include "mozilla/UniquePtr.h"
26 #include "mozilla/WeakPtr.h"
27 #include "nsICanvasRenderingContextInternal.h"
29 #include "SurfaceTypes.h"
30 #include "ScopedGLHelpers.h"
31 #include "TexUnpackBlob.h"
32 #include "mozilla/WeakPtr.h"
35 #include "CacheInvalidator.h"
36 #include "WebGLContextLossHandler.h"
37 #include "WebGLExtensions.h"
38 #include "WebGLObjectModel.h"
39 #include "WebGLStrongTypes.h"
40 #include "WebGLTypes.h"
43 #include "nsICanvasRenderingContextInternal.h"
44 #include "mozilla/dom/HTMLCanvasElement.h"
45 #include "mozilla/dom/WebGLRenderingContextBinding.h"
46 #include "mozilla/dom/WebGL2RenderingContextBinding.h"
54 #define LOCAL_GL_BROWSER_DEFAULT_WEBGL 0x9244
55 #define LOCAL_GL_CONTEXT_LOST_WEBGL 0x9242
56 #define LOCAL_GL_MAX_CLIENT_WAIT_TIMEOUT_WEBGL 0x9247
57 #define LOCAL_GL_UNPACK_COLORSPACE_CONVERSION_WEBGL 0x9243
58 #define LOCAL_GL_UNPACK_FLIP_Y_WEBGL 0x9240
59 #define LOCAL_GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL 0x9241
63 class HostWebGLContext
;
64 class ScopedCopyTexImageSource
;
65 class ScopedDrawCallWrapper
;
66 class ScopedResolveTexturesForDraw
;
68 class WebGLExtensionBase
;
69 class WebGLFramebuffer
;
72 class WebGLRenderbuffer
;
77 class WebGLTransformFeedback
;
78 class WebGLVertexArray
;
84 class OwningHTMLCanvasElementOrOffscreenCanvas
;
85 struct WebGLContextAttributes
;
100 class CompositableHost
;
101 class SurfaceDescriptor
;
102 } // namespace layers
105 class AvailabilityRunnable
;
106 struct CachedDrawFetchLimits
;
109 class FormatUsageAuthority
;
110 struct FormatUsageInfo
;
112 struct LinkedProgramInfo
;
113 struct SamplerUniformInfo
;
114 struct SamplingState
;
115 class ScopedPrepForResourceClear
;
116 class ShaderValidator
;
119 struct UniformBlockInfo
;
120 struct VertAttribPointerDesc
;
123 struct WebGLTexImageData
{
124 TexImageTarget mTarget
;
129 gfxAlphaType mSrcAlphaType
;
132 struct WebGLTexPboOffset
{
133 TexImageTarget mTarget
;
137 WebGLsizeiptr mPboOffset
;
138 bool mHasExpectedImageSize
;
139 GLsizei mExpectedImageSize
;
142 WebGLTexelFormat
GetWebGLTexelFormat(TexInternalFormat format
);
144 void AssertUintParamCorrect(gl::GLContext
* gl
, GLenum pname
, GLuint shadow
);
146 // From WebGLContextUtils
147 TexTarget
TexImageTargetToTexTarget(TexImageTarget texImageTarget
);
149 struct WebGLIntOrFloat
{
150 const enum { Int
, Float
, Uint
} mType
;
158 explicit WebGLIntOrFloat(GLint i
) : mType(Int
) { mValue
.i
= i
; }
159 explicit WebGLIntOrFloat(GLfloat f
) : mType(Float
) { mValue
.f
= f
; }
161 GLint
AsInt() const {
162 return (mType
== Int
) ? mValue
.i
: NS_lroundf(mValue
.f
);
164 GLfloat
AsFloat() const {
165 return (mType
== Float
) ? mValue
.f
: GLfloat(mValue
.i
);
169 struct IndexedBufferBinding
{
170 RefPtr
<WebGLBuffer
> mBufferBinding
;
171 uint64_t mRangeStart
;
174 IndexedBufferBinding();
176 uint64_t ByteCount() const;
179 ////////////////////////////////////
183 class AvailabilityRunnable final
: public Runnable
{
185 const WeakPtr
<const ClientWebGLContext
> mWebGL
;
186 std::vector
<WeakPtr
<WebGLQueryJS
>> mQueries
;
187 std::vector
<WeakPtr
<WebGLSyncJS
>> mSyncs
;
189 explicit AvailabilityRunnable(const ClientWebGLContext
* webgl
);
190 ~AvailabilityRunnable();
192 NS_IMETHOD
Run() override
;
195 struct BufferAndIndex final
{
196 const WebGLBuffer
* buffer
= nullptr;
202 ////////////////////////////////////////////////////////////////////////////////
204 class WebGLContext
: public VRefCounted
, public SupportsWeakPtr
{
205 friend class ScopedDrawCallWrapper
;
206 friend class ScopedDrawWithTransformFeedback
;
207 friend class ScopedFakeVertexAttrib0
;
208 friend class ScopedFBRebinder
;
209 friend class WebGL2Context
;
210 friend class WebGLContextUserData
;
211 friend class WebGLExtensionCompressedTextureASTC
;
212 friend class WebGLExtensionCompressedTextureBPTC
;
213 friend class WebGLExtensionCompressedTextureES3
;
214 friend class WebGLExtensionCompressedTextureETC1
;
215 friend class WebGLExtensionCompressedTexturePVRTC
;
216 friend class WebGLExtensionCompressedTextureRGTC
;
217 friend class WebGLExtensionCompressedTextureS3TC
;
218 friend class WebGLExtensionCompressedTextureS3TC_SRGB
;
219 friend class WebGLExtensionDepthTexture
;
220 friend class WebGLExtensionDisjointTimerQuery
;
221 friend class WebGLExtensionDrawBuffers
;
222 friend class WebGLExtensionLoseContext
;
223 friend class WebGLExtensionMOZDebug
;
224 friend class WebGLExtensionVertexArray
;
225 friend class WebGLMemoryTracker
;
226 friend class webgl::AvailabilityRunnable
;
227 friend struct webgl::LinkedProgramInfo
;
228 friend struct webgl::SamplerUniformInfo
;
229 friend class webgl::ScopedPrepForResourceClear
;
230 friend struct webgl::UniformBlockInfo
;
232 friend const webgl::CachedDrawFetchLimits
* ValidateDraw(WebGLContext
*, GLenum
,
234 friend RefPtr
<const webgl::LinkedProgramInfo
> QueryProgramInfo(
235 WebGLProgram
* prog
, gl::GLContext
* gl
);
237 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(WebGLContext
, override
)
240 UNPACK_FLIP_Y_WEBGL
= 0x9240,
241 UNPACK_PREMULTIPLY_ALPHA_WEBGL
= 0x9241,
242 // We throw InvalidOperation in TexImage if we fail to use GPU fast-path
243 // for texture copy when it is set to true, only for debug purpose.
244 UNPACK_REQUIRE_FASTPATH
= 0x10001,
245 CONTEXT_LOST_WEBGL
= 0x9242,
246 UNPACK_COLORSPACE_CONVERSION_WEBGL
= 0x9243,
247 BROWSER_DEFAULT_WEBGL
= 0x9244,
248 UNMASKED_VENDOR_WEBGL
= 0x9245,
249 UNMASKED_RENDERER_WEBGL
= 0x9246
253 class LruPosition final
{
254 std::list
<WebGLContext
*>::iterator mItr
;
260 explicit LruPosition(WebGLContext
&);
262 LruPosition
& operator=(LruPosition
&& rhs
) {
264 std::swap(mItr
, rhs
.mItr
);
269 ~LruPosition() { reset(); }
272 mutable LruPosition mLruPosition
;
276 LruPosition next
{*this};
277 mLruPosition
= std::move(next
);
280 void LoseLruContextIfLimitExceeded();
284 // We've had issues in the past with nulling `gl` without actually releasing
285 // all of our resources. This construction ensures that we are aware that we
286 // should only null `gl` in DestroyResourcesAndContext.
287 RefPtr
<gl::GLContext
> mGL_OnlyClearInDestroyResourcesAndContext
;
290 // Grab a const reference so we can see changes, but can't make changes.
291 const decltype(mGL_OnlyClearInDestroyResourcesAndContext
)& gl
;
294 void CheckForInactivity();
297 const WeakPtr
<HostWebGLContext
> mHost
;
298 const bool mResistFingerprinting
;
299 WebGLContextOptions mOptions
;
300 const uint32_t mPrincipalKey
;
301 Maybe
<webgl::Limits
> mLimits
;
303 bool mIsContextLost
= false;
304 const uint32_t mMaxPerfWarnings
;
305 mutable uint64_t mNumPerfWarnings
= 0;
306 const uint32_t mMaxAcceptableFBStatusInvals
;
308 uint64_t mNextFenceId
= 1;
309 uint64_t mCompletedFenceId
= 0;
311 std::unique_ptr
<gl::Texture
> mIncompleteTexOverride
;
317 mutable FuncScope
* mFuncScope
= nullptr;
320 static RefPtr
<WebGLContext
> Create(HostWebGLContext
&,
321 const webgl::InitContextDesc
&,
322 webgl::InitContextResult
* out
);
328 WebGLContext(HostWebGLContext
&, const webgl::InitContextDesc
&);
329 virtual ~WebGLContext();
331 RefPtr
<layers::CompositableHost
> mCompositableHost
;
333 layers::LayersBackend mBackend
= layers::LayersBackend::LAYERS_NONE
;
336 void Resize(uvec2 size
);
338 void SetCompositableHost(RefPtr
<layers::CompositableHost
>& aCompositableHost
);
341 * An abstract base class to be implemented by callers wanting to be notified
342 * that a refresh has occurred. Callers must ensure an observer is removed
343 * before it is destroyed.
345 virtual void DidRefresh();
347 void OnMemoryPressure();
353 Here are the bind calls that are supposed to be fully-validated client side,
354 so that client's binding state doesn't diverge:
364 * BindTransformFeedback
372 const auto& CurFuncScope() const { return *mFuncScope
; }
373 const char* FuncName() const;
375 class FuncScope final
{
377 const WebGLContext
& mWebGL
;
378 const char* const mFuncName
;
379 bool mBindFailureGuard
= false;
382 FuncScope(const WebGLContext
& webgl
, const char* funcName
);
386 void GenerateErrorImpl(const GLenum err
, const nsACString
& text
) const {
387 GenerateErrorImpl(err
, std::string(text
.BeginReading()));
389 void GenerateErrorImpl(const GLenum err
, const std::string
& text
) const;
391 void GenerateError(const webgl::ErrorInfo
& err
) {
392 GenerateError(err
.type
, "%s", err
.info
.c_str());
395 template <typename
... Args
>
396 void GenerateError(const GLenum err
, const char* const fmt
,
397 const Args
&... args
) const {
398 MOZ_ASSERT(FuncName());
401 text
.AppendPrintf("WebGL warning: %s: ", FuncName());
404 # pragma clang diagnostic push
405 # pragma clang diagnostic ignored "-Wformat-security"
406 #elif defined(__GNUC__)
407 # pragma GCC diagnostic push
408 # pragma GCC diagnostic ignored "-Wformat-security"
410 text
.AppendPrintf(fmt
, args
...);
412 # pragma clang diagnostic pop
413 #elif defined(__GNUC__)
414 # pragma GCC diagnostic pop
417 GenerateErrorImpl(err
, text
);
420 template <typename
... Args
>
421 void ErrorInvalidEnum(const char* const fmt
, const Args
&... args
) const {
422 GenerateError(LOCAL_GL_INVALID_ENUM
, fmt
, args
...);
424 template <typename
... Args
>
425 void ErrorInvalidOperation(const char* const fmt
, const Args
&... args
) const {
426 GenerateError(LOCAL_GL_INVALID_OPERATION
, fmt
, args
...);
428 template <typename
... Args
>
429 void ErrorInvalidValue(const char* const fmt
, const Args
&... args
) const {
430 GenerateError(LOCAL_GL_INVALID_VALUE
, fmt
, args
...);
432 template <typename
... Args
>
433 void ErrorInvalidFramebufferOperation(const char* const fmt
,
434 const Args
&... args
) const {
435 GenerateError(LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION
, fmt
, args
...);
437 template <typename
... Args
>
438 void ErrorOutOfMemory(const char* const fmt
, const Args
&... args
) const {
439 GenerateError(LOCAL_GL_OUT_OF_MEMORY
, fmt
, args
...);
442 template <typename
... Args
>
443 void ErrorImplementationBug(const char* const fmt
,
444 const Args
&... args
) const {
445 const nsPrintfCString
newFmt(
446 "Implementation bug, please file at %s! %s",
447 "https://bugzilla.mozilla.org/"
448 "enter_bug.cgi?product=Core&component=Canvas%3A+WebGL",
450 GenerateError(LOCAL_GL_OUT_OF_MEMORY
, newFmt
.BeginReading(), args
...);
451 MOZ_ASSERT(false, "WebGLContext::ErrorImplementationBug");
452 NS_ERROR("WebGLContext::ErrorImplementationBug");
455 void ErrorInvalidEnumInfo(const char* info
, GLenum enumValue
) const;
456 void ErrorInvalidEnumArg(const char* argName
, GLenum val
) const;
458 static const char* ErrorName(GLenum error
);
461 * Return displayable name for GLenum.
462 * This version is like gl::GLenumToStr but with out the GL_ prefix to
463 * keep consistency with how errors are reported from WebGL.
464 * Returns hex formatted version of glenum if glenum is unknown.
466 static void EnumName(GLenum val
, nsCString
* out_name
);
468 void DummyReadFramebufferOperation();
470 WebGLTexture
* GetActiveTex(const GLenum texTarget
) const;
472 already_AddRefed
<layers::Layer
> GetCanvasLayer(nsDisplayListBuilder
* builder
,
473 layers::Layer
* oldLayer
,
474 layers::LayerManager
* manager
);
476 Maybe
<ICRData
> InitializeCanvasRenderer(layers::LayersBackend backend
);
478 gl::GLContext
* GL() const { return gl
; }
480 bool IsPremultAlpha() const { return mOptions
.premultipliedAlpha
; }
482 bool IsPreservingDrawingBuffer() const {
483 return mOptions
.preserveDrawingBuffer
;
486 // Present to compositor
488 bool PresentInto(gl::SwapChain
& swapChain
);
489 bool PresentIntoXR(gl::SwapChain
& swapChain
, const gl::MozFramebuffer
& xrFb
);
492 void Present(WebGLFramebuffer
*, layers::TextureType
, const bool webvr
);
493 RefPtr
<gfx::DataSourceSurface
> GetFrontBufferSnapshot();
494 bool FrontBufferSnapshotInto(Range
<uint8_t>);
495 Maybe
<layers::SurfaceDescriptor
> GetFrontBuffer(WebGLFramebuffer
*,
498 void ClearVRSwapChain();
500 void RunContextLossTimer();
501 void CheckForContextLoss();
503 bool TryToRestoreContext();
505 void AssertCachedBindings() const;
506 void AssertCachedGlobalState() const;
508 // WebIDL WebGLRenderingContext API
511 uvec2
DrawingBufferSize();
514 void GetContextAttributes(dom::Nullable
<dom::WebGLContextAttributes
>& retval
);
516 // This is the entrypoint. Don't test against it directly.
517 bool IsContextLost() const { return mIsContextLost
; }
521 RefPtr
<WebGLBuffer
> CreateBuffer();
522 RefPtr
<WebGLFramebuffer
> CreateFramebuffer();
523 RefPtr
<WebGLFramebuffer
> CreateOpaqueFramebuffer(
524 const webgl::OpaqueFramebufferOptions
& options
);
525 RefPtr
<WebGLProgram
> CreateProgram();
526 RefPtr
<WebGLQuery
> CreateQuery();
527 RefPtr
<WebGLRenderbuffer
> CreateRenderbuffer();
528 RefPtr
<WebGLShader
> CreateShader(GLenum type
);
529 RefPtr
<WebGLTexture
> CreateTexture();
530 RefPtr
<WebGLVertexArray
> CreateVertexArray();
534 void AttachShader(WebGLProgram
& prog
, WebGLShader
& shader
);
535 void BindAttribLocation(WebGLProgram
& prog
, GLuint location
,
536 const std::string
& name
) const;
537 void BindFramebuffer(GLenum target
, WebGLFramebuffer
* fb
);
538 void BindRenderbuffer(GLenum target
, WebGLRenderbuffer
* fb
);
539 void BindVertexArray(WebGLVertexArray
* vao
);
540 void BlendColor(GLclampf r
, GLclampf g
, GLclampf b
, GLclampf a
);
541 void BlendEquationSeparate(GLenum modeRGB
, GLenum modeAlpha
);
542 void BlendFuncSeparate(GLenum srcRGB
, GLenum dstRGB
, GLenum srcAlpha
,
544 GLenum
CheckFramebufferStatus(GLenum target
);
545 void Clear(GLbitfield mask
);
546 void ClearColor(GLclampf r
, GLclampf g
, GLclampf b
, GLclampf a
);
547 void ClearDepth(GLclampf v
);
548 void ClearStencil(GLint v
);
549 void ColorMask(WebGLboolean r
, WebGLboolean g
, WebGLboolean b
,
551 void CompileShader(WebGLShader
& shader
);
554 void CompileShaderANGLE(WebGLShader
* shader
);
555 void CompileShaderBypass(WebGLShader
* shader
, const nsCString
& shaderSource
);
558 void CullFace(GLenum face
);
559 void DepthFunc(GLenum func
);
560 void DepthMask(WebGLboolean b
);
561 void DepthRange(GLclampf zNear
, GLclampf zFar
);
562 void DetachShader(WebGLProgram
& prog
, const WebGLShader
& shader
);
563 void DrawBuffers(const std::vector
<GLenum
>& buffers
);
567 void FramebufferAttach(GLenum target
, GLenum attachSlot
,
568 GLenum bindImageTarget
,
569 const webgl::FbAttachInfo
& toAttach
);
571 void FrontFace(GLenum mode
);
573 Maybe
<double> GetBufferParameter(GLenum target
, GLenum pname
);
574 webgl::CompileResult
GetCompileResult(const WebGLShader
&) const;
576 GLint
GetFragDataLocation(const WebGLProgram
&, const std::string
& name
) const;
578 Maybe
<double> GetFramebufferAttachmentParameter(WebGLFramebuffer
*,
582 Maybe
<double> GetRenderbufferParameter(const WebGLRenderbuffer
&,
584 webgl::LinkResult
GetLinkResult(const WebGLProgram
&) const;
586 Maybe
<webgl::ShaderPrecisionFormat
> GetShaderPrecisionFormat(
587 GLenum shadertype
, GLenum precisiontype
) const;
589 webgl::GetUniformData
GetUniform(const WebGLProgram
&, uint32_t loc
) const;
591 void Hint(GLenum target
, GLenum mode
);
593 void LineWidth(GLfloat width
);
594 void LinkProgram(WebGLProgram
& prog
);
595 void PolygonOffset(GLfloat factor
, GLfloat units
);
599 webgl::PackingInfo
ValidImplementationColorReadPI(
600 const webgl::FormatUsageInfo
* usage
) const;
603 webgl::ReadPixelsResult
ReadPixelsImpl(const webgl::ReadPixelsDesc
&,
604 uintptr_t dest
, uint64_t availBytes
);
605 bool DoReadPixelsAndConvert(const webgl::FormatInfo
* srcFormat
,
606 const webgl::ReadPixelsDesc
&, uintptr_t dest
,
607 uint64_t dataLen
, uint32_t rowStride
);
610 void ReadPixelsPbo(const webgl::ReadPixelsDesc
&, uint64_t offset
);
611 webgl::ReadPixelsResult
ReadPixelsInto(const webgl::ReadPixelsDesc
&,
612 const Range
<uint8_t>& dest
);
616 void RenderbufferStorageMultisample(WebGLRenderbuffer
&, uint32_t samples
,
617 GLenum internalformat
, uint32_t width
,
618 uint32_t height
) const;
621 void SampleCoverage(GLclampf value
, WebGLboolean invert
);
622 void Scissor(GLint x
, GLint y
, GLsizei width
, GLsizei height
);
623 void ShaderSource(WebGLShader
& shader
, const std::string
& source
) const;
624 void StencilFuncSeparate(GLenum face
, GLenum func
, GLint ref
, GLuint mask
);
625 void StencilMaskSeparate(GLenum face
, GLuint mask
);
626 void StencilOpSeparate(GLenum face
, GLenum sfail
, GLenum dpfail
,
629 //////////////////////////
631 void UniformData(uint32_t loc
, bool transpose
,
632 const Range
<const uint8_t>& data
) const;
634 ////////////////////////////////////
636 void UseProgram(WebGLProgram
* prog
);
638 bool ValidateAttribArraySetter(uint32_t count
, uint32_t arrayLength
);
639 bool ValidateProgram(const WebGLProgram
& prog
) const;
640 void Viewport(GLint x
, GLint y
, GLsizei width
, GLsizei height
);
642 // -----------------------------------------------------------------------------
643 // Buffer Objects (WebGLContextBuffers.cpp)
644 void BindBuffer(GLenum target
, WebGLBuffer
* buffer
);
645 void BindBufferRange(GLenum target
, GLuint index
, WebGLBuffer
* buf
,
646 uint64_t offset
, uint64_t size
);
648 void BufferData(GLenum target
, uint64_t dataLen
, const uint8_t* data
,
650 void BufferSubData(GLenum target
, uint64_t dstByteOffset
, uint64_t srcDataLen
,
651 const uint8_t* srcData
) const;
654 // bound buffer state
655 RefPtr
<WebGLBuffer
> mBoundArrayBuffer
;
656 RefPtr
<WebGLBuffer
> mBoundCopyReadBuffer
;
657 RefPtr
<WebGLBuffer
> mBoundCopyWriteBuffer
;
658 RefPtr
<WebGLBuffer
> mBoundPixelPackBuffer
;
659 RefPtr
<WebGLBuffer
> mBoundPixelUnpackBuffer
;
660 RefPtr
<WebGLBuffer
> mBoundTransformFeedbackBuffer
;
661 RefPtr
<WebGLBuffer
> mBoundUniformBuffer
;
663 std::vector
<IndexedBufferBinding
> mIndexedUniformBufferBindings
;
665 RefPtr
<WebGLBuffer
>& GetBufferSlotByTarget(GLenum target
);
666 RefPtr
<WebGLBuffer
>& GetBufferSlotByTargetIndexed(GLenum target
,
671 void GenErrorIllegalUse(GLenum useTarget
, uint32_t useId
, GLenum boundTarget
,
672 uint32_t boundId
) const;
674 bool ValidateBufferForNonTf(const WebGLBuffer
&, GLenum nonTfTarget
,
675 uint32_t nonTfId
) const;
677 bool ValidateBufferForNonTf(const WebGLBuffer
* const nonTfBuffer
,
678 const GLenum nonTfTarget
,
679 const uint32_t nonTfId
= -1) const {
680 if (!nonTfBuffer
) return true;
681 return ValidateBufferForNonTf(*nonTfBuffer
, nonTfTarget
, nonTfId
);
684 bool ValidateBuffersForTf(const WebGLTransformFeedback
&,
685 const webgl::LinkedProgramInfo
&) const;
686 bool ValidateBuffersForTf(
687 const std::vector
<webgl::BufferAndIndex
>& tfBuffers
) const;
689 // -----------------------------------------------------------------------------
690 // Queries (WebGL2ContextQueries.cpp)
692 RefPtr
<WebGLQuery
> mQuerySlot_SamplesPassed
;
693 RefPtr
<WebGLQuery
> mQuerySlot_TFPrimsWritten
;
694 RefPtr
<WebGLQuery
> mQuerySlot_TimeElapsed
;
696 RefPtr
<WebGLQuery
>* ValidateQuerySlotByTarget(GLenum target
);
699 void BeginQuery(GLenum target
, WebGLQuery
& query
);
700 void EndQuery(GLenum target
);
701 Maybe
<double> GetQueryParameter(const WebGLQuery
& query
, GLenum pname
) const;
702 void QueryCounter(WebGLQuery
&) const;
704 // -----------------------------------------------------------------------------
705 // State and State Requests (WebGLContextState.cpp)
707 void SetEnabled(const char* funcName
, GLenum cap
, bool enabled
);
710 void Disable(GLenum cap
) { SetEnabled("disabled", cap
, false); }
711 void Enable(GLenum cap
) { SetEnabled("enabled", cap
, true); }
712 bool GetStencilBits(GLint
* const out_stencilBits
) const;
714 virtual Maybe
<double> GetParameter(GLenum pname
);
715 Maybe
<std::string
> GetString(GLenum pname
) const;
717 bool IsEnabled(GLenum cap
);
720 // State tracking slots
721 realGLboolean mDitherEnabled
= 1;
722 realGLboolean mRasterizerDiscardEnabled
= 0;
723 realGLboolean mScissorTestEnabled
= 0;
724 realGLboolean mDepthTestEnabled
= 0;
725 realGLboolean mStencilTestEnabled
= 0;
726 realGLboolean mBlendEnabled
= 0;
727 GLenum mGenerateMipmapHint
= 0;
729 struct ScissorRect final
{
735 void Apply(gl::GLContext
&) const;
737 ScissorRect mScissorRect
= {};
739 bool ValidateCapabilityEnum(GLenum cap
);
740 realGLboolean
* GetStateTrackingSlot(GLenum cap
);
742 // Allocation debugging variables
743 mutable uint64_t mDataAllocGLCallCount
= 0;
745 void OnDataAllocCall() const { mDataAllocGLCallCount
++; }
747 uint64_t GetNumGLDataAllocCalls() const { return mDataAllocGLCallCount
; }
751 // -----------------------------------------------------------------------------
752 // Texture funcions (WebGLContextTextures.cpp)
754 void ActiveTexture(uint32_t texUnit
);
755 void BindTexture(GLenum texTarget
, WebGLTexture
* tex
);
756 void GenerateMipmap(GLenum texTarget
);
758 Maybe
<double> GetTexParameter(const WebGLTexture
&, GLenum pname
) const;
759 void TexParameter_base(GLenum texTarget
, GLenum pname
,
760 const FloatOrInt
& param
);
762 virtual bool IsTexParamValid(GLenum pname
) const;
764 ////////////////////////////////////
767 // CompressedTexSubImage if `sub`
768 void CompressedTexImage(bool sub
, GLenum imageTarget
, uint32_t level
,
769 GLenum format
, uvec3 offset
, uvec3 size
,
770 const Range
<const uint8_t>& src
,
771 const uint32_t pboImageSize
,
772 const Maybe
<uint64_t>& pboOffset
) const;
774 // CopyTexSubImage if `!respectFormat`
775 void CopyTexImage(GLenum imageTarget
, uint32_t level
, GLenum respecFormat
,
776 uvec3 dstOffset
, const ivec2
& srcOffset
,
777 const uvec2
& size
) const;
779 // TexSubImage if `!respectFormat`
780 void TexImage(uint32_t level
, GLenum respecFormat
, uvec3 offset
,
781 const webgl::PackingInfo
& pi
,
782 const webgl::TexUnpackBlobDesc
&) const;
784 void TexStorage(GLenum texTarget
, uint32_t levels
, GLenum sizedFormat
,
787 UniquePtr
<webgl::TexUnpackBlob
> ToTexUnpackBytes(
788 const WebGLTexImageData
& imageData
);
790 UniquePtr
<webgl::TexUnpackBytes
> ToTexUnpackBytes(WebGLTexPboOffset
& aPbo
);
792 ////////////////////////////////////
793 // WebGLTextureUpload.cpp
795 bool ValidateTexImageSpecification(uint8_t funcDims
, GLenum texImageTarget
,
796 GLint level
, GLsizei width
, GLsizei height
,
797 GLsizei depth
, GLint border
,
798 TexImageTarget
* const out_target
,
799 WebGLTexture
** const out_texture
,
800 webgl::ImageInfo
** const out_imageInfo
);
801 bool ValidateTexImageSelection(uint8_t funcDims
, GLenum texImageTarget
,
802 GLint level
, GLint xOffset
, GLint yOffset
,
803 GLint zOffset
, GLsizei width
, GLsizei height
,
805 TexImageTarget
* const out_target
,
806 WebGLTexture
** const out_texture
,
807 webgl::ImageInfo
** const out_imageInfo
);
808 bool ValidateUnpackInfo(bool usePBOs
, GLenum format
, GLenum type
,
809 webgl::PackingInfo
* const out
);
811 // -----------------------------------------------------------------------------
812 // Vertices Feature (WebGLContextVertices.cpp)
813 GLenum mPrimRestartTypeBytes
= 0;
816 void DrawArraysInstanced(GLenum mode
, GLint first
, GLsizei vertexCount
,
817 GLsizei instanceCount
);
818 void DrawElementsInstanced(GLenum mode
, GLsizei vertexCount
, GLenum type
,
819 WebGLintptr byteOffset
, GLsizei instanceCount
);
821 void EnableVertexAttribArray(GLuint index
);
822 void DisableVertexAttribArray(GLuint index
);
824 Maybe
<double> GetVertexAttrib(GLuint index
, GLenum pname
);
828 void VertexAttrib4T(GLuint index
, const webgl::TypedQuad
&);
832 void VertexAttribPointer(uint32_t index
, const webgl::VertAttribPointerDesc
&);
834 void VertexAttribDivisor(GLuint index
, GLuint divisor
);
837 WebGLBuffer
* DrawElements_check(GLsizei indexCount
, GLenum type
,
838 WebGLintptr byteOffset
,
839 GLsizei instanceCount
);
842 void VertexAttrib1fv_base(GLuint index
, uint32_t arrayLength
,
844 void VertexAttrib2fv_base(GLuint index
, uint32_t arrayLength
,
846 void VertexAttrib3fv_base(GLuint index
, uint32_t arrayLength
,
848 void VertexAttrib4fv_base(GLuint index
, uint32_t arrayLength
,
851 bool BindArrayAttribToLocation0(WebGLProgram
* prog
);
853 // -----------------------------------------------------------------------------
856 WebGLVertexAttrib0Status
WhatDoesVertexAttrib0Need() const;
857 bool DoFakeVertexAttrib0(uint64_t vertexCount
);
858 void UndoFakeVertexAttrib0();
860 bool mResetLayer
= true;
861 bool mOptionsFrozen
= false;
862 bool mIsMesa
= false;
863 bool mLoseContextOnMemoryPressure
= false;
864 bool mCanLoseContextInForeground
= true;
865 bool mShouldPresent
= false;
866 bool mDisableFragHighP
= false;
867 bool mForceResizeOnPresent
= false;
868 bool mVRReady
= false;
870 template <typename WebGLObjectType
>
871 void DeleteWebGLObjectsArray(nsTArray
<WebGLObjectType
>& array
);
873 GLuint mActiveTexture
= 0;
874 GLenum mDefaultFB_DrawBuffer0
= 0;
875 GLenum mDefaultFB_ReadBuffer
= 0;
877 mutable GLenum mWebGLError
= 0;
879 std::unique_ptr
<webgl::ShaderValidator
> CreateShaderValidator(
880 GLenum shaderType
) const;
883 uint32_t mGLMaxFragmentUniformVectors
= 0;
884 uint32_t mGLMaxVertexUniformVectors
= 0;
885 uint32_t mGLMaxVertexOutputVectors
= 0;
886 uint32_t mGLMaxFragmentInputVectors
= 0;
888 uint32_t mGLMaxVertexTextureImageUnits
= 0;
889 uint32_t mGLMaxFragmentTextureImageUnits
= 0;
890 uint32_t mGLMaxCombinedTextureImageUnits
= 0;
893 uint32_t mGLMinProgramTexelOffset
= 0;
894 uint32_t mGLMaxProgramTexelOffset
= 0;
897 auto GLMaxDrawBuffers() const { return mLimits
->maxColorDrawBuffers
; }
899 uint32_t MaxValidDrawBuffers() const {
901 IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers
)) {
902 return GLMaxDrawBuffers();
907 GLenum
LastColorAttachmentEnum() const {
908 return LOCAL_GL_COLOR_ATTACHMENT0
+ MaxValidDrawBuffers() - 1;
911 const auto& Options() const { return mOptions
; }
914 uint32_t mGLMaxRenderbufferSize
= 0;
917 const auto& Limits() const { return *mLimits
; }
918 auto MaxVertexAttribs() const { return mLimits
->maxVertexAttribs
; }
919 auto GLMaxTextureUnits() const { return mLimits
->maxTexUnits
; }
921 bool IsFormatValidForFB(TexInternalFormat format
) const;
924 // -------------------------------------------------------------------------
925 // WebGL extensions (implemented in WebGLContextExtensions.cpp)
927 EnumeratedArray
<WebGLExtensionID
, WebGLExtensionID::Max
,
928 std::unique_ptr
<WebGLExtensionBase
>>
932 void RequestExtension(WebGLExtensionID
, bool explicitly
= true);
934 // returns true if the extension has been enabled by calling getExtension.
935 bool IsExtensionEnabled(const WebGLExtensionID id
) const {
936 return bool(mExtensions
[id
]);
939 bool IsExtensionExplicit(WebGLExtensionID
) const;
940 void WarnIfImplicit(WebGLExtensionID
) const;
942 bool IsExtensionSupported(WebGLExtensionID
) const;
944 // -------------------------------------------------------------------------
945 // WebGL 2 specifics (implemented in WebGL2Context.cpp)
947 virtual bool IsWebGL2() const { return false; }
949 struct FailureReason
{
950 nsCString key
; // For reporting.
953 FailureReason() = default;
955 template <typename A
, typename B
>
956 FailureReason(const A
& _key
, const B
& _info
)
957 : key(nsCString(_key
)), info(nsCString(_info
)) {}
961 bool InitWebGL2(FailureReason
* const out_failReason
);
963 bool CreateAndInitGL(bool forceEnabled
,
964 std::vector
<FailureReason
>* const out_failReasons
);
966 // -------------------------------------------------------------------------
967 // Validation functions (implemented in WebGLContextValidate.cpp)
968 bool InitAndValidateGL(FailureReason
* const out_failReason
);
970 bool ValidateBlendEquationEnum(GLenum cap
, const char* info
);
971 bool ValidateBlendFuncEnumsCompatibility(GLenum sfactor
, GLenum dfactor
,
973 bool ValidateStencilOpEnum(GLenum action
, const char* info
);
974 bool ValidateFaceEnum(GLenum face
);
975 bool ValidateTexInputData(GLenum type
, js::Scalar::Type jsArrayType
,
976 WebGLTexImageFunc func
, WebGLTexDimensions dims
);
977 bool ValidateAttribPointer(bool integerMode
, GLuint index
, GLint size
,
978 GLenum type
, WebGLboolean normalized
,
979 GLsizei stride
, WebGLintptr byteOffset
,
981 bool ValidateStencilParamsForDrawCall() const;
983 bool ValidateCopyTexImage(TexInternalFormat srcFormat
,
984 TexInternalFormat dstformat
, WebGLTexImageFunc func
,
985 WebGLTexDimensions dims
);
987 bool ValidateTexImage(TexImageTarget texImageTarget
, GLint level
,
988 GLenum internalFormat
, GLint xoffset
, GLint yoffset
,
989 GLint zoffset
, GLint width
, GLint height
, GLint depth
,
990 GLint border
, GLenum format
, GLenum type
,
991 WebGLTexImageFunc func
, WebGLTexDimensions dims
);
992 bool ValidateTexImageFormat(GLenum internalFormat
, WebGLTexImageFunc func
,
993 WebGLTexDimensions dims
);
994 bool ValidateTexImageType(GLenum type
, WebGLTexImageFunc func
,
995 WebGLTexDimensions dims
);
996 bool ValidateTexImageFormatAndType(GLenum format
, GLenum type
,
997 WebGLTexImageFunc func
,
998 WebGLTexDimensions dims
);
999 bool ValidateCompTexImageInternalFormat(GLenum format
, WebGLTexImageFunc func
,
1000 WebGLTexDimensions dims
);
1001 bool ValidateCopyTexImageInternalFormat(GLenum format
, WebGLTexImageFunc func
,
1002 WebGLTexDimensions dims
);
1003 bool ValidateTexImageSize(TexImageTarget texImageTarget
, GLint level
,
1004 GLint width
, GLint height
, GLint depth
,
1005 WebGLTexImageFunc func
, WebGLTexDimensions dims
);
1006 bool ValidateTexSubImageSize(GLint x
, GLint y
, GLint z
, GLsizei width
,
1007 GLsizei height
, GLsizei depth
, GLsizei baseWidth
,
1008 GLsizei baseHeight
, GLsizei baseDepth
,
1009 WebGLTexImageFunc func
, WebGLTexDimensions dims
);
1010 bool ValidateCompTexImageSize(GLint level
, GLenum internalFormat
,
1011 GLint xoffset
, GLint yoffset
, GLsizei width
,
1012 GLsizei height
, GLsizei levelWidth
,
1013 GLsizei levelHeight
, WebGLTexImageFunc func
,
1014 WebGLTexDimensions dims
);
1015 bool ValidateCompTexImageDataSize(GLint level
, GLenum internalFormat
,
1016 GLsizei width
, GLsizei height
,
1017 uint32_t byteLength
, WebGLTexImageFunc func
,
1018 WebGLTexDimensions dims
);
1020 bool HasDrawBuffers() const {
1021 return IsWebGL2() ||
1022 IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers
);
1025 RefPtr
<WebGLBuffer
>* ValidateBufferSlot(GLenum target
);
1028 WebGLBuffer
* ValidateBufferSelection(GLenum target
) const;
1031 IndexedBufferBinding
* ValidateIndexedBufferSlot(GLenum target
, GLuint index
);
1033 bool ValidateIndexedBufferBinding(
1034 GLenum target
, GLuint index
,
1035 RefPtr
<WebGLBuffer
>** const out_genericBinding
,
1036 IndexedBufferBinding
** const out_indexedBinding
);
1039 bool ValidateNonNegative(const char* argName
, int64_t val
) const {
1040 if (MOZ_UNLIKELY(val
< 0)) {
1041 ErrorInvalidValue("`%s` must be non-negative.", argName
);
1047 template <typename T
>
1048 bool ValidateNonNull(const char* const argName
,
1049 const dom::Nullable
<T
>& maybe
) const {
1050 if (maybe
.IsNull()) {
1051 ErrorInvalidValue("%s: Cannot be null.", argName
);
1060 void DestroyResourcesAndContext();
1064 bool ConvertImage(size_t width
, size_t height
, size_t srcStride
,
1065 size_t dstStride
, const uint8_t* src
, uint8_t* dst
,
1066 WebGLTexelFormat srcFormat
, bool srcPremultiplied
,
1067 WebGLTexelFormat dstFormat
, bool dstPremultiplied
,
1068 size_t dstTexelSize
);
1072 template <typename T
>
1073 bool ValidateObject(const char* const argName
, const T
& object
) const {
1074 // Todo: Remove all callers.
1078 template <typename T
>
1079 bool ValidateObject(const char* const argName
, const T
* const object
) const {
1080 // Todo: Remove most (all?) callers.
1082 ErrorInvalidOperation(
1083 "%s: Object argument cannot have been marked for"
1095 webgl::ContextLossReason reason
= webgl::ContextLossReason::None
);
1098 nsTArray
<RefPtr
<WebGLTexture
>> mBound2DTextures
;
1099 nsTArray
<RefPtr
<WebGLTexture
>> mBoundCubeMapTextures
;
1100 nsTArray
<RefPtr
<WebGLTexture
>> mBound3DTextures
;
1101 nsTArray
<RefPtr
<WebGLTexture
>> mBound2DArrayTextures
;
1102 nsTArray
<RefPtr
<WebGLSampler
>> mBoundSamplers
;
1104 void ResolveTexturesForDraw() const;
1106 RefPtr
<WebGLProgram
> mCurrentProgram
;
1107 RefPtr
<const webgl::LinkedProgramInfo
> mActiveProgramLinkInfo
;
1109 bool ValidateFramebufferTarget(GLenum target
) const;
1110 bool ValidateInvalidateFramebuffer(GLenum target
,
1111 const Range
<const GLenum
>& attachments
,
1112 std::vector
<GLenum
>* const scopedVector
,
1113 GLsizei
* const out_glNumAttachments
,
1114 const GLenum
** const out_glAttachments
);
1116 RefPtr
<WebGLFramebuffer
> mBoundDrawFramebuffer
;
1117 RefPtr
<WebGLFramebuffer
> mBoundReadFramebuffer
;
1118 RefPtr
<WebGLTransformFeedback
> mBoundTransformFeedback
;
1119 RefPtr
<WebGLVertexArray
> mBoundVertexArray
;
1122 const auto& BoundReadFb() const { return mBoundReadFramebuffer
; }
1125 RefPtr
<WebGLTransformFeedback
> mDefaultTransformFeedback
;
1126 RefPtr
<WebGLVertexArray
> mDefaultVertexArray
;
1128 ////////////////////////////////////
1131 GLuint mEmptyTFO
= 0;
1133 // Generic Vertex Attributes
1134 // Though CURRENT_VERTEX_ATTRIB is listed under "Vertex Shader State" in the
1135 // spec state tables, this isn't vertex shader /object/ state. This array is
1136 // merely state useful to vertex shaders, but is global state.
1137 std::vector
<webgl::AttribBaseType
> mGenericVertexAttribTypes
;
1138 CacheInvalidator mGenericVertexAttribTypeInvalidator
;
1140 GLuint mFakeVertexAttrib0BufferObject
= 0;
1141 size_t mFakeVertexAttrib0BufferObjectSize
= 0;
1142 bool mFakeVertexAttrib0DataDefined
= false;
1143 alignas(alignof(float)) uint8_t
1144 mGenericVertexAttrib0Data
[sizeof(float) * 4] = {};
1145 alignas(alignof(float)) uint8_t
1146 mFakeVertexAttrib0Data
[sizeof(float) * 4] = {};
1148 GLint mStencilRefFront
= 0;
1149 GLint mStencilRefBack
= 0;
1150 GLuint mStencilValueMaskFront
= 0;
1151 GLuint mStencilValueMaskBack
= 0;
1152 GLuint mStencilWriteMaskFront
= 0;
1153 GLuint mStencilWriteMaskBack
= 0;
1154 uint8_t mColorWriteMask
= 0xf; // bitmask
1155 realGLboolean mDepthWriteMask
= 0;
1156 GLfloat mColorClearValue
[4];
1157 GLint mStencilClearValue
= 0;
1158 GLfloat mDepthClearValue
= 0.0;
1160 GLint mViewportX
= 0;
1161 GLint mViewportY
= 0;
1162 GLsizei mViewportWidth
= 0;
1163 GLsizei mViewportHeight
= 0;
1164 bool mAlreadyWarnedAboutViewportLargerThanDest
= false;
1166 GLfloat mLineWidth
= 0.0;
1168 WebGLContextLossHandler mContextLossHandler
;
1170 // Used for some hardware (particularly Tegra 2 and 4) that likes to
1171 // be Flushed while doing hundreds of draw calls.
1172 mutable uint64_t mDrawCallsSinceLastFlush
= 0;
1174 mutable uint64_t mWarningCount
= 0;
1175 const uint64_t mMaxWarnings
;
1176 bool mAlreadyWarnedAboutFakeVertexAttrib0
= false;
1178 bool ShouldGenerateWarnings() const { return mWarningCount
< mMaxWarnings
; }
1180 bool ShouldGeneratePerfWarnings() const {
1181 return mNumPerfWarnings
< mMaxPerfWarnings
;
1184 bool mNeedsFakeNoAlpha
= false;
1185 bool mNeedsFakeNoDepth
= false;
1186 bool mNeedsFakeNoStencil
= false;
1187 bool mNeedsFakeNoStencil_UserFBs
= false;
1189 mutable uint8_t mDriverColorMask
= 0;
1190 bool mDriverDepthTest
= false;
1191 bool mDriverStencilTest
= false;
1193 bool mNeedsIndexValidation
= false;
1195 const bool mAllowFBInvalidation
;
1197 bool Has64BitTimestamps() const;
1201 const uint8_t mMsaaSamples
;
1202 mutable uvec2 mRequestedSize
;
1203 mutable UniquePtr
<gl::MozFramebuffer
> mDefaultFB
;
1204 mutable bool mDefaultFB_IsInvalid
= false;
1205 mutable UniquePtr
<gl::MozFramebuffer
> mResolvedDefaultFB
;
1207 gl::SwapChain mSwapChain
;
1208 gl::SwapChain mWebVRSwapChain
;
1212 bool EnsureDefaultFB();
1213 bool ValidateAndInitFB(
1214 const WebGLFramebuffer
* fb
,
1215 GLenum incompleteFbError
= LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION
);
1216 void DoBindFB(const WebGLFramebuffer
* fb
,
1217 GLenum target
= LOCAL_GL_FRAMEBUFFER
) const;
1219 bool BindCurFBForDraw();
1220 bool BindCurFBForColorRead(
1221 const webgl::FormatUsageInfo
** out_format
, uint32_t* out_width
,
1222 uint32_t* out_height
,
1223 GLenum incompleteFbError
= LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION
);
1224 void DoColorMask(uint8_t bitmask
) const;
1225 void BlitBackbufferToCurDriverFB(
1226 const gl::MozFramebuffer
* const source
= nullptr) const;
1227 bool BindDefaultFBForRead();
1232 // console logging helpers
1233 template <typename
... Args
>
1234 void GenerateWarning(const char* const fmt
, const Args
&... args
) const {
1235 GenerateError(0, fmt
, args
...);
1238 template <typename
... Args
>
1239 void GeneratePerfWarning(const char* const fmt
, const Args
&... args
) const {
1240 GenerateError(webgl::kErrorPerfWarning
, fmt
, args
...);
1244 UniquePtr
<webgl::FormatUsageAuthority
> mFormatUsage
;
1246 virtual UniquePtr
<webgl::FormatUsageAuthority
> CreateFormatUsage(
1247 gl::GLContext
* gl
) const;
1249 const decltype(mBound2DTextures
)* TexListForElemType(GLenum elemType
) const;
1252 friend class ScopedCopyTexImageSource
;
1253 friend class ScopedResolveTexturesForDraw
;
1254 friend class webgl::TexUnpackBlob
;
1255 friend class webgl::TexUnpackBytes
;
1256 friend class webgl::TexUnpackImage
;
1257 friend class webgl::TexUnpackSurface
;
1258 friend struct webgl::UniformInfo
;
1259 friend class WebGLTexture
;
1260 friend class WebGLFBAttachPoint
;
1261 friend class WebGLFramebuffer
;
1262 friend class WebGLRenderbuffer
;
1263 friend class WebGLProgram
;
1264 friend class WebGLQuery
;
1265 friend class WebGLBuffer
;
1266 friend class WebGLSampler
;
1267 friend class WebGLShader
;
1268 friend class WebGLSync
;
1269 friend class WebGLTransformFeedback
;
1270 friend class WebGLVertexArray
;
1271 friend class WebGLVertexArrayFake
;
1272 friend class WebGLVertexArrayGL
;
1275 // Returns `value` rounded to the next highest multiple of `multiple`.
1276 // AKA PadToAlignment, StrideForAlignment.
1277 template <typename V
, typename M
>
1278 V
RoundUpToMultipleOf(const V
& value
, const M
& multiple
) {
1279 return ((value
+ multiple
- 1) / multiple
) * multiple
;
1282 const char* GetEnumName(GLenum val
, const char* defaultRet
= "<unknown>");
1283 std::string
EnumString(GLenum val
);
1285 class ScopedFBRebinder final
{
1287 const WebGLContext
* const mWebGL
;
1290 explicit ScopedFBRebinder(const WebGLContext
* const webgl
) : mWebGL(webgl
) {}
1291 ~ScopedFBRebinder();
1296 constexpr inline bool IsBufferTargetLazilyBound(const GLenum target
) {
1297 return target
!= LOCAL_GL_ELEMENT_ARRAY_BUFFER
;
1300 void DoBindBuffer(gl::GLContext
&, GLenum target
, const WebGLBuffer
*);
1302 class ScopedLazyBind final
{
1305 const GLenum mTarget
;
1308 ScopedLazyBind(gl::GLContext
* const gl
, const GLenum target
,
1309 const WebGLBuffer
* const buf
)
1310 : mGL(*gl
), mTarget(IsBufferTargetLazilyBound(target
) ? target
: 0) {
1312 DoBindBuffer(mGL
, mTarget
, buf
);
1318 DoBindBuffer(mGL
, mTarget
, nullptr);
1325 bool Intersect(int32_t srcSize
, int32_t read0
, int32_t readSize
,
1326 int32_t* out_intRead0
, int32_t* out_intWrite0
,
1327 int32_t* out_intSize
);
1329 uint64_t AvailGroups(uint64_t totalAvailItems
, uint64_t firstItemOffset
,
1330 uint32_t groupSize
, uint32_t groupStride
);
1334 class ScopedDrawCallWrapper final
{
1336 WebGLContext
& mWebGL
;
1338 explicit ScopedDrawCallWrapper(WebGLContext
& webgl
);
1339 ~ScopedDrawCallWrapper();
1344 class ScopedPrepForResourceClear final
{
1345 const WebGLContext
& webgl
;
1348 explicit ScopedPrepForResourceClear(const WebGLContext
&);
1349 ~ScopedPrepForResourceClear();
1352 struct IndexedName final
{
1356 Maybe
<IndexedName
> ParseIndexed(const std::string
& str
);
1358 } // namespace webgl
1360 webgl::LinkActiveInfo
GetLinkActiveInfo(
1361 gl::GLContext
& gl
, const GLuint prog
, const bool webgl2
,
1362 const std::unordered_map
<std::string
, std::string
>& nameUnmap
);
1364 } // namespace mozilla