Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit c94d4d3

Browse files
committed
Bug 1366097 - Part 3. Implement VectorImage::GetImageContainerAtSize and VectorImage::IsImageContainerAvailableAtSize. r=tnikkel
This is largely trivial because the meat of the implementation is located in ImageResource and we already added GetFrameInternal. Interestingly VectorImage::IsUnlocked does not actually check if the image is locked, but instead only checks for animation consumers. This is consistent with its historical behavior on when to issue an unlocked draw event. Note that we do not implement the original GetImageContainer and IsImageContainerAvailable APIs. This is because the former does not accept an SVG context and it would be best to discourage its use in old code lest we get incorrect/unexpected results.
1 parent e4a6ddc commit c94d4d3

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

image/VectorImage.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "mozilla/MemoryReporting.h"
1616
#include "mozilla/dom/SVGSVGElement.h"
1717
#include "mozilla/gfx/2D.h"
18+
#include "mozilla/gfx/gfxVars.h"
1819
#include "mozilla/RefPtr.h"
1920
#include "mozilla/Tuple.h"
2021
#include "nsIDOMEvent.h"
@@ -583,6 +584,8 @@ VectorImage::SendInvalidationNotifications()
583584
mProgressTracker->SyncNotifyProgress(FLAG_FRAME_COMPLETE,
584585
GetMaxSizedIntRect());
585586
}
587+
588+
UpdateImageContainer();
586589
}
587590

588591
NS_IMETHODIMP_(IntRect)
@@ -801,6 +804,18 @@ VectorImage::GetFrameInternal(const IntSize& aSize,
801804
}
802805

803806
//******************************************************************************
807+
IntSize
808+
VectorImage::GetImageContainerSize(LayerManager* aManager,
809+
const IntSize& aSize,
810+
uint32_t aFlags)
811+
{
812+
if (!IsImageContainerAvailableAtSize(aManager, aSize, aFlags)) {
813+
return IntSize(0, 0);
814+
}
815+
816+
return aSize;
817+
}
818+
804819
NS_IMETHODIMP_(bool)
805820
VectorImage::IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags)
806821
{
@@ -820,7 +835,14 @@ VectorImage::IsImageContainerAvailableAtSize(LayerManager* aManager,
820835
const IntSize& aSize,
821836
uint32_t aFlags)
822837
{
823-
return false;
838+
if (mError || !mIsFullyLoaded || aSize.IsEmpty() ||
839+
mHaveAnimations || !gfxVars::UseWebRender()) {
840+
return false;
841+
}
842+
843+
int32_t maxTextureSize = aManager->GetMaxTextureSize();
844+
return aSize.width <= maxTextureSize &&
845+
aSize.height <= maxTextureSize;
824846
}
825847

826848
//******************************************************************************
@@ -829,7 +851,10 @@ VectorImage::GetImageContainerAtSize(LayerManager* aManager,
829851
const IntSize& aSize,
830852
uint32_t aFlags)
831853
{
832-
return nullptr;
854+
// Since we do not support high quality scaling with SVG, we mask it off so
855+
// that container requests with and without it map to the same container.
856+
uint32_t flags = aFlags & ~FLAG_HIGH_QUALITY_SCALING;
857+
return GetImageContainerImpl(aManager, aSize, aFlags);
833858
}
834859

835860
//******************************************************************************

image/VectorImage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ class VectorImage final : public ImageResource,
8686
uint32_t aWhichFrame,
8787
uint32_t aFlags) override;
8888

89+
IntSize GetImageContainerSize(layers::LayerManager* aManager,
90+
const IntSize& aSize,
91+
uint32_t aFlags) override;
92+
8993
/// Attempt to find a matching cached surface in the SurfaceCache.
9094
already_AddRefed<SourceSurface>
9195
LookupCachedSurface(const IntSize& aSize,

0 commit comments

Comments
 (0)