summaryrefslogtreecommitdiffstats
path: root/dom/canvas
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-07-20 18:08:16 +0200
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-07-22 12:21:53 +0200
commitd3406cafff5e5c284f07419043eec4ae810db63a (patch)
tree1b3b6163368fec80db2de01f6648a0c881d15afa /dom/canvas
parent0cd2ef552db767ada217c3f61fde65dc5cecc1ef (diff)
downloadUXP-d3406cafff5e5c284f07419043eec4ae810db63a.tar
UXP-d3406cafff5e5c284f07419043eec4ae810db63a.tar.gz
UXP-d3406cafff5e5c284f07419043eec4ae810db63a.tar.lz
UXP-d3406cafff5e5c284f07419043eec4ae810db63a.tar.xz
UXP-d3406cafff5e5c284f07419043eec4ae810db63a.zip
Use WeakPtr for extension parent pointer.
Diffstat (limited to 'dom/canvas')
-rw-r--r--dom/canvas/WebGLContext.h3
-rw-r--r--dom/canvas/WebGLExtensionDebugShaders.cpp7
-rw-r--r--dom/canvas/WebGLExtensionDisjointTimerQuery.cpp42
-rw-r--r--dom/canvas/WebGLExtensionDrawBuffers.cpp4
-rw-r--r--dom/canvas/WebGLExtensionInstancedArrays.cpp18
-rw-r--r--dom/canvas/WebGLExtensionLoseContext.cpp2
-rw-r--r--dom/canvas/WebGLExtensionVertexArray.cpp8
-rw-r--r--dom/canvas/WebGLObjectModel.h4
8 files changed, 55 insertions, 33 deletions
diff --git a/dom/canvas/WebGLContext.h b/dom/canvas/WebGLContext.h
index 8a20237ff..0510e6898 100644
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -20,6 +20,7 @@
#include "mozilla/gfx/2D.h"
#include "mozilla/LinkedList.h"
#include "mozilla/UniquePtr.h"
+#include "mozilla/WeakPtr.h"
#include "nsCycleCollectionNoteChild.h"
#include "nsICanvasRenderingContextInternal.h"
#include "nsLayoutUtils.h"
@@ -299,6 +300,7 @@ class WebGLContext
, public WebGLContextUnchecked
, public WebGLRectangleObject
, public nsWrapperCache
+ , public SupportsWeakPtr<WebGLContext>
{
friend class ScopedDrawHelper;
friend class ScopedDrawWithTransformFeedback;
@@ -342,6 +344,7 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(WebGLContext,
nsIDOMWebGLRenderingContext)
+ MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLContext)
virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override = 0;
diff --git a/dom/canvas/WebGLExtensionDebugShaders.cpp b/dom/canvas/WebGLExtensionDebugShaders.cpp
index 75880465e..8399aeb95 100644
--- a/dom/canvas/WebGLExtensionDebugShaders.cpp
+++ b/dom/canvas/WebGLExtensionDebugShaders.cpp
@@ -29,15 +29,10 @@ WebGLExtensionDebugShaders::GetTranslatedShaderSource(const WebGLShader& shader,
{
retval.SetIsVoid(true);
- if (mIsLost) {
- mContext->ErrorInvalidOperation("%s: Extension is lost.",
- "getTranslatedShaderSource");
+ if (mIsLost || !mContext) {
return;
}
- if (mContext->IsContextLost())
- return;
-
if (!mContext->ValidateObject("getShaderTranslatedSource: shader", shader))
return;
diff --git a/dom/canvas/WebGLExtensionDisjointTimerQuery.cpp b/dom/canvas/WebGLExtensionDisjointTimerQuery.cpp
index e2e34f14e..da76eeb2d 100644
--- a/dom/canvas/WebGLExtensionDisjointTimerQuery.cpp
+++ b/dom/canvas/WebGLExtensionDisjointTimerQuery.cpp
@@ -40,8 +40,10 @@ void
WebGLExtensionDisjointTimerQuery::DeleteQueryEXT(WebGLQuery* query) const
{
const char funcName[] = "deleteQueryEXT";
- if (mIsLost)
- return;
+
+ if (mIsLost || !mContext) {
+ return;
+ }
mContext->DeleteQuery(query, funcName);
}
@@ -50,8 +52,10 @@ bool
WebGLExtensionDisjointTimerQuery::IsQueryEXT(const WebGLQuery* query) const
{
const char funcName[] = "isQueryEXT";
- if (mIsLost)
- return false;
+
+ if (mIsLost || !mContext) {
+ return false;
+ }
return mContext->IsQuery(query, funcName);
}
@@ -60,8 +64,10 @@ void
WebGLExtensionDisjointTimerQuery::BeginQueryEXT(GLenum target, WebGLQuery& query) const
{
const char funcName[] = "beginQueryEXT";
- if (mIsLost)
- return;
+
+ if (mIsLost || !mContext) {
+ return;
+ }
mContext->BeginQuery(target, query, funcName);
}
@@ -70,8 +76,10 @@ void
WebGLExtensionDisjointTimerQuery::EndQueryEXT(GLenum target) const
{
const char funcName[] = "endQueryEXT";
- if (mIsLost)
- return;
+
+ if (mIsLost || !mContext) {
+ return;
+ }
mContext->EndQuery(target, funcName);
}
@@ -80,8 +88,10 @@ void
WebGLExtensionDisjointTimerQuery::QueryCounterEXT(WebGLQuery& query, GLenum target) const
{
const char funcName[] = "queryCounterEXT";
- if (mIsLost)
- return;
+
+ if (mIsLost || !mContext) {
+ return;
+ }
if (!mContext->ValidateObject(funcName, query))
return;
@@ -95,8 +105,10 @@ WebGLExtensionDisjointTimerQuery::GetQueryEXT(JSContext* cx, GLenum target, GLen
{
const char funcName[] = "getQueryEXT";
retval.setNull();
- if (mIsLost)
- return;
+
+ if (mIsLost || !mContext) {
+ return;
+ }
mContext->GetQuery(cx, target, pname, retval, funcName);
}
@@ -108,8 +120,10 @@ WebGLExtensionDisjointTimerQuery::GetQueryObjectEXT(JSContext* cx,
{
const char funcName[] = "getQueryObjectEXT";
retval.setNull();
- if (mIsLost)
- return;
+
+ if (mIsLost || !mContext) {
+ return;
+ }
mContext->GetQueryParameter(cx, query, pname, retval, funcName);
}
diff --git a/dom/canvas/WebGLExtensionDrawBuffers.cpp b/dom/canvas/WebGLExtensionDrawBuffers.cpp
index 27aa76cc7..6f386621f 100644
--- a/dom/canvas/WebGLExtensionDrawBuffers.cpp
+++ b/dom/canvas/WebGLExtensionDrawBuffers.cpp
@@ -36,7 +36,9 @@ void
WebGLExtensionDrawBuffers::DrawBuffersWEBGL(const dom::Sequence<GLenum>& buffers)
{
if (mIsLost) {
- mContext->ErrorInvalidOperation("drawBuffersWEBGL: Extension is lost.");
+ if (mContext) {
+ mContext->ErrorInvalidOperation("drawBuffersWEBGL: Extension is lost.");
+ }
return;
}
diff --git a/dom/canvas/WebGLExtensionInstancedArrays.cpp b/dom/canvas/WebGLExtensionInstancedArrays.cpp
index 10d0533fe..22b3ec12c 100644
--- a/dom/canvas/WebGLExtensionInstancedArrays.cpp
+++ b/dom/canvas/WebGLExtensionInstancedArrays.cpp
@@ -28,8 +28,10 @@ WebGLExtensionInstancedArrays::DrawArraysInstancedANGLE(GLenum mode,
GLsizei primcount)
{
if (mIsLost) {
- mContext->ErrorInvalidOperation("%s: Extension is lost.",
- "drawArraysInstancedANGLE");
+ if (mContext) {
+ mContext->ErrorInvalidOperation("%s: Extension is lost.",
+ "drawArraysInstancedANGLE");
+ }
return;
}
@@ -44,8 +46,10 @@ WebGLExtensionInstancedArrays::DrawElementsInstancedANGLE(GLenum mode,
GLsizei primcount)
{
if (mIsLost) {
- mContext->ErrorInvalidOperation("%s: Extension is lost.",
- "drawElementsInstancedANGLE");
+ if (mContext) {
+ mContext->ErrorInvalidOperation("%s: Extension is lost.",
+ "drawElementsInstancedANGLE");
+ }
return;
}
@@ -57,8 +61,10 @@ WebGLExtensionInstancedArrays::VertexAttribDivisorANGLE(GLuint index,
GLuint divisor)
{
if (mIsLost) {
- mContext->ErrorInvalidOperation("%s: Extension is lost.",
- "vertexAttribDivisorANGLE");
+ if (mContext) {
+ mContext->ErrorInvalidOperation("%s: Extension is lost.",
+ "vertexAttribDivisorANGLE");
+ }
return;
}
diff --git a/dom/canvas/WebGLExtensionLoseContext.cpp b/dom/canvas/WebGLExtensionLoseContext.cpp
index 020731e63..41f1633d8 100644
--- a/dom/canvas/WebGLExtensionLoseContext.cpp
+++ b/dom/canvas/WebGLExtensionLoseContext.cpp
@@ -22,12 +22,14 @@ WebGLExtensionLoseContext::~WebGLExtensionLoseContext()
void
WebGLExtensionLoseContext::LoseContext()
{
+ if (!mContext) return;
mContext->LoseContext();
}
void
WebGLExtensionLoseContext::RestoreContext()
{
+ if (!mContext) return;
mContext->RestoreContext();
}
diff --git a/dom/canvas/WebGLExtensionVertexArray.cpp b/dom/canvas/WebGLExtensionVertexArray.cpp
index 0984582f5..39aa96801 100644
--- a/dom/canvas/WebGLExtensionVertexArray.cpp
+++ b/dom/canvas/WebGLExtensionVertexArray.cpp
@@ -25,7 +25,7 @@ WebGLExtensionVertexArray::~WebGLExtensionVertexArray()
already_AddRefed<WebGLVertexArray>
WebGLExtensionVertexArray::CreateVertexArrayOES()
{
- if (mIsLost)
+ if (mIsLost || !mContext)
return nullptr;
return mContext->CreateVertexArray();
@@ -34,7 +34,7 @@ WebGLExtensionVertexArray::CreateVertexArrayOES()
void
WebGLExtensionVertexArray::DeleteVertexArrayOES(WebGLVertexArray* array)
{
- if (mIsLost)
+ if (mIsLost || !mContext)
return;
mContext->DeleteVertexArray(array);
@@ -43,7 +43,7 @@ WebGLExtensionVertexArray::DeleteVertexArrayOES(WebGLVertexArray* array)
bool
WebGLExtensionVertexArray::IsVertexArrayOES(const WebGLVertexArray* array)
{
- if (mIsLost)
+ if (mIsLost || !mContext)
return false;
return mContext->IsVertexArray(array);
@@ -52,7 +52,7 @@ WebGLExtensionVertexArray::IsVertexArrayOES(const WebGLVertexArray* array)
void
WebGLExtensionVertexArray::BindVertexArrayOES(WebGLVertexArray* array)
{
- if (mIsLost)
+ if (mIsLost || !mContext)
return;
mContext->BindVertexArray(array);
diff --git a/dom/canvas/WebGLObjectModel.h b/dom/canvas/WebGLObjectModel.h
index b18b790c0..6371c7b03 100644
--- a/dom/canvas/WebGLObjectModel.h
+++ b/dom/canvas/WebGLObjectModel.h
@@ -6,8 +6,8 @@
#ifndef WEBGLOBJECTMODEL_H_
#define WEBGLOBJECTMODEL_H_
+#include "mozilla/WeakPtr.h"
#include "nsCycleCollectionNoteChild.h"
-
#include "WebGLTypes.h"
namespace mozilla {
@@ -24,7 +24,7 @@ class WebGLContext;
class WebGLContextBoundObject
{
public:
- WebGLContext* const mContext;
+ const WeakPtr<WebGLContext> mContext;
private:
const uint32_t mContextGeneration;