forked from classilla/tenfourfox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebGLContext.h
1764 lines (1482 loc) · 68.3 KB
/
WebGLContext.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef WEBGLCONTEXT_H_
#define WEBGLCONTEXT_H_
#include <stdarg.h>
#include "GLContextTypes.h"
#include "GLDefs.h"
#include "mozilla/Attributes.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/dom/HTMLCanvasElement.h"
#include "mozilla/dom/TypedArray.h"
#include "mozilla/EnumeratedArray.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/LinkedList.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/WeakPtr.h"
#include "nsCycleCollectionNoteChild.h"
#include "nsICanvasRenderingContextInternal.h"
#include "nsLayoutUtils.h"
#include "nsTArray.h"
#include "nsWrapperCache.h"
#include "SurfaceTypes.h"
#include "ScopedGLHelpers.h"
#include "TexUnpackBlob.h"
#ifdef XP_MACOSX
#include "ForceDiscreteGPUHelperCGL.h"
#endif
// Local
#include "WebGLContextUnchecked.h"
#include "WebGLFormats.h"
#include "WebGLObjectModel.h"
#include "WebGLStrongTypes.h"
#include "WebGLTexture.h"
// Generated
#include "nsIDOMEventListener.h"
#include "nsIDOMWebGLRenderingContext.h"
#include "nsICanvasRenderingContextInternal.h"
#include "nsIObserver.h"
#include "mozilla/dom/HTMLCanvasElement.h"
#include "nsWrapperCache.h"
#include "nsLayoutUtils.h"
class nsIDocShell;
/*
* Minimum value constants defined in 6.2 State Tables of OpenGL ES - 2.0.25
* https://bugzilla.mozilla.org/show_bug.cgi?id=686732
*
* Exceptions: some of the following values are set to higher values than in the spec because
* the values in the spec are ridiculously low. They are explicitly marked below
*/
#define MINVALUE_GL_MAX_TEXTURE_SIZE 1024 // Different from the spec, which sets it to 64 on page 162
#define MINVALUE_GL_MAX_CUBE_MAP_TEXTURE_SIZE 512 // Different from the spec, which sets it to 16 on page 162
#define MINVALUE_GL_MAX_VERTEX_ATTRIBS 8 // Page 164
#define MINVALUE_GL_MAX_FRAGMENT_UNIFORM_VECTORS 16 // Page 164
#define MINVALUE_GL_MAX_VERTEX_UNIFORM_VECTORS 128 // Page 164
#define MINVALUE_GL_MAX_VARYING_VECTORS 8 // Page 164
#define MINVALUE_GL_MAX_TEXTURE_IMAGE_UNITS 8 // Page 164
#define MINVALUE_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0 // Page 164
#define MINVALUE_GL_MAX_RENDERBUFFER_SIZE 1024 // Different from the spec, which sets it to 1 on page 164
#define MINVALUE_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 8 // Page 164
/*
* Minimum value constants define in 6.2 State Tables of OpenGL ES - 3.0.4
*/
#define MINVALUE_GL_MAX_3D_TEXTURE_SIZE 256
#define MINVALUE_GL_MAX_ARRAY_TEXTURE_LAYERS 256
/*
* WebGL-only GLenums
*/
#define LOCAL_GL_BROWSER_DEFAULT_WEBGL 0x9244
#define LOCAL_GL_CONTEXT_LOST_WEBGL 0x9242
#define LOCAL_GL_MAX_CLIENT_WAIT_TIMEOUT_WEBGL 0x9247
#define LOCAL_GL_UNPACK_COLORSPACE_CONVERSION_WEBGL 0x9243
#define LOCAL_GL_UNPACK_FLIP_Y_WEBGL 0x9240
#define LOCAL_GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL 0x9241
namespace mozilla {
class ScopedCopyTexImageSource;
class ScopedResolveTexturesForDraw;
class ScopedUnpackReset;
class WebGLActiveInfo;
class WebGLContextLossHandler;
class WebGLBuffer;
class WebGLExtensionBase;
class WebGLFramebuffer;
class WebGLProgram;
class WebGLQuery;
class WebGLRenderbuffer;
class WebGLSampler;
class WebGLShader;
class WebGLShaderPrecisionFormat;
class WebGLTexture;
class WebGLTransformFeedback;
class WebGLUniformLocation;
class WebGLVertexArray;
namespace dom {
class Element;
class ImageData;
class OwningHTMLCanvasElementOrOffscreenCanvas;
struct WebGLContextAttributes;
template<typename> struct Nullable;
} // namespace dom
namespace gfx {
class SourceSurface;
} // namespace gfx
namespace webgl {
struct LinkedProgramInfo;
class ShaderValidator;
class TexUnpackBlob;
} // namespace webgl
WebGLTexelFormat GetWebGLTexelFormat(TexInternalFormat format);
void AssertUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint shadow);
struct WebGLContextOptions
{
// these are defaults
WebGLContextOptions();
bool operator==(const WebGLContextOptions& other) const {
return
alpha == other.alpha &&
depth == other.depth &&
stencil == other.stencil &&
premultipliedAlpha == other.premultipliedAlpha &&
antialias == other.antialias &&
preserveDrawingBuffer == other.preserveDrawingBuffer;
}
bool operator!=(const WebGLContextOptions& other) const {
return !operator==(other);
}
bool alpha;
bool depth;
bool stencil;
bool premultipliedAlpha;
bool antialias;
bool preserveDrawingBuffer;
bool failIfMajorPerformanceCaveat;
};
// From WebGLContextUtils
TexTarget TexImageTargetToTexTarget(TexImageTarget texImageTarget);
class WebGLIntOrFloat {
enum {
Int,
Float,
Uint
} mType;
union {
GLint i;
GLfloat f;
GLuint u;
} mValue;
public:
explicit WebGLIntOrFloat(GLint i) : mType(Int) { mValue.i = i; }
explicit WebGLIntOrFloat(GLfloat f) : mType(Float) { mValue.f = f; }
GLint AsInt() const { return (mType == Int) ? mValue.i : NS_lroundf(mValue.f); }
GLfloat AsFloat() const { return (mType == Float) ? mValue.f : GLfloat(mValue.i); }
};
class WebGLContext
: public nsIDOMWebGLRenderingContext
, public nsICanvasRenderingContextInternal
, public nsSupportsWeakReference
, public WebGLContextUnchecked
, public WebGLRectangleObject
, public nsWrapperCache
, public SupportsWeakPtr<WebGLContext>
{
friend class WebGL2Context;
friend class WebGLContextUserData;
friend class WebGLExtensionCompressedTextureATC;
friend class WebGLExtensionCompressedTextureETC1;
friend class WebGLExtensionCompressedTexturePVRTC;
friend class WebGLExtensionCompressedTextureS3TC;
friend class WebGLExtensionDepthTexture;
friend class WebGLExtensionDisjointTimerQuery;
friend class WebGLExtensionDrawBuffers;
friend class WebGLExtensionLoseContext;
friend class WebGLExtensionVertexArray;
friend class WebGLMemoryTracker;
enum {
UNPACK_FLIP_Y_WEBGL = 0x9240,
UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241,
CONTEXT_LOST_WEBGL = 0x9242,
UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
BROWSER_DEFAULT_WEBGL = 0x9244,
UNMASKED_VENDOR_WEBGL = 0x9245,
UNMASKED_RENDERER_WEBGL = 0x9246
};
static const uint32_t kMinMaxColorAttachments;
static const uint32_t kMinMaxDrawBuffers;
public:
WebGLContext();
protected:
virtual ~WebGLContext();
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLContext)
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(WebGLContext,
nsIDOMWebGLRenderingContext)
virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override = 0;
NS_DECL_NSIDOMWEBGLRENDERINGCONTEXT
virtual void OnVisibilityChange() override;
virtual void OnMemoryPressure() override;
// nsICanvasRenderingContextInternal
virtual int32_t GetWidth() const override;
virtual int32_t GetHeight() const override;
NS_IMETHOD SetDimensions(int32_t width, int32_t height) override;
NS_IMETHOD InitializeWithSurface(nsIDocShell*, gfxASurface*, int32_t,
int32_t) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD Reset() override {
/* (InitializeWithSurface) */
return NS_ERROR_NOT_IMPLEMENTED;
}
virtual UniquePtr<uint8_t[]> GetImageBuffer(int32_t* out_format) override;
NS_IMETHOD GetInputStream(const char* mimeType,
const char16_t* encoderOptions,
nsIInputStream** out_stream) override;
already_AddRefed<mozilla::gfx::SourceSurface>
GetSurfaceSnapshot(bool* out_premultAlpha) override;
NS_IMETHOD SetIsOpaque(bool) override { return NS_OK; };
bool GetIsOpaque() override { return false; }
NS_IMETHOD SetContextOptions(JSContext* cx,
JS::Handle<JS::Value> options,
ErrorResult& aRvForDictionaryInit) override;
NS_IMETHOD SetIsIPC(bool) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
/**
* An abstract base class to be implemented by callers wanting to be notified
* that a refresh has occurred. Callers must ensure an observer is removed
* before it is destroyed.
*/
virtual void DidRefresh() override;
NS_IMETHOD Redraw(const gfxRect&) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
void SynthesizeGLError(GLenum err);
void SynthesizeGLError(GLenum err, const char* fmt, ...);
void ErrorInvalidEnum(const char* fmt = 0, ...);
void ErrorInvalidOperation(const char* fmt = 0, ...);
void ErrorInvalidValue(const char* fmt = 0, ...);
void ErrorInvalidFramebufferOperation(const char* fmt = 0, ...);
void ErrorInvalidEnumInfo(const char* info, GLenum enumValue);
void ErrorInvalidEnumInfo(const char* info, const char* funcName,
GLenum enumValue);
void ErrorOutOfMemory(const char* fmt = 0, ...);
const char* ErrorName(GLenum error);
/**
* Return displayable name for GLenum.
* This version is like gl::GLenumToStr but with out the GL_ prefix to
* keep consistency with how errors are reported from WebGL.
*/
// Returns nullptr if glenum is unknown.
static const char* EnumName(GLenum glenum);
// Returns hex formatted version of glenum if glenum is unknown.
static void EnumName(GLenum glenum, nsACString* out_name);
void DummyReadFramebufferOperation(const char* funcName);
WebGLTexture* ActiveBoundTextureForTarget(const TexTarget texTarget) const {
switch (texTarget.get()) {
case LOCAL_GL_TEXTURE_2D:
return mBound2DTextures[mActiveTexture];
case LOCAL_GL_TEXTURE_CUBE_MAP:
return mBoundCubeMapTextures[mActiveTexture];
case LOCAL_GL_TEXTURE_3D:
return mBound3DTextures[mActiveTexture];
case LOCAL_GL_TEXTURE_2D_ARRAY:
return mBound2DArrayTextures[mActiveTexture];
default:
MOZ_CRASH("bad target");
}
}
/* Use this function when you have the texture image target, for example:
* GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP_[POSITIVE|NEGATIVE]_[X|Y|Z], and
* not the actual texture binding target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
*/
WebGLTexture*
ActiveBoundTextureForTexImageTarget(const TexImageTarget texImgTarget) const
{
const TexTarget texTarget = TexImageTargetToTexTarget(texImgTarget);
return ActiveBoundTextureForTarget(texTarget);
}
already_AddRefed<CanvasLayer>
GetCanvasLayer(nsDisplayListBuilder* builder, CanvasLayer* oldLayer,
LayerManager* manager) override;
// Note that 'clean' here refers to its invalidation state, not the
// contents of the buffer.
void MarkContextClean() override { mInvalidated = false; }
void MarkContextCleanForFrameCapture() override { mCapturedFrameInvalidated = false; }
bool IsContextCleanForFrameCapture() override { return !mCapturedFrameInvalidated; }
gl::GLContext* GL() const { return gl; }
bool IsPremultAlpha() const { return mOptions.premultipliedAlpha; }
bool IsPreservingDrawingBuffer() const { return mOptions.preserveDrawingBuffer; }
bool PresentScreenBuffer();
// a number that increments every time we have an event that causes
// all context resources to be lost.
uint32_t Generation() { return mGeneration.value(); }
// This is similar to GLContext::ClearSafely, but tries to minimize the
// amount of work it does.
// It only clears the buffers we specify, and can reset its state without
// first having to query anything, as WebGL knows its state at all times.
void ForceClearFramebufferWithDefaultValues(GLbitfield bufferBits, bool fakeNoAlpha);
// Calls ForceClearFramebufferWithDefaultValues() for the Context's 'screen'.
void ClearScreen();
void ClearBackbufferIfNeeded();
bool MinCapabilityMode() const { return mMinCapability; }
void RunContextLossTimer();
void UpdateContextLossStatus();
void EnqueueUpdateContextLossStatus();
bool TryToRestoreContext();
void AssertCachedBindings();
void AssertCachedState();
dom::HTMLCanvasElement* GetCanvas() const { return mCanvasElement; }
// WebIDL WebGLRenderingContext API
void Commit();
void GetCanvas(Nullable<dom::OwningHTMLCanvasElementOrOffscreenCanvas>& retval);
GLsizei DrawingBufferWidth() const { return IsContextLost() ? 0 : mWidth; }
GLsizei DrawingBufferHeight() const {
return IsContextLost() ? 0 : mHeight;
}
layers::LayersBackend GetCompositorBackendType() const;
void
GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& retval);
bool IsContextLost() const { return mContextStatus != ContextNotLost; }
void GetSupportedExtensions(JSContext* cx,
dom::Nullable< nsTArray<nsString> >& retval);
void GetExtension(JSContext* cx, const nsAString& name,
JS::MutableHandle<JSObject*> retval, ErrorResult& rv);
void AttachShader(WebGLProgram* prog, WebGLShader* shader);
void BindAttribLocation(WebGLProgram* prog, GLuint location,
const nsAString& name);
void BindFramebuffer(GLenum target, WebGLFramebuffer* fb);
void BindRenderbuffer(GLenum target, WebGLRenderbuffer* fb);
void BindVertexArray(WebGLVertexArray* vao);
void BlendColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
void BlendEquation(GLenum mode);
void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha);
void BlendFunc(GLenum sfactor, GLenum dfactor);
void BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB,
GLenum srcAlpha, GLenum dstAlpha);
GLenum CheckFramebufferStatus(GLenum target);
void Clear(GLbitfield mask);
void ClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
void ClearDepth(GLclampf v);
void ClearStencil(GLint v);
void ColorMask(WebGLboolean r, WebGLboolean g, WebGLboolean b, WebGLboolean a);
void CompileShader(WebGLShader* shader);
void CompileShaderANGLE(WebGLShader* shader);
void CompileShaderBypass(WebGLShader* shader, const nsCString& shaderSource);
already_AddRefed<WebGLFramebuffer> CreateFramebuffer();
already_AddRefed<WebGLProgram> CreateProgram();
already_AddRefed<WebGLRenderbuffer> CreateRenderbuffer();
already_AddRefed<WebGLShader> CreateShader(GLenum type);
already_AddRefed<WebGLVertexArray> CreateVertexArray();
void CullFace(GLenum face);
void DeleteFramebuffer(WebGLFramebuffer* fb);
void DeleteProgram(WebGLProgram* prog);
void DeleteRenderbuffer(WebGLRenderbuffer* rb);
void DeleteShader(WebGLShader* shader);
void DeleteVertexArray(WebGLVertexArray* vao);
void DepthFunc(GLenum func);
void DepthMask(WebGLboolean b);
void DepthRange(GLclampf zNear, GLclampf zFar);
void DetachShader(WebGLProgram* prog, WebGLShader* shader);
void DrawBuffers(const dom::Sequence<GLenum>& buffers);
void Flush();
void Finish();
void FramebufferRenderbuffer(GLenum target, GLenum attachment,
GLenum rbTarget, WebGLRenderbuffer* rb);
void FramebufferTexture2D(GLenum target, GLenum attachment,
GLenum texImageTarget, WebGLTexture* tex,
GLint level);
// Framebuffer validation
bool ValidateFramebufferAttachment(const WebGLFramebuffer* fb, GLenum attachment,
const char* funcName,
bool badColorAttachmentIsInvalidOp = false);
void FrontFace(GLenum mode);
already_AddRefed<WebGLActiveInfo> GetActiveAttrib(WebGLProgram* prog,
GLuint index);
already_AddRefed<WebGLActiveInfo> GetActiveUniform(WebGLProgram* prog,
GLuint index);
void
GetAttachedShaders(WebGLProgram* prog,
dom::Nullable<nsTArray<RefPtr<WebGLShader>>>& retval);
GLint GetAttribLocation(WebGLProgram* prog, const nsAString& name);
JS::Value GetBufferParameter(GLenum target, GLenum pname);
void GetBufferParameter(JSContext*, GLenum target, GLenum pname,
JS::MutableHandle<JS::Value> retval)
{
retval.set(GetBufferParameter(target, pname));
}
GLenum GetError();
virtual JS::Value GetFramebufferAttachmentParameter(JSContext* cx, GLenum target,
GLenum attachment, GLenum pname,
ErrorResult& rv);
void GetFramebufferAttachmentParameter(JSContext* cx, GLenum target,
GLenum attachment, GLenum pname,
JS::MutableHandle<JS::Value> retval,
ErrorResult& rv)
{
retval.set(GetFramebufferAttachmentParameter(cx, target, attachment,
pname, rv));
}
JS::Value GetProgramParameter(WebGLProgram* prog, GLenum pname);
void GetProgramParameter(JSContext*, WebGLProgram* prog, GLenum pname,
JS::MutableHandle<JS::Value> retval)
{
retval.set(GetProgramParameter(prog, pname));
}
void GetProgramInfoLog(WebGLProgram* prog, nsACString& retval);
void GetProgramInfoLog(WebGLProgram* prog, nsAString& retval);
JS::Value GetRenderbufferParameter(GLenum target, GLenum pname);
void GetRenderbufferParameter(JSContext*, GLenum target, GLenum pname,
JS::MutableHandle<JS::Value> retval)
{
retval.set(GetRenderbufferParameter(target, pname));
}
JS::Value GetShaderParameter(WebGLShader* shader, GLenum pname);
void GetShaderParameter(JSContext*, WebGLShader* shader, GLenum pname,
JS::MutableHandle<JS::Value> retval)
{
retval.set(GetShaderParameter(shader, pname));
}
already_AddRefed<WebGLShaderPrecisionFormat>
GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype);
void GetShaderInfoLog(WebGLShader* shader, nsACString& retval);
void GetShaderInfoLog(WebGLShader* shader, nsAString& retval);
void GetShaderSource(WebGLShader* shader, nsAString& retval);
void GetShaderTranslatedSource(WebGLShader* shader, nsAString& retval);
JS::Value GetUniform(JSContext* cx, WebGLProgram* prog,
WebGLUniformLocation* loc);
void GetUniform(JSContext* cx, WebGLProgram* prog,
WebGLUniformLocation* loc,
JS::MutableHandle<JS::Value> retval)
{
retval.set(GetUniform(cx, prog, loc));
}
already_AddRefed<WebGLUniformLocation>
GetUniformLocation(WebGLProgram* prog, const nsAString& name);
void Hint(GLenum target, GLenum mode);
bool IsFramebuffer(WebGLFramebuffer* fb);
bool IsProgram(WebGLProgram* prog);
bool IsRenderbuffer(WebGLRenderbuffer* rb);
bool IsShader(WebGLShader* shader);
bool IsVertexArray(WebGLVertexArray* vao);
void LineWidth(GLfloat width);
void LinkProgram(WebGLProgram* prog);
void PixelStorei(GLenum pname, GLint param);
void PolygonOffset(GLfloat factor, GLfloat units);
protected:
bool DoReadPixelsAndConvert(GLint x, GLint y, GLsizei width, GLsizei height,
GLenum destFormat, GLenum destType, void* destBytes,
GLenum auxReadFormat, GLenum auxReadType);
public:
void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type,
const dom::Nullable<dom::ArrayBufferView>& pixels,
ErrorResult& rv);
void RenderbufferStorage(GLenum target, GLenum internalFormat,
GLsizei width, GLsizei height);
protected:
void RenderbufferStorage_base(const char* funcName, GLenum target,
GLsizei samples, GLenum internalformat,
GLsizei width, GLsizei height);
public:
void SampleCoverage(GLclampf value, WebGLboolean invert);
void Scissor(GLint x, GLint y, GLsizei width, GLsizei height);
void ShaderSource(WebGLShader* shader, const nsAString& source);
void StencilFunc(GLenum func, GLint ref, GLuint mask);
void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
void StencilMask(GLuint mask);
void StencilMaskSeparate(GLenum face, GLuint mask);
void StencilOp(GLenum sfail, GLenum dpfail, GLenum dppass);
void StencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail,
GLenum dppass);
void Uniform1i(WebGLUniformLocation* loc, GLint x);
void Uniform2i(WebGLUniformLocation* loc, GLint x, GLint y);
void Uniform3i(WebGLUniformLocation* loc, GLint x, GLint y, GLint z);
void Uniform4i(WebGLUniformLocation* loc, GLint x, GLint y, GLint z,
GLint w);
void Uniform1f(WebGLUniformLocation* loc, GLfloat x);
void Uniform2f(WebGLUniformLocation* loc, GLfloat x, GLfloat y);
void Uniform3f(WebGLUniformLocation* loc, GLfloat x, GLfloat y, GLfloat z);
void Uniform4f(WebGLUniformLocation* loc, GLfloat x, GLfloat y, GLfloat z,
GLfloat w);
// Int array
void Uniform1iv(WebGLUniformLocation* loc, const dom::Int32Array& arr) {
arr.ComputeLengthAndData();
Uniform1iv_base(loc, arr.Length(), arr.Data());
}
void Uniform1iv(WebGLUniformLocation* loc,
const dom::Sequence<GLint>& arr)
{
Uniform1iv_base(loc, arr.Length(), arr.Elements());
}
void Uniform1iv_base(WebGLUniformLocation* loc, size_t arrayLength,
const GLint* data);
void Uniform2iv(WebGLUniformLocation* loc, const dom::Int32Array& arr) {
arr.ComputeLengthAndData();
Uniform2iv_base(loc, arr.Length(), arr.Data());
}
void Uniform2iv(WebGLUniformLocation* loc,
const dom::Sequence<GLint>& arr)
{
Uniform2iv_base(loc, arr.Length(), arr.Elements());
}
void Uniform2iv_base(WebGLUniformLocation* loc, size_t arrayLength,
const GLint* data);
void Uniform3iv(WebGLUniformLocation* loc, const dom::Int32Array& arr) {
arr.ComputeLengthAndData();
Uniform3iv_base(loc, arr.Length(), arr.Data());
}
void Uniform3iv(WebGLUniformLocation* loc,
const dom::Sequence<GLint>& arr)
{
Uniform3iv_base(loc, arr.Length(), arr.Elements());
}
void Uniform3iv_base(WebGLUniformLocation* loc, size_t arrayLength,
const GLint* data);
void Uniform4iv(WebGLUniformLocation* loc, const dom::Int32Array& arr) {
arr.ComputeLengthAndData();
Uniform4iv_base(loc, arr.Length(), arr.Data());
}
void Uniform4iv(WebGLUniformLocation* loc,
const dom::Sequence<GLint>& arr)
{
Uniform4iv_base(loc, arr.Length(), arr.Elements());
}
void Uniform4iv_base(WebGLUniformLocation* loc, size_t arrayLength,
const GLint* data);
// Float array
void Uniform1fv(WebGLUniformLocation* loc, const dom::Float32Array& arr) {
arr.ComputeLengthAndData();
Uniform1fv_base(loc, arr.Length(), arr.Data());
}
void Uniform1fv(WebGLUniformLocation* loc,
const dom::Sequence<GLfloat>& arr)
{
Uniform1fv_base(loc, arr.Length(), arr.Elements());
}
void Uniform1fv_base(WebGLUniformLocation* loc, size_t arrayLength,
const GLfloat* data);
void Uniform2fv(WebGLUniformLocation* loc, const dom::Float32Array& arr) {
arr.ComputeLengthAndData();
Uniform2fv_base(loc, arr.Length(), arr.Data());
}
void Uniform2fv(WebGLUniformLocation* loc,
const dom::Sequence<GLfloat>& arr)
{
Uniform2fv_base(loc, arr.Length(), arr.Elements());
}
void Uniform2fv_base(WebGLUniformLocation* loc, size_t arrayLength,
const GLfloat* data);
void Uniform3fv(WebGLUniformLocation* loc, const dom::Float32Array& arr) {
arr.ComputeLengthAndData();
Uniform3fv_base(loc, arr.Length(), arr.Data());
}
void Uniform3fv(WebGLUniformLocation* loc,
const dom::Sequence<GLfloat>& arr)
{
Uniform3fv_base(loc, arr.Length(), arr.Elements());
}
void Uniform3fv_base(WebGLUniformLocation* loc, size_t arrayLength,
const GLfloat* data);
void Uniform4fv(WebGLUniformLocation* loc, const dom::Float32Array& arr) {
arr.ComputeLengthAndData();
Uniform4fv_base(loc, arr.Length(), arr.Data());
}
void Uniform4fv(WebGLUniformLocation* loc,
const dom::Sequence<GLfloat>& arr)
{
Uniform4fv_base(loc, arr.Length(), arr.Elements());
}
void Uniform4fv_base(WebGLUniformLocation* loc, size_t arrayLength,
const GLfloat* data);
// Matrix
void UniformMatrix2fv(WebGLUniformLocation* loc, WebGLboolean transpose,
const dom::Float32Array& value)
{
value.ComputeLengthAndData();
UniformMatrix2fv_base(loc, transpose, value.Length(), value.Data());
}
void UniformMatrix2fv(WebGLUniformLocation* loc, WebGLboolean transpose,
const dom::Sequence<float>& value)
{
UniformMatrix2fv_base(loc, transpose, value.Length(),
value.Elements());
}
void UniformMatrix2fv_base(WebGLUniformLocation* loc, bool transpose,
size_t arrayLength, const float* data);
void UniformMatrix3fv(WebGLUniformLocation* loc, WebGLboolean transpose,
const dom::Float32Array& value)
{
value.ComputeLengthAndData();
UniformMatrix3fv_base(loc, transpose, value.Length(), value.Data());
}
void UniformMatrix3fv(WebGLUniformLocation* loc, WebGLboolean transpose,
const dom::Sequence<float>& value)
{
UniformMatrix3fv_base(loc, transpose, value.Length(), value.Elements());
}
void UniformMatrix3fv_base(WebGLUniformLocation* loc, bool transpose,
size_t arrayLength, const float* data);
void UniformMatrix4fv(WebGLUniformLocation* loc, WebGLboolean transpose,
const dom::Float32Array& value)
{
value.ComputeLengthAndData();
UniformMatrix4fv_base(loc, transpose, value.Length(), value.Data());
}
void UniformMatrix4fv(WebGLUniformLocation* loc, bool transpose,
const dom::Sequence<float>& value)
{
UniformMatrix4fv_base(loc, transpose, value.Length(),
value.Elements());
}
void UniformMatrix4fv_base(WebGLUniformLocation* loc, bool transpose,
size_t arrayLength, const float* data);
void UseProgram(WebGLProgram* prog);
bool ValidateAttribArraySetter(const char* name, uint32_t count,
uint32_t arrayLength);
bool ValidateUniformLocation(WebGLUniformLocation* loc, const char* funcName);
bool ValidateUniformSetter(WebGLUniformLocation* loc, uint8_t setterSize,
GLenum setterType, const char* info,
GLuint* out_rawLoc);
bool ValidateUniformArraySetter(WebGLUniformLocation* loc,
uint8_t setterElemSize, GLenum setterType,
size_t setterArraySize, const char* info,
GLuint* out_rawLoc,
GLsizei* out_numElementsToUpload);
bool ValidateUniformMatrixArraySetter(WebGLUniformLocation* loc,
uint8_t setterCols,
uint8_t setterRows,
GLenum setterType,
size_t setterArraySize,
bool setterTranspose,
const char* info,
GLuint* out_rawLoc,
GLsizei* out_numElementsToUpload);
void ValidateProgram(WebGLProgram* prog);
bool ValidateUniformLocation(const char* info, WebGLUniformLocation* loc);
bool ValidateSamplerUniformSetter(const char* info,
WebGLUniformLocation* loc, GLint value);
void Viewport(GLint x, GLint y, GLsizei width, GLsizei height);
// -----------------------------------------------------------------------------
// WEBGL_lose_context
public:
void LoseContext();
void RestoreContext();
// -----------------------------------------------------------------------------
// Buffer Objects (WebGLContextBuffers.cpp)
private:
void UpdateBoundBuffer(GLenum target, WebGLBuffer* buffer);
void UpdateBoundBufferIndexed(GLenum target, GLuint index, WebGLBuffer* buffer);
public:
void BindBuffer(GLenum target, WebGLBuffer* buffer);
void BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buf);
void BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buf,
WebGLintptr offset, WebGLsizeiptr size);
private:
template<typename BufferT>
void BufferDataT(GLenum target, const BufferT& data, GLenum usage);
public:
void BufferData(GLenum target, WebGLsizeiptr size, GLenum usage);
void BufferData(GLenum target, const dom::ArrayBufferView& data,
GLenum usage);
void BufferData(GLenum target, const dom::Nullable<dom::ArrayBuffer>& maybeData,
GLenum usage);
void BufferData(GLenum target, const dom::SharedArrayBuffer& data,
GLenum usage);
private:
template<typename BufferT>
void BufferSubDataT(GLenum target, WebGLsizeiptr byteOffset,
const BufferT& data);
public:
void BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
const dom::ArrayBufferView& data);
void BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
const dom::Nullable<dom::ArrayBuffer>& maybeData);
void BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
const dom::SharedArrayBuffer& data);
already_AddRefed<WebGLBuffer> CreateBuffer();
void DeleteBuffer(WebGLBuffer* buf);
bool IsBuffer(WebGLBuffer* buf);
protected:
// bound buffer state
WebGLRefPtr<WebGLBuffer> mBoundArrayBuffer;
WebGLRefPtr<WebGLBuffer> mBoundCopyReadBuffer;
WebGLRefPtr<WebGLBuffer> mBoundCopyWriteBuffer;
WebGLRefPtr<WebGLBuffer> mBoundPixelPackBuffer;
WebGLRefPtr<WebGLBuffer> mBoundPixelUnpackBuffer;
WebGLRefPtr<WebGLBuffer> mBoundTransformFeedbackBuffer;
WebGLRefPtr<WebGLBuffer> mBoundUniformBuffer;
nsTArray<WebGLRefPtr<WebGLBuffer>> mBoundUniformBuffers;
nsTArray<WebGLRefPtr<WebGLBuffer>> mBoundTransformFeedbackBuffers;
WebGLRefPtr<WebGLBuffer>& GetBufferSlotByTarget(GLenum target);
WebGLRefPtr<WebGLBuffer>& GetBufferSlotByTargetIndexed(GLenum target,
GLuint index);
GLenum GetCurrentBinding(WebGLBuffer* buffer) const;
// -----------------------------------------------------------------------------
// Queries (WebGL2ContextQueries.cpp)
protected:
WebGLRefPtr<WebGLQuery>& GetQuerySlotByTarget(GLenum target);
WebGLRefPtr<WebGLQuery> mActiveOcclusionQuery;
WebGLRefPtr<WebGLQuery> mActiveTransformFeedbackQuery;
// -----------------------------------------------------------------------------
// State and State Requests (WebGLContextState.cpp)
public:
void Disable(GLenum cap);
void Enable(GLenum cap);
bool GetStencilBits(GLint* out_stencilBits);
virtual JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv);
void GetParameter(JSContext* cx, GLenum pname,
JS::MutableHandle<JS::Value> retval, ErrorResult& rv)
{
retval.set(GetParameter(cx, pname, rv));
}
void GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index,
JS::MutableHandle<JS::Value> retval);
bool IsEnabled(GLenum cap);
private:
// State tracking slots
realGLboolean mDitherEnabled;
realGLboolean mRasterizerDiscardEnabled;
realGLboolean mScissorTestEnabled;
realGLboolean mDepthTestEnabled;
realGLboolean mStencilTestEnabled;
bool ValidateCapabilityEnum(GLenum cap, const char* info);
realGLboolean* GetStateTrackingSlot(GLenum cap);
// -----------------------------------------------------------------------------
// Texture funcions (WebGLContextTextures.cpp)
public:
void ActiveTexture(GLenum texUnit);
void BindTexture(GLenum texTarget, WebGLTexture* tex);
already_AddRefed<WebGLTexture> CreateTexture();
void DeleteTexture(WebGLTexture* tex);
void GenerateMipmap(GLenum texTarget);
void GetTexParameter(JSContext*, GLenum texTarget, GLenum pname,
JS::MutableHandle<JS::Value> retval)
{
retval.set(GetTexParameter(texTarget, pname));
}
bool IsTexture(WebGLTexture* tex);
void TexParameterf(GLenum texTarget, GLenum pname, GLfloat param) {
TexParameter_base(texTarget, pname, nullptr, ¶m);
}
void TexParameteri(GLenum texTarget, GLenum pname, GLint param) {
TexParameter_base(texTarget, pname, ¶m, nullptr);
}
protected:
JS::Value GetTexParameter(GLenum texTarget, GLenum pname);
void TexParameter_base(GLenum texTarget, GLenum pname, GLint* maybeIntParam,
GLfloat* maybeFloatParam);
virtual bool IsTexParamValid(GLenum pname) const;
// Upload funcs
public:
void CompressedTexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
GLsizei width, GLsizei height, GLint border,
const dom::ArrayBufferView& view);
void CompressedTexSubImage2D(GLenum texImageTarget, GLint level, GLint xOffset,
GLint yOffset, GLsizei width, GLsizei height,
GLenum unpackFormat, const dom::ArrayBufferView& view);
void CopyTexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
void CopyTexSubImage2D(GLenum texImageTarget, GLint level, GLint xOffset,
GLint yOffset, GLint x, GLint y, GLsizei width,
GLsizei height);
void TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
GLsizei width, GLsizei height, GLint border, GLenum unpackFormat,
GLenum unpackType,
const dom::Nullable<dom::ArrayBufferView>& maybeView,
ErrorResult&);
void TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
GLenum unpackFormat, GLenum unpackType, dom::ImageData* imageData,
ErrorResult&);
void TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
GLenum unpackFormat, GLenum unpackType, dom::Element* elem,
ErrorResult* const out_error);
void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xOffset, GLint yOffset,
GLsizei width, GLsizei height, GLenum unpackFormat,
GLenum unpackType,
const dom::Nullable<dom::ArrayBufferView>& maybeView,
ErrorResult&);
void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xOffset, GLint yOffset,
GLenum unpackFormat, GLenum unpackType, dom::ImageData* imageData,
ErrorResult&);
void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xOffset, GLint yOffset,
GLenum unpackFormat, GLenum unpackType, dom::Element* elem,
ErrorResult* const out_error);
// Allow whatever element unpackTypes the bindings are willing to pass
// us in Tex(Sub)Image2D
template<typename T>
inline void
TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
GLenum unpackFormat, GLenum unpackType, T& elem, ErrorResult& out_error)
{
TexImage2D(texImageTarget, level, internalFormat, unpackFormat, unpackType, &elem,
&out_error);
}
template<typename T>
inline void
TexSubImage2D(GLenum texImageTarget, GLint level, GLint xOffset, GLint yOffset,
GLenum unpackFormat, GLenum unpackType, T& elem, ErrorResult& out_error)
{
TexSubImage2D(texImageTarget, level, xOffset, yOffset, unpackFormat, unpackType,
&elem, &out_error);
}
// WebGLTextureUpload.cpp
bool ValidateTexImageSpecification(const char* funcName, uint8_t funcDims,
GLenum texImageTarget, GLint level,
GLsizei width, GLsizei height, GLsizei depth,
GLint border,
TexImageTarget* const out_target,
WebGLTexture** const out_texture,
WebGLTexture::ImageInfo** const out_imageInfo);
bool ValidateTexImageSelection(const char* funcName, uint8_t funcDims,
GLenum texImageTarget, GLint level, GLint xOffset,
GLint yOffset, GLint zOffset, GLsizei width,
GLsizei height, GLsizei depth,
TexImageTarget* const out_target,
WebGLTexture** const out_texture,
WebGLTexture::ImageInfo** const out_imageInfo);
// -----------------------------------------------------------------------------
// Vertices Feature (WebGLContextVertices.cpp)
public:
void DrawArrays(GLenum mode, GLint first, GLsizei count);
void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count,
GLsizei primcount);
void DrawElements(GLenum mode, GLsizei count, GLenum type,
WebGLintptr byteOffset);
void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
WebGLintptr byteOffset, GLsizei primcount);
void EnableVertexAttribArray(GLuint index);
void DisableVertexAttribArray(GLuint index);
JS::Value GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
ErrorResult& rv);
void GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
JS::MutableHandle<JS::Value> retval, ErrorResult& rv)
{
retval.set(GetVertexAttrib(cx, index, pname, rv));
}
WebGLsizeiptr GetVertexAttribOffset(GLuint index, GLenum pname);
void VertexAttrib1f(GLuint index, GLfloat x0);
void VertexAttrib2f(GLuint index, GLfloat x0, GLfloat x1);
void VertexAttrib3f(GLuint index, GLfloat x0, GLfloat x1, GLfloat x2);
void VertexAttrib4f(GLuint index, GLfloat x0, GLfloat x1, GLfloat x2,
GLfloat x3);
void VertexAttrib1fv(GLuint idx, const dom::Float32Array& arr) {
arr.ComputeLengthAndData();
VertexAttrib1fv_base(idx, arr.Length(), arr.Data());
}
void VertexAttrib1fv(GLuint idx, const dom::Sequence<GLfloat>& arr) {
VertexAttrib1fv_base(idx, arr.Length(), arr.Elements());
}
void VertexAttrib2fv(GLuint idx, const dom::Float32Array& arr) {
arr.ComputeLengthAndData();
VertexAttrib2fv_base(idx, arr.Length(), arr.Data());
}