Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/canvas/WebGLContext.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/. */
5
6
#ifndef WEBGLCONTEXT_H_
7
#define WEBGLCONTEXT_H_
8
9
#include <stdarg.h>
10
11
#include "GLContextTypes.h"
12
#include "GLDefs.h"
13
#include "mozilla/Attributes.h"
14
#include "mozilla/CheckedInt.h"
15
#include "mozilla/dom/BindingDeclarations.h"
16
#include "mozilla/dom/HTMLCanvasElement.h"
17
#include "mozilla/dom/Nullable.h"
18
#include "mozilla/dom/TypedArray.h"
19
#include "mozilla/EnumeratedArray.h"
20
#include "mozilla/ErrorResult.h"
21
#include "mozilla/gfx/2D.h"
22
#include "mozilla/LinkedList.h"
23
#include "mozilla/UniquePtr.h"
24
#include "nsCycleCollectionNoteChild.h"
25
#include "nsICanvasRenderingContextInternal.h"
26
#include "nsLayoutUtils.h"
27
#include "nsTArray.h"
28
#include "nsWrapperCache.h"
29
#include "SurfaceTypes.h"
30
#include "ScopedGLHelpers.h"
31
#include "TexUnpackBlob.h"
32
33
// Local
34
#include "CacheMap.h"
35
#include "WebGLContextLossHandler.h"
36
#include "WebGLContextUnchecked.h"
37
#include "WebGLFormats.h"
38
#include "WebGLObjectModel.h"
39
#include "WebGLStrongTypes.h"
40
#include "WebGLTexture.h"
41
42
// Generated
43
#include "nsIDOMEventListener.h"
44
#include "nsICanvasRenderingContextInternal.h"
45
#include "nsIObserver.h"
46
#include "mozilla/dom/HTMLCanvasElement.h"
47
#include "nsWrapperCache.h"
48
#include "nsLayoutUtils.h"
49
#include "mozilla/dom/WebGLRenderingContextBinding.h"
50
#include "mozilla/dom/WebGL2RenderingContextBinding.h"
51
52
class nsIDocShell;
53
54
/*
55
 * WebGL-only GLenums
56
 */
57
#define LOCAL_GL_BROWSER_DEFAULT_WEBGL                       0x9244
58
0
#define LOCAL_GL_CONTEXT_LOST_WEBGL                          0x9242
59
0
#define LOCAL_GL_MAX_CLIENT_WAIT_TIMEOUT_WEBGL               0x9247
60
#define LOCAL_GL_UNPACK_COLORSPACE_CONVERSION_WEBGL          0x9243
61
#define LOCAL_GL_UNPACK_FLIP_Y_WEBGL                         0x9240
62
#define LOCAL_GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL              0x9241
63
64
namespace mozilla {
65
class ScopedCopyTexImageSource;
66
class ScopedDrawCallWrapper;
67
class ScopedResolveTexturesForDraw;
68
class ScopedUnpackReset;
69
class WebGLActiveInfo;
70
class WebGLBuffer;
71
class WebGLExtensionBase;
72
class WebGLFramebuffer;
73
class WebGLProgram;
74
class WebGLQuery;
75
class WebGLRenderbuffer;
76
class WebGLSampler;
77
class WebGLShader;
78
class WebGLShaderPrecisionFormat;
79
class WebGLSync;
80
class WebGLTexture;
81
class WebGLTransformFeedback;
82
class WebGLUniformLocation;
83
class WebGLVertexArray;
84
85
namespace dom {
86
class Element;
87
class ImageData;
88
class OwningHTMLCanvasElementOrOffscreenCanvas;
89
struct WebGLContextAttributes;
90
} // namespace dom
91
92
namespace gfx {
93
class SourceSurface;
94
class VRLayerChild;
95
} // namespace gfx
96
97
namespace gl {
98
class GLScreenBuffer;
99
class MozFramebuffer;
100
} // namespace gl
101
102
namespace webgl {
103
class AvailabilityRunnable;
104
struct CachedDrawFetchLimits;
105
struct LinkedProgramInfo;
106
class ShaderValidator;
107
class TexUnpackBlob;
108
struct UniformInfo;
109
struct UniformBlockInfo;
110
} // namespace webgl
111
112
WebGLTexelFormat GetWebGLTexelFormat(TexInternalFormat format);
113
114
void AssertUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint shadow);
115
116
struct WebGLContextOptions
117
{
118
    bool alpha = true;
119
    bool depth = true;
120
    bool stencil = false;
121
    bool premultipliedAlpha = true;
122
    bool antialias = true;
123
    bool preserveDrawingBuffer = false;
124
    bool failIfMajorPerformanceCaveat = false;
125
    dom::WebGLPowerPreference powerPreference = dom::WebGLPowerPreference::Default;
126
127
    WebGLContextOptions();
128
    bool operator==(const WebGLContextOptions&) const;
129
};
130
131
// From WebGLContextUtils
132
TexTarget TexImageTargetToTexTarget(TexImageTarget texImageTarget);
133
134
struct WebGLIntOrFloat {
135
    const enum {
136
        Int,
137
        Float,
138
        Uint
139
    } mType;
140
141
    union {
142
        GLint i;
143
        GLfloat f;
144
        GLuint u;
145
    } mValue;
146
147
0
    explicit WebGLIntOrFloat(GLint i) : mType(Int) { mValue.i = i; }
148
0
    explicit WebGLIntOrFloat(GLfloat f) : mType(Float) { mValue.f = f; }
149
150
0
    GLint AsInt() const { return (mType == Int) ? mValue.i : NS_lroundf(mValue.f); }
151
0
    GLfloat AsFloat() const { return (mType == Float) ? mValue.f : GLfloat(mValue.i); }
152
};
153
154
struct IndexedBufferBinding
155
{
156
    WebGLRefPtr<WebGLBuffer> mBufferBinding;
157
    uint64_t mRangeStart;
158
    uint64_t mRangeSize;
159
160
    IndexedBufferBinding();
161
162
    uint64_t ByteCount() const;
163
};
164
165
////
166
167
struct FloatOrInt final // For TexParameter[fi] and friends.
168
{
169
    const bool isFloat;
170
    const GLfloat f;
171
    const GLint i;
172
173
    explicit FloatOrInt(GLint x)
174
        : isFloat(false)
175
        , f(x)
176
        , i(x)
177
0
    { }
178
179
    explicit FloatOrInt(GLfloat x)
180
        : isFloat(true)
181
        , f(x)
182
        , i(roundf(x))
183
0
    { }
184
185
0
    FloatOrInt& operator =(const FloatOrInt& x) {
186
0
        memcpy(this, &x, sizeof(x));
187
0
        return *this;
188
0
    }
189
};
190
191
////////////////////////////////////
192
193
struct TexImageSource
194
{
195
    const dom::ArrayBufferView* mView;
196
    GLuint mViewElemOffset;
197
    GLuint mViewElemLengthOverride;
198
199
    const WebGLsizeiptr* mPboOffset;
200
201
    const dom::ImageBitmap* mImageBitmap;
202
    const dom::ImageData* mImageData;
203
204
    const dom::Element* mDomElem;
205
    ErrorResult* mOut_error;
206
207
protected:
208
0
    TexImageSource() {
209
0
        memset(this, 0, sizeof(*this));
210
0
    }
211
};
212
213
////
214
215
struct TexImageSourceAdapter final : public TexImageSource
216
{
217
    TexImageSourceAdapter(const dom::Nullable<dom::ArrayBufferView>* maybeView,
218
                          ErrorResult*)
219
0
    {
220
0
        if (!maybeView->IsNull()) {
221
0
            mView = &(maybeView->Value());
222
0
        }
223
0
    }
224
225
0
    TexImageSourceAdapter(const dom::ArrayBufferView* view, ErrorResult*) {
226
0
        mView = view;
227
0
    }
228
229
    TexImageSourceAdapter(const dom::ArrayBufferView* view, GLuint viewElemOffset,
230
                          GLuint viewElemLengthOverride = 0)
231
0
    {
232
0
        mView = view;
233
0
        mViewElemOffset = viewElemOffset;
234
0
        mViewElemLengthOverride = viewElemLengthOverride;
235
0
    }
236
237
0
    TexImageSourceAdapter(const WebGLsizeiptr* pboOffset, GLuint ignored1, GLuint ignored2 = 0) {
238
0
        mPboOffset = pboOffset;
239
0
    }
240
241
0
    TexImageSourceAdapter(const WebGLsizeiptr* pboOffset, ErrorResult* ignored) {
242
0
        mPboOffset = pboOffset;
243
0
    }
244
245
0
    TexImageSourceAdapter(const dom::ImageBitmap* imageBitmap, ErrorResult*) {
246
0
        mImageBitmap = imageBitmap;
247
0
    }
248
249
0
    TexImageSourceAdapter(const dom::ImageData* imageData, ErrorResult*) {
250
0
        mImageData = imageData;
251
0
    }
252
253
0
    TexImageSourceAdapter(const dom::Element* domElem, ErrorResult* const out_error) {
254
0
        mDomElem = domElem;
255
0
        mOut_error = out_error;
256
0
    }
257
};
258
259
// --
260
261
namespace webgl {
262
class AvailabilityRunnable final : public Runnable
263
{
264
public:
265
    const RefPtr<WebGLContext> mWebGL; // Prevent CC
266
    std::vector<RefPtr<WebGLQuery>> mQueries;
267
    std::vector<RefPtr<WebGLSync>> mSyncs;
268
269
    explicit AvailabilityRunnable(WebGLContext* webgl);
270
    ~AvailabilityRunnable();
271
272
    NS_IMETHOD Run() override;
273
};
274
} // namespace webgl
275
276
////////////////////////////////////////////////////////////////////////////////
277
278
class WebGLContext
279
    : public nsICanvasRenderingContextInternal
280
    , public nsSupportsWeakReference
281
    , public WebGLContextUnchecked
282
    , public nsWrapperCache
