aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/RecorderTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/RecorderTest.cpp')
-rw-r--r--tests/RecorderTest.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/RecorderTest.cpp b/tests/RecorderTest.cpp
index 34b3f2c0de..570bce8a3c 100644
--- a/tests/RecorderTest.cpp
+++ b/tests/RecorderTest.cpp
@@ -11,6 +11,8 @@
#include "SkRecorder.h"
#include "SkRecords.h"
+#include "SkEmptyShader.h"
+
#define COUNT(T) + 1
static const int kRecordTypes = SK_RECORD_TYPES(COUNT);
#undef COUNT
@@ -41,3 +43,23 @@ DEF_TEST(Recorder, r) {
REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawRect>());
}
+
+// Regression test for leaking refs held by optional arguments.
+DEF_TEST(Recorder_RefLeaking, r) {
+ // We use SaveLayer to test:
+ // - its SkRect argument is optional and SkRect is POD. Just testing that that works.
+ // - its SkPaint argument is optional and SkPaint is not POD. The bug was here.
+
+ SkRect bounds;
+ SkPaint paint;
+ paint.setShader(SkNEW(SkEmptyShader))->unref();
+
+ REPORTER_ASSERT(r, paint.getShader()->unique());
+ {
+ SkRecord record;
+ SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080);
+ recorder.saveLayer(&bounds, &paint);
+ REPORTER_ASSERT(r, !paint.getShader()->unique());
+ }
+ REPORTER_ASSERT(r, paint.getShader()->unique());
+}