Skip to content

Commit 30b7809

Browse files
committed
Bug 1991689 - Cache a PropertyProvider in SVGTextFrame so that we don't have to create a fresh one for every call to the same textframe. r=firefox-svg-reviewers,longsonr
Differential Revision: https://phabricator.services.mozilla.com/D267440 UltraBlame original commit: c4911116c376f35cf2790bd69d861e1e418e9ab1
1 parent f282b6b commit 30b7809

File tree

3 files changed

+47
-17
lines changed

3 files changed

+47
-17
lines changed

layout/generic/nsTextFrame.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ class nsTextFrame : public nsIFrame {
113113

114114

115115

116-
class MOZ_STACK_CLASS PropertyProvider final
117-
: public gfxTextRun::PropertyProvider {
116+
117+
118+
119+
120+
class PropertyProvider final : public gfxTextRun::PropertyProvider {
118121
using HyphenType = gfxTextRun::HyphenType;
119122

120123
public:

layout/svg/SVGTextFrame.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,6 @@ SVGBBox TextRenderedRun::GetRunUserSpaceRect(nsPresContext* aContext,
835835
vertical ? -self.y : -self.x);
836836

837837
gfxSkipCharsIterator it = mFrame->EnsureTextRun(nsTextFrame::eInflated);
838-
gfxSkipCharsIterator start = it;
839838
gfxTextRun* textRun = mFrame->GetTextRun(nsTextFrame::eInflated);
840839

841840

@@ -845,10 +844,7 @@ SVGBBox TextRenderedRun::GetRunUserSpaceRect(nsPresContext* aContext,
845844
return r;
846845
}
847846

848-
849-
850-
851-
nsTextFrame::PropertyProvider provider(mFrame, start);
847+
auto& provider = mRoot->PropertyProviderFor(mFrame);
852848

853849

854850
gfxTextRun::Metrics metrics = textRun->MeasureText(
@@ -946,7 +942,7 @@ void TextRenderedRun::GetClipEdges(nscoord& aVisIStartEdge,
946942

947943
gfxSkipCharsIterator it = mFrame->EnsureTextRun(nsTextFrame::eInflated);
948944
gfxTextRun* textRun = mFrame->GetTextRun(nsTextFrame::eInflated);
949-
nsTextFrame::PropertyProvider provider(mFrame, it);
945+
auto& provider = mRoot->PropertyProviderFor(mFrame);
950946

951947

952948

@@ -1038,7 +1034,7 @@ void TextRenderedRun::GetClipEdges(nscoord& aVisIStartEdge,
10381034
nscoord TextRenderedRun::GetAdvanceWidth() const {
10391035
gfxSkipCharsIterator it = mFrame->EnsureTextRun(nsTextFrame::eInflated);
10401036
gfxTextRun* textRun = mFrame->GetTextRun(nsTextFrame::eInflated);
1041-
nsTextFrame::PropertyProvider provider(mFrame, it);
1037+
auto& provider = mRoot->PropertyProviderFor(mFrame);
10421038

10431039
Range range = ConvertOriginalToSkipped(it, mTextFrameContentOffset,
10441040
mTextFrameContentLength);
@@ -1088,7 +1084,7 @@ int32_t TextRenderedRun::GetCharNumAtPosition(nsPresContext* aContext,
10881084

10891085
gfxSkipCharsIterator it = mFrame->EnsureTextRun(nsTextFrame::eInflated);
10901086
gfxTextRun* textRun = mFrame->GetTextRun(nsTextFrame::eInflated);
1091-
nsTextFrame::PropertyProvider provider(mFrame, it);
1087+
auto& provider = mRoot->PropertyProviderFor(mFrame);
10921088

10931089

10941090

@@ -1789,6 +1785,11 @@ class TextRenderedRunIterator {
17891785

17901786

17911787

1788+
~TextRenderedRunIterator() { mFrameIterator.Root()->ForgetCachedProvider(); }
1789+
1790+
1791+
1792+
17921793
TextRenderedRun Current() const { return mCurrent; }
17931794

17941795

@@ -2018,6 +2019,11 @@ class MOZ_STACK_CLASS CharIterator {
20182019

20192020

20202021

2022+
~CharIterator() { mFrameIterator.Root()->ForgetCachedProvider(); }
2023+
2024+
2025+
2026+
20212027
bool AtEnd() const { return !mFrameIterator.Current(); }
20222028

20232029

@@ -2374,10 +2380,7 @@ gfxFloat CharIterator::GetAdvance(nsPresContext* aContext) const {
23742380
float cssPxPerDevPx =
23752381
nsPresContext::AppUnitsToFloatCSSPixels(aContext->AppUnitsPerDevPixel());
23762382

2377-
gfxSkipCharsIterator start =
2378-
TextFrame()->EnsureTextRun(nsTextFrame::eInflated);
2379-
nsTextFrame::PropertyProvider provider(TextFrame(), start);
2380-
2383+
auto& provider = mFrameIterator.Root()->PropertyProviderFor(TextFrame());
23812384
uint32_t offset = mSkipCharsIterator.GetSkippedOffset();
23822385
gfxFloat advance =
23832386
mTextRun->GetAdvanceWidth(Range(offset, offset + 1), &provider);
@@ -3733,7 +3736,7 @@ float SVGTextFrame::GetSubStringLengthFastPath(nsIContent* aContent,
37333736

37343737
gfxSkipCharsIterator it = frame->EnsureTextRun(nsTextFrame::eInflated);
37353738
gfxTextRun* textRun = frame->GetTextRun(nsTextFrame::eInflated);
3736-
nsTextFrame::PropertyProvider provider(frame, it);
3739+
auto& provider = PropertyProviderFor(frame);
37373740

37383741
Range range = ConvertOriginalToSkipped(it, offset, trimmedLength);
37393742

@@ -3801,7 +3804,7 @@ float SVGTextFrame::GetSubStringLengthSlowFallback(nsIContent* aContent,
38013804
gfxSkipCharsIterator it =
38023805
run.mFrame->EnsureTextRun(nsTextFrame::eInflated);
38033806
gfxTextRun* textRun = run.mFrame->GetTextRun(nsTextFrame::eInflated);
3804-
nsTextFrame::PropertyProvider provider(run.mFrame, it);
3807+
auto& provider = PropertyProviderFor(run.mFrame);
38053808

38063809
Range range = ConvertOriginalToSkipped(it, offset, length);
38073810

@@ -4356,7 +4359,7 @@ void SVGTextFrame::DetermineCharPositions(nsTArray<nsPoint>& aPositions) {
43564359
for (nsTextFrame* frame = frit.Current(); frame; frame = frit.Next()) {
43574360
gfxSkipCharsIterator it = frame->EnsureTextRun(nsTextFrame::eInflated);
43584361
gfxTextRun* textRun = frame->GetTextRun(nsTextFrame::eInflated);
4359-
nsTextFrame::PropertyProvider provider(frame, it);
4362+
auto& provider = PropertyProviderFor(frame);
43604363

43614364

43624365
position = frit.Position();
@@ -4410,6 +4413,10 @@ void SVGTextFrame::DetermineCharPositions(nsTArray<nsPoint>& aPositions) {
44104413
for (uint32_t i = 0; i < frit.UndisplayedCharacters(); i++) {
44114414
aPositions.AppendElement(position);
44124415
}
4416+
4417+
4418+
4419+
ForgetCachedProvider();
44134420
}
44144421

44154422

layout/svg/SVGTextFrame.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "gfxRect.h"
1212
#include "gfxTextRun.h"
1313
#include "mozilla/Attributes.h"
14+
#include "mozilla/Maybe.h"
1415
#include "mozilla/PresShellForwards.h"
1516
#include "mozilla/RefPtr.h"
1617
#include "mozilla/SVGContainerFrame.h"
@@ -610,9 +611,28 @@ class SVGTextFrame final : public SVGDisplayContainerFrame {
610611
return mCachedRanges[aWhichRange];
611612
}
612613

614+
615+
616+
617+
nsTextFrame::PropertyProvider& PropertyProviderFor(nsTextFrame* aFrame) {
618+
if (!mCachedProvider || aFrame != mCachedProvider->GetFrame()) {
619+
mCachedProvider.reset();
620+
mCachedProvider.emplace(aFrame,
621+
aFrame->EnsureTextRun(nsTextFrame::eInflated));
622+
}
623+
return mCachedProvider.ref();
624+
}
625+
626+
627+
628+
629+
void ForgetCachedProvider() { mCachedProvider.reset(); }
630+
613631
private:
614632
const nsTextFrame* mFrameForCachedRanges = nullptr;
615633
CachedMeasuredRange mCachedRanges[CachedRangeCount];
634+
635+
Maybe<nsTextFrame::PropertyProvider> mCachedProvider;
616636
};
617637

618638
}

0 commit comments

Comments
 (0)