OLD | NEW |
(Empty) | |
| 1 |
| 2 /* |
| 3 * Copyright 2013 Google Inc. |
| 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. |
| 7 */ |
| 8 |
| 9 #include "SkBenchmark.h" |
| 10 #include "SkCanvas.h" |
| 11 #include "SkConfig8888.h" |
| 12 #include "SkString.h" |
| 13 |
| 14 class WritePixelsBench : public SkBenchmark { |
| 15 public: |
| 16 WritePixelsBench(void* param, SkCanvas::Config8888 config) |
| 17 : INHERITED(param) |
| 18 , fConfig(config) |
| 19 , fName("writepix") { |
| 20 switch (config) { |
| 21 case SkCanvas::kNative_Premul_Config8888: |
| 22 fName.append("_native_PM"); |
| 23 break; |
| 24 case SkCanvas::kNative_Unpremul_Config8888: |
| 25 fName.append("_native_UPM"); |
| 26 break; |
| 27 case SkCanvas::kBGRA_Premul_Config8888: |
| 28 fName.append("_bgra_PM"); |
| 29 break; |
| 30 case SkCanvas::kBGRA_Unpremul_Config8888: |
| 31 fName.append("_bgra_UPM"); |
| 32 break; |
| 33 case SkCanvas::kRGBA_Premul_Config8888: |
| 34 fName.append("_rgba_PM"); |
| 35 break; |
| 36 case SkCanvas::kRGBA_Unpremul_Config8888: |
| 37 fName.append("_rgba_UPM"); |
| 38 break; |
| 39 default: |
| 40 SK_CRASH(); |
| 41 break; |
| 42 } |
| 43 } |
| 44 |
| 45 protected: |
| 46 virtual const char* onGetName() SK_OVERRIDE { |
| 47 return fName.c_str(); |
| 48 } |
| 49 |
| 50 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 51 SkISize size = canvas->getDeviceSize(); |
| 52 |
| 53 canvas->clear(0xFFFF0000); |
| 54 |
| 55 SkBitmap bmp; |
| 56 bmp.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
| 57 canvas->readPixels(&bmp, 0, 0); |
| 58 |
| 59 for (int loop = 0; loop < kLoopCount; ++loop) { |
| 60 canvas->writePixels(bmp, 0, 0, fConfig); |
| 61 } |
| 62 } |
| 63 |
| 64 private: |
| 65 static const int kLoopCount = SkBENCHLOOP(50); |
| 66 |
| 67 SkCanvas::Config8888 fConfig; |
| 68 SkString fName; |
| 69 |
| 70 typedef SkBenchmark INHERITED; |
| 71 }; |
| 72 |
| 73 ////////////////////////////////////////////////////////////////////////////// |
| 74 |
| 75 DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (p, SkCanvas::kRGBA_Premul_Config
8888)); ) |
| 76 DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (p, SkCanvas::kRGBA_Unpremul_Conf
ig8888)); ) |
| 77 |
OLD | NEW |