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 "SkBitmapSource.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkMergeImageFilter.h"
|
|
|
|
|
|
|
|
#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-01-09 18:06:39 +00:00
|
|
|
const char* onGetName() SK_OVERRIDE {
|
2013-04-23 14:20:45 +00:00
|
|
|
return fIsSmall ? "merge_small" : "merge_large";
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
void onPreDraw() SK_OVERRIDE {
|
2013-04-23 14:20:45 +00:00
|
|
|
if (!fInitialized) {
|
|
|
|
make_bitmap();
|
|
|
|
make_checkerboard();
|
|
|
|
fInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_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() {
|
2014-03-10 10:51:58 +00:00
|
|
|
SkImageFilter* first = SkBitmapSource::Create(fCheckerboard);
|
|
|
|
SkImageFilter* second = SkBitmapSource::Create(fBitmap);
|
2013-04-23 14:20:45 +00:00
|
|
|
SkAutoUnref aur0(first);
|
|
|
|
SkAutoUnref aur1(second);
|
2014-03-10 10:51:58 +00:00
|
|
|
return SkMergeImageFilter::Create(first, second);
|
2013-04-23 14:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void make_bitmap() {
|
2014-06-10 02:52:07 +00:00
|
|
|
fBitmap.allocN32Pixels(80, 80);
|
|
|
|
SkCanvas canvas(fBitmap);
|
2013-04-23 14:20:45 +00:00
|
|
|
canvas.clear(0x00000000);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(0xFF884422);
|
|
|
|
paint.setTextSize(SkIntToScalar(96));
|
|
|
|
const char* str = "g";
|
|
|
|
canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55), paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void make_checkerboard() {
|
2014-06-10 02:52:07 +00:00
|
|
|
fCheckerboard.allocN32Pixels(80, 80);
|
|
|
|
SkCanvas canvas(fCheckerboard);
|
2013-04-23 14:20:45 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool fIsSmall;
|
|
|
|
bool fInitialized;
|
|
|
|
SkBitmap fBitmap, fCheckerboard;
|
|
|
|
|
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); )
|