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"
|
2017-05-03 19:16:58 +00:00
|
|
|
#include "SkBitmap.h"
|
2013-04-23 14:20:45 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkMagnifierImageFilter.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
|
2013-04-23 14:37:38 +00:00
|
|
|
#define FILTER_WIDTH_SMALL 32
|
|
|
|
#define FILTER_HEIGHT_SMALL 32
|
|
|
|
#define FILTER_WIDTH_LARGE 256
|
|
|
|
#define FILTER_HEIGHT_LARGE 256
|
2013-04-23 14:20:45 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class MagnifierBench : public Benchmark {
|
2013-04-23 14:20:45 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
MagnifierBench(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 ? "magnifier_small" : "magnifier_large";
|
|
|
|
}
|
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2013-04-23 14:20:45 +00:00
|
|
|
if (!fInitialized) {
|
|
|
|
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
|
|
|
const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE;
|
|
|
|
const int h = fIsSmall ? FILTER_HEIGHT_SMALL : FILTER_HEIGHT_LARGE;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setImageFilter(
|
2016-04-07 14:34:15 +00:00
|
|
|
SkMagnifierImageFilter::Make(
|
2013-04-23 14:20:45 +00:00
|
|
|
SkRect::MakeXYWH(SkIntToScalar(w / 4),
|
|
|
|
SkIntToScalar(h / 4),
|
|
|
|
SkIntToScalar(w / 2),
|
2016-04-07 14:34:15 +00:00
|
|
|
SkIntToScalar(h / 2)), 100, nullptr));
|
2013-09-10 19:23:38 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-09-10 19:23:38 +00:00
|
|
|
canvas->drawBitmap(fCheckerboard, 0, 0, &paint);
|
|
|
|
}
|
2013-04-23 14:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void make_checkerboard() {
|
|
|
|
const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE;
|
2019-02-09 01:00:36 +00:00
|
|
|
const int h = fIsSmall ? FILTER_HEIGHT_SMALL : FILTER_HEIGHT_LARGE;
|
2014-06-10 02:52:07 +00:00
|
|
|
fCheckerboard.allocN32Pixels(w, h);
|
|
|
|
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 < h; y += 16) {
|
|
|
|
for (int x = 0; x < w; 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 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 MagnifierBench(true); )
|
|
|
|
DEF_BENCH( return new MagnifierBench(false); )
|