1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "bench/Benchmark.h" 9 #include "include/core/SkBitmap.h" 10 #include "include/core/SkCanvas.h" 11 #include "include/core/SkString.h" 12 13 // Time variants of write-pixels 14 // [ colortype ][ alphatype ][ colorspace ] 15 // Different combinations can trigger fast or slow paths in the impls 16 // 17 class WritePixelsBench : public Benchmark { 18 public: WritePixelsBench(SkColorType ct,SkAlphaType at,sk_sp<SkColorSpace> cs)19 WritePixelsBench(SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs) 20 : fColorType(ct) 21 , fAlphaType(at) 22 , fCS(cs) 23 { 24 fName.printf("writepix_%s_%s_%s", 25 at == kPremul_SkAlphaType ? "pm" : "um", 26 ct == kRGBA_8888_SkColorType ? "rgba" : "bgra", 27 cs ? "srgb" : "null"); 28 } 29 30 protected: onGetName()31 const char* onGetName() override { 32 return fName.c_str(); 33 } 34 onDraw(int loops,SkCanvas * canvas)35 void onDraw(int loops, SkCanvas* canvas) override { 36 SkISize size = canvas->getBaseLayerSize(); 37 38 SkImageInfo info = SkImageInfo::Make(size, fColorType, fAlphaType, fCS); 39 SkBitmap bmp; 40 bmp.allocPixels(info); 41 bmp.eraseColor(SK_ColorBLACK); 42 43 for (int loop = 0; loop < loops; ++loop) { 44 canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0); 45 } 46 } 47 48 private: 49 SkColorType fColorType; 50 SkAlphaType fAlphaType; 51 sk_sp<SkColorSpace> fCS; 52 SkString fName; 53 54 using INHERITED = Benchmark; 55 }; 56 57 ////////////////////////////////////////////////////////////////////////////// 58 59 DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);) 60 DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);) 61 DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());) 62 DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());) 63 64 DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, nullptr);) 65 DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);) 66 DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());) 67 DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());) 68