OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2011 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "gm.h" |
| 9 #include "SkGradientShader.h" |
| 10 |
| 11 #include "SkTypeface.h" |
| 12 #include "SkImageDecoder.h" |
| 13 static void load_bm(SkBitmap* bm) { |
| 14 // SkImageDecoder::DecodeFile("/skia/trunk/books.jpg", bm); |
| 15 |
| 16 bm->setConfig(SkBitmap::kARGB_8888_Config, 160, 120); |
| 17 bm->allocPixels(); |
| 18 SkCanvas canvas(*bm); |
| 19 canvas.drawColor(SK_ColorWHITE); |
| 20 |
| 21 SkPaint paint; |
| 22 paint.setAntiAlias(true); |
| 23 paint.setSubpixelText(true); |
| 24 paint.setTextSize(17); |
| 25 |
| 26 paint.setTypeface(SkTypeface::CreateFromName("Times", SkTypeface::kNormal))-
>unref(); |
| 27 canvas.drawText("Hamburgefons", 12, 10, 25, paint); |
| 28 paint.setTypeface(SkTypeface::CreateFromName("Times", SkTypeface::kItalic))-
>unref(); |
| 29 canvas.drawText("Hamburgefons", 12, 10, 50, paint); |
| 30 paint.setTypeface(SkTypeface::CreateFromName("Times", SkTypeface::kBold))->u
nref(); |
| 31 canvas.drawText("Hamburgefons", 12, 10, 75, paint); |
| 32 paint.setTypeface(SkTypeface::CreateFromName("Times", SkTypeface::kBoldItali
c))->unref(); |
| 33 canvas.drawText("Hamburgefons", 12, 10, 100, paint); |
| 34 } |
| 35 |
| 36 static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) { |
| 37 SkRect bounds = { 0, 0, bm.width(), bm.height() }; |
| 38 mat.mapRect(&bounds); |
| 39 return SkSize::Make(bounds.width(), bounds.height()); |
| 40 } |
| 41 |
| 42 static void draw_col(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, |
| 43 SkScalar dx) { |
| 44 SkPaint paint; |
| 45 |
| 46 SkAutoCanvasRestore acr(canvas, true); |
| 47 |
| 48 canvas->drawBitmapMatrix(bm, mat, &paint); |
| 49 |
| 50 paint.setFilterBitmap(true); |
| 51 canvas->translate(dx, 0); |
| 52 canvas->drawBitmapMatrix(bm, mat, &paint); |
| 53 |
| 54 paint.setFlags(paint.getFlags() | SkPaint::kBicubicFilterBitmap_Flag); |
| 55 canvas->translate(dx, 0); |
| 56 canvas->drawBitmapMatrix(bm, mat, &paint); |
| 57 } |
| 58 |
| 59 class FilterBitmapGM : public skiagm::GM { |
| 60 bool fOnce; |
| 61 void init() { |
| 62 if (fOnce) { |
| 63 return; |
| 64 } |
| 65 fOnce = true; |
| 66 load_bm(&fBM); |
| 67 |
| 68 SkScalar cx = SkScalarHalf(fBM.width()); |
| 69 SkScalar cy = SkScalarHalf(fBM.height()); |
| 70 SkScalar scale = 1.6f; |
| 71 |
| 72 fMatrix[0].setScale(scale, scale); |
| 73 fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(scale, scale); |
| 74 } |
| 75 |
| 76 public: |
| 77 SkBitmap fBM; |
| 78 SkMatrix fMatrix[2]; |
| 79 |
| 80 FilterBitmapGM() : fOnce(false) { |
| 81 this->setBGColor(0xFFDDDDDD); |
| 82 } |
| 83 |
| 84 protected: |
| 85 virtual SkString onShortName() SK_OVERRIDE { |
| 86 return SkString("filterbitmap"); |
| 87 } |
| 88 |
| 89 virtual SkISize onISize() SK_OVERRIDE { |
| 90 return SkISize::Make(920, 480); |
| 91 } |
| 92 |
| 93 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 94 this->init(); |
| 95 |
| 96 canvas->translate(10, 10); |
| 97 for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrix); ++i) { |
| 98 SkSize size = computeSize(fBM, fMatrix[i]); |
| 99 size.fWidth += 20; |
| 100 size.fHeight += 20; |
| 101 |
| 102 draw_col(canvas, fBM, fMatrix[i], size.fWidth); |
| 103 canvas->translate(0, size.fHeight); |
| 104 } |
| 105 } |
| 106 |
| 107 private: |
| 108 typedef skiagm::GM INHERITED; |
| 109 }; |
| 110 |
| 111 ////////////////////////////////////////////////////////////////////////////// |
| 112 |
| 113 DEF_GM( return new FilterBitmapGM; ) |
| 114 |
OLD | NEW |