Bug 922942 - Avoid crashes with PointInFill. r=Bas

--HG--
extra : rebase_source : cf209258a71342590c3d3488912d85df86a14b8b
This commit is contained in:
Matt Woodrow 2013-11-04 14:47:18 +13:00
parent f321c22346
commit c3af978daa
3 changed files with 26 additions and 12 deletions

View File

@ -241,6 +241,9 @@ PathCG::GetBounds(const Matrix &aTransform) const
{
//XXX: are these bounds tight enough
Rect bounds = CGRectToRect(CGPathGetBoundingBox(mPath));
if (!bounds.IsFinite()) {
return Rect();
}
//XXX: curretnly this returns the bounds of the transformed bounds
// this is strictly looser than the bounds of the transformed path
return aTransform.TransformBounds(bounds);
@ -266,6 +269,10 @@ PathCG::GetStrokedBounds(const StrokeOptions &aStrokeOptions,
CGContextRestoreGState(cg);
if (!bounds.IsFinite()) {
return Rect();
}
return aTransform.TransformBounds(bounds);
}

View File

@ -332,35 +332,37 @@ PathD2D::StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
Rect
PathD2D::GetBounds(const Matrix &aTransform) const
{
D2D1_RECT_F bounds;
D2D1_RECT_F d2dBounds;
HRESULT hr = mGeometry->GetBounds(D2DMatrix(aTransform), &bounds);
HRESULT hr = mGeometry->GetBounds(D2DMatrix(aTransform), &d2dBounds);
if (FAILED(hr)) {
Rect bounds = ToRect(d2dBounds);
if (FAILED(hr) || !bounds.IsFinite()) {
gfxWarning() << "Failed to get stroked bounds for path. Code: " << hr;
bounds.bottom = bounds.left = bounds.right = bounds.top = 0;
return Rect();
}
return ToRect(bounds);
return bounds;
}
Rect
PathD2D::GetStrokedBounds(const StrokeOptions &aStrokeOptions,
const Matrix &aTransform) const
{
D2D1_RECT_F bounds;
D2D1_RECT_F d2dBounds;
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
HRESULT hr =
mGeometry->GetWidenedBounds(aStrokeOptions.mLineWidth, strokeStyle,
D2DMatrix(aTransform), &bounds);
D2DMatrix(aTransform), &d2dBounds);
if (FAILED(hr)) {
Rect bounds = ToRect(d2dBounds);
if (FAILED(hr) || !bounds.IsFinite()) {
gfxWarning() << "Failed to get stroked bounds for path. Code: " << hr;
bounds.bottom = bounds.left = bounds.right = bounds.top = 0;
return Rect();
}
return ToRect(bounds);
return bounds;
}
}

View File

@ -1713,7 +1713,8 @@ gfxContext::PointInFill(const gfxPoint& pt)
if (mCairo) {
return cairo_in_fill(mCairo, pt.x, pt.y);
} else {
return mPath->ContainsPoint(ToPoint(pt), mTransform);
EnsurePath();
return mPath->ContainsPoint(ToPoint(pt), Matrix());
}
}
@ -1723,9 +1724,10 @@ gfxContext::PointInStroke(const gfxPoint& pt)
if (mCairo) {
return cairo_in_stroke(mCairo, pt.x, pt.y);
} else {
EnsurePath();
return mPath->StrokeContainsPoint(CurrentState().strokeOptions,
ToPoint(pt),
mTransform);
Matrix());
}
}
@ -1737,6 +1739,7 @@ gfxContext::GetUserPathExtent()
cairo_path_extents(mCairo, &xmin, &ymin, &xmax, &ymax);
return gfxRect(xmin, ymin, xmax - xmin, ymax - ymin);
} else {
EnsurePath();
return ThebesRect(mPath->GetBounds());
}
}
@ -1749,6 +1752,7 @@ gfxContext::GetUserFillExtent()
cairo_fill_extents(mCairo, &xmin, &ymin, &xmax, &ymax);
return gfxRect(xmin, ymin, xmax - xmin, ymax - ymin);
} else {
EnsurePath();
return ThebesRect(mPath->GetBounds());
}
}
@ -1761,6 +1765,7 @@ gfxContext::GetUserStrokeExtent()
cairo_stroke_extents(mCairo, &xmin, &ymin, &xmax, &ymax);
return gfxRect(xmin, ymin, xmax - xmin, ymax - ymin);
} else {
EnsurePath();
return ThebesRect(mPath->GetStrokedBounds(CurrentState().strokeOptions, mTransform));
}
}