283
{
284
    friend class ScopedDrawCallWrapper;
285
    friend class ScopedDrawWithTransformFeedback;
286
    friend class ScopedFakeVertexAttrib0;
287
    friend class ScopedFBRebinder;
288
    friend class WebGL2Context;
289
    friend class WebGLContextUserData;
290
    friend class WebGLExtensionCompressedTextureASTC;
291
    friend class WebGLExtensionCompressedTextureATC;
292
    friend class WebGLExtensionCompressedTextureES3;
293
    friend class WebGLExtensionCompressedTextureETC1;
294
    friend class WebGLExtensionCompressedTexturePVRTC;
295
    friend class WebGLExtensionCompressedTextureS3TC;
296
    friend class WebGLExtensionCompressedTextureS3TC_SRGB;
297
    friend class WebGLExtensionDepthTexture;
298
    friend class WebGLExtensionDisjointTimerQuery;
299
    friend class WebGLExtensionDrawBuffers;
300
    friend class WebGLExtensionLoseContext;
301
    friend class WebGLExtensionMOZDebug;
302
    friend class WebGLExtensionVertexArray;
303
    friend class WebGLMemoryTracker;
304
    friend class webgl::AvailabilityRunnable;
305
    friend struct webgl::LinkedProgramInfo;
306
    friend struct webgl::UniformBlockInfo;
307
308
    friend const webgl::CachedDrawFetchLimits*
309
        ValidateDraw(WebGLContext*, GLenum, uint32_t);
310
311
    enum {
312
        UNPACK_FLIP_Y_WEBGL = 0x9240,
313
        UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241,
314
        // We throw InvalidOperation in TexImage if we fail to use GPU fast-path
315
        // for texture copy when it is set to true, only for debug purpose.
316
        UNPACK_REQUIRE_FASTPATH = 0x10001,
317
        CONTEXT_LOST_WEBGL = 0x9242,
318
        UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
319
        BROWSER_DEFAULT_WEBGL = 0x9244,
320
        UNMASKED_VENDOR_WEBGL = 0x9245,
321
        UNMASKED_RENDERER_WEBGL = 0x9246
322
    };
323
324
    const uint32_t mMaxPerfWarnings;
325
    mutable uint64_t mNumPerfWarnings;
326
    const uint32_t mMaxAcceptableFBStatusInvals;
327
328
    uint64_t mNextFenceId = 1;
329
    uint64_t mCompletedFenceId = 0;
330
331
public:
332
    class FuncScope;
333
private:
334
    mutable FuncScope* mFuncScope = nullptr;
335
336
public:
337
    WebGLContext();
338
339
protected:
340
    virtual ~WebGLContext();
341
342
public:
343
    NS_DECL_CYCLE_COLLECTING_ISUPPORTS
344
345
    NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(WebGLContext,
346
                                                           nsICanvasRenderingContextInternal)
347
348
    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override = 0;
349
350
    virtual void OnVisibilityChange() override;
351
    virtual void OnMemoryPressure() override;
352
353
    // nsICanvasRenderingContextInternal
354
0
    virtual int32_t GetWidth() override { return DrawingBufferWidth(); }
355
0
    virtual int32_t GetHeight() override { return DrawingBufferHeight(); }
356
357
    NS_IMETHOD SetDimensions(int32_t width, int32_t height) override;
358
    NS_IMETHOD InitializeWithDrawTarget(nsIDocShell*,
359
                                        NotNull<gfx::DrawTarget*>) override
360
0
    {
361
0
        return NS_ERROR_NOT_IMPLEMENTED;
362
0
    }
363
364
0
    NS_IMETHOD Reset() override {
365
0
        /* (InitializeWithSurface) */
366
0
        return NS_ERROR_NOT_IMPLEMENTED;
367
0
    }
368
369
    virtual UniquePtr<uint8_t[]> GetImageBuffer(int32_t* out_format) override;
370
    NS_IMETHOD GetInputStream(const char* mimeType,
371
                              const char16_t* encoderOptions,
372
                              nsIInputStream** out_stream) override;
373
374
    virtual already_AddRefed<mozilla::gfx::SourceSurface>
375
    GetSurfaceSnapshot(gfxAlphaType* out_alphaType) override;
376
377
0
    virtual void SetOpaqueValueFromOpaqueAttr(bool) override {};
378
0
    bool GetIsOpaque() override { return !mOptions.alpha; }
379
    NS_IMETHOD SetContextOptions(JSContext* cx,
380
                                 JS::Handle<JS::Value> options,
381
                                 ErrorResult& aRvForDictionaryInit) override;
382
383
0
    NS_IMETHOD SetIsIPC(bool) override {
384
0
        return NS_ERROR_NOT_IMPLEMENTED;
385
0
    }
386
387
    /**
388
     * An abstract base class to be implemented by callers wanting to be notified
389
     * that a refresh has occurred. Callers must ensure an observer is removed
390
     * before it is destroyed.
391
     */
392
    virtual void DidRefresh() override;
393
394
0
    NS_IMETHOD Redraw(const gfxRect&) override {
395
0
        return NS_ERROR_NOT_IMPLEMENTED;
396
0
    }
397
398
    // -
399
400
0
    const auto& CurFuncScope() const { return *mFuncScope; }
401
    const char* FuncName() const;
402
403
    class FuncScope final {
404
    public:
405
        const WebGLContext& mWebGL;
406
        const char* const mFuncName;
407
    private:
408
#ifdef DEBUG
409
        mutable bool mStillNeedsToCheckContextLost = true;
410
#endif
411
412
    public:
413
        FuncScope(const WebGLContext& webgl, const char* funcName);
414
        ~FuncScope();
415
416
0
        void OnCheckContextLost() const {
417
#ifdef DEBUG
418
            mStillNeedsToCheckContextLost = false;
419
#endif
420
        }
421
    };
422
423
    void SynthesizeGLError(GLenum err) const;
424
    void SynthesizeGLError(GLenum err, const char* fmt, ...) const MOZ_FORMAT_PRINTF(3, 4);
425
426
    void ErrorInvalidEnum(const char* fmt = 0, ...) const MOZ_FORMAT_PRINTF(2, 3);
427
    void ErrorInvalidOperation(const char* fmt = 0, ...) const MOZ_FORMAT_PRINTF(2, 3);
428
    void ErrorInvalidValue(const char* fmt = 0, ...) const MOZ_FORMAT_PRINTF(2, 3);
429
    void ErrorInvalidFramebufferOperation(const char* fmt = 0, ...) const MOZ_FORMAT_PRINTF(2, 3);
430
    void ErrorInvalidEnumInfo(const char* info, GLenum enumValue) const;
431
    void ErrorOutOfMemory(const char* fmt = 0, ...) const MOZ_FORMAT_PRINTF(2, 3);
432
    void ErrorImplementationBug(const char* fmt = 0, ...) const MOZ_FORMAT_PRINTF(2, 3);
433
434
    void ErrorInvalidEnumArg(const char* argName, GLenum val) const;
435
436
    static const char* ErrorName(GLenum error);
437
438
    /**
439
     * Return displayable name for GLenum.
440
     * This version is like gl::GLenumToStr but with out the GL_ prefix to
441
     * keep consistency with how errors are reported from WebGL.
442
     * Returns hex formatted version of glenum if glenum is unknown.
443
     */
444
    static void EnumName(GLenum val, nsCString* out_name);
445
446
    void DummyReadFramebufferOperation();
447
448
0
    WebGLTexture* ActiveBoundTextureForTarget(const TexTarget texTarget) const {
449
0
        switch (texTarget.get()) {
450
0
        case LOCAL_GL_TEXTURE_2D:
451
0
            return mBound2DTextures[mActiveTexture];
452
0
        case LOCAL_GL_TEXTURE_CUBE_MAP:
453
0
            return mBoundCubeMapTextures[mActiveTexture];
454
0
        case LOCAL_GL_TEXTURE_3D:
455
0
            return mBound3DTextures[mActiveTexture];
456
0
        case LOCAL_GL_TEXTURE_2D_ARRAY:
457
0
            return mBound2DArrayTextures[mActiveTexture];
458
0
        default:
459
0
            MOZ_CRASH("GFX: bad target");
460
0
        }
461
0
    }
462
463
    /* Use this function when you have the texture image target, for example:
464
     * GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP_[POSITIVE|NEGATIVE]_[X|Y|Z], and
465
     * not the actual texture binding target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
466
     */
467
    WebGLTexture*
468
    ActiveBoundTextureForTexImageTarget(const TexImageTarget texImgTarget) const
469
0
    {
470
0
        const TexTarget texTarget = TexImageTargetToTexTarget(texImgTarget);
471
0
        return ActiveBoundTextureForTarget(texTarget);
472
0
    }
473
474
    void InvalidateResolveCacheForTextureWithTexUnit(const GLuint);
475
476
    already_AddRefed<Layer>
477
    GetCanvasLayer(nsDisplayListBuilder* builder, Layer* oldLayer,
478
                   LayerManager* manager) override;
479
480
    bool
481
    UpdateWebRenderCanvasData(nsDisplayListBuilder* aBuilder,
482
                              WebRenderCanvasData* aCanvasData) override;
483
484
    bool
485
    InitializeCanvasRenderer(nsDisplayListBuilder* aBuilder,
486
                             CanvasRenderer* aRenderer) override;
487
488
    // Note that 'clean' here refers to its invalidation state, not the
489
    // contents of the buffer.
490
0
    void MarkContextClean() override { mInvalidated = false; }
491
492
0
    void MarkContextCleanForFrameCapture() override { mCapturedFrameInvalidated = false; }
493
494
0
    bool IsContextCleanForFrameCapture() override { return !mCapturedFrameInvalidated; }
495
496
0
    gl::GLContext* GL() const { return gl; }
497
498
0
    bool IsPremultAlpha() const { return mOptions.premultipliedAlpha; }
499
500
0
    bool IsPreservingDrawingBuffer() const { return mOptions.preserveDrawingBuffer; }
501
502
    bool PresentScreenBuffer(gl::GLScreenBuffer* const screen = nullptr);
503
504
    // Prepare the context for capture before compositing
505
    void BeginComposition(gl::GLScreenBuffer* const screen = nullptr);
506
    // Clean up the context after captured for compositing
507
    void EndComposition();
508
509
    // a number that increments every time we have an event that causes
510
    // all context resources to be lost.
511
0
    uint32_t Generation() const { return mGeneration.value(); }
512
513
    // This is similar to GLContext::ClearSafely, but tries to minimize the
514
    // amount of work it does.
515
    // It only clears the buffers we specify, and can reset its state without
516
    // first having to query anything, as WebGL knows its state at all times.
517
    void ForceClearFramebufferWithDefaultValues(GLbitfield bufferBits,
518
                                                bool fakeNoAlpha) const;
519
520
    void RunContextLossTimer();
521
    void UpdateContextLossStatus();
522
    void EnqueueUpdateContextLossStatus();
523
524
    bool TryToRestoreContext();
525
526
    void AssertCachedBindings() const;
527
    void AssertCachedGlobalState() const;
528
529
0
    dom::HTMLCanvasElement* GetCanvas() const { return mCanvasElement; }
530
    nsIDocument* GetOwnerDoc() const;
531
532
    // WebIDL WebGLRenderingContext API
533
    void Commit();
534
    void GetCanvas(dom::Nullable<dom::OwningHTMLCanvasElementOrOffscreenCanvas>& retval);
535
private:
536
    gfx::IntSize DrawingBufferSize();
537
public:
538
0
    GLsizei DrawingBufferWidth() {
539
0
        const FuncScope funcScope(*this, "drawingBufferWidth");
540
0
        return DrawingBufferSize().width;
541
0
    }
542
0
    GLsizei DrawingBufferHeight() {
543
0
        const FuncScope funcScope(*this, "drawingBufferHeight");
544
0
        return DrawingBufferSize().height;
545
0
    }
546
547
    layers::LayersBackend GetCompositorBackendType() const;
548
549
    void
550
    GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& retval);
551
552
    // This is the entrypoint. Don't test against it directly.
553
    bool IsContextLost() const;
554
555
    void GetSupportedExtensions(dom::Nullable< nsTArray<nsString> >& retval,
556
                                dom::CallerType callerType);
557
    void GetExtension(JSContext* cx, const nsAString& name,
558
                      JS::MutableHandle<JSObject*> retval,
559
                      dom::CallerType callerType, ErrorResult& rv);
560
    void AttachShader(WebGLProgram& prog, WebGLShader& shader);
561
    void BindAttribLocation(WebGLProgram& prog, GLuint location,
562
                            const nsAString& name);
563
    void BindFramebuffer(GLenum target, WebGLFramebuffer* fb);
564
    void BindRenderbuffer(GLenum target, WebGLRenderbuffer* fb);
565
    void BindVertexArray(WebGLVertexArray* vao);
566
    void BlendColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
567
    void BlendEquation(GLenum mode);
568
    void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha);
569
    void BlendFunc(GLenum sfactor, GLenum dfactor);
570
    void BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB,
571
                           GLenum srcAlpha, GLenum dstAlpha);
572
    GLenum CheckFramebufferStatus(GLenum target);
573
    void Clear(GLbitfield mask);
574
    void ClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
575
    void ClearDepth(GLclampf v);
576
    void ClearStencil(GLint v);
577
    void ColorMask(WebGLboolean r, WebGLboolean g, WebGLboolean b, WebGLboolean a);
578
    void CompileShader(WebGLShader& shader);
579
    void CompileShaderANGLE(WebGLShader* shader);
580
    void CompileShaderBypass(WebGLShader* shader, const nsCString& shaderSource);
581
    already_AddRefed<WebGLFramebuffer> CreateFramebuffer();
582
    already_AddRefed<WebGLProgram> CreateProgram();
583
    already_AddRefed<WebGLRenderbuffer> CreateRenderbuffer();
584
    already_AddRefed<WebGLShader> CreateShader(GLenum type);
585
    already_AddRefed<WebGLVertexArray> CreateVertexArray();
586
    void CullFace(GLenum face);
587
    void DeleteFramebuffer(WebGLFramebuffer* fb);
588
    void DeleteProgram(WebGLProgram* prog);
589
    void DeleteRenderbuffer(WebGLRenderbuffer* rb);
590
    void DeleteShader(WebGLShader* shader);
591
    void DeleteVertexArray(WebGLVertexArray* vao);
592
    void DepthFunc(GLenum func);
593
    void DepthMask(WebGLboolean b);
594
    void DepthRange(GLclampf zNear, GLclampf zFar);
595
    void DetachShader(WebGLProgram& prog, const WebGLShader& shader);
596
    void DrawBuffers(const dom::Sequence<GLenum>& buffers);
597
    void Flush();
598
    void Finish();
599
    void FramebufferRenderbuffer(GLenum target, GLenum attachment,
600
                                 GLenum rbTarget, WebGLRenderbuffer* rb);
601
    void FramebufferTexture2D(GLenum target, GLenum attachment,
602
                              GLenum texImageTarget, WebGLTexture* tex,
603
                              GLint level);
604
605
    void FrontFace(GLenum mode);
606
    already_AddRefed<WebGLActiveInfo> GetActiveAttrib(const WebGLProgram& prog,
607
                                                      GLuint index);
608
    already_AddRefed<WebGLActiveInfo> GetActiveUniform(const WebGLProgram& prog,
609
                                                       GLuint index);
610
611
    void
612
    GetAttachedShaders(const WebGLProgram& prog,
613
                       dom::Nullable<nsTArray<RefPtr<WebGLShader>>>& retval);
614
615
    GLint GetAttribLocation(const WebGLProgram& prog, const nsAString& name);
616
    JS::Value GetBufferParameter(GLenum target, GLenum pname);
617
618
    void GetBufferParameter(JSContext*, GLenum target, GLenum pname,
619
                            JS::MutableHandle<JS::Value> retval)
620
0
    {
621
0
        retval.set(GetBufferParameter(target, pname));
622
0
    }
623
624
    GLenum GetError();
625
    virtual JS::Value GetFramebufferAttachmentParameter(JSContext* cx, GLenum target,
626
                                                        GLenum attachment, GLenum pname,
627
                                                        ErrorResult& rv);
628
629
    void GetFramebufferAttachmentParameter(JSContext* cx, GLenum target,
630
                                           GLenum attachment, GLenum pname,
631
                                           JS::MutableHandle<JS::Value> retval,
632
                                           ErrorResult& rv)
633
0
    {
634
0
        retval.set(GetFramebufferAttachmentParameter(cx, target, attachment,
635
0
                                                     pname, rv));
636
0
    }
637
638
    JS::Value GetProgramParameter(const WebGLProgram& prog, GLenum pname);
639
640
    void  GetProgramParameter(JSContext*, const WebGLProgram& prog, GLenum pname,
641
                              JS::MutableHandle<JS::Value> retval)
642
0
    {
643
0
        retval.set(GetProgramParameter(prog, pname));
644
0
    }
645
646
    void GetProgramInfoLog(const WebGLProgram& prog, nsACString& retval);
647
    void GetProgramInfoLog(const WebGLProgram& prog, nsAString& retval);
648
    JS::Value GetRenderbufferParameter(GLenum target, GLenum pname);
649
650
    void GetRenderbufferParameter(JSContext*, GLenum target, GLenum pname,
651
                                  JS::MutableHandle<JS::Value> retval)
652
0
    {
653
0
        retval.set(GetRenderbufferParameter(target, pname));
654
0
    }
655
656
    JS::Value GetShaderParameter(const WebGLShader& shader, GLenum pname);
657
658
    void GetShaderParameter(JSContext*, const WebGLShader& shader, GLenum pname,
659
                            JS::MutableHandle<JS::Value> retval)
660
0
    {
661
0
        retval.set(GetShaderParameter(shader, pname));
662
0
    }
663
664
    already_AddRefed<WebGLShaderPrecisionFormat>
665
    GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype);
666
667
    void GetShaderInfoLog(const WebGLShader& shader, nsACString& retval);
668
    void GetShaderInfoLog(const WebGLShader& shader, nsAString& retval);
669
    void GetShaderSource(const WebGLShader& shader, nsAString& retval);
670
671
    JS::Value GetUniform(JSContext* cx, const WebGLProgram& prog,
672
                         const WebGLUniformLocation& loc);
673
674
    void GetUniform(JSContext* cx, const WebGLProgram& prog,
675
                    const WebGLUniformLocation& loc,
676
                    JS::MutableHandle<JS::Value> retval)
677
0
    {
678
0
        retval.set(GetUniform(cx, prog, loc));
679
0
    }
