Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1745)

Unified Diff: Source/core/rendering/svg/SVGTextQuery.cpp

Issue 349223003: Optimize SVGTextQuery's character offset ligature adjustment query (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: More explicit invalidation. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/svg/SVGTextQuery.cpp
diff --git a/Source/core/rendering/svg/SVGTextQuery.cpp b/Source/core/rendering/svg/SVGTextQuery.cpp
index f5ead0d43661f2ec0f636f48021b511100a0b748..93d8ea4b7c02b30b31a971abe4ecca7a8b6211f5 100644
--- a/Source/core/rendering/svg/SVGTextQuery.cpp
+++ b/Source/core/rendering/svg/SVGTextQuery.cpp
@@ -38,13 +38,28 @@ struct SVGTextQuery::Data {
, processedCharacters(0)
, textRenderer(0)
, textBox(0)
+ , ligatureAdjustmentLastStartPositionQuery(-1)
+ , ligatureAdjustmentLastEndPositionQuery(-1)
+ , ligatureAdjustmentLastStartPositionResult(-1)
+ , ligatureAdjustmentLastEndPositionResult(-1)
{
}
+ void invalidateLigatureAdjustmentCache()
+ {
+ ligatureAdjustmentLastStartPositionQuery = ligatureAdjustmentLastEndPositionQuery = -1;
+ ligatureAdjustmentLastStartPositionResult = ligatureAdjustmentLastEndPositionResult = -1;
+ }
+
bool isVerticalText;
unsigned processedCharacters;
RenderSVGInlineText* textRenderer;
const SVGInlineTextBox* textBox;
+ // Ligature adjustment cache.
+ int ligatureAdjustmentLastStartPositionQuery;
+ int ligatureAdjustmentLastEndPositionQuery;
+ int ligatureAdjustmentLastStartPositionResult;
+ int ligatureAdjustmentLastEndPositionResult;
};
static inline InlineFlowBox* flowBoxForRenderer(RenderObject* renderer)
@@ -130,6 +145,7 @@ bool SVGTextQuery::executeQuery(Data* queryData, ProcessTextFragmentCallback fra
}
queryData->processedCharacters = processedCharacters;
+ queryData->invalidateLigatureAdjustmentCache();
}
return false;
@@ -156,6 +172,15 @@ bool SVGTextQuery::mapStartEndPositionsIntoFragmentCoordinates(Data* queryData,
void SVGTextQuery::modifyStartEndPositionsRespectingLigatures(Data* queryData, int& startPosition, int& endPosition) const
{
+ if (queryData->ligatureAdjustmentLastStartPositionQuery == startPosition && queryData->ligatureAdjustmentLastEndPositionQuery == endPosition) {
+ startPosition = queryData->ligatureAdjustmentLastStartPositionResult;
+ endPosition = queryData->ligatureAdjustmentLastEndPositionResult;
+ return;
+ }
+
+ queryData->ligatureAdjustmentLastStartPositionQuery = startPosition;
+ queryData->ligatureAdjustmentLastEndPositionQuery = endPosition;
+
SVGTextLayoutAttributes* layoutAttributes = queryData->textRenderer->layoutAttributes();
Vector<SVGTextMetrics>& textMetricsValues = layoutAttributes->textMetricsValues();
unsigned boxStart = queryData->textBox->start();
@@ -212,16 +237,18 @@ void SVGTextQuery::modifyStartEndPositionsRespectingLigatures(Data* queryData, i
positionOffset += metrics.length();
}
- if (!alterStartPosition && !alterEndPosition)
- return;
-
- if (lastPositionOffset != -1 && lastPositionOffset - positionOffset > 1) {
- if (alterStartPosition && startPosition > lastPositionOffset && startPosition < static_cast<int>(positionOffset))
- startPosition = lastPositionOffset;
+ if (alterStartPosition || alterEndPosition) {
+ if (lastPositionOffset != -1 && lastPositionOffset - positionOffset > 1) {
+ if (alterStartPosition && startPosition > lastPositionOffset && startPosition < static_cast<int>(positionOffset))
+ startPosition = lastPositionOffset;
- if (alterEndPosition && endPosition > lastPositionOffset && endPosition < static_cast<int>(positionOffset))
- endPosition = positionOffset;
+ if (alterEndPosition && endPosition > lastPositionOffset && endPosition < static_cast<int>(positionOffset))
+ endPosition = positionOffset;
+ }
}
+
+ queryData->ligatureAdjustmentLastStartPositionResult = startPosition;
+ queryData->ligatureAdjustmentLastEndPositionResult = endPosition;
}
// numberOfCharacters() implementation
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698