2013-04-23 14:20:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-06-27 12:49:53 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2013-04-23 14:20:45 +00:00
|
|
|
#include "SkCanvas.h"
|
2015-09-15 18:26:13 +00:00
|
|
|
#include "SkImageSource.h"
|
2013-04-23 14:20:45 +00:00
|
|
|
#include "SkMergeImageFilter.h"
|
2015-09-15 18:26:13 +00:00
|
|
|
#include "SkSurface.h"
|
2013-04-23 14:20:45 +00:00
|
|
|
|
|
|
|
#define FILTER_WIDTH_SMALL SkIntToScalar(32)
|
|
|
|
#define FILTER_HEIGHT_SMALL SkIntToScalar(32)
|
|
|
|
#define FILTER_WIDTH_LARGE SkIntToScalar(256)
|
|
|
|
#define FILTER_HEIGHT_LARGE SkIntToScalar(256)
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class MergeBench : public Benchmark {
|
2013-04-23 14:20:45 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
MergeBench(bool small) : fIsSmall(small), fInitialized(false) { }
|
2013-04-23 14:20:45 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-23 14:20:45 +00:00
|
|
|
return fIsSmall ? "merge_small" : "merge_large";
|
|
|
|
}
|
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2013-04-23 14:20:45 +00:00
|
|
|
if (!fInitialized) {
|
|
|
|
make_bitmap();
|
|
|
|
make_checkerboard();
|
|
|
|
fInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2013-04-23 14:20:45 +00:00
|
|
|
SkRect r = fIsSmall ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_SMALL) :
|
|
|
|
SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setImageFilter(mergeBitmaps())->unref();
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-09-10 19:23:38 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
2013-04-23 14:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkImageFilter* mergeBitmaps() {
|
2016-03-17 17:51:11 +00:00
|
|
|
SkAutoTUnref<SkImageFilter> first(SkImageSource::Create(fCheckerboard.get()));
|
|
|
|
SkAutoTUnref<SkImageFilter> second(SkImageSource::Create(fImage.get()));
|
2014-03-10 10:51:58 +00:00
|
|
|
return SkMergeImageFilter::Create(first, second);
|
2013-04-23 14:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void make_bitmap() {
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(SkSurface::MakeRasterN32Premul(80, 80));
|
2015-09-15 18:26:13 +00:00
|
|
|
surface->getCanvas()->clear(0x00000000);
|
2013-04-23 14:20:45 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(0xFF884422);
|
|
|
|
paint.setTextSize(SkIntToScalar(96));
|
|
|
|
const char* str = "g";
|
2015-09-15 18:26:13 +00:00
|
|
|
surface->getCanvas()->drawText(str, strlen(str), 15, 55, paint);
|
2016-03-17 17:51:11 +00:00
|
|
|
fImage = surface->makeImageSnapshot();
|
2013-04-23 14:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void make_checkerboard() {
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(SkSurface::MakeRasterN32Premul(80, 80));
|
2015-09-15 18:26:13 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
canvas->clear(0x00000000);
|
2013-04-23 14:20:45 +00:00
|
|
|
SkPaint darkPaint;
|
|
|
|
darkPaint.setColor(0xFF804020);
|
|
|
|
SkPaint lightPaint;
|
|
|
|
lightPaint.setColor(0xFF244484);
|
|
|
|
for (int y = 0; y < 80; y += 16) {
|
|
|
|
for (int x = 0; x < 80; x += 16) {
|
2015-09-15 18:26:13 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
|
|
|
|
canvas->restore();
|
2013-04-23 14:20:45 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-15 18:26:13 +00:00
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
fCheckerboard = surface->makeImageSnapshot();
|
2013-04-23 14:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool fIsSmall;
|
|
|
|
bool fInitialized;
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> fImage, fCheckerboard;
|
2013-04-23 14:20:45 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-04-23 14:20:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new MergeBench(true); )
|
|
|
|
DEF_BENCH( return new MergeBench(false); )
|