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

Side by Side Diff: tests/RecorderTest.cpp

Issue 235983015: SkRecord bug fixes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tomments Created 6 years, 8 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 unified diff | Download patch
« no previous file with comments | « src/record/SkRecords.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Test.h" 8 #include "Test.h"
9 9
10 #include "SkRecord.h" 10 #include "SkRecord.h"
11 #include "SkRecorder.h" 11 #include "SkRecorder.h"
12 #include "SkRecords.h" 12 #include "SkRecords.h"
13 13
14 #include "SkEmptyShader.h"
15
14 #define COUNT(T) + 1 16 #define COUNT(T) + 1
15 static const int kRecordTypes = SK_RECORD_TYPES(COUNT); 17 static const int kRecordTypes = SK_RECORD_TYPES(COUNT);
16 #undef COUNT 18 #undef COUNT
17 19
18 // Tallies the types of commands it sees into a histogram. 20 // Tallies the types of commands it sees into a histogram.
19 class Tally { 21 class Tally {
20 public: 22 public:
21 Tally() { sk_bzero(&fHistogram, sizeof(fHistogram)); } 23 Tally() { sk_bzero(&fHistogram, sizeof(fHistogram)); }
22 24
23 template <typename T> 25 template <typename T>
(...skipping 10 matching lines...) Expand all
34 SkRecord record; 36 SkRecord record;
35 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080); 37 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080);
36 38
37 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint()); 39 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
38 40
39 Tally tally; 41 Tally tally;
40 record.visit(tally); 42 record.visit(tally);
41 43
42 REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawRect>()); 44 REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawRect>());
43 } 45 }
46
47 // Regression test for leaking refs held by optional arguments.
48 DEF_TEST(Recorder_RefLeaking, r) {
49 // We use SaveLayer to test:
50 // - its SkRect argument is optional and SkRect is POD. Just testing that that works.
51 // - its SkPaint argument is optional and SkPaint is not POD. The bug was here.
52
53 SkRect bounds;
54 SkPaint paint;
55 paint.setShader(SkNEW(SkEmptyShader))->unref();
56
57 REPORTER_ASSERT(r, paint.getShader()->unique());
58 {
59 SkRecord record;
60 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080);
61 recorder.saveLayer(&bounds, &paint);
62 REPORTER_ASSERT(r, !paint.getShader()->unique());
63 }
64 REPORTER_ASSERT(r, paint.getShader()->unique());
65 }
OLDNEW
« no previous file with comments | « src/record/SkRecords.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698