Bug 944442 - DeCOMify imgIContainer::GetFrame. r=seth

--HG--
extra : rebase_source : 612c1923f3ed8a01fc30f2d306b4682e585e53fe
This commit is contained in:
Jonathan Watt 2013-12-13 08:34:24 +00:00
parent de607d515b
commit 6c8fbf340c
23 changed files with 100 additions and 135 deletions

View File

@ -752,10 +752,9 @@ WriteBitmap(nsIFile* aFile, imgIContainer* aImage)
{
nsresult rv;
nsRefPtr<gfxASurface> surface;
aImage->GetFrame(imgIContainer::FRAME_FIRST,
imgIContainer::FLAG_SYNC_DECODE,
getter_AddRefs(surface));
nsRefPtr<gfxASurface> surface =
aImage->GetFrame(imgIContainer::FRAME_FIRST,
imgIContainer::FLAG_SYNC_DECODE);
NS_ENSURE_TRUE(surface, NS_ERROR_FAILURE);
nsRefPtr<gfxImageSurface> image(surface->GetAsReadableARGB32ImageSurface());

View File

@ -211,9 +211,9 @@ SVGFEImageElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance,
nsRefPtr<gfxASurface> currentFrame;
if (imageContainer) {
imageContainer->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE,
getter_AddRefs(currentFrame));
currentFrame =
imageContainer->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE);
}
if (!currentFrame) {

View File

@ -55,6 +55,7 @@ native nsSize(nsSize);
native Orientation(mozilla::image::Orientation);
[ref] native TimeStamp(mozilla::TimeStamp);
[ptr] native SVGImageContext(mozilla::SVGImageContext);
native already_AddRefed_gfxASurface(already_AddRefed<gfxASurface>);
/**
@ -64,7 +65,7 @@ native Orientation(mozilla::image::Orientation);
*
* Internally, imgIContainer also manages animation of images.
*/
[scriptable, builtinclass, uuid(73340b79-e3ae-4f02-97d0-822db78017e5)]
[scriptable, builtinclass, uuid(8b7db7dd-bfe9-40d3-9114-3a79c0658afd)]
interface imgIContainer : nsISupports
{
/**
@ -172,7 +173,8 @@ interface imgIContainer : nsISupports
* @param aWhichFrame Frame specifier of the FRAME_* variety.
* @param aFlags Flags of the FLAG_* variety
*/
[noscript] gfxASurface getFrame(in uint32_t aWhichFrame,
[noscript, notxpcom] already_AddRefed_gfxASurface
getFrame(in uint32_t aWhichFrame,
in uint32_t aFlags);
/**

View File

@ -209,23 +209,21 @@ ClippedImage::GetIntrinsicRatio(nsSize* aRatio)
return NS_OK;
}
NS_IMETHODIMP
NS_IMETHODIMP_(already_AddRefed<gfxASurface>)
ClippedImage::GetFrame(uint32_t aWhichFrame,
uint32_t aFlags,
gfxASurface** _retval)
uint32_t aFlags)
{
return GetFrameInternal(mClip.Size(), nullptr, aWhichFrame, aFlags, _retval);
return GetFrameInternal(mClip.Size(), nullptr, aWhichFrame, aFlags);
}
nsresult
already_AddRefed<gfxASurface>
ClippedImage::GetFrameInternal(const nsIntSize& aViewportSize,
const SVGImageContext* aSVGContext,
uint32_t aWhichFrame,
uint32_t aFlags,
gfxASurface** _retval)
uint32_t aFlags)
{
if (!ShouldClip()) {
return InnerImage()->GetFrame(aWhichFrame, aFlags, _retval);
return InnerImage()->GetFrame(aWhichFrame, aFlags);
}
float frameToDraw = InnerImage()->GetFrameIndex(aWhichFrame);
@ -273,9 +271,7 @@ ClippedImage::GetFrameInternal(const nsIntSize& aViewportSize,
}
MOZ_ASSERT(mCachedSurface, "Should have a cached surface now");
nsRefPtr<gfxASurface> surf = mCachedSurface->Surface();
surf.forget(_retval);
return NS_OK;
return mCachedSurface->Surface();
}
NS_IMETHODIMP
@ -335,8 +331,8 @@ ClippedImage::Draw(gfxContext* aContext,
if (MustCreateSurface(aContext, aUserSpaceToImageSpace, sourceRect, aSubimage, aFlags)) {
// Create a temporary surface containing a single tile of this image.
// GetFrame will call DrawSingleTile internally.
nsRefPtr<gfxASurface> surface;
GetFrameInternal(aViewportSize, aSVGContext, aWhichFrame, aFlags, getter_AddRefs(surface));
nsRefPtr<gfxASurface> surface =
GetFrameInternal(aViewportSize, aSVGContext, aWhichFrame, aFlags);
NS_ENSURE_TRUE(surface, NS_ERROR_FAILURE);
// Create a drawable from that surface.

View File

@ -35,9 +35,8 @@ public:
NS_IMETHOD GetHeight(int32_t* aHeight) MOZ_OVERRIDE;
NS_IMETHOD GetIntrinsicSize(nsSize* aSize) MOZ_OVERRIDE;
NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) MOZ_OVERRIDE;
NS_IMETHOD GetFrame(uint32_t aWhichFrame,
uint32_t aFlags,
gfxASurface** _retval) MOZ_OVERRIDE;
NS_IMETHOD_(already_AddRefed<gfxASurface>) GetFrame(uint32_t aWhichFrame,
uint32_t aFlags) MOZ_OVERRIDE;
NS_IMETHOD GetImageContainer(mozilla::layers::LayerManager* aManager,
mozilla::layers::ImageContainer** _retval) MOZ_OVERRIDE;
NS_IMETHOD Draw(gfxContext* aContext,
@ -56,11 +55,10 @@ protected:
ClippedImage(Image* aImage, nsIntRect aClip);
private:
nsresult GetFrameInternal(const nsIntSize& aViewportSize,
const SVGImageContext* aSVGContext,
uint32_t aWhichFrame,
uint32_t aFlags,
gfxASurface** _retval);
already_AddRefed<gfxASurface> GetFrameInternal(const nsIntSize& aViewportSize,
const SVGImageContext* aSVGContext,
uint32_t aWhichFrame,
uint32_t aFlags);
bool ShouldClip();
bool MustCreateSurface(gfxContext* aContext,
const gfxMatrix& aTransform,

View File

@ -40,12 +40,11 @@ FrozenImage::GetAnimated(bool* aAnimated)
return rv;
}
NS_IMETHODIMP
NS_IMETHODIMP_(already_AddRefed<gfxASurface>)
FrozenImage::GetFrame(uint32_t aWhichFrame,
uint32_t aFlags,
gfxASurface** _retval)
uint32_t aFlags)
{
return InnerImage()->GetFrame(FRAME_FIRST, aFlags, _retval);
return InnerImage()->GetFrame(FRAME_FIRST, aFlags);
}
NS_IMETHODIMP_(bool)

View File

@ -34,9 +34,8 @@ public:
virtual void DecrementAnimationConsumers() MOZ_OVERRIDE;
NS_IMETHOD GetAnimated(bool* aAnimated) MOZ_OVERRIDE;
NS_IMETHOD GetFrame(uint32_t aWhichFrame,
uint32_t aFlags,
gfxASurface** _retval) MOZ_OVERRIDE;
NS_IMETHOD_(already_AddRefed<gfxASurface>) 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;

View File

@ -196,12 +196,11 @@ ImageWrapper::GetAnimated(bool* aAnimated)
return mInnerImage->GetAnimated(aAnimated);
}
NS_IMETHODIMP
NS_IMETHODIMP_(already_AddRefed<gfxASurface>)
ImageWrapper::GetFrame(uint32_t aWhichFrame,
uint32_t aFlags,
gfxASurface** _retval)
uint32_t aFlags)
{
return mInnerImage->GetFrame(aWhichFrame, aFlags, _retval);
return mInnerImage->GetFrame(aWhichFrame, aFlags);
}
NS_IMETHODIMP_(bool)

View File

@ -75,15 +75,14 @@ OrientedImage::GetIntrinsicRatio(nsSize* aRatio)
return rv;
}
NS_IMETHODIMP
NS_IMETHODIMP_(already_AddRefed<gfxASurface>)
OrientedImage::GetFrame(uint32_t aWhichFrame,
uint32_t aFlags,
gfxASurface** _retval)
uint32_t aFlags)
{
nsresult rv;
if (mOrientation.IsIdentity()) {
return InnerImage()->GetFrame(aWhichFrame, aFlags, _retval);
return InnerImage()->GetFrame(aWhichFrame, aFlags);
}
// Get the underlying dimensions.
@ -95,7 +94,7 @@ OrientedImage::GetFrame(uint32_t aWhichFrame,
rv = InnerImage()->GetWidth(&width);
rv = NS_FAILED(rv) ? rv : InnerImage()->GetHeight(&height);
}
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_SUCCESS(rv, nullptr);
// Determine an appropriate format for the surface.
gfx::SurfaceFormat surfaceFormat;
@ -116,9 +115,9 @@ OrientedImage::GetFrame(uint32_t aWhichFrame,
GetThebesSurfaceForDrawTarget(target);
// Create our drawable.
nsRefPtr<gfxASurface> innerSurface;
rv = InnerImage()->GetFrame(aWhichFrame, aFlags, getter_AddRefs(innerSurface));
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<gfxASurface> innerSurface =
InnerImage()->GetFrame(aWhichFrame, aFlags);
NS_ENSURE_TRUE(innerSurface, nullptr);
nsRefPtr<gfxDrawable> drawable =
new gfxSurfaceDrawable(innerSurface, gfxIntSize(width, height));
@ -129,8 +128,7 @@ OrientedImage::GetFrame(uint32_t aWhichFrame,
imageRect, imageRect, imageRect, imageRect,
imageFormat, GraphicsFilter::FILTER_FAST);
surface.forget(_retval);
return NS_OK;
return surface.forget();
}
NS_IMETHODIMP

View File

@ -32,9 +32,8 @@ public:
NS_IMETHOD GetHeight(int32_t* aHeight) MOZ_OVERRIDE;
NS_IMETHOD GetIntrinsicSize(nsSize* aSize) MOZ_OVERRIDE;
NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) MOZ_OVERRIDE;
NS_IMETHOD GetFrame(uint32_t aWhichFrame,
uint32_t aFlags,
gfxASurface** _retval) MOZ_OVERRIDE;
NS_IMETHOD_(already_AddRefed<gfxASurface>) GetFrame(uint32_t aWhichFrame,
uint32_t aFlags) MOZ_OVERRIDE;
NS_IMETHOD GetImageContainer(mozilla::layers::LayerManager* aManager,
mozilla::layers::ImageContainer** _retval) MOZ_OVERRIDE;
NS_IMETHOD Draw(gfxContext* aContext,

View File

@ -879,30 +879,29 @@ RasterImage::CopyFrame(uint32_t aWhichFrame,
//******************************************************************************
/* [noscript] gfxASurface getFrame(in uint32_t aWhichFrame,
* in uint32_t aFlags); */
NS_IMETHODIMP
NS_IMETHODIMP_(already_AddRefed<gfxASurface>)
RasterImage::GetFrame(uint32_t aWhichFrame,
uint32_t aFlags,
gfxASurface **_retval)
uint32_t aFlags)
{
MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE);
if (aWhichFrame > FRAME_MAX_VALUE)
return NS_ERROR_INVALID_ARG;
return nullptr;
if (mError)
return NS_ERROR_FAILURE;
return nullptr;
// Disallowed in the API
if (mInDecoder && (aFlags & imgIContainer::FLAG_SYNC_DECODE))
return NS_ERROR_FAILURE;
nsresult rv = NS_OK;
return nullptr;
if (!ApplyDecodeFlags(aFlags))
return NS_ERROR_NOT_AVAILABLE;
return nullptr;
// If the caller requested a synchronous decode, do it
if (aFlags & FLAG_SYNC_DECODE) {
rv = SyncDecode();
CONTAINER_ENSURE_SUCCESS(rv);
nsresult rv = SyncDecode();
CONTAINER_ENSURE_TRUE(NS_SUCCEEDED(rv), nullptr);
}
// Get the frame. If it's not there, it's probably the caller's fault for
@ -912,8 +911,7 @@ RasterImage::GetFrame(uint32_t aWhichFrame,
0 : GetCurrentImgFrameIndex();
imgFrame *frame = GetDrawableImgFrame(frameIndex);
if (!frame) {
*_retval = nullptr;
return NS_ERROR_FAILURE;
return nullptr;
}
nsRefPtr<gfxASurface> framesurf;
@ -924,19 +922,17 @@ RasterImage::GetFrame(uint32_t aWhichFrame,
if (framerect.x == 0 && framerect.y == 0 &&
framerect.width == mSize.width &&
framerect.height == mSize.height)
rv = frame->GetSurface(getter_AddRefs(framesurf));
frame->GetSurface(getter_AddRefs(framesurf));
// The image doesn't have a surface because it's been optimized away. Create
// one.
if (!framesurf) {
nsRefPtr<gfxImageSurface> imgsurf;
rv = CopyFrame(aWhichFrame, aFlags, getter_AddRefs(imgsurf));
CopyFrame(aWhichFrame, aFlags, getter_AddRefs(imgsurf));
framesurf = imgsurf;
}
*_retval = framesurf.forget().get();
return rv;
return framesurf.forget();
}
already_AddRefed<layers::Image>
@ -949,13 +945,8 @@ RasterImage::GetCurrentImage()
return nullptr;
}
nsRefPtr<gfxASurface> imageSurface;
nsresult rv = GetFrame(FRAME_CURRENT, FLAG_NONE, getter_AddRefs(imageSurface));
NS_ENSURE_SUCCESS(rv, nullptr);
if (!imageSurface) {
return nullptr;
}
nsRefPtr<gfxASurface> imageSurface = GetFrame(FRAME_CURRENT, FLAG_NONE);
NS_ENSURE_TRUE(imageSurface, nullptr);
if (!mImageContainer) {
mImageContainer = LayerManager::CreateImageContainer();

View File

@ -647,18 +647,17 @@ VectorImage::FrameIsOpaque(uint32_t aWhichFrame)
//******************************************************************************
/* [noscript] gfxASurface getFrame(in uint32_t aWhichFrame,
* in uint32_t aFlags; */
NS_IMETHODIMP
NS_IMETHODIMP_(already_AddRefed<gfxASurface>)
VectorImage::GetFrame(uint32_t aWhichFrame,
uint32_t aFlags,
gfxASurface** _retval)
uint32_t aFlags)
{
NS_ENSURE_ARG_POINTER(_retval);
MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE);
if (aWhichFrame > FRAME_MAX_VALUE)
return NS_ERROR_INVALID_ARG;
return nullptr;
if (mError)
return NS_ERROR_FAILURE;
return nullptr;
// Look up height & width
// ----------------------
@ -668,7 +667,7 @@ VectorImage::GetFrame(uint32_t aWhichFrame,
!mSVGDocumentWrapper->GetWidthOrHeight(SVGDocumentWrapper::eHeight,
imageIntSize.height)) {
// We'll get here if our SVG doc has a percent-valued width or height.
return NS_ERROR_FAILURE;
return nullptr;
}
// Create a surface that we'll ultimately return
@ -689,9 +688,8 @@ VectorImage::GetFrame(uint32_t aWhichFrame,
nsIntRect(nsIntPoint(0,0), imageIntSize),
imageIntSize, nullptr, aWhichFrame, aFlags);
NS_ENSURE_SUCCESS(rv, rv);
*_retval = surface.forget().get();
return rv;
NS_ENSURE_SUCCESS(rv, nullptr);
return surface.forget();
}
//******************************************************************************

View File

@ -276,10 +276,9 @@ NS_IMETHODIMP imgTools::EncodeImageData(gfxImageSurface *aSurface,
NS_IMETHODIMP imgTools::GetFirstImageFrame(imgIContainer *aContainer,
gfxImageSurface **aSurface)
{
nsRefPtr<gfxASurface> surface;
aContainer->GetFrame(imgIContainer::FRAME_FIRST,
imgIContainer::FLAG_SYNC_DECODE,
getter_AddRefs(surface));
nsRefPtr<gfxASurface> surface =
aContainer->GetFrame(imgIContainer::FRAME_FIRST,
imgIContainer::FLAG_SYNC_DECODE);
NS_ENSURE_TRUE(surface, NS_ERROR_NOT_AVAILABLE);
nsRefPtr<gfxImageSurface> frame(surface->CopyToARGB32ImageSurface());

View File

@ -4816,11 +4816,9 @@ nsLayoutUtils::SurfaceFromElement(nsIImageLoadingContent* aElement,
frameFlags |= imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION;
if (aSurfaceFlags & SFE_NO_PREMULTIPLY_ALPHA)
frameFlags |= imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA;
nsRefPtr<gfxASurface> framesurf;
rv = imgContainer->GetFrame(whichFrame,
frameFlags,
getter_AddRefs(framesurf));
if (NS_FAILED(rv))
nsRefPtr<gfxASurface> framesurf =
imgContainer->GetFrame(whichFrame, frameFlags);
if (!framesurf)
return result;
int32_t imgWidth, imgHeight;

View File

@ -431,10 +431,9 @@ nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTransferable)
continue;
}
nsRefPtr<gfxASurface> surface;
image->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE,
getter_AddRefs(surface));
nsRefPtr<gfxASurface> surface =
image->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE);
if (!surface) {
continue;
}

