Bug 856472: Wrappercache CanvasPattern r=bz

This commit is contained in:
David Zbarsky 2013-04-26 10:55:37 -04:00
Родитель 842496f8c2
Коммит 6ea0ae0156
5 изменённых файлов: 76 добавлений и 15 удалений

Просмотреть файл

@ -8,6 +8,7 @@
#include "mozilla/dom/CanvasRenderingContext2DBinding.h" #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
#include "mozilla/RefPtr.h" #include "mozilla/RefPtr.h"
#include "nsISupports.h" #include "nsISupports.h"
#include "nsWrapperCache.h"
#define NS_CANVASPATTERNAZURE_PRIVATE_IID \ #define NS_CANVASPATTERNAZURE_PRIVATE_IID \
{0xc9bacc25, 0x28da, 0x421e, {0x9a, 0x4b, 0xbb, 0xd6, 0x93, 0x05, 0x12, 0xbc}} {0xc9bacc25, 0x28da, 0x421e, {0x9a, 0x4b, 0xbb, 0xd6, 0x93, 0x05, 0x12, 0xbc}}
@ -20,11 +21,13 @@ class SourceSurface;
namespace dom { namespace dom {
class CanvasPattern MOZ_FINAL : public nsISupports class CanvasPattern MOZ_FINAL : public nsISupports,
public nsWrapperCache
{ {
public: public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_CANVASPATTERNAZURE_PRIVATE_IID) NS_DECLARE_STATIC_IID_ACCESSOR(NS_CANVASPATTERNAZURE_PRIVATE_IID)
NS_DECL_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CanvasPattern)
enum RepeatMode enum RepeatMode
{ {
@ -34,17 +37,20 @@ public:
NOREPEAT NOREPEAT
}; };
CanvasPattern(mozilla::gfx::SourceSurface* aSurface, CanvasPattern(CanvasRenderingContext2D* aContext,
gfx::SourceSurface* aSurface,
RepeatMode aRepeat, RepeatMode aRepeat,
nsIPrincipal* principalForSecurityCheck, nsIPrincipal* principalForSecurityCheck,
bool forceWriteOnly, bool forceWriteOnly,
bool CORSUsed) bool CORSUsed)
: mSurface(aSurface) : mContext(aContext)
, mSurface(aSurface)
, mRepeat(aRepeat) , mRepeat(aRepeat)
, mPrincipal(principalForSecurityCheck) , mPrincipal(principalForSecurityCheck)
, mForceWriteOnly(forceWriteOnly) , mForceWriteOnly(forceWriteOnly)
, mCORSUsed(CORSUsed) , mCORSUsed(CORSUsed)
{ {
SetIsDOMBinding();
} }
JSObject* WrapObject(JSContext* aCx, JSObject* aScope) JSObject* WrapObject(JSContext* aCx, JSObject* aScope)
@ -52,7 +58,13 @@ public:
return CanvasPatternBinding::Wrap(aCx, aScope, this); return CanvasPatternBinding::Wrap(aCx, aScope, this);
} }
mozilla::RefPtr<mozilla::gfx::SourceSurface> mSurface; CanvasRenderingContext2D* GetParentObject()
{
return mContext;
}
nsRefPtr<CanvasRenderingContext2D> mContext;
RefPtr<gfx::SourceSurface> mSurface;
const RepeatMode mRepeat; const RepeatMode mRepeat;
nsCOMPtr<nsIPrincipal> mPrincipal; nsCOMPtr<nsIPrincipal> mPrincipal;
const bool mForceWriteOnly; const bool mForceWriteOnly;

Просмотреть файл

