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

Side by Side Diff: src/core/SkBBoxRecord.cpp

Issue 23001007: Remove the call to getFontMetrics from SkBBoxRecord (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 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 | src/core/SkPictureRecord.h » ('j') | src/core/SkPictureRecord.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkBBoxRecord.h" 9 #include "SkBBoxRecord.h"
10 10
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 if (this->transformBounds(bbox, &paint)) { 175 if (this->transformBounds(bbox, &paint)) {
176 INHERITED::drawPosText(text, byteLength, pos, paint); 176 INHERITED::drawPosText(text, byteLength, pos, paint);
177 } 177 }
178 } 178 }
179 179
180 void SkBBoxRecord::drawPosTextH(const void* text, size_t byteLength, const SkSca lar xpos[], 180 void SkBBoxRecord::drawPosTextH(const void* text, size_t byteLength, const SkSca lar xpos[],
181 SkScalar constY, const SkPaint& paint) { 181 SkScalar constY, const SkPaint& paint) {
182 SkRect bbox; 182 SkRect bbox;
183 size_t numChars = paint.countText(text, byteLength); 183 size_t numChars = paint.countText(text, byteLength);
184
185 const SkFlatData* flatPaintData = this->getFlatPaintData(paint);
186
184 if (numChars > 0) { 187 if (numChars > 0) {
reed1 2013/08/20 17:59:23 minor: if numChars == 0, we should abort everythin
185 bbox.fLeft = xpos[0]; 188 bbox.fLeft = xpos[0];
186 bbox.fRight = xpos[numChars - 1]; 189 bbox.fRight = xpos[numChars - 1];
187 // if we had a guarantee that these will be monotonically increasing, th is could be sped up
188 for (size_t i = 1; i < numChars; ++i) { 190 for (size_t i = 1; i < numChars; ++i) {
189 if (xpos[i] < bbox.fLeft) { 191 if (xpos[i] < bbox.fLeft) {
190 bbox.fLeft = xpos[i]; 192 bbox.fLeft = xpos[i];
191 } 193 }
192 if (xpos[i] > bbox.fRight) { 194 if (xpos[i] > bbox.fRight) {
193 bbox.fRight = xpos[i]; 195 bbox.fRight = xpos[i];
194 } 196 }
195 } 197 }
196 SkPaint::FontMetrics metrics;
197 paint.getFontMetrics(&metrics);
198 198
199 // pad horizontally by max glyph height 199 // pad horizontally by max glyph height
200 SkScalar pad = (metrics.fTop - metrics.fBottom); 200 SkScalar pad = 0;
201 SkScalar top = 0;
202 SkScalar bottom = 0;
caryclark 2013/08/20 20:11:34 no need to initialize top, bottom
203 if (flatPaintData->isTopBotWritten()) {
reed1 2013/08/20 17:59:23 Is there (can there be) a common helper method, pe
sglez 2013/08/21 16:09:35 Added helper method WriteTopBot that wraps what th
204 top = flatPaintData->topBot()[0];
205 bottom = flatPaintData->topBot()[1];
206 pad = top - bottom;
caryclark 2013/08/20 20:11:34 move pad declaration + assignment below 'if'
207 } else { // I have not seen a case where this path is taken, but just i n case...
208 SkPaint::FontMetrics metrics;
209 paint.getFontMetrics(&metrics);
210 pad = (metrics.fTop - metrics.fBottom);
211 top = metrics.fTop;
212 bottom = metrics.fBottom;
213 }
201 bbox.fLeft += pad; 214 bbox.fLeft += pad;
202 bbox.fRight -= pad; 215 bbox.fRight -= pad;
203 216
204 bbox.fTop = metrics.fTop + constY; 217 bbox.fTop = top + constY;
205 bbox.fBottom = metrics.fBottom + constY; 218 bbox.fBottom = bottom + constY;
219
206 if (!this->transformBounds(bbox, &paint)) { 220 if (!this->transformBounds(bbox, &paint)) {
207 return; 221 return;
208 } 222 }
209 } 223 }
210 INHERITED::drawPosTextH(text, byteLength, xpos, constY, paint); 224 // This is the equivalent of calling:
225 // INHERITED::drawPosTextH(text, byteLength, xpos, constY, paint);
226 // but we filled our flat paint beforehand so that we could get font metrics .
227 drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData);
211 } 228 }
212 229
213 void SkBBoxRecord::drawSprite(const SkBitmap& bitmap, int left, int top, 230 void SkBBoxRecord::drawSprite(const SkBitmap& bitmap, int left, int top,
214 const SkPaint* paint) { 231 const SkPaint* paint) {
215 SkRect bbox; 232 SkRect bbox;
216 bbox.set(SkIRect::MakeXYWH(left, top, bitmap.width(), bitmap.height())); 233 bbox.set(SkIRect::MakeXYWH(left, top, bitmap.width(), bitmap.height()));
217 this->handleBBox(bbox); // directly call handleBBox, matrix is ignored 234 this->handleBBox(bbox); // directly call handleBBox, matrix is ignored
218 INHERITED::drawSprite(bitmap, left, top, paint); 235 INHERITED::drawSprite(bitmap, left, top, paint);
219 } 236 }
220 237
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 293 }
277 294
278 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { 295 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) {
279 this->getTotalMatrix().mapRect(&outBounds); 296 this->getTotalMatrix().mapRect(&outBounds);
280 this->handleBBox(outBounds); 297 this->handleBBox(outBounds);
281 return true; 298 return true;
282 } 299 }
283 300
284 return false; 301 return false;
285 } 302 }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPictureRecord.h » ('j') | src/core/SkPictureRecord.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698