| OLD | NEW |
| 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 "SkPictureRecorder.h" | 10 #include "SkPictureRecorder.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 recorder.endCommentGroup(); | 61 recorder.endCommentGroup(); |
| 62 | 62 |
| 63 Tally tally; | 63 Tally tally; |
| 64 tally.apply(record); | 64 tally.apply(record); |
| 65 | 65 |
| 66 REPORTER_ASSERT(r, 1 == tally.count<SkRecords::BeginCommentGroup>()); | 66 REPORTER_ASSERT(r, 1 == tally.count<SkRecords::BeginCommentGroup>()); |
| 67 REPORTER_ASSERT(r, 2 == tally.count<SkRecords::AddComment>()); | 67 REPORTER_ASSERT(r, 2 == tally.count<SkRecords::AddComment>()); |
| 68 REPORTER_ASSERT(r, 1 == tally.count<SkRecords::EndCommentGroup>()); | 68 REPORTER_ASSERT(r, 1 == tally.count<SkRecords::EndCommentGroup>()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // DrawData is similar to comment groups. It doesn't affect drawing, but |
| 72 // it's a pass-through we provide to the client. Again, a simple reg. test. |
| 73 DEF_TEST(Recorder_DrawData, r) { |
| 74 SkRecord record; |
| 75 SkRecorder recorder(&record, 100, 100); |
| 76 |
| 77 const char* data = "This sure is some data, eh?"; |
| 78 recorder.drawData(data, strlen(data)); |
| 79 |
| 80 Tally tally; |
| 81 tally.apply(record); |
| 82 REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawData>()); |
| 83 } |
| 84 |
| 71 // Regression test for leaking refs held by optional arguments. | 85 // Regression test for leaking refs held by optional arguments. |
| 72 DEF_TEST(Recorder_RefLeaking, r) { | 86 DEF_TEST(Recorder_RefLeaking, r) { |
| 73 // We use SaveLayer to test: | 87 // We use SaveLayer to test: |
| 74 // - its SkRect argument is optional and SkRect is POD. Just testing that
that works. | 88 // - its SkRect argument is optional and SkRect is POD. Just testing that
that works. |
| 75 // - its SkPaint argument is optional and SkPaint is not POD. The bug was
here. | 89 // - its SkPaint argument is optional and SkPaint is not POD. The bug was
here. |
| 76 | 90 |
| 77 SkRect bounds = SkRect::MakeWH(320, 240); | 91 SkRect bounds = SkRect::MakeWH(320, 240); |
| 78 SkPaint paint; | 92 SkPaint paint; |
| 79 paint.setShader(SkShader::CreateEmptyShader())->unref(); | 93 paint.setShader(SkShader::CreateEmptyShader())->unref(); |
| 80 | 94 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 102 { | 116 { |
| 103 SkRecord record; | 117 SkRecord record; |
| 104 SkRecorder recorder(&record, 100, 100); | 118 SkRecorder recorder(&record, 100, 100); |
| 105 recorder.drawPicture(pic); | 119 recorder.drawPicture(pic); |
| 106 // the recorder should now also be an owner | 120 // the recorder should now also be an owner |
| 107 REPORTER_ASSERT(r, !pic->unique()); | 121 REPORTER_ASSERT(r, !pic->unique()); |
| 108 } | 122 } |
| 109 // the recorder destructor should have released us (back to unique) | 123 // the recorder destructor should have released us (back to unique) |
| 110 REPORTER_ASSERT(r, pic->unique()); | 124 REPORTER_ASSERT(r, pic->unique()); |
| 111 } | 125 } |
| 126 |
| 127 DEF_TEST(Recorder_IsDrawingToLayer, r) { |
| 128 SkRecord record; |
| 129 SkRecorder recorder(&record, 100, 100); |
| 130 |
| 131 // We'll save, saveLayer, save, and saveLayer, then restore them all, |
| 132 // checking that isDrawingToLayer() is correct at each step. |
| 133 |
| 134 REPORTER_ASSERT(r, !recorder.isDrawingToLayer()); |
| 135 recorder.save(); |
| 136 REPORTER_ASSERT(r, !recorder.isDrawingToLayer()); |
| 137 recorder.saveLayer(NULL, NULL); |
| 138 REPORTER_ASSERT(r, recorder.isDrawingToLayer()); |
| 139 recorder.save(); |
| 140 REPORTER_ASSERT(r, recorder.isDrawingToLayer()); |
| 141 recorder.saveLayer(NULL, NULL); |
| 142 REPORTER_ASSERT(r, recorder.isDrawingToLayer()); |
| 143 recorder.restore(); |
| 144 REPORTER_ASSERT(r, recorder.isDrawingToLayer()); |
| 145 recorder.restore(); |
| 146 REPORTER_ASSERT(r, recorder.isDrawingToLayer()); |
| 147 recorder.restore(); |
| 148 REPORTER_ASSERT(r, !recorder.isDrawingToLayer()); |
| 149 recorder.restore(); |
| 150 REPORTER_ASSERT(r, !recorder.isDrawingToLayer()); |
| 151 } |
| 152 |
| OLD | NEW |