Bug 1732115 - Part 5. Remove reorientation code from RasterImage. r=tnikkel

This is now all handled in the layers below.

Differential Revision: https://phabricator.services.mozilla.com/D126383
This commit is contained in:
Andrew Osmond 2021-10-06 14:41:18 +00:00
Родитель 211e37f75c
Коммит 774ef22598
3 изменённых файлов: 1 добавлений и 113 удалений

Просмотреть файл

@ -577,13 +577,11 @@ RasterImage::GetFrameInternal(const IntSize& aSize,
// FLAG_SYNC_DECODE.
LookupResult result = LookupFrame(size, aFlags, ToPlaybackType(aWhichFrame),
/* aMarkUsed = */ true);
auto resultSuggestedSize =
UnorientedIntSize::FromUnknownSize(result.SuggestedSize());
// The surface cache may have suggested we use a different size than the
// given size in the future. This may or may not be accompanied by an
// actual surface, depending on what it has in its cache.
OrientedIntSize suggestedSize = ToOriented(resultSuggestedSize);
auto suggestedSize = OrientedIntSize::FromUnknownSize(result.SuggestedSize());
if (suggestedSize.IsEmpty()) {
suggestedSize = size;
}
@ -597,12 +595,6 @@ RasterImage::GetFrameInternal(const IntSize& aSize,
}
RefPtr<SourceSurface> surface = result.Surface()->GetSourceSurface();
// If this RasterImage requires orientation, we must return a newly created
// surface with the oriented image instead of returning the frame's surface
// directly.
surface = OrientedImage::OrientSurface(mOrientation, surface);
if (!result.Surface()->IsFinished()) {
return MakeTuple(ImgDrawResult::INCOMPLETE, suggestedSize.ToUnknownSize(),
std::move(surface));
@ -1779,82 +1771,5 @@ IntSize RasterImage::OptimalImageSizeForDest(const gfxSize& aDest,
return mSize.ToUnknownSize();
}
gfxMatrix RasterImage::OrientationMatrix(const UnorientedIntSize& aSize,
bool aInvert) const {
return OrientedImage::OrientationMatrix(mOrientation, aSize.ToUnknownSize(),
aInvert);
}
/**
* Rotate aRect by the given angle within the space specified by aSize.
*
* For example, with aRect = [20, 10, 5, 5] and aSize = [100, 100], rotating
* with Angle::D90 will result in aRect = [85, 20, 5, 5].
*/
static void Rotate(IntRect& aRect, const IntSize& aSize, Angle aAngle) {
switch (aAngle) {
case Angle::D0:
break;
case Angle::D90:
aRect = {aSize.height - aRect.YMost(), aRect.x, aRect.height,
aRect.width};
break;
case Angle::D180:
aRect.MoveTo(aSize.width - aRect.XMost(), aSize.height - aRect.YMost());
break;
case Angle::D270:
aRect = {aRect.y, aSize.width - aRect.XMost(), aRect.height, aRect.width};
break;
}
}
/**
* Flip aRect along the central axis within aSize.
*
* For example, with aRect = [20, 10, 5, 5] and aSize = [100, 100], flipping
* with Flip::Horizontal will result in aRect = [75, 10, 5, 5].
*/
static void Flip(IntRect& aRect, const IntSize& aSize, Flip aFlip) {
switch (aFlip) {
case Flip::Unflipped:
break;
case Flip::Horizontal:
aRect.x = aSize.width - aRect.XMost();
break;
}
}
OrientedIntRect RasterImage::ToOriented(UnorientedIntRect aRect) const {
IntRect rect = aRect.ToUnknownRect();
auto size = ToUnoriented(mSize);
MOZ_ASSERT(!mOrientation.flipFirst,
"flipFirst should only be used by OrientedImage");
// mOrientation specifies the transformation from a correctly oriented image
// to the pixels stored in the file, so we need to rotate by the negation of
// the given angle.
Angle angle = Orientation::InvertAngle(mOrientation.rotation);
Rotate(rect, size.ToUnknownSize(), angle);
// Use mSize instead of size, since after the Rotate call, the size of the
// space that rect is in has had its width and height swapped.
Flip(rect, mSize.ToUnknownSize(), mOrientation.flip);
return OrientedIntRect::FromUnknownRect(rect);
}
UnorientedIntRect RasterImage::ToUnoriented(OrientedIntRect aRect) const {
IntRect rect = aRect.ToUnknownRect();
Flip(rect, mSize.ToUnknownSize(), mOrientation.flip);
Rotate(rect, mSize.ToUnknownSize(), mOrientation.rotation);
MOZ_ASSERT(!mOrientation.flipFirst,
"flipFirst should only be used by OrientedImage");
return UnorientedIntRect::FromUnknownRect(rect);
}
} // namespace image
} // namespace mozilla

Просмотреть файл

@ -361,29 +361,6 @@ class RasterImage final : public ImageResource,
void OnSurfaceDiscardedInternal(bool aAnimatedFramesDiscarded);
/**
* Computes a matrix that applies the rotation and reflection specified by
* mOrientation, or that matrix's inverse if aInvert is true.
*
* See OrientedImage::OrientationMatrix.
*/
gfxMatrix OrientationMatrix(const UnorientedIntSize& aSize,
bool aInvert = false) const;
// Functions to convert between oriented and unoriented pixels.
UnorientedIntSize ToUnoriented(OrientedIntSize aSize) const {
return mOrientation.SwapsWidthAndHeight()
? UnorientedIntSize(aSize.height, aSize.width)
: UnorientedIntSize(aSize.width, aSize.height);
}
OrientedIntSize ToOriented(UnorientedIntSize aSize) const {
return mOrientation.SwapsWidthAndHeight()
? OrientedIntSize(aSize.height, aSize.width)
: OrientedIntSize(aSize.width, aSize.height);
}
OrientedIntRect ToOriented(UnorientedIntRect aRect) const;
UnorientedIntRect ToUnoriented(OrientedIntRect aRect) const;
private: // data
OrientedIntSize mSize;
nsTArray<OrientedIntSize> mNativeSizes;

Просмотреть файл

@ -566,10 +566,6 @@ class ImageSurfaceCache {
return aSize;
}
if (image->GetOrientation().SwapsWidthAndHeight()) {
std::swap(factorSize.width, factorSize.height);
}
if (mIsVectorImage) {
// Ensure the aspect ratio matches the native size before forcing the
// caller to accept a factor of 2 size. The difference between the aspect