Issue #1619 - Convert Intrinsic Ratio to Float

https://bugzilla.mozilla.org/show_bug.cgi?id=1547792

Aspect Ratio handling simplified by using floating point integers:
- Multiplication of value (or inverse value) to a known side for Scaling
- No unequal equal values such as "4/3" vs "8/6" vs "20/15"
- Truly "Empty" aspect ratios, even if one dimension is not 0
This commit is contained in:
Andy 2020-07-31 13:01:18 -07:00 • committed by Roy Tam
commit 3c02d3fc0d
32 changed files with 314 additions and 229 deletions

View file

@ -242,13 +242,13 @@ ClippedImage::GetIntrinsicSize(nsSize* aSize)
}
NS_IMETHODIMP
ClippedImage::GetIntrinsicRatio(nsSize* aRatio)
ClippedImage::GetIntrinsicRatio(AspectRatio* aRatio)
{
if (!ShouldClip()) {
return InnerImage()->GetIntrinsicRatio(aRatio);
}
*aRatio = nsSize(mClip.width, mClip.height);
*aRatio = AspectRatio::FromSize(mClip.width, mClip.height);
return NS_OK;
}

View file

@ -35,7 +35,7 @@ public:
NS_IMETHOD GetWidth(int32_t* aWidth) override;
NS_IMETHOD GetHeight(int32_t* aHeight) override;
NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override;
NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) override;
NS_IMETHOD GetIntrinsicRatio(AspectRatio* aRatio) override;
NS_IMETHOD_(already_AddRefed<SourceSurface>)
GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override;
NS_IMETHOD_(already_AddRefed<SourceSurface>)

View file

@ -136,10 +136,10 @@ DynamicImage::GetIntrinsicSize(nsSize* aSize)
}
NS_IMETHODIMP
DynamicImage::GetIntrinsicRatio(nsSize* aSize)
DynamicImage::GetIntrinsicRatio(AspectRatio* aRatio)
{
IntSize intSize(mDrawable->Size());
*aSize = nsSize(intSize.width, intSize.height);
auto size = mDrawable->Size();
*aRatio = AspectRatio::FromSize(size);
return NS_OK;
}

View file

@ -146,9 +146,9 @@ ImageWrapper::GetIntrinsicSize(nsSize* aSize)
}
NS_IMETHODIMP
ImageWrapper::GetIntrinsicRatio(nsSize* aSize)
ImageWrapper::GetIntrinsicRatio(AspectRatio* aRatio)
{
return mInnerImage->GetIntrinsicRatio(aSize);
return mInnerImage->GetIntrinsicRatio(aRatio);
}
NS_IMETHODIMP_(Orientation)

View file

@ -59,12 +59,12 @@ OrientedImage::GetIntrinsicSize(nsSize* aSize)
}
NS_IMETHODIMP
OrientedImage::GetIntrinsicRatio(nsSize* aRatio)
OrientedImage::GetIntrinsicRatio(AspectRatio* aRatio)
{
nsresult rv = InnerImage()->GetIntrinsicRatio(aRatio);
if (mOrientation.SwapsWidthAndHeight()) {
swap(aRatio->width, aRatio->height);
*aRatio = aRatio->Inverted();
}
return rv;

View file

@ -31,7 +31,7 @@ public:
NS_IMETHOD GetWidth(int32_t* aWidth) override;
NS_IMETHOD GetHeight(int32_t* aHeight) override;
NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override;
NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) override;
NS_IMETHOD GetIntrinsicRatio(AspectRatio* aRatio) override;
NS_IMETHOD_(already_AddRefed<SourceSurface>)
GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override;
NS_IMETHOD_(already_AddRefed<SourceSurface>)

View file

@ -240,13 +240,14 @@ RasterImage::GetIntrinsicSize(nsSize* aSize)
//******************************************************************************
NS_IMETHODIMP
RasterImage::GetIntrinsicRatio(nsSize* aRatio)
RasterImage::GetIntrinsicRatio(AspectRatio* aRatio)
{
if (mError) {
return NS_ERROR_FAILURE;
}
*aRatio = nsSize(mSize.width, mSize.height);
*aRatio = AspectRatio::FromSize(mSize);
return NS_OK;
}

View file

@ -628,7 +628,7 @@ VectorImage::GetIntrinsicSize(nsSize* aSize)
//******************************************************************************
NS_IMETHODIMP
VectorImage::GetIntrinsicRatio(nsSize* aRatio)
VectorImage::GetIntrinsicRatio(AspectRatio* aRatio)
{
if (mError || !mIsFullyLoaded) {
return NS_ERROR_FAILURE;

View file

@ -12,6 +12,7 @@
#include "gfxMatrix.h"
#include "gfxRect.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/AspectRatio.h"
#include "mozilla/Maybe.h"
#include "mozilla/RefPtr.h"
#include "nsRect.h"
@ -55,6 +56,7 @@ native SamplingFilter(mozilla::gfx::SamplingFilter);
native nsIntRectByVal(nsIntRect);
[ref] native nsIntSize(nsIntSize);
native nsSize(nsSize);
native AspectRatio(mozilla::AspectRatio);
[ptr] native nsIFrame(nsIFrame);
native TempRefImageContainer(already_AddRefed<mozilla::layers::ImageContainer>);
[ref] native ImageRegion(mozilla::image::ImageRegion);
@ -101,7 +103,7 @@ interface imgIContainer : nsISupports
* The (dimensionless) intrinsic ratio of this image. In the case of any
* error, an exception will be thrown.
*/
[noscript] readonly attribute nsSize intrinsicRatio;
[noscript] readonly attribute AspectRatio intrinsicRatio;
/**
* Given a size at which this image will be displayed, and the drawing