Skip to content

Commit

Permalink
Bug 1711061 - Part 2. Add imgIContainer::GetImageProvider skeleton. r…
Browse files Browse the repository at this point in the history
…=tnikkel

In later parts in this series, GetImageProvider will replace
GetImageContainerAtSize. This will be a more specialized and lower
overhead means to get a wr::ImageKey for a particular surface.

Differential Revision: https://phabricator.services.mozilla.com/D126596
  • Loading branch information
aosmond committed Nov 27, 2021
1 parent c4d508a commit 6a2ad86
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 0 deletions.
21 changes: 21 additions & 0 deletions image/ClippedImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,27 @@ ClippedImage::GetImageContainerAtSize(WindowRenderer* aRenderer,
return ImgDrawResult::NOT_SUPPORTED;
}

NS_IMETHODIMP_(ImgDrawResult)
ClippedImage::GetImageProvider(WindowRenderer* aRenderer,
const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const Maybe<ImageIntRegion>& aRegion,
uint32_t aFlags,
WebRenderImageProvider** aProvider) {
// 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()->GetImageProvider(aRenderer, aSize, aSVGContext,
aRegion, aFlags, aProvider);
}

return ImgDrawResult::NOT_SUPPORTED;
}

static bool MustCreateSurface(gfxContext* aContext, const nsIntSize& aSize,
const ImageRegion& aRegion,
const uint32_t aFlags) {
Expand Down
5 changes: 5 additions & 0 deletions image/ClippedImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class ClippedImage : public ImageWrapper {
const Maybe<ImageIntRegion>& aRegion, uint32_t aFlags,
layers::ImageContainer** aOutContainer) override;
NS_IMETHOD_(ImgDrawResult)
GetImageProvider(WindowRenderer* aRenderer, const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const Maybe<ImageIntRegion>& aRegion, uint32_t aFlags,
WebRenderImageProvider** aProvider) override;
NS_IMETHOD_(ImgDrawResult)
Draw(gfxContext* aContext, const nsIntSize& aSize, const ImageRegion& aRegion,
uint32_t aWhichFrame, gfx::SamplingFilter aSamplingFilter,
const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
Expand Down
10 changes: 10 additions & 0 deletions image/DynamicImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ DynamicImage::GetImageContainerAtSize(WindowRenderer* aRenderer,
return ImgDrawResult::NOT_SUPPORTED;
}

NS_IMETHODIMP_(ImgDrawResult)
DynamicImage::GetImageProvider(WindowRenderer* aRenderer,
const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const Maybe<ImageIntRegion>& aRegion,
uint32_t aFlags,
WebRenderImageProvider** aProvider) {
return ImgDrawResult::NOT_SUPPORTED;
}

NS_IMETHODIMP_(ImgDrawResult)
DynamicImage::Draw(gfxContext* aContext, const nsIntSize& aSize,
const ImageRegion& aRegion, uint32_t aWhichFrame,
Expand Down
20 changes: 20 additions & 0 deletions image/FrozenImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ FrozenImage::GetImageContainerAtSize(WindowRenderer* aRenderer,
return ImgDrawResult::NOT_SUPPORTED;
}

NS_IMETHODIMP_(ImgDrawResult)
FrozenImage::GetImageProvider(WindowRenderer* aRenderer,
const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const Maybe<ImageIntRegion>& aRegion,
uint32_t aFlags,
WebRenderImageProvider** aProvider) {
if (IsNonAnimated()) {
return InnerImage()->GetImageProvider(aRenderer, aSize, aSVGContext,
aRegion, aFlags, aProvider);
}

// 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 ImgDrawResult::NOT_SUPPORTED;
}

NS_IMETHODIMP_(ImgDrawResult)
FrozenImage::Draw(gfxContext* aContext, const nsIntSize& aSize,
const ImageRegion& aRegion,
Expand Down
5 changes: 5 additions & 0 deletions image/FrozenImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class FrozenImage : public ImageWrapper {
const Maybe<ImageIntRegion>& aRegion, uint32_t aFlags,
layers::ImageContainer** aOutContainer) override;
NS_IMETHOD_(ImgDrawResult)
GetImageProvider(WindowRenderer* aRenderer, const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const Maybe<ImageIntRegion>& aRegion, uint32_t aFlags,
WebRenderImageProvider** aProvider) override;
NS_IMETHOD_(ImgDrawResult)
Draw(gfxContext* aContext, const nsIntSize& aSize, const ImageRegion& aRegion,
uint32_t aWhichFrame, gfx::SamplingFilter aSamplingFilter,
const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
Expand Down
11 changes: 11 additions & 0 deletions image/ImageWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,17 @@ ImageWrapper::GetImageContainerAtSize(WindowRenderer* aRenderer,
aRegion, aFlags, aOutContainer);
}

NS_IMETHODIMP_(ImgDrawResult)
ImageWrapper::GetImageProvider(WindowRenderer* aRenderer,
const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const Maybe<ImageIntRegion>& aRegion,
uint32_t aFlags,
WebRenderImageProvider** aProvider) {
return mInnerImage->GetImageProvider(aRenderer, aSize, aSVGContext, aRegion,
aFlags, aProvider);
}

NS_IMETHODIMP_(ImgDrawResult)
ImageWrapper::Draw(gfxContext* aContext, const nsIntSize& aSize,
const ImageRegion& aRegion, uint32_t aWhichFrame,
Expand Down
21 changes: 21 additions & 0 deletions image/OrientedImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,27 @@ OrientedImage::GetImageContainerAtSize(
return ImgDrawResult::NOT_SUPPORTED;
}

NS_IMETHODIMP_(ImgDrawResult)
OrientedImage::GetImageProvider(WindowRenderer* aRenderer,
const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const Maybe<ImageIntRegion>& aRegion,
uint32_t aFlags,
WebRenderImageProvider** aProvider) {
// 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()->GetImageProvider(aRenderer, aSize, aSVGContext,
aRegion, aFlags, aProvider);
}

return ImgDrawResult::NOT_SUPPORTED;
}

struct MatrixBuilder {
explicit MatrixBuilder(bool aInvert) : mInvert(aInvert) {}

Expand Down
5 changes: 5 additions & 0 deletions image/OrientedImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class OrientedImage : public ImageWrapper {
const Maybe<ImageIntRegion>& aRegion, uint32_t aFlags,
layers::ImageContainer** aOutContainer) override;
NS_IMETHOD_(ImgDrawResult)
GetImageProvider(WindowRenderer* aRenderer, const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const Maybe<ImageIntRegion>& aRegion, uint32_t aFlags,
WebRenderImageProvider** aProvider) override;
NS_IMETHOD_(ImgDrawResult)
Draw(gfxContext* aContext, const nsIntSize& aSize, const ImageRegion& aRegion,
uint32_t aWhichFrame, gfx::SamplingFilter aSamplingFilter,
const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
Expand Down
10 changes: 10 additions & 0 deletions image/RasterImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,16 @@ RasterImage::GetImageContainerAtSize(WindowRenderer* aRenderer,
aOutContainer);
}

NS_IMETHODIMP_(ImgDrawResult)
RasterImage::GetImageProvider(WindowRenderer* aRenderer,
const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const Maybe<ImageIntRegion>& aRegion,
uint32_t aFlags,
WebRenderImageProvider** aProvider) {
return ImgDrawResult::NOT_SUPPORTED;
}

size_t RasterImage::SizeOfSourceWithComputedFallback(
SizeOfState& aState) const {
return mSourceBuffer->SizeOfIncludingThisWithComputedFallback(
Expand Down
11 changes: 11 additions & 0 deletions image/VectorImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,17 @@ VectorImage::GetImageContainerAtSize(WindowRenderer* aRenderer,
return rv;
}

//******************************************************************************
NS_IMETHODIMP_(ImgDrawResult)
VectorImage::GetImageProvider(WindowRenderer* aRenderer,
const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const Maybe<ImageIntRegion>& aRegion,
uint32_t aFlags,
WebRenderImageProvider** aProvider) {
return ImgDrawResult::NOT_SUPPORTED;
}

bool VectorImage::MaybeRestrictSVGContext(
Maybe<SVGImageContext>& aNewSVGContext,
const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags) {
Expand Down
29 changes: 29 additions & 0 deletions image/imgIContainer.idl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace image {

class ImageRegion;
class ImageIntRegion;
class WebRenderImageProvider;
struct Orientation;
struct Resolution;

Expand All @@ -70,6 +71,7 @@ native nsSize(nsSize);
[ptr] native nsIFrame(nsIFrame);
native TempRefImageContainer(already_AddRefed<mozilla::layers::ImageContainer>);
[ptr] native ImageContainer(mozilla::layers::ImageContainer);
[ptr] native WebRenderImageProvider(mozilla::image::WebRenderImageProvider);
[ref] native ImageRegion(mozilla::image::ImageRegion);
[ptr] native WindowRenderer(mozilla::WindowRenderer);
native Orientation(mozilla::image::Orientation);
Expand Down Expand Up @@ -352,6 +354,33 @@ interface imgIContainer : nsISupports
in uint32_t aFlags,
out ImageContainer aOutContainer);

/**
* Attempts to find a WebRenderImageProvider 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.)
*
* @param aRenderer The WindowRenderer which will be used to render the
* ImageContainer.
* @param aSVGContext If specified, SVG-related rendering context, such as
* overridden attributes on the image document's root <svg>
* node, and the size of the viewport that the full image
* would occupy. Ignored for raster images.
* @param aFlags Decoding / drawing flags (in other words, FLAG_* flags).
* Currently only FLAG_SYNC_DECODE and FLAG_SYNC_DECODE_IF_FAST
* are supported.
* @param aProvider Return value for WebRenderImageProvider for the current
* frame. May be null depending on the draw result.
* @return The draw result for the current frame.
*/
[noscript, notxpcom] ImgDrawResult getImageProvider(in WindowRenderer aRenderer,
[const] in nsIntSize aSize,
[const] in MaybeSVGImageContext aSVGContext,
[const] in MaybeImageIntRegion aRegion,
in uint32_t aFlags,
out WebRenderImageProvider aProvider);

/**
* Draw the requested frame of this image onto the context specified.
*
Expand Down

0 comments on commit 6a2ad86

Please sign in to comment.