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

Unified Diff: tests/RecordTest.cpp

Issue 366443002: Implement SkRecord::willPlaybackBitmaps, cache in SkPicture (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkRecordAnalysis.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
+
« no previous file with comments | « src/core/SkRecordAnalysis.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698