Bug 1284837 - Add conversions methods from Point and Size to IntPoint and IntSize for consistency. r=botond

This commit is contained in:
Nicolas Silva 2016-07-26 16:48:34 +02:00
parent 48805c9b3e
commit 40a96c03f2
9 changed files with 79 additions and 19 deletions

View File

@ -538,7 +538,7 @@ DrawTargetSkia::DrawSurfaceWithShadow(SourceSurface *aSurface,
SkPaint shadowPaint;
shadowPaint.setXfermodeMode(GfxOpToSkiaOp(aOperator));
IntPoint shadowDest = RoundedToInt(aDest + aOffset);
auto shadowDest = IntPoint::Round(aDest + aOffset);
SkBitmap blurMask;
if (!UsingSkiaGPU() &&
@ -569,7 +569,7 @@ DrawTargetSkia::DrawSurfaceWithShadow(SourceSurface *aSurface,
}
// Composite the original image after the shadow
IntPoint dest = RoundedToInt(aDest);
auto dest = IntPoint::Round(aDest);
mCanvas->drawBitmap(bitmap, dest.x, dest.y, &paint);
mCanvas->restore();

View File

@ -60,6 +60,9 @@ struct IntParam {
T value;
};
template<class units, class> struct PointTyped;
template<class units, class> struct SizeTyped;
template<class units>
struct IntPointTyped :
public BasePoint< int32_t, IntPointTyped<units>, IntCoordTyped<units> >,
@ -90,6 +93,11 @@ struct IntPointTyped :
return IntPointTyped(int32_t(aX), int32_t(aY));
}
static IntPointTyped<units> Round(const PointTyped<units, float>& aPoint);
static IntPointTyped<units> Ceil(const PointTyped<units, float>& aPoint);
static IntPointTyped<units> Floor(const PointTyped<units, float>& aPoint);
static IntPointTyped<units> Truncate(const PointTyped<units, float>& aPoint);
// XXX When all of the code is ported, the following functions to convert to and from
// unknown types should be removed.
@ -171,6 +179,34 @@ struct Point3DTyped :
typedef Point3DTyped<UnknownUnits> Point3D;
typedef Point3DTyped<UnknownUnits, double> PointDouble3D;
template<typename units>
IntPointTyped<units>
IntPointTyped<units>::Round(const PointTyped<units, float>& aPoint)
{
return IntPointTyped::Round(aPoint.x, aPoint.y);
}
template<typename units>
IntPointTyped<units>
IntPointTyped<units>::Ceil(const PointTyped<units, float>& aPoint)
{
return IntPointTyped::Ceil(aPoint.x, aPoint.y);
}
template<typename units>
IntPointTyped<units>
IntPointTyped<units>::Floor(const PointTyped<units, float>& aPoint)
{
return IntPointTyped::Floor(aPoint.x, aPoint.y);
}
template<typename units>
IntPointTyped<units>
IntPointTyped<units>::Truncate(const PointTyped<units, float>& aPoint)
{
return IntPointTyped::Truncate(aPoint.x, aPoint.y);
}
template<class units, class F = Float>
struct Point4DTyped :
public BasePoint4D< F, Point4DTyped<units, F> > {
@ -229,6 +265,11 @@ struct IntSizeTyped :
return IntSizeTyped(int32_t(floorf(aWidth)), int32_t(floorf(aHeight)));
}
static IntSizeTyped<units> Round(const SizeTyped<units, float>& aSize);
static IntSizeTyped<units> Ceil(const SizeTyped<units, float>& aSize);
static IntSizeTyped<units> Floor(const SizeTyped<units, float>& aSize);
static IntSizeTyped<units> Truncate(const SizeTyped<units, float>& aSize);
// XXX When all of the code is ported, the following functions to convert to and from
// unknown types should be removed.
@ -276,6 +317,26 @@ IntSizeTyped<units> RoundedToInt(const SizeTyped<units>& aSize) {
int32_t(floorf(aSize.height + 0.5f)));
}
template<typename units> IntSizeTyped<units>
IntSizeTyped<units>::Round(const SizeTyped<units, float>& aSize) {
return IntSizeTyped::Round(aSize.width, aSize.height);
}
template<typename units> IntSizeTyped<units>
IntSizeTyped<units>::Ceil(const SizeTyped<units, float>& aSize) {
return IntSizeTyped::Ceil(aSize.width, aSize.height);
}
template<typename units> IntSizeTyped<units>
IntSizeTyped<units>::Floor(const SizeTyped<units, float>& aSize) {
return IntSizeTyped::Floor(aSize.width, aSize.height);
}
template<typename units> IntSizeTyped<units>
IntSizeTyped<units>::Truncate(const SizeTyped<units, float>& aSize) {
return IntSizeTyped::Truncate(aSize.width, aSize.height);
}
} // namespace gfx
} // namespace mozilla

