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

Side by Side Diff: src/core/SkPictureRecord.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 | « src/core/SkPictureRecord.h ('k') | 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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 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 #include "SkPictureRecord.h" 8 #include "SkPictureRecord.h"
9 #include "SkTSearch.h" 9 #include "SkTSearch.h"
10 #include "SkPixelRef.h" 10 #include "SkPixelRef.h"
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 394
395 SkAutoTDelete<SkPaint> dbmPaint(paintDict->unflatten(dbmPaintId)); 395 SkAutoTDelete<SkPaint> dbmPaint(paintDict->unflatten(dbmPaintId));
396 if (NULL == dbmPaint.get() || dbmPaint->getColor() != layerColor) { 396 if (NULL == dbmPaint.get() || dbmPaint->getColor() != layerColor) {
397 return false; 397 return false;
398 } 398 }
399 399
400 SkColor newColor = SkColorSetA(dbmPaint->getColor(), 400 SkColor newColor = SkColorSetA(dbmPaint->getColor(),
401 SkColorGetA(saveLayerPaint->getColor())); 401 SkColorGetA(saveLayerPaint->getColor()));
402 dbmPaint->setColor(newColor); 402 dbmPaint->setColor(newColor);
403 403
404 const int paintIndex = paintDict->find(*dbmPaint); 404 const SkFlatData* data = paintDict->findAndReturnFlat(*dbmPaint);
405 if (NULL == data) {
406 return false;
407 }
405 408
406 // kill the saveLayer and alter the DBMR2R's paint to be the modified one 409 // kill the saveLayer and alter the DBMR2R's paint to be the modified one
407 convert_command_to_noop(writer, saveLayerInfo.fOffset); 410 convert_command_to_noop(writer, saveLayerInfo.fOffset);
408 uint32_t* ptr = writer->peek32(dbmInfo.fOffset+dbmPaintOffset); 411 uint32_t* ptr = writer->peek32(dbmInfo.fOffset+dbmPaintOffset);
409 SkASSERT(dbmPaintId == *ptr); 412 SkASSERT(dbmPaintId == *ptr);
410 *ptr = paintIndex; 413 *ptr = data->index();
411 return true; 414 return true;
412 } 415 }
413 416
414 /* 417 /*
415 * Restore has just been called (but not recorded), look back at the 418 * Restore has just been called (but not recorded), look back at the
416 * matching save* and see if we are in the configuration: 419 * matching save* and see if we are in the configuration:
417 * SAVE_LAYER (with NULL == bounds) 420 * SAVE_LAYER (with NULL == bounds)
418 * SAVE 421 * SAVE
419 * CLIP_RECT 422 * CLIP_RECT
420 * DRAW_BITMAP|DRAW_BITMAP_MATRIX|DRAW_BITMAP_NINE|DRAW_BITMAP_RECT_TO_R ECT 423 * DRAW_BITMAP|DRAW_BITMAP_MATRIX|DRAW_BITMAP_NINE|DRAW_BITMAP_RECT_TO_R ECT
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 uint32_t size = 5 * kUInt32Size; 963 uint32_t size = 5 * kUInt32Size;
961 uint32_t initialOffset = this->addDraw(DRAW_SPRITE, &size); 964 uint32_t initialOffset = this->addDraw(DRAW_SPRITE, &size);
962 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.size()); 965 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.size());
963 addPaintPtr(paint); 966 addPaintPtr(paint);
964 addBitmap(bitmap); 967 addBitmap(bitmap);
965 addInt(left); 968 addInt(left);
966 addInt(top); 969 addInt(top);
967 validate(initialOffset, size); 970 validate(initialOffset, size);
968 } 971 }
969 972
970 // Return fontmetrics.fTop,fBottom in topbot[0,1], after they have been 973 void SkPictureRecord::ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]) {
971 // tweaked by paint.computeFastBounds().
972 //
973 static void computeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2] ) {
974 SkPaint::FontMetrics metrics; 974 SkPaint::FontMetrics metrics;
975 paint.getFontMetrics(&metrics); 975 paint.getFontMetrics(&metrics);
976 SkRect bounds; 976 SkRect bounds;
977 // construct a rect so we can see any adjustments from the paint. 977 // construct a rect so we can see any adjustments from the paint.
978 // we use 0,1 for left,right, just so the rect isn't empty 978 // we use 0,1 for left,right, just so the rect isn't empty
979 bounds.set(0, metrics.fTop, SK_Scalar1, metrics.fBottom); 979 bounds.set(0, metrics.fTop, SK_Scalar1, metrics.fBottom);
980 (void)paint.computeFastBounds(bounds, &bounds); 980 (void)paint.computeFastBounds(bounds, &bounds);
981 topbot[0] = bounds.fTop; 981 topbot[0] = bounds.fTop;
982 topbot[1] = bounds.fBottom; 982 topbot[1] = bounds.fBottom;
983 } 983 }
984 984
985 void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint, const SkFlat Data& flat, 985 void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint, const SkFlat Data& flat,
986 SkScalar minY, SkScalar maxY) { 986 SkScalar minY, SkScalar maxY) {
987 if (!flat.isTopBotWritten()) { 987 WriteTopBot(paint, flat);
988 computeFontMetricsTopBottom(paint, flat.writableTopBot());
989 SkASSERT(flat.isTopBotWritten());
990 }
991 addScalar(flat.topBot()[0] + minY); 988 addScalar(flat.topBot()[0] + minY);
992 addScalar(flat.topBot()[1] + maxY); 989 addScalar(flat.topBot()[1] + maxY);
993 } 990 }
994 991
995 void SkPictureRecord::drawText(const void* text, size_t byteLength, SkScalar x, 992 void SkPictureRecord::drawText(const void* text, size_t byteLength, SkScalar x,
996 SkScalar y, const SkPaint& paint) { 993 SkScalar y, const SkPaint& paint) {
997 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); 994 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds();
998 995
999 // op + paint index + length + 'length' worth of chars + x + y 996 // op + paint index + length + 'length' worth of chars + x + y
1000 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar ); 997 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar );
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 #ifdef SK_DEBUG_SIZE 1093 #ifdef SK_DEBUG_SIZE
1097 fPointBytes += fWriter.size() - start; 1094 fPointBytes += fWriter.size() - start;
1098 fPointWrites += points; 1095 fPointWrites += points;
1099 #endif 1096 #endif
1100 validate(initialOffset, size); 1097 validate(initialOffset, size);
1101 } 1098 }
1102 1099
1103 void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength, 1100 void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength,
1104 const SkScalar xpos[], SkScalar constY, 1101 const SkScalar xpos[], SkScalar constY,
1105 const SkPaint& paint) { 1102 const SkPaint& paint) {
1103
1104 const SkFlatData* flatPaintData = this->getFlatPaintData(paint);
1105 drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData);
1106 }
1107
1108 void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength,
1109 const SkScalar xpos[], SkScalar constY,
1110 const SkPaint& paint, const SkFlatData* flatPaintData) {
1106 size_t points = paint.countText(text, byteLength); 1111 size_t points = paint.countText(text, byteLength);
1107 if (0 == points) 1112 if (0 == points)
1108 return; 1113 return;
1109 1114
1110 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); 1115 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds();
1111 1116
1112 // op + paint index + length + 'length' worth of data + num points 1117 // op + paint index + length + 'length' worth of data + num points
1113 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size; 1118 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size;
1114 if (fast) { 1119 if (fast) {
1115 size += 2 * sizeof(SkScalar); // + top & bottom 1120 size += 2 * sizeof(SkScalar); // + top & bottom
1116 } 1121 }
1117 // + y + the actual points 1122 // + y + the actual points
1118 size += 1 * kUInt32Size + points * sizeof(SkScalar); 1123 size += 1 * kUInt32Size + points * sizeof(SkScalar);
1119
1120 uint32_t initialOffset = this->addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : D RAW_POS_TEXT_H, 1124 uint32_t initialOffset = this->addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : D RAW_POS_TEXT_H,
1121 &size); 1125 &size);
1122 const SkFlatData* flatPaintData = addPaint(paint);
1123 SkASSERT(flatPaintData); 1126 SkASSERT(flatPaintData);
1127 addFlatPaint(flatPaintData);
1128
1124 addText(text, byteLength); 1129 addText(text, byteLength);
1125 addInt(points); 1130 addInt(points);
1126 1131
1127 #ifdef SK_DEBUG_SIZE 1132 #ifdef SK_DEBUG_SIZE
1128 size_t start = fWriter.size(); 1133 size_t start = fWriter.size();
1129 #endif 1134 #endif
1130 if (fast) { 1135 if (fast) {
1131 addFontMetricsTopBottom(paint, *flatPaintData, constY, constY); 1136 addFontMetricsTopBottom(paint, *flatPaintData, constY, constY);
1132 } 1137 }
1133 addScalar(constY); 1138 addScalar(constY);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 } 1263 }
1259 1264
1260 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { 1265 void SkPictureRecord::addMatrix(const SkMatrix& matrix) {
1261 addMatrixPtr(&matrix); 1266 addMatrixPtr(&matrix);
1262 } 1267 }
1263 1268
1264 void SkPictureRecord::addMatrixPtr(const SkMatrix* matrix) { 1269 void SkPictureRecord::addMatrixPtr(const SkMatrix* matrix) {
1265 this->addInt(matrix ? fMatrices.find(*matrix) : 0); 1270 this->addInt(matrix ? fMatrices.find(*matrix) : 0);
1266 } 1271 }
1267 1272
1273 const SkFlatData* SkPictureRecord::getFlatPaintData(const SkPaint& paint) {
1274 return fPaints.findAndReturnFlat(paint);
1275 }
1276
1268 const SkFlatData* SkPictureRecord::addPaintPtr(const SkPaint* paint) { 1277 const SkFlatData* SkPictureRecord::addPaintPtr(const SkPaint* paint) {
1269 const SkFlatData* data = paint ? fPaints.findAndReturnFlat(*paint) : NULL; 1278 const SkFlatData* data = paint ? getFlatPaintData(*paint) : NULL;
1270 int index = data ? data->index() : 0; 1279 this->addFlatPaint(data);
1280 return data;
1281 }
1282
1283 void SkPictureRecord::addFlatPaint(const SkFlatData* flatPaint) {
1284 int index = flatPaint ? flatPaint->index() : 0;
1271 this->addInt(index); 1285 this->addInt(index);
1272 return data;
1273 } 1286 }
1274 1287
1275 void SkPictureRecord::addPath(const SkPath& path) { 1288 void SkPictureRecord::addPath(const SkPath& path) {
1276 if (NULL == fPathHeap) { 1289 if (NULL == fPathHeap) {
1277 fPathHeap = SkNEW(SkPathHeap); 1290 fPathHeap = SkNEW(SkPathHeap);
1278 } 1291 }
1279 addInt(fPathHeap->append(path)); 1292 addInt(fPathHeap->append(path));
1280 } 1293 }
1281 1294
1282 void SkPictureRecord::addPicture(SkPicture& picture) { 1295 void SkPictureRecord::addPicture(SkPicture& picture) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1482 void SkPictureRecord::validateRegions() const { 1495 void SkPictureRecord::validateRegions() const {
1483 int count = fRegions.count(); 1496 int count = fRegions.count();
1484 SkASSERT((unsigned) count < 0x1000); 1497 SkASSERT((unsigned) count < 0x1000);
1485 for (int index = 0; index < count; index++) { 1498 for (int index = 0; index < count; index++) {
1486 const SkFlatData* region = fRegions[index]; 1499 const SkFlatData* region = fRegions[index];
1487 SkASSERT(region); 1500 SkASSERT(region);
1488 // region->validate(); 1501 // region->validate();
1489 } 1502 }
1490 } 1503 }
1491 #endif 1504 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698