| 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 } | 29 } |
| 30 | 30 |
| 31 void drawMask(SkCanvas* canvas, const SkRect& r) { | 31 void drawMask(SkCanvas* canvas, const SkRect& r) { |
| 32 SkPaint paint; | 32 SkPaint paint; |
| 33 paint.setAntiAlias(true); | 33 paint.setAntiAlias(true); |
| 34 | 34 |
| 35 if (true) { | 35 if (true) { |
| 36 SkBitmap mask; | 36 SkBitmap mask; |
| 37 int w = SkScalarRoundToInt(r.width()); | 37 int w = SkScalarRoundToInt(r.width()); |
| 38 int h = SkScalarRoundToInt(r.height()); | 38 int h = SkScalarRoundToInt(r.height()); |
| 39 mask.setConfig(SkBitmap::kARGB_8888_Config, w, h); | 39 mask.allocN32Pixels(w, h); |
| 40 mask.allocPixels(); | |
| 41 mask.eraseColor(SK_ColorTRANSPARENT); | 40 mask.eraseColor(SK_ColorTRANSPARENT); |
| 42 SkCanvas c(mask); | 41 SkCanvas c(mask); |
| 43 SkRect bounds = r; | 42 SkRect bounds = r; |
| 44 bounds.offset(-bounds.fLeft, -bounds.fTop); | 43 bounds.offset(-bounds.fLeft, -bounds.fTop); |
| 45 c.drawOval(bounds, paint); | 44 c.drawOval(bounds, paint); |
| 46 | 45 |
| 47 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); | 46 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); |
| 48 canvas->drawBitmap(mask, r.fLeft, r.fTop, &paint); | 47 canvas->drawBitmap(mask, r.fLeft, r.fTop, &paint); |
| 49 } else { | 48 } else { |
| 50 SkPath p; | 49 SkPath p; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 65 } | 64 } |
| 66 | 65 |
| 67 private: | 66 private: |
| 68 typedef SampleView INHERITED; | 67 typedef SampleView INHERITED; |
| 69 }; | 68 }; |
| 70 | 69 |
| 71 /////////////////////////////////////////////////////////////////////////////// | 70 /////////////////////////////////////////////////////////////////////////////// |
| 72 | 71 |
| 73 static SkView* MyFactory() { return new LayerMaskView; } | 72 static SkView* MyFactory() { return new LayerMaskView; } |
| 74 static SkViewRegister reg(MyFactory); | 73 static SkViewRegister reg(MyFactory); |
| OLD | NEW |