OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 #include "SkBenchmark.h" |
| 8 #include "SkCanvas.h" |
| 9 #include "SkDevice.h" |
| 10 #include "SkMagnifierImageFilter.h" |
| 11 #include "SkRandom.h" |
| 12 |
| 13 #define FILTER_WIDTH_SMALL SkIntToScalar(32) |
| 14 #define FILTER_HEIGHT_SMALL SkIntToScalar(32) |
| 15 #define FILTER_WIDTH_LARGE SkIntToScalar(256) |
| 16 #define FILTER_HEIGHT_LARGE SkIntToScalar(256) |
| 17 |
| 18 class MagnifierBench : public SkBenchmark { |
| 19 public: |
| 20 MagnifierBench(void* param, bool small) : |
| 21 INHERITED(param), fIsSmall(small), fInitialized(false) { |
| 22 } |
| 23 |
| 24 protected: |
| 25 virtual const char* onGetName() SK_OVERRIDE { |
| 26 return fIsSmall ? "magnifier_small" : "magnifier_large"; |
| 27 } |
| 28 |
| 29 virtual void onPreDraw() SK_OVERRIDE { |
| 30 if (!fInitialized) { |
| 31 make_checkerboard(); |
| 32 fInitialized = true; |
| 33 } |
| 34 } |
| 35 |
| 36 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 37 const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; |
| 38 const int h = fIsSmall ? FILTER_HEIGHT_SMALL : FILTER_HEIGHT_LARGE; |
| 39 SkPaint paint; |
| 40 paint.setImageFilter( |
| 41 new SkMagnifierImageFilter( |
| 42 SkRect::MakeXYWH(SkIntToScalar(w / 4), |
| 43 SkIntToScalar(h / 4), |
| 44 SkIntToScalar(w / 2), |
| 45 SkIntToScalar(h / 2)), 100))->unref(); |
| 46 canvas->drawBitmap(fCheckerboard, 0, 0, &paint); |
| 47 } |
| 48 |
| 49 private: |
| 50 void make_checkerboard() { |
| 51 const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; |
| 52 const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; |
| 53 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, w, h); |
| 54 fCheckerboard.allocPixels(); |
| 55 SkDevice device(fCheckerboard); |
| 56 SkCanvas canvas(&device); |
| 57 canvas.clear(0x00000000); |
| 58 SkPaint darkPaint; |
| 59 darkPaint.setColor(0xFF804020); |
| 60 SkPaint lightPaint; |
| 61 lightPaint.setColor(0xFF244484); |
| 62 for (int y = 0; y < h; y += 16) { |
| 63 for (int x = 0; x < w; x += 16) { |
| 64 canvas.save(); |
| 65 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 66 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); |
| 67 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); |
| 68 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); |
| 69 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); |
| 70 canvas.restore(); |
| 71 } |
| 72 } |
| 73 } |
| 74 |
| 75 bool fIsSmall; |
| 76 bool fInitialized; |
| 77 SkBitmap fCheckerboard; |
| 78 typedef SkBenchmark INHERITED; |
| 79 }; |
| 80 |
| 81 /////////////////////////////////////////////////////////////////////////////// |
| 82 |
| 83 DEF_BENCH( return new MagnifierBench(p, true); ) |
| 84 DEF_BENCH( return new MagnifierBench(p, false); ) |
| 85 |
OLD | NEW |