| 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 #include "RecordTestUtils.h" | 9 #include "RecordTestUtils.h" |
| 10 | 10 |
| 11 #include "SkRecord.h" | 11 #include "SkRecord.h" |
| 12 #include "SkRecordOpts.h" | 12 #include "SkRecordOpts.h" |
| 13 #include "SkRecorder.h" | 13 #include "SkRecorder.h" |
| 14 #include "SkRecords.h" | 14 #include "SkRecords.h" |
| 15 #include "SkXfermode.h" | 15 #include "SkXfermode.h" |
| 16 | 16 |
| 17 static const int W = 1920, H = 1080; | 17 static const int W = 1920, H = 1080; |
| 18 | 18 |
| 19 DEF_TEST(RecordOpts_Culling, r) { | 19 DEF_TEST(RecordOpts_Culling, r) { |
| 20 SkRecord record; | 20 SkRecord record; |
| 21 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 21 SkRecorder recorder(&record, W, H); |
| 22 | 22 |
| 23 recorder.drawRect(SkRect::MakeWH(1000, 10000), SkPaint()); | 23 recorder.drawRect(SkRect::MakeWH(1000, 10000), SkPaint()); |
| 24 | 24 |
| 25 recorder.pushCull(SkRect::MakeWH(100, 100)); | 25 recorder.pushCull(SkRect::MakeWH(100, 100)); |
| 26 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint()); | 26 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint()); |
| 27 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint()); | 27 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint()); |
| 28 recorder.pushCull(SkRect::MakeWH(5, 5)); | 28 recorder.pushCull(SkRect::MakeWH(5, 5)); |
| 29 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint()); | 29 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint()); |
| 30 recorder.popCull(); | 30 recorder.popCull(); |
| 31 recorder.popCull(); | 31 recorder.popCull(); |
| 32 | 32 |
| 33 SkRecordAnnotateCullingPairs(&record); | 33 SkRecordAnnotateCullingPairs(&record); |
| 34 | 34 |
| 35 REPORTER_ASSERT(r, 6 == assert_type<SkRecords::PairedPushCull>(r, record, 1)
->skip); | 35 REPORTER_ASSERT(r, 6 == assert_type<SkRecords::PairedPushCull>(r, record, 1)
->skip); |
| 36 REPORTER_ASSERT(r, 2 == assert_type<SkRecords::PairedPushCull>(r, record, 4)
->skip); | 36 REPORTER_ASSERT(r, 2 == assert_type<SkRecords::PairedPushCull>(r, record, 4)
->skip); |
| 37 } | 37 } |
| 38 | 38 |
| 39 DEF_TEST(RecordOpts_NoopCulls, r) { | 39 DEF_TEST(RecordOpts_NoopCulls, r) { |
| 40 SkRecord record; | 40 SkRecord record; |
| 41 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 41 SkRecorder recorder(&record, W, H); |
| 42 | 42 |
| 43 // All should be nooped. | 43 // All should be nooped. |
| 44 recorder.pushCull(SkRect::MakeWH(200, 200)); | 44 recorder.pushCull(SkRect::MakeWH(200, 200)); |
| 45 recorder.pushCull(SkRect::MakeWH(100, 100)); | 45 recorder.pushCull(SkRect::MakeWH(100, 100)); |
| 46 recorder.popCull(); | 46 recorder.popCull(); |
| 47 recorder.popCull(); | 47 recorder.popCull(); |
| 48 | 48 |
| 49 // Kept for now. We could peel off a layer of culling. | 49 // Kept for now. We could peel off a layer of culling. |
| 50 recorder.pushCull(SkRect::MakeWH(5, 5)); | 50 recorder.pushCull(SkRect::MakeWH(5, 5)); |
| 51 recorder.pushCull(SkRect::MakeWH(5, 5)); | 51 recorder.pushCull(SkRect::MakeWH(5, 5)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 70 SkAutoTMalloc<SkPoint> pos(len); | 70 SkAutoTMalloc<SkPoint> pos(len); |
| 71 for (size_t i = 0; i < len; i++) { | 71 for (size_t i = 0; i < len; i++) { |
| 72 pos[i].fX = (SkScalar)i; | 72 pos[i].fX = (SkScalar)i; |
| 73 pos[i].fY = constantY ? SK_Scalar1 : (SkScalar)i; | 73 pos[i].fY = constantY ? SK_Scalar1 : (SkScalar)i; |
| 74 } | 74 } |
| 75 canvas->drawPosText(text, len, pos, SkPaint()); | 75 canvas->drawPosText(text, len, pos, SkPaint()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 DEF_TEST(RecordOpts_StrengthReduction, r) { | 78 DEF_TEST(RecordOpts_StrengthReduction, r) { |
| 79 SkRecord record; | 79 SkRecord record; |
| 80 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 80 SkRecorder recorder(&record, W, H); |
| 81 | 81 |
| 82 // We can convert a drawPosText into a drawPosTextH when all the Ys are the
same. | 82 // We can convert a drawPosText into a drawPosTextH when all the Ys are the
same. |
| 83 draw_pos_text(&recorder, "This will be reduced to drawPosTextH.", true); | 83 draw_pos_text(&recorder, "This will be reduced to drawPosTextH.", true); |
| 84 draw_pos_text(&recorder, "This cannot be reduced to drawPosTextH.", false); | 84 draw_pos_text(&recorder, "This cannot be reduced to drawPosTextH.", false); |
| 85 | 85 |
| 86 SkRecordReduceDrawPosTextStrength(&record); | 86 SkRecordReduceDrawPosTextStrength(&record); |
| 87 | 87 |
| 88 assert_type<SkRecords::DrawPosTextH>(r, record, 0); | 88 assert_type<SkRecords::DrawPosTextH>(r, record, 0); |
| 89 assert_type<SkRecords::DrawPosText>(r, record, 1); | 89 assert_type<SkRecords::DrawPosText>(r, record, 1); |
| 90 } | 90 } |
| 91 | 91 |
| 92 DEF_TEST(RecordOpts_TextBounding, r) { | 92 DEF_TEST(RecordOpts_TextBounding, r) { |
| 93 SkRecord record; | 93 SkRecord record; |
| 94 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 94 SkRecorder recorder(&record, W, H); |
| 95 | 95 |
| 96 // First, get a drawPosTextH. Here's a handy way. Its text size will be th
e default (12). | 96 // First, get a drawPosTextH. Here's a handy way. Its text size will be th
e default (12). |
| 97 draw_pos_text(&recorder, "This will be reduced to drawPosTextH.", true); | 97 draw_pos_text(&recorder, "This will be reduced to drawPosTextH.", true); |
| 98 SkRecordReduceDrawPosTextStrength(&record); | 98 SkRecordReduceDrawPosTextStrength(&record); |
| 99 | 99 |
| 100 const SkRecords::DrawPosTextH* original = | 100 const SkRecords::DrawPosTextH* original = |
| 101 assert_type<SkRecords::DrawPosTextH>(r, record, 0); | 101 assert_type<SkRecords::DrawPosTextH>(r, record, 0); |
| 102 | 102 |
| 103 // This should wrap the original DrawPosTextH with minY and maxY. | 103 // This should wrap the original DrawPosTextH with minY and maxY. |
| 104 SkRecordBoundDrawPosTextH(&record); | 104 SkRecordBoundDrawPosTextH(&record); |
| 105 | 105 |
| 106 const SkRecords::BoundedDrawPosTextH* bounded = | 106 const SkRecords::BoundedDrawPosTextH* bounded = |
| 107 assert_type<SkRecords::BoundedDrawPosTextH>(r, record, 0); | 107 assert_type<SkRecords::BoundedDrawPosTextH>(r, record, 0); |
| 108 | 108 |
| 109 const SkPaint defaults; | 109 const SkPaint defaults; |
| 110 REPORTER_ASSERT(r, bounded->base == original); | 110 REPORTER_ASSERT(r, bounded->base == original); |
| 111 REPORTER_ASSERT(r, bounded->minY <= SK_Scalar1 - defaults.getTextSize()); | 111 REPORTER_ASSERT(r, bounded->minY <= SK_Scalar1 - defaults.getTextSize()); |
| 112 REPORTER_ASSERT(r, bounded->maxY >= SK_Scalar1 + defaults.getTextSize()); | 112 REPORTER_ASSERT(r, bounded->maxY >= SK_Scalar1 + defaults.getTextSize()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 DEF_TEST(RecordOpts_NoopDrawSaveRestore, r) { | 115 DEF_TEST(RecordOpts_NoopDrawSaveRestore, r) { |
| 116 SkRecord record; | 116 SkRecord record; |
| 117 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 117 SkRecorder recorder(&record, W, H); |
| 118 | 118 |
| 119 // The save and restore are pointless if there's only draw commands in the m
iddle. | 119 // The save and restore are pointless if there's only draw commands in the m
iddle. |
| 120 recorder.save(); | 120 recorder.save(); |
| 121 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint()); | 121 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint()); |
| 122 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint()); | 122 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint()); |
| 123 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint()); | 123 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint()); |
| 124 recorder.restore(); | 124 recorder.restore(); |
| 125 | 125 |
| 126 record.replace<SkRecords::NoOp>(2); // NoOps should be allowed. | 126 record.replace<SkRecords::NoOp>(2); // NoOps should be allowed. |
| 127 | 127 |
| 128 SkRecordNoopSaveRestores(&record); | 128 SkRecordNoopSaveRestores(&record); |
| 129 | 129 |
| 130 assert_type<SkRecords::NoOp>(r, record, 0); | 130 assert_type<SkRecords::NoOp>(r, record, 0); |
| 131 assert_type<SkRecords::DrawRect>(r, record, 1); | 131 assert_type<SkRecords::DrawRect>(r, record, 1); |
| 132 assert_type<SkRecords::NoOp>(r, record, 2); | 132 assert_type<SkRecords::NoOp>(r, record, 2); |
| 133 assert_type<SkRecords::DrawRect>(r, record, 3); | 133 assert_type<SkRecords::DrawRect>(r, record, 3); |
| 134 assert_type<SkRecords::NoOp>(r, record, 4); | 134 assert_type<SkRecords::NoOp>(r, record, 4); |
| 135 } | 135 } |
| 136 | 136 |
| 137 DEF_TEST(RecordOpts_SingleNoopSaveRestore, r) { | 137 DEF_TEST(RecordOpts_SingleNoopSaveRestore, r) { |
| 138 SkRecord record; | 138 SkRecord record; |
| 139 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 139 SkRecorder recorder(&record, W, H); |
| 140 | 140 |
| 141 recorder.save(); | 141 recorder.save(); |
| 142 recorder.clipRect(SkRect::MakeWH(200, 200)); | 142 recorder.clipRect(SkRect::MakeWH(200, 200)); |
| 143 recorder.restore(); | 143 recorder.restore(); |
| 144 | 144 |
| 145 SkRecordNoopSaveRestores(&record); | 145 SkRecordNoopSaveRestores(&record); |
| 146 for (unsigned i = 0; i < 3; i++) { | 146 for (unsigned i = 0; i < 3; i++) { |
| 147 assert_type<SkRecords::NoOp>(r, record, i); | 147 assert_type<SkRecords::NoOp>(r, record, i); |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 DEF_TEST(RecordOpts_NoopSaveRestores, r) { | 151 DEF_TEST(RecordOpts_NoopSaveRestores, r) { |
| 152 SkRecord record; | 152 SkRecord record; |
| 153 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 153 SkRecorder recorder(&record, W, H); |
| 154 | 154 |
| 155 // The second pass will clean up this pair after the first pass noops all th
e innards. | 155 // The second pass will clean up this pair after the first pass noops all th
e innards. |
| 156 recorder.save(); | 156 recorder.save(); |
| 157 // A simple pointless pair of save/restore. | 157 // A simple pointless pair of save/restore. |
| 158 recorder.save(); | 158 recorder.save(); |
| 159 recorder.restore(); | 159 recorder.restore(); |
| 160 | 160 |
| 161 // As long as we don't draw in there, everything is a noop. | 161 // As long as we don't draw in there, everything is a noop. |
| 162 recorder.save(); | 162 recorder.save(); |
| 163 recorder.clipRect(SkRect::MakeWH(200, 200)); | 163 recorder.clipRect(SkRect::MakeWH(200, 200)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 180 assert_type<SkRecords::NoOp>(r, *record, i); | 180 assert_type<SkRecords::NoOp>(r, *record, i); |
| 181 assert_type<SkRecords::NoOp>(r, *record, i+2); | 181 assert_type<SkRecords::NoOp>(r, *record, i+2); |
| 182 } else { | 182 } else { |
| 183 assert_type<SkRecords::SaveLayer>(r, *record, i); | 183 assert_type<SkRecords::SaveLayer>(r, *record, i); |
| 184 assert_type<SkRecords::Restore>(r, *record, i+2); | 184 assert_type<SkRecords::Restore>(r, *record, i+2); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 DEF_TEST(RecordOpts_NoopSaveLayerDrawRestore, r) { | 188 DEF_TEST(RecordOpts_NoopSaveLayerDrawRestore, r) { |
| 189 SkRecord record; | 189 SkRecord record; |
| 190 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 190 SkRecorder recorder(&record, W, H); |
| 191 | 191 |
| 192 SkRect bounds = SkRect::MakeWH(100, 200); | 192 SkRect bounds = SkRect::MakeWH(100, 200); |
| 193 SkRect draw = SkRect::MakeWH(50, 60); | 193 SkRect draw = SkRect::MakeWH(50, 60); |
| 194 | 194 |
| 195 SkPaint goodLayerPaint, badLayerPaint, worseLayerPaint; | 195 SkPaint goodLayerPaint, badLayerPaint, worseLayerPaint; |
| 196 goodLayerPaint.setColor(0x03000000); // Only alpha. | 196 goodLayerPaint.setColor(0x03000000); // Only alpha. |
| 197 badLayerPaint.setColor( 0x03040506); // Not only alpha. | 197 badLayerPaint.setColor( 0x03040506); // Not only alpha. |
| 198 worseLayerPaint.setXfermodeMode(SkXfermode::kDstIn_Mode); // Any effect wil
l do. | 198 worseLayerPaint.setXfermodeMode(SkXfermode::kDstIn_Mode); // Any effect wil
l do. |
| 199 | 199 |
| 200 SkPaint goodDrawPaint, badDrawPaint; | 200 SkPaint goodDrawPaint, badDrawPaint; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 // SaveLayer/Restore removed: we can fold in the alpha! | 236 // SaveLayer/Restore removed: we can fold in the alpha! |
| 237 recorder.saveLayer(NULL, &goodLayerPaint); | 237 recorder.saveLayer(NULL, &goodLayerPaint); |
| 238 recorder.drawRect(draw, goodDrawPaint); | 238 recorder.drawRect(draw, goodDrawPaint); |
| 239 recorder.restore(); | 239 recorder.restore(); |
| 240 assert_savelayer_restore(r, &record, 15, true); | 240 assert_savelayer_restore(r, &record, 15, true); |
| 241 | 241 |
| 242 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
cord, 16); | 242 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
cord, 16); |
| 243 REPORTER_ASSERT(r, drawRect != NULL); | 243 REPORTER_ASSERT(r, drawRect != NULL); |
| 244 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); | 244 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); |
| 245 } | 245 } |
| OLD | NEW |