Bug 1767127 - Change the types of FilterInstance::m[UserSpaceToFilter|FilterSpaceToUser]SpaceScale to MatrixScalesDouble. r=botond

Differential Revision: https://phabricator.services.mozilla.com/D148138
This commit is contained in:
Razvan Cojocaru 2022-06-03 19:55:30 +00:00
Родитель 50fea61916
Коммит f0ceea18e4
5 изменённых файлов: 33 добавлений и 29 удалений

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

@ -14,6 +14,7 @@
#include "mozilla/Assertions.h" #include "mozilla/Assertions.h"
#include "mozilla/FloatingPoint.h" #include "mozilla/FloatingPoint.h"
#include "mozilla/gfx/ScaleFactors2D.h"
#include "Types.h" #include "Types.h"
namespace mozilla { namespace mozilla {
@ -584,6 +585,11 @@ struct BaseRect {
height = y1 - y0; height = y1 - y0;
} }
// Scale 'this' by aScale.xScale and aScale.yScale without doing any rounding.
template <class Src, class Dst>
void Scale(const BaseScaleFactors2D<Src, Dst, T>& aScale) {
Scale(aScale.xScale, aScale.yScale);
}
// Scale 'this' by aScale without doing any rounding. // Scale 'this' by aScale without doing any rounding.
void Scale(T aScale) { Scale(aScale, aScale); } void Scale(T aScale) { Scale(aScale, aScale); }
// Scale 'this' by aXScale and aYScale, without doing any rounding. // Scale 'this' by aXScale and aYScale, without doing any rounding.

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

@ -484,8 +484,8 @@ FilterInstance::FilterInstance(
} }
// Get various transforms: // Get various transforms:
gfxMatrix filterToUserSpace(mFilterSpaceToUserSpaceScale.width, 0.0f, 0.0f, gfxMatrix filterToUserSpace(mFilterSpaceToUserSpaceScale.xScale, 0.0f, 0.0f,
mFilterSpaceToUserSpaceScale.height, 0.0f, 0.0f); mFilterSpaceToUserSpaceScale.yScale, 0.0f, 0.0f);
mFilterSpaceToFrameSpaceInCSSPxTransform = mFilterSpaceToFrameSpaceInCSSPxTransform =
filterToUserSpace * GetUserSpaceToFrameSpaceInCSSPxTransform(); filterToUserSpace * GetUserSpaceToFrameSpaceInCSSPxTransform();
@ -526,19 +526,19 @@ bool FilterInstance::ComputeTargetBBoxInFilterSpace() {
bool FilterInstance::ComputeUserSpaceToFilterSpaceScale() { bool FilterInstance::ComputeUserSpaceToFilterSpaceScale() {
if (mTargetFrame) { if (mTargetFrame) {
mUserSpaceToFilterSpaceScale = mPaintTransform.ScaleFactors().ToSize(); mUserSpaceToFilterSpaceScale = mPaintTransform.ScaleFactors();
if (mUserSpaceToFilterSpaceScale.width <= 0.0f || if (mUserSpaceToFilterSpaceScale.xScale <= 0.0f ||
mUserSpaceToFilterSpaceScale.height <= 0.0f) { mUserSpaceToFilterSpaceScale.yScale <= 0.0f) {
// Nothing should be rendered. // Nothing should be rendered.
return false; return false;
} }
} else { } else {
mUserSpaceToFilterSpaceScale = gfxSize(1.0, 1.0); mUserSpaceToFilterSpaceScale = MatrixScalesDouble();
} }
mFilterSpaceToUserSpaceScale = mFilterSpaceToUserSpaceScale =
gfxSize(1.0f / mUserSpaceToFilterSpaceScale.width, MatrixScalesDouble(1.0f / mUserSpaceToFilterSpaceScale.xScale,
1.0f / mUserSpaceToFilterSpaceScale.height); 1.0f / mUserSpaceToFilterSpaceScale.yScale);
return true; return true;
} }
@ -546,16 +546,14 @@ bool FilterInstance::ComputeUserSpaceToFilterSpaceScale() {
gfxRect FilterInstance::UserSpaceToFilterSpace( gfxRect FilterInstance::UserSpaceToFilterSpace(
const gfxRect& aUserSpaceRect) const { const gfxRect& aUserSpaceRect) const {
gfxRect filterSpaceRect = aUserSpaceRect; gfxRect filterSpaceRect = aUserSpaceRect;
filterSpaceRect.Scale(mUserSpaceToFilterSpaceScale.width, filterSpaceRect.Scale(mUserSpaceToFilterSpaceScale);
mUserSpaceToFilterSpaceScale.height);
return filterSpaceRect; return filterSpaceRect;
} }
gfxRect FilterInstance::FilterSpaceToUserSpace( gfxRect FilterInstance::FilterSpaceToUserSpace(
const gfxRect& aFilterSpaceRect) const { const gfxRect& aFilterSpaceRect) const {
gfxRect userSpaceRect = aFilterSpaceRect; gfxRect userSpaceRect = aFilterSpaceRect;
userSpaceRect.Scale(mFilterSpaceToUserSpaceScale.width, userSpaceRect.Scale(mFilterSpaceToUserSpaceScale);
mFilterSpaceToUserSpaceScale.height);
return userSpaceRect; return userSpaceRect;
} }
@ -583,8 +581,8 @@ nsresult FilterInstance::BuildPrimitives(Span<const StyleFilter> aFilterChain,
nsresult FilterInstance::BuildPrimitivesForFilter( nsresult FilterInstance::BuildPrimitivesForFilter(
const StyleFilter& aFilter, nsIFrame* aTargetFrame, bool aInputIsTainted, const StyleFilter& aFilter, nsIFrame* aTargetFrame, bool aInputIsTainted,
nsTArray<FilterPrimitiveDescription>& aPrimitiveDescriptions) { nsTArray<FilterPrimitiveDescription>& aPrimitiveDescriptions) {
NS_ASSERTION(mUserSpaceToFilterSpaceScale.width > 0.0f && NS_ASSERTION(mUserSpaceToFilterSpaceScale.xScale > 0.0f &&
mFilterSpaceToUserSpaceScale.height > 0.0f, mFilterSpaceToUserSpaceScale.yScale > 0.0f,
"scale factors between spaces should be positive values"); "scale factors between spaces should be positive values");
if (aFilter.IsUrl()) { if (aFilter.IsUrl()) {

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

@ -367,8 +367,8 @@ class FilterInstance {
/** /**
* The scale factors between user space and filter space. * The scale factors between user space and filter space.
*/ */
gfxSize mUserSpaceToFilterSpaceScale; gfx::MatrixScalesDouble mUserSpaceToFilterSpaceScale;
gfxSize mFilterSpaceToUserSpaceScale; gfx::MatrixScalesDouble mFilterSpaceToUserSpaceScale;
/** /**
* Pre-filter paint bounds of the element that is being filtered, in filter * Pre-filter paint bounds of the element that is being filtered, in filter

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

@ -32,7 +32,8 @@ namespace mozilla {
SVGFilterInstance::SVGFilterInstance( SVGFilterInstance::SVGFilterInstance(
const StyleFilter& aFilter, nsIFrame* aTargetFrame, const StyleFilter& aFilter, nsIFrame* aTargetFrame,
nsIContent* aTargetContent, const UserSpaceMetrics& aMetrics, nsIContent* aTargetContent, const UserSpaceMetrics& aMetrics,
const gfxRect& aTargetBBox, const gfxSize& aUserSpaceToFilterSpaceScale) const gfxRect& aTargetBBox,
const MatrixScalesDouble& aUserSpaceToFilterSpaceScale)
: mFilter(aFilter), : mFilter(aFilter),
mTargetContent(aTargetContent), mTargetContent(aTargetContent),
mMetrics(aMetrics), mMetrics(aMetrics),
@ -178,14 +179,14 @@ float SVGFilterInstance::GetPrimitiveNumber(uint8_t aCtxType,
switch (aCtxType) { switch (aCtxType) {
case SVGContentUtils::X: case SVGContentUtils::X:
return value * mUserSpaceToFilterSpaceScale.width; return value * static_cast<float>(mUserSpaceToFilterSpaceScale.xScale);
case SVGContentUtils::Y: case SVGContentUtils::Y:
return value * mUserSpaceToFilterSpaceScale.height; return value * static_cast<float>(mUserSpaceToFilterSpaceScale.yScale);
case SVGContentUtils::XY: case SVGContentUtils::XY:
default: default:
return value * SVGContentUtils::ComputeNormalizedHypotenuse( return value * SVGContentUtils::ComputeNormalizedHypotenuse(
mUserSpaceToFilterSpaceScale.width, mUserSpaceToFilterSpaceScale.xScale,
mUserSpaceToFilterSpaceScale.height); mUserSpaceToFilterSpaceScale.yScale);
} }
} }
@ -210,8 +211,7 @@ Point3D SVGFilterInstance::ConvertLocation(const Point3D& aPoint) const {
gfxRect SVGFilterInstance::UserSpaceToFilterSpace( gfxRect SVGFilterInstance::UserSpaceToFilterSpace(
const gfxRect& aUserSpaceRect) const { const gfxRect& aUserSpaceRect) const {
gfxRect filterSpaceRect = aUserSpaceRect; gfxRect filterSpaceRect = aUserSpaceRect;
filterSpaceRect.Scale(mUserSpaceToFilterSpaceScale.width, filterSpaceRect.Scale(mUserSpaceToFilterSpaceScale);
mUserSpaceToFilterSpaceScale.height);
return filterSpaceRect; return filterSpaceRect;
} }

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

@ -79,11 +79,11 @@ class SVGFilterInstance {
* @param aTargetBBox The SVG bbox to use for the target frame, computed by * @param aTargetBBox The SVG bbox to use for the target frame, computed by
* the caller. The caller may decide to override the actual SVG bbox. * the caller. The caller may decide to override the actual SVG bbox.
*/ */
SVGFilterInstance(const StyleFilter& aFilter, nsIFrame* aTargetFrame, SVGFilterInstance(
nsIContent* aTargetContent, const StyleFilter& aFilter, nsIFrame* aTargetFrame,
const UserSpaceMetrics& aMetrics, nsIContent* aTargetContent, const UserSpaceMetrics& aMetrics,
const gfxRect& aTargetBBox, const gfxRect& aTargetBBox,
const gfxSize& aUserSpaceToFilterSpaceScale); const gfx::MatrixScalesDouble& aUserSpaceToFilterSpaceScale);
/** /**
* Returns true if the filter instance was created successfully. * Returns true if the filter instance was created successfully.
@ -233,7 +233,7 @@ class SVGFilterInstance {
/** /**
* The scale factors between user space and filter space. * The scale factors between user space and filter space.
*/ */
gfxSize mUserSpaceToFilterSpaceScale; gfx::MatrixScalesDouble mUserSpaceToFilterSpaceScale;
/** /**
* The 'primitiveUnits' attribute value (objectBoundingBox or userSpaceOnUse). * The 'primitiveUnits' attribute value (objectBoundingBox or userSpaceOnUse).