| 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 "SkBitmapSource.h" | 9 #include "SkBitmapSource.h" |
| 10 #include "SkColor.h" | 10 #include "SkColor.h" |
| 11 #include "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
| 12 | 12 |
| 13 namespace skiagm { | 13 namespace skiagm { |
| 14 | 14 |
| 15 class ResizeGM : public GM { | 15 class ResizeGM : public GM { |
| 16 public: | 16 public: |
| 17 ResizeGM() { | 17 ResizeGM() { |
| 18 this->setBGColor(0x00000000); | 18 this->setBGColor(0x00000000); |
| 19 } | 19 } |
| 20 | 20 |
| 21 protected: | 21 protected: |
| 22 virtual SkString onShortName() { | 22 virtual SkString onShortName() { |
| 23 return SkString("resizeimagefilter"); | 23 return SkString("resizeimagefilter"); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void draw(SkCanvas* canvas, | 26 void draw(SkCanvas* canvas, |
| 27 const SkRect& rect, | 27 const SkRect& rect, |
| 28 const SkSize& deviceSize, | 28 const SkSize& deviceSize, |
| 29 SkFilterQuality filterQuality, | 29 SkFilterQuality filterQuality, |
| 30 SkImageFilter* input = NULL) { | 30 SkImageFilter* input = nullptr) { |
| 31 SkRect dstRect; | 31 SkRect dstRect; |
| 32 canvas->getTotalMatrix().mapRect(&dstRect, rect); | 32 canvas->getTotalMatrix().mapRect(&dstRect, rect); |
| 33 canvas->save(); | 33 canvas->save(); |
| 34 SkScalar deviceScaleX = deviceSize.width() / dstRect.width(); | 34 SkScalar deviceScaleX = deviceSize.width() / dstRect.width(); |
| 35 SkScalar deviceScaleY = deviceSize.height() / dstRect.height(); | 35 SkScalar deviceScaleY = deviceSize.height() / dstRect.height(); |
| 36 canvas->translate(rect.x(), rect.y()); | 36 canvas->translate(rect.x(), rect.y()); |
| 37 canvas->scale(deviceScaleX, deviceScaleY); | 37 canvas->scale(deviceScaleX, deviceScaleY); |
| 38 canvas->translate(-rect.x(), -rect.y()); | 38 canvas->translate(-rect.x(), -rect.y()); |
| 39 SkMatrix matrix; | 39 SkMatrix matrix; |
| 40 matrix.setScale(SkScalarInvert(deviceScaleX), | 40 matrix.setScale(SkScalarInvert(deviceScaleX), |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 private: | 111 private: |
| 112 typedef GM INHERITED; | 112 typedef GM INHERITED; |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 ////////////////////////////////////////////////////////////////////////////// | 115 ////////////////////////////////////////////////////////////////////////////// |
| 116 | 116 |
| 117 static GM* MyFactory(void*) { return new ResizeGM; } | 117 static GM* MyFactory(void*) { return new ResizeGM; } |
| 118 static GMRegistry reg(MyFactory); | 118 static GMRegistry reg(MyFactory); |
| 119 | 119 |
| 120 } | 120 } |
| OLD | NEW |