Open Bug 1298145 Opened 8 years ago Updated 2 years ago

Simplify image decoder initialization

Categories

(Core :: Graphics: ImageLib, defect)

defect

Tracking

()

People

(Reporter: seth, Unassigned)

References

(Depends on 1 open bug)

Details

Attachments

(3 files)

Right now image decoders have this weird initialization model where we construct a Decoder object, call a bunch of setters (some of which are non-optional or effectively non-optional), and then call Init(). If we accidentally forget to call some of the setters, it breaks stuff. If we accidentally call one of these setters after calling Init(), it breaks stuff. This whole situation is actually one of the reasons DecoderFactory was originally created: initializing decoders is very fragile.

We've now de-crufted Decoder enough to where we can clean this stuff up, and I think it makes sense to do so, as it constitutes a major de-crufting in its own right.
OK, step one is to pass a SourceBufferIterator to Decoder's constructor, because
we always have to have one, and since they're move-only, stack-based objects,
passing them to a setter or to Init() requires that we store them in a Maybe,
which in turn results in a bunch of assertions that we really shouldn't need.
Attachment #8784972 - Flags: review?(edwin)
This patch consolidates every setters except for SetSampleSize(), which I'm
inclined to keep separate since it's slated for removal soon and it's specific
to the JPEG decoder. The things that we used to pass to the setters are now all
passed to Init(). There's also a variant, InitForMetadataDecode(), which accepts
only the parameters that a metadata decoder needs.
Attachment #8784975 - Flags: review?(edwin)
The JPEG decoder is all sorts of special. Beyond SetSampleSize(), it also
accepts a DecodeStyle argument to its constructor which tells it whether to do a
progressive decode or not. Other decodes make similar decisions based upon
whether DecoderFlags::IS_REDECODE is set, and indeed that's what DecoderFactory
checks when deciding which DecodeStyle to pass to nsJPEGDecoder's constructor.
Since all decoders have access to their DecoderFlags already, let's just check
this value directly in nsJPEGDecoder and get rid of DecodeStyle totally.
Attachment #8784980 - Flags: review?(edwin)
Comment on attachment 8784972 [details] [diff] [review]
(Part 1) - Accept a SourceBufferIterator in Decoder's constructor.

Review of attachment 8784972 [details] [diff] [review]:
-----------------------------------------------------------------

::: image/Decoder.cpp
@@ +98,5 @@
>    {
>      PROFILER_LABEL("ImageDecoder", "Decode", js::ProfileEntry::Category::GRAPHICS);
>      AutoRecordDecoderTelemetry telemetry(this);
>  
> +    lexerResult =  DoDecode(mIterator, aOnResume);

nit: remove extra space after '='

(which was already there, but it's worth fixing while we're here)
Attachment #8784972 - Flags: review?(edwin) → review+

The bug assignee didn't login in Bugzilla in the last 7 months, so the assignee is being reset.

Assignee: seth.bugzilla → nobody
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: