| 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 "SkRecord.h" | 10 #include "SkRecord.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 const SkRecords::BoundedDrawPosTextH* bounded = | 102 const SkRecords::BoundedDrawPosTextH* bounded = |
| 103 assert_type<SkRecords::BoundedDrawPosTextH>(r, record, 0); | 103 assert_type<SkRecords::BoundedDrawPosTextH>(r, record, 0); |
| 104 | 104 |
| 105 const SkPaint defaults; | 105 const SkPaint defaults; |
| 106 REPORTER_ASSERT(r, bounded->base == original); | 106 REPORTER_ASSERT(r, bounded->base == original); |
| 107 REPORTER_ASSERT(r, bounded->minY <= SK_Scalar1 - defaults.getTextSize()); | 107 REPORTER_ASSERT(r, bounded->minY <= SK_Scalar1 - defaults.getTextSize()); |
| 108 REPORTER_ASSERT(r, bounded->maxY >= SK_Scalar1 + defaults.getTextSize()); | 108 REPORTER_ASSERT(r, bounded->maxY >= SK_Scalar1 + defaults.getTextSize()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 DEF_TEST(RecordOpts_NoopDrawSaveRestore, r) { |
| 112 SkRecord record; |
| 113 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); |
| 114 |
| 115 // The save and restore are pointless if there's only draw commands in the m
iddle. |
| 116 recorder.save(); |
| 117 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint()); |
| 118 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint()); |
| 119 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint()); |
| 120 recorder.restore(); |
| 121 |
| 122 record.replace<SkRecords::NoOp>(2); // NoOps should be allowed. |
| 123 |
| 124 SkRecordNoopSaveRestores(&record); |
| 125 |
| 126 assert_type<SkRecords::NoOp>(r, record, 0); |
| 127 assert_type<SkRecords::DrawRect>(r, record, 1); |
| 128 assert_type<SkRecords::NoOp>(r, record, 2); |
| 129 assert_type<SkRecords::DrawRect>(r, record, 3); |
| 130 assert_type<SkRecords::NoOp>(r, record, 4); |
| 131 } |
| 132 |
| 111 DEF_TEST(RecordOpts_SingleNoopSaveRestore, r) { | 133 DEF_TEST(RecordOpts_SingleNoopSaveRestore, r) { |
| 112 SkRecord record; | 134 SkRecord record; |
| 113 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 135 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); |
| 114 | 136 |
| 115 recorder.save(); | 137 recorder.save(); |
| 116 recorder.clipRect(SkRect::MakeWH(200, 200)); | 138 recorder.clipRect(SkRect::MakeWH(200, 200)); |
| 117 recorder.restore(); | 139 recorder.restore(); |
| 118 | 140 |
| 119 SkRecordNoopSaveRestores(&record); | 141 SkRecordNoopSaveRestores(&record); |
| 120 for (unsigned i = 0; i < 3; i++) { | 142 for (unsigned i = 0; i < 3; i++) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 132 recorder.save(); | 154 recorder.save(); |
| 133 recorder.restore(); | 155 recorder.restore(); |
| 134 | 156 |
| 135 // As long as we don't draw in there, everything is a noop. | 157 // As long as we don't draw in there, everything is a noop. |
| 136 recorder.save(); | 158 recorder.save(); |
| 137 recorder.clipRect(SkRect::MakeWH(200, 200)); | 159 recorder.clipRect(SkRect::MakeWH(200, 200)); |
| 138 recorder.clipRect(SkRect::MakeWH(100, 100)); | 160 recorder.clipRect(SkRect::MakeWH(100, 100)); |
| 139 recorder.restore(); | 161 recorder.restore(); |
| 140 recorder.restore(); | 162 recorder.restore(); |
| 141 | 163 |
| 142 // These will be kept (though some future optimization might noop the save a
nd restore). | |
| 143 recorder.save(); | |
| 144 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint()); | |
| 145 recorder.restore(); | |
| 146 | |
| 147 SkRecordNoopSaveRestores(&record); | 164 SkRecordNoopSaveRestores(&record); |
| 148 | |
| 149 for (unsigned index = 0; index < 8; index++) { | 165 for (unsigned index = 0; index < 8; index++) { |
| 150 assert_type<SkRecords::NoOp>(r, record, index); | 166 assert_type<SkRecords::NoOp>(r, record, index); |
| 151 } | 167 } |
| 152 assert_type<SkRecords::Save>(r, record, 8); | |
| 153 assert_type<SkRecords::DrawRect>(r, record, 9); | |
| 154 assert_type<SkRecords::Restore>(r, record, 10); | |
| 155 } | 168 } |
| 156 | 169 |
| 157 static void assert_savelayer_restore(skiatest::Reporter* r, | 170 static void assert_savelayer_restore(skiatest::Reporter* r, |
| 158 SkRecord* record, | 171 SkRecord* record, |
| 159 unsigned i, | 172 unsigned i, |
| 160 bool shouldBeNoOped) { | 173 bool shouldBeNoOped) { |
| 161 SkRecordNoopSaveLayerDrawRestores(record); | 174 SkRecordNoopSaveLayerDrawRestores(record); |
| 162 if (shouldBeNoOped) { | 175 if (shouldBeNoOped) { |
| 163 assert_type<SkRecords::NoOp>(r, *record, i); | 176 assert_type<SkRecords::NoOp>(r, *record, i); |
| 164 assert_type<SkRecords::NoOp>(r, *record, i+2); | 177 assert_type<SkRecords::NoOp>(r, *record, i+2); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 // SaveLayer/Restore removed: we can fold in the alpha! | 232 // SaveLayer/Restore removed: we can fold in the alpha! |
| 220 recorder.saveLayer(NULL, &goodLayerPaint); | 233 recorder.saveLayer(NULL, &goodLayerPaint); |
| 221 recorder.drawRect(draw, goodDrawPaint); | 234 recorder.drawRect(draw, goodDrawPaint); |
| 222 recorder.restore(); | 235 recorder.restore(); |
| 223 assert_savelayer_restore(r, &record, 15, true); | 236 assert_savelayer_restore(r, &record, 15, true); |
| 224 | 237 |
| 225 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
cord, 16); | 238 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
cord, 16); |
| 226 REPORTER_ASSERT(r, drawRect != NULL); | 239 REPORTER_ASSERT(r, drawRect != NULL); |
| 227 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); | 240 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); |
| 228 } | 241 } |
| OLD | NEW |