diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index 81c48d0fcb9e..dcb639c128bb 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -297,7 +297,6 @@ NS_INTERFACE_MAP_BEGIN(nsTextMetrics) NS_INTERFACE_MAP_END struct nsCanvasBidiProcessor; -class CanvasRenderingContext2DUserData; /** ** nsCanvasRenderingContext2D @@ -378,7 +377,6 @@ public: nsRefPtr mPath; }; friend class PathAutoSaveRestore; - friend class CanvasRenderingContext2DUserData; protected: nsresult GetImageDataArray(JSContext* aCx, int32_t aX, int32_t aY, @@ -441,8 +439,6 @@ protected: // the canvas element we're a context of nsCOMPtr mCanvasElement; - nsTArray mUserDatas; - nsHTMLCanvasElement *HTMLCanvasElement() { return static_cast(mCanvasElement.get()); } @@ -759,40 +755,6 @@ protected: friend struct nsCanvasBidiProcessor; }; -class CanvasRenderingContext2DUserData : public LayerUserData { -public: - CanvasRenderingContext2DUserData(nsCanvasRenderingContext2D *aContext) - : mContext(aContext) - { - aContext->mUserDatas.AppendElement(this); - } - ~CanvasRenderingContext2DUserData() - { - if (mContext) { - mContext->mUserDatas.RemoveElement(this); - } - } - static void DidTransactionCallback(void* aData) - { - CanvasRenderingContext2DUserData* self = - static_cast(aData); - if (self->mContext) { - self->mContext->MarkContextClean(); - } - } - bool IsForContext(nsCanvasRenderingContext2D *aContext) - { - return mContext == aContext; - } - void Forget() - { - mContext = nsnull; - } - -private: - nsCanvasRenderingContext2D *mContext; -}; - NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCanvasRenderingContext2D) NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCanvasRenderingContext2D) @@ -848,10 +810,6 @@ nsCanvasRenderingContext2D::nsCanvasRenderingContext2D() nsCanvasRenderingContext2D::~nsCanvasRenderingContext2D() { Reset(); - // Drop references from all CanvasRenderingContext2DUserDatas to this context - for (PRUint32 i = 0; i < mUserDatas.Length(); ++i) { - mUserDatas[i]->Forget(); - } sNumLivingContexts--; if (!sNumLivingContexts) { delete[] sUnpremultiplyTable; @@ -4202,6 +4160,19 @@ nsCanvasRenderingContext2D::SetMozImageSmoothingEnabled(bool val) static PRUint8 g2DContextLayerUserData; +class CanvasRenderingContext2DUserData : public LayerUserData { +public: + CanvasRenderingContext2DUserData(nsHTMLCanvasElement *aContent) + : mContent(aContent) {} + static void DidTransactionCallback(void* aData) + { + static_cast(aData)->mContent->MarkContextClean(); + } + +private: + nsRefPtr mContent; +}; + already_AddRefed nsCanvasRenderingContext2D::GetCanvasLayer(nsDisplayListBuilder* aBuilder, CanvasLayer *aOldLayer, @@ -4210,14 +4181,10 @@ nsCanvasRenderingContext2D::GetCanvasLayer(nsDisplayListBuilder* aBuilder, if (!EnsureSurface()) return nsnull; - if (!mResetLayer && aOldLayer) { - CanvasRenderingContext2DUserData* userData = - static_cast( - aOldLayer->GetUserData(&g2DContextLayerUserData)); - if (userData && userData->IsForContext(this)) { - NS_ADDREF(aOldLayer); - return aOldLayer; - } + if (!mResetLayer && aOldLayer && + aOldLayer->HasUserData(&g2DContextLayerUserData)) { + NS_ADDREF(aOldLayer); + return aOldLayer; } nsRefPtr canvasLayer = aManager->CreateCanvasLayer(); @@ -4239,7 +4206,7 @@ nsCanvasRenderingContext2D::GetCanvasLayer(nsDisplayListBuilder* aBuilder, // releasing the reference to the element. // The userData will receive DidTransactionCallbacks, which flush the // the invalidation state to indicate that the canvas is up to date. - userData = new CanvasRenderingContext2DUserData(this); + userData = new CanvasRenderingContext2DUserData(HTMLCanvasElement()); canvasLayer->SetDidTransactionCallback( CanvasRenderingContext2DUserData::DidTransactionCallback, userData); } diff --git a/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp b/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp index 72829a344edd..a0d1cdd28743 100644 --- a/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp @@ -351,7 +351,6 @@ NS_INTERFACE_MAP_BEGIN(nsTextMetricsAzure) NS_INTERFACE_MAP_END struct nsCanvasBidiProcessorAzure; -class CanvasRenderingContext2DUserData; // Cap sigma to avoid overly large temp surfaces. static const Float SIGMA_MAX = 100; @@ -417,8 +416,6 @@ public: nsresult LineTo(const Point& aPoint); nsresult BezierTo(const Point& aCP1, const Point& aCP2, const Point& aCP3); - friend class CanvasRenderingContext2DUserData; - protected: nsresult GetImageDataArray(JSContext* aCx, int32_t aX, int32_t aY, uint32_t aWidth, uint32_t aHeight, @@ -504,8 +501,6 @@ protected: // the canvas element we're a context of nsCOMPtr mCanvasElement; - nsTArray mUserDatas; - // If mCanvasElement is not provided, then a docshell is nsCOMPtr mDocShell; @@ -938,40 +933,6 @@ protected: friend struct nsCanvasBidiProcessorAzure; }; -class CanvasRenderingContext2DUserData : public LayerUserData { -public: - CanvasRenderingContext2DUserData(nsCanvasRenderingContext2DAzure *aContext) - : mContext(aContext) - { - aContext->mUserDatas.AppendElement(this); - } - ~CanvasRenderingContext2DUserData() - { - if (mContext) { - mContext->mUserDatas.RemoveElement(this); - } - } - static void DidTransactionCallback(void* aData) - { - CanvasRenderingContext2DUserData* self = - static_cast(aData); - if (self->mContext) { - self->mContext->MarkContextClean(); - } - } - bool IsForContext(nsCanvasRenderingContext2DAzure *aContext) - { - return mContext == aContext; - } - void Forget() - { - mContext = nsnull; - } - -private: - nsCanvasRenderingContext2DAzure *mContext; -}; - NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCanvasRenderingContext2DAzure) NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCanvasRenderingContext2DAzure) @@ -1039,10 +1000,6 @@ nsCanvasRenderingContext2DAzure::nsCanvasRenderingContext2DAzure() nsCanvasRenderingContext2DAzure::~nsCanvasRenderingContext2DAzure() { Reset(); - // Drop references from all CanvasRenderingContext2DUserDatas to this context - for (PRUint32 i = 0; i < mUserDatas.Length(); ++i) { - mUserDatas[i]->Forget(); - } sNumLivingContexts--; if (!sNumLivingContexts) { delete[] sUnpremultiplyTable; @@ -4388,6 +4345,19 @@ nsCanvasRenderingContext2DAzure::SetMozImageSmoothingEnabled(bool val) static PRUint8 g2DContextLayerUserData; +class CanvasRenderingContext2DUserData : public LayerUserData { +public: + CanvasRenderingContext2DUserData(nsHTMLCanvasElement *aContent) + : mContent(aContent) {} + static void DidTransactionCallback(void* aData) + { + static_cast(aData)->mContent->MarkContextClean(); + } + +private: + nsRefPtr mContent; +}; + already_AddRefed nsCanvasRenderingContext2DAzure::GetCanvasLayer(nsDisplayListBuilder* aBuilder, CanvasLayer *aOldLayer, @@ -4401,20 +4371,16 @@ nsCanvasRenderingContext2DAzure::GetCanvasLayer(nsDisplayListBuilder* aBuilder, mTarget->Flush(); } - if (!mResetLayer && aOldLayer) { - CanvasRenderingContext2DUserData* userData = - static_cast( - aOldLayer->GetUserData(&g2DContextLayerUserData)); - if (userData && userData->IsForContext(this)) { + if (!mResetLayer && aOldLayer && + aOldLayer->HasUserData(&g2DContextLayerUserData)) { NS_ADDREF(aOldLayer); return aOldLayer; - } } nsRefPtr canvasLayer = aManager->CreateCanvasLayer(); if (!canvasLayer) { - NS_WARNING("CreateCanvasLayer returned null!"); - return nsnull; + NS_WARNING("CreateCanvasLayer returned null!"); + return nsnull; } CanvasRenderingContext2DUserData *userData = nsnull; if (aBuilder->IsPaintingToWindow()) { @@ -4430,7 +4396,7 @@ nsCanvasRenderingContext2DAzure::GetCanvasLayer(nsDisplayListBuilder* aBuilder, // releasing the reference to the element. // The userData will receive DidTransactionCallbacks, which flush the // the invalidation state to indicate that the canvas is up to date. - userData = new CanvasRenderingContext2DUserData(this); + userData = new CanvasRenderingContext2DUserData(HTMLCanvasElement()); canvasLayer->SetDidTransactionCallback( CanvasRenderingContext2DUserData::DidTransactionCallback, userData); }