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 15 matching lines...) Expand all Loading... |
26 #include "SkMath.h" | 26 #include "SkMath.h" |
27 #include "SkPath.h" | 27 #include "SkPath.h" |
28 #include "SkPictureRecorder.h" | 28 #include "SkPictureRecorder.h" |
29 #include "SkRegion.h" | 29 #include "SkRegion.h" |
30 #include "SkShader.h" | 30 #include "SkShader.h" |
31 #include "SkComposeShader.h" | 31 #include "SkComposeShader.h" |
32 #include "SkCornerPathEffect.h" | 32 #include "SkCornerPathEffect.h" |
33 #include "SkPathMeasure.h" | 33 #include "SkPathMeasure.h" |
34 #include "SkPicture.h" | 34 #include "SkPicture.h" |
35 #include "SkRandom.h" | 35 #include "SkRandom.h" |
36 #include "SkTransparentShader.h" | |
37 #include "SkTypeface.h" | 36 #include "SkTypeface.h" |
38 #include "SkUtils.h" | 37 #include "SkUtils.h" |
39 #include "SkXfermode.h" | 38 #include "SkXfermode.h" |
40 | 39 |
41 #include <math.h> | 40 #include <math.h> |
42 | 41 |
43 static inline SkPMColor rgb2gray(SkPMColor c) { | 42 static inline SkPMColor rgb2gray(SkPMColor c) { |
44 unsigned r = SkGetPackedR32(c); | 43 unsigned r = SkGetPackedR32(c); |
45 unsigned g = SkGetPackedG32(c); | 44 unsigned g = SkGetPackedG32(c); |
46 unsigned b = SkGetPackedB32(c); | 45 unsigned b = SkGetPackedB32(c); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 SkPoint radialCenter = { SkIntToScalar(25), SkIntToScalar(25) }; | 368 SkPoint radialCenter = { SkIntToScalar(25), SkIntToScalar(25) }; |
370 SkScalar radialRadius = SkIntToScalar(25); | 369 SkScalar radialRadius = SkIntToScalar(25); |
371 SkColor radialColors[] = { SK_ColorGREEN, SK_ColorGRAY, SK_ColorRED }; | 370 SkColor radialColors[] = { SK_ColorGREEN, SK_ColorGRAY, SK_ColorRED }; |
372 SkScalar radialPos[] = { 0, SkIntToScalar(3) / 5, SkIntToScalar(1)}; | 371 SkScalar radialPos[] = { 0, SkIntToScalar(3) / 5, SkIntToScalar(1)}; |
373 int radialCount = 3; | 372 int radialCount = 3; |
374 SkShader::TileMode radialMode = SkShader::kRepeat_TileMode; | 373 SkShader::TileMode radialMode = SkShader::kRepeat_TileMode; |
375 SkShader* radial = SkGradientShader::CreateRadial(radialCenter, | 374 SkShader* radial = SkGradientShader::CreateRadial(radialCenter, |
376 radialRadius, radialColors, radialPos, radialCount, | 375 radialRadius, radialColors, radialPos, radialCount, |
377 radialMode); | 376 radialMode); |
378 | 377 |
379 SkTransparentShader* transparentShader = new SkTransparentShader(); | |
380 SkEmbossMaskFilter::Light light; | 378 SkEmbossMaskFilter::Light light; |
381 light.fDirection[0] = SK_Scalar1/2; | 379 light.fDirection[0] = SK_Scalar1/2; |
382 light.fDirection[1] = SK_Scalar1/2; | 380 light.fDirection[1] = SK_Scalar1/2; |
383 light.fDirection[2] = SK_Scalar1/3; | 381 light.fDirection[2] = SK_Scalar1/3; |
384 light.fAmbient = 0x48; | 382 light.fAmbient = 0x48; |
385 light.fSpecular = 0x80; | 383 light.fSpecular = 0x80; |
386 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(12)/5); | 384 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(12)/5); |
387 SkEmbossMaskFilter* embossFilter = SkEmbossMaskFilter::Create(sigma, lig
ht); | 385 SkEmbossMaskFilter* embossFilter = SkEmbossMaskFilter::Create(sigma, lig
ht); |
388 | 386 |
389 SkXfermode* xfermode = SkXfermode::Create(SkXfermode::kXor_Mode); | 387 SkXfermode* xfermode = SkXfermode::Create(SkXfermode::kXor_Mode); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 paint.setShader(linear)->unref(); | 419 paint.setShader(linear)->unref(); |
422 paint.setPathEffect(pathEffectTest())->unref(); | 420 paint.setPathEffect(pathEffectTest())->unref(); |
423 canvas->drawRect(rect, paint); | 421 canvas->drawRect(rect, paint); |
424 paint.setPathEffect(NULL); | 422 paint.setPathEffect(NULL); |
425 | 423 |
426 // circle w/ emboss & transparent (exercises 3dshader) | 424 // circle w/ emboss & transparent (exercises 3dshader) |
427 canvas->translate(SkIntToScalar(50), 0); | 425 canvas->translate(SkIntToScalar(50), 0); |
428 paint.setMaskFilter(embossFilter)->unref(); | 426 paint.setMaskFilter(embossFilter)->unref(); |
429 canvas->drawOval(rect, paint); | 427 canvas->drawOval(rect, paint); |
430 canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); | 428 canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); |
431 paint.setShader(transparentShader)->unref(); | 429 // paint.setShader(transparentShader)->unref(); |
432 canvas->drawOval(rect, paint); | 430 canvas->drawOval(rect, paint); |
433 canvas->translate(0, SkIntToScalar(-10)); | 431 canvas->translate(0, SkIntToScalar(-10)); |
434 | 432 |
435 // path | 433 // path |
436 canvas->translate(SkIntToScalar(50), 0); | 434 canvas->translate(SkIntToScalar(50), 0); |
437 paint.setColor(SK_ColorRED); | 435 paint.setColor(SK_ColorRED); |
438 paint.setStyle(SkPaint::kStroke_Style); | 436 paint.setStyle(SkPaint::kStroke_Style); |
439 paint.setStrokeWidth(SkIntToScalar(5)); | 437 paint.setStrokeWidth(SkIntToScalar(5)); |
440 paint.setShader(radial)->unref(); | 438 paint.setShader(radial)->unref(); |
441 paint.setMaskFilter(NULL); | 439 paint.setMaskFilter(NULL); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 private: | 575 private: |
578 SkPoint fClickPt; | 576 SkPoint fClickPt; |
579 SkBitmap fBug, fTb, fTx; | 577 SkBitmap fBug, fTb, fTx; |
580 typedef SampleView INHERITED; | 578 typedef SampleView INHERITED; |
581 }; | 579 }; |
582 | 580 |
583 ////////////////////////////////////////////////////////////////////////////// | 581 ////////////////////////////////////////////////////////////////////////////// |
584 | 582 |
585 static SkView* MyFactory() { return new DemoView; } | 583 static SkView* MyFactory() { return new DemoView; } |
586 static SkViewRegister reg(MyFactory); | 584 static SkViewRegister reg(MyFactory); |
OLD | NEW |