680
681
    already_AddRefed<WebGLUniformLocation>
682
    GetUniformLocation(const WebGLProgram& prog, const nsAString& name);
683
684
    void Hint(GLenum target, GLenum mode);
685
686
    bool IsBuffer(const WebGLBuffer* obj);
687
    bool IsFramebuffer(const WebGLFramebuffer* obj);
688
    bool IsProgram(const WebGLProgram* obj);
689
    bool IsRenderbuffer(const WebGLRenderbuffer* obj);
690
    bool IsShader(const WebGLShader* obj);
691
    bool IsTexture(const WebGLTexture* obj);
692
    bool IsVertexArray(const WebGLVertexArray* obj);
693
694
    void LineWidth(GLfloat width);
695
    void LinkProgram(WebGLProgram& prog);
696
    void PixelStorei(GLenum pname, GLint param);
697
    void PolygonOffset(GLfloat factor, GLfloat units);
698
699
    already_AddRefed<layers::SharedSurfaceTextureClient> GetVRFrame();
700
701
    ////
702
703
    webgl::PackingInfo
704
    ValidImplementationColorReadPI(const webgl::FormatUsageInfo* usage) const;
705
706
protected:
707
    bool ReadPixels_SharedPrecheck(dom::CallerType aCallerType,
708
                                   ErrorResult& out_error);
709
    void ReadPixelsImpl(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
710
                        GLenum type, void* data, uint32_t dataLen);
711
    bool DoReadPixelsAndConvert(const webgl::FormatInfo* srcFormat, GLint x, GLint y,
712
                                GLsizei width, GLsizei height, GLenum format,
713
                                GLenum destType, void* dest, uint32_t dataLen,
714
                                uint32_t rowStride);
715
public:
716
    void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
717
                    GLenum type, const dom::Nullable<dom::ArrayBufferView>& maybeView,
718
                    dom::CallerType aCallerType, ErrorResult& rv)
719
0
    {
720
0
        const FuncScope funcScope(*this, "readPixels");
721
0
        if (!ValidateNonNull("pixels", maybeView))
722
0
            return;
723
0
        ReadPixels(x, y, width, height, format, type, maybeView.Value(), 0,
724
0
                   aCallerType, rv);
725
0
    }
726
727
    void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
728
                    GLenum type, WebGLsizeiptr offset,
729
                    dom::CallerType, ErrorResult& out_error);
730
731
    void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
732
                    GLenum type, const dom::ArrayBufferView& dstData, GLuint dstOffset,
733
                    dom::CallerType, ErrorResult& out_error);
734
735
    ////
736
737
    void RenderbufferStorage(GLenum target, GLenum internalFormat,
738
                             GLsizei width, GLsizei height)
739
0
    {
740
0
        const FuncScope funcScope(*this, "renderbufferStorage");
741
0
        RenderbufferStorage_base(target, 0, internalFormat, width, height);
742
0
    }
743
protected:
744
    void RenderbufferStorage_base(GLenum target, GLsizei samples, GLenum internalformat,
745
                                  GLsizei width, GLsizei height);
746
public:
747
    void SampleCoverage(GLclampf value, WebGLboolean invert);
748
    void Scissor(GLint x, GLint y, GLsizei width, GLsizei height);
749
    void ShaderSource(WebGLShader& shader, const nsAString& source);
750
    void StencilFunc(GLenum func, GLint ref, GLuint mask);
751
    void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
752
    void StencilMask(GLuint mask);
753
    void StencilMaskSeparate(GLenum face, GLuint mask);
754
    void StencilOp(GLenum sfail, GLenum dpfail, GLenum dppass);
755
    void StencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail,
756
                           GLenum dppass);
757
758
    //////
759
760
    void Uniform1f(WebGLUniformLocation* loc, GLfloat x);
761
    void Uniform2f(WebGLUniformLocation* loc, GLfloat x, GLfloat y);
762
    void Uniform3f(WebGLUniformLocation* loc, GLfloat x, GLfloat y, GLfloat z);
