OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkView.h" | 9 #include "SkView.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkBlurMaskFilter.h" | 11 #include "SkBlurMaskFilter.h" |
12 #include "SkCamera.h" | 12 #include "SkCamera.h" |
13 #include "SkColorFilter.h" | 13 #include "SkColorFilter.h" |
14 #include "SkColorPriv.h" | 14 #include "SkColorPriv.h" |
15 #include "SkDevice.h" | |
16 #include "SkGradientShader.h" | 15 #include "SkGradientShader.h" |
17 #include "SkImage.h" | 16 #include "SkImage.h" |
18 #include "SkInterpolator.h" | 17 #include "SkInterpolator.h" |
19 #include "SkMaskFilter.h" | 18 #include "SkMaskFilter.h" |
20 #include "SkPath.h" | 19 #include "SkPath.h" |
21 #include "SkRegion.h" | 20 #include "SkRegion.h" |
22 #include "SkShader.h" | 21 #include "SkShader.h" |
23 #include "SkTime.h" | 22 #include "SkTime.h" |
24 #include "SkTypeface.h" | 23 #include "SkTypeface.h" |
25 #include "SkUtils.h" | 24 #include "SkUtils.h" |
26 #include "SkKey.h" | 25 #include "SkKey.h" |
27 #include "SkXfermode.h" | 26 #include "SkXfermode.h" |
28 #include "SkDrawFilter.h" | 27 #include "SkDrawFilter.h" |
29 | 28 |
30 static void make_paint(SkPaint* paint, const SkMatrix& localMatrix) { | 29 static void make_paint(SkPaint* paint, const SkMatrix& localMatrix) { |
31 SkColor colors[] = { 0, SK_ColorWHITE }; | 30 SkColor colors[] = { 0, SK_ColorWHITE }; |
32 SkPoint pts[] = { { 0, 0 }, { 0, SK_Scalar1*20 } }; | 31 SkPoint pts[] = { { 0, 0 }, { 0, SK_Scalar1*20 } }; |
33 paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, | 32 paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, |
34 SkShader::kClamp_TileMode, 0,
&localMatrix)); | 33 SkShader::kClamp_TileMode, 0,
&localMatrix)); |
35 paint->setXfermodeMode(SkXfermode::kDstIn_Mode); | 34 paint->setXfermodeMode(SkXfermode::kDstIn_Mode); |
36 } | 35 } |
37 | 36 |
38 static void dump_layers(const char label[], SkCanvas* canvas) { | |
39 SkDebugf("Dump Layers(%s)\n", label); | |
40 | |
41 SkCanvas::LayerIter iter(canvas, true); | |
42 int index = 0; | |
43 while (!iter.done()) { | |
44 SkImageInfo info = iter.device()->imageInfo(); | |
45 const SkIRect& clip = iter.clip().getBounds(); | |
46 SkDebugf("Layer[%d] bitmap [%d %d] X=%d Y=%d clip=[%d %d %d %d] alpha=%d
\n", index++, | |
47 info.width(), info.height(), iter.x(), iter.y(), | |
48 clip.fLeft, clip.fTop, clip.fRight, clip.fBottom, | |
49 iter.paint().getAlpha()); | |
50 iter.next(); | |
51 } | |
52 } | |
53 | |
54 // test drawing with strips of fading gradient above and below | 37 // test drawing with strips of fading gradient above and below |
55 static void test_fade(SkCanvas* canvas) { | 38 static void test_fade(SkCanvas* canvas) { |
56 SkAutoCanvasRestore ar(canvas, true); | 39 SkAutoCanvasRestore ar(canvas, true); |
57 | 40 |
58 SkRect r; | 41 SkRect r; |
59 | 42 |
60 SkPaint p; | 43 SkPaint p; |
61 p.setAlpha(0x88); | 44 p.setAlpha(0x88); |
62 | 45 |
63 SkAutoCanvasRestore ar2(canvas, false); | 46 SkAutoCanvasRestore ar2(canvas, false); |
(...skipping 15 matching lines...) Expand all Loading... |
79 if (true) { | 62 if (true) { |
80 r.set(0, 0, SkIntToScalar(100), SkIntToScalar(100)); | 63 r.set(0, 0, SkIntToScalar(100), SkIntToScalar(100)); |
81 | 64 |
82 canvas->saveLayerAlpha(&r, 0x80); | 65 canvas->saveLayerAlpha(&r, 0x80); |
83 | 66 |
84 SkPaint p; | 67 SkPaint p; |
85 p.setColor(SK_ColorRED); | 68 p.setColor(SK_ColorRED); |
86 p.setAntiAlias(true); | 69 p.setAntiAlias(true); |
87 canvas->drawOval(r, p); | 70 canvas->drawOval(r, p); |
88 | 71 |
89 dump_layers("inside layer alpha", canvas); | |
90 | |
91 canvas->restore(); | 72 canvas->restore(); |
92 } else { | 73 } else { |
93 r.set(0, 0, SkIntToScalar(100), SkIntToScalar(100)); | 74 r.set(0, 0, SkIntToScalar(100), SkIntToScalar(100)); |
94 | 75 |
95 SkPaint p; | 76 SkPaint p; |
96 p.setColor(SK_ColorRED); | 77 p.setColor(SK_ColorRED); |
97 p.setAntiAlias(true); | 78 p.setAntiAlias(true); |
98 canvas->drawOval(r, p); | 79 canvas->drawOval(r, p); |
99 } | 80 } |
100 | 81 |
101 // return; | 82 // return; |
102 | 83 |
103 dump_layers("outside layer alpha", canvas); | |
104 | |
105 // now apply an effect | 84 // now apply an effect |
106 SkMatrix m; | 85 SkMatrix m; |
107 m.setScale(SK_Scalar1, -SK_Scalar1); | 86 m.setScale(SK_Scalar1, -SK_Scalar1); |
108 m.postTranslate(0, SkIntToScalar(100)); | 87 m.postTranslate(0, SkIntToScalar(100)); |
109 | 88 |
110 SkPaint paint; | 89 SkPaint paint; |
111 make_paint(&paint, m); | 90 make_paint(&paint, m); |
112 r.set(0, 0, SkIntToScalar(100), SkIntToScalar(20)); | 91 r.set(0, 0, SkIntToScalar(100), SkIntToScalar(20)); |
113 // SkDebugf("--------- draw top grad\n"); | 92 // SkDebugf("--------- draw top grad\n"); |
114 canvas->drawRect(r, paint); | 93 canvas->drawRect(r, paint); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 bool onClick(Click* click) override { | 278 bool onClick(Click* click) override { |
300 this->inval(nullptr); | 279 this->inval(nullptr); |
301 fCenter = click->fCurr; | 280 fCenter = click->fCurr; |
302 return this->INHERITED::onClick(click); | 281 return this->INHERITED::onClick(click); |
303 } | 282 } |
304 | 283 |
305 private: | 284 private: |
306 typedef SampleView INHERITED; | 285 typedef SampleView INHERITED; |
307 }; | 286 }; |
308 DEF_SAMPLE( return new BackdropView; ) | 287 DEF_SAMPLE( return new BackdropView; ) |
OLD | NEW |