| 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 "SkView.h" | 9 #include "SkView.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
| 12 #include "SkPath.h" | 12 #include "SkPath.h" |
| 13 #include "SkRegion.h" | 13 #include "SkRegion.h" |
| 14 #include "SkShader.h" | 14 #include "SkShader.h" |
| 15 #include "SkUtils.h" | 15 #include "SkUtils.h" |
| 16 #include "Sk1DPathEffect.h" | 16 #include "Sk1DPathEffect.h" |
| 17 #include "SkCornerPathEffect.h" | 17 #include "SkCornerPathEffect.h" |
| 18 #include "SkPathMeasure.h" | 18 #include "SkPathMeasure.h" |
| 19 #include "SkRandom.h" | 19 #include "SkRandom.h" |
| 20 #include "SkColorPriv.h" | 20 #include "SkColorPriv.h" |
| 21 #include "SkColorFilter.h" | 21 #include "SkColorFilter.h" |
| 22 #include "SkDither.h" | 22 #include "SkDither.h" |
| 23 | 23 |
| 24 static void make_bm(SkBitmap* bm) { | 24 static void make_bm(SkBitmap* bm) { |
| 25 const SkColor colors[] = { | 25 const SkPMColor colors[] = { |
| 26 SK_ColorRED, SK_ColorGREEN, | 26 SkPreMultiplyColor(SK_ColorRED), SkPreMultiplyColor(SK_ColorGREEN), |
| 27 SK_ColorBLUE, SK_ColorWHITE | 27 SkPreMultiplyColor(SK_ColorBLUE), SkPreMultiplyColor(SK_ColorWHITE) |
| 28 }; | 28 }; |
| 29 SkColorTable* ctable = new SkColorTable(colors, 4); | 29 SkColorTable* ctable = new SkColorTable(colors, 4); |
| 30 bm->setConfig(SkBitmap::kIndex8_Config, 2, 2); | 30 bm->allocPixels(SkImageInfo::Make(2, 2, kIndex_8_SkColorType, |
| 31 bm->allocPixels(ctable); | 31 kOpaque_SkAlphaType), |
| 32 NULL, ctable); |
| 32 ctable->unref(); | 33 ctable->unref(); |
| 33 | 34 |
| 34 *bm->getAddr8(0, 0) = 0; | 35 *bm->getAddr8(0, 0) = 0; |
| 35 *bm->getAddr8(1, 0) = 1; | 36 *bm->getAddr8(1, 0) = 1; |
| 36 *bm->getAddr8(0, 1) = 2; | 37 *bm->getAddr8(0, 1) = 2; |
| 37 *bm->getAddr8(1, 1) = 3; | 38 *bm->getAddr8(1, 1) = 3; |
| 38 } | 39 } |
| 39 | 40 |
| 40 static SkScalar draw_bm(SkCanvas* canvas, const SkBitmap& bm, | 41 static SkScalar draw_bm(SkCanvas* canvas, const SkBitmap& bm, |
| 41 SkScalar x, SkScalar y, SkPaint* paint) { | 42 SkScalar x, SkScalar y, SkPaint* paint) { |
| 42 #if 1 | |
| 43 canvas->drawBitmap(bm, x, y, paint); | 43 canvas->drawBitmap(bm, x, y, paint); |
| 44 return SkIntToScalar(bm.width()) * 5/4; | 44 return SkIntToScalar(bm.width()) * 5/4; |
| 45 #else | |
| 46 SkAutoCanvasRestore acr(canvas, true); | |
| 47 canvas->translate(x, y); | |
| 48 | |
| 49 SkScalar w = SkIntToScalar(bm.width()); | |
| 50 SkScalar h = SkIntToScalar(bm.height()); | |
| 51 SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, | |
| 52 SkShader::kRepeat_TileMode); | |
| 53 paint->setShader(s)->unref(); | |
| 54 canvas->drawRect(SkRect::MakeWH(w, h), *paint); | |
| 55 paint->setShader(NULL); | |
| 56 return w * 5/4; | |
| 57 #endif | |
| 58 } | 45 } |
| 59 | 46 |
| 60 static SkScalar draw_set(SkCanvas* c, const SkBitmap& bm, SkScalar x, SkPaint* p
) { | 47 static SkScalar draw_set(SkCanvas* c, const SkBitmap& bm, SkScalar x, SkPaint* p
) { |
| 61 x += draw_bm(c, bm, x, 0, p); | 48 x += draw_bm(c, bm, x, 0, p); |
| 62 p->setFilterLevel(SkPaint::kLow_FilterLevel); | 49 p->setFilterLevel(SkPaint::kLow_FilterLevel); |
| 63 x += draw_bm(c, bm, x, 0, p); | 50 x += draw_bm(c, bm, x, 0, p); |
| 64 p->setDither(true); | 51 p->setDither(true); |
| 65 return x + draw_bm(c, bm, x, 0, p); | 52 return x + draw_bm(c, bm, x, 0, p); |
| 66 } | 53 } |
| 67 | 54 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 121 } |
| 135 | 122 |
| 136 private: | 123 private: |
| 137 typedef SampleView INHERITED; | 124 typedef SampleView INHERITED; |
| 138 }; | 125 }; |
| 139 | 126 |
| 140 ////////////////////////////////////////////////////////////////////////////// | 127 ////////////////////////////////////////////////////////////////////////////// |
| 141 | 128 |
| 142 static SkView* MyFactory() { return new FilterView; } | 129 static SkView* MyFactory() { return new FilterView; } |
| 143 static SkViewRegister reg(MyFactory); | 130 static SkViewRegister reg(MyFactory); |
| OLD | NEW |