Skip to content

Commit

Permalink
Bug 1779598 - Stop passing around Maybe<SVGImageContext>. r=aosmond
Browse files Browse the repository at this point in the history
All its members are optional, so we can just use it as a plain struct
rather than Maybe<> all around, which simplifies the code and prevents
silly bugs like bug 1779592.

Mostly automatic via:

  rg -l 'SVGImageContext' . | xargs sed -i 's/Maybe<SVGImageContext>/SVGImageContext/g'

With trivial build fixes.

Not intended to change behavior.

Differential Revision: https://phabricator.services.mozilla.com/D151846
  • Loading branch information
emilio committed Jul 14, 2022
1 parent 012b6f1 commit 4414d74
Show file tree
Hide file tree
Showing 31 changed files with 173 additions and 227 deletions.
8 changes: 3 additions & 5 deletions dom/canvas/CanvasRenderingContext2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5187,16 +5187,14 @@ void CanvasRenderingContext2D::DrawDirectlyToCanvas(
// FLAG_CLAMP is added for increased performance, since we never tile here.
uint32_t modifiedFlags = aImage.mDrawingFlags | imgIContainer::FLAG_CLAMP;

CSSIntSize sz(
scaledImageSize.width,
scaledImageSize
.height); // XXX hmm is scaledImageSize really in CSS pixels?
// XXX hmm is scaledImageSize really in CSS pixels?
CSSIntSize sz(scaledImageSize.width, scaledImageSize.height);
SVGImageContext svgContext(Some(sz));

auto result = aImage.mImgContainer->Draw(
context, scaledImageSize,
ImageRegion::Create(gfxRect(aSrc.x, aSrc.y, aSrc.width, aSrc.height)),
aImage.mWhichFrame, SamplingFilter::GOOD, Some(svgContext), modifiedFlags,
aImage.mWhichFrame, SamplingFilter::GOOD, svgContext, modifiedFlags,
CurrentState().globalAlpha);

if (result != ImgDrawResult::SUCCESS) {
Expand Down
7 changes: 3 additions & 4 deletions dom/svg/SVGSVGElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,17 @@ class MOZ_RAII AutoSVGTimeSetRestore {

class MOZ_RAII AutoPreserveAspectRatioOverride {
public:
AutoPreserveAspectRatioOverride(const Maybe<SVGImageContext>& aSVGContext,
AutoPreserveAspectRatioOverride(const SVGImageContext& aSVGContext,
dom::SVGSVGElement* aRootElem)
: mRootElem(aRootElem), mDidOverride(false) {
MOZ_ASSERT(mRootElem, "No SVG/Symbol node to manage?");

if (aSVGContext.isSome() &&
aSVGContext->GetPreserveAspectRatio().isSome()) {
if (aSVGContext.GetPreserveAspectRatio().isSome()) {
// Override preserveAspectRatio in our helper document.
// XXXdholbert We should technically be overriding the helper doc's clip
// and overflow properties here, too. See bug 272288 comment 36.
mRootElem->SetImageOverridePreserveAspectRatio(
*aSVGContext->GetPreserveAspectRatio());
*aSVGContext.GetPreserveAspectRatio());
mDidOverride = true;
}
}
Expand Down
11 changes: 5 additions & 6 deletions image/AutoRestoreSVGState.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MOZ_STACK_CLASS AutoRestoreSVGState final {
: AutoRestoreSVGState(aParams.svgContext, aParams.animationTime,
aSVGDocumentWrapper, aContextPaint) {}

AutoRestoreSVGState(const Maybe<SVGImageContext>& aSVGContext,
AutoRestoreSVGState(const SVGImageContext& aSVGContext,
float aAnimationTime,
SVGDocumentWrapper* aSVGDocumentWrapper,
bool aContextPaint)
Expand All @@ -42,9 +42,8 @@ class MOZ_STACK_CLASS AutoRestoreSVGState final {

if (auto* pc = aSVGDocumentWrapper->GetDocument()->GetPresContext()) {
pc->SetColorSchemeOverride([&] {
if (aSVGContext && aSVGContext->GetColorScheme()) {
auto scheme = *aSVGContext->GetColorScheme();
return scheme == ColorScheme::Light
if (auto scheme = aSVGContext.GetColorScheme()) {
return *scheme == ColorScheme::Light
? dom::PrefersColorSchemeOverride::Light
: dom::PrefersColorSchemeOverride::Dark;
}
Expand All @@ -56,8 +55,8 @@ class MOZ_STACK_CLASS AutoRestoreSVGState final {

// Set context paint (if specified) on the document:
if (aContextPaint) {
MOZ_ASSERT(aSVGContext->GetContextPaint());
mContextPaint.emplace(*aSVGContext->GetContextPaint(),
MOZ_ASSERT(aSVGContext.GetContextPaint());
mContextPaint.emplace(*aSVGContext.GetContextPaint(),
*aSVGDocumentWrapper->GetDocument());
}
}
Expand Down
11 changes: 4 additions & 7 deletions image/BlobSurfaceProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,16 @@ Maybe<BlobImageKeyData> BlobSurfaceProvider::RecordDrawing(
return Nothing();
}

bool contextPaint = svgContext && svgContext->GetContextPaint();
bool contextPaint = svgContext.GetContextPaint();

float animTime = (GetSurfaceKey().Playback() == PlaybackType::eStatic)
? 0.0f
: mSVGDocumentWrapper->GetCurrentTimeAsFloat();

IntSize viewportSize = size;
if (svgContext) {
auto cssViewportSize = svgContext->GetViewportSize();
if (cssViewportSize) {
// XXX losing unit
viewportSize.SizeTo(cssViewportSize->width, cssViewportSize->height);
}
if (auto cssViewportSize = svgContext.GetViewportSize()) {
// XXX losing unit
viewportSize.SizeTo(cssViewportSize->width, cssViewportSize->height);
}

{
Expand Down
35 changes: 14 additions & 21 deletions image/ClippedImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,16 @@
namespace mozilla {

using namespace gfx;
using layers::ImageContainer;
using std::make_pair;
using std::max;
using std::modf;
using std::pair;

namespace image {

class ClippedImageCachedSurface {
public:
ClippedImageCachedSurface(already_AddRefed<SourceSurface> aSurface,
const nsIntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
float aFrame, uint32_t aFlags,
ImgDrawResult aDrawResult)
const SVGImageContext& aSVGContext, float aFrame,
uint32_t aFlags, ImgDrawResult aDrawResult)
: mSurface(aSurface),
mSize(aSize),
mSVGContext(aSVGContext),
Expand All @@ -48,9 +43,8 @@ class ClippedImageCachedSurface {
MOZ_ASSERT(mSurface, "Must have a valid surface");
}

bool Matches(const nsIntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext, float aFrame,
uint32_t aFlags) const {
bool Matches(const nsIntSize& aSize, const SVGImageContext& aSVGContext,
float aFrame, uint32_t aFlags) const {
return mSize == aSize && mSVGContext == aSVGContext && mFrame == aFrame &&
mFlags == aFlags;
}
Expand All @@ -70,7 +64,7 @@ class ClippedImageCachedSurface {
private:
RefPtr<SourceSurface> mSurface;
const nsIntSize mSize;
Maybe<SVGImageContext> mSVGContext;
SVGImageContext mSVGContext;
const float mFrame;
const uint32_t mFlags;
const ImgDrawResult mDrawResult;
Expand All @@ -79,7 +73,7 @@ class ClippedImageCachedSurface {
class DrawSingleTileCallback : public gfxDrawingCallback {
public:
DrawSingleTileCallback(ClippedImage* aImage, const nsIntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const SVGImageContext& aSVGContext,
uint32_t aWhichFrame, uint32_t aFlags, float aOpacity)
: mImage(aImage),
mSize(aSize),
Expand Down Expand Up @@ -112,7 +106,7 @@ class DrawSingleTileCallback : public gfxDrawingCallback {
private:
RefPtr<ClippedImage> mImage;
const nsIntSize mSize;
const Maybe<SVGImageContext>& mSVGContext;
const SVGImageContext& mSVGContext;
const uint32_t mWhichFrame;
const uint32_t mFlags;
ImgDrawResult mDrawResult;
Expand Down Expand Up @@ -223,8 +217,8 @@ NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
ClippedImage::GetFrame(uint32_t aWhichFrame, uint32_t aFlags) {
ImgDrawResult result;
RefPtr<SourceSurface> surface;
Tie(result, surface) = GetFrameInternal(mClip.Size(), Nothing(), Nothing(),
aWhichFrame, aFlags, 1.0);
Tie(result, surface) = GetFrameInternal(mClip.Size(), SVGImageContext(),
Nothing(), aWhichFrame, aFlags, 1.0);
return surface.forget();
}

Expand All @@ -237,7 +231,7 @@ ClippedImage::GetFrameAtSize(const IntSize& aSize, uint32_t aWhichFrame,
}

std::pair<ImgDrawResult, RefPtr<SourceSurface>> ClippedImage::GetFrameInternal(
const nsIntSize& aSize, const Maybe<SVGImageContext>& aSVGContext,
const nsIntSize& aSize, const SVGImageContext& aSVGContext,
const Maybe<ImageIntRegion>& aRegion, uint32_t aWhichFrame, uint32_t aFlags,
float aOpacity) {
if (!ShouldClip()) {
Expand Down Expand Up @@ -300,7 +294,7 @@ ClippedImage::IsImageContainerAvailable(WindowRenderer* aRenderer,
NS_IMETHODIMP_(ImgDrawResult)
ClippedImage::GetImageProvider(WindowRenderer* aRenderer,
const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const SVGImageContext& aSVGContext,
const Maybe<ImageIntRegion>& aRegion,
uint32_t aFlags,
WebRenderImageProvider** aProvider) {
Expand Down Expand Up @@ -333,7 +327,7 @@ NS_IMETHODIMP_(ImgDrawResult)
ClippedImage::Draw(gfxContext* aContext, const nsIntSize& aSize,
const ImageRegion& aRegion, uint32_t aWhichFrame,
SamplingFilter aSamplingFilter,
const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
const SVGImageContext& aSVGContext, uint32_t aFlags,
float aOpacity) {
if (!ShouldClip()) {
return InnerImage()->Draw(aContext, aSize, aRegion, aWhichFrame,
Expand Down Expand Up @@ -373,8 +367,7 @@ ClippedImage::Draw(gfxContext* aContext, const nsIntSize& aSize,
ImgDrawResult ClippedImage::DrawSingleTile(
gfxContext* aContext, const nsIntSize& aSize, const ImageRegion& aRegion,
uint32_t aWhichFrame, SamplingFilter aSamplingFilter,
const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
float aOpacity) {
const SVGImageContext& aSVGContext, uint32_t aFlags, float aOpacity) {
MOZ_ASSERT(!MustCreateSurface(aContext, aSize, aRegion, aFlags),
"Shouldn't need to create a surface");

Expand Down Expand Up @@ -431,7 +424,7 @@ ImgDrawResult ClippedImage::DrawSingleTile(
};

return InnerImage()->Draw(aContext, size, region, aWhichFrame,
aSamplingFilter, aSVGContext.map(unclipViewport),
aSamplingFilter, unclipViewport(aSVGContext),
aFlags, aOpacity);
}

Expand Down
8 changes: 4 additions & 4 deletions image/ClippedImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ class ClippedImage : public ImageWrapper {
uint32_t aFlags) override;
NS_IMETHOD_(ImgDrawResult)
GetImageProvider(WindowRenderer* aRenderer, const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const 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,
const SVGImageContext& aSVGContext, uint32_t aFlags,
float aOpacity) override;
NS_IMETHOD RequestDiscard() override;
NS_IMETHOD_(Orientation) GetOrientation() override;
Expand All @@ -71,14 +71,14 @@ class ClippedImage : public ImageWrapper {

private:
std::pair<ImgDrawResult, RefPtr<SourceSurface>> GetFrameInternal(
const nsIntSize& aSize, const Maybe<SVGImageContext>& aSVGContext,
const nsIntSize& aSize, const SVGImageContext& aSVGContext,
const Maybe<ImageIntRegion>& aRegion, uint32_t aWhichFrame,
uint32_t aFlags, float aOpacity);
bool ShouldClip();
ImgDrawResult DrawSingleTile(gfxContext* aContext, const nsIntSize& aSize,
const ImageRegion& aRegion, uint32_t aWhichFrame,
gfx::SamplingFilter aSamplingFilter,
const Maybe<SVGImageContext>& aSVGContext,
const SVGImageContext& aSVGContext,
uint32_t aFlags, float aOpacity);

// If we are forced to draw a temporary surface, we cache it here.
Expand Down
13 changes: 5 additions & 8 deletions image/DynamicImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@

using namespace mozilla;
using namespace mozilla::gfx;
using mozilla::layers::ImageContainer;

namespace mozilla {
namespace image {
namespace mozilla::image {

// Inherited methods from Image.

Expand Down Expand Up @@ -156,7 +154,7 @@ DynamicImage::GetFrameAtSize(const IntSize& aSize, uint32_t aWhichFrame,
MOZ_ASSERT(context); // already checked the draw target above

auto result = Draw(context, aSize, ImageRegion::Create(aSize), aWhichFrame,
SamplingFilter::POINT, Nothing(), aFlags, 1.0);
SamplingFilter::POINT, SVGImageContext(), aFlags, 1.0);

return result == ImgDrawResult::SUCCESS ? dt->Snapshot() : nullptr;
}
Expand All @@ -173,7 +171,7 @@ DynamicImage::IsImageContainerAvailable(WindowRenderer* aRenderer,
NS_IMETHODIMP_(ImgDrawResult)
DynamicImage::GetImageProvider(WindowRenderer* aRenderer,
const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const SVGImageContext& aSVGContext,
const Maybe<ImageIntRegion>& aRegion,
uint32_t aFlags,
WebRenderImageProvider** aProvider) {
Expand All @@ -184,7 +182,7 @@ NS_IMETHODIMP_(ImgDrawResult)
DynamicImage::Draw(gfxContext* aContext, const nsIntSize& aSize,
const ImageRegion& aRegion, uint32_t aWhichFrame,
SamplingFilter aSamplingFilter,
const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
const SVGImageContext& aSVGContext, uint32_t aFlags,
float aOpacity) {
MOZ_ASSERT(!aSize.IsEmpty(), "Unexpected empty size");

Expand Down Expand Up @@ -298,5 +296,4 @@ nsresult DynamicImage::GetHotspotY(int32_t* aY) {
return Image::GetHotspotY(aY);
}

} // namespace image
} // namespace mozilla
} // namespace mozilla::image
4 changes: 2 additions & 2 deletions image/FrozenImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ FrozenImage::IsImageContainerAvailable(WindowRenderer* aRenderer,
NS_IMETHODIMP_(ImgDrawResult)
FrozenImage::GetImageProvider(WindowRenderer* aRenderer,
const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const SVGImageContext& aSVGContext,
const Maybe<ImageIntRegion>& aRegion,
uint32_t aFlags,
WebRenderImageProvider** aProvider) {
Expand All @@ -84,7 +84,7 @@ FrozenImage::Draw(gfxContext* aContext, const nsIntSize& aSize,
const ImageRegion& aRegion,
uint32_t /* aWhichFrame - ignored */,
SamplingFilter aSamplingFilter,
const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
const SVGImageContext& aSVGContext, uint32_t aFlags,
float aOpacity) {
return InnerImage()->Draw(aContext, aSize, aRegion, FRAME_FIRST,
aSamplingFilter, aSVGContext, aFlags, aOpacity);
Expand Down
4 changes: 2 additions & 2 deletions image/FrozenImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class FrozenImage : public ImageWrapper {
uint32_t aFlags) override;
NS_IMETHOD_(ImgDrawResult)
GetImageProvider(WindowRenderer* aRenderer, const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const 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,
const SVGImageContext& aSVGContext, uint32_t aFlags,
float aOpacity) override;
NS_IMETHOD StartDecoding(uint32_t aFlags, uint32_t aWhichFrame) override;
NS_IMETHOD_(bool)
Expand Down
4 changes: 2 additions & 2 deletions image/ImageWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ ImageWrapper::IsImageContainerAvailable(WindowRenderer* aRenderer,
NS_IMETHODIMP_(ImgDrawResult)
ImageWrapper::GetImageProvider(WindowRenderer* aRenderer,
const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const SVGImageContext& aSVGContext,
const Maybe<ImageIntRegion>& aRegion,
uint32_t aFlags,
WebRenderImageProvider** aProvider) {
Expand All @@ -185,7 +185,7 @@ NS_IMETHODIMP_(ImgDrawResult)
ImageWrapper::Draw(gfxContext* aContext, const nsIntSize& aSize,
const ImageRegion& aRegion, uint32_t aWhichFrame,
SamplingFilter aSamplingFilter,
const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
const SVGImageContext& aSVGContext, uint32_t aFlags,
float aOpacity) {
return mInnerImage->Draw(aContext, aSize, aRegion, aWhichFrame,
aSamplingFilter, aSVGContext, aFlags, aOpacity);
Expand Down
7 changes: 3 additions & 4 deletions image/OrientedImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ using std::swap;
namespace mozilla {

using namespace gfx;
using layers::ImageContainer;

namespace image {

Expand Down Expand Up @@ -158,7 +157,7 @@ OrientedImage::IsImageContainerAvailable(WindowRenderer* aRenderer,
NS_IMETHODIMP_(ImgDrawResult)
OrientedImage::GetImageProvider(WindowRenderer* aRenderer,
const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const SVGImageContext& aSVGContext,
const Maybe<ImageIntRegion>& aRegion,
uint32_t aFlags,
WebRenderImageProvider** aProvider) {
Expand Down Expand Up @@ -262,7 +261,7 @@ NS_IMETHODIMP_(ImgDrawResult)
OrientedImage::Draw(gfxContext* aContext, const nsIntSize& aSize,
const ImageRegion& aRegion, uint32_t aWhichFrame,
SamplingFilter aSamplingFilter,
const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
const SVGImageContext& aSVGContext, uint32_t aFlags,
float aOpacity) {
if (mOrientation.IsIdentity()) {
return InnerImage()->Draw(aContext, aSize, aRegion, aWhichFrame,
Expand Down Expand Up @@ -301,7 +300,7 @@ OrientedImage::Draw(gfxContext* aContext, const nsIntSize& aSize,
};

return InnerImage()->Draw(aContext, size, region, aWhichFrame,
aSamplingFilter, aSVGContext.map(orientViewport),
aSamplingFilter, orientViewport(aSVGContext),
aFlags, aOpacity);
}

Expand Down
4 changes: 2 additions & 2 deletions image/OrientedImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class OrientedImage : public ImageWrapper {
uint32_t aFlags) override;
NS_IMETHOD_(ImgDrawResult)
GetImageProvider(WindowRenderer* aRenderer, const gfx::IntSize& aSize,
const Maybe<SVGImageContext>& aSVGContext,
const 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,
const SVGImageContext& aSVGContext, uint32_t aFlags,
float aOpacity) override;
NS_IMETHOD_(nsIntRect)
GetImageSpaceInvalidationRect(const nsIntRect& aRect) override;
Expand Down
Loading

0 comments on commit 4414d74

Please sign in to comment.