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 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 assert_type<SkRecords::NoOp>(r, record, index); | 70 assert_type<SkRecords::NoOp>(r, record, index); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 DEF_TEST(RecordOpts_SaveSaveLayerRestoreRestore, r) { | 74 DEF_TEST(RecordOpts_SaveSaveLayerRestoreRestore, r) { |
75 SkRecord record; | 75 SkRecord record; |
76 SkRecorder recorder(&record, W, H); | 76 SkRecorder recorder(&record, W, H); |
77 | 77 |
78 // A previous bug NoOp'd away the first 3 commands. | 78 // A previous bug NoOp'd away the first 3 commands. |
79 recorder.save(); | 79 recorder.save(); |
80 recorder.saveLayer(NULL, NULL); | 80 recorder.saveLayer(nullptr, nullptr); |
81 recorder.restore(); | 81 recorder.restore(); |
82 recorder.restore(); | 82 recorder.restore(); |
83 | 83 |
84 SkRecordNoopSaveRestores(&record); | 84 SkRecordNoopSaveRestores(&record); |
85 switch (record.count()) { | 85 switch (record.count()) { |
86 case 4: | 86 case 4: |
87 assert_type<SkRecords::Save> (r, record, 0); | 87 assert_type<SkRecords::Save> (r, record, 0); |
88 assert_type<SkRecords::SaveLayer>(r, record, 1); | 88 assert_type<SkRecords::SaveLayer>(r, record, 1); |
89 assert_type<SkRecords::Restore> (r, record, 2); | 89 assert_type<SkRecords::Restore> (r, record, 2); |
90 assert_type<SkRecords::Restore> (r, record, 3); | 90 assert_type<SkRecords::Restore> (r, record, 3); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 SkPaint alphaOnlyLayerPaint, translucentLayerPaint, xfermodeLayerPaint; | 124 SkPaint alphaOnlyLayerPaint, translucentLayerPaint, xfermodeLayerPaint; |
125 alphaOnlyLayerPaint.setColor(0x03000000); // Only alpha. | 125 alphaOnlyLayerPaint.setColor(0x03000000); // Only alpha. |
126 translucentLayerPaint.setColor(0x03040506); // Not only alpha. | 126 translucentLayerPaint.setColor(0x03040506); // Not only alpha. |
127 xfermodeLayerPaint.setXfermodeMode(SkXfermode::kDstIn_Mode); // Any effect
will do. | 127 xfermodeLayerPaint.setXfermodeMode(SkXfermode::kDstIn_Mode); // Any effect
will do. |
128 | 128 |
129 SkPaint opaqueDrawPaint, translucentDrawPaint; | 129 SkPaint opaqueDrawPaint, translucentDrawPaint; |
130 opaqueDrawPaint.setColor(0xFF020202); // Opaque. | 130 opaqueDrawPaint.setColor(0xFF020202); // Opaque. |
131 translucentDrawPaint.setColor(0x0F020202); // Not opaque. | 131 translucentDrawPaint.setColor(0x0F020202); // Not opaque. |
132 | 132 |
133 // SaveLayer/Restore removed: No paint = no point. | 133 // SaveLayer/Restore removed: No paint = no point. |
134 recorder.saveLayer(NULL, NULL); | 134 recorder.saveLayer(nullptr, nullptr); |
135 recorder.drawRect(draw, opaqueDrawPaint); | 135 recorder.drawRect(draw, opaqueDrawPaint); |
136 recorder.restore(); | 136 recorder.restore(); |
137 assert_savelayer_restore(r, &record, 0, true); | 137 assert_savelayer_restore(r, &record, 0, true); |
138 | 138 |
139 // Bounds don't matter. | 139 // Bounds don't matter. |
140 recorder.saveLayer(&bounds, NULL); | 140 recorder.saveLayer(&bounds, nullptr); |
141 recorder.drawRect(draw, opaqueDrawPaint); | 141 recorder.drawRect(draw, opaqueDrawPaint); |
142 recorder.restore(); | 142 recorder.restore(); |
143 assert_savelayer_restore(r, &record, 3, true); | 143 assert_savelayer_restore(r, &record, 3, true); |
144 | 144 |
145 // TODO(mtklein): test case with null draw paint | 145 // TODO(mtklein): test case with null draw paint |
146 | 146 |
147 // No change: layer paint isn't alpha-only. | 147 // No change: layer paint isn't alpha-only. |
148 recorder.saveLayer(NULL, &translucentLayerPaint); | 148 recorder.saveLayer(nullptr, &translucentLayerPaint); |
149 recorder.drawRect(draw, opaqueDrawPaint); | 149 recorder.drawRect(draw, opaqueDrawPaint); |
150 recorder.restore(); | 150 recorder.restore(); |
151 assert_savelayer_restore(r, &record, 6, false); | 151 assert_savelayer_restore(r, &record, 6, false); |
152 | 152 |
153 // No change: layer paint has an effect. | 153 // No change: layer paint has an effect. |
154 recorder.saveLayer(NULL, &xfermodeLayerPaint); | 154 recorder.saveLayer(nullptr, &xfermodeLayerPaint); |
155 recorder.drawRect(draw, opaqueDrawPaint); | 155 recorder.drawRect(draw, opaqueDrawPaint); |
156 recorder.restore(); | 156 recorder.restore(); |
157 assert_savelayer_restore(r, &record, 9, false); | 157 assert_savelayer_restore(r, &record, 9, false); |
158 | 158 |
159 // SaveLayer/Restore removed: we can fold in the alpha! | 159 // SaveLayer/Restore removed: we can fold in the alpha! |
160 recorder.saveLayer(NULL, &alphaOnlyLayerPaint); | 160 recorder.saveLayer(nullptr, &alphaOnlyLayerPaint); |
161 recorder.drawRect(draw, translucentDrawPaint); | 161 recorder.drawRect(draw, translucentDrawPaint); |
162 recorder.restore(); | 162 recorder.restore(); |
163 assert_savelayer_restore(r, &record, 12, true); | 163 assert_savelayer_restore(r, &record, 12, true); |
164 | 164 |
165 // SaveLayer/Restore removed: we can fold in the alpha! | 165 // SaveLayer/Restore removed: we can fold in the alpha! |
166 recorder.saveLayer(NULL, &alphaOnlyLayerPaint); | 166 recorder.saveLayer(nullptr, &alphaOnlyLayerPaint); |
167 recorder.drawRect(draw, opaqueDrawPaint); | 167 recorder.drawRect(draw, opaqueDrawPaint); |
168 recorder.restore(); | 168 recorder.restore(); |
169 assert_savelayer_restore(r, &record, 15, true); | 169 assert_savelayer_restore(r, &record, 15, true); |
170 | 170 |
171 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
cord, 16); | 171 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
cord, 16); |
172 REPORTER_ASSERT(r, drawRect != NULL); | 172 REPORTER_ASSERT(r, drawRect != nullptr); |
173 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); | 173 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); |
174 } | 174 } |
175 | 175 |
176 static void assert_merge_svg_opacity_and_filter_layers(skiatest::Reporter* r, | 176 static void assert_merge_svg_opacity_and_filter_layers(skiatest::Reporter* r, |
177 SkRecord* record, | 177 SkRecord* record, |
178 int i, | 178 int i, |
179 bool shouldBeNoOped) { | 179 bool shouldBeNoOped) { |
180 SkRecordMergeSvgOpacityAndFilterLayers(record); | 180 SkRecordMergeSvgOpacityAndFilterLayers(record); |
181 if (shouldBeNoOped) { | 181 if (shouldBeNoOped) { |
182 assert_type<SkRecords::NoOp>(r, *record, i); | 182 assert_type<SkRecords::NoOp>(r, *record, i); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 shapePaint.setColor(SK_ColorWHITE); | 216 shapePaint.setColor(SK_ColorWHITE); |
217 canvas->drawRect(SkRect::MakeWH(SkIntToScalar(50), SkIntToScalar(50)), s
hapePaint); | 217 canvas->drawRect(SkRect::MakeWH(SkIntToScalar(50), SkIntToScalar(50)), s
hapePaint); |
218 shape.reset(recorder.endRecordingAsPicture()); | 218 shape.reset(recorder.endRecordingAsPicture()); |
219 } | 219 } |
220 translucentFilterLayerPaint.setImageFilter(SkPictureImageFilter::Create(shap
e))->unref(); | 220 translucentFilterLayerPaint.setImageFilter(SkPictureImageFilter::Create(shap
e))->unref(); |
221 | 221 |
222 int index = 0; | 222 int index = 0; |
223 | 223 |
224 { | 224 { |
225 // Any combination of these should cause the pattern to be optimized. | 225 // Any combination of these should cause the pattern to be optimized. |
226 SkRect* firstBounds[] = { NULL, &bounds }; | 226 SkRect* firstBounds[] = { nullptr, &bounds }; |
227 SkPaint* firstPaints[] = { NULL, &alphaOnlyLayerPaint }; | 227 SkPaint* firstPaints[] = { nullptr, &alphaOnlyLayerPaint }; |
228 SkRect* secondBounds[] = { NULL, &bounds }; | 228 SkRect* secondBounds[] = { nullptr, &bounds }; |
229 SkPaint* secondPaints[] = { &opaqueFilterLayerPaint, &translucentFilterL
ayerPaint }; | 229 SkPaint* secondPaints[] = { &opaqueFilterLayerPaint, &translucentFilterL
ayerPaint }; |
230 | 230 |
231 for (size_t i = 0; i < SK_ARRAY_COUNT(firstBounds); ++ i) { | 231 for (size_t i = 0; i < SK_ARRAY_COUNT(firstBounds); ++ i) { |
232 for (size_t j = 0; j < SK_ARRAY_COUNT(firstPaints); ++j) { | 232 for (size_t j = 0; j < SK_ARRAY_COUNT(firstPaints); ++j) { |
233 for (size_t k = 0; k < SK_ARRAY_COUNT(secondBounds); ++k) { | 233 for (size_t k = 0; k < SK_ARRAY_COUNT(secondBounds); ++k) { |
234 for (size_t m = 0; m < SK_ARRAY_COUNT(secondPaints); ++m) { | 234 for (size_t m = 0; m < SK_ARRAY_COUNT(secondPaints); ++m) { |
235 recorder.saveLayer(firstBounds[i], firstPaints[j]); | 235 recorder.saveLayer(firstBounds[i], firstPaints[j]); |
236 recorder.save(); | 236 recorder.save(); |
237 recorder.clipRect(clip); | 237 recorder.clipRect(clip); |
238 recorder.saveLayer(secondBounds[k], secondPaints[m]); | 238 recorder.saveLayer(secondBounds[k], secondPaints[m]); |
239 recorder.restore(); | 239 recorder.restore(); |
240 recorder.restore(); | 240 recorder.restore(); |
241 recorder.restore(); | 241 recorder.restore(); |
242 assert_merge_svg_opacity_and_filter_layers(r, &record, i
ndex, true); | 242 assert_merge_svg_opacity_and_filter_layers(r, &record, i
ndex, true); |
243 index += 7; | 243 index += 7; |
244 } | 244 } |
245 } | 245 } |
246 } | 246 } |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 // These should cause the pattern to stay unoptimized: | 250 // These should cause the pattern to stay unoptimized: |
251 struct { | 251 struct { |
252 SkPaint* firstPaint; | 252 SkPaint* firstPaint; |
253 SkPaint* secondPaint; | 253 SkPaint* secondPaint; |
254 } noChangeTests[] = { | 254 } noChangeTests[] = { |
255 // No change: NULL filter layer paint not implemented. | 255 // No change: nullptr filter layer paint not implemented. |
256 { &alphaOnlyLayerPaint, NULL }, | 256 { &alphaOnlyLayerPaint, nullptr }, |
257 // No change: layer paint is not alpha-only. | 257 // No change: layer paint is not alpha-only. |
258 { &translucentLayerPaint, &opaqueFilterLayerPaint }, | 258 { &translucentLayerPaint, &opaqueFilterLayerPaint }, |
259 // No change: layer paint has an xfereffect. | 259 // No change: layer paint has an xfereffect. |
260 { &xfermodePaint, &opaqueFilterLayerPaint }, | 260 { &xfermodePaint, &opaqueFilterLayerPaint }, |
261 // No change: filter layer paint has an xfereffect. | 261 // No change: filter layer paint has an xfereffect. |
262 { &alphaOnlyLayerPaint, &xfermodePaint }, | 262 { &alphaOnlyLayerPaint, &xfermodePaint }, |
263 // No change: layer paint has a color filter. | 263 // No change: layer paint has a color filter. |
264 { &colorFilterPaint, &opaqueFilterLayerPaint }, | 264 { &colorFilterPaint, &opaqueFilterLayerPaint }, |
265 // No change: filter layer paint has a color filter (until the optimizat
ion accounts for | 265 // No change: filter layer paint has a color filter (until the optimizat
ion accounts for |
266 // constant color draws that can filter the color). | 266 // constant color draws that can filter the color). |
267 { &alphaOnlyLayerPaint, &colorFilterPaint } | 267 { &alphaOnlyLayerPaint, &colorFilterPaint } |
268 }; | 268 }; |
269 | 269 |
270 for (size_t i = 0; i < SK_ARRAY_COUNT(noChangeTests); ++i) { | 270 for (size_t i = 0; i < SK_ARRAY_COUNT(noChangeTests); ++i) { |
271 recorder.saveLayer(NULL, noChangeTests[i].firstPaint); | 271 recorder.saveLayer(nullptr, noChangeTests[i].firstPaint); |
272 recorder.save(); | 272 recorder.save(); |
273 recorder.clipRect(clip); | 273 recorder.clipRect(clip); |
274 recorder.saveLayer(NULL, noChangeTests[i].secondPaint); | 274 recorder.saveLayer(nullptr, noChangeTests[i].secondPaint); |
275 recorder.restore(); | 275 recorder.restore(); |
276 recorder.restore(); | 276 recorder.restore(); |
277 recorder.restore(); | 277 recorder.restore(); |
278 assert_merge_svg_opacity_and_filter_layers(r, &record, index, false); | 278 assert_merge_svg_opacity_and_filter_layers(r, &record, index, false); |
279 index += 7; | 279 index += 7; |
280 } | 280 } |
281 | 281 |
282 // Test the folded alpha value. | 282 // Test the folded alpha value. |
283 recorder.saveLayer(NULL, &alphaOnlyLayerPaint); | 283 recorder.saveLayer(nullptr, &alphaOnlyLayerPaint); |
284 recorder.save(); | 284 recorder.save(); |
285 recorder.clipRect(clip); | 285 recorder.clipRect(clip); |
286 recorder.saveLayer(NULL, &opaqueFilterLayerPaint); | 286 recorder.saveLayer(nullptr, &opaqueFilterLayerPaint); |
287 recorder.restore(); | 287 recorder.restore(); |
288 recorder.restore(); | 288 recorder.restore(); |
289 recorder.restore(); | 289 recorder.restore(); |
290 assert_merge_svg_opacity_and_filter_layers(r, &record, index, true); | 290 assert_merge_svg_opacity_and_filter_layers(r, &record, index, true); |
291 | 291 |
292 const SkRecords::SaveLayer* saveLayer = assert_type<SkRecords::SaveLayer>(r,
record, index + 3); | 292 const SkRecords::SaveLayer* saveLayer = assert_type<SkRecords::SaveLayer>(r,
record, index + 3); |
293 REPORTER_ASSERT(r, saveLayer != NULL); | 293 REPORTER_ASSERT(r, saveLayer != nullptr); |
294 REPORTER_ASSERT(r, saveLayer->paint->getColor() == 0x03020202); | 294 REPORTER_ASSERT(r, saveLayer->paint->getColor() == 0x03020202); |
295 | 295 |
296 index += 7; | 296 index += 7; |
297 | 297 |
298 // Test that currently we do not fold alphas for patterns without the clip.
This is just not | 298 // Test that currently we do not fold alphas for patterns without the clip.
This is just not |
299 // implemented. | 299 // implemented. |
300 recorder.saveLayer(NULL, &alphaOnlyLayerPaint); | 300 recorder.saveLayer(nullptr, &alphaOnlyLayerPaint); |
301 recorder.saveLayer(NULL, &opaqueFilterLayerPaint); | 301 recorder.saveLayer(nullptr, &opaqueFilterLayerPaint); |
302 recorder.restore(); | 302 recorder.restore(); |
303 recorder.restore(); | 303 recorder.restore(); |
304 SkRecordMergeSvgOpacityAndFilterLayers(&record); | 304 SkRecordMergeSvgOpacityAndFilterLayers(&record); |
305 assert_type<SkRecords::SaveLayer>(r, record, index); | 305 assert_type<SkRecords::SaveLayer>(r, record, index); |
306 assert_type<SkRecords::SaveLayer>(r, record, index + 1); | 306 assert_type<SkRecords::SaveLayer>(r, record, index + 1); |
307 assert_type<SkRecords::Restore>(r, record, index + 2); | 307 assert_type<SkRecords::Restore>(r, record, index + 2); |
308 assert_type<SkRecords::Restore>(r, record, index + 3); | 308 assert_type<SkRecords::Restore>(r, record, index + 3); |
309 index += 4; | 309 index += 4; |
310 } | 310 } |
OLD | NEW |