Backed out changeset 450c9dfc8858 (bug 1922208) for causing multiple failures.

This commit is contained in:
Stanca Serban
2024-10-02 15:55:26 +03:00
parent b8c2336350
commit 242553ef4b
14 changed files with 54 additions and 37 deletions

View File

@@ -205,11 +205,12 @@ ClippedImage::GetIntrinsicSize(nsSize* aSize) {
return NS_OK; return NS_OK;
} }
AspectRatio ClippedImage::GetIntrinsicRatio() { Maybe<AspectRatio> ClippedImage::GetIntrinsicRatio() {
if (!ShouldClip()) { if (!ShouldClip()) {
return InnerImage()->GetIntrinsicRatio(); return InnerImage()->GetIntrinsicRatio();
} }
return AspectRatio::FromSize(mClip.Width(), mClip.Height());
return Some(AspectRatio::FromSize(mClip.Width(), mClip.Height()));
} }
NS_IMETHODIMP_(already_AddRefed<SourceSurface>) NS_IMETHODIMP_(already_AddRefed<SourceSurface>)

View File

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

View File

@@ -104,9 +104,9 @@ DynamicImage::GetIntrinsicSize(nsSize* aSize) {
return NS_OK; return NS_OK;
} }
AspectRatio DynamicImage::GetIntrinsicRatio() { Maybe<AspectRatio> DynamicImage::GetIntrinsicRatio() {
auto size = mDrawable->Size(); auto size = mDrawable->Size();
return AspectRatio::FromSize(size.width, size.height); return Some(AspectRatio::FromSize(size.width, size.height));
} }
NS_IMETHODIMP_(Orientation) NS_IMETHODIMP_(Orientation)

View File

@@ -119,7 +119,7 @@ ImageWrapper::GetIntrinsicSize(nsSize* aSize) {
return mInnerImage->GetIntrinsicSize(aSize); return mInnerImage->GetIntrinsicSize(aSize);
} }
AspectRatio ImageWrapper::GetIntrinsicRatio() { Maybe<AspectRatio> ImageWrapper::GetIntrinsicRatio() {
return mInnerImage->GetIntrinsicRatio(); return mInnerImage->GetIntrinsicRatio();
} }

View File

@@ -66,10 +66,10 @@ OrientedImage::GetIntrinsicSize(nsSize* aSize) {
return rv; return rv;
} }
AspectRatio OrientedImage::GetIntrinsicRatio() { Maybe<AspectRatio> OrientedImage::GetIntrinsicRatio() {
AspectRatio ratio = InnerImage()->GetIntrinsicRatio(); Maybe<AspectRatio> ratio = InnerImage()->GetIntrinsicRatio();
if (ratio && mOrientation.SwapsWidthAndHeight()) { if (ratio && mOrientation.SwapsWidthAndHeight()) {
ratio = ratio.Inverted(); ratio = Some(ratio->Inverted());
} }
return ratio; return ratio;
} }

View File

@@ -31,7 +31,7 @@ class OrientedImage : public ImageWrapper {
NS_IMETHOD GetHeight(int32_t* aHeight) override; NS_IMETHOD GetHeight(int32_t* aHeight) override;
nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) override; nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) override;
NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override; NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override;
AspectRatio GetIntrinsicRatio() override; Maybe<AspectRatio> GetIntrinsicRatio() override;
NS_IMETHOD_(already_AddRefed<SourceSurface>) NS_IMETHOD_(already_AddRefed<SourceSurface>)
GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override; GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override;
NS_IMETHOD_(already_AddRefed<SourceSurface>) NS_IMETHOD_(already_AddRefed<SourceSurface>)

View File

@@ -256,11 +256,12 @@ RasterImage::GetIntrinsicSize(nsSize* aSize) {
} }
//****************************************************************************** //******************************************************************************
AspectRatio RasterImage::GetIntrinsicRatio() { Maybe<AspectRatio> RasterImage::GetIntrinsicRatio() {
if (mError) { if (mError) {
return {}; return Nothing();
} }
return AspectRatio::FromSize(mSize.width, mSize.height);
return Some(AspectRatio::FromSize(mSize.width, mSize.height));
} }
NS_IMETHODIMP_(Orientation) NS_IMETHODIMP_(Orientation)

