Skip to content

Commit 09266ef

Browse files
committed
Bug 1732115 - Part 3. Refactor decoder pipeline to partially use Unoriented/OrientedPixel. r=tnikkel
Rather than change every use of IntSize/Rect/Point in image/, this patch attempts to draw the line at the relevant parts of the decoding pipeline to prevent confusion about which size and orientation we are working with. Differential Revision: https://phabricator.services.mozilla.com/D126381
1 parent e2050d4 commit 09266ef

30 files changed

+285
-298
lines changed

image/Decoder.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ void Decoder::CompleteDecode() {
266266
}
267267
}
268268

269-
void Decoder::SetOutputSize(const gfx::IntSize& aSize) {
269+
void Decoder::SetOutputSize(const OrientedIntSize& aSize) {
270270
mOutputSize = Some(aSize);
271271
mHaveExplicitOutputSize = true;
272272
}
273273

274-
Maybe<gfx::IntSize> Decoder::ExplicitOutputSize() const {
274+
Maybe<OrientedIntSize> Decoder::ExplicitOutputSize() const {
275275
MOZ_ASSERT_IF(mHaveExplicitOutputSize, mOutputSize);
276276
return mHaveExplicitOutputSize ? mOutputSize : Nothing();
277277
}
@@ -448,10 +448,11 @@ void Decoder::PostSize(int32_t aWidth, int32_t aHeight,
448448

449449
// Set our output size if it's not already set.
450450
if (!mOutputSize) {
451-
mOutputSize = Some(IntSize(aWidth, aHeight));
451+
mOutputSize = Some(mImageMetadata.GetSize());
452452
}
453453

454-
MOZ_ASSERT(mOutputSize->width <= aWidth && mOutputSize->height <= aHeight,
454+
MOZ_ASSERT(mOutputSize->width <= mImageMetadata.GetSize().width &&
455+
mOutputSize->height <= mImageMetadata.GetSize().height,
455456
"Output size will result in upscaling");
456457

457458
// Record this notification.
@@ -486,7 +487,8 @@ void Decoder::PostFrameStop(Opacity aFrameOpacity) {
486487
// If we're not sending partial invalidations, then we send an invalidation
487488
// here when the first frame is complete.
488489
if (!ShouldSendPartialInvalidations()) {
489-
mInvalidRect.UnionRect(mInvalidRect, IntRect(IntPoint(), Size()));
490+
mInvalidRect.UnionRect(mInvalidRect,
491+
OrientedIntRect(OrientedIntPoint(), Size()));
490492
}
491493

492494
// If we dispose of the first frame by clearing it, then the first frame's
@@ -498,7 +500,7 @@ void Decoder::PostFrameStop(Opacity aFrameOpacity) {
498500
case DisposalMethod::CLEAR:
499501
case DisposalMethod::CLEAR_ALL:
500502
case DisposalMethod::RESTORE_PREVIOUS:
501-
mFirstFrameRefreshArea = IntRect(IntPoint(), Size());
503+
mFirstFrameRefreshArea = IntRect(IntPoint(), Size().ToUnknownSize());
502504
break;
503505
case DisposalMethod::KEEP:
504506
case DisposalMethod::NOT_SPECIFIED:
@@ -512,8 +514,8 @@ void Decoder::PostFrameStop(Opacity aFrameOpacity) {
512514
}
513515
}
514516

515-
void Decoder::PostInvalidation(const gfx::IntRect& aRect,
516-
const Maybe<gfx::IntRect>& aRectAtOutputSize
517+
void Decoder::PostInvalidation(const OrientedIntRect& aRect,
518+
const Maybe<OrientedIntRect>& aRectAtOutputSize
517519
/* = Nothing() */) {
518520
// We should be mid-frame
519521
MOZ_ASSERT(mInFrame, "Can't invalidate when not mid-frame!");
@@ -523,7 +525,8 @@ void Decoder::PostInvalidation(const gfx::IntRect& aRect,
523525
// or we're past the first frame.
524526
if (ShouldSendPartialInvalidations() && mFrameCount == 1) {
525527
mInvalidRect.UnionRect(mInvalidRect, aRect);
526-
mCurrentFrame->ImageUpdated(aRectAtOutputSize.valueOr(aRect));
528+
mCurrentFrame->ImageUpdated(
529+
aRectAtOutputSize.valueOr(aRect).ToUnknownRect());
527530
}
528531
}
529532

image/Decoder.h

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class Decoder {
157157
* TakeInvalidRect() returns only the invalidation region accumulated since
158158
* the last call to TakeInvalidRect().
159159
*/
160-
nsIntRect TakeInvalidRect() {
161-
nsIntRect invalidRect = mInvalidRect;
160+
OrientedIntRect TakeInvalidRect() {
161+
OrientedIntRect invalidRect = mInvalidRect;
162162
mInvalidRect.SetEmpty();
163163
return invalidRect;
164164
}
@@ -211,7 +211,7 @@ class Decoder {
211211
*
212212
* This must be called before Init() is called.
213213
*/
214-
void SetOutputSize(const gfx::IntSize& aSize);
214+
void SetOutputSize(const OrientedIntSize& aSize);
215215

216216
/**
217217
* @return the output size of this decoder. If this is smaller than the
@@ -220,7 +220,7 @@ class Decoder {
220220
*
221221
* Illegal to call if HasSize() returns false.
222222
*/
223-
gfx::IntSize OutputSize() const {
223+
OrientedIntSize OutputSize() const {
224224
MOZ_ASSERT(HasSize());
225225
return *mOutputSize;
226226
}
@@ -229,13 +229,13 @@ class Decoder {
229229
* @return either the size passed to SetOutputSize() or Nothing(), indicating
230230
* that SetOutputSize() was not explicitly called.
231231
*/
232-
Maybe<gfx::IntSize> ExplicitOutputSize() const;
232+
Maybe<OrientedIntSize> ExplicitOutputSize() const;
233233

234234
/**
235235
* Sets the expected image size of this decoder. Decoding will fail if this
236236
* does not match.
237237
*/
238-
void SetExpectedSize(const gfx::IntSize& aSize) {
238+
void SetExpectedSize(const OrientedIntSize& aSize) {
239239
mExpectedSize.emplace(aSize);
240240
}
241241

@@ -342,7 +342,7 @@ class Decoder {
342342
*
343343
* Illegal to call if HasSize() returns false.
344344
*/
345-
gfx::IntSize Size() const {
345+
OrientedIntSize Size() const {
346346
MOZ_ASSERT(HasSize());
347347
return mImageMetadata.GetSize();
348348
}
@@ -354,8 +354,8 @@ class Decoder {
354354
*
355355
* Illegal to call if HasSize() returns false.
356356
*/
357-
gfx::IntRect FullFrame() const {
358-
return gfx::IntRect(gfx::IntPoint(), Size());
357+
OrientedIntRect FullFrame() const {
358+
return OrientedIntRect(OrientedIntPoint(), Size());
359359
}
360360

361361
/**
@@ -369,8 +369,18 @@ class Decoder {
369369
*
370370
* Illegal to call if HasSize() returns false.
371371
*/
372-
gfx::IntRect FullOutputFrame() const {
373-
return gfx::IntRect(gfx::IntPoint(), OutputSize());
372+
OrientedIntRect FullOutputFrame() const {
373+
return OrientedIntRect(OrientedIntPoint(), OutputSize());
374+
}
375+
376+
/**
377+
* @return the orientation of the image.
378+
*
379+
* Illegal to call if HasSize() returns false.
380+
*/
381+
Orientation GetOrientation() const {
382+
MOZ_ASSERT(HasSize());
383+
return mImageMetadata.GetOrientation();
374384
}
375385

376386
/// @return final status information about this decoder. Should be called
@@ -514,8 +524,8 @@ class Decoder {
514524
* be supplied if we're downscaling during decode.
515525
*/
516526
void PostInvalidation(
517-
const gfx::IntRect& aRect,
518-
const Maybe<gfx::IntRect>& aRectAtOutputSize = Nothing());
527+
const OrientedIntRect& aRect,
528+
const Maybe<OrientedIntRect>& aRectAtOutputSize = Nothing());
519529

520530
// Called by the decoders when they have successfully decoded the image. This
521531
// may occur as the result of the decoder getting to the appropriate point in
@@ -586,14 +596,14 @@ class Decoder {
586596

587597
ImageMetadata mImageMetadata;
588598

589-
gfx::IntRect
599+
OrientedIntRect
590600
mInvalidRect; // Tracks new rows as the current frame is decoded.
591-
gfx::IntRect mRestoreDirtyRect; // Tracks an invalidation region between the
592-
// restore frame and the previous frame.
593-
gfx::IntRect mRecycleRect; // Tracks an invalidation region between the
594-
// recycled frame and the current frame.
595-
Maybe<gfx::IntSize> mOutputSize; // The size of our output surface.
596-
Maybe<gfx::IntSize> mExpectedSize; // The expected size of the image.
601+
gfx::IntRect mRestoreDirtyRect; // Tracks an invalidation region between the
602+
// restore frame and the previous frame.
603+
gfx::IntRect mRecycleRect; // Tracks an invalidation region between the
604+
// recycled frame and the current frame.
605+
Maybe<OrientedIntSize> mOutputSize; // The size of our output surface.
606+
Maybe<OrientedIntSize> mExpectedSize; // The expected size of the image.
597607
Progress mProgress;
598608

599609
uint32_t mFrameCount; // Number of frames, including anything in-progress

image/DecoderFactory.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ nsresult DecoderFactory::CreateDecoder(
170170
// Initialize the decoder.
171171
decoder->SetMetadataDecode(false);
172172
decoder->SetIterator(aSourceBuffer->Iterator());
173-
decoder->SetOutputSize(aOutputSize);
173+
decoder->SetOutputSize(OrientedIntSize::FromUnknownSize(aOutputSize));
174174
decoder->SetDecoderFlags(aDecoderFlags | DecoderFlags::FIRST_FRAME_ONLY);
175175
decoder->SetSurfaceFlags(aSurfaceFlags);
176176

@@ -320,7 +320,8 @@ already_AddRefed<IDecodingTask> DecoderFactory::CreateMetadataDecoder(
320320
already_AddRefed<Decoder> DecoderFactory::CreateDecoderForICOResource(
321321
DecoderType aType, SourceBufferIterator&& aIterator,
322322
NotNull<nsICODecoder*> aICODecoder, bool aIsMetadataDecode,
323-
const Maybe<IntSize>& aExpectedSize, const Maybe<uint32_t>& aDataOffset
323+
const Maybe<OrientedIntSize>& aExpectedSize,
324+
const Maybe<uint32_t>& aDataOffset
324325
/* = Nothing() */) {
325326
// Create the decoder.
326327
RefPtr<Decoder> decoder;
@@ -389,7 +390,7 @@ already_AddRefed<Decoder> DecoderFactory::CreateAnonymousDecoder(
389390

390391
// Set an output size for downscale-during-decode if requested.
391392
if (aOutputSize) {
392-
decoder->SetOutputSize(*aOutputSize);
393+
decoder->SetOutputSize(OrientedIntSize::FromUnknownSize(*aOutputSize));
393394
}
394395

395396
if (NS_FAILED(decoder->Init())) {

image/DecoderFactory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "mozilla/NotNull.h"
1414
#include "mozilla/gfx/2D.h"
1515
#include "nsCOMPtr.h"
16+
#include "Orientation.h"
1617
#include "SurfaceFlags.h"
1718

1819
namespace mozilla::image {
@@ -154,7 +155,7 @@ class DecoderFactory {
154155
static already_AddRefed<Decoder> CreateDecoderForICOResource(
155156
DecoderType aType, SourceBufferIterator&& aIterator,
156157
NotNull<nsICODecoder*> aICODecoder, bool aIsMetadataDecode,
157-
const Maybe<gfx::IntSize>& aExpectedSize,
158+
const Maybe<OrientedIntSize>& aExpectedSize,
158159
const Maybe<uint32_t>& aDataOffset = Nothing());
159160

160161
/**

image/FrameAnimator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ LookupResult FrameAnimator::GetCompositedFrame(AnimationState& aState,
467467
// getting called which calls UpdateState. The reason we care about this
468468
// is that img.decode promises won't resolve until GetCompositedFrame
469469
// returns a frame.
470-
UnorientedIntRect rect = UnorientedIntRect::FromUnknownRect(
470+
OrientedIntRect rect = OrientedIntRect::FromUnknownRect(
471471
aState.UpdateStateInternal(result, mSize));
472472

473473
if (!rect.IsEmpty()) {

image/IDecodingTask.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ void IDecodingTask::NotifyProgress(NotNull<RasterImage*> aImage,
6565
// calls we make off-main-thread and the notifications that RasterImage
6666
// actually receives, which would cause bugs.
6767
Progress progress = aDecoder->TakeProgress();
68-
UnorientedIntRect invalidRect =
69-
UnorientedIntRect::FromUnknownRect(aDecoder->TakeInvalidRect());
68+
OrientedIntRect invalidRect = aDecoder->TakeInvalidRect();
7069
Maybe<uint32_t> frameCount = aDecoder->TakeCompleteFrameCount();
7170
DecoderFlags decoderFlags = aDecoder->GetDecoderFlags();
7271
SurfaceFlags surfaceFlags = aDecoder->GetSurfaceFlags();
@@ -106,8 +105,7 @@ void IDecodingTask::NotifyDecodeComplete(NotNull<RasterImage*> aImage,
106105
ImageMetadata metadata = aDecoder->GetImageMetadata();
107106
DecoderTelemetry telemetry = aDecoder->Telemetry();
108107
Progress progress = aDecoder->TakeProgress();
109-
UnorientedIntRect invalidRect =
110-
UnorientedIntRect::FromUnknownRect(aDecoder->TakeInvalidRect());
108+
OrientedIntRect invalidRect = aDecoder->TakeInvalidRect();
111109
Maybe<uint32_t> frameCount = aDecoder->TakeCompleteFrameCount();
112110
DecoderFlags decoderFlags = aDecoder->GetDecoderFlags();
113111
SurfaceFlags surfaceFlags = aDecoder->GetSurfaceFlags();

image/ImageMetadata.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,24 @@ class ImageMetadata {
5656
void SetSize(int32_t aWidth, int32_t aHeight, Orientation aOrientation,
5757
Resolution aResolution) {
5858
if (!HasSize()) {
59-
mSize.emplace(nsIntSize(aWidth, aHeight));
59+
mSize.emplace(
60+
aOrientation.ToOriented(UnorientedIntSize(aWidth, aHeight)));
6061
mOrientation.emplace(aOrientation);
6162
mResolution = aResolution;
6263
}
6364
}
64-
nsIntSize GetSize() const { return *mSize; }
65+
OrientedIntSize GetSize() const { return *mSize; }
6566
bool HasSize() const { return mSize.isSome(); }
6667

67-
void AddNativeSize(const nsIntSize& aSize) {
68+
void AddNativeSize(const OrientedIntSize& aSize) {
6869
mNativeSizes.AppendElement(aSize);
6970
}
7071

7172
Resolution GetResolution() const { return mResolution; }
7273

73-
const nsTArray<nsIntSize>& GetNativeSizes() const { return mNativeSizes; }
74+
const nsTArray<OrientedIntSize>& GetNativeSizes() const {
75+
return mNativeSizes;
76+
}
7477

7578
Orientation GetOrientation() const { return *mOrientation; }
7679
bool HasOrientation() const { return mOrientation.isSome(); }
@@ -98,11 +101,11 @@ class ImageMetadata {
98101
// loops.
99102
Maybe<gfx::IntRect> mFirstFrameRefreshArea;
100103

101-
Maybe<nsIntSize> mSize;
104+
Maybe<OrientedIntSize> mSize;
102105
Maybe<Orientation> mOrientation;
103106

104107
// Sizes the image can natively decode to.
105-
CopyableTArray<nsIntSize> mNativeSizes;
108+
CopyableTArray<OrientedIntSize> mNativeSizes;
106109

107110
bool mHasAnimation = false;
108111
};

0 commit comments

Comments
 (0)