| 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 "gm.h" | 8 #include "gm.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkPath.h" | 10 #include "SkPath.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 canvas->drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0), &drawPain
t); | 93 canvas->drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0), &drawPain
t); |
| 94 canvas->restore(); | 94 canvas->restore(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Draws an pattern that can be optimized by alpha folding outer savelayer alpha
value to | 97 // Draws an pattern that can be optimized by alpha folding outer savelayer alpha
value to |
| 98 // inner savelayer. We know that alpha folding happens to inner savelayer, so ad
d detector there. | 98 // inner savelayer. We know that alpha folding happens to inner savelayer, so ad
d detector there. |
| 99 static void draw_svg_opacity_and_filter_layer_sequence(SkCanvas* canvas, SkColor
shapeColor, | 99 static void draw_svg_opacity_and_filter_layer_sequence(SkCanvas* canvas, SkColor
shapeColor, |
| 100 InstallDetectorFunc insta
llDetector) { | 100 InstallDetectorFunc insta
llDetector) { |
| 101 | 101 |
| 102 SkRect targetRect(SkRect::MakeWH(SkIntToScalar(kTestRectSize), SkIntToScalar
(kTestRectSize))); | 102 SkRect targetRect(SkRect::MakeWH(SkIntToScalar(kTestRectSize), SkIntToScalar
(kTestRectSize))); |
| 103 SkAutoTUnref<SkPicture> shape; | 103 sk_sp<SkPicture> shape; |
| 104 { | 104 { |
| 105 SkPictureRecorder recorder; | 105 SkPictureRecorder recorder; |
| 106 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kTestRectSize +
2), | 106 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kTestRectSize +
2), |
| 107 SkIntToScalar(kTestRectSize +
2)); | 107 SkIntToScalar(kTestRectSize +
2)); |
| 108 SkPaint shapePaint; | 108 SkPaint shapePaint; |
| 109 shapePaint.setColor(shapeColor); | 109 shapePaint.setColor(shapeColor); |
| 110 canvas->drawRect(targetRect, shapePaint); | 110 canvas->drawRect(targetRect, shapePaint); |
| 111 shape.reset(recorder.endRecordingAsPicture()); | 111 shape = recorder.finishRecordingAsPicture(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 SkPaint layerPaint; | 114 SkPaint layerPaint; |
| 115 layerPaint.setColor(SkColorSetARGB(130, 0, 0, 0)); | 115 layerPaint.setColor(SkColorSetARGB(130, 0, 0, 0)); |
| 116 canvas->saveLayer(&targetRect, &layerPaint); | 116 canvas->saveLayer(&targetRect, &layerPaint); |
| 117 canvas->save(); | 117 canvas->save(); |
| 118 canvas->clipRect(targetRect); | 118 canvas->clipRect(targetRect); |
| 119 SkPaint drawPaint; | 119 SkPaint drawPaint; |
| 120 drawPaint.setImageFilter(SkPictureImageFilter::Create(shape))->unref
(); | 120 drawPaint.setImageFilter(SkPictureImageFilter::Create(shape.get()))-
>unref(); |
| 121 installDetector(&drawPaint); | 121 installDetector(&drawPaint); |
| 122 canvas->saveLayer(&targetRect, &drawPaint); | 122 canvas->saveLayer(&targetRect, &drawPaint); |
| 123 canvas->restore(); | 123 canvas->restore(); |
| 124 canvas->restore(); | 124 canvas->restore(); |
| 125 canvas->restore(); | 125 canvas->restore(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Draws two columns of rectangles. The test is correct when: | 128 // Draws two columns of rectangles. The test is correct when: |
| 129 // - Left and right columns always identical | 129 // - Left and right columns always identical |
| 130 // - First 3 rows are green, with a white dent in the middle row | 130 // - First 3 rows are green, with a white dent in the middle row |
| (...skipping 23 matching lines...) Expand all Loading... |
| 154 | 154 |
| 155 TestVariantSequence drawTestSequence = funcs[k]; | 155 TestVariantSequence drawTestSequence = funcs[k]; |
| 156 drawTestSequence(canvas, shapeColor, no_detector_install); | 156 drawTestSequence(canvas, shapeColor, no_detector_install); |
| 157 canvas->flush(); | 157 canvas->flush(); |
| 158 canvas->translate(SkIntToScalar(kTestRectSize) + SkIntToScalar(1), SkInt
ToScalar(0)); | 158 canvas->translate(SkIntToScalar(kTestRectSize) + SkIntToScalar(1), SkInt
ToScalar(0)); |
| 159 { | 159 { |
| 160 SkPictureRecorder recorder; | 160 SkPictureRecorder recorder; |
| 161 drawTestSequence(recorder.beginRecording(SkIntToScalar(kTestRectSize
), | 161 drawTestSequence(recorder.beginRecording(SkIntToScalar(kTestRectSize
), |
| 162 SkIntToScalar(kTestRectSize
)), | 162 SkIntToScalar(kTestRectSize
)), |
| 163 shapeColor, no_detector_install); | 163 shapeColor, no_detector_install); |
| 164 SkAutoTUnref<SkPicture> optimizedPicture(recorder.endRecordingAsPict
ure()); | 164 recorder.finishRecordingAsPicture()->playback(canvas); |
| 165 optimizedPicture->playback(canvas); | |
| 166 canvas->flush(); | 165 canvas->flush(); |
| 167 } | 166 } |
| 168 canvas->restore(); | 167 canvas->restore(); |
| 169 canvas->translate(SkIntToScalar(0), SkIntToScalar(kTestRectSize) + SkInt
ToScalar(1)); | 168 canvas->translate(SkIntToScalar(0), SkIntToScalar(kTestRectSize) + SkInt
ToScalar(1)); |
| 170 } | 169 } |
| 171 | 170 |
| 172 // Draw the same layer related sequences, but manipulate the sequences so th
at the result is | 171 // Draw the same layer related sequences, but manipulate the sequences so th
at the result is |
| 173 // incorrect if the alpha is folded or folded incorrectly. These test the ob
servable state | 172 // incorrect if the alpha is folded or folded incorrectly. These test the ob
servable state |
| 174 // throughout the pixel pipeline, and thus may turn off the optimizations (t
his is why we | 173 // throughout the pixel pipeline, and thus may turn off the optimizations (t
his is why we |
| 175 // trigger the optimizations above). | 174 // trigger the optimizations above). |
| (...skipping 20 matching lines...) Expand all Loading... |
| 196 TestVariantSequence drawTestSequence = funcs[k]; | 195 TestVariantSequence drawTestSequence = funcs[k]; |
| 197 canvas->save(); | 196 canvas->save(); |
| 198 drawTestSequence(canvas, shapeColor, detectorInstallFunc); | 197 drawTestSequence(canvas, shapeColor, detectorInstallFunc); |
| 199 canvas->flush(); | 198 canvas->flush(); |
| 200 canvas->translate(SkIntToScalar(kTestRectSize) + SkIntToScalar(1
), SkIntToScalar(0)); | 199 canvas->translate(SkIntToScalar(kTestRectSize) + SkIntToScalar(1
), SkIntToScalar(0)); |
| 201 { | 200 { |
| 202 SkPictureRecorder recorder; | 201 SkPictureRecorder recorder; |
| 203 drawTestSequence(recorder.beginRecording(SkIntToScalar(kTest
RectSize), | 202 drawTestSequence(recorder.beginRecording(SkIntToScalar(kTest
RectSize), |
| 204 SkIntToScalar(kTest
RectSize)), | 203 SkIntToScalar(kTest
RectSize)), |
| 205 shapeColor, detectorInstallFunc); | 204 shapeColor, detectorInstallFunc); |
| 206 SkAutoTUnref<SkPicture> optimizedPicture(recorder.endRecordi
ngAsPicture()); | 205 recorder.finishRecordingAsPicture()->playback(canvas); |
| 207 optimizedPicture->playback(canvas); | |
| 208 canvas->flush(); | 206 canvas->flush(); |
| 209 } | 207 } |
| 210 | 208 |
| 211 canvas->restore(); | 209 canvas->restore(); |
| 212 canvas->translate(SkIntToScalar(0), SkIntToScalar(kTestRectSize)
+ SkIntToScalar(1)); | 210 canvas->translate(SkIntToScalar(0), SkIntToScalar(kTestRectSize)
+ SkIntToScalar(1)); |
| 213 } | 211 } |
| 214 | 212 |
| 215 } | 213 } |
| 216 } | 214 } |
| 217 } | 215 } |
| 218 | 216 |
| OLD | NEW |