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