View File

@ -631,7 +631,7 @@ Layer::SnapTransformTranslation(const Matrix4x4& aTransform,
if (aTransform.CanDraw2D(&matrix2D) &&
!matrix2D.HasNonTranslation() &&
matrix2D.HasNonIntegerTranslation()) {
IntPoint snappedTranslation = RoundedToInt(matrix2D.GetTranslation());
auto snappedTranslation = IntPoint::Round(matrix2D.GetTranslation());
Matrix snappedMatrix = Matrix::Translation(snappedTranslation.x,
snappedTranslation.y);
result = Matrix4x4::From2D(snappedMatrix);
@ -663,8 +663,7 @@ Layer::SnapTransformTranslation(const Matrix4x4& aTransform,
// Compute the transformed snap by rounding the values of
// transformed origin.
IntPoint transformedSnapXY =
RoundedToInt(Point(transformedOrigin.x, transformedOrigin.y));
auto transformedSnapXY = IntPoint::Round(transformedOrigin.x, transformedOrigin.y);
Matrix4x4 inverse = aTransform;
inverse.Invert();
// see Matrix4x4::ProjectPoint()
@ -722,9 +721,9 @@ Layer::SnapTransform(const Matrix4x4& aTransform,
aTransform.Is2D(&matrix2D) &&
gfxSize(1.0, 1.0) <= aSnapRect.Size() &&
matrix2D.PreservesAxisAlignedRectangles()) {
IntPoint transformedTopLeft = RoundedToInt(matrix2D * ToPoint(aSnapRect.TopLeft()));
IntPoint transformedTopRight = RoundedToInt(matrix2D * ToPoint(aSnapRect.TopRight()));
IntPoint transformedBottomRight = RoundedToInt(matrix2D * ToPoint(aSnapRect.BottomRight()));
auto transformedTopLeft = IntPoint::Round(matrix2D * ToPoint(aSnapRect.TopLeft()));
auto transformedTopRight = IntPoint::Round(matrix2D * ToPoint(aSnapRect.TopRight()));
auto transformedBottomRight = IntPoint::Round(matrix2D * ToPoint(aSnapRect.BottomRight()));
Matrix snappedMatrix = gfxUtils::TransformRectToRect(aSnapRect,
transformedTopLeft, transformedTopRight, transformedBottomRight);
@ -1028,7 +1027,7 @@ Layer::TransformRectToRenderTarget(const LayerIntRect& aRect)
bool
Layer::GetVisibleRegionRelativeToRootLayer(nsIntRegion& aResult,
nsIntPoint* aLayerOffset)
IntPoint* aLayerOffset)
{
MOZ_ASSERT(aLayerOffset, "invalid offset pointer");
@ -1046,7 +1045,7 @@ Layer::GetVisibleRegionRelativeToRootLayer(nsIntRegion& aResult,
}
// The offset of |layer| to its parent.
IntPoint currentLayerOffset = RoundedToInt(matrix.GetTranslation());
auto currentLayerOffset = IntPoint::Round(matrix.GetTranslation());
// Translate the accumulated visible region of |this| by the offset of
// |layer|.
@ -1073,7 +1072,7 @@ Layer::GetVisibleRegionRelativeToRootLayer(nsIntRegion& aResult,
// Retreive the translation from sibling to |layer|. The accumulated
// visible region is currently oriented with |layer|.
IntPoint siblingOffset = RoundedToInt(siblingMatrix.GetTranslation());
auto siblingOffset = IntPoint::Round(siblingMatrix.GetTranslation());
nsIntRegion siblingVisibleRegion(sibling->GetLocalVisibleRegion().ToUnknownRegion());
// Translate the siblings region to |layer|'s origin.
siblingVisibleRegion.MoveBy(-siblingOffset.x, -siblingOffset.y);
@ -1092,7 +1091,7 @@ Layer::GetVisibleRegionRelativeToRootLayer(nsIntRegion& aResult,
offset += currentLayerOffset;
}
*aLayerOffset = nsIntPoint(offset.x, offset.y);
*aLayerOffset = IntPoint(offset.x, offset.y);
return true;
}

View File

@ -1387,7 +1387,7 @@ public:
* visible regions of higher siblings of this layer and each ancestor.
*
* Note translation values for offsets of visible regions and accumulated
* aLayerOffset are integer rounded using Point's RoundedToInt.
* aLayerOffset are integer rounded using IntPoint::Round.
*
* @param aResult - the resulting visible region of this layer.
* @param aLayerOffset - this layer's total offset from the root layer.

View File

@ -158,7 +158,7 @@ public:
const gfx::IntSize& GetTileSize() const { return mTileSize; }
gfx::IntSize GetScaledTileSize() const { return RoundedToInt(gfx::Size(mTileSize) / mResolution); }
gfx::IntSize GetScaledTileSize() const { return gfx::IntSize::Round(gfx::Size(mTileSize) / mResolution); }
unsigned int GetTileCount() const { return mRetainedTiles.Length(); }

View File

@ -267,7 +267,7 @@ HitTestingTreeNode::HitTest(const ParentLayerPoint& aPoint) const
if (!pointInLayerPixels) {
return HitTestResult::HitNothing;
}
LayerIntPoint point = RoundedToInt(pointInLayerPixels.ref());
auto point = LayerIntPoint::Round(pointInLayerPixels.ref());
// test against event regions in Layer coordinate space
if (!mEventRegions.mHitRegion.Contains(point.x, point.y)) {

View File

@ -430,7 +430,7 @@ APZCCallbackHelper::ApplyCallbackTransform(const LayoutDeviceIntPoint& aPoint,
{
LayoutDevicePoint point = LayoutDevicePoint(aPoint.x, aPoint.y);
point = ApplyCallbackTransform(point / aScale, aGuid) * aScale;
return gfx::RoundedToInt(point);
return LayoutDeviceIntPoint::Round(point);
}
void

View File

@ -256,7 +256,7 @@ APZEventState::ProcessLongTap(const nsCOMPtr<nsIPresShell>& aPresShell,
// waiting for a touchend don't trigger.
WidgetTouchEvent cancelTouchEvent(true, eTouchCancel, widget.get());
cancelTouchEvent.mModifiers = WidgetModifiersToDOMModifiers(aModifiers);
LayoutDeviceIntPoint ldPoint = RoundedToInt(point * widget->GetDefaultScale());
auto ldPoint = LayoutDeviceIntPoint::Round(point * widget->GetDefaultScale());
cancelTouchEvent.mTouches.AppendElement(new mozilla::dom::Touch(mLastTouchIdentifier,
ldPoint, LayoutDeviceIntPoint(), 0, 0));
APZCCallbackHelper::DispatchWidgetEvent(cancelTouchEvent);

View File

@ -251,13 +251,13 @@ LayerManagerComposite::PostProcessLayers(Layer* aLayer,
// a giant layer if it is a leaf.
Matrix4x4 transform = GetAccTransformIn3DContext(aLayer);
Matrix transform2d;
Maybe<nsIntPoint> integerTranslation;
Maybe<IntPoint> integerTranslation;
// If aLayer has a simple transform (only an integer translation) then we
// can easily convert aOpaqueRegion into pre-transform coordinates and include
// that region.
if (transform.Is2D(&transform2d)) {
if (transform2d.IsIntegerTranslation()) {
integerTranslation = Some(TruncatedToInt(transform2d.GetTranslation()));
integerTranslation = Some(IntPoint::Truncate(transform2d.GetTranslation()));
localOpaque = aOpaqueRegion;
localOpaque.MoveBy(-*integerTranslation);
}