Bug 1368776 - Part 9. Expose getting an image container at a given size. r=tnikkel

This adds IsImageContainerAvailableAtSize and GetImageContainerAtSize to
the imgIContainer interface, as well as stubbing it for all of the
classes which implement it. The real implementations will follow for the
more complicated classes (RasterImage, VectorImage).
This commit is contained in:
Andrew Osmond
2017-11-17 06:45:26 -05:00
parent c54664a378
commit cb4c0d8e52
11 changed files with 202 additions and 1 deletions

View File

@@ -356,6 +356,35 @@ ClippedImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
return nullptr;
}
NS_IMETHODIMP_(bool)
ClippedImage::IsImageContainerAvailableAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
if (!ShouldClip()) {
return InnerImage()->IsImageContainerAvailableAtSize(aManager, aSize, aFlags);
}
return false;
}
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
ClippedImage::GetImageContainerAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
// XXX(seth): We currently don't have a way of clipping the result of
// GetImageContainer. We work around this by always returning null, but if it
// ever turns out that ClippedImage is widely used on codepaths that can
// actually benefit from GetImageContainer, it would be a good idea to fix
// that method for performance reasons.
if (!ShouldClip()) {
return InnerImage()->GetImageContainerAtSize(aManager, aSize, aFlags);
}
return nullptr;
}
static bool
MustCreateSurface(gfxContext* aContext,
const nsIntSize& aSize,

View File

@@ -47,6 +47,14 @@ public:
NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
GetImageContainer(layers::LayerManager* aManager,
uint32_t aFlags) override;
NS_IMETHOD_(bool)
IsImageContainerAvailableAtSize(layers::LayerManager* aManager,
const gfx::IntSize& aSize,
uint32_t aFlags) override;
NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
GetImageContainerAtSize(layers::LayerManager* aManager,
const gfx::IntSize& aSize,
uint32_t aFlags) override;
NS_IMETHOD_(DrawResult) Draw(gfxContext* aContext,
const nsIntSize& aSize,
const ImageRegion& aRegion,

View File

@@ -226,6 +226,22 @@ DynamicImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
return nullptr;
}
NS_IMETHODIMP_(bool)
DynamicImage::IsImageContainerAvailableAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
return false;
}
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
DynamicImage::GetImageContainerAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
return nullptr;
}
NS_IMETHODIMP_(DrawResult)
DynamicImage::Draw(gfxContext* aContext,
const nsIntSize& aSize,

View File

@@ -71,6 +71,27 @@ FrozenImage::GetImageContainer(layers::LayerManager* aManager, uint32_t aFlags)
return nullptr;
}
NS_IMETHODIMP_(bool)
FrozenImage::IsImageContainerAvailableAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
return false;
}
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
FrozenImage::GetImageContainerAtSize(layers::LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
// XXX(seth): GetImageContainer does not currently support anything but the
// current frame. We work around this by always returning null, but if it ever
// turns out that FrozenImage is widely used on codepaths that can actually
// benefit from GetImageContainer, it would be a good idea to fix that method
// for performance reasons.
return nullptr;
}
NS_IMETHODIMP_(DrawResult)
FrozenImage::Draw(gfxContext* aContext,
const nsIntSize& aSize,

View File

@@ -46,6 +46,14 @@ public:
NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
GetImageContainer(layers::LayerManager* aManager,
uint32_t aFlags) override;
NS_IMETHOD_(bool)
IsImageContainerAvailableAtSize(layers::LayerManager* aManager,
const gfx::IntSize& aSize,
uint32_t aFlags) override;
NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
GetImageContainerAtSize(layers::LayerManager* aManager,
const gfx::IntSize& aSize,
uint32_t aFlags) override;
NS_IMETHOD_(DrawResult) Draw(gfxContext* aContext,
const nsIntSize& aSize,
const ImageRegion& aRegion,

View File

@@ -214,6 +214,22 @@ ImageWrapper::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
return mInnerImage->GetImageContainer(aManager, aFlags);
}
NS_IMETHODIMP_(bool)
ImageWrapper::IsImageContainerAvailableAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
return mInnerImage->IsImageContainerAvailableAtSize(aManager, aSize, aFlags);
}
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
ImageWrapper::GetImageContainerAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
return mInnerImage->GetImageContainerAtSize(aManager, aSize, aFlags);
}
NS_IMETHODIMP_(DrawResult)
ImageWrapper::Draw(gfxContext* aContext,
const nsIntSize& aSize,

View File

@@ -173,6 +173,35 @@ OrientedImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
return nullptr;
}
NS_IMETHODIMP_(bool)
OrientedImage::IsImageContainerAvailableAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
if (mOrientation.IsIdentity()) {
return InnerImage()->IsImageContainerAvailableAtSize(aManager, aSize, aFlags);
}
return false;
}
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
OrientedImage::GetImageContainerAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
// XXX(seth): We currently don't have a way of orienting the result of
// GetImageContainer. We work around this by always returning null, but if it
// ever turns out that OrientedImage is widely used on codepaths that can
// actually benefit from GetImageContainer, it would be a good idea to fix
// that method for performance reasons.
if (mOrientation.IsIdentity()) {
return InnerImage()->GetImageContainerAtSize(aManager, aSize, aFlags);
}
return nullptr;
}
struct MatrixBuilder
{
explicit MatrixBuilder(bool aInvert) : mInvert(aInvert) { }

View File

@@ -44,6 +44,14 @@ public:
NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
GetImageContainer(layers::LayerManager* aManager,
uint32_t aFlags) override;
NS_IMETHOD_(bool)
IsImageContainerAvailableAtSize(layers::LayerManager* aManager,
const gfx::IntSize& aSize,
uint32_t aFlags) override;
NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
GetImageContainerAtSize(layers::LayerManager* aManager,
const gfx::IntSize& aSize,
uint32_t aFlags) override;
NS_IMETHOD_(DrawResult) Draw(gfxContext* aContext,
const nsIntSize& aSize,
const ImageRegion& aRegion,

View File

@@ -639,6 +639,22 @@ RasterImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
return GetImageContainerImpl(aManager, mSize, aFlags);
}
NS_IMETHODIMP_(bool)
RasterImage::IsImageContainerAvailableAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
return false;
}
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
RasterImage::GetImageContainerAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
return nullptr;
}
size_t
RasterImage::SizeOfSourceWithComputedFallback(SizeOfState& aState) const
{

View File

@@ -770,6 +770,7 @@ VectorImage::GetFrameAtSize(const IntSize& aSize,
return result == DrawResult::SUCCESS ? dt->Snapshot() : nullptr;
}
//******************************************************************************
NS_IMETHODIMP_(bool)
VectorImage::IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags)
{
@@ -783,6 +784,24 @@ VectorImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
return nullptr;
}
//******************************************************************************
NS_IMETHODIMP_(bool)
VectorImage::IsImageContainerAvailableAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
return false;
}
//******************************************************************************
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
VectorImage::GetImageContainerAtSize(LayerManager* aManager,
const IntSize& aSize,
uint32_t aFlags)
{
return nullptr;
}
//******************************************************************************
NS_IMETHODIMP_(DrawResult)
VectorImage::Draw(gfxContext* aContext,

View File

@@ -280,7 +280,7 @@ interface imgIContainer : nsISupports
in uint32_t aFlags);
/**
* Attempts to create an ImageContainer (and Image) containing the current
* frame.
* frame at its native size.
*
* Avoid calling this unless you're actually going to layerize this image.
*
@@ -295,6 +295,37 @@ interface imgIContainer : nsISupports
[noscript, notxpcom] TempRefImageContainer getImageContainer(in LayerManager aManager,
in uint32_t aFlags);
/**
* @return true if getImageContainer() is expected to return a valid
* ImageContainer when passed the given @Manager, @Size and @Flags
* parameters.
*/
[noscript, notxpcom] boolean isImageContainerAvailableAtSize(in LayerManager aManager,
[const] in nsIntSize aSize,
in uint32_t aFlags);
/**
* Attempts to create an ImageContainer (and Image) containing the current
* frame at the given size. Match the requested size is best effort; it's
* not guaranteed that the surface you get will be a perfect match. (Some
* reasons you may get a surface of a different size include: if you
* requested upscaling, or if downscale-during-decode is disabled.)
*
* Avoid calling this unless you're actually going to layerize this image.
*
* @param aManager The LayerManager which will be used to create the
* ImageContainer.
* @param aSize The size to decode the frame at.
* @param aFlags Decoding / drawing flags (in other words, FLAG_* flags).
* Currently only FLAG_SYNC_DECODE and FLAG_SYNC_DECODE_IF_FAST
* are supported.
* @return An ImageContainer for the current frame, or nullptr if one could
* not be created.
*/
[noscript, notxpcom] TempRefImageContainer getImageContainerAtSize(in LayerManager aManager,
[const] in nsIntSize aSize,
in uint32_t aFlags);
/**
* Draw the requested frame of this image onto the context specified.
*