View File

@@ -596,9 +596,10 @@ class ImageSurfaceCache {
// available. If our guess was too small, don't use factor-of-scaling. // available. If our guess was too small, don't use factor-of-scaling.
MOZ_ASSERT(mIsVectorImage); MOZ_ASSERT(mIsVectorImage);
factorSize = IntSize(100, 100); factorSize = IntSize(100, 100);
if (AspectRatio aspectRatio = image->GetIntrinsicRatio()) { Maybe<AspectRatio> aspectRatio = image->GetIntrinsicRatio();
if (aspectRatio && *aspectRatio) {
factorSize.width = factorSize.width =
NSToIntRound(aspectRatio.ApplyToFloat(float(factorSize.height))); NSToIntRound(aspectRatio->ApplyToFloat(float(factorSize.height)));
if (factorSize.IsEmpty()) { if (factorSize.IsEmpty()) {
return aSize; return aSize;
} }

View File

@@ -580,15 +580,17 @@ VectorImage::GetIntrinsicSize(nsSize* aSize) {
} }
//****************************************************************************** //******************************************************************************
AspectRatio VectorImage::GetIntrinsicRatio() { Maybe<AspectRatio> VectorImage::GetIntrinsicRatio() {
if (mError || !mIsFullyLoaded) { if (mError || !mIsFullyLoaded) {
return {}; return Nothing();
} }
nsIFrame* rootFrame = mSVGDocumentWrapper->GetRootLayoutFrame(); nsIFrame* rootFrame = mSVGDocumentWrapper->GetRootLayoutFrame();
if (!rootFrame) { if (!rootFrame) {
return {}; return Nothing();
} }
return rootFrame->GetIntrinsicRatio();
return Some(rootFrame->GetIntrinsicRatio());
} }
NS_IMETHODIMP_(Orientation) NS_IMETHODIMP_(Orientation)

View File

@@ -21,12 +21,9 @@ webidl Document;
#include "limits.h" #include "limits.h"
class gfxContext; class gfxContext;
class nsIFrame;
namespace mozilla { namespace mozilla {
class TimeStamp; struct AspectRatio;
class SVGImageContext;
struct MediaFeatureChange;
namespace gfx { namespace gfx {
class SourceSurface; class SourceSurface;
@@ -36,19 +33,31 @@ class WindowRenderer;
namespace layers { namespace layers {
class ImageContainer; class ImageContainer;
} }
}
class nsIFrame;
namespace mozilla {
class TimeStamp;
class SVGImageContext;
struct MediaFeatureChange;
}
namespace mozilla {
namespace image { namespace image {
class ImageRegion; class ImageRegion;
class ImageIntRegion; class ImageIntRegion;
class WebRenderImageProvider; class WebRenderImageProvider;
struct Orientation; struct Orientation;
struct Resolution; struct Resolution;
} }
} }
%} %}
native AspectRatio(mozilla::AspectRatio); native MaybeAspectRatio(mozilla::Maybe<mozilla::AspectRatio>);
native ImgDrawResult(mozilla::image::ImgDrawResult); native ImgDrawResult(mozilla::image::ImgDrawResult);
[ptr] native gfxContext(gfxContext); [ptr] native gfxContext(gfxContext);
[ref] native gfxMatrix(gfxMatrix); [ref] native gfxMatrix(gfxMatrix);
@@ -106,11 +115,10 @@ interface imgIContainer : nsISupports
[noscript] readonly attribute nsSize intrinsicSize; [noscript] readonly attribute nsSize intrinsicSize;
/** /**
* The (dimensionless) intrinsic ratio of this image. Might return a * The (dimensionless) intrinsic ratio of this image. In the case of any
* degenerate ratio (one that returns 'false' when coerced to a bool) * error, Nothing() will be returned.
* if the image is in an error state, or there's no ratio.
*/ */
[notxpcom, nostdcall] readonly attribute AspectRatio intrinsicRatio; [notxpcom, nostdcall] readonly attribute MaybeAspectRatio intrinsicRatio;
/** /**
* The x coordinate of the image's hotspot, or 0 if there is no hotspot. * The x coordinate of the image's hotspot, or 0 if there is no hotspot.

View File

@@ -6215,7 +6215,8 @@ void nsLayoutUtils::ComputeSizeForDrawing(
/* outparam */ bool& aGotHeight) { /* outparam */ bool& aGotHeight) {
aGotWidth = NS_SUCCEEDED(aImage->GetWidth(&aImageSize.width)); aGotWidth = NS_SUCCEEDED(aImage->GetWidth(&aImageSize.width));
aGotHeight = NS_SUCCEEDED(aImage->GetHeight(&aImageSize.height)); aGotHeight = NS_SUCCEEDED(aImage->GetHeight(&aImageSize.height));
aIntrinsicRatio = aImage->GetIntrinsicRatio(); Maybe<AspectRatio> intrinsicRatio = aImage->GetIntrinsicRatio();
aIntrinsicRatio = intrinsicRatio.valueOr(AspectRatio());
if (aGotWidth) { if (aGotWidth) {
aResolution.ApplyXTo(aImageSize.width); aResolution.ApplyXTo(aImageSize.width);
@@ -6224,7 +6225,7 @@ void nsLayoutUtils::ComputeSizeForDrawing(
aResolution.ApplyYTo(aImageSize.height); aResolution.ApplyYTo(aImageSize.height);
} }
if (!(aGotWidth && aGotHeight) && !aIntrinsicRatio) { if (!(aGotWidth && aGotHeight) && intrinsicRatio.isNothing()) {
// We hit an error (say, because the image failed to load or couldn't be // We hit an error (say, because the image failed to load or couldn't be
// decoded) and should return zero size. // decoded) and should return zero size.
aGotWidth = aGotHeight = true; aGotWidth = aGotHeight = true;

View File

@@ -924,8 +924,8 @@ AspectRatio nsImageFrame::ComputeIntrinsicRatioForImage(
} }
if (aImage) { if (aImage) {
if (AspectRatio fromImage = aImage->GetIntrinsicRatio()) { if (Maybe<AspectRatio> fromImage = aImage->GetIntrinsicRatio()) {
return fromImage; return *fromImage;
} }
} }
if (ShouldUseMappedAspectRatio()) { if (ShouldUseMappedAspectRatio()) {

View File

@@ -249,6 +249,7 @@ bool SVGImageFrame::GetIntrinsicImageDimensions(
} }
ImageResolution resolution = mImageContainer->GetResolution(); ImageResolution resolution = mImageContainer->GetResolution();
int32_t width, height; int32_t width, height;
if (NS_FAILED(mImageContainer->GetWidth(&width))) { if (NS_FAILED(mImageContainer->GetWidth(&width))) {
aSize.width = -1; aSize.width = -1;
@@ -264,7 +265,9 @@ bool SVGImageFrame::GetIntrinsicImageDimensions(
resolution.ApplyYTo(aSize.height); resolution.ApplyYTo(aSize.height);
} }
aAspectRatio = mImageContainer->GetIntrinsicRatio(); Maybe<AspectRatio> asp = mImageContainer->GetIntrinsicRatio();
aAspectRatio = asp.valueOr(AspectRatio{});
return true; return true;
} }

View File

@@ -515,16 +515,16 @@ nsresult nsCocoaUtils::CreateNSImageFromImageContainer(
{ {
const bool gotWidth = NS_SUCCEEDED(aImage->GetWidth(&width)); const bool gotWidth = NS_SUCCEEDED(aImage->GetWidth(&width));
const bool gotHeight = NS_SUCCEEDED(aImage->GetHeight(&height)); const bool gotHeight = NS_SUCCEEDED(aImage->GetHeight(&height));
if (auto ratio = aImage->GetIntrinsicRatio()) { if (auto ratio = aImage->GetIntrinsicRatio(); ratio && *ratio) {
if (gotWidth != gotHeight) { if (gotWidth != gotHeight) {
if (gotWidth) { if (gotWidth) {
height = ratio.Inverted().ApplyTo(width); height = ratio->Inverted().ApplyTo(width);
} else { } else {
width = ratio.ApplyTo(height); width = ratio->ApplyTo(height);
} }
} else if (!gotWidth) { } else if (!gotWidth) {
height = std::ceil(aPreferredSize.height); height = std::ceil(aPreferredSize.height);
width = ratio.ApplyTo(height); width = ratio->ApplyTo(height);
} }
} }
} }