From 4c74ef0ee644b3415426bc073c90da570a32efe8 Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Fri, 15 Oct 2010 12:20:22 +0200 Subject: [PATCH] Bug 592118 - Don't stack-allocate gfxContexts that are passed to other functions. r=roc a=blocking2.0:final --HG-- extra : rebase_source : efcf3b58c953ea8ec8cad45f4b0ffa0b898a2397 --- content/svg/content/src/nsSVGFilters.cpp | 4 +- content/svg/content/src/nsSVGPathElement.cpp | 11 ++--- gfx/thebes/gfxUtils.cpp | 6 +-- layout/generic/crashtests/592118.html | 4 ++ layout/generic/crashtests/crashtests.list | 1 + .../svg/base/src/nsSVGPathGeometryFrame.cpp | 41 ++++++++++--------- 6 files changed, 38 insertions(+), 29 deletions(-) create mode 100755 layout/generic/crashtests/592118.html diff --git a/content/svg/content/src/nsSVGFilters.cpp b/content/svg/content/src/nsSVGFilters.cpp index ed094833de79..8172ab52decd 100644 --- a/content/svg/content/src/nsSVGFilters.cpp +++ b/content/svg/content/src/nsSVGFilters.cpp @@ -5565,8 +5565,8 @@ nsSVGFEImageElement::Filter(nsSVGFilterInstance *instance, gfxMatrix TM = viewBoxTM * xyTM; - gfxContext ctx(aTarget->mImage); - nsSVGUtils::CompositePatternMatrix(&ctx, thebesPattern, TM, nativeWidth, nativeHeight, 1.0); + nsRefPtr ctx = new gfxContext(aTarget->mImage); + nsSVGUtils::CompositePatternMatrix(ctx, thebesPattern, TM, nativeWidth, nativeHeight, 1.0); } return NS_OK; diff --git a/content/svg/content/src/nsSVGPathElement.cpp b/content/svg/content/src/nsSVGPathElement.cpp index 1a0e4f9da019..692900f453ed 100644 --- a/content/svg/content/src/nsSVGPathElement.cpp +++ b/content/svg/content/src/nsSVGPathElement.cpp @@ -1042,11 +1042,12 @@ nsSVGPathList::Playback(gfxContext *aCtx) already_AddRefed nsSVGPathList::GetFlattenedPath(const gfxMatrix& aMatrix) { - gfxContext ctx(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); + nsRefPtr ctx = + new gfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); - ctx.SetMatrix(aMatrix); - Playback(&ctx); - ctx.IdentityMatrix(); + ctx->SetMatrix(aMatrix); + Playback(ctx); + ctx->IdentityMatrix(); - return ctx.GetFlattenedPath(); + return ctx->GetFlattenedPath(); } diff --git a/gfx/thebes/gfxUtils.cpp b/gfx/thebes/gfxUtils.cpp index c8334c68af2f..051cd109f118 100644 --- a/gfx/thebes/gfxUtils.cpp +++ b/gfx/thebes/gfxUtils.cpp @@ -270,9 +270,9 @@ CreateSamplingRestrictedDrawable(gfxDrawable* aDrawable, if (!temp || temp->CairoStatus()) return nsnull; - gfxContext tmpCtx(temp); - tmpCtx.SetOperator(OptimalFillOperator()); - aDrawable->Draw(&tmpCtx, needed - needed.pos, PR_TRUE, + nsRefPtr tmpCtx = new gfxContext(temp); + tmpCtx->SetOperator(OptimalFillOperator()); + aDrawable->Draw(tmpCtx, needed - needed.pos, PR_TRUE, gfxPattern::FILTER_FAST, gfxMatrix().Translate(needed.pos)); nsRefPtr resultPattern = new gfxPattern(temp); diff --git a/layout/generic/crashtests/592118.html b/layout/generic/crashtests/592118.html new file mode 100755 index 000000000000..77b81768eb9f --- /dev/null +++ b/layout/generic/crashtests/592118.html @@ -0,0 +1,4 @@ + +Stack pointer free with -moz-element +
+
diff --git a/layout/generic/crashtests/crashtests.list b/layout/generic/crashtests/crashtests.list index 3ad2d646a214..b601637bf095 100644 --- a/layout/generic/crashtests/crashtests.list +++ b/layout/generic/crashtests/crashtests.list @@ -338,3 +338,4 @@ load 586973-1.html load 589002-1.html load 590404.html load 591141.html +asserts(0-1) load 592118.html diff --git a/layout/svg/base/src/nsSVGPathGeometryFrame.cpp b/layout/svg/base/src/nsSVGPathGeometryFrame.cpp index c44288e0fede..9f25b8131ca3 100644 --- a/layout/svg/base/src/nsSVGPathGeometryFrame.cpp +++ b/layout/svg/base/src/nsSVGPathGeometryFrame.cpp @@ -170,23 +170,24 @@ nsSVGPathGeometryFrame::GetFrameForPoint(const nsPoint &aPoint) PRBool isHit = PR_FALSE; - gfxContext context(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); + nsRefPtr context = + new gfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); - GeneratePath(&context); + GeneratePath(context); gfxPoint userSpacePoint = - context.DeviceToUser(gfxPoint(PresContext()->AppUnitsToGfxUnits(aPoint.x), - PresContext()->AppUnitsToGfxUnits(aPoint.y))); + context->DeviceToUser(gfxPoint(PresContext()->AppUnitsToGfxUnits(aPoint.x), + PresContext()->AppUnitsToGfxUnits(aPoint.y))); if (fillRule == NS_STYLE_FILL_RULE_EVENODD) - context.SetFillRule(gfxContext::FILL_RULE_EVEN_ODD); + context->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD); else - context.SetFillRule(gfxContext::FILL_RULE_WINDING); + context->SetFillRule(gfxContext::FILL_RULE_WINDING); if (mask & HITTEST_MASK_FILL) - isHit = context.PointInFill(userSpacePoint); + isHit = context->PointInFill(userSpacePoint); if (!isHit && (mask & HITTEST_MASK_STROKE)) { - SetupCairoStrokeHitGeometry(&context); - isHit = context.PointInStroke(userSpacePoint); + SetupCairoStrokeHitGeometry(context); + isHit = context->PointInStroke(userSpacePoint); } if (isHit && nsSVGUtils::HitTestClip(this, aPoint)) @@ -250,12 +251,13 @@ nsSVGPathGeometryFrame::UpdateCoveredRegion() { mRect.Empty(); - gfxContext context(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); + nsRefPtr context = + new gfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); - GeneratePath(&context); - context.IdentityMatrix(); + GeneratePath(context); + context->IdentityMatrix(); - gfxRect extent = context.GetUserPathExtent(); + gfxRect extent = context->GetUserPathExtent(); // Be careful when replacing the following logic to get the fill and stroke // extents independently (instead of computing the stroke extents from the @@ -270,12 +272,12 @@ nsSVGPathGeometryFrame::UpdateCoveredRegion() // stroke bounds that it will return will be empty. if (HasStroke()) { - SetupCairoStrokeGeometry(&context); + SetupCairoStrokeGeometry(context); if (extent.Width() <= 0 && extent.Height() <= 0) { // If 'extent' is empty, its position will not be set. Although // GetUserStrokeExtent gets the extents wrong we can still use it // to get the device space position of zero length stroked paths. - extent = context.GetUserStrokeExtent(); + extent = context->GetUserStrokeExtent(); extent.pos.x += extent.size.width / 2; extent.pos.y += extent.size.height / 2; extent.size.width = 0; @@ -362,10 +364,11 @@ nsSVGPathGeometryFrame::GetBBoxContribution(const gfxMatrix &aToBBoxUserspace) // XXX ReportToConsole return gfxRect(0.0, 0.0, 0.0, 0.0); } - gfxContext context(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); - GeneratePath(&context, &aToBBoxUserspace); - context.IdentityMatrix(); - return context.GetUserPathExtent(); + nsRefPtr context = + new gfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); + GeneratePath(context, &aToBBoxUserspace); + context->IdentityMatrix(); + return context->GetUserPathExtent(); } //----------------------------------------------------------------------