Index: src/core/SkPictureRecord.cpp |
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp |
index e38cfb8be4cbc1d4bb27a4c0673d66f18245a859..f1a1e8f9717a00567c41bc0a0fd1cc1438d45e17 100644 |
--- a/src/core/SkPictureRecord.cpp |
+++ b/src/core/SkPictureRecord.cpp |
@@ -15,6 +15,15 @@ |
#define HEAP_BLOCK_SIZE 4096 |
+// If SK_RECORD_LITERAL_PICTURES is defined, record our inputs as literally as possible. |
+// Otherwise, we can be clever and record faster equivalents. kBeClever is normally true. |
+static const bool kBeClever = |
+#ifdef SK_RECORD_LITERAL_PICTURES |
+ false; |
+#else |
+ true; |
+#endif |
+ |
enum { |
// just need a value that save or getSaveCount would never return |
kNoInitialSave = -1, |
@@ -34,7 +43,7 @@ SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) |
, fFlattenableHeap(HEAP_BLOCK_SIZE) |
, fPaints(&fFlattenableHeap) |
, fRecordFlags(flags) |
- , fOptsEnabled(true) { |
+ , fOptsEnabled(kBeClever) { |
#ifdef SK_DEBUG_SIZE |
fPointBytes = fRectBytes = fTextBytes = 0; |
fPointWrites = fRectWrites = fTextWrites = 0; |
@@ -1032,9 +1041,9 @@ void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
#endif |
- if (rrect.isRect()) { |
+ if (rrect.isRect() && kBeClever) { |
this->SkPictureRecord::drawRect(rrect.getBounds(), paint); |
- } else if (rrect.isOval()) { |
+ } else if (rrect.isOval() && kBeClever) { |
this->SkPictureRecord::drawOval(rrect.getBounds(), paint); |
} else { |
// op + paint index + rrect |
@@ -1081,7 +1090,7 @@ void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { |
void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
const SkPaint* paint = NULL) { |
- if (bitmap.drawsNothing()) { |
+ if (bitmap.drawsNothing() && kBeClever) { |
return; |
} |
@@ -1103,7 +1112,7 @@ void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar |
void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, |
const SkRect& dst, const SkPaint* paint, |
DrawBitmapRectFlags flags) { |
- if (bitmap.drawsNothing()) { |
+ if (bitmap.drawsNothing() && kBeClever) { |
return; |
} |
@@ -1130,7 +1139,7 @@ void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* |
void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix, |
const SkPaint* paint) { |
- if (bitmap.drawsNothing()) { |
+ if (bitmap.drawsNothing() && kBeClever) { |
return; |
} |
@@ -1150,7 +1159,7 @@ void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m |
void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
const SkRect& dst, const SkPaint* paint) { |
- if (bitmap.drawsNothing()) { |
+ if (bitmap.drawsNothing() && kBeClever) { |
return; |
} |
@@ -1171,7 +1180,7 @@ void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent |
void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, |
const SkPaint* paint = NULL) { |
- if (bitmap.drawsNothing()) { |
+ if (bitmap.drawsNothing() && kBeClever) { |
return; |
} |
@@ -1216,7 +1225,7 @@ void SkPictureRecord::drawText(const void* text, size_t byteLength, SkScalar x, |
fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
#endif |
- bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); |
+ bool fast = !paint.isVerticalText() && paint.canComputeFastBounds() && kBeClever; |
// op + paint index + length + 'length' worth of chars + x + y |
size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar); |
@@ -1267,8 +1276,8 @@ void SkPictureRecord::drawPosText(const void* text, size_t byteLength, |
} |
} |
- bool fastBounds = !paint.isVerticalText() && paint.canComputeFastBounds(); |
- bool fast = canUseDrawH && fastBounds; |
+ bool fastBounds = !paint.isVerticalText() && paint.canComputeFastBounds() && kBeClever; |
+ bool fast = canUseDrawH && fastBounds && kBeClever; |
// op + paint index + length + 'length' worth of data + num points |
size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size; |
@@ -1343,10 +1352,11 @@ void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength, |
const SkScalar xpos[], SkScalar constY, |
const SkPaint& paint, const SkFlatData* flatPaintData) { |
int points = paint.countText(text, byteLength); |
- if (0 == points) |
+ if (0 == points && kBeClever) { |
return; |
+ } |
- bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); |
+ bool fast = !paint.isVerticalText() && paint.canComputeFastBounds() && kBeClever; |
// op + paint index + length + 'length' worth of data + num points |
size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size; |
@@ -1541,7 +1551,7 @@ void SkPictureRecord::onPopCull() { |
fCullOffsetStack.pop(); |
// Collapse empty push/pop pairs. |
- if ((size_t)(cullSkipOffset + kUInt32Size) == fWriter.bytesWritten()) { |
+ if ((size_t)(cullSkipOffset + kUInt32Size) == fWriter.bytesWritten() && kBeClever) { |
SkASSERT(fWriter.bytesWritten() >= kPushCullOpSize); |
SkASSERT(PUSH_CULL == peek_op(&fWriter, fWriter.bytesWritten() - kPushCullOpSize)); |
fWriter.rewindToOffset(fWriter.bytesWritten() - kPushCullOpSize); |