Index: tests/RecordTest.cpp |
diff --git a/tests/RecordTest.cpp b/tests/RecordTest.cpp |
index 96f3ad41e1a427c9c33e15708a73d057a97bb573..8ec5bcba7653fa27c9ad432b18b1a024335fe493 100644 |
--- a/tests/RecordTest.cpp |
+++ b/tests/RecordTest.cpp |
@@ -7,7 +7,11 @@ |
#include "Test.h" |
+#include "SkBitmap.h" |
+#include "SkImageInfo.h" |
+#include "SkShader.h" |
#include "SkRecord.h" |
+#include "SkRecordAnalysis.h" |
#include "SkRecords.h" |
// Sums the area of any DrawRect command it sees. |
@@ -48,6 +52,8 @@ struct Stretch { |
} |
}; |
+#define APPEND(record, type, ...) SkNEW_PLACEMENT_ARGS(record.append<type>(), type, (__VA_ARGS__)) |
+ |
// Basic tests for the low-level SkRecord code. |
DEF_TEST(Record, r) { |
SkRecord record; |
@@ -55,7 +61,7 @@ DEF_TEST(Record, r) { |
// Add a simple DrawRect command. |
SkRect rect = SkRect::MakeWH(10, 10); |
SkPaint paint; |
- SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawRect>(), SkRecords::DrawRect, (paint, rect)); |
+ APPEND(record, SkRecords::DrawRect, paint, rect); |
// Its area should be 100. |
AreaSummer summer; |
@@ -70,3 +76,38 @@ DEF_TEST(Record, r) { |
summer.apply(record); |
REPORTER_ASSERT(r, summer.area() == 500); |
} |
+ |
+DEF_TEST(RecordAnalysis, r) { |
+ SkRecord record; |
+ |
+ SkRect rect = SkRect::MakeWH(10, 10); |
+ SkPaint paint; |
+ APPEND(record, SkRecords::DrawRect, paint, rect); |
+ REPORTER_ASSERT(r, !SkRecordWillPlaybackBitmaps(record)); |
+ |
+ SkBitmap bitmap; |
+ APPEND(record, SkRecords::DrawBitmap, &paint, bitmap, 0.0f, 0.0f); |
+ REPORTER_ASSERT(r, SkRecordWillPlaybackBitmaps(record)); |
+ |
+ SkNEW_PLACEMENT_ARGS(record.replace<SkRecords::DrawRect>(1), |
+ SkRecords::DrawRect, (paint, rect)); |
+ REPORTER_ASSERT(r, !SkRecordWillPlaybackBitmaps(record)); |
+ |
+ SkPaint paint2; |
+ // CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shader |
+ // gets optimized into a non-bitmap form, so we create a 2x2 bitmap here. |
+ SkBitmap bitmap2; |
+ bitmap2.allocPixels(SkImageInfo::MakeN32Premul(2, 2)); |
+ bitmap2.eraseColor(SK_ColorBLUE); |
+ *(bitmap2.getAddr32(0, 0)) = SK_ColorGREEN; |
+ SkShader* shader = SkShader::CreateBitmapShader(bitmap2, SkShader::kClamp_TileMode, |
+ SkShader::kClamp_TileMode); |
+ paint2.setShader(shader); |
+ REPORTER_ASSERT(r, shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefault_BitmapType); |
+ |
+ APPEND(record, SkRecords::DrawRect, paint2, rect); |
+ REPORTER_ASSERT(r, SkRecordWillPlaybackBitmaps(record)); |
+} |
+ |
+#undef APPEND |
+ |