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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 SkEmbossMaskFilter::Light light; | 377 SkEmbossMaskFilter::Light light; |
378 light.fDirection[0] = SK_Scalar1/2; | 378 light.fDirection[0] = SK_Scalar1/2; |
379 light.fDirection[1] = SK_Scalar1/2; | 379 light.fDirection[1] = SK_Scalar1/2; |
380 light.fDirection[2] = SK_Scalar1/3; | 380 light.fDirection[2] = SK_Scalar1/3; |
381 light.fAmbient = 0x48; | 381 light.fAmbient = 0x48; |
382 light.fSpecular = 0x80; | 382 light.fSpecular = 0x80; |
383 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(12)/5); | 383 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(12)/5); |
384 SkMaskFilter* embossFilter = SkEmbossMaskFilter::Create(sigma, light); | 384 SkMaskFilter* embossFilter = SkEmbossMaskFilter::Create(sigma, light); |
385 | 385 |
386 SkXfermode* xfermode = SkXfermode::Create(SkXfermode::kXor_Mode); | 386 SkXfermode* xfermode = SkXfermode::Create(SkXfermode::kXor_Mode); |
387 auto lightingFilter = SkColorMatrixFilter::MakeLightingFilter( | 387 SkColorFilter* lightingFilter = SkColorMatrixFilter::CreateLightingFilte
r( |
388 0xff89bc45, 0xff112233); | 388 0xff89bc45, 0xff112233); |
389 | 389 |
390 canvas->save(); | 390 canvas->save(); |
391 canvas->translate(SkIntToScalar(0), SkIntToScalar(5)); | 391 canvas->translate(SkIntToScalar(0), SkIntToScalar(5)); |
392 paint.setAntiAlias(true); | 392 paint.setAntiAlias(true); |
393 paint.setFilterQuality(kLow_SkFilterQuality); | 393 paint.setFilterQuality(kLow_SkFilterQuality); |
394 // !!! draw through a clip | 394 // !!! draw through a clip |
395 paint.setColor(SK_ColorLTGRAY); | 395 paint.setColor(SK_ColorLTGRAY); |
396 paint.setStyle(SkPaint::kFill_Style); | 396 paint.setStyle(SkPaint::kFill_Style); |
397 SkRect clip = {0, 0, SkIntToScalar(320), SkIntToScalar(120)}; | 397 SkRect clip = {0, 0, SkIntToScalar(320), SkIntToScalar(120)}; |
398 canvas->clipRect(clip); | 398 canvas->clipRect(clip); |
399 paint.setShader(SkShader::MakeBitmapShader(fTx, | 399 paint.setShader(SkShader::MakeBitmapShader(fTx, |
400 SkShader::kMirror_TileMode, SkShader::kRepeat_TileMode)); | 400 SkShader::kMirror_TileMode, SkShader::kRepeat_TileMode)); |
401 canvas->drawPaint(paint); | 401 canvas->drawPaint(paint); |
402 canvas->save(); | 402 canvas->save(); |
403 | 403 |
404 // line (exercises xfermode, colorShader, colorFilter, filterShader) | 404 // line (exercises xfermode, colorShader, colorFilter, filterShader) |
405 paint.setColor(SK_ColorGREEN); | 405 paint.setColor(SK_ColorGREEN); |
406 paint.setStrokeWidth(SkIntToScalar(10)); | 406 paint.setStrokeWidth(SkIntToScalar(10)); |
407 paint.setStyle(SkPaint::kStroke_Style); | 407 paint.setStyle(SkPaint::kStroke_Style); |
408 paint.setXfermode(xfermode)->unref(); | 408 paint.setXfermode(xfermode)->unref(); |
409 paint.setColorFilter(lightingFilter); | 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()); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 SkString str("GOOGLE"); | 536 SkString str("GOOGLE"); |
537 | 537 |
538 for (size_t i = 0; i < SK_ARRAY_COUNT(gRastProcs); i++) { | 538 for (size_t i = 0; i < SK_ARRAY_COUNT(gRastProcs); i++) { |
539 apply_shader(&paint, (int)i); | 539 apply_shader(&paint, (int)i); |
540 | 540 |
541 // paint.setMaskFilter(nullptr); | 541 // paint.setMaskFilter(nullptr); |
542 // paint.setColor(SK_ColorBLACK); | 542 // paint.setColor(SK_ColorBLACK); |
543 | 543 |
544 #if 01 | 544 #if 01 |
545 int index = i % SK_ARRAY_COUNT(gLightingColors); | 545 int index = i % SK_ARRAY_COUNT(gLightingColors); |
546 paint.setColorFilter(SkColorMatrixFilter::MakeLightingFilter( | 546 paint.setColorFilter(SkColorMatrixFilter::CreateLightingFilter( |
547 gLightingColors[index].fMul, | 547 gLightingColors[index].fMul, |
548 gLightingColors[index].fAdd)); | 548 gLightingColors[index].fAdd))->unref(); |
549 #endif | 549 #endif |
550 | 550 |
551 canvas->drawText(str.c_str(), str.size(), x, y, paint); | 551 canvas->drawText(str.c_str(), str.size(), x, y, paint); |
552 SkRect oval = { x, y - SkIntToScalar(40), x + SkIntToScalar(40), y
}; | 552 SkRect oval = { x, y - SkIntToScalar(40), x + SkIntToScalar(40), y
}; |
553 paint.setStyle(SkPaint::kStroke_Style); | 553 paint.setStyle(SkPaint::kStroke_Style); |
554 canvas->drawOval(oval, paint); | 554 canvas->drawOval(oval, paint); |
555 paint.setStyle(SkPaint::kFill_Style); | 555 paint.setStyle(SkPaint::kFill_Style); |
556 | 556 |
557 y += paint.getFontSpacing(); | 557 y += paint.getFontSpacing(); |
558 } | 558 } |
559 | 559 |
560 canvas->restore(); | 560 canvas->restore(); |
561 } | 561 } |
562 | 562 |
563 private: | 563 private: |
564 SkPoint fClickPt; | 564 SkPoint fClickPt; |
565 SkBitmap fBug, fTb, fTx; | 565 SkBitmap fBug, fTb, fTx; |
566 typedef SampleView INHERITED; | 566 typedef SampleView INHERITED; |
567 }; | 567 }; |
568 | 568 |
569 ////////////////////////////////////////////////////////////////////////////// | 569 ////////////////////////////////////////////////////////////////////////////// |
570 | 570 |
571 static SkView* MyFactory() { return new DemoView; } | 571 static SkView* MyFactory() { return new DemoView; } |
572 static SkViewRegister reg(MyFactory); | 572 static SkViewRegister reg(MyFactory); |
OLD | NEW |