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