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