Index: sky/engine/core/rendering/InlineTextBox.cpp |
diff --git a/sky/engine/core/rendering/InlineTextBox.cpp b/sky/engine/core/rendering/InlineTextBox.cpp |
index cb54daf7618fe099146e88cf69cf17f5237a52f5..0141af6a88181a92cbe157062127f549bd75f6dd 100644 |
--- a/sky/engine/core/rendering/InlineTextBox.cpp |
+++ b/sky/engine/core/rendering/InlineTextBox.cpp |
@@ -64,12 +64,17 @@ COMPILE_ASSERT(sizeof(InlineTextBox) == sizeof(SameSizeAsInlineTextBox), InlineT |
typedef WTF::HashMap<const InlineTextBox*, LayoutRect> InlineTextBoxOverflowMap; |
static InlineTextBoxOverflowMap* gTextBoxesWithOverflow; |
+typedef WTF::HashMap<const InlineTextBox*, TextBlobPtr> InlineTextBoxBlobCacheMap; |
+static InlineTextBoxBlobCacheMap* gTextBlobCache; |
esprehn
2015/01/21 09:58:57
Lets just add a ptr to InlineTextBox. I don't know
abarth-chromium
2015/01/21 19:30:35
It was part of the first CL. I think they were wo
|
+ |
static const int misspellingLineThickness = 3; |
void InlineTextBox::destroy() |
{ |
if (!knownToHaveNoOverflow() && gTextBoxesWithOverflow) |
gTextBoxesWithOverflow->remove(this); |
+ if (gTextBlobCache) |
+ gTextBlobCache->remove(this); |
InlineBox::destroy(); |
} |
@@ -416,13 +421,16 @@ void paintText(GraphicsContext* context, |
const Font& font, const TextRun& textRun, |
const AtomicString& emphasisMark, int emphasisMarkOffset, |
int startOffset, int endOffset, int truncationPoint, |
- const FloatPoint& textOrigin, const FloatRect& boxRect) |
+ const FloatPoint& textOrigin, const FloatRect& boxRect, |
+ TextBlobPtr* cachedTextBlob = 0) |
{ |
TextRunPaintInfo textRunPaintInfo(textRun); |
textRunPaintInfo.bounds = boxRect; |
if (startOffset <= endOffset) { |
textRunPaintInfo.from = startOffset; |
textRunPaintInfo.to = endOffset; |
+ // FIXME: We should be able to use cachedTextBlob in more cases. |
+ textRunPaintInfo.cachedTextBlob = cachedTextBlob; |
if (emphasisMark.isEmpty()) |
context->drawText(font, textRunPaintInfo, textOrigin); |
else |
@@ -460,11 +468,11 @@ inline void paintEmphasisMark(GraphicsContext* context, |
void paintTextWithEmphasisMark( |
GraphicsContext* context, const Font& font, const TextPaintingStyle& textStyle, const TextRun& textRun, |
const AtomicString& emphasisMark, int emphasisMarkOffset, int startOffset, int endOffset, int length, |
- const FloatPoint& textOrigin, const FloatRect& boxRect) |
+ const FloatPoint& textOrigin, const FloatRect& boxRect, TextBlobPtr* cachedTextBlob = 0) |
{ |
GraphicsContextStateSaver stateSaver(*context, false); |
updateGraphicsContext(context, textStyle, stateSaver); |
- paintText(context, font, textRun, nullAtom, 0, startOffset, endOffset, length, textOrigin, boxRect); |
+ paintText(context, font, textRun, nullAtom, 0, startOffset, endOffset, length, textOrigin, boxRect, cachedTextBlob); |
if (!emphasisMark.isEmpty()) { |
if (textStyle.emphasisMarkColor != textStyle.fillColor) |
@@ -473,6 +481,13 @@ void paintTextWithEmphasisMark( |
} |
} |
+TextBlobPtr* addToTextBlobCache(InlineTextBox& inlineTextBox) |
+{ |
+ if (!gTextBlobCache) |
+ gTextBlobCache = new InlineTextBoxBlobCacheMap; |
+ return &gTextBlobCache->add(&inlineTextBox, nullptr).storedValue->value; |
+} |
+ |
} // namespace |
void InlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit /*lineTop*/, LayoutUnit /*lineBottom*/) |
@@ -603,12 +618,23 @@ void InlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, |
startOffset = ePos; |
endOffset = sPos; |
} |
- paintTextWithEmphasisMark(context, font, textStyle, textRun, emphasisMark, emphasisMarkOffset, startOffset, endOffset, length, textOrigin, boxRect); |
+ // FIXME: This cache should probably ultimately be held somewhere else. |
+ // A hashmap is convenient to avoid a memory hit when the |
+ // RuntimeEnabledFeature is off. |
+ bool textBlobIsCacheable = RuntimeEnabledFeatures::textBlobEnabled() && startOffset == 0 && endOffset == length; |
+ TextBlobPtr* cachedTextBlob = 0; |
+ if (textBlobIsCacheable) |
+ cachedTextBlob = addToTextBlobCache(*this); |
+ paintTextWithEmphasisMark(context, font, textStyle, textRun, emphasisMark, emphasisMarkOffset, startOffset, endOffset, length, textOrigin, boxRect, cachedTextBlob); |
} |
if ((paintSelectedTextOnly || paintSelectedTextSeparately) && sPos < ePos) { |
// paint only the text that is selected |
- paintTextWithEmphasisMark(context, font, selectionStyle, textRun, emphasisMark, emphasisMarkOffset, sPos, ePos, length, textOrigin, boxRect); |
+ bool textBlobIsCacheable = RuntimeEnabledFeatures::textBlobEnabled() && sPos == 0 && ePos == length; |
+ TextBlobPtr* cachedTextBlob = 0; |
+ if (textBlobIsCacheable) |
+ cachedTextBlob = addToTextBlobCache(*this); |
+ paintTextWithEmphasisMark(context, font, selectionStyle, textRun, emphasisMark, emphasisMarkOffset, sPos, ePos, length, textOrigin, boxRect, cachedTextBlob); |
} |
// Paint decorations |