mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 923512 - Introduce strongly-typed coordinate classes. r=kats,Bas
--HG-- extra : rebase_source : 22e5fe577ea503aede765c70e16c0bf875c4a9fd
This commit is contained in:
parent
f22c80707b
commit
54aeea8833
@ -728,7 +728,7 @@ public:
|
||||
int32_t ScrollTop()
|
||||
{
|
||||
nsIScrollableFrame* sf = GetScrollFrame();
|
||||
return sf ? sf->GetScrollPositionCSSPixels().y : 0;
|
||||
return sf ? sf->GetScrollPositionCSSPixels().y.value : 0;
|
||||
}
|
||||
void SetScrollTop(int32_t aScrollTop)
|
||||
{
|
||||
@ -741,7 +741,7 @@ public:
|
||||
int32_t ScrollLeft()
|
||||
{
|
||||
nsIScrollableFrame* sf = GetScrollFrame();
|
||||
return sf ? sf->GetScrollPositionCSSPixels().x : 0;
|
||||
return sf ? sf->GetScrollPositionCSSPixels().x.value : 0;
|
||||
}
|
||||
void SetScrollLeft(int32_t aScrollLeft)
|
||||
{
|
||||
|
@ -1985,7 +1985,7 @@ CanvasRenderingContext2D::ArcTo(double x1, double y1, double x2,
|
||||
}
|
||||
|
||||
// Check for colinearity
|
||||
dir = (p2.x - p1.x) * (p0.y - p1.y) + (p2.y - p1.y) * (p1.x - p0.x);
|
||||
dir = (p2.x - p1.x).value * (p0.y - p1.y).value + (p2.y - p1.y).value * (p1.x - p0.x).value;
|
||||
if (dir == 0) {
|
||||
LineTo(p1.x, p1.y);
|
||||
return;
|
||||
@ -4500,7 +4500,7 @@ CanvasPath::ArcTo(double x1, double y1, double x2, double y2, double radius,
|
||||
}
|
||||
|
||||
// Check for colinearity
|
||||
dir = (p2.x - p1.x) * (p0.y - p1.y) + (p2.y - p1.y) * (p1.x - p0.x);
|
||||
dir = (p2.x - p1.x).value * (p0.y - p1.y).value + (p2.y - p1.y).value * (p1.x - p0.x).value;
|
||||
if (dir == 0) {
|
||||
LineTo(p1.x, p1.y);
|
||||
return;
|
||||
|
@ -790,7 +790,7 @@ protected:
|
||||
// The spec says we should not draw shadows if the operator is OVER.
|
||||
// If it's over and the alpha value is zero, nothing needs to be drawn.
|
||||
return NS_GET_A(state.shadowColor) != 0 &&
|
||||
(state.shadowBlur != 0 || state.shadowOffset.x != 0 || state.shadowOffset.y != 0);
|
||||
(state.shadowBlur != 0.f || state.shadowOffset.x != 0.f || state.shadowOffset.y != 0.f);
|
||||
}
|
||||
|
||||
mozilla::gfx::CompositionOp UsedOperation()
|
||||
|
@ -1595,8 +1595,9 @@ EventStateManager::GenerateDragGesture(nsPresContext* aPresContext,
|
||||
// fire drag gesture if mouse has moved enough
|
||||
LayoutDeviceIntPoint pt = aEvent->refPoint +
|
||||
LayoutDeviceIntPoint::FromUntyped(aEvent->widget->WidgetToScreenOffset());
|
||||
if (DeprecatedAbs(pt.x - mGestureDownPoint.x) > pixelThresholdX ||
|
||||
DeprecatedAbs(pt.y - mGestureDownPoint.y) > pixelThresholdY) {
|
||||
LayoutDeviceIntPoint distance = pt - mGestureDownPoint;
|
||||
if (Abs(distance.x.value) > SafeCast<uint32_t>(pixelThresholdX) ||
|
||||
Abs(distance.y.value) > SafeCast<uint32_t>(pixelThresholdY)) {
|
||||
if (Prefs::ClickHoldContextMenu()) {
|
||||
// stop the click-hold before we fire off the drag gesture, in case
|
||||
// it takes a long time
|
||||
|
110
gfx/2d/BaseCoord.h
Normal file
110
gfx/2d/BaseCoord.h
Normal file
@ -0,0 +1,110 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef MOZILLA_GFX_BASECOORD_H_
|
||||
#define MOZILLA_GFX_BASECOORD_H_
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
/**
|
||||
* Do not use this class directly. Subclass it, pass that subclass as the
|
||||
* Sub parameter, and only use that subclass. This allows methods to safely
|
||||
* cast 'this' to 'Sub*'.
|
||||
*/
|
||||
template <class T, class Sub>
|
||||
struct BaseCoord {
|
||||
T value;
|
||||
|
||||
// Constructors
|
||||
MOZ_CONSTEXPR BaseCoord() : value(0) {}
|
||||
explicit MOZ_CONSTEXPR BaseCoord(T aValue) : value(aValue) {}
|
||||
|
||||
// Note that '=' isn't defined so we'll get the
|
||||
// compiler generated default assignment operator
|
||||
|
||||
operator T() const { return value; }
|
||||
|
||||
friend bool operator==(Sub aA, Sub aB) {
|
||||
return aA.value == aB.value;
|
||||
}
|
||||
friend bool operator!=(Sub aA, Sub aB) {
|
||||
return aA.value != aB.value;
|
||||
}
|
||||
|
||||
friend Sub operator+(Sub aA, Sub aB) {
|
||||
return Sub(aA.value + aB.value);
|
||||
}
|
||||
friend Sub operator-(Sub aA, Sub aB) {
|
||||
return Sub(aA.value - aB.value);
|
||||
}
|
||||
friend Sub operator*(Sub aCoord, T aScale) {
|
||||
return Sub(aCoord.value * aScale);
|
||||
}
|
||||
friend Sub operator*(T aScale, Sub aCoord) {
|
||||
return Sub(aScale * aCoord.value);
|
||||
}
|
||||
friend Sub operator/(Sub aCoord, T aScale) {
|
||||
return Sub(aCoord.value / aScale);
|
||||
}
|
||||
// 'scale / coord' is intentionally omitted because it doesn't make sense.
|
||||
|
||||
Sub& operator+=(Sub aCoord) {
|
||||
value += aCoord.value;
|
||||
return *static_cast<Sub*>(this);
|
||||
}
|
||||
Sub& operator-=(Sub aCoord) {
|
||||
value -= aCoord.value;
|
||||
return *static_cast<Sub*>(this);
|
||||
}
|
||||
Sub& operator*=(T aScale) {
|
||||
value *= aScale;
|
||||
return *static_cast<Sub*>(this);
|
||||
}
|
||||
Sub& operator/=(T aScale) {
|
||||
value /= aScale;
|
||||
return *static_cast<Sub*>(this);
|
||||
}
|
||||
|
||||
// Since BaseCoord is implicitly convertible to its value type T, we need
|
||||
// mixed-type operator overloads to avoid ambiguities at mixed-type call
|
||||
// sites. As we transition more of our code to strongly-typed classes, we
|
||||
// may be able to remove some or all of these overloads.
|
||||
friend bool operator==(Sub aA, T aB) {
|
||||
return aA.value == aB;
|
||||
}
|
||||
friend bool operator==(T aA, Sub aB) {
|
||||
return aA == aB.value;
|
||||
}
|
||||
friend bool operator!=(Sub aA, T aB) {
|
||||
return aA.value != aB;
|
||||
}
|
||||
friend bool operator!=(T aA, Sub aB) {
|
||||
return aA != aB.value;
|
||||
}
|
||||
friend T operator+(Sub aA, T aB) {
|
||||
return aA.value + aB;
|
||||
}
|
||||
friend T operator+(T aA, Sub aB) {
|
||||
return aA + aB.value;
|
||||
}
|
||||
friend T operator-(Sub aA, T aB) {
|
||||
return aA.value - aB;
|
||||
}
|
||||
friend T operator-(T aA, Sub aB) {
|
||||
return aA - aB.value;
|
||||
}
|
||||
|
||||
Sub operator-() const {
|
||||
return Sub(-value);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MOZILLA_GFX_BASECOORD_H_ */
|
@ -17,13 +17,13 @@ namespace gfx {
|
||||
* Sub parameter, and only use that subclass. This allows methods to safely
|
||||
* cast 'this' to 'Sub*'.
|
||||
*/
|
||||
template <class T, class Sub>
|
||||
template <class T, class Sub, class Coord = T>
|
||||
struct BasePoint {
|
||||
T x, y;
|
||||
Coord x, y;
|
||||
|
||||
// Constructors
|
||||
MOZ_CONSTEXPR BasePoint() : x(0), y(0) {}
|
||||
MOZ_CONSTEXPR BasePoint(T aX, T aY) : x(aX), y(aY) {}
|
||||
MOZ_CONSTEXPR BasePoint(Coord aX, Coord aY) : x(aX), y(aY) {}
|
||||
|
||||
void MoveTo(T aX, T aY) { x = aX; y = aY; }
|
||||
void MoveBy(T aDx, T aDy) { x += aDx; y += aDy; }
|
||||
@ -67,15 +67,15 @@ struct BasePoint {
|
||||
}
|
||||
|
||||
T Length() const {
|
||||
return hypot(x, y);
|
||||
return hypot(x.value, y.value);
|
||||
}
|
||||
|
||||
// Round() is *not* rounding to nearest integer if the values are negative.
|
||||
// They are always rounding as floor(n + 0.5).
|
||||
// See https://bugzilla.mozilla.org/show_bug.cgi?id=410748#c14
|
||||
Sub& Round() {
|
||||
x = static_cast<T>(floor(x + 0.5));
|
||||
y = static_cast<T>(floor(y + 0.5));
|
||||
x = Coord(floor(T(x) + T(0.5)));
|
||||
y = Coord(floor(T(y) + T(0.5)));
|
||||
return *static_cast<Sub*>(this);
|
||||
}
|
||||
|
||||
|
@ -734,8 +734,8 @@ static const Float GAUSSIAN_SCALE_FACTOR = Float((3 * sqrt(2 * M_PI) / 4) * 1.5)
|
||||
IntSize
|
||||
AlphaBoxBlur::CalculateBlurRadius(const Point& aStd)
|
||||
{
|
||||
IntSize size(static_cast<int32_t>(floor(aStd.x * GAUSSIAN_SCALE_FACTOR + 0.5)),
|
||||
static_cast<int32_t>(floor(aStd.y * GAUSSIAN_SCALE_FACTOR + 0.5)));
|
||||
IntSize size(static_cast<int32_t>(floor(aStd.x * GAUSSIAN_SCALE_FACTOR + 0.5f)),
|
||||
static_cast<int32_t>(floor(aStd.y * GAUSSIAN_SCALE_FACTOR + 0.5f)));
|
||||
|
||||
return size;
|
||||
}
|
||||
|
142
gfx/2d/Coord.h
Normal file
142
gfx/2d/Coord.h
Normal file
@ -0,0 +1,142 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef MOZILLA_GFX_COORD_H_
|
||||
#define MOZILLA_GFX_COORD_H_
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "Types.h"
|
||||
#include "BaseCoord.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
template <typename> struct IsPixel;
|
||||
|
||||
namespace gfx {
|
||||
|
||||
template <class units> struct IntCoordTyped;
|
||||
template <class units> struct CoordTyped;
|
||||
|
||||
// CommonType<coord, primitive> is a metafunction that returns the type of the
|
||||
// result of an arithmetic operation on the underlying type of a strongly-typed
|
||||
// coordinate type 'coord', and a primitive type 'primitive'. C++ rules for
|
||||
// arithmetic conversions are designed to avoid losing information - for
|
||||
// example, the result of adding an int and a float is a float - and we want
|
||||
// the same behaviour when mixing our coordinate types with primitive types.
|
||||
// We get C++ to compute the desired result type using 'decltype'.
|
||||
|
||||
template <class coord, class primitive>
|
||||
struct CommonType;
|
||||
|
||||
template <class units, class primitive>
|
||||
struct CommonType<IntCoordTyped<units>, primitive> {
|
||||
typedef decltype(int32_t() + primitive()) type;
|
||||
};
|
||||
|
||||
template <class units, class primitive>
|
||||
struct CommonType<CoordTyped<units>, primitive> {
|
||||
typedef decltype(Float() + primitive()) type;
|
||||
};
|
||||
|
||||
// This is a base class that provides mixed-type operator overloads between
|
||||
// a strongly-typed Coord and a primitive value. It is needed to avoid
|
||||
// ambiguities at mixed-type call sites, because Coord classes are implicitly
|
||||
// convertible to their underlying value type. As we transition more of our code
|
||||
// to strongly-typed classes, we may be able to remove some or all of these
|
||||
// overloads.
|
||||
template <class coord, class primitive>
|
||||
struct CoordOperatorsHelper {
|
||||
friend bool operator==(coord aA, primitive aB) {
|
||||
return aA.value == aB;
|
||||
}
|
||||
friend bool operator==(primitive aA, coord aB) {
|
||||
return aA == aB.value;
|
||||
}
|
||||
friend bool operator!=(coord aA, primitive aB) {
|
||||
return aA.value != aB;
|
||||
}
|
||||
friend bool operator!=(primitive aA, coord aB) {
|
||||
return aA != aB.value;
|
||||
}
|
||||
|
||||
typedef typename CommonType<coord, primitive>::type result_type;
|
||||
|
||||
friend result_type operator+(coord aA, primitive aB) {
|
||||
return aA.value + aB;
|
||||
}
|
||||
friend result_type operator+(primitive aA, coord aB) {
|
||||
return aA + aB.value;
|
||||
}
|
||||
friend result_type operator-(coord aA, primitive aB) {
|
||||
return aA.value - aB;
|
||||
}
|
||||
friend result_type operator-(primitive aA, coord aB) {
|
||||
return aA - aB.value;
|
||||
}
|
||||
friend result_type operator*(coord aCoord, primitive aScale) {
|
||||
return aCoord.value * aScale;
|
||||
}
|
||||
friend result_type operator*(primitive aScale, coord aCoord) {
|
||||
return aScale * aCoord.value;
|
||||
}
|
||||
friend result_type operator/(coord aCoord, primitive aScale) {
|
||||
return aCoord.value / aScale;
|
||||
}
|
||||
// 'scale / coord' is intentionally omitted because it doesn't make sense.
|
||||
};
|
||||
|
||||
// Note: 'IntCoordTyped<units>' and 'CoordTyped<units>' do not derive from
|
||||
// 'units' to work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61959.
|
||||
|
||||
template<class units>
|
||||
struct IntCoordTyped :
|
||||
public BaseCoord< int32_t, IntCoordTyped<units> >,
|
||||
public CoordOperatorsHelper< IntCoordTyped<units>, float >,
|
||||
public CoordOperatorsHelper< IntCoordTyped<units>, double > {
|
||||
static_assert(IsPixel<units>::value,
|
||||
"'units' must be a coordinate system tag");
|
||||
|
||||
typedef BaseCoord< int32_t, IntCoordTyped<units> > Super;
|
||||
|
||||
MOZ_CONSTEXPR IntCoordTyped() : Super() {}
|
||||
MOZ_CONSTEXPR IntCoordTyped(int32_t aValue) : Super(aValue) {}
|
||||
};
|
||||
|
||||
template<class units>
|
||||
struct CoordTyped :
|
||||
public BaseCoord< Float, CoordTyped<units> >,
|
||||
public CoordOperatorsHelper< CoordTyped<units>, int32_t >,
|
||||
public CoordOperatorsHelper< CoordTyped<units>, uint32_t >,
|
||||
public CoordOperatorsHelper< CoordTyped<units>, double > {
|
||||
static_assert(IsPixel<units>::value,
|
||||
"'units' must be a coordinate system tag");
|
||||
|
||||
typedef BaseCoord< Float, CoordTyped<units> > Super;
|
||||
|
||||
MOZ_CONSTEXPR CoordTyped() : Super() {}
|
||||
MOZ_CONSTEXPR CoordTyped(Float aValue) : Super(aValue) {}
|
||||
explicit MOZ_CONSTEXPR CoordTyped(const IntCoordTyped<units>& aCoord) : Super(float(aCoord.value)) {}
|
||||
|
||||
void Round() {
|
||||
this->value = floor(this->value + 0.5);
|
||||
}
|
||||
void Truncate() {
|
||||
this->value = int32_t(this->value);
|
||||
}
|
||||
|
||||
IntCoordTyped<units> Rounded() const {
|
||||
return IntCoordTyped<units>(int32_t(floor(this->value + 0.5)));
|
||||
}
|
||||
IntCoordTyped<units> Truncated() const {
|
||||
return IntCoordTyped<units>(int32_t(this->value));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MOZILLA_GFX_COORD_H_ */
|
@ -2599,7 +2599,7 @@ DrawTargetD2D::SetupEffectForRadialGradient(const RadialGradientPattern *aPatter
|
||||
mPrivateData->mEffect->GetVariableByName("DeviceSpaceToUserSpace")->
|
||||
AsMatrix()->SetMatrix(matrix);
|
||||
|
||||
float A = dc.x * dc.x + dc.y * dc.y - dr * dr;
|
||||
float A = dc.x.value * dc.x.value + dc.y.value * dc.y.value - dr * dr;
|
||||
|
||||
uint32_t offset = 0;
|
||||
switch (stops->mStopCollection->GetExtendMode()) {
|
||||
|
@ -35,8 +35,8 @@ DrawTargetTiled::Init(const TileSet& aTiles)
|
||||
mTiles[i].mTileOrigin.x + mTiles[i].mDrawTarget->GetSize().width);
|
||||
uint32_t newYMost = max(mRect.YMost(),
|
||||
mTiles[i].mTileOrigin.y + mTiles[i].mDrawTarget->GetSize().height);
|
||||
mRect.x = min(mRect.x, mTiles[i].mTileOrigin.x);
|
||||
mRect.y = min(mRect.y, mTiles[i].mTileOrigin.y);
|
||||
mRect.x = min(mRect.x, mTiles[i].mTileOrigin.x.value);
|
||||
mRect.y = min(mRect.y, mTiles[i].mTileOrigin.y.value);
|
||||
mRect.width = newXMost - mRect.x;
|
||||
mRect.height = newYMost - mRect.y;
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ static inline bool IsPatternSupportedByD2D(const Pattern &aPattern)
|
||||
|
||||
Point diff = pat->mCenter2 - pat->mCenter1;
|
||||
|
||||
if (sqrt(diff.x * diff.x + diff.y * diff.y) >= pat->mRadius2) {
|
||||
if (sqrt(diff.x.value * diff.x.value + diff.y.value * diff.y.value) >= pat->mRadius2) {
|
||||
// Inner point lies outside the circle.
|
||||
return false;
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ FlattenedPath::QuadraticBezierTo(const Point &aCP1,
|
||||
const Point &aCP2)
|
||||
{
|
||||
MOZ_ASSERT(!mCalculatedLength);
|
||||
// We need to elevate the degree of this quadratic Bézier to cubic, so we're
|
||||
// We need to elevate the degree of this quadratic B<EFBFBD>zier to cubic, so we're
|
||||
// going to add an intermediate control point, and recompute control point 1.
|
||||
// The first and last control points remain the same.
|
||||
// This formula can be found on http://fontforge.sourceforge.net/bezier.html
|
||||
@ -250,7 +250,7 @@ FlattenBezierCurveSegment(const BezierControlPoints &aControlPoints,
|
||||
Point cp21 = currentCP.mCP2 - currentCP.mCP3;
|
||||
Point cp31 = currentCP.mCP3 - currentCP.mCP1;
|
||||
|
||||
Float s3 = (cp31.x * cp21.y - cp31.y * cp21.x) / hypotf(cp21.x, cp21.y);
|
||||
Float s3 = (cp31.x.value * cp21.y.value - cp31.y.value * cp21.x.value) / hypotf(cp21.x, cp21.y);
|
||||
|
||||
t = 2 * Float(sqrt(aTolerance / (3. * abs(s3))));
|
||||
|
||||
@ -276,7 +276,7 @@ FindInflectionApproximationRange(BezierControlPoints aControlPoints,
|
||||
Point cp21 = aControlPoints.mCP2 - aControlPoints.mCP1;
|
||||
Point cp41 = aControlPoints.mCP4 - aControlPoints.mCP1;
|
||||
|
||||
if (cp21.x == 0 && cp21.y == 0) {
|
||||
if (cp21.x == 0.f && cp21.y == 0.f) {
|
||||
// In this case s3 becomes lim[n->0] (cp41.x * n) / n - (cp41.y * n) / n = cp41.x - cp41.y.
|
||||
|
||||
// Use the absolute value so that Min and Max will correspond with the
|
||||
@ -286,7 +286,7 @@ FindInflectionApproximationRange(BezierControlPoints aControlPoints,
|
||||
return;
|
||||
}
|
||||
|
||||
Float s3 = (cp41.x * cp21.y - cp41.y * cp21.x) / hypotf(cp21.x, cp21.y);
|
||||
Float s3 = (cp41.x.value * cp21.y.value - cp41.y.value * cp21.x.value) / hypotf(cp21.x, cp21.y);
|
||||
|
||||
if (s3 == 0) {
|
||||
// This means within the precision we have it can be approximated
|
||||
|
@ -16,8 +16,8 @@ template <typename T>
|
||||
void ArcToBezier(T* aSink, const Point &aOrigin, const Size &aRadius,
|
||||
float aStartAngle, float aEndAngle, bool aAntiClockwise)
|
||||
{
|
||||
Point startPoint(aOrigin.x + cos(aStartAngle) * aRadius.width,
|
||||
aOrigin.y + sin(aStartAngle) * aRadius.height);
|
||||
Point startPoint(aOrigin.x + cosf(aStartAngle) * aRadius.width,
|
||||
aOrigin.y + sinf(aStartAngle) * aRadius.height);
|
||||
|
||||
aSink->LineTo(startPoint);
|
||||
|
||||
@ -56,10 +56,10 @@ void ArcToBezier(T* aSink, const Point &aOrigin, const Size &aRadius,
|
||||
currentEndAngle = currentStartAngle + arcSweepLeft * sweepDirection;
|
||||
}
|
||||
|
||||
Point currentStartPoint(aOrigin.x + cos(currentStartAngle) * aRadius.width,
|
||||
aOrigin.y + sin(currentStartAngle) * aRadius.height);
|
||||
Point currentEndPoint(aOrigin.x + cos(currentEndAngle) * aRadius.width,
|
||||
aOrigin.y + sin(currentEndAngle) * aRadius.height);
|
||||
Point currentStartPoint(aOrigin.x + cosf(currentStartAngle) * aRadius.width,
|
||||
aOrigin.y + sinf(currentStartAngle) * aRadius.height);
|
||||
Point currentEndPoint(aOrigin.x + cosf(currentEndAngle) * aRadius.width,
|
||||
aOrigin.y + sinf(currentEndAngle) * aRadius.height);
|
||||
|
||||
// Calculate kappa constant for partial curve. The sign of angle in the
|
||||
// tangent will actually ensure this is negative for a counter clockwise
|
||||
|
@ -141,10 +141,10 @@ PathSkia::ContainsPoint(const Point &aPoint, const Matrix &aTransform) const
|
||||
}
|
||||
|
||||
SkRegion pointRect;
|
||||
pointRect.setRect(int32_t(SkFloatToScalar(transformed.x - 1)),
|
||||
int32_t(SkFloatToScalar(transformed.y - 1)),
|
||||
int32_t(SkFloatToScalar(transformed.x + 1)),
|
||||
int32_t(SkFloatToScalar(transformed.y + 1)));
|
||||
pointRect.setRect(int32_t(SkFloatToScalar(transformed.x - 1.f)),
|
||||
int32_t(SkFloatToScalar(transformed.y - 1.f)),
|
||||
int32_t(SkFloatToScalar(transformed.x + 1.f)),
|
||||
int32_t(SkFloatToScalar(transformed.y + 1.f)));
|
||||
|
||||
SkRegion pathRegion;
|
||||
|
||||
@ -174,10 +174,10 @@ PathSkia::StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
|
||||
}
|
||||
|
||||
SkRegion pointRect;
|
||||
pointRect.setRect(int32_t(SkFloatToScalar(transformed.x - 1)),
|
||||
int32_t(SkFloatToScalar(transformed.y - 1)),
|
||||
int32_t(SkFloatToScalar(transformed.x + 1)),
|
||||
int32_t(SkFloatToScalar(transformed.y + 1)));
|
||||
pointRect.setRect(int32_t(SkFloatToScalar(transformed.x - 1.f)),
|
||||
int32_t(SkFloatToScalar(transformed.y - 1.f)),
|
||||
int32_t(SkFloatToScalar(transformed.x + 1.f)),
|
||||
int32_t(SkFloatToScalar(transformed.y + 1.f)));
|
||||
|
||||
SkRegion pathRegion;
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "Types.h"
|
||||
#include "Coord.h"
|
||||
#include "BaseCoord.h"
|
||||
#include "BasePoint.h"
|
||||
#include "BasePoint3D.h"
|
||||
#include "BasePoint4D.h"
|
||||
@ -33,15 +35,21 @@ namespace gfx {
|
||||
|
||||
template<class units>
|
||||
struct IntPointTyped :
|
||||
public BasePoint< int32_t, IntPointTyped<units> >,
|
||||
public BasePoint< int32_t, IntPointTyped<units>, IntCoordTyped<units> >,
|
||||
public units {
|
||||
static_assert(IsPixel<units>::value,
|
||||
"'units' must be a coordinate system tag");
|
||||
|
||||
typedef BasePoint< int32_t, IntPointTyped<units> > Super;
|
||||
typedef IntCoordTyped<units> Coord;
|
||||
typedef BasePoint< int32_t, IntPointTyped<units>, IntCoordTyped<units> > Super;
|
||||
|
||||
MOZ_CONSTEXPR IntPointTyped() : Super() {}
|
||||
MOZ_CONSTEXPR IntPointTyped(int32_t aX, int32_t aY) : Super(aX, aY) {}
|
||||
MOZ_CONSTEXPR IntPointTyped(int32_t aX, int32_t aY) : Super(Coord(aX), Coord(aY)) {}
|
||||
// The mixed-type constructors (int, Coord) and (Coord, int) are needed to
|
||||
// avoid ambiguities because Coord is implicitly convertible to int.
|
||||
MOZ_CONSTEXPR IntPointTyped(int32_t aX, Coord aY) : Super(Coord(aX), aY) {}
|
||||
MOZ_CONSTEXPR IntPointTyped(Coord aX, int32_t aY) : Super(aX, Coord(aY)) {}
|
||||
MOZ_CONSTEXPR IntPointTyped(Coord aX, Coord aY) : Super(aX, aY) {}
|
||||
|
||||
// XXX When all of the code is ported, the following functions to convert to and from
|
||||
// unknown types should be removed.
|
||||
@ -58,15 +66,21 @@ typedef IntPointTyped<UnknownUnits> IntPoint;
|
||||
|
||||
template<class units>
|
||||
struct PointTyped :
|
||||
public BasePoint< Float, PointTyped<units> >,
|
||||
public BasePoint< Float, PointTyped<units>, CoordTyped<units> >,
|
||||
public units {
|
||||
static_assert(IsPixel<units>::value,
|
||||
"'units' must be a coordinate system tag");
|
||||
|
||||
typedef BasePoint< Float, PointTyped<units> > Super;
|
||||
typedef CoordTyped<units> Coord;
|
||||
typedef BasePoint< Float, PointTyped<units>, CoordTyped<units> > Super;
|
||||
|
||||
MOZ_CONSTEXPR PointTyped() : Super() {}
|
||||
MOZ_CONSTEXPR PointTyped(Float aX, Float aY) : Super(aX, aY) {}
|
||||
MOZ_CONSTEXPR PointTyped(Float aX, Float aY) : Super(Coord(aX), Coord(aY)) {}
|
||||
// The mixed-type constructors (Float, Coord) and (Coord, Float) are needed to
|
||||
// avoid ambiguities because Coord is implicitly convertible to Float.
|
||||
MOZ_CONSTEXPR PointTyped(Float aX, Coord aY) : Super(Coord(aX), aY) {}
|
||||
MOZ_CONSTEXPR PointTyped(Coord aX, Float aY) : Super(aX, Coord(aY)) {}
|
||||
MOZ_CONSTEXPR PointTyped(Coord aX, Coord aY) : Super(aX.value, aY.value) {}
|
||||
MOZ_CONSTEXPR MOZ_IMPLICIT PointTyped(const IntPointTyped<units>& point) : Super(float(point.x), float(point.y)) {}
|
||||
|
||||
// XXX When all of the code is ported, the following functions to convert to and from
|
||||
@ -84,8 +98,14 @@ typedef PointTyped<UnknownUnits> Point;
|
||||
|
||||
template<class units>
|
||||
IntPointTyped<units> RoundedToInt(const PointTyped<units>& aPoint) {
|
||||
return IntPointTyped<units>(int32_t(floorf(aPoint.x + 0.5f)),
|
||||
int32_t(floorf(aPoint.y + 0.5f)));
|
||||
return IntPointTyped<units>(aPoint.x.Rounded(),
|
||||
aPoint.y.Rounded());
|
||||
}
|
||||
|
||||
template<class units>
|
||||
IntPointTyped<units> TruncatedToInt(const PointTyped<units>& aPoint) {
|
||||
return IntPointTyped<units>(aPoint.x.Truncated(),
|
||||
aPoint.y.Truncated());
|
||||
}
|
||||
|
||||
template<class units>
|
||||
|
@ -240,15 +240,15 @@ SVGTurbulenceRenderer<Type,Stitch,f32x4_t,i32x4_t,u8x16_t>::Noise2(Point aVec, c
|
||||
uint8_t i = mLatticeSelector[b0.x & sBM];
|
||||
uint8_t j = mLatticeSelector[b1.x & sBM];
|
||||
|
||||
const f32x4_t* qua = mGradient[(i + b0.y) & sBM];
|
||||
const f32x4_t* qub = mGradient[(i + b1.y) & sBM];
|
||||
const f32x4_t* qva = mGradient[(j + b0.y) & sBM];
|
||||
const f32x4_t* qvb = mGradient[(j + b1.y) & sBM];
|
||||
const f32x4_t* qua = mGradient[(i + b0.y.value) & sBM];
|
||||
const f32x4_t* qub = mGradient[(i + b1.y.value) & sBM];
|
||||
const f32x4_t* qva = mGradient[(j + b0.y.value) & sBM];
|
||||
const f32x4_t* qvb = mGradient[(j + b1.y.value) & sBM];
|
||||
|
||||
return BiMix(simd::WSumF32(qua[0], qua[1], r.x, r.y),
|
||||
simd::WSumF32(qva[0], qva[1], r.x - 1, r.y),
|
||||
simd::WSumF32(qub[0], qub[1], r.x, r.y - 1),
|
||||
simd::WSumF32(qvb[0], qvb[1], r.x - 1, r.y - 1),
|
||||
simd::WSumF32(qva[0], qva[1], r.x - 1.f, r.y),
|
||||
simd::WSumF32(qub[0], qub[1], r.x, r.y - 1.f),
|
||||
simd::WSumF32(qvb[0], qvb[1], r.x - 1.f, r.y - 1.f),
|
||||
SCurve(r));
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ EXPORTS.mozilla += [
|
||||
|
||||
EXPORTS.mozilla.gfx += [
|
||||
'2D.h',
|
||||
'BaseCoord.h',
|
||||
'BaseMargin.h',
|
||||
'BasePoint.h',
|
||||
'BasePoint3D.h',
|
||||
@ -18,6 +19,7 @@ EXPORTS.mozilla.gfx += [
|
||||
'BaseSize.h',
|
||||
'Blur.h',
|
||||
'BorrowedContext.h',
|
||||
'Coord.h',
|
||||
'DataSurfaceHelpers.h',
|
||||
'Filters.h',
|
||||
'Helpers.h',
|
||||
|
@ -26,8 +26,8 @@ TestPoint::Addition()
|
||||
|
||||
a += b;
|
||||
|
||||
VERIFY(a.x == 7);
|
||||
VERIFY(a.y == -3);
|
||||
VERIFY(a.x == 7.f);
|
||||
VERIFY(a.y == -3.f);
|
||||
}
|
||||
|
||||
void
|
||||
@ -41,6 +41,6 @@ TestPoint::Subtraction()
|
||||
|
||||
a -= b;
|
||||
|
||||
VERIFY(a.x == -3);
|
||||
VERIFY(a.y == 7);
|
||||
VERIFY(a.x == -3.f);
|
||||
VERIFY(a.y == 7.f);
|
||||
}
|
||||
|
@ -507,6 +507,38 @@ struct ParamTraits<nsIntSize>
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct ParamTraits< mozilla::gfx::CoordTyped<T> >
|
||||
{
|
||||
typedef mozilla::gfx::CoordTyped<T> paramType;
|
||||
|
||||
static void Write(Message* msg, const paramType& param)
|
||||
{
|
||||
WriteParam(msg, param.value);
|
||||
}
|
||||
|
||||
static bool Read(const Message* msg, void** iter, paramType* result)
|
||||
{
|
||||
return (ReadParam(msg, iter, &result->value));
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct ParamTraits< mozilla::gfx::IntCoordTyped<T> >
|
||||
{
|
||||
typedef mozilla::gfx::IntCoordTyped<T> paramType;
|
||||
|
||||
static void Write(Message* msg, const paramType& param)
|
||||
{
|
||||
WriteParam(msg, param.value);
|
||||
}
|
||||
|
||||
static bool Read(const Message* msg, void** iter, paramType* result)
|
||||
{
|
||||
return (ReadParam(msg, iter, &result->value));
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
struct ParamTraits< mozilla::gfx::ScaleFactor<T, U> >
|
||||
{
|
||||
|
@ -382,16 +382,14 @@ APZCTreeManager::UpdatePanZoomControllerTree(CompositorParent* aCompositor,
|
||||
ApplyTransform(gfx::PointTyped<T>* aPoint, const Matrix4x4& aMatrix)
|
||||
{
|
||||
Point result = aMatrix * aPoint->ToUnknownPoint();
|
||||
aPoint->x = result.x;
|
||||
aPoint->y = result.y;
|
||||
*aPoint = ViewAs<T>(result);
|
||||
}
|
||||
|
||||
/*static*/ template<class T> void
|
||||
ApplyTransform(gfx::IntPointTyped<T>* aPoint, const Matrix4x4& aMatrix)
|
||||
{
|
||||
Point result = aMatrix * aPoint->ToUnknownPoint();
|
||||
aPoint->x = result.x;
|
||||
aPoint->y = result.y;
|
||||
*aPoint = TruncatedToInt(ViewAs<T>(result));
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
@ -635,9 +633,7 @@ APZCTreeManager::TransformCoordinateToGecko(const ScreenIntPoint& aPoint,
|
||||
Matrix4x4 transformToGecko;
|
||||
GetInputTransforms(apzc, transformToApzc, transformToGecko);
|
||||
Matrix4x4 outTransform = transformToApzc * transformToGecko;
|
||||
aOutTransformedPoint->x = aPoint.x;
|
||||
aOutTransformedPoint->y = aPoint.y;
|
||||
ApplyTransform(aOutTransformedPoint, outTransform);
|
||||
*aOutTransformedPoint = TransformTo<LayoutDevicePixel>(outTransform, aPoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,8 +379,8 @@ static bool IsCloseToVertical(float aAngle, float aThreshold)
|
||||
template <typename Units>
|
||||
static bool IsZero(const gfx::PointTyped<Units>& aPoint)
|
||||
{
|
||||
return FuzzyEqualsMultiplicative(aPoint.x, 0.0f)
|
||||
&& FuzzyEqualsMultiplicative(aPoint.y, 0.0f);
|
||||
return FuzzyEqualsMultiplicative(aPoint.x.value, 0.0f)
|
||||
&& FuzzyEqualsMultiplicative(aPoint.y.value, 0.0f);
|
||||
}
|
||||
|
||||
static inline void LogRendertraceRect(const ScrollableLayerGuid& aGuid, const char* aDesc, const char* aColor, const CSSRect& aRect)
|
||||
@ -538,9 +538,9 @@ public:
|
||||
// We may have reached the end of the scroll range along one axis but
|
||||
// not the other. In such a case we only want to hand off the relevant
|
||||
// component of the fling.
|
||||
if (FuzzyEqualsAdditive(overscroll.x, 0.0f, COORDINATE_EPSILON)) {
|
||||
if (FuzzyEqualsAdditive(overscroll.x.value, 0.0f, COORDINATE_EPSILON)) {
|
||||
velocity.x = 0;
|
||||
} else if (FuzzyEqualsAdditive(overscroll.y, 0.0f, COORDINATE_EPSILON)) {
|
||||
} else if (FuzzyEqualsAdditive(overscroll.y.value, 0.0f, COORDINATE_EPSILON)) {
|
||||
velocity.y = 0;
|
||||
}
|
||||
|
||||
@ -610,7 +610,7 @@ public:
|
||||
|
||||
// Sample the zoom at the current time point. The sampled zoom
|
||||
// will affect the final computed resolution.
|
||||
double sampledPosition = gComputedTimingFunction->GetValue(animPosition);
|
||||
float sampledPosition = gComputedTimingFunction->GetValue(animPosition);
|
||||
|
||||
// We scale the scrollOffset linearly with sampledPosition, so the zoom
|
||||
// needs to scale inversely to match.
|
||||
@ -1337,8 +1337,8 @@ AsyncPanZoomController::ConvertToGecko(const ScreenPoint& aPoint, CSSPoint* aOut
|
||||
nsEventStatus AsyncPanZoomController::OnPanMayBegin(const PanGestureInput& aEvent) {
|
||||
APZC_LOG("%p got a pan-maybegin in state %d\n", this, mState);
|
||||
|
||||
mX.StartTouch(aEvent.mPanStartPoint.x, aEvent.mTime);
|
||||
mY.StartTouch(aEvent.mPanStartPoint.y, aEvent.mTime);
|
||||
mX.StartTouch(aEvent.mPanStartPoint.x.Truncated(), aEvent.mTime);
|
||||
mY.StartTouch(aEvent.mPanStartPoint.y.Truncated(), aEvent.mTime);
|
||||
if (mPanGestureState) {
|
||||
mPanGestureState->GetOverscrollHandoffChain()->CancelAnimations();
|
||||
} else {
|
||||
@ -1363,8 +1363,8 @@ nsEventStatus AsyncPanZoomController::OnPanBegin(const PanGestureInput& aEvent)
|
||||
|
||||
mPanGestureState = MakeUnique<InputBlockState>(BuildOverscrollHandoffChain());
|
||||
|
||||
mX.StartTouch(aEvent.mPanStartPoint.x, aEvent.mTime);
|
||||
mY.StartTouch(aEvent.mPanStartPoint.y, aEvent.mTime);
|
||||
mX.StartTouch(aEvent.mPanStartPoint.x.Truncated(), aEvent.mTime);
|
||||
mY.StartTouch(aEvent.mPanStartPoint.y.Truncated(), aEvent.mTime);
|
||||
|
||||
if (GetAxisLockMode() == FREE) {
|
||||
SetState(PANNING);
|
||||
@ -1387,8 +1387,8 @@ nsEventStatus AsyncPanZoomController::OnPan(const PanGestureInput& aEvent, bool
|
||||
// size and position. We need to do so even if this is a momentum pan (i.e.
|
||||
// aFingersOnTouchpad == false); in that case the "with touch" part is not
|
||||
// really appropriate, so we may want to rethink this at some point.
|
||||
mX.UpdateWithTouchAtDevicePoint(aEvent.mPanStartPoint.x, aEvent.mTime);
|
||||
mY.UpdateWithTouchAtDevicePoint(aEvent.mPanStartPoint.y, aEvent.mTime);
|
||||
mX.UpdateWithTouchAtDevicePoint(aEvent.mPanStartPoint.x.Truncated(), aEvent.mTime);
|
||||
mY.UpdateWithTouchAtDevicePoint(aEvent.mPanStartPoint.y.Truncated(), aEvent.mTime);
|
||||
|
||||
HandlePanningUpdate(aEvent.mPanDisplacement.x, aEvent.mPanDisplacement.y);
|
||||
|
||||
|
@ -33,7 +33,7 @@ Axis::Axis(AsyncPanZoomController* aAsyncPanZoomController)
|
||||
{
|
||||
}
|
||||
|
||||
void Axis::UpdateWithTouchAtDevicePoint(int32_t aPos, uint32_t aTimestampMs) {
|
||||
void Axis::UpdateWithTouchAtDevicePoint(ScreenIntCoord aPos, uint32_t aTimestampMs) {
|
||||
// mVelocityQueue is controller-thread only
|
||||
AsyncPanZoomController::AssertOnControllerThread();
|
||||
|
||||
@ -62,16 +62,16 @@ void Axis::UpdateWithTouchAtDevicePoint(int32_t aPos, uint32_t aTimestampMs) {
|
||||
}
|
||||
}
|
||||
|
||||
void Axis::StartTouch(int32_t aPos, uint32_t aTimestampMs) {
|
||||
void Axis::StartTouch(ScreenIntCoord aPos, uint32_t aTimestampMs) {
|
||||
mStartPos = aPos;
|
||||
mPos = aPos;
|
||||
mPosTimeMs = aTimestampMs;
|
||||
mAxisLocked = false;
|
||||
}
|
||||
|
||||
bool Axis::AdjustDisplacement(float aDisplacement,
|
||||
float& aDisplacementOut,
|
||||
float& aOverscrollAmountOut)
|
||||
bool Axis::AdjustDisplacement(CSSCoord aDisplacement,
|
||||
CSSCoord& aDisplacementOut,
|
||||
CSSCoord& aOverscrollAmountOut)
|
||||
{
|
||||
if (mAxisLocked) {
|
||||
aOverscrollAmountOut = 0;
|
||||
@ -79,14 +79,14 @@ bool Axis::AdjustDisplacement(float aDisplacement,
|
||||
return false;
|
||||
}
|
||||
|
||||
float displacement = aDisplacement;
|
||||
CSSCoord displacement = aDisplacement;
|
||||
|
||||
// First consume any overscroll in the opposite direction along this axis.
|
||||
float consumedOverscroll = 0;
|
||||
CSSCoord consumedOverscroll = 0;
|
||||
if (mOverscroll > 0 && aDisplacement < 0) {
|
||||
consumedOverscroll = std::min(mOverscroll, -aDisplacement);
|
||||
} else if (mOverscroll < 0 && aDisplacement > 0) {
|
||||
consumedOverscroll = 0 - std::min(-mOverscroll, aDisplacement);
|
||||
consumedOverscroll = 0.f - std::min(-mOverscroll, aDisplacement);
|
||||
}
|
||||
mOverscroll -= consumedOverscroll;
|
||||
displacement += consumedOverscroll;
|
||||
@ -104,7 +104,7 @@ bool Axis::AdjustDisplacement(float aDisplacement,
|
||||
return fabsf(consumedOverscroll) > EPSILON;
|
||||
}
|
||||
|
||||
float Axis::ApplyResistance(float aRequestedOverscroll) const {
|
||||
CSSCoord Axis::ApplyResistance(CSSCoord aRequestedOverscroll) const {
|
||||
// 'resistanceFactor' is a value between 0 and 1, which:
|
||||
// - tends to 1 as the existing overscroll tends to 0
|
||||
// - tends to 0 as the existing overscroll tends to the composition length
|
||||
@ -112,23 +112,23 @@ float Axis::ApplyResistance(float aRequestedOverscroll) const {
|
||||
// factor; this should prevent overscrolling by more than the composition
|
||||
// length.
|
||||
float resistanceFactor = 1 - fabsf(mOverscroll) / GetCompositionLength();
|
||||
return resistanceFactor < 0 ? 0 : aRequestedOverscroll * resistanceFactor;
|
||||
return resistanceFactor < 0 ? CSSCoord(0) : aRequestedOverscroll * resistanceFactor;
|
||||
}
|
||||
|
||||
void Axis::OverscrollBy(float aOverscroll) {
|
||||
void Axis::OverscrollBy(CSSCoord aOverscroll) {
|
||||
MOZ_ASSERT(CanScroll());
|
||||
aOverscroll = ApplyResistance(aOverscroll);
|
||||
if (aOverscroll > 0) {
|
||||
MOZ_ASSERT(FuzzyEqualsAdditive(GetCompositionEnd(), GetPageEnd(), COORDINATE_EPSILON));
|
||||
MOZ_ASSERT(FuzzyEqualsAdditive(GetCompositionEnd().value, GetPageEnd().value, COORDINATE_EPSILON));
|
||||
MOZ_ASSERT(mOverscroll >= 0);
|
||||
} else if (aOverscroll < 0) {
|
||||
MOZ_ASSERT(FuzzyEqualsAdditive(GetOrigin(), GetPageStart(), COORDINATE_EPSILON));
|
||||
MOZ_ASSERT(FuzzyEqualsAdditive(GetOrigin().value, GetPageStart().value, COORDINATE_EPSILON));
|
||||
MOZ_ASSERT(mOverscroll <= 0);
|
||||
}
|
||||
mOverscroll += aOverscroll;
|
||||
}
|
||||
|
||||
float Axis::GetOverscroll() const {
|
||||
CSSCoord Axis::GetOverscroll() const {
|
||||
return mOverscroll;
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ bool Axis::SampleSnapBack(const TimeDuration& aDelta) {
|
||||
}
|
||||
mOverscroll = std::max(mOverscroll + cssDisplacement, 0.0f);
|
||||
// Overscroll relieved, do not continue animation.
|
||||
if (mOverscroll == 0) {
|
||||
if (mOverscroll == 0.f) {
|
||||
mVelocity = 0;
|
||||
return false;
|
||||
}
|
||||
@ -174,7 +174,7 @@ bool Axis::SampleSnapBack(const TimeDuration& aDelta) {
|
||||
}
|
||||
mOverscroll = std::min(mOverscroll + cssDisplacement, 0.0f);
|
||||
// Overscroll relieved, do not continue animation.
|
||||
if (mOverscroll == 0) {
|
||||
if (mOverscroll == 0.f) {
|
||||
mVelocity = 0;
|
||||
return false;
|
||||
}
|
||||
@ -185,7 +185,7 @@ bool Axis::SampleSnapBack(const TimeDuration& aDelta) {
|
||||
}
|
||||
|
||||
bool Axis::IsOverscrolled() const {
|
||||
return mOverscroll != 0;
|
||||
return mOverscroll != 0.f;
|
||||
}
|
||||
|
||||
void Axis::ClearOverscroll() {
|
||||
@ -193,11 +193,11 @@ void Axis::ClearOverscroll() {
|
||||
}
|
||||
|
||||
float Axis::PanDistance() {
|
||||
return fabsf(mPos - mStartPos);
|
||||
return fabsf((mPos - mStartPos).value);
|
||||
}
|
||||
|
||||
float Axis::PanDistance(float aPos) {
|
||||
return fabsf(aPos - mStartPos);
|
||||
float Axis::PanDistance(ScreenIntCoord aPos) {
|
||||
return fabsf((aPos - mStartPos).value);
|
||||
}
|
||||
|
||||
void Axis::EndTouch(uint32_t aTimestampMs) {
|
||||
@ -252,7 +252,7 @@ bool Axis::FlingApplyFrictionOrCancel(const TimeDuration& aDelta,
|
||||
return true;
|
||||
}
|
||||
|
||||
Axis::Overscroll Axis::DisplacementWillOverscroll(float aDisplacement) {
|
||||
Axis::Overscroll Axis::DisplacementWillOverscroll(CSSCoord aDisplacement) {
|
||||
// If the current pan plus a displacement takes the window to the left of or
|
||||
// above the current page rect.
|
||||
bool minus = GetOrigin() + aDisplacement < GetPageStart();
|
||||
@ -271,7 +271,7 @@ Axis::Overscroll Axis::DisplacementWillOverscroll(float aDisplacement) {
|
||||
return OVERSCROLL_NONE;
|
||||
}
|
||||
|
||||
float Axis::DisplacementWillOverscrollAmount(float aDisplacement) {
|
||||
CSSCoord Axis::DisplacementWillOverscrollAmount(CSSCoord aDisplacement) {
|
||||
switch (DisplacementWillOverscroll(aDisplacement)) {
|
||||
case OVERSCROLL_MINUS: return (GetOrigin() + aDisplacement) - GetPageStart();
|
||||
case OVERSCROLL_PLUS: return (GetCompositionEnd() + aDisplacement) - GetPageEnd();
|
||||
@ -281,8 +281,8 @@ float Axis::DisplacementWillOverscrollAmount(float aDisplacement) {
|
||||
}
|
||||
}
|
||||
|
||||
float Axis::ScaleWillOverscrollAmount(float aScale, float aFocus) {
|
||||
float originAfterScale = (GetOrigin() + aFocus) - (aFocus / aScale);
|
||||
CSSCoord Axis::ScaleWillOverscrollAmount(float aScale, CSSCoord aFocus) {
|
||||
CSSCoord originAfterScale = (GetOrigin() + aFocus) - (aFocus / aScale);
|
||||
|
||||
bool both = ScaleWillOverscrollBothSides(aScale);
|
||||
bool minus = GetPageStart() - originAfterScale > COORDINATE_EPSILON;
|
||||
@ -310,29 +310,29 @@ void Axis::SetVelocity(float aVelocity) {
|
||||
mVelocity = aVelocity;
|
||||
}
|
||||
|
||||
float Axis::GetCompositionEnd() const {
|
||||
CSSCoord Axis::GetCompositionEnd() const {
|
||||
return GetOrigin() + GetCompositionLength();
|
||||
}
|
||||
|
||||
float Axis::GetPageEnd() const {
|
||||
CSSCoord Axis::GetPageEnd() const {
|
||||
return GetPageStart() + GetPageLength();
|
||||
}
|
||||
|
||||
float Axis::GetOrigin() const {
|
||||
CSSCoord Axis::GetOrigin() const {
|
||||
CSSPoint origin = GetFrameMetrics().GetScrollOffset();
|
||||
return GetPointOffset(origin);
|
||||
}
|
||||
|
||||
float Axis::GetCompositionLength() const {
|
||||
CSSCoord Axis::GetCompositionLength() const {
|
||||
return GetRectLength(GetFrameMetrics().CalculateCompositedRectInCssPixels());
|
||||
}
|
||||
|
||||
float Axis::GetPageStart() const {
|
||||
CSSCoord Axis::GetPageStart() const {
|
||||
CSSRect pageRect = GetFrameMetrics().GetExpandedScrollableRect();
|
||||
return GetRectOffset(pageRect);
|
||||
}
|
||||
|
||||
float Axis::GetPageLength() const {
|
||||
CSSCoord Axis::GetPageLength() const {
|
||||
CSSRect pageRect = GetFrameMetrics().GetExpandedScrollableRect();
|
||||
return GetRectLength(pageRect);
|
||||
}
|
||||
@ -357,17 +357,17 @@ AxisX::AxisX(AsyncPanZoomController* aAsyncPanZoomController)
|
||||
|
||||
}
|
||||
|
||||
float AxisX::GetPointOffset(const CSSPoint& aPoint) const
|
||||
CSSCoord AxisX::GetPointOffset(const CSSPoint& aPoint) const
|
||||
{
|
||||
return aPoint.x;
|
||||
}
|
||||
|
||||
float AxisX::GetRectLength(const CSSRect& aRect) const
|
||||
CSSCoord AxisX::GetRectLength(const CSSRect& aRect) const
|
||||
{
|
||||
return aRect.width;
|
||||
}
|
||||
|
||||
float AxisX::GetRectOffset(const CSSRect& aRect) const
|
||||
CSSCoord AxisX::GetRectOffset(const CSSRect& aRect) const
|
||||
{
|
||||
return aRect.x;
|
||||
}
|
||||
@ -378,17 +378,17 @@ AxisY::AxisY(AsyncPanZoomController* aAsyncPanZoomController)
|
||||
|
||||
}
|
||||
|
||||
float AxisY::GetPointOffset(const CSSPoint& aPoint) const
|
||||
CSSCoord AxisY::GetPointOffset(const CSSPoint& aPoint) const
|
||||
{
|
||||
return aPoint.y;
|
||||
}
|
||||
|
||||
float AxisY::GetRectLength(const CSSRect& aRect) const
|
||||
CSSCoord AxisY::GetRectLength(const CSSRect& aRect) const
|
||||
{
|
||||
return aRect.height;
|
||||
}
|
||||
|
||||
float AxisY::GetRectOffset(const CSSRect& aRect) const
|
||||
CSSCoord AxisY::GetRectOffset(const CSSRect& aRect) const
|
||||
{
|
||||
return aRect.y;
|
||||
}
|
||||
|
@ -55,13 +55,13 @@ public:
|
||||
* Notify this Axis that a new touch has been received, including a timestamp
|
||||
* for when the touch was received. This triggers a recalculation of velocity.
|
||||
*/
|
||||
void UpdateWithTouchAtDevicePoint(int32_t aPos, uint32_t aTimestampMs);
|
||||
void UpdateWithTouchAtDevicePoint(ScreenIntCoord aPos, uint32_t aTimestampMs);
|
||||
|
||||
/**
|
||||
* Notify this Axis that a touch has begun, i.e. the user has put their finger
|
||||
* on the screen but has not yet tried to pan.
|
||||
*/
|
||||
void StartTouch(int32_t aPos, uint32_t aTimestampMs);
|
||||
void StartTouch(ScreenIntCoord aPos, uint32_t aTimestampMs);
|
||||
|
||||
/**
|
||||
* Notify this Axis that a touch has ended gracefully. This may perform
|
||||
@ -87,20 +87,20 @@ public:
|
||||
* displacement, and the function returns true iff internal overscroll amounts
|
||||
* were changed.
|
||||
*/
|
||||
bool AdjustDisplacement(float aDisplacement,
|
||||
float& aDisplacementOut,
|
||||
float& aOverscrollAmountOut);
|
||||
bool AdjustDisplacement(CSSCoord aDisplacement,
|
||||
CSSCoord& aDisplacementOut,
|
||||
CSSCoord& aOverscrollAmountOut);
|
||||
|
||||
/**
|
||||
* Overscrolls this axis by the requested amount in the requested direction.
|
||||
* The axis must be at the end of its scroll range in this direction.
|
||||
*/
|
||||
void OverscrollBy(float aOverscroll);
|
||||
void OverscrollBy(CSSCoord aOverscroll);
|
||||
|
||||
/**
|
||||
* Return the amount of overscroll on this axis, in CSS pixels.
|
||||
*/
|
||||
float GetOverscroll() const;
|
||||
CSSCoord GetOverscroll() const;
|
||||
|
||||
/**
|
||||
* Sample the snap-back animation to relieve overscroll.
|
||||
@ -129,7 +129,7 @@ public:
|
||||
* Gets the distance between the starting position of the touch supplied in
|
||||
* startTouch() and the supplied position.
|
||||
*/
|
||||
float PanDistance(float aPos);
|
||||
float PanDistance(ScreenIntCoord aPos);
|
||||
|
||||
/**
|
||||
* Applies friction during a fling, or cancels the fling if the velocity is
|
||||
@ -177,13 +177,13 @@ public:
|
||||
* That is to say, if the given displacement is applied, this will tell you
|
||||
* whether or not it will overscroll, and in what direction.
|
||||
*/
|
||||
Overscroll DisplacementWillOverscroll(float aDisplacement);
|
||||
Overscroll DisplacementWillOverscroll(CSSCoord aDisplacement);
|
||||
|
||||
/**
|
||||
* If a displacement will overscroll the axis, this returns the amount and in
|
||||
* what direction. Similar to GetExcess() but takes a displacement to apply.
|
||||
*/
|
||||
float DisplacementWillOverscrollAmount(float aDisplacement);
|
||||
CSSCoord DisplacementWillOverscrollAmount(CSSCoord aDisplacement);
|
||||
|
||||
/**
|
||||
* If a scale will overscroll the axis, this returns the amount and in what
|
||||
@ -193,7 +193,7 @@ public:
|
||||
* scroll offset in such a way that it remains in the same place on the page
|
||||
* relative.
|
||||
*/
|
||||
float ScaleWillOverscrollAmount(float aScale, float aFocus);
|
||||
CSSCoord ScaleWillOverscrollAmount(float aScale, CSSCoord aFocus);
|
||||
|
||||
/**
|
||||
* Checks if an axis will overscroll in both directions by computing the
|
||||
@ -204,23 +204,23 @@ public:
|
||||
*/
|
||||
bool ScaleWillOverscrollBothSides(float aScale);
|
||||
|
||||
float GetOrigin() const;
|
||||
float GetCompositionLength() const;
|
||||
float GetPageStart() const;
|
||||
float GetPageLength() const;
|
||||
float GetCompositionEnd() const;
|
||||
float GetPageEnd() const;
|
||||
CSSCoord GetOrigin() const;
|
||||
CSSCoord GetCompositionLength() const;
|
||||
CSSCoord GetPageStart() const;
|
||||
CSSCoord GetPageLength() const;
|
||||
CSSCoord GetCompositionEnd() const;
|
||||
CSSCoord GetPageEnd() const;
|
||||
|
||||
int32_t GetPos() const { return mPos; }
|
||||
ScreenIntCoord GetPos() const { return mPos; }
|
||||
|
||||
virtual float GetPointOffset(const CSSPoint& aPoint) const = 0;
|
||||
virtual float GetRectLength(const CSSRect& aRect) const = 0;
|
||||
virtual float GetRectOffset(const CSSRect& aRect) const = 0;
|
||||
virtual CSSCoord GetPointOffset(const CSSPoint& aPoint) const = 0;
|
||||
virtual CSSCoord GetRectLength(const CSSRect& aRect) const = 0;
|
||||
virtual CSSCoord GetRectOffset(const CSSRect& aRect) const = 0;
|
||||
|
||||
protected:
|
||||
int32_t mPos;
|
||||
ScreenIntCoord mPos;
|
||||
uint32_t mPosTimeMs;
|
||||
int32_t mStartPos;
|
||||
ScreenIntCoord mStartPos;
|
||||
float mVelocity;
|
||||
bool mAxisLocked; // Whether movement on this axis is locked.
|
||||
AsyncPanZoomController* mAsyncPanZoomController;
|
||||
@ -230,7 +230,7 @@ protected:
|
||||
// extreme allowed value in the relevant direction (that is, it must be at
|
||||
// its maximum value if mOverscroll is positive, and at its minimum value
|
||||
// if mOverscroll is negative).
|
||||
float mOverscroll;
|
||||
CSSCoord mOverscroll;
|
||||
// A queue of (timestamp, velocity) pairs; these are the historical
|
||||
// velocities at the given timestamps. Timestamps are in milliseconds,
|
||||
// velocities are in screen pixels per ms. This member can only be
|
||||
@ -241,23 +241,23 @@ protected:
|
||||
|
||||
// Adjust a requested overscroll amount for resistance, yielding a smaller
|
||||
// actual overscroll amount.
|
||||
float ApplyResistance(float aOverscroll) const;
|
||||
CSSCoord ApplyResistance(CSSCoord aOverscroll) const;
|
||||
};
|
||||
|
||||
class AxisX : public Axis {
|
||||
public:
|
||||
AxisX(AsyncPanZoomController* mAsyncPanZoomController);
|
||||
virtual float GetPointOffset(const CSSPoint& aPoint) const;
|
||||
virtual float GetRectLength(const CSSRect& aRect) const;
|
||||
virtual float GetRectOffset(const CSSRect& aRect) const;
|
||||
virtual CSSCoord GetPointOffset(const CSSPoint& aPoint) const;
|
||||
virtual CSSCoord GetRectLength(const CSSRect& aRect) const;
|
||||
virtual CSSCoord GetRectOffset(const CSSRect& aRect) const;
|
||||
};
|
||||
|
||||
class AxisY : public Axis {
|
||||
public:
|
||||
AxisY(AsyncPanZoomController* mAsyncPanZoomController);
|
||||
virtual float GetPointOffset(const CSSPoint& aPoint) const;
|
||||
virtual float GetRectLength(const CSSRect& aRect) const;
|
||||
virtual float GetRectOffset(const CSSRect& aRect) const;
|
||||
virtual CSSCoord GetPointOffset(const CSSPoint& aPoint) const;
|
||||
virtual CSSCoord GetRectLength(const CSSRect& aRect) const;
|
||||
virtual CSSCoord GetRectOffset(const CSSRect& aRect) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -227,8 +227,8 @@ static void DrawVelGraph(const nsIntRect& aClipRect,
|
||||
for (int32_t i = (int32_t)velocityData->mData.size() - 2; i >= 0; i--) {
|
||||
const gfx::Point& p1 = velocityData->mData[i+1].mPoint;
|
||||
const gfx::Point& p2 = velocityData->mData[i].mPoint;
|
||||
int vel = sqrt((p1.x - p2.x) * (p1.x - p2.x) +
|
||||
(p1.y - p2.y) * (p1.y - p2.y));
|
||||
int vel = sqrt((p1.x - p2.x).value * (p1.x - p2.x).value +
|
||||
(p1.y - p2.y).value * (p1.y - p2.y).value);
|
||||
Point next = Point(graphRect.width / circularBufferSize * i,
|
||||
graphRect.height - vel/yScaleFactor);
|
||||
if (first) {
|
||||
@ -270,11 +270,9 @@ static void PrintUniformityInfo(Layer* aLayer)
|
||||
return;
|
||||
}
|
||||
|
||||
LayerIntPoint scrollOffset = RoundedToInt(frameMetrics.GetScrollOffsetInLayerPixels());
|
||||
const LayerPoint scrollOffset = frameMetrics.GetScrollOffsetInLayerPixels();
|
||||
const gfx::Point layerTransform = GetScrollData(aLayer);
|
||||
gfx::Point layerScroll;
|
||||
layerScroll.x = scrollOffset.x - layerTransform.x;
|
||||
layerScroll.y = scrollOffset.y - layerTransform.y;
|
||||
const gfx::Point layerScroll = scrollOffset.ToUnknownPoint() - layerTransform;
|
||||
|
||||
printf_stderr("UniformityInfo Layer_Move %llu %p %f, %f\n",
|
||||
TimeStamp::Now(), aLayer, layerScroll.x, layerScroll.y);
|
||||
|
@ -474,8 +474,8 @@ DecomposeIntoNoRepeatRects(const Rect& aRect,
|
||||
|
||||
// If we are dealing with wrapping br.x and br.y are greater than 1.0 so
|
||||
// wrap them here as well.
|
||||
br = Point(xwrap ? WrapTexCoord(br.x) : br.x,
|
||||
ywrap ? WrapTexCoord(br.y) : br.y);
|
||||
br = Point(xwrap ? WrapTexCoord(br.x) : br.x.value,
|
||||
ywrap ? WrapTexCoord(br.y) : br.y.value);
|
||||
|
||||
// If we wrap around along the x axis, we will draw first from
|
||||
// tl.x .. 1.0 and then from 0.0 .. br.x (which we just wrapped above).
|
||||
@ -759,8 +759,7 @@ CompositorOGL::BeginFrame(const nsIntRegion& aInvalidRegion,
|
||||
// UI for its dynamic toolbar.
|
||||
IntPoint origin;
|
||||
if (!mTarget) {
|
||||
origin.x = -mRenderOffset.x;
|
||||
origin.y = -mRenderOffset.y;
|
||||
origin = -TruncatedToInt(mRenderOffset.ToUnknownPoint());
|
||||
}
|
||||
|
||||
mCurrentRenderTarget =
|
||||
|
@ -7,6 +7,7 @@
|
||||
#ifndef MOZ_UNITS_H_
|
||||
#define MOZ_UNITS_H_
|
||||
|
||||
#include "mozilla/gfx/Coord.h"
|
||||
#include "mozilla/gfx/Point.h"
|
||||
#include "mozilla/gfx/Rect.h"
|
||||
#include "mozilla/gfx/ScaleFactor.h"
|
||||
@ -30,6 +31,8 @@ template<> struct IsPixel<LayoutDevicePixel> : TrueType {};
|
||||
template<> struct IsPixel<LayerPixel> : TrueType {};
|
||||
template<> struct IsPixel<ScreenPixel> : TrueType {};
|
||||
|
||||
typedef gfx::CoordTyped<CSSPixel> CSSCoord;
|
||||
typedef gfx::IntCoordTyped<CSSPixel> CSSIntCoord;
|
||||
typedef gfx::PointTyped<CSSPixel> CSSPoint;
|
||||
typedef gfx::IntPointTyped<CSSPixel> CSSIntPoint;
|
||||
typedef gfx::SizeTyped<CSSPixel> CSSSize;
|
||||
@ -39,6 +42,8 @@ typedef gfx::IntRectTyped<CSSPixel> CSSIntRect;
|
||||
typedef gfx::MarginTyped<CSSPixel> CSSMargin;
|
||||
typedef gfx::IntMarginTyped<CSSPixel> CSSIntMargin;
|
||||
|
||||
typedef gfx::CoordTyped<LayoutDevicePixel> LayoutDeviceCoord;
|
||||
typedef gfx::IntCoordTyped<LayoutDevicePixel> LayoutDeviceIntCoord;
|
||||
typedef gfx::PointTyped<LayoutDevicePixel> LayoutDevicePoint;
|
||||
typedef gfx::IntPointTyped<LayoutDevicePixel> LayoutDeviceIntPoint;
|
||||
typedef gfx::SizeTyped<LayoutDevicePixel> LayoutDeviceSize;
|
||||
@ -48,6 +53,8 @@ typedef gfx::IntRectTyped<LayoutDevicePixel> LayoutDeviceIntRect;
|
||||
typedef gfx::MarginTyped<LayoutDevicePixel> LayoutDeviceMargin;
|
||||
typedef gfx::IntMarginTyped<LayoutDevicePixel> LayoutDeviceIntMargin;
|
||||
|
||||
typedef gfx::CoordTyped<LayerPixel> LayerCoord;
|
||||
typedef gfx::IntCoordTyped<LayerPixel> LayerIntCoord;
|
||||
typedef gfx::PointTyped<LayerPixel> LayerPoint;
|
||||
typedef gfx::IntPointTyped<LayerPixel> LayerIntPoint;
|
||||
typedef gfx::SizeTyped<LayerPixel> LayerSize;
|
||||
@ -57,6 +64,8 @@ typedef gfx::IntRectTyped<LayerPixel> LayerIntRect;
|
||||
typedef gfx::MarginTyped<LayerPixel> LayerMargin;
|
||||
typedef gfx::IntMarginTyped<LayerPixel> LayerIntMargin;
|
||||
|
||||
typedef gfx::CoordTyped<ScreenPixel> ScreenCoord;
|
||||
typedef gfx::IntCoordTyped<ScreenPixel> ScreenIntCoord;
|
||||
typedef gfx::PointTyped<ScreenPixel> ScreenPoint;
|
||||
typedef gfx::IntPointTyped<ScreenPixel> ScreenIntPoint;
|
||||
typedef gfx::SizeTyped<ScreenPixel> ScreenSize;
|
||||
|
@ -737,9 +737,7 @@ MetroInput::TransformRefPoint(const Foundation::Point& aPosition, LayoutDeviceIn
|
||||
// If this event is destined for content we need to transform our ref point through
|
||||
// the apz so that zoom can be accounted for.
|
||||
aRefPointOut = LayoutDeviceIntPoint::FromUntyped(MetroUtils::LogToPhys(aPosition));
|
||||
ScreenIntPoint spt;
|
||||
spt.x = aRefPointOut.x;
|
||||
spt.y = aRefPointOut.y;
|
||||
ScreenIntPoint spt(aRefPointOut.x, aRefPointOut.y);
|
||||
// This is currently a general contained rect hit test, it may produce a false positive for
|
||||
// overlay chrome elements.
|
||||
bool apzIntersect = mWidget->ApzHitTest(spt);
|
||||
|
@ -1805,8 +1805,8 @@ nsBaseWidget::debug_DumpEvent(FILE * aFileOut,
|
||||
(void *) aWidget,
|
||||
aWidgetName.get(),
|
||||
aWindowID,
|
||||
aGuiEvent->refPoint.x,
|
||||
aGuiEvent->refPoint.y);
|
||||
aGuiEvent->refPoint.x.value,
|
||||
aGuiEvent->refPoint.y.value);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////
|
||||
/* static */ void
|
||||
|
Loading…
Reference in New Issue
Block a user