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 "SkBitmapSource.h" | 9 #include "SkBitmapSource.h" |
9 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
10 #include "SkDevice.h" | |
11 #include "SkDisplacementMapEffect.h" | 11 #include "SkDisplacementMapEffect.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 DisplacementBaseBench : public SkBenchmark { | 18 class DisplacementBaseBench : public SkBenchmark { |
19 public: | 19 public: |
20 DisplacementBaseBench(void* param, bool small) : | 20 DisplacementBaseBench(void* param, bool small) : |
21 INHERITED(param), fInitialized(false), fIsSmall(small) { | 21 INHERITED(param), fInitialized(false), fIsSmall(small) { |
22 } | 22 } |
23 | 23 |
24 protected: | 24 protected: |
25 virtual void onPreDraw() SK_OVERRIDE { | 25 virtual void onPreDraw() SK_OVERRIDE { |
26 if (!fInitialized) { | 26 if (!fInitialized) { |
27 make_bitmap(); | 27 make_bitmap(); |
28 make_checkerboard(); | 28 make_checkerboard(); |
29 fInitialized = true; | 29 fInitialized = true; |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 void make_bitmap() { | 33 void make_bitmap() { |
34 const int w = isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; | 34 const int w = isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; |
35 const int h = isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; | 35 const int h = isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; |
36 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); | 36 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); |
37 fBitmap.allocPixels(); | 37 fBitmap.allocPixels(); |
38 SkDevice device(fBitmap); | 38 SkBitmapDevice device(fBitmap); |
39 SkCanvas canvas(&device); | 39 SkCanvas canvas(&device); |
40 canvas.clear(0x00000000); | 40 canvas.clear(0x00000000); |
41 SkPaint paint; | 41 SkPaint paint; |
42 paint.setAntiAlias(true); | 42 paint.setAntiAlias(true); |
43 paint.setColor(0xFF884422); | 43 paint.setColor(0xFF884422); |
44 paint.setTextSize(SkIntToScalar(96)); | 44 paint.setTextSize(SkIntToScalar(96)); |
45 const char* str = "g"; | 45 const char* str = "g"; |
46 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55),
paint); | 46 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55),
paint); |
47 } | 47 } |
48 | 48 |
49 void make_checkerboard() { | 49 void make_checkerboard() { |
50 const int w = isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; | 50 const int w = isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; |
51 const int h = isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; | 51 const int h = isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; |
52 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, w, h); | 52 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, w, h); |
53 fCheckerboard.allocPixels(); | 53 fCheckerboard.allocPixels(); |
54 SkDevice device(fCheckerboard); | 54 SkBitmapDevice device(fCheckerboard); |
55 SkCanvas canvas(&device); | 55 SkCanvas canvas(&device); |
56 canvas.clear(0x00000000); | 56 canvas.clear(0x00000000); |
57 SkPaint darkPaint; | 57 SkPaint darkPaint; |
58 darkPaint.setColor(0xFF804020); | 58 darkPaint.setColor(0xFF804020); |
59 SkPaint lightPaint; | 59 SkPaint lightPaint; |
60 lightPaint.setColor(0xFF244484); | 60 lightPaint.setColor(0xFF244484); |
61 for (int y = 0; y < h; y += 16) { | 61 for (int y = 0; y < h; y += 16) { |
62 for (int x = 0; x < w; x += 16) { | 62 for (int x = 0; x < w; x += 16) { |
63 canvas.save(); | 63 canvas.save(); |
64 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); | 64 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 }; | 161 }; |
162 | 162 |
163 /////////////////////////////////////////////////////////////////////////////// | 163 /////////////////////////////////////////////////////////////////////////////// |
164 | 164 |
165 DEF_BENCH( return new DisplacementZeroBench(p, true); ) | 165 DEF_BENCH( return new DisplacementZeroBench(p, true); ) |
166 DEF_BENCH( return new DisplacementAlphaBench(p, true); ) | 166 DEF_BENCH( return new DisplacementAlphaBench(p, true); ) |
167 DEF_BENCH( return new DisplacementFullBench(p, true); ) | 167 DEF_BENCH( return new DisplacementFullBench(p, true); ) |
168 DEF_BENCH( return new DisplacementZeroBench(p, false); ) | 168 DEF_BENCH( return new DisplacementZeroBench(p, false); ) |
169 DEF_BENCH( return new DisplacementAlphaBench(p, false); ) | 169 DEF_BENCH( return new DisplacementAlphaBench(p, false); ) |
170 DEF_BENCH( return new DisplacementFullBench(p, false); ) | 170 DEF_BENCH( return new DisplacementFullBench(p, false); ) |
OLD | NEW |