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(SkCanvas::Config8888 config) 17 : fConfig(config) 18 , fName("writepix") { 19 switch (config) { 20 case SkCanvas::kNative_Premul_Config8888: 21 fName.append("_native_PM"); 22 break; 23 case SkCanvas::kNative_Unpremul_Config8888: 24 fName.append("_native_UPM"); 25 break; 26 case SkCanvas::kBGRA_Premul_Config8888: 27 fName.append("_bgra_PM"); 28 break; 29 case SkCanvas::kBGRA_Unpremul_Config8888: 30 fName.append("_bgra_UPM"); 31 break; 32 case SkCanvas::kRGBA_Premul_Config8888: 33 fName.append("_rgba_PM"); 34 break; 35 case SkCanvas::kRGBA_Unpremul_Config8888: 36 fName.append("_rgba_UPM"); 37 break; 38 default: 39 SK_CRASH(); 40 break; 41 } 42 } 43 44 protected: 45 virtual const char* onGetName() SK_OVERRIDE { 46 return fName.c_str(); 47 } 48 49 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 50 SkISize size = canvas->getDeviceSize(); 51 52 canvas->clear(0xFFFF0000); 53 54 SkBitmap bmp; 55 bmp.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); 56 canvas->readPixels(&bmp, 0, 0); 57 58 for (int loop = 0; loop < loops; ++loop) { 59 canvas->writePixels(bmp, 0, 0, fConfig); 60 } 61 } 62 63 private: 64 SkCanvas::Config8888 fConfig; 65 SkString fName; 66 67 typedef SkBenchmark INHERITED; 68 }; 69 70 ////////////////////////////////////////////////////////////////////////////// 71 72 DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (SkCanvas::kRGBA_Premul_Config8888)); ) 73 DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (SkCanvas::kRGBA_Unpremul_Config8888)); ) 74