OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 "gm.h" | 8 #include "gm.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkBlurMask.h" | 10 #include "SkBlurMask.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 class DrawBitmapMatrixGM : public GM { | 22 class DrawBitmapMatrixGM : public GM { |
23 public: | 23 public: |
24 DrawBitmapMatrixGM() {} | 24 DrawBitmapMatrixGM() {} |
25 | 25 |
26 protected: | 26 protected: |
27 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 27 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
28 return kSkipTiled_Flag; | 28 return kSkipTiled_Flag; |
29 } | 29 } |
30 | 30 |
31 virtual SkString onShortName() SK_OVERRIDE { | 31 virtual SkString onShortName() SK_OVERRIDE { |
32 return SkString("drawbitmapmatrix"); | 32 return SkString("drawbitmapmatrix"); |
f(malita)
2014/12/09 23:50:08
Should we just remove this GM instead of convertin
| |
33 } | 33 } |
34 | 34 |
35 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(1024, 256); } | 35 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(1024, 256); } |
36 | 36 |
37 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 37 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
38 SkBitmap bm; | 38 SkBitmap bm; |
39 this->setupBitmap(&bm); | 39 this->setupBitmap(&bm); |
40 | 40 |
41 // Draw normally. | 41 // Draw normally. |
42 SkMatrix matrix; | 42 SkMatrix matrix; |
43 matrix.reset(); | 43 matrix.reset(); |
44 SkPaint paint; | 44 SkPaint paint; |
45 paint.setAntiAlias(true); | 45 paint.setAntiAlias(true); |
46 paint.setDither(true); | 46 paint.setDither(true); |
47 canvas->drawBitmapMatrix(bm, matrix, &paint); | 47 canvas->drawBitmap(bm, 0, 0, &paint); |
48 | 48 |
49 // Draw stretched horizontally and squished vertically. | 49 // Draw stretched horizontally and squished vertically. |
50 canvas->translate(SkIntToScalar(bm.width() + 5), 0); | 50 canvas->translate(SkIntToScalar(bm.width() + 5), 0); |
51 matrix.setScale(SkIntToScalar(2), SK_ScalarHalf); | 51 matrix.setScale(SkIntToScalar(2), SK_ScalarHalf); |
52 canvas->drawBitmapMatrix(bm, matrix, &paint); | 52 { |
53 SkAutoCanvasRestore acr(canvas, true); | |
54 canvas->concat(matrix); | |
55 canvas->drawBitmap(bm, 0, 0, &paint); | |
56 } | |
53 | 57 |
54 // Draw rotated | 58 // Draw rotated |
55 canvas->translate(SkIntToScalar(bm.width()*2 + 5), 0); | 59 canvas->translate(SkIntToScalar(bm.width()*2 + 5), 0); |
56 matrix.reset(); | 60 matrix.reset(); |
57 matrix.setRotate(SkIntToScalar(45), SkIntToScalar(bm.width() / 2), | 61 matrix.setRotate(SkIntToScalar(45), SkIntToScalar(bm.width() / 2), |
58 SkIntToScalar(bm.height() / 2)); | 62 SkIntToScalar(bm.height() / 2)); |
59 canvas->save(); | 63 canvas->save(); |
60 canvas->translate(0, SkIntToScalar(10)); | 64 canvas->translate(0, SkIntToScalar(10)); |
61 canvas->drawBitmapMatrix(bm, matrix, &paint); | 65 canvas->concat(matrix); |
66 canvas->drawBitmap(bm, 0, 0, &paint); | |
62 canvas->restore(); | 67 canvas->restore(); |
63 | 68 |
64 // Draw with perspective | 69 // Draw with perspective |
65 canvas->translate(SkIntToScalar(bm.width() + 15), 0); | 70 canvas->translate(SkIntToScalar(bm.width() + 15), 0); |
66 matrix.reset(); | 71 matrix.reset(); |
67 matrix.setPerspX(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000))); | 72 matrix.setPerspX(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000))); |
68 matrix.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000))); | 73 matrix.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000))); |
69 canvas->drawBitmapMatrix(bm, matrix, &paint); | 74 { |
75 SkAutoCanvasRestore acr(canvas, true); | |
76 canvas->concat(matrix); | |
77 canvas->drawBitmap(bm, 0, 0, &paint); | |
78 } | |
70 | 79 |
71 // Draw with skew | 80 // Draw with skew |
72 canvas->translate(SkIntToScalar(bm.width() + 5), 0); | 81 canvas->translate(SkIntToScalar(bm.width() + 5), 0); |
73 matrix.reset(); | 82 matrix.reset(); |
74 matrix.setSkew(SkIntToScalar(2), SkIntToScalar(2)); | 83 matrix.setSkew(SkIntToScalar(2), SkIntToScalar(2)); |
75 canvas->drawBitmapMatrix(bm, matrix, &paint); | 84 { |
85 SkAutoCanvasRestore acr(canvas, true); | |
86 canvas->concat(matrix); | |
87 canvas->drawBitmap(bm, 0, 0, &paint); | |
88 } | |
76 | 89 |
77 // Draw with sin/cos | 90 // Draw with sin/cos |
78 canvas->translate(SkIntToScalar(bm.width() * 4), 0); | 91 canvas->translate(SkIntToScalar(bm.width() * 4), 0); |
79 matrix.reset(); | 92 matrix.reset(); |
80 matrix.setSinCos(SK_ScalarHalf, SkIntToScalar(2)); | 93 matrix.setSinCos(SK_ScalarHalf, SkIntToScalar(2)); |
81 canvas->drawBitmapMatrix(bm, matrix, &paint); | 94 { |
95 SkAutoCanvasRestore acr(canvas, true); | |
96 canvas->concat(matrix); | |
97 canvas->drawBitmap(bm, 0, 0, &paint); | |
98 } | |
82 | 99 |
83 { | 100 { |
84 // test the following code path: | 101 // test the following code path: |
85 // SkGpuDevice::drawPath() -> SkGpuDevice::drawWithMaskFilter() | 102 // SkGpuDevice::drawPath() -> SkGpuDevice::drawWithMaskFilter() |
86 SkPaint paint; | 103 SkPaint paint; |
87 | 104 |
88 paint.setFilterLevel(SkPaint::kLow_FilterLevel); | 105 paint.setFilterLevel(SkPaint::kLow_FilterLevel); |
89 | 106 |
90 SkMaskFilter* mf = SkBlurMaskFilter::Create( | 107 SkMaskFilter* mf = SkBlurMaskFilter::Create( |
91 kNormal_SkBlurStyle, | 108 kNormal_SkBlurStyle, |
92 SkBlurMask::ConvertRadiusToSigma(5), | 109 SkBlurMask::ConvertRadiusToSigma(5), |
93 SkBlurMaskFilter::kHighQuality_BlurFlag | | 110 SkBlurMaskFilter::kHighQuality_BlurFlag | |
94 SkBlurMaskFilter::kIgnoreTransform_BlurFlag); | 111 SkBlurMaskFilter::kIgnoreTransform_BlurFlag); |
95 paint.setMaskFilter(mf)->unref(); | 112 paint.setMaskFilter(mf)->unref(); |
96 | 113 |
97 canvas->translate(SkIntToScalar(bm.width()*2 + 20), 0); | 114 canvas->translate(SkIntToScalar(bm.width()*2 + 20), 0); |
98 | 115 |
99 matrix.reset(); | 116 matrix.reset(); |
100 matrix.setRotate(SkIntToScalar(45), SkIntToScalar(bm.width() / 2), | 117 matrix.setRotate(SkIntToScalar(45), SkIntToScalar(bm.width() / 2), |
101 SkIntToScalar(bm.height() / 2)); | 118 SkIntToScalar(bm.height() / 2)); |
102 | 119 |
103 canvas->save(); | 120 canvas->save(); |
104 canvas->translate(0, SkIntToScalar(20)); | 121 canvas->translate(0, SkIntToScalar(20)); |
105 canvas->drawBitmapMatrix(bm, matrix, &paint); | 122 canvas->concat(matrix); |
123 canvas->drawBitmap(bm, 0, 0, &paint); | |
106 canvas->restore(); | 124 canvas->restore(); |
107 } | 125 } |
108 | 126 |
109 } | 127 } |
110 private: | 128 private: |
111 void setupBitmap(SkBitmap* bm) { | 129 void setupBitmap(SkBitmap* bm) { |
112 SkASSERT(bm); | 130 SkASSERT(bm); |
113 static const int SIZE = 64; | 131 static const int SIZE = 64; |
114 bm->allocN32Pixels(SIZE, SIZE); | 132 bm->allocN32Pixels(SIZE, SIZE); |
115 SkCanvas canvas(*bm); | 133 SkCanvas canvas(*bm); |
(...skipping 10 matching lines...) Expand all Loading... | |
126 canvas.drawPath(path, paint); | 144 canvas.drawPath(path, paint); |
127 } | 145 } |
128 }; | 146 }; |
129 | 147 |
130 //////////////////////////////////////////////////////////////////////////////// | 148 //////////////////////////////////////////////////////////////////////////////// |
131 | 149 |
132 static GM* MyFactory(void*) { return new DrawBitmapMatrixGM; } | 150 static GM* MyFactory(void*) { return new DrawBitmapMatrixGM; } |
133 static GMRegistry reg(MyFactory); | 151 static GMRegistry reg(MyFactory); |
134 | 152 |
135 } | 153 } |
OLD | NEW |