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
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/effects/SkImageSource.h"
|
|
|
|
#include "include/effects/SkMergeImageFilter.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)
|
|
|
|
|
2016-03-30 20:34:16 +00:00
|
|
|
static sk_sp<SkImage> make_bitmap() {
|
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(80, 80));
|
|
|
|
surface->getCanvas()->clear(0x00000000);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0xFF884422);
|
2019-01-03 17:59:14 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setSize(SkIntToScalar(96));
|
|
|
|
surface->getCanvas()->drawSimpleText("g", 1, kUTF8_SkTextEncoding, 15, 55, font, paint);
|
2016-03-30 20:34:16 +00:00
|
|
|
return surface->makeImageSnapshot();
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<SkImage> make_checkerboard() {
|
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(80, 80));
|
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
canvas->clear(0x00000000);
|
|
|
|
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) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return surface->makeImageSnapshot();
|
|
|
|
}
|
|
|
|
|
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) {
|
2016-03-30 20:34:16 +00:00
|
|
|
fImage = make_bitmap();
|
|
|
|
fCheckerboard = make_checkerboard();
|
2013-04-23 14:20:45 +00:00
|
|
|
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;
|
2016-03-30 20:34:16 +00:00
|
|
|
paint.setImageFilter(this->mergeBitmaps());
|
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:
|
2016-03-30 20:34:16 +00:00
|
|
|
sk_sp<SkImageFilter> mergeBitmaps() {
|
2016-04-01 16:28:51 +00:00
|
|
|
return SkMergeImageFilter::Make(SkImageSource::Make(fCheckerboard),
|
2017-06-19 03:35:57 +00:00
|
|
|
SkImageSource::Make(fImage));
|
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); )
|