View File

@ -372,10 +372,8 @@ nsresult nsCocoaUtils::CreateNSImageFromImageContainer(imgIContainer *aImage, ui
}
else {
nsRefPtr<gfxASurface> surface;
aImage->GetFrame(aWhichFrame,
imgIContainer::FLAG_SYNC_DECODE,
getter_AddRefs(surface));
nsRefPtr<gfxASurface> surface =
aImage->GetFrame(aWhichFrame, imgIContainer::FLAG_SYNC_DECODE);
NS_ENSURE_TRUE(surface, NS_ERROR_FAILURE);
frame = surface->GetAsReadableARGB32ImageSurface();

View File

@ -384,10 +384,9 @@ nsMenuItemIconX::OnStopFrame(imgIRequest* aRequest)
mImageRegionRect.SetRect(0, 0, origWidth, origHeight);
}
nsRefPtr<gfxASurface> surface;
imageContainer->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_NONE,
getter_AddRefs(surface));
nsRefPtr<gfxASurface> surface =
imageContainer->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_NONE);
if (!surface) {
[mNativeMenuItem setImage:nil];
return NS_ERROR_FAILURE;

View File

@ -36,19 +36,17 @@ nsImageToPixbuf::ConvertImageToPixbuf(imgIContainer* aImage)
GdkPixbuf*
nsImageToPixbuf::ImageToPixbuf(imgIContainer* aImage)
{
nsRefPtr<gfxASurface> surface;
aImage->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE,
getter_AddRefs(surface));
nsRefPtr<gfxASurface> surface =
aImage->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE);
// If the last call failed, it was probably because our call stack originates
// in an imgINotificationObserver event, meaning that we're not allowed request
// a sync decode. Presumably the originating event is something sensible like
// OnStopFrame(), so we can just retry the call without a sync decode.
if (!surface)
aImage->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_NONE,
getter_AddRefs(surface));
surface = aImage->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_NONE);
NS_ENSURE_TRUE(surface, nullptr);

