From: Florin Malita Date: Mon, 1 May 2017 20:27:02 +0000 (-0400) Subject: Add a clip mask bench X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~36^2~541 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c59a38d12dce287427f3d3fe1d4b3ad8052cda35;p=platform%2Fupstream%2FlibSkiaSharp.git Add a clip mask bench Change-Id: I230729492fc23e290136f7d62610abe5ca51c067 Reviewed-on: https://skia-review.googlesource.com/14941 Reviewed-by: Mike Reed Commit-Queue: Florin Malita --- diff --git a/bench/ClipMaskBench.cpp b/bench/ClipMaskBench.cpp new file mode 100644 index 0000000..b678397 --- /dev/null +++ b/bench/ClipMaskBench.cpp @@ -0,0 +1,68 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "Benchmark.h" +#include "sk_tool_utils.h" +#include "SkCanvas.h" +#include "SkColorSpace.h" +#include "SkImage.h" +#include "SkPictureRecorder.h" +#include "SkString.h" +#include "SkSurface.h" + +static void DrawMask(SkCanvas* canvas) { + sk_tool_utils::draw_checkerboard(canvas, SK_ColorTRANSPARENT, SK_ColorGREEN, 10); +} + +class ClipMaskBench : public Benchmark { +public: + using MaskMakerFunc = sk_sp (*)(int); + + ClipMaskBench(const char name[], const MaskMakerFunc maskMaker) + : fName(SkStringPrintf("clipmask_%s", name)) + , fClip(maskMaker(kSize)) {} + +protected: + const char* onGetName() override { return fName.c_str(); } + + void onDraw(int loops, SkCanvas* canvas) override { + SkCanvas::SaveLayerRec rec(nullptr, nullptr, nullptr, fClip, nullptr, 0); + + for (int i = 0; i < loops; ++i) { + canvas->saveLayer(rec); + canvas->drawColor(SK_ColorBLUE); + canvas->restore(); + } + } + +private: + static constexpr int kSize = 400; + + SkString fName; + sk_sp fClip; +}; + +DEF_BENCH(return new ClipMaskBench("a8", [](int size) -> sk_sp { + sk_sp surface = SkSurface::MakeRaster(SkImageInfo::MakeA8(size, size)); + DrawMask(surface->getCanvas()); + return surface->makeImageSnapshot(); +});) + +DEF_BENCH(return new ClipMaskBench("8888", [](int size) -> sk_sp { + sk_sp surface = SkSurface::MakeRasterN32Premul(size, size); + DrawMask(surface->getCanvas()); + return surface->makeImageSnapshot(); +});) + +DEF_BENCH(return new ClipMaskBench("picture", [](int size) -> sk_sp { + SkPictureRecorder recorder; + DrawMask(recorder.beginRecording(size, size)); + return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), SkISize::Make(size, size), + nullptr, nullptr, SkImage::BitDepth::kU8, + SkColorSpace::MakeSRGB()); +});) + diff --git a/gn/bench.gni b/gn/bench.gni index 5aff91b..4364f65 100644 --- a/gn/bench.gni +++ b/gn/bench.gni @@ -27,6 +27,7 @@ bench_sources = [ "$_bench/ChartBench.cpp", "$_bench/ChecksumBench.cpp", "$_bench/ChromeBench.cpp", + "$_bench/ClipMaskBench.cpp", "$_bench/CmapBench.cpp", "$_bench/CodecBench.cpp", "$_bench/ColorCanvasDrawBitmapBench.cpp",