From 626d39ccdc948cfba37fbcc815816c4277681ef3 Mon Sep 17 00:00:00 2001 From: Seth Fowler Date: Mon, 24 Nov 2014 23:42:43 -0800 Subject: [PATCH] Bug 1102617 - Replace imgIContainer::FrameIsOpaque with imgIContainer::IsOpaque. r=tn --- image/public/imgIContainer.idl | 9 +++----- image/src/DynamicImage.cpp | 2 +- image/src/FrozenImage.cpp | 6 ----- image/src/FrozenImage.h | 1 - image/src/ImageWrapper.cpp | 4 ++-- image/src/OrientedImage.cpp | 2 +- image/src/ProgressTracker.h | 3 +++ image/src/RasterImage.cpp | 40 ++++++++++++--------------------- image/src/RasterImage.h | 2 +- image/src/VectorImage.cpp | 8 +------ image/src/imgFrame.cpp | 6 ----- image/src/imgFrame.h | 1 - layout/generic/nsImageFrame.cpp | 4 +--- layout/style/nsStyleStruct.cpp | 4 ++-- 14 files changed, 29 insertions(+), 63 deletions(-) diff --git a/image/public/imgIContainer.idl b/image/public/imgIContainer.idl index 4005ffaec766..d7905087316a 100644 --- a/image/public/imgIContainer.idl +++ b/image/public/imgIContainer.idl @@ -69,7 +69,7 @@ native nsIntSizeByVal(nsIntSize); * * Internally, imgIContainer also manages animation of images. */ -[scriptable, builtinclass, uuid(f8bb7671-5f36-490b-b828-3f4c6ad38665)] +[scriptable, builtinclass, uuid(14ea6fa5-183e-4409-ac88-110bd2e05292)] interface imgIContainer : nsISupports { /** @@ -215,12 +215,9 @@ interface imgIContainer : nsISupports in uint32_t aFlags); /** - * Whether the given frame is opaque; that is, needs the background painted - * behind it. - * - * @param aWhichFrame Frame specifier of the FRAME_* variety. + * Whether this image is opaque (i.e., needs a background painted behind it). */ - [notxpcom] boolean frameIsOpaque(in uint32_t aWhichFrame); + [notxpcom] boolean isOpaque(); /** * Attempts to create an ImageContainer (and Image) containing the current diff --git a/image/src/DynamicImage.cpp b/image/src/DynamicImage.cpp index c9fdf34e9700..3f2b63699cee 100644 --- a/image/src/DynamicImage.cpp +++ b/image/src/DynamicImage.cpp @@ -228,7 +228,7 @@ DynamicImage::GetFrame(uint32_t aWhichFrame, } NS_IMETHODIMP_(bool) -DynamicImage::FrameIsOpaque(uint32_t aWhichFrame) +DynamicImage::IsOpaque() { // XXX(seth): For performance reasons it'd be better to return true here, but // I'm not sure how we can guarantee it for an arbitrary gfxDrawable. diff --git a/image/src/FrozenImage.cpp b/image/src/FrozenImage.cpp index 923b58a5d0fd..8460c475726f 100644 --- a/image/src/FrozenImage.cpp +++ b/image/src/FrozenImage.cpp @@ -50,12 +50,6 @@ FrozenImage::GetFrame(uint32_t aWhichFrame, return InnerImage()->GetFrame(FRAME_FIRST, aFlags); } -NS_IMETHODIMP_(bool) -FrozenImage::FrameIsOpaque(uint32_t aWhichFrame) -{ - return InnerImage()->FrameIsOpaque(FRAME_FIRST); -} - NS_IMETHODIMP FrozenImage::GetImageContainer(layers::LayerManager* aManager, layers::ImageContainer** _retval) diff --git a/image/src/FrozenImage.h b/image/src/FrozenImage.h index c197f61c97a3..895036f4457d 100644 --- a/image/src/FrozenImage.h +++ b/image/src/FrozenImage.h @@ -38,7 +38,6 @@ public: NS_IMETHOD GetAnimated(bool* aAnimated) MOZ_OVERRIDE; NS_IMETHOD_(TemporaryRef) GetFrame(uint32_t aWhichFrame, uint32_t aFlags) MOZ_OVERRIDE; - NS_IMETHOD_(bool) FrameIsOpaque(uint32_t aWhichFrame) MOZ_OVERRIDE; NS_IMETHOD GetImageContainer(layers::LayerManager* aManager, layers::ImageContainer** _retval) MOZ_OVERRIDE; NS_IMETHOD Draw(gfxContext* aContext, diff --git a/image/src/ImageWrapper.cpp b/image/src/ImageWrapper.cpp index c43bf5de55b3..ed28788e12ad 100644 --- a/image/src/ImageWrapper.cpp +++ b/image/src/ImageWrapper.cpp @@ -209,9 +209,9 @@ ImageWrapper::GetFrame(uint32_t aWhichFrame, } NS_IMETHODIMP_(bool) -ImageWrapper::FrameIsOpaque(uint32_t aWhichFrame) +ImageWrapper::IsOpaque() { - return mInnerImage->FrameIsOpaque(aWhichFrame); + return mInnerImage->IsOpaque(); } NS_IMETHODIMP diff --git a/image/src/OrientedImage.cpp b/image/src/OrientedImage.cpp index b620e7faf73b..70ec7cb4546c 100644 --- a/image/src/OrientedImage.cpp +++ b/image/src/OrientedImage.cpp @@ -112,7 +112,7 @@ OrientedImage::GetFrame(uint32_t aWhichFrame, // Determine an appropriate format for the surface. gfx::SurfaceFormat surfaceFormat; - if (InnerImage()->FrameIsOpaque(aWhichFrame)) { + if (InnerImage()->IsOpaque()) { surfaceFormat = gfx::SurfaceFormat::B8G8R8X8; } else { surfaceFormat = gfx::SurfaceFormat::B8G8R8A8; diff --git a/image/src/ProgressTracker.h b/image/src/ProgressTracker.h index ecc3d2f6b280..8f22717c3f9a 100644 --- a/image/src/ProgressTracker.h +++ b/image/src/ProgressTracker.h @@ -101,6 +101,9 @@ public: // Get the current image status (as in imgIRequest). uint32_t GetImageStatus() const; + // Get the current Progress. + Progress GetProgress() const { return mProgress; } + // Schedule an asynchronous "replaying" of all the notifications that would // have to happen to put us in the current state. // We will also take note of any notifications that happen between the time diff --git a/image/src/RasterImage.cpp b/image/src/RasterImage.cpp index f1d20f82c4c0..72f894c0d95e 100644 --- a/image/src/RasterImage.cpp +++ b/image/src/RasterImage.cpp @@ -654,33 +654,22 @@ RasterImage::GetFirstFrameRect() return nsIntRect(nsIntPoint(0,0), mSize); } -//****************************************************************************** -/* [notxpcom] boolean frameIsOpaque(in uint32_t aWhichFrame); */ NS_IMETHODIMP_(bool) -RasterImage::FrameIsOpaque(uint32_t aWhichFrame) +RasterImage::IsOpaque() { - if (aWhichFrame > FRAME_MAX_VALUE) { - NS_WARNING("aWhichFrame outside valid range!"); + if (mError) { return false; } - if (mError) + Progress progress = mProgressTracker->GetProgress(); + + // If we haven't yet finished decoding, the safe answer is "not opaque". + if (!(progress & FLAG_DECODE_COMPLETE)) { return false; + } - // See if we can get an image frame. - nsRefPtr frame = - LookupFrameNoDecode(GetRequestedFrameIndex(aWhichFrame)); - - // If we don't get a frame, the safe answer is "not opaque". - if (!frame) - return false; - - // Other, the frame is transparent if either: - // 1. It needs a background. - // 2. Its size doesn't cover our entire area. - nsIntRect framerect = frame->GetRect(); - return !frame->GetNeedsBackground() && - framerect.IsEqualInterior(nsIntRect(0, 0, mSize.width, mSize.height)); + // Other, we're opaque if FLAG_HAS_TRANSPARENCY is not set. + return !(progress & FLAG_HAS_TRANSPARENCY); } nsIntRect @@ -767,7 +756,7 @@ RasterImage::CopyFrame(uint32_t aWhichFrame, if (mError) return nullptr; - if (!ApplyDecodeFlags(aFlags, aWhichFrame)) + if (!ApplyDecodeFlags(aFlags)) return nullptr; // Get the frame. If it's not there, it's probably the caller's fault for @@ -844,7 +833,7 @@ RasterImage::GetFrameInternal(uint32_t aWhichFrame, if (mError) return nullptr; - if (!ApplyDecodeFlags(aFlags, aWhichFrame)) + if (!ApplyDecodeFlags(aFlags)) return nullptr; // Get the frame. If it's not there, it's probably the caller's fault for @@ -1120,7 +1109,7 @@ RasterImage::InternalAddFrame(uint32_t framenum, } bool -RasterImage::ApplyDecodeFlags(uint32_t aNewFlags, uint32_t aWhichFrame) +RasterImage::ApplyDecodeFlags(uint32_t aNewFlags) { if (mFrameDecodeFlags == (aNewFlags & DECODE_FLAGS_MASK)) return true; // Not asking very much of us here. @@ -1133,7 +1122,7 @@ RasterImage::ApplyDecodeFlags(uint32_t aNewFlags, uint32_t aWhichFrame) (mFrameDecodeFlags & DECODE_FLAGS_MASK) & ~FLAG_DECODE_NO_PREMULTIPLY_ALPHA; uint32_t newNonAlphaFlags = (aNewFlags & DECODE_FLAGS_MASK) & ~FLAG_DECODE_NO_PREMULTIPLY_ALPHA; - if (currentNonAlphaFlags == newNonAlphaFlags && FrameIsOpaque(aWhichFrame)) { + if (currentNonAlphaFlags == newNonAlphaFlags && IsOpaque()) { return true; } @@ -2537,8 +2526,7 @@ RasterImage::Draw(gfxContext* aContext, // is opaque. bool haveDefaultFlags = (mFrameDecodeFlags == DECODE_FLAGS_DEFAULT); bool haveSafeAlphaFlags = - (mFrameDecodeFlags == FLAG_DECODE_NO_PREMULTIPLY_ALPHA) && - FrameIsOpaque(FRAME_CURRENT); + (mFrameDecodeFlags == FLAG_DECODE_NO_PREMULTIPLY_ALPHA) && IsOpaque(); if (!(haveDefaultFlags || haveSafeAlphaFlags)) { if (!CanForciblyDiscardAndRedecode()) diff --git a/image/src/RasterImage.h b/image/src/RasterImage.h index 89239ab16e9a..5d4e974032dd 100644 --- a/image/src/RasterImage.h +++ b/image/src/RasterImage.h @@ -338,7 +338,7 @@ private: nsresult DoImageDataComplete(); - bool ApplyDecodeFlags(uint32_t aNewFlags, uint32_t aWhichFrame); + bool ApplyDecodeFlags(uint32_t aNewFlags); already_AddRefed GetCurrentImage(); void UpdateImageContainer(); diff --git a/image/src/VectorImage.cpp b/image/src/VectorImage.cpp index 2465eb2d1610..42fb26a7e057 100644 --- a/image/src/VectorImage.cpp +++ b/image/src/VectorImage.cpp @@ -687,15 +687,9 @@ VectorImage::GetFirstFrameDelay() return 0; } - -//****************************************************************************** -/* [notxpcom] boolean frameIsOpaque(in uint32_t aWhichFrame); */ NS_IMETHODIMP_(bool) -VectorImage::FrameIsOpaque(uint32_t aWhichFrame) +VectorImage::IsOpaque() { - if (aWhichFrame > FRAME_MAX_VALUE) - NS_WARNING("aWhichFrame outside valid range!"); - return false; // In general, SVG content is not opaque. } diff --git a/image/src/imgFrame.cpp b/image/src/imgFrame.cpp index 3f70652f45fa..dd9d461fe323 100644 --- a/image/src/imgFrame.cpp +++ b/image/src/imgFrame.cpp @@ -584,12 +584,6 @@ SurfaceFormat imgFrame::GetFormat() const return mFormat; } -bool imgFrame::GetNeedsBackground() const -{ - // We need a background painted if we have alpha or we're incomplete. - return (mFormat == SurfaceFormat::B8G8R8A8 || !ImageComplete()); -} - uint32_t imgFrame::GetImageBytesPerRow() const { if (mVBuf) diff --git a/image/src/imgFrame.h b/image/src/imgFrame.h index b43df76bfc33..55052e880973 100644 --- a/image/src/imgFrame.h +++ b/image/src/imgFrame.h @@ -88,7 +88,6 @@ public: bool NeedsPadding() const { return mOffset != nsIntPoint(0, 0); } int32_t GetStride() const; SurfaceFormat GetFormat() const; - bool GetNeedsBackground() const; uint32_t GetImageBytesPerRow() const; uint32_t GetImageDataLength() const; bool GetIsPaletted() const; diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 1690a5a0ab11..47794ba938f7 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -1453,9 +1453,7 @@ nsDisplayImage::GetOpaqueRegion(nsDisplayListBuilder* aBuilder, bool* aSnap) { *aSnap = true; - bool animated; - if (mImage && mImage->GetAnimated(&animated) == NS_OK && !animated && - mImage->FrameIsOpaque(imgIContainer::FRAME_CURRENT)) { + if (mImage && mImage->IsOpaque()) { // OK, the entire region painted by the image is opaque. But what is that // region? It's the image's "dest rect" (the rect where a full copy of // the image is mapped), clipped to the container's content box (which is diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index 06add505587c..5956c174c239 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -2054,8 +2054,8 @@ nsStyleImage::IsOpaque() const mImage->GetImage(getter_AddRefs(imageContainer)); NS_ABORT_IF_FALSE(imageContainer, "IsComplete() said image container is ready"); - // Check if the crop region of the current image frame is opaque. - if (imageContainer->FrameIsOpaque(imgIContainer::FRAME_CURRENT)) { + // Check if the crop region of the image is opaque. + if (imageContainer->IsOpaque()) { if (!mCropRect) return true;