View File

@ -1334,10 +1334,9 @@ NS_IMETHODIMP nsWindow::SetCursor(imgIContainer* aCursor,
return NS_OK;
}
nsRefPtr<gfxASurface> surface;
aCursor->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE,
getter_AddRefs(surface));
nsRefPtr<gfxASurface> surface =
aCursor->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE);
NS_ENSURE_TRUE(surface, NS_ERROR_NOT_AVAILABLE);
nsRefPtr<gfxImageSurface> frame(surface->GetAsReadableARGB32ImageSurface());

View File

@ -176,10 +176,9 @@ nsClipboard::SetNativeClipboardData( nsITransferable *aTransferable,
if (!image) // Not getting an image for an image mime type!?
continue;
nsRefPtr<gfxASurface> surface;
image->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE,
getter_AddRefs(surface));
nsRefPtr<gfxASurface> surface =
image->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE);
if (!surface)
continue;

View File

@ -694,8 +694,8 @@ AsyncFaviconDataReady::OnComplete(nsIURI *aFaviconURI,
getter_AddRefs(container));
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<gfxASurface> imgFrame;
rv = container->GetFrame(imgIContainer::FRAME_FIRST, 0, getter_AddRefs(imgFrame));
nsRefPtr<gfxASurface> imgFrame =
container->GetFrame(imgIContainer::FRAME_FIRST, 0);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<gfxImageSurface> imageSurface;

View File

@ -116,10 +116,9 @@ nsImageToClipboard::CreateFromImage ( imgIContainer* inImage, HANDLE* outBitmap
nsresult rv;
*outBitmap = nullptr;
nsRefPtr<gfxASurface> surface;
inImage->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE,
getter_AddRefs(surface));
nsRefPtr<gfxASurface> surface =
inImage->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE);
NS_ENSURE_TRUE(surface, NS_ERROR_FAILURE);
nsRefPtr<gfxImageSurface> frame(surface->GetAsReadableARGB32ImageSurface());

View File

@ -647,10 +647,9 @@ nsresult nsWindowGfx::CreateIcon(imgIContainer *aContainer,
HICON *aIcon) {
// Get the image data
nsRefPtr<gfxASurface> surface;
aContainer->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE,
getter_AddRefs(surface));
nsRefPtr<gfxASurface> surface =
aContainer->GetFrame(imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE);
NS_ENSURE_TRUE(surface, NS_ERROR_NOT_AVAILABLE);
nsRefPtr<gfxImageSurface> frame(surface->GetAsReadableARGB32ImageSurface());