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

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

Issue 494483002: Cheat to go fast, but be careful in debug mode. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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
« 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 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkRecordDraw.h" 8 #include "SkRecordDraw.h"
9 #include "SkTSort.h" 9 #include "SkTSort.h"
10 10
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 for (int i = 1; i < N; i++) { 305 for (int i = 1; i < N; i++) {
306 left = SkMinScalar(left, op.xpos[i]); 306 left = SkMinScalar(left, op.xpos[i]);
307 right = SkMaxScalar(right, op.xpos[i]); 307 right = SkMaxScalar(right, op.xpos[i]);
308 } 308 }
309 SkRect dst = { left, op.y, right, op.y }; 309 SkRect dst = { left, op.y, right, op.y };
310 AdjustTextForFontMetrics(&dst, op.paint); 310 AdjustTextForFontMetrics(&dst, op.paint);
311 return this->adjustAndMap(dst, &op.paint); 311 return this->adjustAndMap(dst, &op.paint);
312 } 312 }
313 313
314 static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) { 314 static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) {
315 // FIXME: These bounds should be tight (and correct), but reading SkFont Metrics is likely 315 #if SK_DEBUG
316 // a performance bottleneck. It's safe to overapproximate these metrics for speed. E.g. 316 SkRect correct = *rect;
317 // fTop <= 1.5 * paint.getTextSize(), fXMax <= 8 * fTop, etc. 317 #endif
318 const SkScalar yPad = 1.5f * paint.getTextSize(), // In practice, this seems to be enough.
319 xPad = 4.0f * yPad; // Hack for very wide Github logo font.
320 rect->outset(xPad, yPad);
321 #if SK_DEBUG
318 SkPaint::FontMetrics metrics; 322 SkPaint::FontMetrics metrics;
319 paint.getFontMetrics(&metrics); 323 paint.getFontMetrics(&metrics);
320 rect->fLeft += metrics.fXMin; 324 correct.fLeft += metrics.fXMin;
321 rect->fTop += metrics.fTop; 325 correct.fTop += metrics.fTop;
322 rect->fRight += metrics.fXMax; 326 correct.fRight += metrics.fXMax;
323 rect->fBottom += metrics.fBottom; 327 correct.fBottom += metrics.fBottom;
328 SkASSERTF(rect->contains(correct), "%f %f %f %f vs. %f %f %f %f\n",
329 -xPad, -yPad, +xPad, +yPad,
330 metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom);
331 #endif
324 } 332 }
325 333
326 // Returns true if rect was meaningfully adjusted for the effects of paint, 334 // Returns true if rect was meaningfully adjusted for the effects of paint,
327 // false if the paint could affect the rect in unknown ways. 335 // false if the paint could affect the rect in unknown ways.
328 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) { 336 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) {
329 if (paint) { 337 if (paint) {
330 if (paint->canComputeFastBounds()) { 338 if (paint->canComputeFastBounds()) {
331 *rect = paint->computeFastBounds(*rect, rect); 339 *rect = paint->computeFastBounds(*rect, rect);
332 return true; 340 return true;
333 } 341 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // Used to track the bounds of Save/Restore blocks and the control ops insid e them. 387 // Used to track the bounds of Save/Restore blocks and the control ops insid e them.
380 SkTDArray<SaveBounds> fSaveStack; 388 SkTDArray<SaveBounds> fSaveStack;
381 SkTDArray<unsigned> fControlIndices; 389 SkTDArray<unsigned> fControlIndices;
382 }; 390 };
383 391
384 } // namespace SkRecords 392 } // namespace SkRecords
385 393
386 void SkRecordFillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) { 394 void SkRecordFillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) {
387 SkRecords::FillBounds(record, bbh); 395 SkRecords::FillBounds(record, bbh);
388 } 396 }
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