OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 p.setXfermodeMode(SkXfermode::kClear_Mode); | 134 p.setXfermodeMode(SkXfermode::kClear_Mode); |
135 rastBuilder->addLayer(p, SK_Scalar1*3/2, SK_Scalar1*3/2); | 135 rastBuilder->addLayer(p, SK_Scalar1*3/2, SK_Scalar1*3/2); |
136 | 136 |
137 p.setXfermode(nullptr); | 137 p.setXfermode(nullptr); |
138 rastBuilder->addLayer(p); | 138 rastBuilder->addLayer(p); |
139 } | 139 } |
140 | 140 |
141 static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { | 141 static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
142 rastBuilder->addLayer(p); | 142 rastBuilder->addLayer(p); |
143 | 143 |
144 p.setPathEffect(SkDiscretePathEffect::Make(SK_Scalar1*4, SK_Scalar1*3)); | 144 p.setPathEffect(SkDiscretePathEffect::Create(SK_Scalar1*4, SK_Scalar1*3))->u
nref(); |
145 p.setXfermodeMode(SkXfermode::kSrcOut_Mode); | 145 p.setXfermodeMode(SkXfermode::kSrcOut_Mode); |
146 rastBuilder->addLayer(p); | 146 rastBuilder->addLayer(p); |
147 } | 147 } |
148 | 148 |
149 static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { | 149 static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
150 rastBuilder->addLayer(p); | 150 rastBuilder->addLayer(p); |
151 | 151 |
152 p.setAntiAlias(false); | 152 p.setAntiAlias(false); |
153 SkLayerRasterizer::Builder rastBuilder2; | 153 SkLayerRasterizer::Builder rastBuilder2; |
154 r5(&rastBuilder2, p); | 154 r5(&rastBuilder2, p); |
(...skipping 22 matching lines...) Expand all Loading... |
177 private: | 177 private: |
178 SkScalar fRadius; | 178 SkScalar fRadius; |
179 | 179 |
180 typedef Sk2DPathEffect INHERITED; | 180 typedef Sk2DPathEffect INHERITED; |
181 }; | 181 }; |
182 | 182 |
183 static void r7(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { | 183 static void r7(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
184 SkMatrix lattice; | 184 SkMatrix lattice; |
185 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); | 185 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); |
186 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); | 186 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); |
187 p.setPathEffect(sk_make_sp<Dot2DPathEffect>(SK_Scalar1*4, lattice)); | 187 p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*4, lattice))->unref(); |
188 rastBuilder->addLayer(p); | 188 rastBuilder->addLayer(p); |
189 } | 189 } |
190 | 190 |
191 static void r8(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { | 191 static void r8(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
192 rastBuilder->addLayer(p); | 192 rastBuilder->addLayer(p); |
193 | 193 |
194 SkMatrix lattice; | 194 SkMatrix lattice; |
195 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); | 195 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); |
196 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); | 196 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); |
197 p.setPathEffect(sk_make_sp<Dot2DPathEffect>(SK_Scalar1*2, lattice)); | 197 p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*2, lattice))->unref(); |
198 p.setXfermodeMode(SkXfermode::kClear_Mode); | 198 p.setXfermodeMode(SkXfermode::kClear_Mode); |
199 rastBuilder->addLayer(p); | 199 rastBuilder->addLayer(p); |
200 | 200 |
201 p.setPathEffect(nullptr); | 201 p.setPathEffect(nullptr); |
202 p.setXfermode(nullptr); | 202 p.setXfermode(nullptr); |
203 p.setStyle(SkPaint::kStroke_Style); | 203 p.setStyle(SkPaint::kStroke_Style); |
204 p.setStrokeWidth(SK_Scalar1); | 204 p.setStrokeWidth(SK_Scalar1); |
205 rastBuilder->addLayer(p); | 205 rastBuilder->addLayer(p); |
206 } | 206 } |
207 | 207 |
208 static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { | 208 static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
209 rastBuilder->addLayer(p); | 209 rastBuilder->addLayer(p); |
210 | 210 |
211 SkMatrix lattice; | 211 SkMatrix lattice; |
212 lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); | 212 lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); |
213 lattice.postRotate(SkIntToScalar(30), 0, 0); | 213 lattice.postRotate(SkIntToScalar(30), 0, 0); |
214 p.setPathEffect(SkLine2DPathEffect::Make(SK_Scalar1*2, lattice)); | 214 p.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1*2, lattice))->unref(); |
215 p.setXfermodeMode(SkXfermode::kClear_Mode); | 215 p.setXfermodeMode(SkXfermode::kClear_Mode); |
216 rastBuilder->addLayer(p); | 216 rastBuilder->addLayer(p); |
217 | 217 |
218 p.setPathEffect(nullptr); | 218 p.setPathEffect(nullptr); |
219 p.setXfermode(nullptr); | 219 p.setXfermode(nullptr); |
220 p.setStyle(SkPaint::kStroke_Style); | 220 p.setStyle(SkPaint::kStroke_Style); |
221 p.setStrokeWidth(SK_Scalar1); | 221 p.setStrokeWidth(SK_Scalar1); |
222 rastBuilder->addLayer(p); | 222 rastBuilder->addLayer(p); |
223 } | 223 } |
224 | 224 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 paint.setColorFilter(lightingFilter)->unref(); | 409 paint.setColorFilter(lightingFilter)->unref(); |
410 canvas->drawLine(start.fX, start.fY, stop.fX, stop.fY, paint); // should
not be green | 410 canvas->drawLine(start.fX, start.fY, stop.fX, stop.fY, paint); // should
not be green |
411 paint.setXfermode(nullptr); | 411 paint.setXfermode(nullptr); |
412 paint.setColorFilter(nullptr); | 412 paint.setColorFilter(nullptr); |
413 | 413 |
414 // rectangle | 414 // rectangle |
415 paint.setStyle(SkPaint::kFill_Style); | 415 paint.setStyle(SkPaint::kFill_Style); |
416 canvas->translate(SkIntToScalar(50), 0); | 416 canvas->translate(SkIntToScalar(50), 0); |
417 paint.setColor(SK_ColorYELLOW); | 417 paint.setColor(SK_ColorYELLOW); |
418 paint.setShader(linear); | 418 paint.setShader(linear); |
419 paint.setPathEffect(pathEffectTest()); | 419 paint.setPathEffect(pathEffectTest())->unref(); |
420 canvas->drawRect(rect, paint); | 420 canvas->drawRect(rect, paint); |
421 paint.setPathEffect(nullptr); | 421 paint.setPathEffect(nullptr); |
422 | 422 |
423 // circle w/ emboss & transparent (exercises 3dshader) | 423 // circle w/ emboss & transparent (exercises 3dshader) |
424 canvas->translate(SkIntToScalar(50), 0); | 424 canvas->translate(SkIntToScalar(50), 0); |
425 paint.setMaskFilter(embossFilter)->unref(); | 425 paint.setMaskFilter(embossFilter)->unref(); |
426 canvas->drawOval(rect, paint); | 426 canvas->drawOval(rect, paint); |
427 canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); | 427 canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); |
428 // paint.setShader(transparentShader)->unref(); | 428 // paint.setShader(transparentShader)->unref(); |
429 canvas->drawOval(rect, paint); | 429 canvas->drawOval(rect, paint); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 paint.setTextEncoding(SkPaint::kUTF8_TextEncoding); | 474 paint.setTextEncoding(SkPaint::kUTF8_TextEncoding); |
475 canvas->restore(); | 475 canvas->restore(); |
476 } | 476 } |
477 | 477 |
478 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned m
odi) { | 478 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned m
odi) { |
479 fClickPt.set(x, y); | 479 fClickPt.set(x, y); |
480 this->inval(nullptr); | 480 this->inval(nullptr); |
481 return this->INHERITED::onFindClickHandler(x, y, modi); | 481 return this->INHERITED::onFindClickHandler(x, y, modi); |
482 } | 482 } |
483 | 483 |
484 sk_sp<SkPathEffect> pathEffectTest() { | 484 SkPathEffect* pathEffectTest() { |
485 static const int gXY[] = { 1, 0, 0, -1, 2, -1, 3, 0, 2, 1, 0, 1 }; | 485 static const int gXY[] = { 1, 0, 0, -1, 2, -1, 3, 0, 2, 1, 0, 1 }; |
486 SkScalar gPhase = 0; | 486 SkScalar gPhase = 0; |
487 SkPath path; | 487 SkPath path; |
488 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); | 488 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); |
489 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) | 489 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) |
490 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); | 490 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); |
491 path.close(); | 491 path.close(); |
492 path.offset(SkIntToScalar(-6), 0); | 492 path.offset(SkIntToScalar(-6), 0); |
493 auto outer = SkPath1DPathEffect::Make(path, SkIntToScalar(12), | 493 SkPathEffect* outer = SkPath1DPathEffect::Create(path, SkIntToScalar(12)
, |
494 gPhase, SkPath1DPathEffect::kRotate_Style); | 494 gPhase, SkPath1DPathEffect::kRotate_Style); |
495 auto inner = SkDiscretePathEffect::Make(SkIntToScalar(2), | 495 SkPathEffect* inner = SkDiscretePathEffect::Create(SkIntToScalar(2), |
496 SkIntToScalar(1)/10); // SkCornerPathEffect(SkIntToScalar(2)); | 496 SkIntToScalar(1)/10); // SkCornerPathEffect(SkIntToScalar(2)); |
497 return SkComposePathEffect::Make(outer, inner); | 497 SkPathEffect* result = SkComposePathEffect::Create(outer, inner); |
| 498 outer->unref(); |
| 499 inner->unref(); |
| 500 return result; |
498 } | 501 } |
499 | 502 |
500 sk_sp<SkShader> shaderTest() { | 503 sk_sp<SkShader> shaderTest() { |
501 SkPoint pts[] = { { 0, 0, }, { SkIntToScalar(100), 0 } }; | 504 SkPoint pts[] = { { 0, 0, }, { SkIntToScalar(100), 0 } }; |
502 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; | 505 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; |
503 auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, | 506 auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, |
504 2, SkShader::kClamp_TileMode); | 507 2, SkShader::kClamp_TileMode); |
505 pts[1].set(0, SkIntToScalar(100)); | 508 pts[1].set(0, SkIntToScalar(100)); |
506 SkColor colors2[] = {SK_ColorBLACK, SkColorSetARGB(0x80, 0, 0, 0)}; | 509 SkColor colors2[] = {SK_ColorBLACK, SkColorSetARGB(0x80, 0, 0, 0)}; |
507 auto shaderB = SkGradientShader::MakeLinear(pts, colors2, nullptr, | 510 auto shaderB = SkGradientShader::MakeLinear(pts, colors2, nullptr, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 private: | 566 private: |
564 SkPoint fClickPt; | 567 SkPoint fClickPt; |
565 SkBitmap fBug, fTb, fTx; | 568 SkBitmap fBug, fTb, fTx; |
566 typedef SampleView INHERITED; | 569 typedef SampleView INHERITED; |
567 }; | 570 }; |
568 | 571 |
569 ////////////////////////////////////////////////////////////////////////////// | 572 ////////////////////////////////////////////////////////////////////////////// |
570 | 573 |
571 static SkView* MyFactory() { return new DemoView; } | 574 static SkView* MyFactory() { return new DemoView; } |
572 static SkViewRegister reg(MyFactory); | 575 static SkViewRegister reg(MyFactory); |
OLD | NEW |