Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 dst : same size as src, diff size | 37 dst : same size as src, diff size |
| 38 paint : filter-p | 38 paint : filter-p |
| 39 */ | 39 */ |
| 40 | 40 |
| 41 class BitmapRectBench : public SkBenchmark { | 41 class BitmapRectBench : public SkBenchmark { |
| 42 SkBitmap fBitmap; | 42 SkBitmap fBitmap; |
| 43 bool fDoFilter; | 43 bool fDoFilter; |
| 44 bool fSlightMatrix; | 44 bool fSlightMatrix; |
| 45 uint8_t fAlpha; | 45 uint8_t fAlpha; |
| 46 SkString fName; | 46 SkString fName; |
| 47 SkRect fSrcR, fDstR; | 47 SkRect fSrcR, fDstR; |
|
robertphillips
2013/07/29 11:57:10
kWidth, kHeight
| |
| 48 static const int w = 128; | |
| 49 static const int h = 128; | |
| 48 enum { N = SkBENCHLOOP(300) }; | 50 enum { N = SkBENCHLOOP(300) }; |
| 49 public: | 51 public: |
| 50 BitmapRectBench(void* param, U8CPU alpha, bool doFilter, bool slightMatrix) : INHERITED(param) { | 52 BitmapRectBench(void* param, U8CPU alpha, bool doFilter, bool slightMatrix) : INHERITED(param) { |
| 51 fAlpha = SkToU8(alpha); | 53 fAlpha = SkToU8(alpha); |
| 52 fDoFilter = doFilter; | 54 fDoFilter = doFilter; |
| 53 fSlightMatrix = slightMatrix; | 55 fSlightMatrix = slightMatrix; |
| 54 | 56 |
| 55 const int w = 128; | 57 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); |
| 56 const int h = 128; | 58 } |
| 57 | 59 |
| 58 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); | 60 protected: |
|
robertphillips
2013/07/29 11:57:10
SK_OVERRIDE
| |
| 61 virtual const char* onGetName() { | |
| 62 fName.printf("bitmaprect_%02X_%sfilter_%s", | |
| 63 fAlpha, fDoFilter ? "" : "no", | |
| 64 fSlightMatrix ? "trans" : "identity"); | |
| 65 return fName.c_str(); | |
| 66 } | |
| 67 | |
|
robertphillips
2013/07/29 11:57:10
SK_OVERRIDE
| |
| 68 virtual void onPreDraw() { | |
| 59 fBitmap.allocPixels(); | 69 fBitmap.allocPixels(); |
| 60 fBitmap.setIsOpaque(true); | 70 fBitmap.setIsOpaque(true); |
| 61 fBitmap.eraseColor(SK_ColorBLACK); | 71 fBitmap.eraseColor(SK_ColorBLACK); |
|
robertphillips
2013/07/29 11:57:10
rename to draw_into_bitmap
| |
| 62 drawIntoBitmap(fBitmap); | 72 drawIntoBitmap(fBitmap); |
| 63 | 73 |
| 64 fSrcR.iset(0, 0, w, h); | 74 fSrcR.iset(0, 0, w, h); |
| 65 fDstR.iset(0, 0, w, h); | 75 fDstR.iset(0, 0, w, h); |
| 66 | 76 |
| 67 if (slightMatrix) { | 77 if (fSlightMatrix) { |
| 68 // want fractional translate | 78 // want fractional translate |
| 69 fDstR.offset(SK_Scalar1 / 3, SK_Scalar1 * 5 / 7); | 79 fDstR.offset(SK_Scalar1 / 3, SK_Scalar1 * 5 / 7); |
| 70 // want enough to create a scale matrix, but not enough to scare | 80 // want enough to create a scale matrix, but not enough to scare |
| 71 // off our sniffer which tries to see if the matrix is "effectively" | 81 // off our sniffer which tries to see if the matrix is "effectively" |
| 72 // translate-only. | 82 // translate-only. |
| 73 fDstR.fRight += SK_Scalar1 / (w * 60); | 83 fDstR.fRight += SK_Scalar1 / (w * 60); |
| 74 } | 84 } |
| 75 } | 85 } |
| 76 | 86 |
| 77 protected: | |
| 78 virtual const char* onGetName() { | |
| 79 fName.printf("bitmaprect_%02X_%sfilter_%s", | |
| 80 fAlpha, fDoFilter ? "" : "no", | |
| 81 fSlightMatrix ? "trans" : "identity"); | |
| 82 return fName.c_str(); | |
| 83 } | |
| 84 | 87 |
|
robertphillips
2013/07/29 11:57:10
SK_OVERRIDE
| |
| 85 virtual void onDraw(SkCanvas* canvas) { | 88 virtual void onDraw(SkCanvas* canvas) { |
| 86 SkRandom rand; | 89 SkRandom rand; |
| 87 | 90 |
| 88 SkPaint paint; | 91 SkPaint paint; |
| 89 this->setupPaint(&paint); | 92 this->setupPaint(&paint); |
| 90 paint.setFilterBitmap(fDoFilter); | 93 paint.setFilterBitmap(fDoFilter); |
| 91 paint.setAlpha(fAlpha); | 94 paint.setAlpha(fAlpha); |
| 92 | 95 |
| 93 for (int i = 0; i < N; i++) { | 96 for (int i = 0; i < N; i++) { |
| 94 canvas->drawBitmapRectToRect(fBitmap, &fSrcR, fDstR, &paint); | 97 canvas->drawBitmapRectToRect(fBitmap, &fSrcR, fDstR, &paint); |
| 95 } | 98 } |
| 96 } | 99 } |
| 97 | 100 |
| 98 private: | 101 private: |
| 99 typedef SkBenchmark INHERITED; | 102 typedef SkBenchmark INHERITED; |
| 100 }; | 103 }; |
| 101 | 104 |
| 102 DEF_BENCH(return new BitmapRectBench(p, 0xFF, false, false)) | 105 DEF_BENCH(return new BitmapRectBench(p, 0xFF, false, false)) |
| 103 DEF_BENCH(return new BitmapRectBench(p, 0x80, false, false)) | 106 DEF_BENCH(return new BitmapRectBench(p, 0x80, false, false)) |
| 104 DEF_BENCH(return new BitmapRectBench(p, 0xFF, true, false)) | 107 DEF_BENCH(return new BitmapRectBench(p, 0xFF, true, false)) |
| 105 DEF_BENCH(return new BitmapRectBench(p, 0x80, true, false)) | 108 DEF_BENCH(return new BitmapRectBench(p, 0x80, true, false)) |
| 106 | 109 |
| 107 DEF_BENCH(return new BitmapRectBench(p, 0xFF, false, true)) | 110 DEF_BENCH(return new BitmapRectBench(p, 0xFF, false, true)) |
| 108 DEF_BENCH(return new BitmapRectBench(p, 0xFF, true, true)) | 111 DEF_BENCH(return new BitmapRectBench(p, 0xFF, true, true)) |
| OLD | NEW |