Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkBlurImageFilter.h" | 9 #include "SkResizeImageFilter.h" |
| 10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
| 11 | 11 |
| 12 #define WIDTH 640 | 12 #define WIDTH 640 |
| 13 #define HEIGHT 480 | 13 #define HEIGHT 480 |
| 14 | 14 |
| 15 #define RESIZE_FACTOR SkIntToScalar(2) | |
| 16 | |
| 15 namespace skiagm { | 17 namespace skiagm { |
| 16 | 18 |
| 17 class ImageBlurTiledGM : public GM { | 19 class ImageResizeTiledGM : public GM { |
| 18 public: | 20 public: |
| 19 ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY) | 21 ImageResizeTiledGM() { |
| 20 : fSigmaX(sigmaX), fSigmaY(sigmaY) { | |
| 21 } | 22 } |
| 22 | 23 |
| 23 protected: | 24 protected: |
|
robertphillips
2014/02/19 19:42:01
SK_OVERRIDE on next 3?
Stephen White
2014/02/19 20:32:44
Done.
| |
| 24 virtual SkString onShortName() { | 25 virtual SkString onShortName() { |
| 25 return SkString("imageblurtiled"); | 26 return SkString("imageresizetiled"); |
| 26 } | 27 } |
| 27 | 28 |
| 28 virtual SkISize onISize() { | 29 virtual SkISize onISize() { |
| 29 return make_isize(WIDTH, HEIGHT); | 30 return make_isize(WIDTH, HEIGHT); |
| 30 } | 31 } |
| 31 | 32 |
| 32 virtual void onDraw(SkCanvas* canvas) { | 33 virtual void onDraw(SkCanvas* canvas) { |
| 33 SkPaint paint; | 34 SkPaint paint; |
|
robertphillips
2014/02/19 19:42:01
over length line.
Stephen White
2014/02/19 20:32:44
Done.
| |
| 34 paint.setImageFilter(new SkBlurImageFilter(fSigmaX, fSigmaY))->unref(); | 35 paint.setImageFilter(new SkResizeImageFilter(RESIZE_FACTOR, RESIZE_FACTO R, SkPaint::kNone_FilterLevel))->unref(); |
| 35 const SkScalar tile_size = SkIntToScalar(128); | 36 const SkScalar tile_size = SkIntToScalar(100); |
| 36 SkRect bounds; | 37 SkRect bounds; |
| 37 canvas->getClipBounds(&bounds); | 38 canvas->getClipBounds(&bounds); |
| 38 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tile_size) { | 39 SkRect layerBounds = SkRect::MakeWH(WIDTH, HEIGHT); |
| 39 for (SkScalar x = bounds.left(); x < bounds.right(); x += tile_size) { | 40 for (SkScalar y = 0; y < HEIGHT; y += tile_size) { |
| 41 for (SkScalar x = 0; x < WIDTH; x += tile_size) { | |
| 40 canvas->save(); | 42 canvas->save(); |
| 41 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size)); | 43 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size)); |
| 42 canvas->saveLayer(NULL, &paint); | 44 canvas->translate(layerBounds.x(), layerBounds.y()); |
| 45 canvas->scale(SkScalarInvert(RESIZE_FACTOR), | |
| 46 SkScalarInvert(RESIZE_FACTOR)); | |
| 47 canvas->translate(-layerBounds.x(), -layerBounds.y()); | |
| 48 canvas->saveLayer(&layerBounds, &paint); | |
| 43 const char* str[] = { | 49 const char* str[] = { |
| 44 "The quick", | 50 "The quick", |
| 45 "brown fox", | 51 "brown fox", |
| 46 "jumped over", | 52 "jumped over", |
| 47 "the lazy dog.", | 53 "the lazy dog.", |
| 48 }; | 54 }; |
| 49 SkPaint textPaint; | 55 SkPaint textPaint; |
| 50 textPaint.setAntiAlias(true); | 56 textPaint.setAntiAlias(true); |
| 51 textPaint.setTextSize(SkIntToScalar(100)); | 57 textPaint.setTextSize(SkIntToScalar(100)); |
| 52 int posY = 0; | 58 int posY = 0; |
| 53 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { | 59 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { |
| 54 posY += 100; | 60 posY += 100; |
| 55 canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0), | 61 canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0), |
| 56 SkIntToScalar(posY), textPaint); | 62 SkIntToScalar(posY), textPaint); |
| 57 } | 63 } |
| 58 canvas->restore(); | 64 canvas->restore(); |
| 59 canvas->restore(); | 65 canvas->restore(); |
| 60 } | 66 } |
| 61 } | 67 } |
| 62 } | 68 } |
| 63 | 69 |
| 64 private: | 70 private: |
| 65 SkScalar fSigmaX; | |
| 66 SkScalar fSigmaY; | |
| 67 | |
| 68 typedef GM INHERITED; | 71 typedef GM INHERITED; |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 ////////////////////////////////////////////////////////////////////////////// | 74 ////////////////////////////////////////////////////////////////////////////// |
| 72 | 75 |
|
robertphillips
2014/02/19 19:42:01
DEF_GM?
Stephen White
2014/02/19 20:32:44
Done.
| |
| 73 static GM* MyFactory1(void*) { return new ImageBlurTiledGM(3.0f, 3.0f); } | 76 static GM* MyFactory1(void*) { return new ImageResizeTiledGM(); } |
| 74 static GMRegistry reg1(MyFactory1); | 77 static GMRegistry reg1(MyFactory1); |
| 75 | 78 |
| 76 } | 79 } |
| OLD | NEW |