| 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" |
| 11 #include "SkColor.h" | 11 #include "SkColor.h" |
| 12 #include "SkResizeImageFilter.h" | 12 #include "SkMatrixImageFilter.h" |
| 13 #include "SkRefCnt.h" | 13 #include "SkRefCnt.h" |
| 14 | 14 |
| 15 namespace skiagm { | 15 namespace skiagm { |
| 16 | 16 |
| 17 class ResizeGM : public GM { | 17 class ResizeGM : public GM { |
| 18 public: | 18 public: |
| 19 ResizeGM() { | 19 ResizeGM() { |
| 20 this->setBGColor(0x00000000); | 20 this->setBGColor(0x00000000); |
| 21 } | 21 } |
| 22 | 22 |
| 23 protected: | 23 protected: |
| 24 virtual SkString onShortName() { | 24 virtual SkString onShortName() { |
| 25 return SkString("resizeimagefilter"); | 25 return SkString("resizeimagefilter"); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void draw(SkCanvas* canvas, | 28 void draw(SkCanvas* canvas, |
| 29 const SkRect& rect, | 29 const SkRect& rect, |
| 30 const SkSize& deviceSize, | 30 const SkSize& deviceSize, |
| 31 SkPaint::FilterLevel filterLevel, | 31 SkPaint::FilterLevel filterLevel, |
| 32 SkImageFilter* input = NULL) { | 32 SkImageFilter* input = NULL) { |
| 33 SkRect dstRect; | 33 SkRect dstRect; |
| 34 canvas->getTotalMatrix().mapRect(&dstRect, rect); | 34 canvas->getTotalMatrix().mapRect(&dstRect, rect); |
| 35 canvas->save(); | 35 canvas->save(); |
| 36 SkScalar deviceScaleX = SkScalarDiv(deviceSize.width(), dstRect.width())
; | 36 SkScalar deviceScaleX = SkScalarDiv(deviceSize.width(), dstRect.width())
; |
| 37 SkScalar deviceScaleY = SkScalarDiv(deviceSize.height(), dstRect.height(
)); | 37 SkScalar deviceScaleY = SkScalarDiv(deviceSize.height(), dstRect.height(
)); |
| 38 canvas->translate(rect.x(), rect.y()); | 38 canvas->translate(rect.x(), rect.y()); |
| 39 canvas->scale(deviceScaleX, deviceScaleY); | 39 canvas->scale(deviceScaleX, deviceScaleY); |
| 40 canvas->translate(-rect.x(), -rect.y()); | 40 canvas->translate(-rect.x(), -rect.y()); |
| 41 SkMatrix matrix; |
| 42 matrix.setScale(SkScalarInvert(deviceScaleX), |
| 43 SkScalarInvert(deviceScaleY)); |
| 41 SkAutoTUnref<SkImageFilter> imageFilter( | 44 SkAutoTUnref<SkImageFilter> imageFilter( |
| 42 SkResizeImageFilter::Create(SkScalarInvert(deviceScaleX), | 45 SkMatrixImageFilter::Create(matrix, filterLevel, input)); |
| 43 SkScalarInvert(deviceScaleY), | |
| 44 filterLevel, | |
| 45 input)); | |
| 46 SkPaint filteredPaint; | 46 SkPaint filteredPaint; |
| 47 filteredPaint.setImageFilter(imageFilter.get()); | 47 filteredPaint.setImageFilter(imageFilter.get()); |
| 48 canvas->saveLayer(&rect, &filteredPaint); | 48 canvas->saveLayer(&rect, &filteredPaint); |
| 49 SkPaint paint; | 49 SkPaint paint; |
| 50 paint.setColor(0xFF00FF00); | 50 paint.setColor(0xFF00FF00); |
| 51 SkRect ovalRect = rect; | 51 SkRect ovalRect = rect; |
| 52 ovalRect.inset(SkIntToScalar(4), SkIntToScalar(4)); | 52 ovalRect.inset(SkIntToScalar(4), SkIntToScalar(4)); |
| 53 canvas->drawOval(ovalRect, paint); | 53 canvas->drawOval(ovalRect, paint); |
| 54 canvas->restore(); // for saveLayer | 54 canvas->restore(); // for saveLayer |
| 55 canvas->restore(); | 55 canvas->restore(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 private: | 114 private: |
| 115 typedef GM INHERITED; | 115 typedef GM INHERITED; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 ////////////////////////////////////////////////////////////////////////////// | 118 ////////////////////////////////////////////////////////////////////////////// |
| 119 | 119 |
| 120 static GM* MyFactory(void*) { return new ResizeGM; } | 120 static GM* MyFactory(void*) { return new ResizeGM; } |
| 121 static GMRegistry reg(MyFactory); | 121 static GMRegistry reg(MyFactory); |
| 122 | 122 |
| 123 } | 123 } |
| OLD | NEW |