2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColorPriv.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2009-08-12 20:30:58 +00:00
|
|
|
|
When skia run bench cases to test performance, it will run constructors for all cases one by one, then getName to skip unnecessary cases according to command line parameters, so these constructors should be lightweight enough to avoid redundant computing. Unfortunately, some constructors contain intensive computing/rendering. They are very heavy, maybe much heavier than need-to-run bench case itself. And these redundant computation will be run every time you run bench, even you just test a single simple case. Moreover, it will mislead the real hotspot/bottleneck of the case itself.
For example, run a lightweight case, say, region_intersectsrgn_16, the hot spots are gles operation, SuperBlitter, SkRTree... introduced by irrelevant cases' constructors. These redundant computation will mislead performance tuning.
So we can move these intensive computation to onPreDraw() of these case. They will be executed only if this case should be run.
R=reed@google.com, robertphillips@google.com, humper@google.com, tomhudson@chromium.org
Author: yunchao.he@intel.com
Review URL: https://chromiumcodereview.appspot.com/20997003
git-svn-id: http://skia.googlecode.com/svn/trunk@10486 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-08-01 15:58:07 +00:00
|
|
|
static void draw_into_bitmap(const SkBitmap& bm) {
|
2009-08-12 20:30:58 +00:00
|
|
|
const int w = bm.width();
|
|
|
|
const int h = bm.height();
|
|
|
|
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setColor(SK_ColorRED);
|
|
|
|
canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2,
|
2020-02-06 16:25:43 +00:00
|
|
|
SkIntToScalar(std::min(w, h))*3/8, p);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-08-12 20:30:58 +00:00
|
|
|
SkRect r;
|
2019-08-24 23:39:13 +00:00
|
|
|
r.setWH(SkIntToScalar(w), SkIntToScalar(h));
|
2009-08-12 20:30:58 +00:00
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(SkIntToScalar(4));
|
|
|
|
p.setColor(SK_ColorBLUE);
|
|
|
|
canvas.drawRect(r, p);
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class RepeatTileBench : public Benchmark {
|
2014-06-10 02:52:07 +00:00
|
|
|
const SkAlphaType fAlphaType;
|
|
|
|
SkPaint fPaint;
|
|
|
|
SkString fName;
|
|
|
|
SkBitmap fBitmap;
|
2009-08-12 20:30:58 +00:00
|
|
|
public:
|
2017-07-03 17:36:17 +00:00
|
|
|
RepeatTileBench(SkColorType ct, SkAlphaType at = kPremul_SkAlphaType) : fAlphaType(at) {
|
2009-08-12 20:30:58 +00:00
|
|
|
const int w = 50;
|
|
|
|
const int h = 50;
|
|
|
|
|
2017-07-03 17:36:17 +00:00
|
|
|
fBitmap.setInfo(SkImageInfo::Make(w, h, ct, at));
|
When skia run bench cases to test performance, it will run constructors for all cases one by one, then getName to skip unnecessary cases according to command line parameters, so these constructors should be lightweight enough to avoid redundant computing. Unfortunately, some constructors contain intensive computing/rendering. They are very heavy, maybe much heavier than need-to-run bench case itself. And these redundant computation will be run every time you run bench, even you just test a single simple case. Moreover, it will mislead the real hotspot/bottleneck of the case itself.
For example, run a lightweight case, say, region_intersectsrgn_16, the hot spots are gles operation, SuperBlitter, SkRTree... introduced by irrelevant cases' constructors. These redundant computation will mislead performance tuning.
So we can move these intensive computation to onPreDraw() of these case. They will be executed only if this case should be run.
R=reed@google.com, robertphillips@google.com, humper@google.com, tomhudson@chromium.org
Author: yunchao.he@intel.com
Review URL: https://chromiumcodereview.appspot.com/20997003
git-svn-id: http://skia.googlecode.com/svn/trunk@10486 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-08-01 15:58:07 +00:00
|
|
|
fName.printf("repeatTile_%s_%c",
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::colortype_name(ct),
|
|
|
|
kOpaque_SkAlphaType == at ? 'X' : 'A');
|
When skia run bench cases to test performance, it will run constructors for all cases one by one, then getName to skip unnecessary cases according to command line parameters, so these constructors should be lightweight enough to avoid redundant computing. Unfortunately, some constructors contain intensive computing/rendering. They are very heavy, maybe much heavier than need-to-run bench case itself. And these redundant computation will be run every time you run bench, even you just test a single simple case. Moreover, it will mislead the real hotspot/bottleneck of the case itself.
For example, run a lightweight case, say, region_intersectsrgn_16, the hot spots are gles operation, SuperBlitter, SkRTree... introduced by irrelevant cases' constructors. These redundant computation will mislead performance tuning.
So we can move these intensive computation to onPreDraw() of these case. They will be executed only if this case should be run.
R=reed@google.com, robertphillips@google.com, humper@google.com, tomhudson@chromium.org
Author: yunchao.he@intel.com
Review URL: https://chromiumcodereview.appspot.com/20997003
git-svn-id: http://skia.googlecode.com/svn/trunk@10486 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-08-01 15:58:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
When skia run bench cases to test performance, it will run constructors for all cases one by one, then getName to skip unnecessary cases according to command line parameters, so these constructors should be lightweight enough to avoid redundant computing. Unfortunately, some constructors contain intensive computing/rendering. They are very heavy, maybe much heavier than need-to-run bench case itself. And these redundant computation will be run every time you run bench, even you just test a single simple case. Moreover, it will mislead the real hotspot/bottleneck of the case itself.
For example, run a lightweight case, say, region_intersectsrgn_16, the hot spots are gles operation, SuperBlitter, SkRTree... introduced by irrelevant cases' constructors. These redundant computation will mislead performance tuning.
So we can move these intensive computation to onPreDraw() of these case. They will be executed only if this case should be run.
R=reed@google.com, robertphillips@google.com, humper@google.com, tomhudson@chromium.org
Author: yunchao.he@intel.com
Review URL: https://chromiumcodereview.appspot.com/20997003
git-svn-id: http://skia.googlecode.com/svn/trunk@10486 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-08-01 15:58:07 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
When skia run bench cases to test performance, it will run constructors for all cases one by one, then getName to skip unnecessary cases according to command line parameters, so these constructors should be lightweight enough to avoid redundant computing. Unfortunately, some constructors contain intensive computing/rendering. They are very heavy, maybe much heavier than need-to-run bench case itself. And these redundant computation will be run every time you run bench, even you just test a single simple case. Moreover, it will mislead the real hotspot/bottleneck of the case itself.
For example, run a lightweight case, say, region_intersectsrgn_16, the hot spots are gles operation, SuperBlitter, SkRTree... introduced by irrelevant cases' constructors. These redundant computation will mislead performance tuning.
So we can move these intensive computation to onPreDraw() of these case. They will be executed only if this case should be run.
R=reed@google.com, robertphillips@google.com, humper@google.com, tomhudson@chromium.org
Author: yunchao.he@intel.com
Review URL: https://chromiumcodereview.appspot.com/20997003
git-svn-id: http://skia.googlecode.com/svn/trunk@10486 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-08-01 15:58:07 +00:00
|
|
|
fBitmap.allocPixels();
|
2014-06-10 02:52:07 +00:00
|
|
|
fBitmap.eraseColor(kOpaque_SkAlphaType == fAlphaType ? SK_ColorWHITE : 0);
|
2009-08-12 20:30:58 +00:00
|
|
|
|
When skia run bench cases to test performance, it will run constructors for all cases one by one, then getName to skip unnecessary cases according to command line parameters, so these constructors should be lightweight enough to avoid redundant computing. Unfortunately, some constructors contain intensive computing/rendering. They are very heavy, maybe much heavier than need-to-run bench case itself. And these redundant computation will be run every time you run bench, even you just test a single simple case. Moreover, it will mislead the real hotspot/bottleneck of the case itself.
For example, run a lightweight case, say, region_intersectsrgn_16, the hot spots are gles operation, SuperBlitter, SkRTree... introduced by irrelevant cases' constructors. These redundant computation will mislead performance tuning.
So we can move these intensive computation to onPreDraw() of these case. They will be executed only if this case should be run.
R=reed@google.com, robertphillips@google.com, humper@google.com, tomhudson@chromium.org
Author: yunchao.he@intel.com
Review URL: https://chromiumcodereview.appspot.com/20997003
git-svn-id: http://skia.googlecode.com/svn/trunk@10486 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-08-01 15:58:07 +00:00
|
|
|
draw_into_bitmap(fBitmap);
|
|
|
|
|
2020-12-12 14:51:11 +00:00
|
|
|
fPaint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
|
|
|
SkSamplingOptions()));
|
2009-08-12 20:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2009-08-12 20:30:58 +00:00
|
|
|
SkPaint paint(fPaint);
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2009-08-12 20:30:58 +00:00
|
|
|
canvas->drawPaint(paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2009-08-12 20:30:58 +00:00
|
|
|
};
|
|
|
|
|
2014-06-10 02:52:07 +00:00
|
|
|
DEF_BENCH(return new RepeatTileBench(kN32_SkColorType, kOpaque_SkAlphaType))
|
|
|
|
DEF_BENCH(return new RepeatTileBench(kN32_SkColorType, kPremul_SkAlphaType))
|
|
|
|
DEF_BENCH(return new RepeatTileBench(kRGB_565_SkColorType, kOpaque_SkAlphaType))
|