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

Unified Diff: tests/PictureTest.cpp

Issue 2106843004: Experiment: add flag for finish-recording to return null (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address comments from #21 Created 4 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
Index: tests/PictureTest.cpp
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index f10948231123a4b8eae6c8b449fb73c7fd6c52ff..eb0c6a8f0e6fe408acca8da3c40f222603aea662 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -1447,3 +1447,63 @@ DEF_TEST(PictureGpuAnalyzer, r) {
}
#endif // SK_SUPPORT_GPU
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+static void empty_ops(SkCanvas* canvas) {
+}
+static void clip_ops(SkCanvas* canvas) {
+ canvas->save();
+ canvas->clipRect(SkRect::MakeWH(20, 20));
+ canvas->restore();
+}
+static void matrix_ops(SkCanvas* canvas) {
+ canvas->save();
+ canvas->scale(2, 3);
+ canvas->restore();
+}
+static void matrixclip_ops(SkCanvas* canvas) {
+ canvas->save();
+ canvas->scale(2, 3);
+ canvas->clipRect(SkRect::MakeWH(20, 20));
+ canvas->restore();
+}
+typedef void (*CanvasProc)(SkCanvas*);
+
+// Test the kReturnNullForEmpty_FinishFlag option when recording
+//
+DEF_TEST(Picture_RecordEmpty, r) {
+ const SkRect cull = SkRect::MakeWH(100, 100);
+
+ CanvasProc procs[] { empty_ops, clip_ops, matrix_ops, matrixclip_ops };
+
+ for (auto proc : procs) {
+ {
+ SkPictureRecorder rec;
+ proc(rec.beginRecording(cull));
+ sk_sp<SkPicture> pic = rec.finishRecordingAsPicture(0);
+ REPORTER_ASSERT(r, pic.get());
+ REPORTER_ASSERT(r, pic->approximateOpCount() == 0);
+ }
+ {
+ SkPictureRecorder rec;
+ proc(rec.beginRecording(cull));
+ sk_sp<SkPicture> pic = rec.finishRecordingAsPicture(
+ SkPictureRecorder::kReturnNullForEmpty_FinishFlag);
+ REPORTER_ASSERT(r, !pic.get());
+ }
+ {
+ SkPictureRecorder rec;
+ proc(rec.beginRecording(cull));
+ sk_sp<SkDrawable> dr = rec.finishRecordingAsDrawable(0);
+ REPORTER_ASSERT(r, dr.get());
+ }
+ {
+ SkPictureRecorder rec;
+ proc(rec.beginRecording(cull));
+ sk_sp<SkDrawable> dr = rec.finishRecordingAsDrawable(
+ SkPictureRecorder::kReturnNullForEmpty_FinishFlag);
+ REPORTER_ASSERT(r, !dr.get());
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698