| OLD | NEW |
| (Empty) |
| 1 | |
| 2 /* | |
| 3 * Copyright 2012 Google Inc. | |
| 4 * | |
| 5 * Use of this source code is governed by a BSD-style license that can be | |
| 6 * found in the LICENSE file. | |
| 7 */ | |
| 8 #include "gm.h" | |
| 9 #include "SkBitmap.h" | |
| 10 #include "SkBlurMask.h" | |
| 11 #include "SkBlurMaskFilter.h" | |
| 12 #include "SkCanvas.h" | |
| 13 #include "SkColor.h" | |
| 14 #include "SkMatrix.h" | |
| 15 #include "SkPath.h" | |
| 16 #include "SkRect.h" | |
| 17 #include "SkSize.h" | |
| 18 #include "SkString.h" | |
| 19 | |
| 20 namespace skiagm { | |
| 21 | |
| 22 class DrawBitmapMatrixGM : public GM { | |
| 23 public: | |
| 24 DrawBitmapMatrixGM() {} | |
| 25 | |
| 26 protected: | |
| 27 virtual uint32_t onGetFlags() const SK_OVERRIDE { | |
| 28 return kSkipTiled_Flag; | |
| 29 } | |
| 30 | |
| 31 virtual SkString onShortName() SK_OVERRIDE { | |
| 32 return SkString("drawbitmapmatrix"); | |
| 33 } | |
| 34 | |
| 35 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(1024, 256); } | |
| 36 | |
| 37 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | |
| 38 SkBitmap bm; | |
| 39 this->setupBitmap(&bm); | |
| 40 | |
| 41 // Draw normally. | |
| 42 SkMatrix matrix; | |
| 43 matrix.reset(); | |
| 44 SkPaint paint; | |
| 45 paint.setAntiAlias(true); | |
| 46 paint.setDither(true); | |
| 47 canvas->drawBitmapMatrix(bm, matrix, &paint); | |
| 48 | |
| 49 // Draw stretched horizontally and squished vertically. | |
| 50 canvas->translate(SkIntToScalar(bm.width() + 5), 0); | |
| 51 matrix.setScale(SkIntToScalar(2), SK_ScalarHalf); | |
| 52 canvas->drawBitmapMatrix(bm, matrix, &paint); | |
| 53 | |
| 54 // Draw rotated | |
| 55 canvas->translate(SkIntToScalar(bm.width()*2 + 5), 0); | |
| 56 matrix.reset(); | |
| 57 matrix.setRotate(SkIntToScalar(45), SkIntToScalar(bm.width() / 2), | |
| 58 SkIntToScalar(bm.height() / 2)); | |
| 59 canvas->save(); | |
| 60 canvas->translate(0, SkIntToScalar(10)); | |
| 61 canvas->drawBitmapMatrix(bm, matrix, &paint); | |
| 62 canvas->restore(); | |
| 63 | |
| 64 // Draw with perspective | |
| 65 canvas->translate(SkIntToScalar(bm.width() + 15), 0); | |
| 66 matrix.reset(); | |
| 67 matrix.setPerspX(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000))); | |
| 68 matrix.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000))); | |
| 69 canvas->drawBitmapMatrix(bm, matrix, &paint); | |
| 70 | |
| 71 // Draw with skew | |
| 72 canvas->translate(SkIntToScalar(bm.width() + 5), 0); | |
| 73 matrix.reset(); | |
| 74 matrix.setSkew(SkIntToScalar(2), SkIntToScalar(2)); | |
| 75 canvas->drawBitmapMatrix(bm, matrix, &paint); | |
| 76 | |
| 77 // Draw with sin/cos | |
| 78 canvas->translate(SkIntToScalar(bm.width() * 4), 0); | |
| 79 matrix.reset(); | |
| 80 matrix.setSinCos(SK_ScalarHalf, SkIntToScalar(2)); | |
| 81 canvas->drawBitmapMatrix(bm, matrix, &paint); | |
| 82 | |
| 83 { | |
| 84 // test the following code path: | |
| 85 // SkGpuDevice::drawPath() -> SkGpuDevice::drawWithMaskFilter() | |
| 86 SkPaint paint; | |
| 87 | |
| 88 paint.setFilterLevel(SkPaint::kLow_FilterLevel); | |
| 89 | |
| 90 SkMaskFilter* mf = SkBlurMaskFilter::Create( | |
| 91 kNormal_SkBlurStyle, | |
| 92 SkBlurMask::ConvertRadiusToSigma(5), | |
| 93 SkBlurMaskFilter::kHighQuality_BlurFlag | | |
| 94 SkBlurMaskFilter::kIgnoreTransform_BlurFlag); | |
| 95 paint.setMaskFilter(mf)->unref(); | |
| 96 | |
| 97 canvas->translate(SkIntToScalar(bm.width()*2 + 20), 0); | |
| 98 | |
| 99 matrix.reset(); | |
| 100 matrix.setRotate(SkIntToScalar(45), SkIntToScalar(bm.width() / 2), | |
| 101 SkIntToScalar(bm.height() / 2)); | |
| 102 | |
| 103 canvas->save(); | |
| 104 canvas->translate(0, SkIntToScalar(20)); | |
| 105 canvas->drawBitmapMatrix(bm, matrix, &paint); | |
| 106 canvas->restore(); | |
| 107 } | |
| 108 | |
| 109 } | |
| 110 private: | |
| 111 void setupBitmap(SkBitmap* bm) { | |
| 112 SkASSERT(bm); | |
| 113 static const int SIZE = 64; | |
| 114 bm->allocN32Pixels(SIZE, SIZE); | |
| 115 SkCanvas canvas(*bm); | |
| 116 | |
| 117 SkPaint paint; | |
| 118 paint.setColor(SK_ColorGREEN); | |
| 119 canvas.drawPaint(paint); | |
| 120 | |
| 121 paint.setColor(SK_ColorBLUE); | |
| 122 paint.setAntiAlias(true); | |
| 123 SkRect rect = SkRect::MakeWH(SkIntToScalar(SIZE), SkIntToScalar(SIZE)); | |
| 124 SkPath path; | |
| 125 path.addOval(rect); | |
| 126 canvas.drawPath(path, paint); | |
| 127 } | |
| 128 }; | |
| 129 | |
| 130 //////////////////////////////////////////////////////////////////////////////// | |
| 131 | |
| 132 static GM* MyFactory(void*) { return new DrawBitmapMatrixGM; } | |
| 133 static GMRegistry reg(MyFactory); | |
| 134 | |
| 135 } | |
| OLD | NEW |