763
    void Uniform4f(WebGLUniformLocation* loc, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
764
765
    void Uniform1i(WebGLUniformLocation* loc, GLint x);
766
    void Uniform2i(WebGLUniformLocation* loc, GLint x, GLint y);
767
    void Uniform3i(WebGLUniformLocation* loc, GLint x, GLint y, GLint z);
768
    void Uniform4i(WebGLUniformLocation* loc, GLint x, GLint y, GLint z, GLint w);
769
770
    void Uniform1ui(WebGLUniformLocation* loc, GLuint v0);
771
    void Uniform2ui(WebGLUniformLocation* loc, GLuint v0, GLuint v1);
772
    void Uniform3ui(WebGLUniformLocation* loc, GLuint v0, GLuint v1, GLuint v2);
773
    void Uniform4ui(WebGLUniformLocation* loc, GLuint v0, GLuint v1, GLuint v2,
774
                    GLuint v3);
775
776
    //////////////////////////
777
778
    typedef dom::Float32ArrayOrUnrestrictedFloatSequence Float32ListU;
779
    typedef dom::Int32ArrayOrLongSequence Int32ListU;
780
    typedef dom::Uint32ArrayOrUnsignedLongSequence Uint32ListU;
781
782
protected:
783
    template<typename elemT, typename viewT>
784
    struct Arr {
785
        const size_t elemCount;
786
        const elemT* const elemBytes;
787
788
    private:
789
0
        static size_t ComputeAndReturnLength(const viewT& view) {
790
0
            view.ComputeLengthAndData();
791
0
            return view.LengthAllowShared();
792
0
        }
Unexecuted instantiation: mozilla::WebGLContext::Arr<float, mozilla::dom::TypedArray<float, &js::UnwrapFloat32Array, &(JS_GetFloat32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetFloat32ArrayLengthAndData, &(JS_NewFloat32Array(JSContext*, unsigned int))> >::ComputeAndReturnLength(mozilla::dom::TypedArray<float, &js::UnwrapFloat32Array, &(JS_GetFloat32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetFloat32ArrayLengthAndData, &(JS_NewFloat32Array(JSContext*, unsigned int))> const&)
Unexecuted instantiation: mozilla::WebGLContext::Arr<int, mozilla::dom::TypedArray<int, &js::UnwrapInt32Array, &(JS_GetInt32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetInt32ArrayLengthAndData, &(JS_NewInt32Array(JSContext*, unsigned int))> >::ComputeAndReturnLength(mozilla::dom::TypedArray<int, &js::UnwrapInt32Array, &(JS_GetInt32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetInt32ArrayLengthAndData, &(JS_NewInt32Array(JSContext*, unsigned int))> const&)
Unexecuted instantiation: mozilla::WebGLContext::Arr<unsigned int, mozilla::dom::TypedArray<unsigned int, &js::UnwrapUint32Array, &(JS_GetUint32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetUint32ArrayLengthAndData, &(JS_NewUint32Array(JSContext*, unsigned int))> >::ComputeAndReturnLength(mozilla::dom::TypedArray<unsigned int, &js::UnwrapUint32Array, &(JS_GetUint32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetUint32ArrayLengthAndData, &(JS_NewUint32Array(JSContext*, unsigned int))> const&)
793
794
    public:
795
        explicit Arr(const viewT& view)
796
            : elemCount(ComputeAndReturnLength(view))
797
            , elemBytes(view.DataAllowShared())
798
0
        { }
Unexecuted instantiation: mozilla::WebGLContext::Arr<float, mozilla::dom::TypedArray<float, &js::UnwrapFloat32Array, &(JS_GetFloat32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetFloat32ArrayLengthAndData, &(JS_NewFloat32Array(JSContext*, unsigned int))> >::Arr(mozilla::dom::TypedArray<float, &js::UnwrapFloat32Array, &(JS_GetFloat32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetFloat32ArrayLengthAndData, &(JS_NewFloat32Array(JSContext*, unsigned int))> const&)
Unexecuted instantiation: mozilla::WebGLContext::Arr<int, mozilla::dom::TypedArray<int, &js::UnwrapInt32Array, &(JS_GetInt32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetInt32ArrayLengthAndData, &(JS_NewInt32Array(JSContext*, unsigned int))> >::Arr(mozilla::dom::TypedArray<int, &js::UnwrapInt32Array, &(JS_GetInt32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetInt32ArrayLengthAndData, &(JS_NewInt32Array(JSContext*, unsigned int))> const&)
Unexecuted instantiation: mozilla::WebGLContext::Arr<unsigned int, mozilla::dom::TypedArray<unsigned int, &js::UnwrapUint32Array, &(JS_GetUint32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetUint32ArrayLengthAndData, &(JS_NewUint32Array(JSContext*, unsigned int))> >::Arr(mozilla::dom::TypedArray<unsigned int, &js::UnwrapUint32Array, &(JS_GetUint32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetUint32ArrayLengthAndData, &(JS_NewUint32Array(JSContext*, unsigned int))> const&)
799
800
        explicit Arr(const dom::Sequence<elemT>& seq)
801
            : elemCount(seq.Length())
802
            , elemBytes(seq.Elements())
803
0
        { }
Unexecuted instantiation: mozilla::WebGLContext::Arr<float, mozilla::dom::TypedArray<float, &js::UnwrapFloat32Array, &(JS_GetFloat32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetFloat32ArrayLengthAndData, &(JS_NewFloat32Array(JSContext*, unsigned int))> >::Arr(mozilla::dom::Sequence<float> const&)
Unexecuted instantiation: mozilla::WebGLContext::Arr<int, mozilla::dom::TypedArray<int, &js::UnwrapInt32Array, &(JS_GetInt32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetInt32ArrayLengthAndData, &(JS_NewInt32Array(JSContext*, unsigned int))> >::Arr(mozilla::dom::Sequence<int> const&)
Unexecuted instantiation: mozilla::WebGLContext::Arr<unsigned int, mozilla::dom::TypedArray<unsigned int, &js::UnwrapUint32Array, &(JS_GetUint32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetUint32ArrayLengthAndData, &(JS_NewUint32Array(JSContext*, unsigned int))> >::Arr(mozilla::dom::Sequence<unsigned int> const&)
804
805
        Arr(size_t _elemCount, const elemT* _elemBytes)
806
            : elemCount(_elemCount)
807
            , elemBytes(_elemBytes)
808
        { }
809
810
        ////
811
812
0
        static Arr From(const Float32ListU& list) {
813
0
            if (list.IsFloat32Array())
814
0
                return Arr(list.GetAsFloat32Array());
815
0
816
0
            return Arr(list.GetAsUnrestrictedFloatSequence());
817
0
        }
818
819
0
        static Arr From(const Int32ListU& list) {
820
0
            if (list.IsInt32Array())
821
0
                return Arr(list.GetAsInt32Array());
822
0
823
0
            return Arr(list.GetAsLongSequence());
824
0
        }
825
826
0
        static Arr From(const Uint32ListU& list) {
827
0
            if (list.IsUint32Array())
828
0
                return Arr(list.GetAsUint32Array());
829
0
830
0
            return Arr(list.GetAsUnsignedLongSequence());
831
0
        }
832
    };
833
834
    typedef Arr<GLfloat, dom::Float32Array> Float32Arr;
835
    typedef Arr<GLint, dom::Int32Array> Int32Arr;
836
    typedef Arr<GLuint, dom::Uint32Array> Uint32Arr;
837
838
    ////////////////
839
840
    void UniformNfv(const char* funcName, uint8_t N, WebGLUniformLocation* loc,
841
                    const Float32Arr& arr, GLuint elemOffset, GLuint elemCountOverride);
842
    void UniformNiv(const char* funcName, uint8_t N, WebGLUniformLocation* loc,
843
                    const Int32Arr& arr, GLuint elemOffset, GLuint elemCountOverride);
844
    void UniformNuiv(const char* funcName, uint8_t N, WebGLUniformLocation* loc,
845
                     const Uint32Arr& arr, GLuint elemOffset, GLuint elemCountOverride);
846
847
    void UniformMatrixAxBfv(const char* funcName, uint8_t A, uint8_t B,
848
                            WebGLUniformLocation* loc, bool transpose,
849
                            const Float32Arr& arr, GLuint elemOffset,
850
                            GLuint elemCountOverride);
851
852
    ////////////////
853
854
public:
855
    #define FOO(N) \
856
        void Uniform ## N ## fv(WebGLUniformLocation* loc, const Float32ListU& list,  \
857
                                GLuint elemOffset = 0, GLuint elemCountOverride = 0)  \
858
0
        {                                                                             \
859
0
            UniformNfv("uniform" #N "fv", N, loc, Float32Arr::From(list), elemOffset, \
860
0
                       elemCountOverride);                                            \
861
0
        }
Unexecuted instantiation: mozilla::WebGLContext::Uniform1fv(mozilla::WebGLUniformLocation*, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::Uniform2fv(mozilla::WebGLUniformLocation*, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::Uniform3fv(mozilla::WebGLUniformLocation*, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::Uniform4fv(mozilla::WebGLUniformLocation*, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
862
863
    FOO(1)
864
    FOO(2)
865
    FOO(3)
866
    FOO(4)
867
868
    #undef FOO
869
870
    //////
871
872
    #define FOO(N) \
873
        void Uniform ## N ## iv(WebGLUniformLocation* loc, const Int32ListU& list,   \
874
                                GLuint elemOffset = 0, GLuint elemCountOverride = 0) \
875
0
        {                                                                            \
876
0
            UniformNiv("uniform" #N "iv", N, loc, Int32Arr::From(list), elemOffset,  \
877
0
                       elemCountOverride);                                           \
878
0
        }
Unexecuted instantiation: mozilla::WebGLContext::Uniform1iv(mozilla::WebGLUniformLocation*, mozilla::dom::Int32ArrayOrLongSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::Uniform2iv(mozilla::WebGLUniformLocation*, mozilla::dom::Int32ArrayOrLongSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::Uniform3iv(mozilla::WebGLUniformLocation*, mozilla::dom::Int32ArrayOrLongSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::Uniform4iv(mozilla::WebGLUniformLocation*, mozilla::dom::Int32ArrayOrLongSequence const&, unsigned int, unsigned int)
879
880
    FOO(1)
881
    FOO(2)
882
    FOO(3)
883
    FOO(4)
884
885
    #undef FOO
886
887
    //////
888
889
    #define FOO(N) \
890
        void Uniform ## N ## uiv(WebGLUniformLocation* loc, const Uint32ListU& list,   \
891
                                 GLuint elemOffset = 0, GLuint elemCountOverride = 0)  \
892
0
        {                                                                              \
893
0
            UniformNuiv("uniform" #N "uiv", N, loc, Uint32Arr::From(list), elemOffset, \
894
0
                        elemCountOverride);                                            \
895
0
        }
Unexecuted instantiation: mozilla::WebGLContext::Uniform1uiv(mozilla::WebGLUniformLocation*, mozilla::dom::Uint32ArrayOrUnsignedLongSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::Uniform2uiv(mozilla::WebGLUniformLocation*, mozilla::dom::Uint32ArrayOrUnsignedLongSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::Uniform3uiv(mozilla::WebGLUniformLocation*, mozilla::dom::Uint32ArrayOrUnsignedLongSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::Uniform4uiv(mozilla::WebGLUniformLocation*, mozilla::dom::Uint32ArrayOrUnsignedLongSequence const&, unsigned int, unsigned int)
896
897
    FOO(1)
898
    FOO(2)
899
    FOO(3)
900
    FOO(4)
901
902
    #undef FOO
903
904
    //////
905
906
    #define FOO(X,A,B) \
907
        void UniformMatrix ## X ## fv(WebGLUniformLocation* loc, bool transpose,       \
908
                                      const Float32ListU& list, GLuint elemOffset = 0, \
909
                                      GLuint elemCountOverride = 0)                    \
910
0
        {                                                                              \
911
0
            UniformMatrixAxBfv("uniformMatrix" #X "fv", A, B, loc, transpose,          \
912
0
                               Float32Arr::From(list), elemOffset, elemCountOverride); \
913
0
        }
Unexecuted instantiation: mozilla::WebGLContext::UniformMatrix2fv(mozilla::WebGLUniformLocation*, bool, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::UniformMatrix3x2fv(mozilla::WebGLUniformLocation*, bool, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::UniformMatrix4x2fv(mozilla::WebGLUniformLocation*, bool, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::UniformMatrix2x3fv(mozilla::WebGLUniformLocation*, bool, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::UniformMatrix3fv(mozilla::WebGLUniformLocation*, bool, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::UniformMatrix4x3fv(mozilla::WebGLUniformLocation*, bool, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::UniformMatrix2x4fv(mozilla::WebGLUniformLocation*, bool, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::UniformMatrix3x4fv(mozilla::WebGLUniformLocation*, bool, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
Unexecuted instantiation: mozilla::WebGLContext::UniformMatrix4fv(mozilla::WebGLUniformLocation*, bool, mozilla::dom::Float32ArrayOrUnrestrictedFloatSequence const&, unsigned int, unsigned int)
914
915
    FOO(2,2,2)
916
    FOO(2x3,2,3)
917
    FOO(2x4,2,4)
918
919
    FOO(3x2,3,2)
920
    FOO(3,3,3)
921
    FOO(3x4,3,4)
922
923
    FOO(4x2,4,2)
924
    FOO(4x3,4,3)
925
    FOO(4,4,4)
926
927
    #undef FOO
928
929
    ////////////////////////////////////
930
931
    void UseProgram(WebGLProgram* prog);
932
933
    bool ValidateAttribArraySetter(uint32_t count, uint32_t arrayLength);
934
    bool ValidateUniformLocation(WebGLUniformLocation* loc);
935
    bool ValidateUniformSetter(WebGLUniformLocation* loc, uint8_t setterSize,
936
                               GLenum setterType);
937
    bool ValidateUniformArraySetter(WebGLUniformLocation* loc,
938
                                    uint8_t setterElemSize, GLenum setterType,
939
                                    uint32_t setterArraySize,
940
                                    uint32_t* out_numElementsToUpload);
941
    bool ValidateUniformMatrixArraySetter(WebGLUniformLocation* loc,
942
                                          uint8_t setterCols,
943
                                          uint8_t setterRows,
944
                                          GLenum setterType,
945
                                          uint32_t setterArraySize,
946
                                          bool setterTranspose,
947
                                          uint32_t* out_numElementsToUpload);
948
    void ValidateProgram(const WebGLProgram& prog);
949
    bool ValidateUniformLocation(const char* info, WebGLUniformLocation* loc);
950
    bool ValidateSamplerUniformSetter(const char* info,
951
                                      WebGLUniformLocation* loc, GLint value);
952
    void Viewport(GLint x, GLint y, GLsizei width, GLsizei height);
953
// -----------------------------------------------------------------------------
954
// WEBGL_lose_context
955
public:
956
    void LoseContext();
957
    void RestoreContext();
958
959
// -----------------------------------------------------------------------------
960
// Buffer Objects (WebGLContextBuffers.cpp)
961
    void BindBuffer(GLenum target, WebGLBuffer* buffer);
962
    void BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buf);
963
    void BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buf,
964
                         WebGLintptr offset, WebGLsizeiptr size);
965
966
private:
967
    void BufferDataImpl(GLenum target, size_t dataLen, const uint8_t* data, GLenum usage);
968
969
public:
970
    void BufferData(GLenum target, WebGLsizeiptr size, GLenum usage);
971
    void BufferData(GLenum target, const dom::Nullable<dom::ArrayBuffer>& maybeSrc,
972
                    GLenum usage);
973
    void BufferData(GLenum target, const dom::ArrayBufferView& srcData, GLenum usage,
974
                    GLuint srcElemOffset = 0, GLuint srcElemCountOverride = 0);
975
976
private:
977
    void BufferSubDataImpl(GLenum target, WebGLsizeiptr dstByteOffset,
978
                           size_t srcDataLen, const uint8_t* srcData);
979
980
public:
981
    void BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
982
                       const dom::ArrayBufferView& src, GLuint srcElemOffset = 0,
983
                       GLuint srcElemCountOverride = 0);
984
    void BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
985
                       const dom::ArrayBuffer& src);
986
    void BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
987
                       const dom::SharedArrayBuffer& src);
988
989
    already_AddRefed<WebGLBuffer> CreateBuffer();
990
    void DeleteBuffer(WebGLBuffer* buf);
991
992
protected:
993
    // bound buffer state
994
    WebGLRefPtr<WebGLBuffer> mBoundArrayBuffer;
995
    WebGLRefPtr<WebGLBuffer> mBoundCopyReadBuffer;
996
    WebGLRefPtr<WebGLBuffer> mBoundCopyWriteBuffer;
997
    WebGLRefPtr<WebGLBuffer> mBoundPixelPackBuffer;
998
    WebGLRefPtr<WebGLBuffer> mBoundPixelUnpackBuffer;
999
    WebGLRefPtr<WebGLBuffer> mBoundTransformFeedbackBuffer;
1000
    WebGLRefPtr<WebGLBuffer> mBoundUniformBuffer;
1001
1002
    std::vector<IndexedBufferBinding> mIndexedUniformBufferBindings;
1003
1004
    WebGLRefPtr<WebGLBuffer>& GetBufferSlotByTarget(GLenum target);
1005
    WebGLRefPtr<WebGLBuffer>& GetBufferSlotByTargetIndexed(GLenum target,
1006
                                                           GLuint index);
1007
1008
// -----------------------------------------------------------------------------
1009
// Queries (WebGL2ContextQueries.cpp)
1010
protected:
1011
    WebGLRefPtr<WebGLQuery> mQuerySlot_SamplesPassed;
1012
    WebGLRefPtr<WebGLQuery> mQuerySlot_TFPrimsWritten;
1013
    WebGLRefPtr<WebGLQuery> mQuerySlot_TimeElapsed;
1014
1015
    WebGLRefPtr<WebGLQuery>*
1016
    ValidateQuerySlotByTarget(GLenum target);
1017
1018
public:
1019
    already_AddRefed<WebGLQuery> CreateQuery();
1020
    void DeleteQuery(WebGLQuery* query);
1021
    bool IsQuery(const WebGLQuery* query);
1022
    void BeginQuery(GLenum target, WebGLQuery& query);
1023
    void EndQuery(GLenum target);
1024
    void GetQuery(JSContext* cx, GLenum target, GLenum pname,
1025
                  JS::MutableHandleValue retval);
1026
    void GetQueryParameter(JSContext* cx, const WebGLQuery& query, GLenum pname,
1027
                           JS::MutableHandleValue retval);
1028
1029
1030
// -----------------------------------------------------------------------------
1031
// State and State Requests (WebGLContextState.cpp)
1032
private:
1033
    void SetEnabled(const char* funcName, GLenum cap, bool enabled);
1034
public:
1035
0
    void Disable(GLenum cap) { SetEnabled("disabled", cap, false); }
1036
0
    void Enable(GLenum cap) { SetEnabled("enabled", cap, true); }
1037
    bool GetStencilBits(GLint* const out_stencilBits) const;
1038
    virtual JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv);
1039
1040
    void GetParameter(JSContext* cx, GLenum pname,
1041
                      JS::MutableHandle<JS::Value> retval, ErrorResult& rv)
1042
0
    {
1043
0
        retval.set(GetParameter(cx, pname, rv));
1044
0
    }
1045
1046
    void GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index,
1047
                             JS::MutableHandle<JS::Value> retval);
1048
    bool IsEnabled(GLenum cap);
1049
1050
private:
1051
    // State tracking slots
1052
    realGLboolean mDitherEnabled;
1053
    realGLboolean mRasterizerDiscardEnabled;
1054
    realGLboolean mScissorTestEnabled;
1055
    realGLboolean mDepthTestEnabled = 0;
1056
    realGLboolean mStencilTestEnabled;
1057
    GLenum mGenerateMipmapHint = 0;
1058
1059
    bool ValidateCapabilityEnum(GLenum cap);
1060
    realGLboolean* GetStateTrackingSlot(GLenum cap);
1061
1062
    // Allocation debugging variables
1063
    mutable uint64_t mDataAllocGLCallCount;
1064
1065
0
    void OnDataAllocCall() const {
1066
0
       mDataAllocGLCallCount++;
1067
0
    }
1068
1069
0
    uint64_t GetNumGLDataAllocCalls() const {
1070
0
       return mDataAllocGLCallCount;
1071
0
    }
1072
1073
    void OnEndOfFrame() const;
1074
1075
// -----------------------------------------------------------------------------
1076
// Texture funcions (WebGLContextTextures.cpp)
1077
public:
1078
    void ActiveTexture(GLenum texUnit);
1079
    void BindTexture(GLenum texTarget, WebGLTexture* tex);
1080
    already_AddRefed<WebGLTexture> CreateTexture();
1081
    void DeleteTexture(WebGLTexture* tex);
1082
    void GenerateMipmap(GLenum texTarget);
1083
1084
    void GetTexParameter(JSContext*, GLenum texTarget, GLenum pname,
1085
                         JS::MutableHandle<JS::Value> retval)
1086
0
    {
1087
0
        retval.set(GetTexParameter(texTarget, pname));
1088
0
    }
1089
1090
0
    void TexParameterf(GLenum texTarget, GLenum pname, GLfloat param) {
1091
0
        TexParameter_base(texTarget, pname, FloatOrInt(param));
1092
0
    }
1093
1094
0
    void TexParameteri(GLenum texTarget, GLenum pname, GLint param) {
1095
0
        TexParameter_base(texTarget, pname, FloatOrInt(param));
1096
0
    }
1097
1098
protected:
1099
    JS::Value GetTexParameter(GLenum texTarget, GLenum pname);
1100
    void TexParameter_base(GLenum texTarget, GLenum pname, const FloatOrInt& param);
1101
1102
    virtual bool IsTexParamValid(GLenum pname) const;
1103
1104
    ////////////////////////////////////
1105
1106
public:
1107
    void CompressedTexImage2D(GLenum target, GLint level, GLenum internalFormat,
1108
                              GLsizei width, GLsizei height, GLint border,
1109
                              GLsizei imageSize, WebGLsizeiptr offset)
1110
0
    {
1111
0
        const FuncScope funcScope(*this, "compressedTexImage2D");
1112
0
        const uint8_t funcDims = 2;
1113
0
        const GLsizei depth = 1;
1114
0
        const TexImageSourceAdapter src(&offset, 0, 0);
1115
0
        CompressedTexImage(funcDims, target, level, internalFormat, width,
1116
0
                           height, depth, border, src, Some(imageSize));
1117
0
    }
1118
1119
    template<typename T>
1120
    void CompressedTexImage2D(GLenum target, GLint level, GLenum internalFormat,
1121
                              GLsizei width, GLsizei height, GLint border,
1122
                              const T& anySrc, GLuint viewElemOffset = 0,
1123
                              GLuint viewElemLengthOverride = 0)
1124
0
    {
1125
0
        const FuncScope funcScope(*this, "compressedTexImage2D");
1126
0
        const uint8_t funcDims = 2;
1127
0
        const GLsizei depth = 1;
1128
0
        const TexImageSourceAdapter src(&anySrc, viewElemOffset, viewElemLengthOverride);
1129
0
        CompressedTexImage(funcDims, target, level, internalFormat, width,
1130
0
                           height, depth, border, src, Nothing());
1131
0
    }
1132
1133
    void CompressedTexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
1134
                                 GLsizei width, GLsizei height, GLenum unpackFormat,
1135
                                 GLsizei imageSize, WebGLsizeiptr offset)
1136
0
    {
1137
0
        const FuncScope funcScope(*this, "compressedTexSubImage2D");
1138
0
        const uint8_t funcDims = 2;
1139
0
        const GLint zOffset = 0;
1140
0
        const GLsizei depth = 1;
1141
0
        const TexImageSourceAdapter src(&offset, 0, 0);
1142
0
        CompressedTexSubImage(funcDims, target, level, xOffset, yOffset,
1143
0
                              zOffset, width, height, depth, unpackFormat, src, Some(imageSize));
1144
0
    }
1145
1146
    template<typename T>
1147
    void CompressedTexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
1148
                                 GLsizei width, GLsizei height, GLenum unpackFormat,
1149
                                 const T& anySrc, GLuint viewElemOffset = 0,
1150
                                 GLuint viewElemLengthOverride = 0)
1151
0
    {
1152
0
        const FuncScope funcScope(*this, "compressedTexSubImage2D");
1153
0
        const uint8_t funcDims = 2;
1154
0
        const GLint zOffset = 0;
1155
0
        const GLsizei depth = 1;
1156
0
        const TexImageSourceAdapter src(&anySrc, viewElemOffset, viewElemLengthOverride);
1157
0
        CompressedTexSubImage(funcDims, target, level, xOffset, yOffset,
1158
0
                              zOffset, width, height, depth, unpackFormat, src, Nothing());
1159
0
    }
1160
1161
protected:
1162
    void CompressedTexImage(uint8_t funcDims, GLenum target,
1163
                            GLint level, GLenum internalFormat, GLsizei width,
1164
                            GLsizei height, GLsizei depth, GLint border,
1165
                            const TexImageSource& src, const Maybe<GLsizei>& expectedImageSize);
1166
    void CompressedTexSubImage(uint8_t funcDims, GLenum target,
1167
                               GLint level, GLint xOffset, GLint yOffset, GLint zOffset,
1168
                               GLsizei width, GLsizei height, GLsizei depth,
1169
                               GLenum unpackFormat, const TexImageSource& src,
1170
                               const Maybe<GLsizei>& expectedImageSize);
1171
1172
    ////////////////////////////////////
1173
1174
public:
1175
    void CopyTexImage2D(GLenum target, GLint level, GLenum internalFormat, GLint x,
1176
                        GLint y, GLsizei width, GLsizei height, GLint border);
1177
1178
    void CopyTexSubImage2D(GLenum target, GLint level, GLint xOffset,
1179
                           GLint yOffset, GLint x, GLint y, GLsizei width,
1180
                           GLsizei height)
1181
0
    {
1182
0
        const FuncScope funcScope(*this, "copyTexSubImage2D");
1183
0
        const uint8_t funcDims = 2;
1184
0
        const GLint zOffset = 0;
1185
0
        CopyTexSubImage(funcDims, target, level, xOffset, yOffset, zOffset,
1186
0
                        x, y, width, height);
1187
0
    }
1188
1189
protected:
1190
    void CopyTexSubImage(uint8_t funcDims, GLenum target,
1191
                         GLint level, GLint xOffset, GLint yOffset, GLint zOffset,
1192
                         GLint x, GLint y, GLsizei width, GLsizei height);
1193
1194
    ////////////////////////////////////
1195
    // TexImage
1196
1197
    // Implicit width/height uploads
1198
1199
public:
1200
    template<typename T>
1201
    void TexImage2D(GLenum target, GLint level, GLenum internalFormat,
1202
                    GLenum unpackFormat, GLenum unpackType, const T& src,
1203
                    ErrorResult& out_error)
1204
0
    {
1205
0
        GLsizei width = 0;
1206
0
        GLsizei height = 0;
1207
0
        GLint border = 0;
1208
0
        TexImage2D(target, level, internalFormat, width, height, border, unpackFormat,
1209
0
                   unpackType, src, out_error);
1210
0
    }
Unexecuted instantiation: void mozilla::WebGLContext::TexImage2D<mozilla::dom::HTMLCanvasElement>(unsigned int, int, unsigned int, unsigned int, unsigned int, mozilla::dom::HTMLCanvasElement const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexImage2D<mozilla::dom::HTMLImageElement>(unsigned int, int, unsigned int, unsigned int, unsigned int, mozilla::dom::HTMLImageElement const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexImage2D<mozilla::dom::HTMLVideoElement>(unsigned int, int, unsigned int, unsigned int, unsigned int, mozilla::dom::HTMLVideoElement const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexImage2D<mozilla::dom::ImageBitmap>(unsigned int, int, unsigned int, unsigned int, unsigned int, mozilla::dom::ImageBitmap const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexImage2D<mozilla::dom::ImageData>(unsigned int, int, unsigned int, unsigned int, unsigned int, mozilla::dom::ImageData const&, mozilla::ErrorResult&)
1211
1212
    template<typename T>
1213
    void TexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
1214
                       GLenum unpackFormat, GLenum unpackType, const T& src,
1215
                       ErrorResult& out_error)
1216
0
    {
1217
0
        GLsizei width = 0;
1218
0
        GLsizei height = 0;
1219
0
        TexSubImage2D(target, level, xOffset, yOffset, width, height, unpackFormat,
1220
0
                      unpackType, src, out_error);
1221
0
    }
Unexecuted instantiation: void mozilla::WebGLContext::TexSubImage2D<mozilla::dom::HTMLCanvasElement>(unsigned int, int, int, int, unsigned int, unsigned int, mozilla::dom::HTMLCanvasElement const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexSubImage2D<mozilla::dom::HTMLImageElement>(unsigned int, int, int, int, unsigned int, unsigned int, mozilla::dom::HTMLImageElement const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexSubImage2D<mozilla::dom::HTMLVideoElement>(unsigned int, int, int, int, unsigned int, unsigned int, mozilla::dom::HTMLVideoElement const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexSubImage2D<mozilla::dom::ImageBitmap>(unsigned int, int, int, int, unsigned int, unsigned int, mozilla::dom::ImageBitmap const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexSubImage2D<mozilla::dom::ImageData>(unsigned int, int, int, int, unsigned int, unsigned int, mozilla::dom::ImageData const&, mozilla::ErrorResult&)
1222
1223
    ////
1224
1225
    template<typename T>
1226
    void TexImage2D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
1227
                    GLsizei height, GLint border, GLenum unpackFormat, GLenum unpackType,
1228
                    const T& anySrc, ErrorResult& out_error)
1229
0
    {
1230
0
        const TexImageSourceAdapter src(&anySrc, &out_error);
1231
0
        TexImage2D(target, level, internalFormat, width, height, border, unpackFormat,
1232
0
                   unpackType, src);
1233
0
    }
Unexecuted instantiation: void mozilla::WebGLContext::TexImage2D<mozilla::dom::RootedSpiderMonkeyInterface<mozilla::dom::Nullable<mozilla::dom::ArrayBufferView_base<&js::UnwrapArrayBufferView, &js::GetArrayBufferViewLengthAndData, &(JS_GetArrayBufferViewType(JSObject*))> > > >(unsigned int, int, unsigned int, int, int, int, unsigned int, unsigned int, mozilla::dom::RootedSpiderMonkeyInterface<mozilla::dom::Nullable<mozilla::dom::ArrayBufferView_base<&js::UnwrapArrayBufferView, &js::GetArrayBufferViewLengthAndData, &(JS_GetArrayBufferViewType(JSObject*))> > > const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexImage2D<mozilla::dom::HTMLCanvasElement>(unsigned int, int, unsigned int, int, int, int, unsigned int, unsigned int, mozilla::dom::HTMLCanvasElement const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexImage2D<mozilla::dom::HTMLImageElement>(unsigned int, int, unsigned int, int, int, int, unsigned int, unsigned int, mozilla::dom::HTMLImageElement const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexImage2D<mozilla::dom::HTMLVideoElement>(unsigned int, int, unsigned int, int, int, int, unsigned int, unsigned int, mozilla::dom::HTMLVideoElement const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexImage2D<mozilla::dom::ImageBitmap>(unsigned int, int, unsigned int, int, int, int, unsigned int, unsigned int, mozilla::dom::ImageBitmap const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexImage2D<mozilla::dom::ImageData>(unsigned int, int, unsigned int, int, int, int, unsigned int, unsigned int, mozilla::dom::ImageData const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexImage2D<long>(unsigned int, int, unsigned int, int, int, int, unsigned int, unsigned int, long const&, mozilla::ErrorResult&)
1234
1235
    void TexImage2D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
1236
                    GLsizei height, GLint border, GLenum unpackFormat, GLenum unpackType,
1237
                    const dom::ArrayBufferView& view, GLuint viewElemOffset,
1238
                    ErrorResult&)
1239
0
    {
1240
0
        const TexImageSourceAdapter src(&view, viewElemOffset);
1241
0
        TexImage2D(target, level, internalFormat, width, height, border, unpackFormat,
1242
0
                   unpackType, src);
1243
0
    }
1244
1245
protected:
1246
    void TexImage2D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
1247
                    GLsizei height, GLint border, GLenum unpackFormat,
1248
                    GLenum unpackType, const TexImageSource& src)
1249
0
    {
1250
0
        const FuncScope funcScope(*this, "texImage2D");
1251
0
        const uint8_t funcDims = 2;
1252
0
        const GLsizei depth = 1;
1253
0
        TexImage(funcDims, target, level, internalFormat, width, height, depth,
1254
0
                 border, unpackFormat, unpackType, src);
1255
0
    }
1256
1257
    void TexImage(uint8_t funcDims, GLenum target, GLint level,
1258
                  GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth,
1259
                  GLint border, GLenum unpackFormat, GLenum unpackType,
1260
                  const TexImageSource& src);
1261
1262
    ////
1263
1264
public:
1265
    template<typename T>
1266
    void TexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
1267
                       GLsizei width, GLsizei height, GLenum unpackFormat,
1268
                       GLenum unpackType, const T& anySrc, ErrorResult& out_error)
1269
0
    {
1270
0
        const TexImageSourceAdapter src(&anySrc, &out_error);
1271
0
        TexSubImage2D(target, level, xOffset, yOffset, width, height, unpackFormat,
1272
0
                      unpackType, src);
1273
0
    }
Unexecuted instantiation: void mozilla::WebGLContext::TexSubImage2D<mozilla::dom::RootedSpiderMonkeyInterface<mozilla::dom::Nullable<mozilla::dom::ArrayBufferView_base<&js::UnwrapArrayBufferView, &js::GetArrayBufferViewLengthAndData, &(JS_GetArrayBufferViewType(JSObject*))> > > >(unsigned int, int, int, int, int, int, unsigned int, unsigned int, mozilla::dom::RootedSpiderMonkeyInterface<mozilla::dom::Nullable<mozilla::dom::ArrayBufferView_base<&js::UnwrapArrayBufferView, &js::GetArrayBufferViewLengthAndData, &(JS_GetArrayBufferViewType(JSObject*))> > > const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexSubImage2D<mozilla::dom::HTMLCanvasElement>(unsigned int, int, int, int, int, int, unsigned int, unsigned int, mozilla::dom::HTMLCanvasElement const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexSubImage2D<mozilla::dom::HTMLImageElement>(unsigned int, int, int, int, int, int, unsigned int, unsigned int, mozilla::dom::HTMLImageElement const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexSubImage2D<mozilla::dom::HTMLVideoElement>(unsigned int, int, int, int, int, int, unsigned int, unsigned int, mozilla::dom::HTMLVideoElement const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexSubImage2D<mozilla::dom::ImageBitmap>(unsigned int, int, int, int, int, int, unsigned int, unsigned int, mozilla::dom::ImageBitmap const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexSubImage2D<mozilla::dom::ImageData>(unsigned int, int, int, int, int, int, unsigned int, unsigned int, mozilla::dom::ImageData const&, mozilla::ErrorResult&)
Unexecuted instantiation: void mozilla::WebGLContext::TexSubImage2D<long>(unsigned int, int, int, int, int, int, unsigned int, unsigned int, long const&, mozilla::ErrorResult&)
1274
1275
    void TexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
1276
                       GLsizei width, GLsizei height, GLenum unpackFormat,
1277
                       GLenum unpackType, const dom::ArrayBufferView& view,
1278
                       GLuint viewElemOffset, ErrorResult&)
1279
0
    {
1280
0
        const TexImageSourceAdapter src(&view, viewElemOffset);
1281
0
        TexSubImage2D(target, level, xOffset, yOffset, width, height, unpackFormat,
1282
0
                      unpackType, src);
1283
0
    }
1284
1285
protected:
1286
    void TexSubImage2D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
1287
                       GLsizei width, GLsizei height, GLenum unpackFormat,
1288
                       GLenum unpackType, const TexImageSource& src)
1289
0
    {
1290
0
        const FuncScope funcScope(*this, "texSubImage2D");
1291
0
        const uint8_t funcDims = 2;
1292
0
        const GLint zOffset = 0;
1293
0
        const GLsizei depth = 1;
1294
0
        TexSubImage(funcDims, target, level, xOffset, yOffset, zOffset, width,
1295
0
                    height, depth, unpackFormat, unpackType, src);
1296
0
    }
1297
1298
    void TexSubImage(uint8_t funcDims, GLenum target, GLint level,
1299
                     GLint xOffset, GLint yOffset, GLint zOffset, GLsizei width,
1300
                     GLsizei height, GLsizei depth, GLenum unpackFormat,
1301
                     GLenum unpackType, const TexImageSource& src);
1302
1303
    ////////////////////////////////////
1304
    // WebGLTextureUpload.cpp
1305
public:
1306
    UniquePtr<webgl::TexUnpackBlob>
1307
    From(TexImageTarget target, GLsizei rawWidth, GLsizei rawHeight,
1308
         GLsizei rawDepth, GLint border, const TexImageSource& src,
1309
         dom::Uint8ClampedArray* const scopedArr);
1310
1311
protected:
1312
    bool ValidateTexImageSpecification(uint8_t funcDims,
1313
                                       GLenum texImageTarget, GLint level,
1314
                                       GLsizei width, GLsizei height, GLsizei depth,
1315
                                       GLint border,
1316
                                       TexImageTarget* const out_target,
1317
                                       WebGLTexture** const out_texture,
1318
                                       WebGLTexture::ImageInfo** const out_imageInfo);
1319
    bool ValidateTexImageSelection(uint8_t funcDims,
1320
                                   GLenum texImageTarget, GLint level, GLint xOffset,
1321
                                   GLint yOffset, GLint zOffset, GLsizei width,
1322
                                   GLsizei height, GLsizei depth,
1323
                                   TexImageTarget* const out_target,
1324
                                   WebGLTexture** const out_texture,
1325
                                   WebGLTexture::ImageInfo** const out_imageInfo);
1326
    bool ValidateUnpackInfo(bool usePBOs, GLenum format,
1327
                            GLenum type, webgl::PackingInfo* const out);
1328
1329
    UniquePtr<webgl::TexUnpackBlob>
1330
    FromDomElem(TexImageTarget target, uint32_t width,
1331
                uint32_t height, uint32_t depth, const dom::Element& elem,
1332
                ErrorResult* const out_error);
1333
1334
    UniquePtr<webgl::TexUnpackBytes>
1335
    FromCompressed(TexImageTarget target, GLsizei rawWidth,
1336
                   GLsizei rawHeight, GLsizei rawDepth, GLint border,
1337
                   const TexImageSource& src, const Maybe<GLsizei>& expectedImageSize);
1338
1339
// -----------------------------------------------------------------------------
1340
// Vertices Feature (WebGLContextVertices.cpp)
1341
    GLenum mPrimRestartTypeBytes = 0;
1342
1343
public:
1344
0
    void DrawArrays(GLenum mode, GLint first, GLsizei count) {
1345
0
        const FuncScope funcScope(*this, "drawArrays");
1346
0
        DrawArraysInstanced(mode, first, count, 1);
1347
0
    }
1348
1349
    void DrawElements(GLenum mode, GLsizei count, GLenum type,
1350
                      WebGLintptr byteOffset)
1351
0
    {
1352
0
        const FuncScope funcScope(*this, "drawElements");
1353
0
        DrawElementsInstanced(mode, count, type, byteOffset, 1);
1354
0
    }
1355
1356
    void DrawArraysInstanced(GLenum mode, GLint first, GLsizei vertexCount,
1357
                             GLsizei instanceCount);
1358
    void DrawElementsInstanced(GLenum mode, GLsizei vertexCount, GLenum type,
1359
                               WebGLintptr byteOffset, GLsizei instanceCount);
1360
1361
    void EnableVertexAttribArray(GLuint index);
1362
    void DisableVertexAttribArray(GLuint index);
1363
1364
    JS::Value GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
1365
                              ErrorResult& rv);
1366
1367
    void GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
1368
                         JS::MutableHandle<JS::Value> retval, ErrorResult& rv)
1369
0
    {
1370
0
        retval.set(GetVertexAttrib(cx, index, pname, rv));
1371
0
    }
1372
1373
    WebGLsizeiptr GetVertexAttribOffset(GLuint index, GLenum pname);
1374
1375
    ////
1376
1377
    void VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
1378
1379
    ////
1380
1381
0
    void VertexAttrib1f(GLuint index, GLfloat x) {
1382
0
        const FuncScope funcScope(*this, "vertexAttrib1f");
1383
0
        VertexAttrib4f(index, x, 0, 0, 1);
1384
0
    }
1385
0
    void VertexAttrib2f(GLuint index, GLfloat x, GLfloat y) {
1386
0
        const FuncScope funcScope(*this, "vertexAttrib2f");
1387
0
        VertexAttrib4f(index, x, y, 0, 1);
1388
0
    }
1389
0
    void VertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) {
1390
0
        const FuncScope funcScope(*this, "vertexAttrib3f");
1391
0
        VertexAttrib4f(index, x, y, z, 1);
1392
0
    }
1393
1394
    ////
1395
1396
0
    void VertexAttrib1fv(GLuint index, const Float32ListU& list) {
1397
0
        const FuncScope funcScope(*this, "vertexAttrib1fv");
1398
0
        const auto& arr = Float32Arr::From(list);
1399
0
        if (!ValidateAttribArraySetter(1, arr.elemCount))
1400
0
            return;
1401
0
1402
0
        VertexAttrib4f(index, arr.elemBytes[0], 0, 0, 1);
1403
0
    }
1404
1405
0
    void VertexAttrib2fv(GLuint index, const Float32ListU& list) {
1406
0
        const FuncScope funcScope(*this, "vertexAttrib2fv");
1407
0
        const auto& arr = Float32Arr::From(list);
1408
0
        if (!ValidateAttribArraySetter(2, arr.elemCount))
1409
0
            return;
1410
0
1411
0
        VertexAttrib4f(index, arr.elemBytes[0], arr.elemBytes[1], 0, 1);
1412
0
    }
1413
1414
0
    void VertexAttrib3fv(GLuint index, const Float32ListU& list) {
1415
0
        const FuncScope funcScope(*this, "vertexAttrib3fv");
1416
0
        const auto& arr = Float32Arr::From(list);
1417
0
        if (!ValidateAttribArraySetter(3, arr.elemCount))
1418
0
            return;
1419
0
1420
0
        VertexAttrib4f(index, arr.elemBytes[0], arr.elemBytes[1], arr.elemBytes[2], 1);
1421
0
    }
1422
1423
0
    void VertexAttrib4fv(GLuint index, const Float32ListU& list) {
1424
0
        const FuncScope funcScope(*this, "vertexAttrib4fv");
1425
0
        const auto& arr = Float32Arr::From(list);
1426
0
        if (!ValidateAttribArraySetter(4, arr.elemCount))
1427
0
            return;
1428
0
1429
0
        VertexAttrib4f(index, arr.elemBytes[0], arr.elemBytes[1], arr.elemBytes[2],
1430
0
                       arr.elemBytes[3]);
1431
0
    }
1432
1433
    ////
1434
1435
protected:
1436
    void VertexAttribAnyPointer(bool isFuncInt, GLuint index,
1437
                                GLint size, GLenum type, bool normalized, GLsizei stride,
1438
                                WebGLintptr byteOffset);
1439
1440
public:
1441
    void VertexAttribPointer(GLuint index, GLint size, GLenum type,
1442
                             WebGLboolean normalized, GLsizei stride,
1443
                             WebGLintptr byteOffset)
1444
0
    {
1445
0
        const FuncScope funcScope(*this, "vertexAttribPointer");
1446
0
        const bool isFuncInt = false;
1447
0
        VertexAttribAnyPointer(isFuncInt, index, size, type, normalized, stride,
1448
0
                               byteOffset);
1449
0
    }
1450
1451
    void VertexAttribDivisor(GLuint index, GLuint divisor);
1452
1453
private:
1454
    WebGLBuffer* DrawElements_check(GLsizei indexCount, GLenum type,
1455
                                    WebGLintptr byteOffset, GLsizei instanceCount);
1456
    void Draw_cleanup();
1457
1458
    void VertexAttrib1fv_base(GLuint index, uint32_t arrayLength,
1459
                              const GLfloat* ptr);
1460
    void VertexAttrib2fv_base(GLuint index, uint32_t arrayLength,
1461
                              const GLfloat* ptr);
1462
    void VertexAttrib3fv_base(GLuint index, uint32_t arrayLength,
1463
                              const GLfloat* ptr);
1464
    void VertexAttrib4fv_base(GLuint index, uint32_t arrayLength,
1465
                              const GLfloat* ptr);
1466
1467
    bool BindArrayAttribToLocation0(WebGLProgram* prog);
1468
1469
// -----------------------------------------------------------------------------
1470
// PROTECTED
1471
protected:
1472
    WebGLVertexAttrib0Status WhatDoesVertexAttrib0Need() const;
1473
    bool DoFakeVertexAttrib0(uint64_t vertexCount);
1474
    void UndoFakeVertexAttrib0();
1475
1476
    CheckedUint32 mGeneration;
1477
1478
    WebGLContextOptions mOptions;
1479
1480
    bool mInvalidated;
1481
    bool mCapturedFrameInvalidated;
1482
    bool mResetLayer;
1483
    bool mOptionsFrozen;
1484
    bool mDisableExtensions;
1485
    bool mIsMesa;
1486
    bool mLoseContextOnMemoryPressure;
1487
    bool mCanLoseContextInForeground;
1488
    bool mRestoreWhenVisible;
1489
    bool mShouldPresent;
1490
    bool mDisableFragHighP;
1491
1492
    template<typename WebGLObjectType>
1493
    void DeleteWebGLObjectsArray(nsTArray<WebGLObjectType>& array);
1494
1495
    GLuint mActiveTexture = 0;
1496
    GLenum mDefaultFB_DrawBuffer0 = 0;
1497
    GLenum mDefaultFB_ReadBuffer = 0;
1498
1499
    // glGetError sources:
1500
    bool mEmitContextLostErrorOnce;
1501
    mutable GLenum mWebGLError;
1502
    mutable GLenum mUnderlyingGLError;
1503
    GLenum GetAndFlushUnderlyingGLErrors() const;
1504
1505
    bool mBypassShaderValidation;
1506
1507
    webgl::ShaderValidator* CreateShaderValidator(GLenum shaderType) const;
1508
1509
    // some GL constants
1510
    uint32_t mGLMaxTextureUnits = 0;
1511
1512
    uint32_t mGLMaxVertexAttribs = 0;
1513
    uint32_t mGLMaxFragmentUniformVectors = 0;
1514
    uint32_t mGLMaxVertexUniformVectors = 0;
1515
    uint32_t mGLMaxVaryingVectors = 0;
1516
1517
    uint32_t mGLMaxTransformFeedbackSeparateAttribs = 0;
1518
    uint32_t mGLMaxUniformBufferBindings = 0;
1519
1520
    uint32_t mGLMaxVertexTextureImageUnits = 0;
1521
    uint32_t mGLMaxFragmentTextureImageUnits = 0;
1522
    uint32_t mGLMaxCombinedTextureImageUnits = 0;
1523
1524
    uint32_t mGLMaxColorAttachments = 0;
1525
    uint32_t mGLMaxDrawBuffers = 0;
1526
1527
    uint32_t mGLMaxViewportDims[2];
1528
1529
public:
1530
0
    GLenum LastColorAttachmentEnum() const {
1531
0
        return LOCAL_GL_COLOR_ATTACHMENT0 + mGLMaxColorAttachments - 1;
1532
0
    }
1533
1534
0
    const decltype(mOptions)& Options() const { return mOptions; }
1535
1536
protected:
1537
1538
    // Texture sizes are often not actually the GL values. Let's be explicit that these
1539
    // are implementation limits.
1540
    uint32_t mGLMaxTextureSize = 0;
1541
    uint32_t mGLMaxCubeMapTextureSize = 0;
1542
    uint32_t mGLMax3DTextureSize = 0;
1543
    uint32_t mGLMaxArrayTextureLayers = 0;
1544
    uint32_t mGLMaxRenderbufferSize = 0;
1545
1546
public:
1547
0
    GLuint MaxVertexAttribs() const {
1548
0
        return mGLMaxVertexAttribs;
1549
0
    }
1550
1551
0
    GLuint GLMaxTextureUnits() const {
1552
0
        return mGLMaxTextureUnits;
1553
0
    }
1554
1555
    float mGLAliasedLineWidthRange[2];
1556
    float mGLAliasedPointSizeRange[2];
1557
1558
    bool IsFormatValidForFB(TexInternalFormat format) const;
1559
1560
protected:
1561
    // Represents current status of the context with respect to context loss.
1562
    // That is, whether the context is lost, and what part of the context loss
1563
    // process we currently are at.
1564
    // This is used to support the WebGL spec's asyncronous nature in handling
1565
    // context loss.
1566
    enum class ContextStatus {
1567
        // The context is stable; there either are none or we don't know of any.
1568
        NotLost,
1569
        // The context has been lost, but we have not yet sent an event to the
1570
        // script informing it of this.
1571
        LostAwaitingEvent,
1572
        // The context has been lost, and we have sent the script an event
1573
        // informing it of this.
1574
        Lost,
1575
        // The context is lost, an event has been sent to the script, and the
1576
        // script correctly handled the event. We are waiting for the context to
1577
        // be restored.
1578
        LostAwaitingRestore
1579
    };
1580
1581
    // -------------------------------------------------------------------------
1582
    // WebGL extensions (implemented in WebGLContextExtensions.cpp)
1583
    typedef EnumeratedArray<WebGLExtensionID, WebGLExtensionID::Max,
1584
                            RefPtr<WebGLExtensionBase>> ExtensionsArrayType;
1585
1586
    ExtensionsArrayType mExtensions;
1587
1588
    // enable an extension. the extension should not be enabled before.
1589
    void EnableExtension(WebGLExtensionID ext);
1590
1591
    // Enable an extension if it's supported. Return the extension on success.
1592
    WebGLExtensionBase* EnableSupportedExtension(dom::CallerType callerType,
1593
                                                 WebGLExtensionID ext);
1594
1595
public:
1596
    // returns true if the extension has been enabled by calling getExtension.
1597
    bool IsExtensionEnabled(WebGLExtensionID ext) const;
1598
1599
protected:
1600
    // returns true if the extension is supported for this caller type (this decides what getSupportedExtensions exposes)
1601
    bool IsExtensionSupported(dom::CallerType callerType,
1602
                              WebGLExtensionID ext) const;
1603
    bool IsExtensionSupported(WebGLExtensionID ext) const;
1604
1605
    static const char* GetExtensionString(WebGLExtensionID ext);
1606
1607
    nsTArray<GLenum> mCompressedTextureFormats;
1608
1609
    // -------------------------------------------------------------------------
1610
    // WebGL 2 specifics (implemented in WebGL2Context.cpp)
1611
public:
1612
    virtual bool IsWebGL2() const = 0;
1613
1614
    struct FailureReason {
1615
        nsCString key; // For reporting.
1616
        nsCString info;
1617
1618
0
        FailureReason() { }
1619
1620
        template<typename A, typename B>
1621
        FailureReason(const A& _key, const B& _info)
1622
            : key(nsCString(_key))
1623
            , info(nsCString(_info))
1624
0
        { }
Unexecuted instantiation: mozilla::WebGLContext::FailureReason::FailureReason<char [28], nsPrintfCString>(char const (&) [28], nsPrintfCString const&)
Unexecuted instantiation: mozilla::WebGLContext::FailureReason::FailureReason<nsTString<char>, char const*>(nsTString<char> const&, char const* const&)
Unexecuted instantiation: mozilla::WebGLContext::FailureReason::FailureReason<char [40], char [29]>(char const (&) [40], char const (&) [29])
Unexecuted instantiation: mozilla::WebGLContext::FailureReason::FailureReason<char [29], char [31]>(char const (&) [29], char const (&) [31])
Unexecuted instantiation: mozilla::WebGLContext::FailureReason::FailureReason<char [30], nsPrintfCString>(char const (&) [30], nsPrintfCString const&)
Unexecuted instantiation: mozilla::WebGLContext::FailureReason::FailureReason<char [29], nsPrintfCString>(char const (&) [29], nsPrintfCString const&)
Unexecuted instantiation: mozilla::WebGLContext::FailureReason::FailureReason<char [27], char [39]>(char const (&) [27], char const (&) [39])
Unexecuted instantiation: mozilla::WebGLContext::FailureReason::FailureReason<char [27], char [30]>(char const (&) [27], char const (&) [30])
1625
    };
1626
protected:
1627
    bool InitWebGL2(FailureReason* const out_failReason);
1628
1629
    bool CreateAndInitGL(bool forceEnabled,
1630
                         std::vector<FailureReason>* const out_failReasons);
1631
1632
    void ThrowEvent_WebGLContextCreationError(const nsACString& text);
1633
1634
    // -------------------------------------------------------------------------
1635
    // Validation functions (implemented in WebGLContextValidate.cpp)
1636
    bool InitAndValidateGL(FailureReason* const out_failReason);
1637
1638
    bool ValidateBlendEquationEnum(GLenum cap, const char* info);
1639
    bool ValidateBlendFuncEnumsCompatibility(GLenum sfactor, GLenum dfactor,
1640
                                             const char* info);
1641
    bool ValidateStencilOpEnum(GLenum action, const char* info);
1642
    bool ValidateFaceEnum(GLenum face);
1643
    bool ValidateTexInputData(GLenum type, js::Scalar::Type jsArrayType,
1644
                              WebGLTexImageFunc func, WebGLTexDimensions dims);
1645
    bool ValidateAttribPointer(bool integerMode, GLuint index, GLint size, GLenum type,
1646
                               WebGLboolean normalized, GLsizei stride,
1647
                               WebGLintptr byteOffset, const char* info);
1648
    bool ValidateStencilParamsForDrawCall() const;
1649
1650
    bool ValidateCopyTexImage(TexInternalFormat srcFormat, TexInternalFormat dstformat,
1651
                              WebGLTexImageFunc func, WebGLTexDimensions dims);
1652
1653
    bool ValidateTexImage(TexImageTarget texImageTarget,
1654
                          GLint level, GLenum internalFormat,
1655
                          GLint xoffset, GLint yoffset, GLint zoffset,
1656
                          GLint width, GLint height, GLint depth,
1657
                          GLint border, GLenum format, GLenum type,
1658
                          WebGLTexImageFunc func, WebGLTexDimensions dims);
1659
    bool ValidateTexImageFormat(GLenum internalFormat, WebGLTexImageFunc func,
1660
                                WebGLTexDimensions dims);
1661
    bool ValidateTexImageType(GLenum type, WebGLTexImageFunc func,
1662
                              WebGLTexDimensions dims);
1663
    bool ValidateTexImageFormatAndType(GLenum format, GLenum type,
1664
                                       WebGLTexImageFunc func,
1665
                                       WebGLTexDimensions dims);
1666
    bool ValidateCompTexImageInternalFormat(GLenum format,
1667
                                            WebGLTexImageFunc func,
1668
                                            WebGLTexDimensions dims);
1669
    bool ValidateCopyTexImageInternalFormat(GLenum format,
1670
                                            WebGLTexImageFunc func,
1671
                                            WebGLTexDimensions dims);
1672
    bool ValidateTexImageSize(TexImageTarget texImageTarget, GLint level,
1673
                              GLint width, GLint height, GLint depth,
1674
                              WebGLTexImageFunc func, WebGLTexDimensions dims);
1675
    bool ValidateTexSubImageSize(GLint x, GLint y, GLint z, GLsizei width,
1676
                                 GLsizei height, GLsizei depth,
1677
                                 GLsizei baseWidth, GLsizei baseHeight,
1678
                                 GLsizei baseDepth, WebGLTexImageFunc func,
1679
                                 WebGLTexDimensions dims);
1680
    bool ValidateCompTexImageSize(GLint level, GLenum internalFormat,
1681
                                  GLint xoffset, GLint yoffset, GLsizei width,
1682
                                  GLsizei height, GLsizei levelWidth,
1683
                                  GLsizei levelHeight, WebGLTexImageFunc func,
1684
                                  WebGLTexDimensions dims);
1685
    bool ValidateCompTexImageDataSize(GLint level, GLenum internalFormat,
1686
                                      GLsizei width, GLsizei height,
1687
                                      uint32_t byteLength,
1688
                                      WebGLTexImageFunc func,
1689
                                      WebGLTexDimensions dims);
1690
1691
    bool ValidateUniformLocationForProgram(WebGLUniformLocation* location,
1692
                                           WebGLProgram* program);
1693
1694
0
    bool HasDrawBuffers() const {
1695
0
        return IsWebGL2() ||
1696
0
               IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers);
1697
0
    }
1698
1699
    WebGLRefPtr<WebGLBuffer>* ValidateBufferSlot(GLenum target);
1700
public:
1701
    WebGLBuffer* ValidateBufferSelection(GLenum target);
1702
protected:
1703
    IndexedBufferBinding* ValidateIndexedBufferSlot(GLenum target, GLuint index);
1704
1705
    bool ValidateIndexedBufferBinding(GLenum target, GLuint index,
1706
                                      WebGLRefPtr<WebGLBuffer>** const out_genericBinding,
1707
                                      IndexedBufferBinding** const out_indexedBinding);
1708
1709
0
    bool ValidateNonNegative(const char* argName, int64_t val) {
1710
0
        if (MOZ_UNLIKELY(val < 0)) {
1711
0
            ErrorInvalidValue("`%s` must be non-negative.", argName);
1712
0
            return false;
1713
0
        }
1714
0
        return true;
1715
0
    }
1716
1717
public:
1718
    template<typename T>
1719
0
    bool ValidateNonNull(const char* const argName, const dom::Nullable<T>& maybe) {
1720
0
        if (maybe.IsNull()) {
1721
0
            ErrorInvalidValue("%s: Cannot be null.", argName);
1722
0
            return false;
1723
0
        }
1724
0
        return true;
1725
0
    }
Unexecuted instantiation: bool mozilla::WebGLContext::ValidateNonNull<mozilla::dom::ArrayBufferView_base<&js::UnwrapArrayBufferView, &js::GetArrayBufferViewLengthAndData, &(JS_GetArrayBufferViewType(JSObject*))> >(char const*, mozilla::dom::Nullable<mozilla::dom::ArrayBufferView_base<&js::UnwrapArrayBufferView, &js::GetArrayBufferViewLengthAndData, &(JS_GetArrayBufferViewType(JSObject*))> > const&)
Unexecuted instantiation: bool mozilla::WebGLContext::ValidateNonNull<mozilla::dom::TypedArray<unsigned char, &js::UnwrapArrayBuffer, &(JS_GetArrayBufferData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetArrayBufferLengthAndData, &(JS_NewArrayBuffer(JSContext*, unsigned int))> >(char const*, mozilla::dom::Nullable<mozilla::dom::TypedArray<unsigned char, &js::UnwrapArrayBuffer, &(JS_GetArrayBufferData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &js::GetArrayBufferLengthAndData, &(JS_NewArrayBuffer(JSContext*, unsigned int))> > const&)
1726
1727
    bool ValidateArrayBufferView(const dom::ArrayBufferView& view,
1728
                                 GLuint elemOffset, GLuint elemCountOverride,
1729
                                 uint8_t** const out_bytes, size_t* const out_byteLen);
1730
1731
protected:
1732
    ////
1733
1734
    void Invalidate();
1735
    void DestroyResourcesAndContext();
1736
1737
    // helpers
1738
1739
    bool ConvertImage(size_t width, size_t height, size_t srcStride,
1740
                      size_t dstStride, const uint8_t* src, uint8_t* dst,
1741
                      WebGLTexelFormat srcFormat, bool srcPremultiplied,
1742
                      WebGLTexelFormat dstFormat, bool dstPremultiplied,
1743
                      size_t dstTexelSize);
1744
1745
    //////
1746
public:
1747
    bool ValidateObjectAllowDeleted(const char* const argName,
1748
                                    const WebGLContextBoundObject& object)
1749
0
    {
1750
0
        if (!object.IsCompatibleWithContext(this)) {
1751
0
            ErrorInvalidOperation("%s: Object from different WebGL context (or older"
1752
0
                                  " generation of this one) passed as argument.",
1753
0
                                  argName);
1754
0
            return false;
1755
0
        }
1756
0
1757
0
        return true;
1758
0
    }
1759
1760
    bool ValidateObject(const char* const argName, const WebGLDeletableObject& object,
1761
                        const bool isShaderOrProgram = false)
1762
0
    {
1763
0
        if (!ValidateObjectAllowDeleted(argName, object))
1764
0
            return false;
1765
0
1766
0
        if (isShaderOrProgram) {
1767
0
            /* GLES 3.0.5 p45:
1768
0
             * "Commands that accept shader or program object names will generate the
1769
0
             *  error INVALID_VALUE if the provided name is not the name of either a
1770
0
             *  shader or program object[.]"
1771
0
             * Further, shaders and programs appear to be different from other objects,
1772
0
             * in that their lifetimes are better defined. However, they also appear to
1773
0
             * allow use of objects marked for deletion, and only reject
1774
0
             * actually-destroyed objects.
1775
0
             */
1776
0
            if (object.IsDeleted()) {
1777
0
                ErrorInvalidValue("%s: Shader or program object argument cannot have been"
1778
0
                                  " deleted.",
1779
0
                                  argName);
1780
0
                return false;
1781
0
            }
1782
0
        } else {
1783
0
            if (object.IsDeleteRequested()) {
1784
0
                ErrorInvalidOperation("%s: Object argument cannot have been marked for"
1785
0
                                      " deletion.",
1786
0
                                      argName);
1787
0
                return false;
1788
0
            }
1789
0
        }
1790
0
1791
0
        return true;
1792
0
    }
1793
1794
    ////
1795
1796
    // Program and Shader are incomplete, so we can't inline the conversion to
1797
    // WebGLDeletableObject here.
1798
    bool ValidateObject(const char* const argName, const WebGLProgram& object);
1799
    bool ValidateObject(const char* const argName, const WebGLShader& object);
1800
1801
    ////
1802
1803
    bool ValidateIsObject(const WebGLDeletableObject* object) const;
1804
    bool ValidateDeleteObject(const WebGLDeletableObject* object);
1805
1806
    ////
1807
1808
private:
1809
    // -------------------------------------------------------------------------
1810
    // Context customization points
1811
    virtual WebGLVertexArray* CreateVertexArrayImpl();
1812
1813
public:
1814
    void ForceLoseContext(bool simulateLoss = false);
1815
1816
protected:
1817
    void ForceRestoreContext();
1818
1819
    nsTArray<WebGLRefPtr<WebGLTexture> > mBound2DTextures;
1820
    nsTArray<WebGLRefPtr<WebGLTexture> > mBoundCubeMapTextures;
1821
    nsTArray<WebGLRefPtr<WebGLTexture> > mBound3DTextures;
1822
    nsTArray<WebGLRefPtr<WebGLTexture> > mBound2DArrayTextures;
1823
    nsTArray<WebGLRefPtr<WebGLSampler> > mBoundSamplers;
1824
1825
    void ResolveTexturesForDraw() const;
1826
1827
    WebGLRefPtr<WebGLProgram> mCurrentProgram;
1828
    RefPtr<const webgl::LinkedProgramInfo> mActiveProgramLinkInfo;
1829
1830
    bool ValidateFramebufferTarget(GLenum target);
1831
    bool ValidateInvalidateFramebuffer(GLenum target,
1832
                                       const dom::Sequence<GLenum>& attachments,
1833
                                       ErrorResult* const out_rv,
1834
                                       std::vector<GLenum>* const scopedVector,
1835
                                       GLsizei* const out_glNumAttachments,
1836
                                       const GLenum** const out_glAttachments);
1837
1838
    WebGLRefPtr<WebGLFramebuffer> mBoundDrawFramebuffer;
1839
    WebGLRefPtr<WebGLFramebuffer> mBoundReadFramebuffer;
1840
    WebGLRefPtr<WebGLRenderbuffer> mBoundRenderbuffer;
1841
    WebGLRefPtr<WebGLTransformFeedback> mBoundTransformFeedback;
1842
    WebGLRefPtr<WebGLVertexArray> mBoundVertexArray;
1843
1844
    LinkedList<WebGLBuffer> mBuffers;
1845
    LinkedList<WebGLFramebuffer> mFramebuffers;
1846
    LinkedList<WebGLProgram> mPrograms;
1847
    LinkedList<WebGLQuery> mQueries;
1848
    LinkedList<WebGLRenderbuffer> mRenderbuffers;
1849
    LinkedList<WebGLSampler> mSamplers;
1850
    LinkedList<WebGLShader> mShaders;
1851
    LinkedList<WebGLSync> mSyncs;
1852
    LinkedList<WebGLTexture> mTextures;
1853
    LinkedList<WebGLTransformFeedback> mTransformFeedbacks;
1854
    LinkedList<WebGLVertexArray> mVertexArrays;
1855
1856
    WebGLRefPtr<WebGLTransformFeedback> mDefaultTransformFeedback;
1857
    WebGLRefPtr<WebGLVertexArray> mDefaultVertexArray;
1858
1859
    // PixelStore parameters
1860
    uint32_t mPixelStore_UnpackImageHeight = 0;
1861
    uint32_t mPixelStore_UnpackSkipImages = 0;
1862
    uint32_t mPixelStore_UnpackRowLength = 0;
1863
    uint32_t mPixelStore_UnpackSkipRows = 0;
1864
    uint32_t mPixelStore_UnpackSkipPixels = 0;
1865
    uint32_t mPixelStore_UnpackAlignment = 0;
1866
    uint32_t mPixelStore_PackRowLength = 0;
1867
    uint32_t mPixelStore_PackSkipRows = 0;
1868
    uint32_t mPixelStore_PackSkipPixels = 0;
1869
    uint32_t mPixelStore_PackAlignment = 0;
1870
1871
    CheckedUint32 GetUnpackSize(bool isFunc3D, uint32_t width, uint32_t height,
1872
                                uint32_t depth, uint8_t bytesPerPixel);
1873
1874
    bool ValidatePackSize(uint32_t width, uint32_t height,
1875
                          uint8_t bytesPerPixel, uint32_t* const out_rowStride,
1876
                          uint32_t* const out_endOffset);
1877
1878
    GLenum mPixelStore_ColorspaceConversion = 0;
1879
    bool mPixelStore_FlipY = false;
1880
    bool mPixelStore_PremultiplyAlpha = false;
1881
    bool mPixelStore_RequireFastPath = false;
1882
1883
    ////////////////////////////////////
1884
    class FakeBlackTexture {
1885
    public:
1886
        static UniquePtr<FakeBlackTexture> Create(gl::GLContext* gl,
1887
                                                  TexTarget target,
1888
                                                  FakeBlackType type);
1889
        gl::GLContext* const mGL;
1890
        const GLuint mGLName;
1891
1892
        ~FakeBlackTexture();
1893
    protected:
1894
        explicit FakeBlackTexture(gl::GLContext* gl);
1895
    };
1896
1897
    UniquePtr<FakeBlackTexture> mFakeBlack_2D_0000;
1898
    UniquePtr<FakeBlackTexture> mFakeBlack_2D_0001;
1899
    UniquePtr<FakeBlackTexture> mFakeBlack_CubeMap_0000;
1900
    UniquePtr<FakeBlackTexture> mFakeBlack_CubeMap_0001;
1901
    UniquePtr<FakeBlackTexture> mFakeBlack_3D_0000;
1902
    UniquePtr<FakeBlackTexture> mFakeBlack_3D_0001;
1903
    UniquePtr<FakeBlackTexture> mFakeBlack_2D_Array_0000;
1904
    UniquePtr<FakeBlackTexture> mFakeBlack_2D_Array_0001;
1905
1906
    bool BindFakeBlack(uint32_t texUnit, TexTarget target, FakeBlackType fakeBlack);
1907
1908
    ////////////////////////////////////
1909
1910
protected:
1911
    GLuint mEmptyTFO;
1912
1913
    // Generic Vertex Attributes
1914
    // Though CURRENT_VERTEX_ATTRIB is listed under "Vertex Shader State" in the spec
1915
    // state tables, this isn't vertex shader /object/ state. This array is merely state
1916
    // useful to vertex shaders, but is global state.
1917
    UniquePtr<GLenum[]> mGenericVertexAttribTypes;
1918
    uint8_t mGenericVertexAttrib0Data[sizeof(float) * 4];
1919
    CacheMapInvalidator mGenericVertexAttribTypeInvalidator;
1920
1921
    GLuint mFakeVertexAttrib0BufferObject = 0;
1922
    size_t mFakeVertexAttrib0BufferObjectSize = 0;
1923
    bool mFakeVertexAttrib0DataDefined = false;
1924
    uint8_t mFakeVertexAttrib0Data[sizeof(float) * 4];
1925
1926
    JSObject* GetVertexAttribFloat32Array(JSContext* cx, GLuint index);
1927
    JSObject* GetVertexAttribInt32Array(JSContext* cx, GLuint index);
1928
    JSObject* GetVertexAttribUint32Array(JSContext* cx, GLuint index);
1929
1930
    GLint mStencilRefFront = 0;
1931
    GLint mStencilRefBack = 0;
1932
    GLuint mStencilValueMaskFront = 0;
1933
    GLuint mStencilValueMaskBack = 0;
1934
    GLuint mStencilWriteMaskFront = 0;
1935
    GLuint mStencilWriteMaskBack = 0;
1936
    uint8_t mColorWriteMask = 0; // bitmask
1937
    realGLboolean mDepthWriteMask = 0;
1938
    GLfloat mColorClearValue[4];
1939
    GLint mStencilClearValue = 0;
1940
    GLfloat mDepthClearValue = 0.0;
1941
1942
    GLint mViewportX;
1943
    GLint mViewportY;
1944
    GLsizei mViewportWidth;
1945
    GLsizei mViewportHeight;
1946
    bool mAlreadyWarnedAboutViewportLargerThanDest;
1947
1948
    GLfloat mLineWidth = 0.0;
1949
1950
    WebGLContextLossHandler mContextLossHandler;
1951
    bool mAllowContextRestore;
1952
    bool mLastLossWasSimulated;
1953
    ContextStatus mContextStatus = ContextStatus::NotLost;
1954
    bool mContextLostErrorSet;
1955
1956
    // Used for some hardware (particularly Tegra 2 and 4) that likes to
1957
    // be Flushed while doing hundreds of draw calls.
1958
    int mDrawCallsSinceLastFlush;
1959
1960
    mutable int mAlreadyGeneratedWarnings;
1961
    int mMaxWarnings;
1962
    bool mAlreadyWarnedAboutFakeVertexAttrib0;
1963
1964
    bool ShouldGenerateWarnings() const;
1965
1966
0
    bool ShouldGeneratePerfWarnings() const {
1967
0
        return mNumPerfWarnings < mMaxPerfWarnings;
1968
0
    }
1969
1970
    uint64_t mLastUseIndex;
1971
1972
    bool mNeedsFakeNoAlpha;
1973
    bool mNeedsFakeNoDepth;
1974
    bool mNeedsFakeNoStencil;
1975
    bool mNeedsFakeNoStencil_UserFBs = false;
1976
1977
    mutable uint8_t mDriverColorMask = 0;
1978
    bool mDriverDepthTest = false;
1979
    bool mDriverStencilTest = false;
1980
1981
    bool mNeedsIndexValidation = false;
1982
1983
    const bool mAllowFBInvalidation;
1984
#if defined(MOZ_WIDGET_ANDROID)
1985
    UniquePtr<gl::GLScreenBuffer> mVRScreen;
1986
#endif
1987
1988
    bool Has64BitTimestamps() const;
1989
1990
    // --
1991
1992
    const uint8_t mMsaaSamples;
1993
    mutable gfx::IntSize mRequestedSize;
1994
    mutable UniquePtr<gl::MozFramebuffer> mDefaultFB;
1995
    mutable bool mDefaultFB_IsInvalid = false;
1996
    mutable UniquePtr<gl::MozFramebuffer> mResolvedDefaultFB;
1997
1998
    // --
1999
2000
    bool EnsureDefaultFB();
2001
    bool ValidateAndInitFB(const WebGLFramebuffer* fb);
2002
    void DoBindFB(const WebGLFramebuffer* fb, GLenum target = LOCAL_GL_FRAMEBUFFER) const;
2003
2004
    bool BindCurFBForDraw();
2005
    bool BindCurFBForColorRead(const webgl::FormatUsageInfo** out_format,
2006
                               uint32_t* out_width, uint32_t* out_height);
2007
    void DoColorMask(uint8_t bitmask) const;
2008
    void BlitBackbufferToCurDriverFB() const;
2009
    bool BindDefaultFBForRead();
2010
2011
    // --
2012
2013
public:
2014
    void LoseOldestWebGLContextIfLimitExceeded();
2015
    void UpdateLastUseIndex();
2016
2017
    template <typename WebGLObjectType>
2018
    JS::Value WebGLObjectAsJSValue(JSContext* cx, const WebGLObjectType*,
2019
                                   ErrorResult& rv) const;
2020
    template <typename WebGLObjectType>
2021
    JSObject* WebGLObjectAsJSObject(JSContext* cx, const WebGLObjectType*,
2022
                                    ErrorResult& rv) const;
2023
public:
2024
    // console logging helpers
2025
    void GenerateWarning(const char* fmt, ...) const MOZ_FORMAT_PRINTF(2, 3);
2026
    void GenerateWarning(const char* fmt, va_list ap) const MOZ_FORMAT_PRINTF(2, 0);
2027
2028
    void GeneratePerfWarning(const char* fmt, ...) const MOZ_FORMAT_PRINTF(2, 3);
2029
2030
public:
2031
    UniquePtr<webgl::FormatUsageAuthority> mFormatUsage;
2032
2033
    virtual UniquePtr<webgl::FormatUsageAuthority>
2034
    CreateFormatUsage(gl::GLContext* gl) const = 0;
2035
2036
2037
    const decltype(mBound2DTextures)* TexListForElemType(GLenum elemType) const;
2038
2039
    void UpdateMaxDrawBuffers();
2040
2041
    // --
2042
private:
2043
    webgl::AvailabilityRunnable* mAvailabilityRunnable = nullptr;
2044
public:
2045
    webgl::AvailabilityRunnable* EnsureAvailabilityRunnable();
2046
2047
    // Friend list
2048
    friend class ScopedCopyTexImageSource;
2049
    friend class ScopedResolveTexturesForDraw;
2050
    friend class ScopedUnpackReset;
2051
    friend class webgl::TexUnpackBlob;
2052
    friend class webgl::TexUnpackBytes;
2053
    friend class webgl::TexUnpackImage;
2054
    friend class webgl::TexUnpackSurface;
2055
    friend struct webgl::UniformInfo;
2056
    friend class WebGLTexture;
2057
    friend class WebGLFBAttachPoint;
2058
    friend class WebGLFramebuffer;
2059
    friend class WebGLRenderbuffer;
2060
    friend class WebGLProgram;
2061
    friend class WebGLQuery;
2062
    friend class WebGLBuffer;
2063
    friend class WebGLSampler;
2064
    friend class WebGLShader;
2065
    friend class WebGLSync;
2066
    friend class WebGLTransformFeedback;
2067
    friend class WebGLUniformLocation;
2068
    friend class WebGLVertexArray;
2069
    friend class WebGLVertexArrayFake;
2070
    friend class WebGLVertexArrayGL;
2071
};
2072
2073
// used by DOM bindings in conjunction with GetParentObject
2074
inline nsISupports*
2075
ToSupports(WebGLContext* webgl)
2076
0
{
2077
0
    return static_cast<nsICanvasRenderingContextInternal*>(webgl);
2078
0
}
2079
2080
// Returns `value` rounded to the next highest multiple of `multiple`.
2081
// AKA PadToAlignment, StrideForAlignment.
2082
template<typename V, typename M>
2083
V
2084
RoundUpToMultipleOf(const V& value, const M& multiple)
2085
0
{
2086
0
    return ((value + multiple - 1) / multiple) * multiple;
2087
0
}
Unexecuted instantiation: mozilla::CheckedInt<unsigned int> mozilla::RoundUpToMultipleOf<mozilla::CheckedInt<unsigned int>, unsigned int>(mozilla::CheckedInt<unsigned int> const&, unsigned int const&)
Unexecuted instantiation: unsigned int mozilla::RoundUpToMultipleOf<unsigned int, unsigned int>(unsigned int const&, unsigned int const&)
Unexecuted instantiation: int mozilla::RoundUpToMultipleOf<int, unsigned char>(int const&, unsigned char const&)
Unexecuted instantiation: int mozilla::RoundUpToMultipleOf<int, unsigned int>(int const&, unsigned int const&)
Unexecuted instantiation: mozilla::CheckedInt<unsigned int> mozilla::RoundUpToMultipleOf<mozilla::CheckedInt<unsigned int>, unsigned char>(mozilla::CheckedInt<unsigned int> const&, unsigned char const&)
2088
2089
const char* GetEnumName(GLenum val, const char* defaultRet = "<unknown>");
2090
std::string EnumString(GLenum val);
2091
2092
bool
2093
ValidateTexTarget(WebGLContext* webgl, uint8_t funcDims,
2094
                  GLenum rawTexTarget, TexTarget* const out_texTarget,
2095
                  WebGLTexture** const out_tex);
2096
bool
2097
ValidateTexImageTarget(WebGLContext* webgl, uint8_t funcDims,
2098
                       GLenum rawTexImageTarget, TexImageTarget* const out_texImageTarget,
2099
                       WebGLTexture** const out_tex);
2100
2101
class ScopedUnpackReset final
2102
    : public gl::ScopedGLWrapper<ScopedUnpackReset>
2103
{
2104
    friend struct gl::ScopedGLWrapper<ScopedUnpackReset>;
2105
2106
private:
2107
    WebGLContext* const mWebGL;
2108
2109
public:
2110
    explicit ScopedUnpackReset(WebGLContext* webgl);
2111
2112
private:
2113
    void UnwrapImpl();
2114
};
2115
2116
class ScopedFBRebinder final
2117
    : public gl::ScopedGLWrapper<ScopedFBRebinder>
2118
{
2119
    friend struct gl::ScopedGLWrapper<ScopedFBRebinder>;
2120
2121
private:
2122
    WebGLContext* const mWebGL;
2123
2124
public:
2125
    explicit ScopedFBRebinder(WebGLContext* webgl)
2126
        : ScopedGLWrapper<ScopedFBRebinder>(webgl->gl)
2127
        , mWebGL(webgl)
2128
0
    { }
2129
2130
private:
2131
    void UnwrapImpl();
2132
};
2133
2134
class ScopedLazyBind final
2135
    : public gl::ScopedGLWrapper<ScopedLazyBind>
2136
{
2137
    friend struct gl::ScopedGLWrapper<ScopedLazyBind>;
2138
2139
    const GLenum mTarget;
2140
    const WebGLBuffer* const mBuf;
2141
2142
public:
2143
    ScopedLazyBind(gl::GLContext* gl, GLenum target, const WebGLBuffer* buf);
2144
2145
private:
2146
    void UnwrapImpl();
2147
};
2148
2149
////
2150
2151
bool
2152
Intersect(int32_t srcSize, int32_t read0, int32_t readSize, int32_t* out_intRead0,
2153
          int32_t* out_intWrite0, int32_t* out_intSize);
2154
2155
uint64_t
2156
AvailGroups(uint64_t totalAvailItems, uint64_t firstItemOffset, uint32_t groupSize,
2157
            uint32_t groupStride);
2158
2159
////
2160
2161
class ScopedDrawCallWrapper final
2162
{
2163
public:
2164
    WebGLContext& mWebGL;
2165
2166
    explicit ScopedDrawCallWrapper(WebGLContext& webgl);
2167
    ~ScopedDrawCallWrapper();
2168
};
2169
2170
////
2171
2172
void
2173
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
2174
                            const std::vector<IndexedBufferBinding>& field,
2175
                            const char* name, uint32_t flags = 0);
2176
2177
void
2178
ImplCycleCollectionUnlink(std::vector<IndexedBufferBinding>& field);
2179
2180
} // namespace mozilla
2181
2182
#endif