From 0d4956809074c02a512e876be6457f43ba7549f3 Mon Sep 17 00:00:00 2001 From: Seth Fowler Date: Mon, 11 Jul 2016 23:19:58 -0700 Subject: [PATCH] Bug 1285867 (Part 3e) - Use TerminalState to exit the Decode() loop. r=edwin --- image/Decoder.cpp | 11 ++++++----- image/decoders/nsBMPDecoder.cpp | 19 +++++++++++++------ image/decoders/nsBMPDecoder.h | 7 ------- image/decoders/nsICODecoder.cpp | 9 --------- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/image/Decoder.cpp b/image/Decoder.cpp index 70458a2f95c4..08b85fe9665a 100644 --- a/image/Decoder.cpp +++ b/image/Decoder.cpp @@ -164,10 +164,6 @@ Decoder::Decode(NotNull aOnResume) // Pass the data along to the implementation. terminalState = DoDecode(*mIterator); - if (terminalState == Some(TerminalState::FAILURE)) { - PostDataError(); - } - break; } @@ -175,7 +171,12 @@ Decoder::Decode(NotNull aOnResume) MOZ_ASSERT_UNREACHABLE("Unknown SourceBufferIterator state"); terminalState = Some(TerminalState::FAILURE); } - } while (!GetDecodeDone() && !HasError()); + } while (!GetDecodeDone() && !terminalState); + + // If decoding failed, record that fact. + if (terminalState == Some(TerminalState::FAILURE)) { + PostDataError(); + } CompleteDecode(); return HasError() ? NS_ERROR_FAILURE : NS_OK; diff --git a/image/decoders/nsBMPDecoder.cpp b/image/decoders/nsBMPDecoder.cpp index 0cd9de13f83c..6faaffeb2b9c 100644 --- a/image/decoders/nsBMPDecoder.cpp +++ b/image/decoders/nsBMPDecoder.cpp @@ -262,12 +262,19 @@ nsBMPDecoder::FinishInternal() nsIntRect r(0, 0, mH.mWidth, AbsoluteHeight()); PostInvalidation(r); - if (mDoesHaveTransparency) { - MOZ_ASSERT(mMayHaveTransparency); - PostFrameStop(Opacity::SOME_TRANSPARENCY); - } else { - PostFrameStop(Opacity::FULLY_OPAQUE); - } + MOZ_ASSERT_IF(mDoesHaveTransparency, mMayHaveTransparency); + + // We have transparency if we either detected some in the image itself + // (i.e., |mDoesHaveTransparency| is true) or we're in an ICO, which could + // mean we have an AND mask that provides transparency (i.e., |mIsWithinICO| + // is true). + // XXX(seth): We can tell when we create the decoder if the AND mask is + // present, so we could be more precise about this. + const Opacity opacity = mDoesHaveTransparency || mIsWithinICO + ? Opacity::SOME_TRANSPARENCY + : Opacity::FULLY_OPAQUE; + + PostFrameStop(opacity); PostDecodeDone(); } diff --git a/image/decoders/nsBMPDecoder.h b/image/decoders/nsBMPDecoder.h index 1f7285570c54..a01251d29e7b 100644 --- a/image/decoders/nsBMPDecoder.h +++ b/image/decoders/nsBMPDecoder.h @@ -142,13 +142,6 @@ public: /// bitmap has been fully decoded.) bool HasTransparency() const { return mDoesHaveTransparency; } - /// Force transparency from outside. (Used by the ICO decoder.) - void SetHasTransparency() - { - mMayHaveTransparency = true; - mDoesHaveTransparency = true; - } - Maybe DoDecode(SourceBufferIterator& aIterator) override; nsresult BeforeFinishInternal() override; nsresult FinishInternal() override; diff --git a/image/decoders/nsICODecoder.cpp b/image/decoders/nsICODecoder.cpp index 67a3d60995c8..904ddca760b0 100644 --- a/image/decoders/nsICODecoder.cpp +++ b/image/decoders/nsICODecoder.cpp @@ -573,15 +573,6 @@ nsICODecoder::FinishMask() } } - // If the mask contained any transparent pixels, record that fact. - if (mHasMaskAlpha) { - PostHasTransparency(); - - RefPtr bmpDecoder = - static_cast(mContainedDecoder.get()); - bmpDecoder->SetHasTransparency(); - } - return Transition::To(ICOState::FINISHED_RESOURCE, 0); }