diff --git a/gfx/2d/Point.h b/gfx/2d/Point.h index a4925816b4e2..396d7d47284d 100644 --- a/gfx/2d/Point.h +++ b/gfx/2d/Point.h @@ -85,23 +85,37 @@ struct MOZ_EMPTY_BASES IntPointTyped return IntPointTyped(int32_t(floorf(aX + 0.5f)), int32_t(floorf(aY + 0.5f))); } + static IntPointTyped Round(double aX, double aY) { + return IntPointTyped(int32_t(floor(aX + 0.5)), int32_t(floor(aY + 0.5))); + } static IntPointTyped Ceil(float aX, float aY) { return IntPointTyped(int32_t(ceilf(aX)), int32_t(ceilf(aY))); } + static IntPointTyped Ceil(double aX, double aY) { + return IntPointTyped(int32_t(ceil(aX)), int32_t(ceil(aY))); + } static IntPointTyped Floor(float aX, float aY) { return IntPointTyped(int32_t(floorf(aX)), int32_t(floorf(aY))); } + static IntPointTyped Floor(double aX, double aY) { + return IntPointTyped(int32_t(floor(aX)), int32_t(floor(aY))); + } - static IntPointTyped Truncate(float aX, float aY) { + template + static IntPointTyped Truncate(F aX, F aY) { return IntPointTyped(int32_t(aX), int32_t(aY)); } - static IntPointTyped Round(const PointTyped& aPoint); - static IntPointTyped Ceil(const PointTyped& aPoint); - static IntPointTyped Floor(const PointTyped& aPoint); - static IntPointTyped Truncate(const PointTyped& aPoint); + template + static IntPointTyped Round(const PointTyped& aPoint); + template + static IntPointTyped Ceil(const PointTyped& aPoint); + template + static IntPointTyped Floor(const PointTyped& aPoint); + template + static IntPointTyped Truncate(const PointTyped& aPoint); // XXX When all of the code is ported, the following functions to convert to // and from unknown types should be removed. @@ -165,13 +179,13 @@ struct MOZ_EMPTY_BASES PointTyped typedef PointTyped Point; typedef PointTyped PointDouble; -template -IntPointTyped RoundedToInt(const PointTyped& aPoint) { +template +IntPointTyped RoundedToInt(const PointTyped& aPoint) { return IntPointTyped::Round(aPoint.x, aPoint.y); } -template -IntPointTyped TruncatedToInt(const PointTyped& aPoint) { +template +IntPointTyped TruncatedToInt(const PointTyped& aPoint) { return IntPointTyped::Truncate(aPoint.x, aPoint.y); } @@ -204,26 +218,30 @@ typedef Point3DTyped Point3D; typedef Point3DTyped PointDouble3D; template +template IntPointTyped IntPointTyped::Round( - const PointTyped& aPoint) { + const PointTyped& aPoint) { return IntPointTyped::Round(aPoint.x, aPoint.y); } template +template IntPointTyped IntPointTyped::Ceil( - const PointTyped& aPoint) { + const PointTyped& aPoint) { return IntPointTyped::Ceil(aPoint.x, aPoint.y); } template +template IntPointTyped IntPointTyped::Floor( - const PointTyped& aPoint) { + const PointTyped& aPoint) { return IntPointTyped::Floor(aPoint.x, aPoint.y); } template +template IntPointTyped IntPointTyped::Truncate( - const PointTyped& aPoint) { + const PointTyped& aPoint) { return IntPointTyped::Truncate(aPoint.x, aPoint.y); } diff --git a/gfx/src/nsCoord.h b/gfx/src/nsCoord.h index 84294a3a6da1..a706b432204a 100644 --- a/gfx/src/nsCoord.h +++ b/gfx/src/nsCoord.h @@ -319,6 +319,11 @@ inline nscoord NSFloatPixelsToAppUnits(float aPixels, float aAppUnitsPerPixel) { return NSToCoordRoundWithClamp(aPixels * aAppUnitsPerPixel); } +inline nscoord NSDoublePixelsToAppUnits(double aPixels, + double aAppUnitsPerPixel) { + return NSToCoordRoundWithClamp(aPixels * aAppUnitsPerPixel); +} + inline nscoord NSIntPixelsToAppUnits(int32_t aPixels, int32_t aAppUnitsPerPixel) { // The cast to nscoord makes sure we don't overflow if we ever change diff --git a/layout/base/Units.h b/layout/base/Units.h index b36a4a2cdfb1..ae2c16a8e929 100644 --- a/layout/base/Units.h +++ b/layout/base/Units.h @@ -63,6 +63,7 @@ struct IsPixel : std::true_type {}; typedef gfx::CoordTyped CSSCoord; typedef gfx::IntCoordTyped CSSIntCoord; +typedef gfx::PointTyped CSSDoublePoint; typedef gfx::PointTyped CSSPoint; typedef gfx::IntPointTyped CSSIntPoint; typedef gfx::SizeTyped CSSSize; @@ -85,8 +86,10 @@ typedef gfx::MarginTyped OuterCSSMargin; typedef gfx::IntMarginTyped OuterCSSIntMargin; typedef gfx::IntRegionTyped OuterCSSIntRegion; +typedef gfx::CoordTyped LayoutDeviceDoubleCoord; typedef gfx::CoordTyped LayoutDeviceCoord; typedef gfx::IntCoordTyped LayoutDeviceIntCoord; +typedef gfx::PointTyped LayoutDeviceDoublePoint; typedef gfx::PointTyped LayoutDevicePoint; typedef gfx::IntPointTyped LayoutDeviceIntPoint; typedef gfx::SizeTyped LayoutDeviceSize; @@ -548,12 +551,33 @@ struct LayoutDevicePixel { return ToAppUnits(LayoutDeviceCoord(aCoord), aAppUnitsPerDevPixel); } + static nscoord ToAppUnits(double aCoord, nscoord aAppUnitsPerDevPixel) { + return ToAppUnits(LayoutDeviceDoubleCoord(aCoord), aAppUnitsPerDevPixel); + } + + static nscoord ToAppUnits(LayoutDeviceDoubleCoord aCoord, + nscoord aAppUnitsPerDevPixel) { + return NSDoublePixelsToAppUnits(aCoord, aAppUnitsPerDevPixel); + } + static nsPoint ToAppUnits(const LayoutDeviceIntPoint& aPoint, nscoord aAppUnitsPerDevPixel) { return nsPoint(ToAppUnits(aPoint.x, aAppUnitsPerDevPixel), ToAppUnits(aPoint.y, aAppUnitsPerDevPixel)); } + static nsPoint ToAppUnits(const LayoutDevicePoint& aPoint, + nscoord aAppUnitsPerDevPixel) { + return nsPoint(ToAppUnits(aPoint.x, aAppUnitsPerDevPixel), + ToAppUnits(aPoint.y, aAppUnitsPerDevPixel)); + } + + static nsPoint ToAppUnits(const LayoutDeviceDoublePoint& aPoint, + nscoord aAppUnitsPerDevPixel) { + return nsPoint(ToAppUnits(aPoint.x, aAppUnitsPerDevPixel), + ToAppUnits(aPoint.y, aAppUnitsPerDevPixel)); + } + static nsSize ToAppUnits(const LayoutDeviceIntSize& aSize, nscoord aAppUnitsPerDevPixel) { return nsSize(ToAppUnits(aSize.width, aAppUnitsPerDevPixel), @@ -692,16 +716,18 @@ gfx::CoordTyped operator/(const gfx::CoordTyped& aCoord, return gfx::CoordTyped(aCoord.value / aScale.scale); } -template -gfx::PointTyped operator*(const gfx::PointTyped& aPoint, - const gfx::ScaleFactor& aScale) { - return gfx::PointTyped(aPoint.x * aScale.scale, aPoint.y * aScale.scale); +template +gfx::PointTyped operator*(const gfx::PointTyped& aPoint, + const gfx::ScaleFactor& aScale) { + return gfx::PointTyped(aPoint.x * aScale.scale, + aPoint.y * aScale.scale); } -template -gfx::PointTyped operator/(const gfx::PointTyped& aPoint, - const gfx::ScaleFactor& aScale) { - return gfx::PointTyped(aPoint.x / aScale.scale, aPoint.y / aScale.scale); +template +gfx::PointTyped operator/(const gfx::PointTyped& aPoint, + const gfx::ScaleFactor& aScale) { + return gfx::PointTyped(aPoint.x / aScale.scale, + aPoint.y / aScale.scale); } template