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 #include "SkBenchmark.h" | 7 #include "SkBenchmark.h" |
| 8 #include "SkBitmapDevice.h" |
8 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
9 #include "SkDevice.h" | |
10 #include "SkMagnifierImageFilter.h" | 10 #include "SkMagnifierImageFilter.h" |
11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
12 | 12 |
13 #define FILTER_WIDTH_SMALL 32 | 13 #define FILTER_WIDTH_SMALL 32 |
14 #define FILTER_HEIGHT_SMALL 32 | 14 #define FILTER_HEIGHT_SMALL 32 |
15 #define FILTER_WIDTH_LARGE 256 | 15 #define FILTER_WIDTH_LARGE 256 |
16 #define FILTER_HEIGHT_LARGE 256 | 16 #define FILTER_HEIGHT_LARGE 256 |
17 | 17 |
18 class MagnifierBench : public SkBenchmark { | 18 class MagnifierBench : public SkBenchmark { |
19 public: | 19 public: |
(...skipping 25 matching lines...) Expand all Loading... |
45 SkIntToScalar(h / 2)), 100))->unref(); | 45 SkIntToScalar(h / 2)), 100))->unref(); |
46 canvas->drawBitmap(fCheckerboard, 0, 0, &paint); | 46 canvas->drawBitmap(fCheckerboard, 0, 0, &paint); |
47 } | 47 } |
48 | 48 |
49 private: | 49 private: |
50 void make_checkerboard() { | 50 void make_checkerboard() { |
51 const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; | 51 const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; |
52 const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; | 52 const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; |
53 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, w, h); | 53 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, w, h); |
54 fCheckerboard.allocPixels(); | 54 fCheckerboard.allocPixels(); |
55 SkDevice device(fCheckerboard); | 55 SkBitmapDevice device(fCheckerboard); |
56 SkCanvas canvas(&device); | 56 SkCanvas canvas(&device); |
57 canvas.clear(0x00000000); | 57 canvas.clear(0x00000000); |
58 SkPaint darkPaint; | 58 SkPaint darkPaint; |
59 darkPaint.setColor(0xFF804020); | 59 darkPaint.setColor(0xFF804020); |
60 SkPaint lightPaint; | 60 SkPaint lightPaint; |
61 lightPaint.setColor(0xFF244484); | 61 lightPaint.setColor(0xFF244484); |
62 for (int y = 0; y < h; y += 16) { | 62 for (int y = 0; y < h; y += 16) { |
63 for (int x = 0; x < w; x += 16) { | 63 for (int x = 0; x < w; x += 16) { |
64 canvas.save(); | 64 canvas.save(); |
65 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); | 65 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); |
66 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); | 66 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); |
67 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); | 67 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); |
68 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); | 68 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); |
69 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | 69 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); |
70 canvas.restore(); | 70 canvas.restore(); |
71 } | 71 } |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 bool fIsSmall; | 75 bool fIsSmall; |
76 bool fInitialized; | 76 bool fInitialized; |
77 SkBitmap fCheckerboard; | 77 SkBitmap fCheckerboard; |
78 typedef SkBenchmark INHERITED; | 78 typedef SkBenchmark INHERITED; |
79 }; | 79 }; |
80 | 80 |
81 /////////////////////////////////////////////////////////////////////////////// | 81 /////////////////////////////////////////////////////////////////////////////// |
82 | 82 |
83 DEF_BENCH( return new MagnifierBench(p, true); ) | 83 DEF_BENCH( return new MagnifierBench(p, true); ) |
84 DEF_BENCH( return new MagnifierBench(p, false); ) | 84 DEF_BENCH( return new MagnifierBench(p, false); ) |
OLD | NEW |