| 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 21 matching lines...) Expand all Loading... |
| 32 canvas.drawRect(r, p); | 32 canvas.drawRect(r, p); |
| 33 } | 33 } |
| 34 | 34 |
| 35 /* Variants for bitmaprect | 35 /* Variants for bitmaprect |
| 36 src : entire bitmap, subset, fractional subset | 36 src : entire bitmap, subset, fractional subset |
| 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 fSlightMatrix; |
| 44 bool fSlightMatrix; | 44 uint8_t fAlpha; |
| 45 uint8_t fAlpha; | 45 SkPaint::FilterLevel fFilterLevel; |
| 46 SkString fName; | 46 SkString fName; |
| 47 SkRect fSrcR, fDstR; | 47 SkRect fSrcR, fDstR; |
| 48 |
| 48 static const int kWidth = 128; | 49 static const int kWidth = 128; |
| 49 static const int kHeight = 128; | 50 static const int kHeight = 128; |
| 50 public: | 51 public: |
| 51 BitmapRectBench(U8CPU alpha, bool doFilter, bool slightMatrix) { | 52 BitmapRectBench(U8CPU alpha, SkPaint::FilterLevel filterLevel, |
| 53 bool slightMatrix) { |
| 52 fAlpha = SkToU8(alpha); | 54 fAlpha = SkToU8(alpha); |
| 53 fDoFilter = doFilter; | 55 fFilterLevel = filterLevel; |
| 54 fSlightMatrix = slightMatrix; | 56 fSlightMatrix = slightMatrix; |
| 55 | 57 |
| 56 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, kWidth, kHeight); | 58 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, kWidth, kHeight); |
| 57 } | 59 } |
| 58 | 60 |
| 59 protected: | 61 protected: |
| 60 virtual const char* onGetName() SK_OVERRIDE { | 62 virtual const char* onGetName() SK_OVERRIDE { |
| 61 fName.printf("bitmaprect_%02X_%sfilter_%s", | 63 fName.printf("bitmaprect_%02X_%sfilter_%s", |
| 62 fAlpha, fDoFilter ? "" : "no", | 64 fAlpha, |
| 65 SkPaint::kNone_FilterLevel == fFilterLevel ? "no" : "", |
| 63 fSlightMatrix ? "trans" : "identity"); | 66 fSlightMatrix ? "trans" : "identity"); |
| 64 return fName.c_str(); | 67 return fName.c_str(); |
| 65 } | 68 } |
| 66 | 69 |
| 67 virtual void onPreDraw() SK_OVERRIDE { | 70 virtual void onPreDraw() SK_OVERRIDE { |
| 68 fBitmap.allocPixels(); | 71 fBitmap.allocPixels(); |
| 69 fBitmap.setAlphaType(kOpaque_SkAlphaType); | 72 fBitmap.setAlphaType(kOpaque_SkAlphaType); |
| 70 fBitmap.eraseColor(SK_ColorBLACK); | 73 fBitmap.eraseColor(SK_ColorBLACK); |
| 71 draw_into_bitmap(fBitmap); | 74 draw_into_bitmap(fBitmap); |
| 72 | 75 |
| 73 fSrcR.iset(0, 0, kWidth, kHeight); | 76 fSrcR.iset(0, 0, kWidth, kHeight); |
| 74 fDstR.iset(0, 0, kWidth, kHeight); | 77 fDstR.iset(0, 0, kWidth, kHeight); |
| 75 | 78 |
| 76 if (fSlightMatrix) { | 79 if (fSlightMatrix) { |
| 77 // want fractional translate | 80 // want fractional translate |
| 78 fDstR.offset(SK_Scalar1 / 3, SK_Scalar1 * 5 / 7); | 81 fDstR.offset(SK_Scalar1 / 3, SK_Scalar1 * 5 / 7); |
| 79 // want enough to create a scale matrix, but not enough to scare | 82 // want enough to create a scale matrix, but not enough to scare |
| 80 // off our sniffer which tries to see if the matrix is "effectively" | 83 // off our sniffer which tries to see if the matrix is "effectively" |
| 81 // translate-only. | 84 // translate-only. |
| 82 fDstR.fRight += SK_Scalar1 / (kWidth * 60); | 85 fDstR.fRight += SK_Scalar1 / (kWidth * 60); |
| 83 } | 86 } |
| 84 } | 87 } |
| 85 | 88 |
| 86 | 89 |
| 87 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 90 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 88 SkRandom rand; | 91 SkRandom rand; |
| 89 | 92 |
| 90 SkPaint paint; | 93 SkPaint paint; |
| 91 this->setupPaint(&paint); | 94 this->setupPaint(&paint); |
| 92 paint.setFilterBitmap(fDoFilter); | 95 paint.setFilterLevel(fFilterLevel); |
| 93 paint.setAlpha(fAlpha); | 96 paint.setAlpha(fAlpha); |
| 94 | 97 |
| 95 for (int i = 0; i < this->getLoops(); i++) { | 98 for (int i = 0; i < this->getLoops(); i++) { |
| 96 canvas->drawBitmapRectToRect(fBitmap, &fSrcR, fDstR, &paint); | 99 canvas->drawBitmapRectToRect(fBitmap, &fSrcR, fDstR, &paint); |
| 97 } | 100 } |
| 98 } | 101 } |
| 99 | 102 |
| 100 private: | 103 private: |
| 101 typedef SkBenchmark INHERITED; | 104 typedef SkBenchmark INHERITED; |
| 102 }; | 105 }; |
| 103 | 106 |
| 104 DEF_BENCH(return new BitmapRectBench(0xFF, false, false)) | 107 DEF_BENCH(return new BitmapRectBench(0xFF, SkPaint::kNone_FilterLevel, false)) |
| 105 DEF_BENCH(return new BitmapRectBench(0x80, false, false)) | 108 DEF_BENCH(return new BitmapRectBench(0x80, SkPaint::kNone_FilterLevel, false)) |
| 106 DEF_BENCH(return new BitmapRectBench(0xFF, true, false)) | 109 DEF_BENCH(return new BitmapRectBench(0xFF, SkPaint::kLow_FilterLevel, false)) |
| 107 DEF_BENCH(return new BitmapRectBench(0x80, true, false)) | 110 DEF_BENCH(return new BitmapRectBench(0x80, SkPaint::kLow_FilterLevel, false)) |
| 108 | 111 |
| 109 DEF_BENCH(return new BitmapRectBench(0xFF, false, true)) | 112 DEF_BENCH(return new BitmapRectBench(0xFF, SkPaint::kNone_FilterLevel, true)) |
| 110 DEF_BENCH(return new BitmapRectBench(0xFF, true, true)) | 113 DEF_BENCH(return new BitmapRectBench(0xFF, SkPaint::kLow_FilterLevel, true)) |
| OLD | NEW |