Skip to content

Commit

Permalink
Make resuming of decoding work for anonymous decoders.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfbeast committed Jan 21, 2019
1 parent d1a0bfe commit 64d65e0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
15 changes: 14 additions & 1 deletion image/IDecodingTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ MetadataDecodingTask::Run()
// AnonymousDecodingTask implementation.
///////////////////////////////////////////////////////////////////////////////

AnonymousDecodingTask::AnonymousDecodingTask(NotNull<Decoder*> aDecoder)
AnonymousDecodingTask::AnonymousDecodingTask(NotNull<Decoder*> aDecoder,
bool aResumable)
: mDecoder(aDecoder)
, mResumable(aResumable)
{ }

void
Expand All @@ -168,5 +170,16 @@ AnonymousDecodingTask::Run()
}
}

void
AnonymousDecodingTask::Resume()
{
// Anonymous decoders normally get all their data at once. We have some situations
// where they don't. If explicitly requested, resuming should be supported.
if (mResumable) {
RefPtr<AnonymousDecodingTask> self(this);
NS_DispatchToMainThread(NS_NewRunnableFunction([self]() -> void { self->Run(); }));
}
}

} // namespace image
} // namespace mozilla
8 changes: 3 additions & 5 deletions image/IDecodingTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,20 @@ class AnonymousDecodingTask final : public IDecodingTask
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AnonymousDecodingTask, override)

explicit AnonymousDecodingTask(NotNull<Decoder*> aDecoder);
explicit AnonymousDecodingTask(NotNull<Decoder*> aDecoder, bool aResumable);

void Run() override;

bool ShouldPreferSyncRun() const override { return true; }
TaskPriority Priority() const override { return TaskPriority::eLow; }

// Anonymous decoders normally get all their data at once. We have tests where
// they don't; in these situations, the test re-runs them manually. So no
// matter what, we don't want to resume by posting a task to the DecodePool.
void Resume() override { }
void Resume() override;

private:
virtual ~AnonymousDecodingTask() { }

NotNull<RefPtr<Decoder>> mDecoder;
bool mResumable;
};

} // namespace image
Expand Down
2 changes: 1 addition & 1 deletion image/ImageOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ ImageOps::DecodeToSurface(nsIInputStream* aInputStream,
}

// Run the decoder synchronously.
RefPtr<IDecodingTask> task = new AnonymousDecodingTask(WrapNotNull(decoder));
RefPtr<IDecodingTask> task = new AnonymousDecodingTask(WrapNotNull(decoder), /* aResumable */ false);
task->Run();
if (!decoder->GetDecodeDone() || decoder->HasError()) {
return nullptr;
Expand Down

0 comments on commit 64d65e0

Please sign in to comment.