1 /* 2 * Copyright 2017 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 "Benchmark.h" 9 #include "SkBitmap.h" 10 #include "SkCanvas.h" 11 #include "SkColorSpaceXformCanvas.h" 12 #include "SkString.h" 13 14 class ColorCanvasDrawBitmap : public Benchmark { 15 public: ColorCanvasDrawBitmap(sk_sp<SkColorSpace> src,sk_sp<SkColorSpace> dst,const char * name)16 ColorCanvasDrawBitmap(sk_sp<SkColorSpace> src, sk_sp<SkColorSpace> dst, const char* name) 17 : fDst(dst) 18 , fName(SkStringPrintf("ColorCanvasDrawBitmap_%s", name)) 19 { 20 fBitmap.allocPixels(SkImageInfo::MakeN32(100, 100, kOpaque_SkAlphaType, src)); 21 fBitmap.eraseColor(SK_ColorBLUE); 22 } 23 onGetName()24 const char* onGetName() override { 25 return fName.c_str(); 26 } 27 onGetSize()28 SkIPoint onGetSize() override { 29 return SkIPoint::Make(100, 100); 30 } 31 isSuitableFor(Backend backend)32 bool isSuitableFor(Backend backend) override { 33 return kRaster_Backend == backend || kGPU_Backend == backend; 34 } 35 onDraw(int n,SkCanvas * canvas)36 void onDraw(int n, SkCanvas* canvas) override { 37 // This simulates an Android app that draws bitmaps to a software canvas. 38 // Chrome and the Android framework both use SkImages exclusively. 39 std::unique_ptr<SkCanvas> colorCanvas = SkCreateColorSpaceXformCanvas(canvas, fDst); 40 for (int i = 0; i < n; i++) { 41 colorCanvas->drawBitmap(fBitmap, 0, 0, nullptr); 42 } 43 } 44 45 private: 46 sk_sp<SkColorSpace> fDst; 47 SkString fName; 48 SkBitmap fBitmap; 49 50 typedef Benchmark INHERITED; 51 }; 52 53 DEF_BENCH(return new ColorCanvasDrawBitmap(nullptr, SkColorSpace::MakeSRGB(), "null_to_sRGB");) 54 DEF_BENCH(return new ColorCanvasDrawBitmap(SkColorSpace::MakeSRGB(), SkColorSpace::MakeSRGB(), 55 "sRGB_to_sRGB");) 56 DEF_BENCH(return new ColorCanvasDrawBitmap( 57 SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kAdobeRGB_Gamut), 58 SkColorSpace::MakeSRGB(), "AdobeRGB_to_sRGB");) 59