Bug 1034115 - Stop creating CSS-px-to-dev-pixel matrices when doing SVG hit-testing. r=longsonr

This commit is contained in:
Jonathan Watt 2014-07-05 19:19:13 +01:00
Родитель 0081690039
Коммит 491f9fba82
11 изменённых файлов: 58 добавлений и 31 удалений

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

@ -3419,6 +3419,9 @@ SVGTextFrame::FindCloserFrameForSelection(
TextRenderedRun::eIncludeStroke |
TextRenderedRun::eNoHorizontalOverflow;
SVGBBox userRect = run.GetUserSpaceRect(presContext, flags);
float devPxPerCSSPx = presContext->CSSPixelsToDevPixels(1.f);
userRect.Scale(devPxPerCSSPx);
if (!userRect.IsEmpty()) {
nsRect rect = nsSVGUtils::ToCanvasBounds(userRect.ToThebesRect(),
GetCanvasTM(FOR_HIT_TESTING),
@ -3699,7 +3702,8 @@ SVGTextFrame::GetFrameForPoint(const nsPoint& aPoint)
nsPresContext* presContext = PresContext();
gfxPoint pointInOuterSVGUserUnits = AppUnitsToGfxUnits(aPoint, presContext);
gfxPoint pointInOuterSVGUserUnits =
gfxPoint(aPoint.x, aPoint.y) / PresContext()->AppUnitsPerCSSPixel();
TextRenderedRunIterator it(this);
nsIFrame* hit = nullptr;
@ -3869,10 +3873,12 @@ SVGTextFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
{
if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) &&
!aTransformRoot) {
if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
(aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
if (aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) {
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
}
if (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled()) {
return gfxMatrix();
}
}
if (!mCanvasTM) {
NS_ASSERTION(GetParent(), "null parent");

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

@ -135,10 +135,12 @@ gfxMatrix
nsSVGAFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
{
if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) {
if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
(aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
if (aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) {
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
}
if (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled()) {
return gfxMatrix();
}
}
if (!mCanvasTM) {
NS_ASSERTION(GetParent(), "null parent");

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

@ -303,7 +303,7 @@ nsSVGForeignObjectFrame::GetFrameForPoint(const nsPoint &aPoint)
// Convert aPoint from app units in canvas space to user space:
gfxPoint pt = gfxPoint(aPoint.x, aPoint.y) / PresContext()->AppUnitsPerDevPixel();
gfxPoint pt = gfxPoint(aPoint.x, aPoint.y) / PresContext()->AppUnitsPerCSSPixel();
pt = tm.Transform(pt);
if (!gfxRect(0.0f, 0.0f, width, height).Contains(pt))
@ -493,10 +493,12 @@ gfxMatrix
nsSVGForeignObjectFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
{
if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) {
if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
(aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
if (aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) {
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
}
if (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled()) {
return gfxMatrix();
}
}
if (!mCanvasTM) {
NS_ASSERTION(GetParent(), "null parent");

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

@ -68,10 +68,12 @@ gfxMatrix
nsSVGGFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
{
if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) {
if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
(aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
if (aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) {
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
}
if (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled()) {
return gfxMatrix();
}
}
if (!mCanvasTM) {
NS_ASSERTION(GetParent(), "null parent");

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

@ -50,10 +50,12 @@ nsSVGGenericContainerFrame::GetCanvasTM(uint32_t aFor,
nsIFrame* aTransformRoot)
{
if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) {
if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
(aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
if (aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) {
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
}
if (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled()) {
return gfxMatrix();
}
}
NS_ASSERTION(GetParent(), "null parent");

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

@ -438,8 +438,8 @@ nsSVGImageFrame::GetFrameForPoint(const nsPoint &aPoint)
GetRasterImageTransform(nativeWidth, nativeHeight,
FOR_HIT_TESTING),
0, 0, nativeWidth, nativeHeight,
PresContext()->AppUnitsToDevPixels(aPoint.x),
PresContext()->AppUnitsToDevPixels(aPoint.y))) {
PresContext()->AppUnitsToFloatCSSPixels(aPoint.x),
PresContext()->AppUnitsToFloatCSSPixels(aPoint.y))) {
return nullptr;
}
}

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

@ -279,10 +279,12 @@ gfxMatrix
nsSVGInnerSVGFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
{
if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) {
if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
(aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
if (aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) {
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
}
if (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled()) {
return gfxMatrix();
}
}
if (!mCanvasTM) {
NS_ASSERTION(GetParent(), "null parent");

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

@ -823,10 +823,12 @@ gfxMatrix
nsSVGOuterSVGFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
{
if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) {
if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
(aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
if (aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) {
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
}
if (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled()) {
return gfxMatrix();
}
}
if (!mCanvasTM) {
NS_ASSERTION(!aTransformRoot, "transform root will be ignored here");

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

@ -244,8 +244,6 @@ nsSVGPathGeometryFrame::GetFrameForPoint(const nsPoint &aPoint)
fillRule = StyleSVG()->mClipRule;
} else {
hitTestFlags = GetHitTestFlags();
// XXX once bug 614732 is fixed, aPoint won't need any conversion in order
// to compare it with mRect.
nsPoint point =
nsSVGUtils::TransformOuterSVGPointToChildFrame(aPoint, canvasTM, PresContext());
if (!hitTestFlags || ((hitTestFlags & SVG_HIT_TEST_CHECK_MRECT) &&
@ -261,8 +259,7 @@ nsSVGPathGeometryFrame::GetFrameForPoint(const nsPoint &aPoint)
GeneratePath(tmpCtx, ToMatrix(canvasTM));
gfxPoint userSpacePoint =
tmpCtx->DeviceToUser(gfxPoint(PresContext()->AppUnitsToGfxUnits(aPoint.x),
PresContext()->AppUnitsToGfxUnits(aPoint.y)));
tmpCtx->DeviceToUser(gfxPoint(aPoint.x, aPoint.y) / PresContext()->AppUnitsPerCSSPixel());
if (fillRule == NS_STYLE_FILL_RULE_EVENODD)
tmpCtx->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
@ -512,10 +509,12 @@ gfxMatrix
nsSVGPathGeometryFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
{
if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) {
if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
(aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
if (aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) {
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
}
if (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled()) {
return gfxMatrix();
}
}
NS_ASSERTION(GetParent(), "null parent");

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

@ -373,12 +373,14 @@ nsSVGUtils::GetCanvasTM(nsIFrame *aFrame, uint32_t aFor,
if (!(aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY) &&
!aTransformRoot) {
if ((aFor == nsISVGChildFrame::FOR_PAINTING &&
NS_SVGDisplayListPaintingEnabled()) ||
(aFor == nsISVGChildFrame::FOR_HIT_TESTING &&
NS_SVGDisplayListHitTestingEnabled())) {
if (aFor == nsISVGChildFrame::FOR_PAINTING &&
NS_SVGDisplayListPaintingEnabled()) {
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aFrame);
}
if (aFor == nsISVGChildFrame::FOR_HIT_TESTING &&
NS_SVGDisplayListHitTestingEnabled()) {
return gfxMatrix();
}
}
nsIAtom* type = aFrame->GetType();
@ -759,9 +761,9 @@ nsSVGUtils::TransformOuterSVGPointToChildFrame(nsPoint aPoint,
"Callers must not pass a singular matrix");
gfxMatrix canvasDevToFrameUserSpace = aFrameToCanvasTM;
canvasDevToFrameUserSpace.Invert();
gfxPoint devPt = gfxPoint(aPoint.x, aPoint.y) /
aPresContext->AppUnitsPerDevPixel();
gfxPoint userPt = canvasDevToFrameUserSpace.Transform(devPt);
gfxPoint cssPxPt =
gfxPoint(aPoint.x, aPoint.y) / aPresContext->AppUnitsPerCSSPixel();
gfxPoint userPt = canvasDevToFrameUserSpace.Transform(cssPxPt);
gfxPoint appPt = (userPt * aPresContext->AppUnitsPerCSSPixel()).Round();
userPt.x = clamped(appPt.x, gfxFloat(nscoord_MIN), gfxFloat(nscoord_MAX));
userPt.y = clamped(appPt.y, gfxFloat(nscoord_MIN), gfxFloat(nscoord_MAX));

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

@ -104,6 +104,14 @@ public:
return mIsEmpty;
}
bool IsFinite() const {
return mBBox.IsFinite();
}
void Scale(float aScale) {
mBBox.Scale(aScale);
}
void UnionEdges(const SVGBBox& aSVGBBox) {
if (aSVGBBox.mIsEmpty) {
return;