Bug 826093 (Part 5) - Remove imgIContainer::ExtractFrame. r=joe, sr=bz

--HG--
extra : rebase_source : fcf5028a8f91f28306ca009cbe41f48794f19291
This commit is contained in:
Seth Fowler 2013-04-05 14:15:05 -07:00
parent a635c53879
commit 53b25d147a
9 changed files with 19 additions and 234 deletions

View File

@ -52,13 +52,12 @@ native nsSize(nsSize);
/**
* imgIContainer is the interface that represents an image. It allows
* access to frames as Thebes surfaces, and permits users to extract subregions
* as other imgIContainers. It also allows drawing of images on to Thebes
* contexts.
* access to frames as Thebes surfaces. It also allows drawing of images
* onto Thebes contexts.
*
* Internally, imgIContainer also manages animation of images.
*/
[scriptable, builtinclass, uuid(01c4f92f-f883-4837-a127-d8f30920e374)]
[scriptable, builtinclass, uuid(0c1caf24-bce7-4db5-971d-8e1b6ed07540)]
interface imgIContainer : nsISupports
{
/**
@ -178,19 +177,6 @@ interface imgIContainer : nsISupports
*/
[noscript] ImageContainer getImageContainer(in LayerManager aManager);
/**
* Create a new imgContainer that contains only a single frame, which itself
* contains a subregion of the given frame.
*
* @param aWhichFrame Frame specifier of the FRAME_* variety.
* @param aRect the area of the current frame to be duplicated in the
* returned imgContainer's frame.
* @param aFlags Flags of the FLAG_* variety
*/
[noscript] imgIContainer extractFrame(in uint32_t aWhichFrame,
[const] in nsIntRect aRect,
in uint32_t aFlags);
/**
* Draw a frame onto the context specified.
*
@ -229,11 +215,10 @@ interface imgIContainer : nsISupports
/*
* Ensures that an image is decoding. Calling this function guarantees that
* the image will at some point fire off decode notifications. Calling draw(),
* getFrame(), copyFrame(), or extractCurrentFrame() triggers the same
* mechanism internally. Thus, if you want to be sure that the image will be
* decoded but don't want to access it until then, you must call
* requestDecode().
* the image will at some point fire off decode notifications. Calling draw()
* or getFrame() triggers the same mechanism internally. Thus, if you want to
* be sure that the image will be decoded but don't want to access it until
* then, you must call requestDecode().
*/
void requestDecode();

View File

@ -210,19 +210,6 @@ ClippedImage::GetImageContainer(LayerManager* aManager, ImageContainer** _retval
return NS_OK;
}
NS_IMETHODIMP
ClippedImage::ExtractFrame(uint32_t /* aWhichFrame */,
const nsIntRect& /* aRegion */,
uint32_t /* aFlags */,
imgIContainer** /* _retval */)
{
// XXX(seth): This method has to be present in this patch because we haven't
// gotten to the point where we can remove ExtractFrame yet, but implementing
// it would be a waste of effort.
MOZ_ASSERT(false, "ClippedImage::ExtractFrame shouldn't be called");
return NS_ERROR_NOT_AVAILABLE;
}
bool
ClippedImage::MustCreateSurface(gfxContext* aContext,
const gfxMatrix& aTransform,

View File

@ -38,10 +38,6 @@ public:
gfxASurface** _retval) MOZ_OVERRIDE;
NS_IMETHOD GetImageContainer(mozilla::layers::LayerManager* aManager,
mozilla::layers::ImageContainer** _retval) MOZ_OVERRIDE;
NS_IMETHOD ExtractFrame(uint32_t aWhichFrame,
const nsIntRect& aRegion,
uint32_t aFlags,
imgIContainer** _retval) MOZ_OVERRIDE;
NS_IMETHOD Draw(gfxContext* aContext,
gfxPattern::GraphicsFilter aFilter,
const gfxMatrix& aUserSpaceToImageSpace,

View File

@ -68,15 +68,6 @@ FrozenImage::GetImageContainer(layers::LayerManager* aManager,
return NS_OK;
}
NS_IMETHODIMP
FrozenImage::ExtractFrame(uint32_t aWhichFrame,
const nsIntRect& aRegion,
uint32_t aFlags,
imgIContainer** _retval)
{
return InnerImage()->ExtractFrame(FRAME_FIRST, aRegion, aFlags, _retval);
}
NS_IMETHODIMP
FrozenImage::Draw(gfxContext* aContext,
gfxPattern::GraphicsFilter aFilter,

View File

@ -40,10 +40,6 @@ public:
NS_IMETHOD_(bool) FrameIsOpaque(uint32_t aWhichFrame) MOZ_OVERRIDE;
NS_IMETHOD GetImageContainer(layers::LayerManager* aManager,
layers::ImageContainer** _retval) MOZ_OVERRIDE;
NS_IMETHOD ExtractFrame(uint32_t aWhichFrame,
const nsIntRect& aRegion,
uint32_t aFlags,
imgIContainer** _retval) MOZ_OVERRIDE;
NS_IMETHOD Draw(gfxContext* aContext,
gfxPattern::GraphicsFilter aFilter,
const gfxMatrix& aUserSpaceToImageSpace,

View File

@ -203,15 +203,6 @@ ImageWrapper::GetImageContainer(LayerManager* aManager, ImageContainer** _retval
return mInnerImage->GetImageContainer(aManager, _retval);
}
NS_IMETHODIMP
ImageWrapper::ExtractFrame(uint32_t aWhichFrame,
const nsIntRect& aRegion,
uint32_t aFlags,
imgIContainer** _retval)
{
return mInnerImage->ExtractFrame(aWhichFrame, aRegion, aFlags, _retval);
}
NS_IMETHODIMP
ImageWrapper::Draw(gfxContext* aContext,
gfxPattern::GraphicsFilter aFilter,

View File

@ -513,14 +513,6 @@ RasterImage::Init(const char* aMimeType,
discardable_source_bytes += mSourceData.Length();
}
// If we're being called from ExtractFrame (used by borderimage),
// we don't actually do any decoding. Bail early.
// XXX - This should be removed when we fix borderimage
if (mSourceDataMimeType.Length() == 0) {
mInitialized = true;
return NS_OK;
}
// Instantiate the decoder
nsresult rv = InitDecoder(/* aDoSizeDecode = */ true);
CONTAINER_ENSURE_SUCCESS(rv);
@ -694,85 +686,6 @@ RasterImage::RequestRefresh(const mozilla::TimeStamp& aTime)
}
}
//******************************************************************************
/* [noscript] imgIContainer extractFrame(uint32_t aWhichFrame,
* [const] in nsIntRect aRegion,
* in uint32_t aFlags); */
NS_IMETHODIMP
RasterImage::ExtractFrame(uint32_t aWhichFrame,
const nsIntRect &aRegion,
uint32_t aFlags,
imgIContainer **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsresult rv;
if (aWhichFrame > FRAME_MAX_VALUE)
return NS_ERROR_INVALID_ARG;
if (mError)
return NS_ERROR_FAILURE;
// Disallowed in the API
if (mInDecoder && (aFlags & imgIContainer::FLAG_SYNC_DECODE))
return NS_ERROR_FAILURE;
// Make a new container. This should switch to another class with bug 505959.
nsRefPtr<RasterImage> img(new RasterImage());
// We don't actually have a mimetype in this case. The empty string tells the
// init routine not to try to instantiate a decoder. This should be fixed in
// bug 505959.
img->Init("", INIT_FLAG_NONE);
img->SetSize(aRegion.width, aRegion.height);
img->mDecoded = true; // Also, we need to mark the image as decoded
img->mHasBeenDecoded = true;
img->mFrameDecodeFlags = aFlags & DECODE_FLAGS_MASK;
if (!ApplyDecodeFlags(aFlags))
return NS_ERROR_NOT_AVAILABLE;
// If a synchronous decode was requested, do it
if (aFlags & FLAG_SYNC_DECODE) {
rv = SyncDecode();
CONTAINER_ENSURE_SUCCESS(rv);
}
// Get the frame. If it's not there, it's probably the caller's fault for
// not waiting for the data to be loaded from the network or not passing
// FLAG_SYNC_DECODE
uint32_t frameIndex = (aWhichFrame == FRAME_FIRST) ?
0 : GetCurrentImgFrameIndex();
imgFrame *frame = GetDrawableImgFrame(frameIndex);
if (!frame) {
*_retval = nullptr;
return NS_ERROR_FAILURE;
}
// The frame can be smaller than the image. We want to extract only the part
// of the frame that actually exists.
nsIntRect framerect = frame->GetRect();
framerect.IntersectRect(framerect, aRegion);
if (framerect.IsEmpty())
return NS_ERROR_NOT_AVAILABLE;
nsAutoPtr<imgFrame> subframe;
rv = frame->Extract(framerect, getter_Transfers(subframe));
if (NS_FAILED(rv))
return rv;
img->mFrames.AppendElement(subframe.forget());
img->mStatusTracker->RecordLoaded();
img->mStatusTracker->RecordDecoded();
*_retval = img.forget().get();
return NS_OK;
}
//******************************************************************************
/* readonly attribute int32_t width; */
NS_IMETHODIMP
@ -2774,11 +2687,10 @@ RasterImage::WriteToDecoder(const char *aBuffer, uint32_t aCount)
}
// This function is called in situations where it's clear that we want the
// frames in decoded form (Draw, GetFrame, CopyFrame, ExtractFrame, etc).
// If we're completely decoded, this method resets the discard timer (if
// we're discardable), since wanting the frames now is a good indicator of
// wanting them again soon. If we're not decoded, this method kicks off
// asynchronous decoding to generate the frames.
// frames in decoded form (Draw, GetFrame, etc). If we're completely decoded,
// this method resets the discard timer (if we're discardable), since wanting
// the frames now is a good indicator of wanting them again soon. If we're not
// decoded, this method kicks off asynchronous decoding to generate the frames.
nsresult
RasterImage::WantDecodedFrames()
{

View File

@ -301,12 +301,10 @@ NS_IMPL_ISUPPORTS3(VectorImage,
VectorImage::VectorImage(imgStatusTracker* aStatusTracker,
nsIURI* aURI /* = nullptr */) :
ImageResource(aStatusTracker, aURI), // invoke superclass's constructor
mRestrictedRegion(0, 0, 0, 0),
mIsInitialized(false),
mIsFullyLoaded(false),
mIsDrawing(false),
mHaveAnimations(false),
mHaveRestrictedRegion(false)
mHaveAnimations(false)
{
}
@ -326,8 +324,7 @@ VectorImage::Init(const char* aMimeType,
if (mIsInitialized)
return NS_ERROR_ILLEGAL_VALUE;
MOZ_ASSERT(!mIsFullyLoaded && !mHaveAnimations &&
!mHaveRestrictedRegion && !mError,
MOZ_ASSERT(!mIsFullyLoaded && !mHaveAnimations && !mError,
"Flags unexpectedly set before initialization");
MOZ_ASSERT(!strcmp(aMimeType, IMAGE_SVG_XML), "Unexpected mimetype");
@ -595,14 +592,7 @@ VectorImage::GetFrame(uint32_t aWhichFrame,
// ---------------------------------------------
// Make our surface the size of what will ultimately be drawn to it.
// (either the full image size, or the restricted region)
gfxIntSize surfaceSize;
if (mHaveRestrictedRegion) {
surfaceSize.width = mRestrictedRegion.width;
surfaceSize.height = mRestrictedRegion.height;
} else {
surfaceSize.width = imageIntSize.width;
surfaceSize.height = imageIntSize.height;
}
gfxIntSize surfaceSize(imageIntSize.width, imageIntSize.height);
nsRefPtr<gfxImageSurface> surface =
new gfxImageSurface(surfaceSize, gfxASurface::ImageFormatARGB32);
@ -631,54 +621,6 @@ VectorImage::GetImageContainer(LayerManager* aManager,
return NS_OK;
}
//******************************************************************************
/* [noscript] imgIContainer extractFrame(uint32_t aWhichFrame,
* [const] in nsIntRect aRegion,
* in uint32_t aFlags); */
NS_IMETHODIMP
VectorImage::ExtractFrame(uint32_t aWhichFrame,
const nsIntRect& aRegion,
uint32_t aFlags,
imgIContainer** _retval)
{
NS_ENSURE_ARG_POINTER(_retval);
if (mError || !mIsFullyLoaded)
return NS_ERROR_FAILURE;
// XXXdholbert NOTE: This method assumes FRAME_CURRENT (not FRAME_FIRST)
// right now, because mozilla doesn't actually contain any clients of this
// method that use FRAME_FIRST. If it's needed, we *could* handle
// FRAME_FIRST by saving the helper-doc's current SMIL time, seeking it to
// time 0, rendering to a RasterImage, and then restoring our saved time.
if (aWhichFrame != FRAME_CURRENT) {
NS_WARNING("VectorImage::ExtractFrame with something other than "
"FRAME_CURRENT isn't supported yet. Assuming FRAME_CURRENT.");
}
// XXXdholbert This method also doesn't actually freeze animation in the
// returned imgIContainer, because it shares our helper-document. To
// get a true snapshot, we need to clone the document - see bug 590792.
// Make a new container with same SVG document.
nsRefPtr<VectorImage> extractedImg = new VectorImage();
extractedImg->mSVGDocumentWrapper = mSVGDocumentWrapper;
extractedImg->mAnimationMode = kDontAnimMode;
extractedImg->mRestrictedRegion.x = aRegion.x;
extractedImg->mRestrictedRegion.y = aRegion.y;
// (disallow negative width/height on our restricted region)
extractedImg->mRestrictedRegion.width = std::max(aRegion.width, 0);
extractedImg->mRestrictedRegion.height = std::max(aRegion.height, 0);
extractedImg->mIsInitialized = true;
extractedImg->mIsFullyLoaded = true;
extractedImg->mHaveRestrictedRegion = true;
*_retval = extractedImg.forget().get();
return NS_OK;
}
//******************************************************************************
/* [noscript] void draw(in gfxContext aContext,
* in gfxGraphicsFilter aFilter,
@ -722,24 +664,19 @@ VectorImage::Draw(gfxContext* aContext,
mSVGDocumentWrapper->UpdateViewportBounds(aViewportSize);
mSVGDocumentWrapper->FlushImageTransformInvalidation();
nsIntSize imageSize = mHaveRestrictedRegion ?
mRestrictedRegion.Size() : aViewportSize;
// XXXdholbert Do we need to convert image size from
// CSS pixels to dev pixels here? (is gfxCallbackDrawable's 2nd arg in dev
// pixels?)
gfxIntSize imageSizeGfx(imageSize.width, imageSize.height);
gfxIntSize imageSizeGfx(aViewportSize.width, aViewportSize.height);
// Based on imgFrame::Draw
gfxRect sourceRect = aUserSpaceToImageSpace.Transform(aFill);
gfxRect imageRect(0, 0, imageSize.width, imageSize.height);
gfxRect imageRect(0, 0, aViewportSize.width, aViewportSize.height);
gfxRect subimage(aSubimage.x, aSubimage.y, aSubimage.width, aSubimage.height);
nsRefPtr<gfxDrawingCallback> cb =
new SVGDrawingCallback(mSVGDocumentWrapper,
mHaveRestrictedRegion ?
mRestrictedRegion :
nsIntRect(nsIntPoint(0, 0), aViewportSize),
aFlags);
@ -750,12 +687,9 @@ VectorImage::Draw(gfxContext* aContext,
subimage, sourceRect, imageRect, aFill,
gfxASurface::ImageFormatARGB32, aFilter);
MOZ_ASSERT(mRenderingObserver || mHaveRestrictedRegion,
"Should have a rendering observer by now unless ExtractFrame created us");
if (mRenderingObserver) {
// Allow ourselves to fire FrameChanged and OnStopFrame again.
mRenderingObserver->ResumeListening();
}
// Allow ourselves to fire FrameChanged and OnStopFrame again.
MOZ_ASSERT(mRenderingObserver, "Should have a rendering observer by now");
mRenderingObserver->ResumeListening();
return NS_OK;
}

View File

@ -84,18 +84,11 @@ private:
nsRefPtr<SVGLoadEventListener> mLoadEventListener;
nsRefPtr<SVGParseCompleteListener> mParseCompleteListener;
nsIntRect mRestrictedRegion; // If we were created by
// ExtractFrame, this is the region
// that we're restricted to using.
// Otherwise, this is ignored.
bool mIsInitialized; // Have we been initalized?
bool mIsFullyLoaded; // Has the SVG document finished loading?
bool mIsDrawing; // Are we currently drawing?
bool mHaveAnimations; // Is our SVG content SMIL-animated?
// (Only set after mIsFullyLoaded.)
bool mHaveRestrictedRegion; // Are we a restricted-region clone
// created via ExtractFrame?
friend class ImageFactory;
};