From 2850db7128d248615a5c1fa767afa92f338b008e Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Thu, 28 Jul 2016 03:12:00 +0200 Subject: [PATCH] Bug 1285320 - (Part 1) Add struct "CachedBorderImageData" to keep cached data for border in nsStyleImage. r=dholbert --HG-- extra : rebase_source : 5c654bd0dab03864ed1e1bf2883525bccea73d8a --- layout/style/nsStyleStruct.cpp | 28 +++++++++++++++++++++++++++- layout/style/nsStyleStruct.h | 17 +++++++++++++++-- layout/style/nsStyleStructInlines.h | 17 ++++++++++++----- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index e68f9fe11443..7b8ce971f799 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -1909,6 +1909,30 @@ nsStyleGradient::HasCalc() mRadiusX.IsCalcUnit() || mRadiusY.IsCalcUnit(); } +// -------------------- +// CachedBorderImageData +// +void +CachedBorderImageData::PurgeCachedImages() +{ + mSubImages.Clear(); +} + +void +CachedBorderImageData::SetSubImage(uint8_t aIndex, imgIContainer* aSubImage) +{ + mSubImages.ReplaceObjectAt(aSubImage, aIndex); +} + +imgIContainer* +CachedBorderImageData::GetSubImage(uint8_t aIndex) +{ + imgIContainer* subImage = nullptr; + if (aIndex < mSubImages.Count()) + subImage = mSubImages[aIndex]; + return subImage; +} + // -------------------- // nsStyleImage // @@ -2004,7 +2028,9 @@ nsStyleImage::SetImageData(imgRequestProxy* aImage) mImage = aImage; mType = eStyleImageType_Image; } - mSubImages.Clear(); + if (mCachedBIData) { + mCachedBIData->PurgeCachedImages(); + } } void diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index 31cd677feabb..cd479f0460f3 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -18,6 +18,7 @@ #include "mozilla/SheetType.h" #include "mozilla/StaticPtr.h" #include "mozilla/StyleStructContext.h" +#include "mozilla/UniquePtr.h" #include "nsAutoPtr.h" #include "nsColor.h" #include "nsCoord.h" @@ -246,6 +247,16 @@ enum nsStyleImageType { eStyleImageType_Element }; +struct CachedBorderImageData +{ + void PurgeCachedImages(); + void SetSubImage(uint8_t aIndex, imgIContainer* aSubImage); + imgIContainer* GetSubImage(uint8_t aIndex); + +private: + nsCOMArray mSubImages; +}; + /** * Represents a paintable image of one of the following types. * (1) A real image loaded from an external source. @@ -361,9 +372,11 @@ struct nsStyleImage private: void DoCopy(const nsStyleImage& aOther); + void EnsureCachedBIData() const; - // Cache for border-image painting. - nsCOMArray mSubImages; + // This variable keeps some cache data for border image and is lazily + // allocated since it is only used in border image case. + mozilla::UniquePtr mCachedBIData; nsStyleImageType mType; union { diff --git a/layout/style/nsStyleStructInlines.h b/layout/style/nsStyleStructInlines.h index 367a2b21221f..a51c6a78c0b4 100644 --- a/layout/style/nsStyleStructInlines.h +++ b/layout/style/nsStyleStructInlines.h @@ -16,19 +16,26 @@ #include "nsIContent.h" // for GetParent() #include "nsTextFrame.h" // for nsTextFrame::ShouldSuppressLineBreak +inline void +nsStyleImage::EnsureCachedBIData() const +{ + if (!mCachedBIData) { + const_cast(this)->mCachedBIData = + mozilla::MakeUnique(); + } +} + inline void nsStyleImage::SetSubImage(uint8_t aIndex, imgIContainer* aSubImage) const { - const_cast(this)->mSubImages.ReplaceObjectAt(aSubImage, aIndex); + EnsureCachedBIData(); + mCachedBIData->SetSubImage(aIndex, aSubImage); } inline imgIContainer* nsStyleImage::GetSubImage(uint8_t aIndex) const { - imgIContainer* subImage = nullptr; - if (aIndex < mSubImages.Count()) - subImage = mSubImages[aIndex]; - return subImage; + return (mCachedBIData) ? mCachedBIData->GetSubImage(aIndex) : nullptr; } bool