Bug 1564526 - Remove CachedBorderImageData. r=tnikkel

See comments in the bug, which still stand.

This cache is barely hit, and when it is hit it causes correctness
issues, see bug 1815022 for a recent example.

Differential Revision: https://phabricator.services.mozilla.com/D171391
This commit is contained in:
Emilio Cobos Álvarez 2023-03-08 12:04:03 +00:00
Родитель fa402eb899
Коммит b5ab8c533c
7 изменённых файлов: 1 добавлений и 94 удалений

Просмотреть файл

@ -1369,7 +1369,6 @@ void nsIFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) {
if (oldBorderImage != newBorderImage) {
// stop and restart the image loading/notification
if (oldBorderImage && HasImageRequest()) {
RemoveProperty(CachedBorderImageDataProperty());
loader->DisassociateRequestFromFrame(oldBorderImage, this);
}
if (newBorderImage) {

Просмотреть файл

@ -1257,9 +1257,6 @@ class nsIFrame : public nsQueryFrame {
NS_DECLARE_FRAME_PROPERTY_DELETABLE(PreTransformOverflowAreasProperty,
mozilla::OverflowAreas)
NS_DECLARE_FRAME_PROPERTY_DELETABLE(CachedBorderImageDataProperty,
CachedBorderImageData)
NS_DECLARE_FRAME_PROPERTY_DELETABLE(OverflowAreasProperty,
mozilla::OverflowAreas)

Просмотреть файл

@ -3429,8 +3429,6 @@ ImgDrawResult nsCSSBorderImageRenderer::DrawBorderImage(
Maybe<nsSize> svgViewportSize =
intrinsicSize.CanComputeConcreteSize() ? Nothing() : Some(mImageSize);
bool hasIntrinsicRatio = intrinsicSize.HasRatio();
mImageRenderer.PurgeCacheForViewportChange(svgViewportSize,
hasIntrinsicRatio);
// These helper tables recharacterize the 'slice' and 'width' margins
// in a more convenient form: they are the x/y/width/height coords

Просмотреть файл

@ -927,17 +927,7 @@ ImgDrawResult nsImageRenderer::DrawBorderImageComponent(
// Retrieve or create the subimage we'll draw.
nsIntRect srcRect(aSrc.x, aSrc.y, aSrc.width, aSrc.height);
if (isRequestBacked) {
CachedBorderImageData* cachedData =
mForFrame->GetProperty(nsIFrame::CachedBorderImageDataProperty());
if (!cachedData) {
cachedData = new CachedBorderImageData();
mForFrame->AddProperty(nsIFrame::CachedBorderImageDataProperty(),
cachedData);
}
if (!(subImage = cachedData->GetSubImage(aIndex))) {
subImage = ImageOps::Clip(mImageContainer, srcRect, aSVGViewportSize);
cachedData->SetSubImage(aIndex, subImage);
}
subImage = ImageOps::Clip(mImageContainer, srcRect, aSVGViewportSize);
} else {
// This path, for eStyleImageType_Element, is currently slower than it
// needs to be because we don't cache anything. (In particular, if we have
@ -1060,17 +1050,3 @@ bool nsImageRenderer::IsRasterImage() {
already_AddRefed<imgIContainer> nsImageRenderer::GetImage() {
return do_AddRef(mImageContainer);
}
void nsImageRenderer::PurgeCacheForViewportChange(
const Maybe<nsSize>& aSVGViewportSize, const bool aHasIntrinsicRatio) {
// Check if we should flush the cached data - only vector images need to do
// the check since they might not have fixed ratio.
if (mImageContainer &&
mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) {
if (auto* cachedData =
mForFrame->GetProperty(nsIFrame::CachedBorderImageDataProperty())) {
cachedData->PurgeCacheForViewportChange(aSVGViewportSize,
aHasIntrinsicRatio);
}
}
}

Просмотреть файл

@ -248,8 +248,6 @@ class nsImageRenderer {
ImgDrawResult PrepareResult() const { return mPrepareResult; }
void SetExtendMode(mozilla::gfx::ExtendMode aMode) { mExtendMode = aMode; }
void SetMaskOp(mozilla::StyleMaskMode aMaskOp) { mMaskOp = aMaskOp; }
void PurgeCacheForViewportChange(
const mozilla::Maybe<nsSize>& aSVGViewportSize, const bool aHasRatio);
const nsSize& GetSize() const { return mSize; }
mozilla::StyleImage::Tag GetType() const { return mType; }
const mozilla::StyleGradient* GetGradientData() const {

Просмотреть файл

@ -1452,29 +1452,6 @@ bool StyleGradient::IsOpaque() const {
return GradientItemsAreOpaque(AsConic().items.AsSpan());
}
// --------------------
// CachedBorderImageData
void CachedBorderImageData::PurgeCachedImages() {
MOZ_ASSERT(!ServoStyleSet::IsInServoTraversal());
MOZ_ASSERT(NS_IsMainThread());
mSubImages.Clear();
}
void CachedBorderImageData::PurgeCacheForViewportChange(
const Maybe<nsSize>& aSize, const bool aHasIntrinsicRatio) {
// If we're redrawing with a different viewport-size than we used for our
// cached subimages, then we can't trust that our subimages are valid;
// any percent sizes/positions in our SVG doc may be different now. Purge!
// (We don't have to purge if the SVG document has an intrinsic ratio,
// though, because the actual size of elements in SVG documant's coordinate
// axis are fixed in this case.)
if (aSize != mCachedSVGViewportSize && !aHasIntrinsicRatio) {
PurgeCachedImages();
SetCachedSVGViewportSize(aSize);
}
}
static int32_t ConvertToPixelCoord(const StyleNumberOrPercentage& aCoord,
int32_t aPercentScale) {
double pixelValue;

Просмотреть файл

@ -162,44 +162,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleFont {
RefPtr<nsAtom> mLanguage;
};
// TODO(emilio, bug 1564526): Evaluate whether this is still needed.
struct CachedBorderImageData {
~CachedBorderImageData() { PurgeCachedImages(); }
// Caller are expected to ensure that the value of aSize is different from the
// cached one since the method won't do the check.
void SetCachedSVGViewportSize(const mozilla::Maybe<nsSize>& aSize) {
mCachedSVGViewportSize = aSize;
}
const mozilla::Maybe<nsSize>& GetCachedSVGViewportSize() const {
return mCachedSVGViewportSize;
}
void PurgeCachedImages();
void SetSubImage(uint8_t aIndex, imgIContainer* aSubImage) {
mSubImages.EnsureLengthAtLeast(aIndex + 1);
mSubImages[aIndex] = aSubImage;
}
imgIContainer* GetSubImage(uint8_t aIndex) {
return mSubImages.SafeElementAt(aIndex);
}
// These methods are used for the caller to caches the sub images created
// during a border-image paint operation
void PurgeCacheForViewportChange(
const mozilla::Maybe<nsSize>& aSVGViewportSize,
const bool aHasIntrinsicRatio);
private:
// If this is a SVG border-image, we save the size of the SVG viewport that
// we used when rasterizing any cached border-image subimages. (The viewport
// size matters for percent-valued sizes & positions in inner SVG doc).
mozilla::Maybe<nsSize> mCachedSVGViewportSize;
nsTArray<RefPtr<imgIContainer>> mSubImages;
};
struct nsStyleImageLayers {
enum class LayerType : uint8_t { Background = 0, Mask };