From 51d744aa93649df47098740c5de0d4a08ad13cf2 Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Tue, 29 Nov 2016 18:30:28 -0800 Subject: [PATCH] Bug 1320030 - Simplify marking and deletion checks. - r=ethlin --- dom/canvas/WebGL2Context.h | 6 +- dom/canvas/WebGL2ContextPrograms.cpp | 2 +- dom/canvas/WebGL2ContextQueries.cpp | 26 +-- dom/canvas/WebGL2ContextSamplers.cpp | 32 +--- dom/canvas/WebGL2ContextSync.cpp | 48 +++-- dom/canvas/WebGL2ContextTransformFeedback.cpp | 24 +-- dom/canvas/WebGL2ContextUniforms.cpp | 12 +- dom/canvas/WebGLBuffer.cpp | 2 +- dom/canvas/WebGLBuffer.h | 1 - dom/canvas/WebGLContext.cpp | 2 +- dom/canvas/WebGLContext.h | 166 +++++++----------- dom/canvas/WebGLContextBuffers.cpp | 31 +--- dom/canvas/WebGLContextGL.cpp | 127 ++++---------- dom/canvas/WebGLContextTextures.cpp | 7 +- dom/canvas/WebGLContextValidate.cpp | 2 +- dom/canvas/WebGLContextVertexArray.cpp | 34 +--- dom/canvas/WebGLExtensionDebugShaders.cpp | 2 +- .../WebGLExtensionDisjointTimerQuery.cpp | 2 +- dom/canvas/WebGLExtensionVertexArray.cpp | 2 +- dom/canvas/WebGLExtensions.h | 2 +- dom/canvas/WebGLFramebuffer.cpp | 29 +-- dom/canvas/WebGLFramebuffer.h | 1 - dom/canvas/WebGLObjectModel.h | 98 +++++++---- dom/canvas/WebGLProgram.cpp | 2 +- dom/canvas/WebGLProgram.h | 1 - dom/canvas/WebGLQuery.cpp | 8 +- dom/canvas/WebGLQuery.h | 1 - dom/canvas/WebGLRenderbuffer.cpp | 2 +- dom/canvas/WebGLRenderbuffer.h | 1 - dom/canvas/WebGLSampler.cpp | 2 +- dom/canvas/WebGLSampler.h | 1 - dom/canvas/WebGLShader.cpp | 2 +- dom/canvas/WebGLShader.h | 1 - dom/canvas/WebGLSync.cpp | 2 +- dom/canvas/WebGLSync.h | 1 - dom/canvas/WebGLTexture.cpp | 2 +- dom/canvas/WebGLTexture.h | 1 - dom/canvas/WebGLTransformFeedback.cpp | 2 +- dom/canvas/WebGLTransformFeedback.h | 1 - dom/canvas/WebGLVertexArray.cpp | 4 +- dom/canvas/WebGLVertexArray.h | 5 +- dom/canvas/WebGLVertexArrayFake.cpp | 2 +- dom/canvas/WebGLVertexArrayFake.h | 2 +- dom/canvas/WebGLVertexArrayGL.cpp | 2 +- dom/canvas/WebGLVertexArrayGL.h | 2 +- 45 files changed, 262 insertions(+), 443 deletions(-) diff --git a/dom/canvas/WebGL2Context.h b/dom/canvas/WebGL2Context.h index 144984f355f8..99b85b16de79 100644 --- a/dom/canvas/WebGL2Context.h +++ b/dom/canvas/WebGL2Context.h @@ -314,7 +314,7 @@ public: already_AddRefed CreateSampler(); void DeleteSampler(WebGLSampler* sampler); - bool IsSampler(WebGLSampler* sampler); + bool IsSampler(const WebGLSampler* sampler); void BindSampler(GLuint unit, WebGLSampler* sampler); void SamplerParameteri(WebGLSampler& sampler, GLenum pname, GLint param); void SamplerParameterf(WebGLSampler& sampler, GLenum pname, GLfloat param); @@ -326,7 +326,7 @@ public: // Sync objects - WebGL2ContextSync.cpp already_AddRefed FenceSync(GLenum condition, GLbitfield flags); - bool IsSync(WebGLSync* sync); + bool IsSync(const WebGLSync* sync); void DeleteSync(WebGLSync* sync); GLenum ClientWaitSync(const WebGLSync& sync, GLbitfield flags, GLuint64 timeout); void WaitSync(const WebGLSync& sync, GLbitfield flags, GLint64 timeout); @@ -339,7 +339,7 @@ public: already_AddRefed CreateTransformFeedback(); void DeleteTransformFeedback(WebGLTransformFeedback* tf); - bool IsTransformFeedback(WebGLTransformFeedback* tf); + bool IsTransformFeedback(const WebGLTransformFeedback* tf); void BindTransformFeedback(GLenum target, WebGLTransformFeedback* tf); void BeginTransformFeedback(GLenum primitiveMode); void EndTransformFeedback(); diff --git a/dom/canvas/WebGL2ContextPrograms.cpp b/dom/canvas/WebGL2ContextPrograms.cpp index 277c64f72e0c..b53798e75546 100644 --- a/dom/canvas/WebGL2ContextPrograms.cpp +++ b/dom/canvas/WebGL2ContextPrograms.cpp @@ -19,7 +19,7 @@ WebGL2Context::GetFragDataLocation(const WebGLProgram& prog, const nsAString& na if (IsContextLost()) return -1; - if (!ValidateObjectRef("getFragDataLocation: program", prog)) + if (!ValidateObject("getFragDataLocation: program", prog)) return -1; return prog.GetFragDataLocation(name); diff --git a/dom/canvas/WebGL2ContextQueries.cpp b/dom/canvas/WebGL2ContextQueries.cpp index 6673554b0b5e..a2eafcfc4ca8 100644 --- a/dom/canvas/WebGL2ContextQueries.cpp +++ b/dom/canvas/WebGL2ContextQueries.cpp @@ -78,13 +78,7 @@ WebGLContext::DeleteQuery(WebGLQuery* query, const char* funcName) funcName = "deleteQuery"; } - if (IsContextLost()) - return; - - if (!query) - return; - - if (!ValidateObjectAllowDeleted(funcName, query)) + if (!ValidateDeleteObject(funcName, query)) return; query->DeleteQuery(); @@ -97,13 +91,7 @@ WebGLContext::IsQuery(const WebGLQuery* query, const char* funcName) funcName = "isQuery"; } - if (IsContextLost()) - return false; - - if (!query) - return false; - - if (!ValidateObjectAllowDeleted("isQuery", query)) + if (!ValidateIsObject(funcName, query)) return false; return query->IsQuery(); @@ -119,12 +107,9 @@ WebGLContext::BeginQuery(GLenum target, WebGLQuery& query, const char* funcName) if (IsContextLost()) return; - if (!ValidateObjectAllowDeleted(funcName, &query)) + if (!ValidateObject(funcName, query)) return; - if (query.IsDeleted()) - return ErrorInvalidOperation("%s: Cannot begin a deleted query.", funcName); - const auto& slot = ValidateQuerySlotByTarget(funcName, target); if (!slot) return; @@ -238,12 +223,9 @@ WebGLContext::GetQueryParameter(JSContext*, const WebGLQuery& query, GLenum pnam if (IsContextLost()) return; - if (!ValidateObjectAllowDeleted(funcName, &query)) + if (!ValidateObject(funcName, query)) return; - if (query.IsDeleted()) - return ErrorInvalidOperation("%s: Query must not be deleted.", funcName); - query.GetQueryParameter(pname, retval); } diff --git a/dom/canvas/WebGL2ContextSamplers.cpp b/dom/canvas/WebGL2ContextSamplers.cpp index 7594ff22234d..8c7d9bf659b8 100644 --- a/dom/canvas/WebGL2ContextSamplers.cpp +++ b/dom/canvas/WebGL2ContextSamplers.cpp @@ -26,13 +26,7 @@ WebGL2Context::CreateSampler() void WebGL2Context::DeleteSampler(WebGLSampler* sampler) { - if (IsContextLost()) - return; - - if (!ValidateObjectAllowDeletedOrNull("deleteSampler", sampler)) - return; - - if (!sampler || sampler->IsDeleted()) + if (!ValidateDeleteObject("deleteSampler", sampler)) return; for (int n = 0; n < mGLMaxTextureUnits; n++) { @@ -47,18 +41,9 @@ WebGL2Context::DeleteSampler(WebGLSampler* sampler) } bool -WebGL2Context::IsSampler(WebGLSampler* sampler) +WebGL2Context::IsSampler(const WebGLSampler* sampler) { - if (IsContextLost()) - return false; - - if (!sampler) - return false; - - if (!ValidateObjectAllowDeleted("isSampler", sampler)) - return false; - - if (sampler->IsDeleted()) + if (!ValidateIsObject("isSampler", sampler)) return false; MakeContextCurrent(); @@ -71,15 +56,12 @@ WebGL2Context::BindSampler(GLuint unit, WebGLSampler* sampler) if (IsContextLost()) return; - if (!ValidateObjectAllowDeletedOrNull("bindSampler", sampler)) + if (sampler && !ValidateObject("bindSampler", *sampler)) return; if (GLint(unit) >= mGLMaxTextureUnits) return ErrorInvalidValue("bindSampler: unit must be < %d", mGLMaxTextureUnits); - if (sampler && sampler->IsDeleted()) - return ErrorInvalidOperation("bindSampler: binding deleted sampler"); - //// gl->MakeCurrent(); @@ -96,7 +78,7 @@ WebGL2Context::SamplerParameteri(WebGLSampler& sampler, GLenum pname, GLint para if (IsContextLost()) return; - if (!ValidateObjectRef(funcName, sampler)) + if (!ValidateObject(funcName, sampler)) return; sampler.SamplerParameter(funcName, pname, paramInt); @@ -109,7 +91,7 @@ WebGL2Context::SamplerParameterf(WebGLSampler& sampler, GLenum pname, GLfloat pa if (IsContextLost()) return; - if (!ValidateObjectRef(funcName, sampler)) + if (!ValidateObject(funcName, sampler)) return; sampler.SamplerParameter(funcName, pname, WebGLIntOrFloat(paramFloat).AsInt()); @@ -125,7 +107,7 @@ WebGL2Context::GetSamplerParameter(JSContext*, const WebGLSampler& sampler, GLen if (IsContextLost()) return; - if (!ValidateObjectRef(funcName, sampler)) + if (!ValidateObject(funcName, sampler)) return; //// diff --git a/dom/canvas/WebGL2ContextSync.cpp b/dom/canvas/WebGL2ContextSync.cpp index 6ff39387fef5..3d60d45c06f1 100644 --- a/dom/canvas/WebGL2ContextSync.cpp +++ b/dom/canvas/WebGL2ContextSync.cpp @@ -16,43 +16,37 @@ namespace mozilla { already_AddRefed WebGL2Context::FenceSync(GLenum condition, GLbitfield flags) { - if (IsContextLost()) - return nullptr; + if (IsContextLost()) + return nullptr; - if (condition != LOCAL_GL_SYNC_GPU_COMMANDS_COMPLETE) { - ErrorInvalidEnum("fenceSync: condition must be SYNC_GPU_COMMANDS_COMPLETE"); - return nullptr; - } + if (condition != LOCAL_GL_SYNC_GPU_COMMANDS_COMPLETE) { + ErrorInvalidEnum("fenceSync: condition must be SYNC_GPU_COMMANDS_COMPLETE"); + return nullptr; + } - if (flags != 0) { - ErrorInvalidValue("fenceSync: flags must be 0"); - return nullptr; - } + if (flags != 0) { + ErrorInvalidValue("fenceSync: flags must be 0"); + return nullptr; + } - MakeContextCurrent(); - RefPtr globj = new WebGLSync(this, condition, flags); - return globj.forget(); + MakeContextCurrent(); + RefPtr globj = new WebGLSync(this, condition, flags); + return globj.forget(); } bool -WebGL2Context::IsSync(WebGLSync* sync) +WebGL2Context::IsSync(const WebGLSync* sync) { - if (IsContextLost()) - return false; + if (!ValidateIsObject("isSync", sync)) + return false; - return ValidateObjectAllowDeleted("isSync", sync) && !sync->IsDeleted(); + return true; } void WebGL2Context::DeleteSync(WebGLSync* sync) { - if (IsContextLost()) - return; - - if (!ValidateObjectAllowDeletedOrNull("deleteSync", sync)) - return; - - if (!sync || sync->IsDeleted()) + if (!ValidateDeleteObject("deleteSync", sync)) return; sync->RequestDelete(); @@ -65,7 +59,7 @@ WebGL2Context::ClientWaitSync(const WebGLSync& sync, GLbitfield flags, GLuint64 if (IsContextLost()) return LOCAL_GL_WAIT_FAILED; - if (!ValidateObjectRef(funcName, sync)) + if (!ValidateObject(funcName, sync)) return LOCAL_GL_WAIT_FAILED; if (flags != 0 && flags != LOCAL_GL_SYNC_FLUSH_COMMANDS_BIT) { @@ -84,7 +78,7 @@ WebGL2Context::WaitSync(const WebGLSync& sync, GLbitfield flags, GLint64 timeout if (IsContextLost()) return; - if (!ValidateObjectRef(funcName, sync)) + if (!ValidateObject(funcName, sync)) return; if (flags != 0) { @@ -110,7 +104,7 @@ WebGL2Context::GetSyncParameter(JSContext*, const WebGLSync& sync, GLenum pname, if (IsContextLost()) return; - if (!ValidateObjectRef(funcName, sync)) + if (!ValidateObject(funcName, sync)) return; //// diff --git a/dom/canvas/WebGL2ContextTransformFeedback.cpp b/dom/canvas/WebGL2ContextTransformFeedback.cpp index fe5ec00a98d0..ee2f99341535 100644 --- a/dom/canvas/WebGL2ContextTransformFeedback.cpp +++ b/dom/canvas/WebGL2ContextTransformFeedback.cpp @@ -32,10 +32,7 @@ void WebGL2Context::DeleteTransformFeedback(WebGLTransformFeedback* tf) { const char funcName[] = "deleteTransformFeedback"; - if (IsContextLost()) - return; - - if (!ValidateObject(funcName, tf)) + if (!ValidateDeleteObject(funcName, tf)) return; if (tf->mIsActive) { @@ -51,15 +48,9 @@ WebGL2Context::DeleteTransformFeedback(WebGLTransformFeedback* tf) } bool -WebGL2Context::IsTransformFeedback(WebGLTransformFeedback* tf) +WebGL2Context::IsTransformFeedback(const WebGLTransformFeedback* tf) { - if (IsContextLost()) - return false; - - if (!ValidateObjectAllowDeletedOrNull("isTransformFeedback", tf)) - return false; - - if (!tf || tf->IsDeleted()) + if (!ValidateIsObject("isTransformFeedback", tf)) return false; MakeContextCurrent(); @@ -76,12 +67,9 @@ WebGL2Context::BindTransformFeedback(GLenum target, WebGLTransformFeedback* tf) if (target != LOCAL_GL_TRANSFORM_FEEDBACK) return ErrorInvalidEnum("%s: `target` must be TRANSFORM_FEEDBACK.", funcName); - if (!ValidateObjectAllowDeletedOrNull(funcName, tf)) + if (tf && !ValidateObject(funcName, *tf)) return; - if (tf && tf->IsDeleted()) - return ErrorInvalidOperation("%s: TFO already deleted.", funcName); - if (mBoundTransformFeedback->mIsActive && !mBoundTransformFeedback->mIsPaused) { @@ -143,7 +131,7 @@ WebGL2Context::TransformFeedbackVaryings(WebGLProgram& program, if (IsContextLost()) return; - if (!ValidateObjectRef("transformFeedbackVaryings: program", program)) + if (!ValidateObject("transformFeedbackVaryings: program", program)) return; program.TransformFeedbackVaryings(varyings, bufferMode); @@ -155,7 +143,7 @@ WebGL2Context::GetTransformFeedbackVarying(const WebGLProgram& program, GLuint i if (IsContextLost()) return nullptr; - if (!ValidateObjectRef("getTransformFeedbackVarying: program", program)) + if (!ValidateObject("getTransformFeedbackVarying: program", program)) return nullptr; return program.GetTransformFeedbackVarying(index); diff --git a/dom/canvas/WebGL2ContextUniforms.cpp b/dom/canvas/WebGL2ContextUniforms.cpp index e6e1d6990d19..95ca07fbf332 100644 --- a/dom/canvas/WebGL2ContextUniforms.cpp +++ b/dom/canvas/WebGL2ContextUniforms.cpp @@ -138,7 +138,7 @@ WebGL2Context::GetUniformIndices(const WebGLProgram& program, if (IsContextLost()) return; - if (!ValidateObjectRef("getUniformIndices: program", program)) + if (!ValidateObject("getUniformIndices: program", program)) return; if (!uniformNames.Length()) @@ -179,7 +179,7 @@ WebGL2Context::GetActiveUniforms(JSContext* cx, const WebGLProgram& program, if (!ValidateUniformEnum(this, pname, funcName)) return; - if (!ValidateObjectRef("getActiveUniforms: program", program)) + if (!ValidateObject("getActiveUniforms: program", program)) return; const auto& count = uniformIndices.Length(); @@ -231,7 +231,7 @@ WebGL2Context::GetUniformBlockIndex(const WebGLProgram& program, if (IsContextLost()) return 0; - if (!ValidateObjectRef("getUniformBlockIndex: program", program)) + if (!ValidateObject("getUniformBlockIndex: program", program)) return 0; return program.GetUniformBlockIndex(uniformBlockName); @@ -247,7 +247,7 @@ WebGL2Context::GetActiveUniformBlockParameter(JSContext* cx, const WebGLProgram& if (IsContextLost()) return; - if (!ValidateObjectRef("getActiveUniformBlockParameter: program", program)) + if (!ValidateObject("getActiveUniformBlockParameter: program", program)) return; MakeContextCurrent(); @@ -278,7 +278,7 @@ WebGL2Context::GetActiveUniformBlockName(const WebGLProgram& program, if (IsContextLost()) return; - if (!ValidateObjectRef("getActiveUniformBlockName: program", program)) + if (!ValidateObject("getActiveUniformBlockName: program", program)) return; program.GetActiveUniformBlockName(uniformBlockIndex, retval); @@ -291,7 +291,7 @@ WebGL2Context::UniformBlockBinding(WebGLProgram& program, GLuint uniformBlockInd if (IsContextLost()) return; - if (!ValidateObjectRef("uniformBlockBinding: program", program)) + if (!ValidateObject("uniformBlockBinding: program", program)) return; program.UniformBlockBinding(uniformBlockIndex, uniformBlockBinding); diff --git a/dom/canvas/WebGLBuffer.cpp b/dom/canvas/WebGLBuffer.cpp index 2647bc33cbac..8bea9ffbbee4 100644 --- a/dom/canvas/WebGLBuffer.cpp +++ b/dom/canvas/WebGLBuffer.cpp @@ -13,7 +13,7 @@ namespace mozilla { WebGLBuffer::WebGLBuffer(WebGLContext* webgl, GLuint buf) - : WebGLContextBoundObject(webgl) + : WebGLRefCountedObject(webgl) , mGLName(buf) , mContent(Kind::Undefined) , mUsage(LOCAL_GL_STATIC_DRAW) diff --git a/dom/canvas/WebGLBuffer.h b/dom/canvas/WebGLBuffer.h index cb4c87edc33b..c60bc9b5d81f 100644 --- a/dom/canvas/WebGLBuffer.h +++ b/dom/canvas/WebGLBuffer.h @@ -22,7 +22,6 @@ class WebGLBuffer final : public nsWrapperCache , public WebGLRefCountedObject , public LinkedListElement - , public WebGLContextBoundObject { friend class WebGLContext; friend class WebGL2Context; diff --git a/dom/canvas/WebGLContext.cpp b/dom/canvas/WebGLContext.cpp index 86bdd7ab23b4..3e9569ad227e 100644 --- a/dom/canvas/WebGLContext.cpp +++ b/dom/canvas/WebGLContext.cpp @@ -222,7 +222,7 @@ WebGLContext::~WebGLContext() } template -static void +void ClearLinkedList(LinkedList& list) { while (!list.isEmpty()) { diff --git a/dom/canvas/WebGLContext.h b/dom/canvas/WebGLContext.h index 635ecad515af..f2941c4156a8 100644 --- a/dom/canvas/WebGLContext.h +++ b/dom/canvas/WebGLContext.h @@ -616,11 +616,11 @@ public: GetUniformLocation(const 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); + bool IsFramebuffer(const WebGLFramebuffer* fb); + bool IsProgram(const WebGLProgram* prog); + bool IsRenderbuffer(const WebGLRenderbuffer* rb); + bool IsShader(const WebGLShader* shader); + bool IsVertexArray(const WebGLVertexArray* vao); void LineWidth(GLfloat width); void LinkProgram(WebGLProgram& prog); void PixelStorei(GLenum pname, GLint param); @@ -1628,33 +1628,69 @@ protected: ////// public: - // Returns false if `object` is null or not valid. - template - bool ValidateObject(const char* info, const ObjectType* object); + bool ValidateObjectAllowDeleted(const char* funcName, + const WebGLContextBoundObject& object) + { + if (!object.IsCompatibleWithContext(this)) { + ErrorInvalidOperation("%s: Object from different WebGL context (or older" + " generation of this one) passed as argument.", + funcName); + return false; + } - // Returns false if `object` is not valid. - template - bool ValidateObjectRef(const char* info, const ObjectType& object); + return true; + } - // Returns false if `object` is not valid. Considers null to be valid. - template - bool ValidateObjectAllowNull(const char* info, const ObjectType* object); + bool ValidateObject(const char* funcName, const WebGLDeletableObject& object) { + if (!ValidateObjectAllowDeleted(funcName, object)) + return false; - // Returns false if `object` is not valid, but considers deleted objects and - // null objects valid. - template - bool ValidateObjectAllowDeletedOrNull(const char* info, const ObjectType* object); + if (object.IsDeleteRequested()) { + ErrorInvalidOperation("%s: Object argument cannot be marked for deletion.", + funcName); + return false; + } - // Returns false if `object` is null or not valid, but considers deleted - // objects valid. - template - bool ValidateObjectAllowDeleted(const char* info, const ObjectType* object); + return true; + } -private: - // Like ValidateObject, but only for cases when `object` is known to not be - // null already. - template - bool ValidateObjectAssumeNonNull(const char* info, const ObjectType* object); + //// + + bool ValidateIsObject(const char* funcName, + const WebGLDeletableObject* object) const + { + if (IsContextLost()) + return false; + + if (!object) + return false; + + if (!object->IsCompatibleWithContext(this)) + return false; + + if (object->IsDeleted()) + return false; + + return true; + } + + bool ValidateDeleteObject(const char* funcName, const WebGLDeletableObject* object) { + if (IsContextLost()) + return false; + + if (!object) + return false; + + if (!ValidateObjectAllowDeleted(funcName, *object)) + return false; + + if (object->IsDeleteRequested()) + return false; + + return true; + } + + //// private: // ------------------------------------------------------------------------- @@ -1953,82 +1989,6 @@ ToSupports(WebGLContext* webgl) return static_cast(webgl); } -/** - ** Template implementations - **/ - -template -inline bool -WebGLContext::ValidateObjectAllowDeletedOrNull(const char* info, const ObjectType* object) -{ - if (object && !object->IsCompatibleWithContext(this)) { - ErrorInvalidOperation("%s: object from different WebGL context " - "(or older generation of this one) " - "passed as argument", info); - return false; - } - - return true; -} - -template -inline bool -WebGLContext::ValidateObjectAssumeNonNull(const char* info, const ObjectType* object) -{ - MOZ_ASSERT(object); - - if (!ValidateObjectAllowDeletedOrNull(info, object)) - return false; - - if (object->IsDeleted()) { - ErrorInvalidValue("%s: Deleted object passed as argument.", info); - return false; - } - - return true; -} - -template -inline bool -WebGLContext::ValidateObjectAllowNull(const char* info, const ObjectType* object) -{ - if (!object) - return true; - - return ValidateObjectAssumeNonNull(info, object); -} - -template -inline bool -WebGLContext::ValidateObjectAllowDeleted(const char* info, const ObjectType* object) -{ - if (!object) { - ErrorInvalidValue("%s: null object passed as argument", info); - return false; - } - - return ValidateObjectAllowDeletedOrNull(info, object); -} - -template -inline bool -WebGLContext::ValidateObject(const char* info, const ObjectType* object) -{ - if (!object) { - ErrorInvalidValue("%s: null object passed as argument", info); - return false; - } - - return ValidateObjectAssumeNonNull(info, object); -} - -template -inline bool -WebGLContext::ValidateObjectRef(const char* info, const ObjectType& object) -{ - return ValidateObjectAssumeNonNull(info, &object); -} - // Returns `value` rounded to the next highest multiple of `multiple`. // AKA PadToAlignment, StrideForAlignment. template diff --git a/dom/canvas/WebGLContextBuffers.cpp b/dom/canvas/WebGLContextBuffers.cpp index 03bd50934b39..54c09370563d 100644 --- a/dom/canvas/WebGLContextBuffers.cpp +++ b/dom/canvas/WebGLContextBuffers.cpp @@ -119,12 +119,9 @@ WebGLContext::BindBuffer(GLenum target, WebGLBuffer* buffer) if (IsContextLost()) return; - if (!ValidateObjectAllowDeletedOrNull(funcName, buffer)) + if (buffer && !ValidateObject(funcName, *buffer)) return; - if (buffer && buffer->IsDeleted()) - return ErrorInvalidOperation("%s: Cannot bind a deleted object.", funcName); - const auto& slot = ValidateBufferSlot(funcName, target); if (!slot) return; @@ -183,12 +180,9 @@ WebGLContext::BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buffer) if (IsContextLost()) return; - if (!ValidateObjectAllowDeletedOrNull(funcName, buffer)) + if (buffer && !ValidateObject(funcName, *buffer)) return; - if (buffer && buffer->IsDeleted()) - return ErrorInvalidOperation("%s: Cannot bind a deleted object.", funcName); - WebGLRefPtr* genericBinding; IndexedBufferBinding* indexedBinding; if (!ValidateIndexedBufferBinding(funcName, target, index, &genericBinding, @@ -234,12 +228,9 @@ WebGLContext::BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buffer, if (IsContextLost()) return; - if (!ValidateObjectAllowDeletedOrNull(funcName, buffer)) + if (buffer && !ValidateObject(funcName, *buffer)) return; - if (buffer && buffer->IsDeleted()) - return ErrorInvalidOperation("%s: Cannot bind a deleted object.", funcName); - if (!ValidateNonNegative(funcName, "offset", offset) || !ValidateNonNegative(funcName, "size", size)) { @@ -476,13 +467,7 @@ WebGLContext::CreateBuffer() void WebGLContext::DeleteBuffer(WebGLBuffer* buffer) { - if (IsContextLost()) - return; - - if (!ValidateObjectAllowDeletedOrNull("deleteBuffer", buffer)) - return; - - if (!buffer || buffer->IsDeleted()) + if (!ValidateDeleteObject("deleteBuffer", buffer)) return; //// @@ -530,13 +515,7 @@ WebGLContext::DeleteBuffer(WebGLBuffer* buffer) bool WebGLContext::IsBuffer(WebGLBuffer* buffer) { - if (IsContextLost()) - return false; - - if (!ValidateObjectAllowDeleted("isBuffer", buffer)) - return false; - - if (buffer->IsDeleted()) + if (!ValidateIsObject("isBuffer", buffer)) return false; MakeContextCurrent(); diff --git a/dom/canvas/WebGLContextGL.cpp b/dom/canvas/WebGLContextGL.cpp index 30fb6664c9a2..b508e092789a 100644 --- a/dom/canvas/WebGLContextGL.cpp +++ b/dom/canvas/WebGLContextGL.cpp @@ -92,8 +92,8 @@ WebGLContext::AttachShader(WebGLProgram& program, WebGLShader& shader) if (IsContextLost()) return; - if (!ValidateObjectRef("attachShader: program", program) || - !ValidateObjectRef("attachShader: shader", shader)) + if (!ValidateObject("attachShader: program", program) || + !ValidateObject("attachShader: shader", shader)) { return; } @@ -108,7 +108,7 @@ WebGLContext::BindAttribLocation(WebGLProgram& prog, GLuint location, if (IsContextLost()) return; - if (!ValidateObjectRef("bindAttribLocation: program", prog)) + if (!ValidateObject("bindAttribLocation: program", prog)) return; prog.BindAttribLocation(location, name); @@ -123,12 +123,9 @@ WebGLContext::BindFramebuffer(GLenum target, WebGLFramebuffer* wfb) if (!ValidateFramebufferTarget(target, "bindFramebuffer")) return; - if (!ValidateObjectAllowDeletedOrNull("bindFramebuffer", wfb)) + if (wfb && !ValidateObject("bindFramebuffer", *wfb)) return; - if (wfb && wfb->IsDeleted()) - return ErrorInvalidOperation("bindFramebuffer: Cannot bind a deleted object."); - MakeContextCurrent(); if (!wfb) { @@ -166,12 +163,9 @@ WebGLContext::BindRenderbuffer(GLenum target, WebGLRenderbuffer* wrb) if (target != LOCAL_GL_RENDERBUFFER) return ErrorInvalidEnumInfo("bindRenderbuffer: target", target); - if (!ValidateObjectAllowDeletedOrNull("bindRenderbuffer", wrb)) + if (wrb && !ValidateObject("bindRenderbuffer", *wrb)) return; - if (wrb && wrb->IsDeleted()) - return ErrorInvalidOperation("bindRenderbuffer: Cannot bind a deleted object."); - // Usually, we would now call into glBindRenderbuffer. However, since we have to // potentially emulate packed-depth-stencil, there's not a specific renderbuffer that // we know we should bind here. @@ -320,13 +314,7 @@ WebGLContext::CullFace(GLenum face) void WebGLContext::DeleteFramebuffer(WebGLFramebuffer* fbuf) { - if (IsContextLost()) - return; - - if (!ValidateObjectAllowDeletedOrNull("deleteFramebuffer", fbuf)) - return; - - if (!fbuf || fbuf->IsDeleted()) + if (!ValidateDeleteObject("deleteFramebuffer", fbuf)) return; fbuf->RequestDelete(); @@ -348,13 +336,7 @@ WebGLContext::DeleteFramebuffer(WebGLFramebuffer* fbuf) void WebGLContext::DeleteRenderbuffer(WebGLRenderbuffer* rbuf) { - if (IsContextLost()) - return; - - if (!ValidateObjectAllowDeletedOrNull("deleteRenderbuffer", rbuf)) - return; - - if (!rbuf || rbuf->IsDeleted()) + if (!ValidateDeleteObject("deleteRenderbuffer", rbuf)) return; if (mBoundDrawFramebuffer) @@ -374,13 +356,7 @@ WebGLContext::DeleteRenderbuffer(WebGLRenderbuffer* rbuf) void WebGLContext::DeleteTexture(WebGLTexture* tex) { - if (IsContextLost()) - return; - - if (!ValidateObjectAllowDeletedOrNull("deleteTexture", tex)) - return; - - if (!tex || tex->IsDeleted()) + if (!ValidateDeleteObject("deleteTexture", tex)) return; if (mBoundDrawFramebuffer) @@ -408,13 +384,7 @@ WebGLContext::DeleteTexture(WebGLTexture* tex) void WebGLContext::DeleteProgram(WebGLProgram* prog) { - if (IsContextLost()) - return; - - if (!ValidateObjectAllowDeletedOrNull("deleteProgram", prog)) - return; - - if (!prog || prog->IsDeleted()) + if (!ValidateDeleteObject("deleteProgram", prog)) return; prog->RequestDelete(); @@ -423,13 +393,7 @@ WebGLContext::DeleteProgram(WebGLProgram* prog) void WebGLContext::DeleteShader(WebGLShader* shader) { - if (IsContextLost()) - return; - - if (!ValidateObjectAllowDeletedOrNull("deleteShader", shader)) - return; - - if (!shader || shader->IsDeleted()) + if (!ValidateDeleteObject("deleteShader", shader)) return; shader->RequestDelete(); @@ -443,8 +407,8 @@ WebGLContext::DetachShader(WebGLProgram& program, const WebGLShader& shader) // It's valid to attempt to detach a deleted shader, since it's still a // shader. - if (!ValidateObjectRef("detachShader: program", program) || - !ValidateObjectAllowDeleted("detachShader: shader", &shader)) + if (!ValidateObject("detachShader: program", program) || + !ValidateObjectAllowDeleted("detachShader: shader", shader)) { return; } @@ -569,7 +533,7 @@ WebGLContext::GetActiveAttrib(const WebGLProgram& prog, GLuint index) if (IsContextLost()) return nullptr; - if (!ValidateObjectRef("getActiveAttrib: program", prog)) + if (!ValidateObject("getActiveAttrib: program", prog)) return nullptr; return prog.GetActiveAttrib(index); @@ -581,7 +545,7 @@ WebGLContext::GetActiveUniform(const WebGLProgram& prog, GLuint index) if (IsContextLost()) return nullptr; - if (!ValidateObjectRef("getActiveUniform: program", prog)) + if (!ValidateObject("getActiveUniform: program", prog)) return nullptr; return prog.GetActiveUniform(index); @@ -595,7 +559,7 @@ WebGLContext::GetAttachedShaders(const WebGLProgram& prog, if (IsContextLost()) return; - if (!ValidateObjectRef("getAttachedShaders", prog)) + if (!ValidateObject("getAttachedShaders", prog)) return; prog.GetAttachedShaders(&retval.SetValue()); @@ -607,7 +571,7 @@ WebGLContext::GetAttribLocation(const WebGLProgram& prog, const nsAString& name) if (IsContextLost()) return -1; - if (!ValidateObjectRef("getAttribLocation: program", prog)) + if (!ValidateObject("getAttribLocation: program", prog)) return -1; return prog.GetAttribLocation(name); @@ -910,7 +874,7 @@ WebGLContext::GetProgramParameter(const WebGLProgram& prog, GLenum pname) if (IsContextLost()) return JS::NullValue(); - if (!ValidateObjectAllowDeleted("getProgramParameter: program", &prog)) + if (!ValidateObjectAllowDeleted("getProgramParameter: program", prog)) return JS::NullValue(); return prog.GetProgramParameter(pname); @@ -924,7 +888,7 @@ WebGLContext::GetProgramInfoLog(const WebGLProgram& prog, nsAString& retval) if (IsContextLost()) return; - if (!ValidateObjectRef("getProgramInfoLog: program", prog)) + if (!ValidateObject("getProgramInfoLog: program", prog)) return; prog.GetProgramInfoLog(&retval); @@ -937,10 +901,10 @@ WebGLContext::GetUniform(JSContext* js, const WebGLProgram& prog, if (IsContextLost()) return JS::NullValue(); - if (!ValidateObjectRef("getUniform: `program`", prog)) + if (!ValidateObject("getUniform: `program`", prog)) return JS::NullValue(); - if (!ValidateObjectRef("getUniform: `location`", loc)) + if (!ValidateObjectAllowDeleted("getUniform: `location`", loc)) return JS::NullValue(); if (!loc.ValidateForProgram(&prog, "getUniform")) @@ -955,7 +919,7 @@ WebGLContext::GetUniformLocation(const WebGLProgram& prog, const nsAString& name if (IsContextLost()) return nullptr; - if (!ValidateObjectRef("getUniformLocation: program", prog)) + if (!ValidateObject("getUniformLocation: program", prog)) return nullptr; return prog.GetUniformLocation(name); @@ -995,15 +959,9 @@ WebGLContext::Hint(GLenum target, GLenum mode) } bool -WebGLContext::IsFramebuffer(WebGLFramebuffer* fb) +WebGLContext::IsFramebuffer(const WebGLFramebuffer* fb) { - if (IsContextLost()) - return false; - - if (!ValidateObjectAllowDeleted("isFramebuffer", fb)) - return false; - - if (fb->IsDeleted()) + if (!ValidateIsObject("isFramebuffer", fb)) return false; #ifdef ANDROID @@ -1019,37 +977,30 @@ WebGLContext::IsFramebuffer(WebGLFramebuffer* fb) } bool -WebGLContext::IsProgram(WebGLProgram* prog) +WebGLContext::IsProgram(const WebGLProgram* prog) { - if (IsContextLost()) + if (!ValidateIsObject("isProgram", prog)) return false; - return ValidateObjectAllowDeleted("isProgram", prog) && !prog->IsDeleted(); + return true; } bool -WebGLContext::IsRenderbuffer(WebGLRenderbuffer* rb) +WebGLContext::IsRenderbuffer(const WebGLRenderbuffer* rb) { - if (IsContextLost()) - return false; - - if (!ValidateObjectAllowDeleted("isRenderBuffer", rb)) - return false; - - if (rb->IsDeleted()) + if (!ValidateIsObject("isRenderbuffer", rb)) return false; return rb->mHasBeenBound; } bool -WebGLContext::IsShader(WebGLShader* shader) +WebGLContext::IsShader(const WebGLShader* shader) { - if (IsContextLost()) + if (!ValidateIsObject("isShader", shader)) return false; - return ValidateObjectAllowDeleted("isShader", shader) && - !shader->IsDeleted(); + return true; } void @@ -1058,7 +1009,7 @@ WebGLContext::LinkProgram(WebGLProgram& prog) if (IsContextLost()) return; - if (!ValidateObjectRef("linkProgram", prog)) + if (!ValidateObject("linkProgram", prog)) return; prog.LinkProgram(); @@ -2101,7 +2052,7 @@ WebGLContext::UseProgram(WebGLProgram* prog) return; } - if (!ValidateObject("useProgram", prog)) + if (!ValidateObject("useProgram", *prog)) return; if (prog->UseProgram()) { @@ -2116,7 +2067,7 @@ WebGLContext::ValidateProgram(const WebGLProgram& prog) if (IsContextLost()) return; - if (!ValidateObjectRef("validateProgram", prog)) + if (!ValidateObject("validateProgram", prog)) return; prog.ValidateProgram(); @@ -2171,7 +2122,7 @@ WebGLContext::CompileShader(WebGLShader& shader) if (IsContextLost()) return; - if (!ValidateObjectRef("compileShader", shader)) + if (!ValidateObject("compileShader", shader)) return; shader.CompileShader(); @@ -2183,7 +2134,7 @@ WebGLContext::GetShaderParameter(const WebGLShader& shader, GLenum pname) if (IsContextLost()) return JS::NullValue(); - if (!ValidateObjectRef("getShaderParameter: shader", shader)) + if (!ValidateObjectAllowDeleted("getShaderParameter: shader", shader)) return JS::NullValue(); return shader.GetShaderParameter(pname); @@ -2197,7 +2148,7 @@ WebGLContext::GetShaderInfoLog(const WebGLShader& shader, nsAString& retval) if (IsContextLost()) return; - if (!ValidateObjectRef("getShaderInfoLog: shader", shader)) + if (!ValidateObject("getShaderInfoLog: shader", shader)) return; shader.GetShaderInfoLog(&retval); @@ -2259,7 +2210,7 @@ WebGLContext::GetShaderSource(const WebGLShader& shader, nsAString& retval) if (IsContextLost()) return; - if (!ValidateObjectRef("getShaderSource: shader", shader)) + if (!ValidateObject("getShaderSource: shader", shader)) return; shader.GetShaderSource(&retval); @@ -2271,7 +2222,7 @@ WebGLContext::ShaderSource(WebGLShader& shader, const nsAString& source) if (IsContextLost()) return; - if (!ValidateObjectRef("shaderSource: shader", shader)) + if (!ValidateObject("shaderSource: shader", shader)) return; shader.ShaderSource(source); diff --git a/dom/canvas/WebGLContextTextures.cpp b/dom/canvas/WebGLContextTextures.cpp index e5975f36f3de..033be7d33236 100644 --- a/dom/canvas/WebGLContextTextures.cpp +++ b/dom/canvas/WebGLContextTextures.cpp @@ -209,7 +209,7 @@ WebGLContext::BindTexture(GLenum rawTarget, WebGLTexture* newTex) if (IsContextLost()) return; - if (!ValidateObjectAllowDeletedOrNull("bindTexture", newTex)) + if (newTex && !ValidateObject("bindTexture", *newTex)) return; // Need to check rawTarget first before comparing against newTex->Target() as @@ -290,10 +290,7 @@ WebGLContext::GetTexParameter(GLenum rawTexTarget, GLenum pname) bool WebGLContext::IsTexture(WebGLTexture* tex) { - if (IsContextLost()) - return false; - - if (!ValidateObjectAllowDeleted("isTexture", tex)) + if (!ValidateIsObject("isTexture", tex)) return false; return tex->IsTexture(); diff --git a/dom/canvas/WebGLContextValidate.cpp b/dom/canvas/WebGLContextValidate.cpp index b3edcf3fbd15..03367140503a 100644 --- a/dom/canvas/WebGLContextValidate.cpp +++ b/dom/canvas/WebGLContextValidate.cpp @@ -207,7 +207,7 @@ WebGLContext::ValidateUniformLocation(WebGLUniformLocation* loc, const char* fun if (!loc) return false; - if (!ValidateObject(funcName, loc)) + if (!ValidateObjectAllowDeleted(funcName, *loc)) return false; if (!mCurrentProgram) { diff --git a/dom/canvas/WebGLContextVertexArray.cpp b/dom/canvas/WebGLContextVertexArray.cpp index 6a4eabf888bc..e9f16d3f75e2 100644 --- a/dom/canvas/WebGLContextVertexArray.cpp +++ b/dom/canvas/WebGLContextVertexArray.cpp @@ -18,20 +18,9 @@ WebGLContext::BindVertexArray(WebGLVertexArray* array) if (IsContextLost()) return; - if (!ValidateObjectAllowDeletedOrNull("bindVertexArrayObject", array)) + if (array && !ValidateObject("bindVertexArrayObject", *array)) return; - if (array && array->IsDeleted()) { - /* http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt - * BindVertexArrayOES fails and an INVALID_OPERATION error is - * generated if array is not a name returned from a previous call to - * GenVertexArraysOES, or if such a name has since been deleted with - * DeleteVertexArraysOES - */ - ErrorInvalidOperation("bindVertexArray: can't bind a deleted array!"); - return; - } - InvalidateBufferFetching(); MakeContextCurrent(); @@ -68,13 +57,7 @@ WebGLContext::CreateVertexArrayImpl() void WebGLContext::DeleteVertexArray(WebGLVertexArray* array) { - if (IsContextLost()) - return; - - if (array == nullptr) - return; - - if (array->IsDeleted()) + if (!ValidateDeleteObject("deleteVertexArray", array)) return; if (mBoundVertexArray == array) @@ -84,18 +67,9 @@ WebGLContext::DeleteVertexArray(WebGLVertexArray* array) } bool -WebGLContext::IsVertexArray(WebGLVertexArray* array) +WebGLContext::IsVertexArray(const WebGLVertexArray* array) { - if (IsContextLost()) - return false; - - if (!array) - return false; - - if (!ValidateObjectAllowDeleted("isVertexArray", array)) - return false; - - if (array->IsDeleted()) + if (!ValidateIsObject("isVertexArray", array)) return false; MakeContextCurrent(); diff --git a/dom/canvas/WebGLExtensionDebugShaders.cpp b/dom/canvas/WebGLExtensionDebugShaders.cpp index a65bd5d12ef6..75880465e2dc 100644 --- a/dom/canvas/WebGLExtensionDebugShaders.cpp +++ b/dom/canvas/WebGLExtensionDebugShaders.cpp @@ -38,7 +38,7 @@ WebGLExtensionDebugShaders::GetTranslatedShaderSource(const WebGLShader& shader, if (mContext->IsContextLost()) return; - if (!mContext->ValidateObjectRef("getShaderTranslatedSource: shader", shader)) + if (!mContext->ValidateObject("getShaderTranslatedSource: shader", shader)) return; shader.GetShaderTranslatedSource(&retval); diff --git a/dom/canvas/WebGLExtensionDisjointTimerQuery.cpp b/dom/canvas/WebGLExtensionDisjointTimerQuery.cpp index 344be81b4eaf..e2e34f14e58c 100644 --- a/dom/canvas/WebGLExtensionDisjointTimerQuery.cpp +++ b/dom/canvas/WebGLExtensionDisjointTimerQuery.cpp @@ -83,7 +83,7 @@ WebGLExtensionDisjointTimerQuery::QueryCounterEXT(WebGLQuery& query, GLenum targ if (mIsLost) return; - if (!mContext->ValidateObjectRef(funcName, query)) + if (!mContext->ValidateObject(funcName, query)) return; query.QueryCounter(funcName, target); diff --git a/dom/canvas/WebGLExtensionVertexArray.cpp b/dom/canvas/WebGLExtensionVertexArray.cpp index 1dfa99d84fc6..0984582f5326 100644 --- a/dom/canvas/WebGLExtensionVertexArray.cpp +++ b/dom/canvas/WebGLExtensionVertexArray.cpp @@ -41,7 +41,7 @@ WebGLExtensionVertexArray::DeleteVertexArrayOES(WebGLVertexArray* array) } bool -WebGLExtensionVertexArray::IsVertexArrayOES(WebGLVertexArray* array) +WebGLExtensionVertexArray::IsVertexArrayOES(const WebGLVertexArray* array) { if (mIsLost) return false; diff --git a/dom/canvas/WebGLExtensions.h b/dom/canvas/WebGLExtensions.h index e1d5c4c24b42..038c8780a9ee 100644 --- a/dom/canvas/WebGLExtensions.h +++ b/dom/canvas/WebGLExtensions.h @@ -344,7 +344,7 @@ public: already_AddRefed CreateVertexArrayOES(); void DeleteVertexArrayOES(WebGLVertexArray* array); - bool IsVertexArrayOES(WebGLVertexArray* array); + bool IsVertexArrayOES(const WebGLVertexArray* array); void BindVertexArrayOES(WebGLVertexArray* array); DECL_WEBGL_EXTENSION_GOOP diff --git a/dom/canvas/WebGLFramebuffer.cpp b/dom/canvas/WebGLFramebuffer.cpp index a773dfbded9d..a9390f05366d 100644 --- a/dom/canvas/WebGLFramebuffer.cpp +++ b/dom/canvas/WebGLFramebuffer.cpp @@ -604,7 +604,7 @@ WebGLFBAttachPoint::GetParameter(const char* funcName, WebGLContext* webgl, JSCo // WebGLFramebuffer WebGLFramebuffer::WebGLFramebuffer(WebGLContext* webgl, GLuint fbo) - : WebGLContextBoundObject(webgl) + : WebGLRefCountedObject(webgl) , mGLName(fbo) #ifdef ANDROID , mIsFB(false) @@ -1301,7 +1301,7 @@ WebGLFramebuffer::FramebufferRenderbuffer(const char* funcName, GLenum attachEnu } // `rb` - if (!mContext->ValidateObjectAllowNull("framebufferRenderbuffer: rb", rb)) + if (rb && !mContext->ValidateObject("framebufferRenderbuffer: rb", *rb)) return; // End of validation. @@ -1343,10 +1343,10 @@ WebGLFramebuffer::FramebufferTexture2D(const char* funcName, GLenum attachEnum, } // `texture` - if (!mContext->ValidateObjectAllowNull("framebufferTexture2D: texture", tex)) - return; - if (tex) { + if (!mContext->ValidateObject("framebufferTexture2D: texture", *tex)) + return; + if (!tex->HasEverBeenBound()) { mContext->ErrorInvalidOperation("%s: `texture` has never been bound.", funcName); @@ -1419,15 +1419,6 @@ WebGLFramebuffer::FramebufferTextureLayer(const char* funcName, GLenum attachEnu } const auto& attach = maybeAttach.value(); - // `texture` - if (!mContext->ValidateObjectAllowNull("framebufferTextureLayer: texture", tex)) - return; - - if (tex && !tex->HasEverBeenBound()) { - mContext->ErrorInvalidOperation("%s: `texture` has never been bound.", funcName); - return; - } - // `level`, `layer` if (layer < 0) return mContext->ErrorInvalidValue("%s: `layer` must be >= 0.", funcName); @@ -1435,8 +1426,18 @@ WebGLFramebuffer::FramebufferTextureLayer(const char* funcName, GLenum attachEnu if (level < 0) return mContext->ErrorInvalidValue("%s: `level` must be >= 0.", funcName); + // `texture` TexImageTarget texImageTarget = LOCAL_GL_TEXTURE_3D; if (tex) { + if (!mContext->ValidateObject("framebufferTextureLayer: texture", *tex)) + return; + + if (!tex->HasEverBeenBound()) { + mContext->ErrorInvalidOperation("%s: `texture` has never been bound.", + funcName); + return; + } + texImageTarget = tex->Target().get(); switch (texImageTarget.get()) { case LOCAL_GL_TEXTURE_3D: diff --git a/dom/canvas/WebGLFramebuffer.h b/dom/canvas/WebGLFramebuffer.h index eb69fddb7750..3b69d1fb0f12 100644 --- a/dom/canvas/WebGLFramebuffer.h +++ b/dom/canvas/WebGLFramebuffer.h @@ -132,7 +132,6 @@ class WebGLFramebuffer final : public nsWrapperCache , public WebGLRefCountedObject , public LinkedListElement - , public WebGLContextBoundObject , public SupportsWeakPtr { friend class WebGLContext; diff --git a/dom/canvas/WebGLObjectModel.h b/dom/canvas/WebGLObjectModel.h index 307c86966a76..54ea0ede5f4f 100644 --- a/dom/canvas/WebGLObjectModel.h +++ b/dom/canvas/WebGLObjectModel.h @@ -12,8 +12,55 @@ namespace mozilla { +template class LinkedList; class WebGLContext; +//// + +// This class is a mixin for objects that are tied to a specific +// context (which is to say, all of them). They provide initialization +// as well as comparison with the current context. +class WebGLContextBoundObject +{ +public: + WebGLContext* const mContext; +private: + const uint32_t mContextGeneration; + +public: + explicit WebGLContextBoundObject(WebGLContext* webgl); + + bool IsCompatibleWithContext(const WebGLContext* other) const; +}; + +//// + +class WebGLDeletableObject : public WebGLContextBoundObject +{ + template friend class WebGLRefCountedObject; + +private: + enum DeletionStatus { Default, DeleteRequested, Deleted }; + + DeletionStatus mDeletionStatus; + + //// + + explicit WebGLDeletableObject(WebGLContext* webgl) + : WebGLContextBoundObject(webgl) + , mDeletionStatus(Default) + {} + + ~WebGLDeletableObject() { + MOZ_ASSERT(mDeletionStatus == Deleted, + "Derived class destructor must call DeleteOnce()."); + } + +public: + bool IsDeleted() const { return mDeletionStatus == Deleted; } + bool IsDeleteRequested() const { return mDeletionStatus != Default; } +}; + /* Each WebGL object class WebGLFoo wants to: * - inherit WebGLRefCountedObject * - implement a Delete() method @@ -91,22 +138,25 @@ class WebGLContext; * class, without either method being virtual. This is a common C++ pattern * known as the "curiously recursive template pattern (CRTP)". */ -template -class WebGLRefCountedObject -{ -public: - enum DeletionStatus { Default, DeleteRequested, Deleted }; - WebGLRefCountedObject() - : mDeletionStatus(Default) - {} +template +class WebGLRefCountedObject : public WebGLDeletableObject +{ + friend class WebGLContext; + template friend void ClearLinkedList(LinkedList& list); + +private: + nsAutoRefCnt mWebGLRefCnt; + +public: + WebGLRefCountedObject(WebGLContext* webgl) + : WebGLDeletableObject(webgl) + { } ~WebGLRefCountedObject() { MOZ_ASSERT(mWebGLRefCnt == 0, "Destroying WebGL object still referenced by other WebGL" " objects."); - MOZ_ASSERT(mDeletionStatus == Deleted, - "Derived class destructor must call DeleteOnce()."); } // called by WebGLRefPtr @@ -129,14 +179,7 @@ public: MaybeDelete(); } - bool IsDeleted() const { - return mDeletionStatus == Deleted; - } - - bool IsDeleteRequested() const { - return mDeletionStatus != Default; - } - +protected: void DeleteOnce() { if (mDeletionStatus != Deleted) { static_cast(this)->Delete(); @@ -152,10 +195,6 @@ private: DeleteOnce(); } } - -protected: - nsAutoRefCnt mWebGLRefCnt; - DeletionStatus mDeletionStatus; }; /* This WebGLRefPtr class is meant to be used for references between WebGL @@ -259,21 +298,6 @@ protected: T* mRawPtr; }; -// This class is a mixin for objects that are tied to a specific -// context (which is to say, all of them). They provide initialization -// as well as comparison with the current context. -class WebGLContextBoundObject -{ -public: - explicit WebGLContextBoundObject(WebGLContext* webgl); - - bool IsCompatibleWithContext(const WebGLContext* other) const; - - WebGLContext* const mContext; -protected: - const uint32_t mContextGeneration; -}; - // this class is a mixin for GL objects that have dimensions // that we need to track. class WebGLRectangleObject diff --git a/dom/canvas/WebGLProgram.cpp b/dom/canvas/WebGLProgram.cpp index 8abf4edb6e4d..f80096d1ea70 100644 --- a/dom/canvas/WebGLProgram.cpp +++ b/dom/canvas/WebGLProgram.cpp @@ -443,7 +443,7 @@ CreateProgram(gl::GLContext* gl) } WebGLProgram::WebGLProgram(WebGLContext* webgl) - : WebGLContextBoundObject(webgl) + : WebGLRefCountedObject(webgl) , mGLName(CreateProgram(webgl->GL())) , mNumActiveTFOs(0) , mNextLink_TransformFeedbackBufferMode(LOCAL_GL_SEPARATE_ATTRIBS) diff --git a/dom/canvas/WebGLProgram.h b/dom/canvas/WebGLProgram.h index 1d1378b62bd7..17f3f31ca24f 100644 --- a/dom/canvas/WebGLProgram.h +++ b/dom/canvas/WebGLProgram.h @@ -130,7 +130,6 @@ class WebGLProgram final : public nsWrapperCache , public WebGLRefCountedObject , public LinkedListElement - , public WebGLContextBoundObject { friend class WebGLTransformFeedback; diff --git a/dom/canvas/WebGLQuery.cpp b/dom/canvas/WebGLQuery.cpp index 065fc6d3a071..a64a895a7f1b 100644 --- a/dom/canvas/WebGLQuery.cpp +++ b/dom/canvas/WebGLQuery.cpp @@ -40,7 +40,7 @@ GenQuery(gl::GLContext* gl) } WebGLQuery::WebGLQuery(WebGLContext* webgl) - : WebGLContextBoundObject(webgl) + : WebGLRefCountedObject(webgl) , mGLName(GenQuery(mContext->gl)) , mTarget(0) , mActiveSlot(nullptr) @@ -211,8 +211,7 @@ WebGLQuery::GetQueryParameter(GLenum pname, JS::MutableHandleValue retval) const bool WebGLQuery::IsQuery() const { - if (IsDeleted()) - return false; + MOZ_ASSERT(!IsDeleted()); if (!mTarget) return false; @@ -223,8 +222,7 @@ WebGLQuery::IsQuery() const void WebGLQuery::DeleteQuery() { - if (IsDeleted()) - return; + MOZ_ASSERT(!IsDeleteRequested()); if (mActiveSlot) { EndQuery(); diff --git a/dom/canvas/WebGLQuery.h b/dom/canvas/WebGLQuery.h index a0aa200fec5a..132e70ae97e8 100644 --- a/dom/canvas/WebGLQuery.h +++ b/dom/canvas/WebGLQuery.h @@ -18,7 +18,6 @@ class WebGLQuery final : public nsWrapperCache , public WebGLRefCountedObject , public LinkedListElement - , public WebGLContextBoundObject { friend class AvailableRunnable; friend class WebGLRefCountedObject; diff --git a/dom/canvas/WebGLRenderbuffer.cpp b/dom/canvas/WebGLRenderbuffer.cpp index 3200d6008ee7..dd0aa5d11636 100644 --- a/dom/canvas/WebGLRenderbuffer.cpp +++ b/dom/canvas/WebGLRenderbuffer.cpp @@ -47,7 +47,7 @@ EmulatePackedDepthStencil(gl::GLContext* gl) } WebGLRenderbuffer::WebGLRenderbuffer(WebGLContext* webgl) - : WebGLContextBoundObject(webgl) + : WebGLRefCountedObject(webgl) , mPrimaryRB( DoCreateRenderbuffer(webgl->gl) ) , mEmulatePackedDepthStencil( EmulatePackedDepthStencil(webgl->gl) ) , mSecondaryRB(0) diff --git a/dom/canvas/WebGLRenderbuffer.h b/dom/canvas/WebGLRenderbuffer.h index 1481441d4341..d16110375d1d 100644 --- a/dom/canvas/WebGLRenderbuffer.h +++ b/dom/canvas/WebGLRenderbuffer.h @@ -23,7 +23,6 @@ class WebGLRenderbuffer final , public WebGLRefCountedObject , public LinkedListElement , public WebGLRectangleObject - , public WebGLContextBoundObject , public WebGLFramebufferAttachable { friend class WebGLContext; diff --git a/dom/canvas/WebGLSampler.cpp b/dom/canvas/WebGLSampler.cpp index e782ccef6382..01795de3dbbf 100644 --- a/dom/canvas/WebGLSampler.cpp +++ b/dom/canvas/WebGLSampler.cpp @@ -12,7 +12,7 @@ namespace mozilla { WebGLSampler::WebGLSampler(WebGLContext* webgl, GLuint sampler) - : WebGLContextBoundObject(webgl) + : WebGLRefCountedObject(webgl) , mGLName(sampler) , mMinFilter(LOCAL_GL_NEAREST_MIPMAP_LINEAR) , mMagFilter(LOCAL_GL_LINEAR) diff --git a/dom/canvas/WebGLSampler.h b/dom/canvas/WebGLSampler.h index 34ffa565456f..282757df2bf4 100644 --- a/dom/canvas/WebGLSampler.h +++ b/dom/canvas/WebGLSampler.h @@ -17,7 +17,6 @@ class WebGLSampler final : public nsWrapperCache , public WebGLRefCountedObject , public LinkedListElement - , public WebGLContextBoundObject { friend class WebGLContext2; friend class WebGLTexture; diff --git a/dom/canvas/WebGLShader.cpp b/dom/canvas/WebGLShader.cpp index 9606505f32cc..edb2757fef9b 100644 --- a/dom/canvas/WebGLShader.cpp +++ b/dom/canvas/WebGLShader.cpp @@ -141,7 +141,7 @@ CreateShader(gl::GLContext* gl, GLenum type) } WebGLShader::WebGLShader(WebGLContext* webgl, GLenum type) - : WebGLContextBoundObject(webgl) + : WebGLRefCountedObject(webgl) , mGLName(CreateShader(webgl->GL(), type)) , mType(type) , mTranslationSuccessful(false) diff --git a/dom/canvas/WebGLShader.h b/dom/canvas/WebGLShader.h index 7cfa1624c37a..92ca3f8baaea 100644 --- a/dom/canvas/WebGLShader.h +++ b/dom/canvas/WebGLShader.h @@ -28,7 +28,6 @@ class WebGLShader final : public nsWrapperCache , public WebGLRefCountedObject , public LinkedListElement - , public WebGLContextBoundObject { friend class WebGLContext; friend class WebGLProgram; diff --git a/dom/canvas/WebGLSync.cpp b/dom/canvas/WebGLSync.cpp index d9cc56044055..c6988fba6de3 100644 --- a/dom/canvas/WebGLSync.cpp +++ b/dom/canvas/WebGLSync.cpp @@ -12,7 +12,7 @@ namespace mozilla { WebGLSync::WebGLSync(WebGLContext* webgl, GLenum condition, GLbitfield flags) - : WebGLContextBoundObject(webgl) + : WebGLRefCountedObject(webgl) { mContext->mSyncs.insertBack(this); mGLName = mContext->gl->fFenceSync(condition, flags); diff --git a/dom/canvas/WebGLSync.h b/dom/canvas/WebGLSync.h index 9893d5a76a23..7a31b9c606b5 100644 --- a/dom/canvas/WebGLSync.h +++ b/dom/canvas/WebGLSync.h @@ -16,7 +16,6 @@ class WebGLSync final : public nsWrapperCache , public WebGLRefCountedObject , public LinkedListElement - , public WebGLContextBoundObject { friend class WebGL2Context; diff --git a/dom/canvas/WebGLTexture.cpp b/dom/canvas/WebGLTexture.cpp index f491db3f906d..fcf208fe1c36 100644 --- a/dom/canvas/WebGLTexture.cpp +++ b/dom/canvas/WebGLTexture.cpp @@ -127,7 +127,7 @@ WebGLTexture::WrapObject(JSContext* cx, JS::Handle givenProto) { } WebGLTexture::WebGLTexture(WebGLContext* webgl, GLuint tex) - : WebGLContextBoundObject(webgl) + : WebGLRefCountedObject(webgl) , mGLName(tex) , mTarget(LOCAL_GL_NONE) , mFaceCount(0) diff --git a/dom/canvas/WebGLTexture.h b/dom/canvas/WebGLTexture.h index 89d278d352ae..1a2dd73ce0c1 100644 --- a/dom/canvas/WebGLTexture.h +++ b/dom/canvas/WebGLTexture.h @@ -57,7 +57,6 @@ class WebGLTexture final : public nsWrapperCache , public WebGLRefCountedObject , public LinkedListElement - , public WebGLContextBoundObject { // Friends friend class WebGLContext; diff --git a/dom/canvas/WebGLTransformFeedback.cpp b/dom/canvas/WebGLTransformFeedback.cpp index 2fa2752be879..6e5c0b745444 100644 --- a/dom/canvas/WebGLTransformFeedback.cpp +++ b/dom/canvas/WebGLTransformFeedback.cpp @@ -12,7 +12,7 @@ namespace mozilla { WebGLTransformFeedback::WebGLTransformFeedback(WebGLContext* webgl, GLuint tf) - : WebGLContextBoundObject(webgl) + : WebGLRefCountedObject(webgl) , mGLName(tf) , mIndexedBindings(webgl->mGLMaxTransformFeedbackSeparateAttribs) , mIsPaused(false) diff --git a/dom/canvas/WebGLTransformFeedback.h b/dom/canvas/WebGLTransformFeedback.h index e681242291a0..d97484a99b47 100644 --- a/dom/canvas/WebGLTransformFeedback.h +++ b/dom/canvas/WebGLTransformFeedback.h @@ -16,7 +16,6 @@ class WebGLTransformFeedback final : public nsWrapperCache , public WebGLRefCountedObject , public LinkedListElement - , public WebGLContextBoundObject { friend class ScopedDrawWithTransformFeedback; friend class WebGLContext; diff --git a/dom/canvas/WebGLVertexArray.cpp b/dom/canvas/WebGLVertexArray.cpp index 1b6f98813fe7..4669f9c3b8f5 100644 --- a/dom/canvas/WebGLVertexArray.cpp +++ b/dom/canvas/WebGLVertexArray.cpp @@ -21,7 +21,7 @@ WebGLVertexArray::WrapObject(JSContext* cx, JS::Handle givenProto) } WebGLVertexArray::WebGLVertexArray(WebGLContext* webgl) - : WebGLContextBoundObject(webgl) + : WebGLRefCountedObject(webgl) , mGLName(0) { mContext->mVertexArrays.insertBack(this); @@ -50,7 +50,7 @@ WebGLVertexArray::Delete() } bool -WebGLVertexArray::IsVertexArray() +WebGLVertexArray::IsVertexArray() const { return IsVertexArrayImpl(); } diff --git a/dom/canvas/WebGLVertexArray.h b/dom/canvas/WebGLVertexArray.h index 9d2d0ff67e49..b49ce26f319b 100644 --- a/dom/canvas/WebGLVertexArray.h +++ b/dom/canvas/WebGLVertexArray.h @@ -23,7 +23,6 @@ class WebGLVertexArray : public nsWrapperCache , public WebGLRefCountedObject , public LinkedListElement - , public WebGLContextBoundObject { public: static WebGLVertexArray* Create(WebGLContext* webgl); @@ -44,7 +43,7 @@ public: // Implement parent classes: void Delete(); - bool IsVertexArray(); + bool IsVertexArray() const; WebGLContext* GetParentObject() const { return mContext; @@ -67,7 +66,7 @@ protected: virtual void GenVertexArray() = 0; virtual void BindVertexArrayImpl() = 0; virtual void DeleteImpl() = 0; - virtual bool IsVertexArrayImpl() = 0; + virtual bool IsVertexArrayImpl() const = 0; GLuint mGLName; nsTArray mAttribs; diff --git a/dom/canvas/WebGLVertexArrayFake.cpp b/dom/canvas/WebGLVertexArrayFake.cpp index 4c9482dfbd4c..ee9df6dacba5 100644 --- a/dom/canvas/WebGLVertexArrayFake.cpp +++ b/dom/canvas/WebGLVertexArrayFake.cpp @@ -62,7 +62,7 @@ WebGLVertexArrayFake::DeleteImpl() } bool -WebGLVertexArrayFake::IsVertexArrayImpl() +WebGLVertexArrayFake::IsVertexArrayImpl() const { return mIsVAO; } diff --git a/dom/canvas/WebGLVertexArrayFake.h b/dom/canvas/WebGLVertexArrayFake.h index 6f970c965747..b7dc569e1587 100644 --- a/dom/canvas/WebGLVertexArrayFake.h +++ b/dom/canvas/WebGLVertexArrayFake.h @@ -19,7 +19,7 @@ protected: virtual void BindVertexArrayImpl() override; virtual void DeleteImpl() override; virtual void GenVertexArray() override {}; - virtual bool IsVertexArrayImpl() override; + virtual bool IsVertexArrayImpl() const override; private: explicit WebGLVertexArrayFake(WebGLContext* webgl); diff --git a/dom/canvas/WebGLVertexArrayGL.cpp b/dom/canvas/WebGLVertexArrayGL.cpp index 2ba38330ecdf..aa7313150f7c 100644 --- a/dom/canvas/WebGLVertexArrayGL.cpp +++ b/dom/canvas/WebGLVertexArrayGL.cpp @@ -47,7 +47,7 @@ WebGLVertexArrayGL::GenVertexArray() } bool -WebGLVertexArrayGL::IsVertexArrayImpl() +WebGLVertexArrayGL::IsVertexArrayImpl() const { gl::GLContext* gl = mContext->gl; if (gl->WorkAroundDriverBugs()) diff --git a/dom/canvas/WebGLVertexArrayGL.h b/dom/canvas/WebGLVertexArrayGL.h index c64291033e35..8ab172470dec 100644 --- a/dom/canvas/WebGLVertexArrayGL.h +++ b/dom/canvas/WebGLVertexArrayGL.h @@ -19,7 +19,7 @@ public: virtual void DeleteImpl() override; virtual void BindVertexArrayImpl() override; virtual void GenVertexArray() override; - virtual bool IsVertexArrayImpl() override; + virtual bool IsVertexArrayImpl() const override; protected: explicit WebGLVertexArrayGL(WebGLContext* webgl);