@ -405,10 +405,13 @@ NS_INTERFACE_MAP_END
NS_DEFINE_STATIC_IID_ACCESSOR(CanvasPattern, NS_CANVASPATTERNAZURE_PRIVATE_IID) NS_DEFINE_STATIC_IID_ACCESSOR(CanvasPattern, NS_CANVASPATTERNAZURE_PRIVATE_IID)
NS_IMPL_ADDREF(CanvasPattern) NS_IMPL_CYCLE_COLLECTING_ADDREF(CanvasPattern)
NS_IMPL_RELEASE(CanvasPattern) NS_IMPL_CYCLE_COLLECTING_RELEASE(CanvasPattern)
NS_INTERFACE_MAP_BEGIN(CanvasPattern) NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(CanvasPattern, mContext)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CanvasPattern)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(mozilla::dom::CanvasPattern) NS_INTERFACE_MAP_ENTRY(mozilla::dom::CanvasPattern)
NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
@ -464,7 +467,25 @@ private:
NS_IMPL_CYCLE_COLLECTING_ADDREF(CanvasRenderingContext2D) NS_IMPL_CYCLE_COLLECTING_ADDREF(CanvasRenderingContext2D)
NS_IMPL_CYCLE_COLLECTING_RELEASE(CanvasRenderingContext2D) NS_IMPL_CYCLE_COLLECTING_RELEASE(CanvasRenderingContext2D)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(CanvasRenderingContext2D, mCanvasElement) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CanvasRenderingContext2D)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCanvasElement)
for (uint32_t i = 0; i < tmp->mStyleStack.Length(); i++) {
ImplCycleCollectionUnlink(tmp->mStyleStack[i].patternStyles[STYLE_STROKE]);
ImplCycleCollectionUnlink(tmp->mStyleStack[i].patternStyles[STYLE_FILL]);
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CanvasRenderingContext2D)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCanvasElement)
for (uint32_t i = 0; i < tmp->mStyleStack.Length(); i++) {
ImplCycleCollectionTraverse(cb, tmp->mStyleStack[i].patternStyles[STYLE_STROKE], "Stroke CanvasPattern");
ImplCycleCollectionTraverse(cb, tmp->mStyleStack[i].patternStyles[STYLE_FILL], "Fill CanvasPattern");
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(CanvasRenderingContext2D)
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(CanvasRenderingContext2D) NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(CanvasRenderingContext2D)
if (nsCCUncollectableMarker::sGeneration && tmp->IsBlack()) { if (nsCCUncollectableMarker::sGeneration && tmp->IsBlack()) {
@ -1400,7 +1421,7 @@ CanvasRenderingContext2D::CreatePattern(const HTMLImageOrCanvasOrVideoElement& e
RefPtr<SourceSurface> srcSurf = srcCanvas->GetSurfaceSnapshot(); RefPtr<SourceSurface> srcSurf = srcCanvas->GetSurfaceSnapshot();
nsRefPtr<CanvasPattern> pat = nsRefPtr<CanvasPattern> pat =
new CanvasPattern(srcSurf, repeatMode, htmlElement->NodePrincipal(), canvas->IsWriteOnly(), false); new CanvasPattern(this, srcSurf, repeatMode, htmlElement->NodePrincipal(), canvas->IsWriteOnly(), false);
return pat.forget(); return pat.forget();
} }
@ -1431,7 +1452,7 @@ CanvasRenderingContext2D::CreatePattern(const HTMLImageOrCanvasOrVideoElement& e
gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(mTarget, res.mSurface); gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(mTarget, res.mSurface);
nsRefPtr<CanvasPattern> pat = nsRefPtr<CanvasPattern> pat =
new CanvasPattern(srcSurf, repeatMode, res.mPrincipal, new CanvasPattern(this, srcSurf, repeatMode, res.mPrincipal,
res.mIsWriteOnly, res.mCORSUsed); res.mIsWriteOnly, res.mCORSUsed);
return pat.forget(); return pat.forget();

Просмотреть файл

@ -105,6 +105,7 @@ MOCHITEST_FILES = \
test_bug613794.html \ test_bug613794.html \
test_bug753758.html \ test_bug753758.html \
test_bug764125.html \ test_bug764125.html \
test_bug856472.html \
test_drawImage_edge_cases.html \ test_drawImage_edge_cases.html \
test_drawImage_document_domain.html \ test_drawImage_document_domain.html \
test_mozDashOffset.html \ test_mozDashOffset.html \

Просмотреть файл

@ -0,0 +1,31 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=856472
-->
<head>
<title>Test for Bug 856472</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=856472">Mozilla Bug 856472</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script>
/** Test for Bug 856472 **/
var c = document.createElement("canvas");
var ctx = c.getContext("2d");
var pattern = ctx.createPattern(c, null);
pattern.x = 1;
ctx.fillStyle = pattern;
is(ctx.fillStyle.x, 1, "CanvasPattern stored as fillstyle drops expandos");
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -150,10 +150,6 @@ DOMInterfaces = {
'headerFile': 'BatteryManager.h' 'headerFile': 'BatteryManager.h'
}, },
'CanvasPattern': {
'wrapperCache': False,
},
'CanvasRenderingContext2D': { 'CanvasRenderingContext2D': {
'implicitJSContext': [ 'implicitJSContext': [
'createImageData', 'getImageData', 'strokeStyle', 'createImageData', 'getImageData', 'strokeStyle',