OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkBitmapDevice.h" | 9 #include "SkBitmapDevice.h" |
10 #include "SkBitmapSource.h" | 10 #include "SkBitmapSource.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 } | 25 } |
26 | 26 |
27 void draw(SkCanvas* canvas, | 27 void draw(SkCanvas* canvas, |
28 const SkRect& rect, | 28 const SkRect& rect, |
29 const SkSize& deviceSize, | 29 const SkSize& deviceSize, |
30 SkFilterQuality filterQuality, | 30 SkFilterQuality filterQuality, |
31 SkImageFilter* input = NULL) { | 31 SkImageFilter* input = NULL) { |
32 SkRect dstRect; | 32 SkRect dstRect; |
33 canvas->getTotalMatrix().mapRect(&dstRect, rect); | 33 canvas->getTotalMatrix().mapRect(&dstRect, rect); |
34 canvas->save(); | 34 canvas->save(); |
35 SkScalar deviceScaleX = deviceSize.width() / dstRect.width(); | 35 SkScalar deviceScaleX = SkScalarDiv(deviceSize.width(), dstRect.width())
; |
36 SkScalar deviceScaleY = deviceSize.height() / dstRect.height(); | 36 SkScalar deviceScaleY = SkScalarDiv(deviceSize.height(), dstRect.height(
)); |
37 canvas->translate(rect.x(), rect.y()); | 37 canvas->translate(rect.x(), rect.y()); |
38 canvas->scale(deviceScaleX, deviceScaleY); | 38 canvas->scale(deviceScaleX, deviceScaleY); |
39 canvas->translate(-rect.x(), -rect.y()); | 39 canvas->translate(-rect.x(), -rect.y()); |
40 SkMatrix matrix; | 40 SkMatrix matrix; |
41 matrix.setScale(SkScalarInvert(deviceScaleX), | 41 matrix.setScale(SkScalarInvert(deviceScaleX), |
42 SkScalarInvert(deviceScaleY)); | 42 SkScalarInvert(deviceScaleY)); |
43 SkAutoTUnref<SkImageFilter> imageFilter( | 43 SkAutoTUnref<SkImageFilter> imageFilter( |
44 SkImageFilter::CreateMatrixFilter(matrix, filterQuality, input)); | 44 SkImageFilter::CreateMatrixFilter(matrix, filterQuality, input)); |
45 SkPaint filteredPaint; | 45 SkPaint filteredPaint; |
46 filteredPaint.setImageFilter(imageFilter.get()); | 46 filteredPaint.setImageFilter(imageFilter.get()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 SkBitmap bitmap; | 90 SkBitmap bitmap; |
91 bitmap.allocN32Pixels(16, 16); | 91 bitmap.allocN32Pixels(16, 16); |
92 bitmap.eraseARGB(0x00, 0x00, 0x00, 0x00); | 92 bitmap.eraseARGB(0x00, 0x00, 0x00, 0x00); |
93 { | 93 { |
94 SkBitmapDevice bitmapDevice(bitmap); | 94 SkBitmapDevice bitmapDevice(bitmap); |
95 SkCanvas bitmapCanvas(&bitmapDevice); | 95 SkCanvas bitmapCanvas(&bitmapDevice); |
96 SkPaint paint; | 96 SkPaint paint; |
97 paint.setColor(0xFF00FF00); | 97 paint.setColor(0xFF00FF00); |
98 SkRect ovalRect = SkRect::MakeWH(16, 16); | 98 SkRect ovalRect = SkRect::MakeWH(16, 16); |
99 ovalRect.inset(SkIntToScalar(2)/3, SkIntToScalar(2)/3); | 99 ovalRect.inset(SkScalarDiv(2.0f, 3.0f), SkScalarDiv(2.0f, 3.0f)); |
100 bitmapCanvas.drawOval(ovalRect, paint); | 100 bitmapCanvas.drawOval(ovalRect, paint); |
101 } | 101 } |
102 SkRect inRect = SkRect::MakeXYWH(-4, -4, 20, 20); | 102 SkRect inRect = SkRect::MakeXYWH(-4, -4, 20, 20); |
103 SkRect outRect = SkRect::MakeXYWH(-24, -24, 120, 120); | 103 SkRect outRect = SkRect::MakeXYWH(-24, -24, 120, 120); |
104 SkAutoTUnref<SkBitmapSource> source(SkBitmapSource::Create(bitmap, inRec
t, outRect)); | 104 SkAutoTUnref<SkBitmapSource> source(SkBitmapSource::Create(bitmap, inRec
t, outRect)); |
105 canvas->translate(srcRect.width() + SkIntToScalar(10), 0); | 105 canvas->translate(srcRect.width() + SkIntToScalar(10), 0); |
106 draw(canvas, | 106 draw(canvas, |
107 srcRect, | 107 srcRect, |
108 deviceSize, | 108 deviceSize, |
109 kHigh_SkFilterQuality, | 109 kHigh_SkFilterQuality, |
110 source.get()); | 110 source.get()); |
111 } | 111 } |
112 | 112 |
113 private: | 113 private: |
114 typedef GM INHERITED; | 114 typedef GM INHERITED; |
115 }; | 115 }; |
116 | 116 |
117 ////////////////////////////////////////////////////////////////////////////// | 117 ////////////////////////////////////////////////////////////////////////////// |
118 | 118 |
119 static GM* MyFactory(void*) { return new ResizeGM; } | 119 static GM* MyFactory(void*) { return new ResizeGM; } |
120 static GMRegistry reg(MyFactory); | 120 static GMRegistry reg(MyFactory); |
121 | 121 |
122 } | 122 } |
OLD | NEW |