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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 20 matching lines...) Expand all
31 31
32 namespace WebCore { 32 namespace WebCore {
33 33
34 // Base structure for callback user data 34 // Base structure for callback user data
35 struct SVGTextQuery::Data { 35 struct SVGTextQuery::Data {
36 Data() 36 Data()
37 : isVerticalText(false) 37 : isVerticalText(false)
38 , processedCharacters(0) 38 , processedCharacters(0)
39 , textRenderer(0) 39 , textRenderer(0)
40 , textBox(0) 40 , textBox(0)
41 , ligatureAdjustmentLastStartPositionQuery(-1)
42 , ligatureAdjustmentLastEndPositionQuery(-1)
43 , ligatureAdjustmentLastStartPositionResult(-1)
44 , ligatureAdjustmentLastEndPositionResult(-1)
41 { 45 {
42 } 46 }
43 47
48 void invalidateLigatureAdjustmentCache()
49 {
50 ligatureAdjustmentLastStartPositionQuery = ligatureAdjustmentLastEndPosi tionQuery = -1;
51 ligatureAdjustmentLastStartPositionResult = ligatureAdjustmentLastEndPos itionResult = -1;
52 }
53
44 bool isVerticalText; 54 bool isVerticalText;
45 unsigned processedCharacters; 55 unsigned processedCharacters;
46 RenderSVGInlineText* textRenderer; 56 RenderSVGInlineText* textRenderer;
47 const SVGInlineTextBox* textBox; 57 const SVGInlineTextBox* textBox;
58 // Ligature adjustment cache.
59 int ligatureAdjustmentLastStartPositionQuery;
60 int ligatureAdjustmentLastEndPositionQuery;
61 int ligatureAdjustmentLastStartPositionResult;
62 int ligatureAdjustmentLastEndPositionResult;
48 }; 63 };
49 64
50 static inline InlineFlowBox* flowBoxForRenderer(RenderObject* renderer) 65 static inline InlineFlowBox* flowBoxForRenderer(RenderObject* renderer)
51 { 66 {
52 if (!renderer) 67 if (!renderer)
53 return 0; 68 return 0;
54 69
55 if (renderer->isRenderBlock()) { 70 if (renderer->isRenderBlock()) {
56 // If we're given a block element, it has to be a RenderSVGText. 71 // If we're given a block element, it has to be a RenderSVGText.
57 ASSERT(renderer->isSVGText()); 72 ASSERT(renderer->isSVGText());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 unsigned fragmentCount = fragments.size(); 138 unsigned fragmentCount = fragments.size();
124 for (unsigned i = 0; i < fragmentCount; ++i) { 139 for (unsigned i = 0; i < fragmentCount; ++i) {
125 const SVGTextFragment& fragment = fragments.at(i); 140 const SVGTextFragment& fragment = fragments.at(i);
126 if ((this->*fragmentCallback)(queryData, fragment)) 141 if ((this->*fragmentCallback)(queryData, fragment))
127 return true; 142 return true;
128 143
129 processedCharacters += fragment.length; 144 processedCharacters += fragment.length;
130 } 145 }
131 146
132 queryData->processedCharacters = processedCharacters; 147 queryData->processedCharacters = processedCharacters;
148 queryData->invalidateLigatureAdjustmentCache();
133 } 149 }
134 150
135 return false; 151 return false;
136 } 152 }
137 153
138 bool SVGTextQuery::mapStartEndPositionsIntoFragmentCoordinates(Data* queryData, const SVGTextFragment& fragment, int& startPosition, int& endPosition) const 154 bool SVGTextQuery::mapStartEndPositionsIntoFragmentCoordinates(Data* queryData, const SVGTextFragment& fragment, int& startPosition, int& endPosition) const
139 { 155 {
140 // Reuse the same logic used for text selection & painting, to map our query start/length into start/endPositions of the current text fragment. 156 // Reuse the same logic used for text selection & painting, to map our query start/length into start/endPositions of the current text fragment.
141 startPosition -= queryData->processedCharacters; 157 startPosition -= queryData->processedCharacters;
142 endPosition -= queryData->processedCharacters; 158 endPosition -= queryData->processedCharacters;
143 159
144 startPosition = max(0, startPosition); 160 startPosition = max(0, startPosition);
145 161
146 if (startPosition >= endPosition) 162 if (startPosition >= endPosition)
147 return false; 163 return false;
148 164
149 modifyStartEndPositionsRespectingLigatures(queryData, startPosition, endPosi tion); 165 modifyStartEndPositionsRespectingLigatures(queryData, startPosition, endPosi tion);
150 if (!queryData->textBox->mapStartEndPositionsIntoFragmentCoordinates(fragmen t, startPosition, endPosition)) 166 if (!queryData->textBox->mapStartEndPositionsIntoFragmentCoordinates(fragmen t, startPosition, endPosition))
151 return false; 167 return false;
152 168
153 ASSERT(startPosition < endPosition); 169 ASSERT(startPosition < endPosition);
154 return true; 170 return true;
155 } 171 }
156 172
157 void SVGTextQuery::modifyStartEndPositionsRespectingLigatures(Data* queryData, i nt& startPosition, int& endPosition) const 173 void SVGTextQuery::modifyStartEndPositionsRespectingLigatures(Data* queryData, i nt& startPosition, int& endPosition) const
158 { 174 {
175 if (queryData->ligatureAdjustmentLastStartPositionQuery == startPosition && queryData->ligatureAdjustmentLastEndPositionQuery == endPosition) {
176 startPosition = queryData->ligatureAdjustmentLastStartPositionResult;
177 endPosition = queryData->ligatureAdjustmentLastEndPositionResult;
178 return;
179 }
180
181 queryData->ligatureAdjustmentLastStartPositionQuery = startPosition;
182 queryData->ligatureAdjustmentLastEndPositionQuery = endPosition;
183
159 SVGTextLayoutAttributes* layoutAttributes = queryData->textRenderer->layoutA ttributes(); 184 SVGTextLayoutAttributes* layoutAttributes = queryData->textRenderer->layoutA ttributes();
160 Vector<SVGTextMetrics>& textMetricsValues = layoutAttributes->textMetricsVal ues(); 185 Vector<SVGTextMetrics>& textMetricsValues = layoutAttributes->textMetricsVal ues();
161 unsigned boxStart = queryData->textBox->start(); 186 unsigned boxStart = queryData->textBox->start();
162 unsigned boxLength = queryData->textBox->len(); 187 unsigned boxLength = queryData->textBox->len();
163 188
164 unsigned textMetricsOffset = 0; 189 unsigned textMetricsOffset = 0;
165 unsigned textMetricsSize = textMetricsValues.size(); 190 unsigned textMetricsSize = textMetricsValues.size();
166 191
167 unsigned positionOffset = 0; 192 unsigned positionOffset = 0;
168 unsigned positionSize = layoutAttributes->context()->textLength(); 193 unsigned positionSize = layoutAttributes->context()->textLength();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 230 }
206 } 231 }
207 232
208 if (!alterStartPosition && !alterEndPosition) 233 if (!alterStartPosition && !alterEndPosition)
209 break; 234 break;
210 235
211 lastPositionOffset = positionOffset; 236 lastPositionOffset = positionOffset;
212 positionOffset += metrics.length(); 237 positionOffset += metrics.length();
213 } 238 }
214 239
215 if (!alterStartPosition && !alterEndPosition) 240 if (alterStartPosition || alterEndPosition) {
216 return; 241 if (lastPositionOffset != -1 && lastPositionOffset - positionOffset > 1) {
242 if (alterStartPosition && startPosition > lastPositionOffset && star tPosition < static_cast<int>(positionOffset))
243 startPosition = lastPositionOffset;
217 244
218 if (lastPositionOffset != -1 && lastPositionOffset - positionOffset > 1) { 245 if (alterEndPosition && endPosition > lastPositionOffset && endPosit ion < static_cast<int>(positionOffset))
219 if (alterStartPosition && startPosition > lastPositionOffset && startPos ition < static_cast<int>(positionOffset)) 246 endPosition = positionOffset;
220 startPosition = lastPositionOffset; 247 }
248 }
221 249
222 if (alterEndPosition && endPosition > lastPositionOffset && endPosition < static_cast<int>(positionOffset)) 250 queryData->ligatureAdjustmentLastStartPositionResult = startPosition;
223 endPosition = positionOffset; 251 queryData->ligatureAdjustmentLastEndPositionResult = endPosition;
224 }
225 } 252 }
226 253
227 // numberOfCharacters() implementation 254 // numberOfCharacters() implementation
228 bool SVGTextQuery::numberOfCharactersCallback(Data*, const SVGTextFragment&) con st 255 bool SVGTextQuery::numberOfCharactersCallback(Data*, const SVGTextFragment&) con st
229 { 256 {
230 // no-op 257 // no-op
231 return false; 258 return false;
232 } 259 }
233 260
234 unsigned SVGTextQuery::numberOfCharacters() const 261 unsigned SVGTextQuery::numberOfCharacters() const
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 return -1; 568 return -1;
542 569
543 CharacterNumberAtPositionData data(position); 570 CharacterNumberAtPositionData data(position);
544 if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback)) 571 if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback))
545 return -1; 572 return -1;
546 573
547 return data.processedCharacters; 574 return data.processedCharacters;
548 } 575 }
549 576
550 } 577 }
OLDNEW
« 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