2014-08-12 15:34:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#include "Benchmark.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkPatchUtils.h"
|
|
|
|
#include "SkString.h"
|
2014-08-15 20:30:47 +00:00
|
|
|
|
|
|
|
/**
|
2016-03-29 16:03:52 +00:00
|
|
|
* This bench measures the rendering time of the call SkCanvas::drawPatch with different types of
|
|
|
|
* input patches (regular case, with loops, a square, with a big difference between "parallel"
|
|
|
|
* sides). This bench also tests the different combination of optional parameters for the function
|
2014-08-15 20:30:47 +00:00
|
|
|
* (passing texture coordinates and colors, only textures coordinates, only colors or none).
|
2016-03-29 16:03:52 +00:00
|
|
|
* Finally, it applies a scale to test if the size affects the rendering time.
|
2014-08-15 20:30:47 +00:00
|
|
|
*/
|
2014-08-12 15:34:29 +00:00
|
|
|
|
|
|
|
class PatchBench : public Benchmark {
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2014-08-12 15:34:29 +00:00
|
|
|
public:
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2014-08-12 15:34:29 +00:00
|
|
|
enum VertexMode {
|
|
|
|
kNone_VertexMode,
|
|
|
|
kColors_VertexMode,
|
|
|
|
kTexCoords_VertexMode,
|
|
|
|
kBoth_VertexMode
|
|
|
|
};
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2014-08-12 15:34:29 +00:00
|
|
|
PatchBench(SkPoint scale, VertexMode vertexMode)
|
|
|
|
: fScale(scale)
|
|
|
|
, fVertexMode(vertexMode) { }
|
|
|
|
|
|
|
|
// to add name of specific class override this method
|
|
|
|
virtual void appendName(SkString* name) {
|
|
|
|
name->append("normal");
|
|
|
|
}
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2014-08-12 15:34:29 +00:00
|
|
|
// to make other type of patches override this method
|
|
|
|
virtual void setCubics() {
|
|
|
|
const SkPoint points[SkPatchUtils::kNumCtrlPts] = {
|
|
|
|
//top points
|
|
|
|
{100,100},{150,50},{250,150}, {300,100},
|
|
|
|
//right points
|
|
|
|
{350, 150},{250,200},
|
|
|
|
//bottom points
|
|
|
|
{300,300},{250,250},{150,350},{100,300},
|
|
|
|
//left points
|
|
|
|
{50,250},{150,50}
|
|
|
|
};
|
|
|
|
memcpy(fCubics, points, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint));
|
|
|
|
}
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2014-08-12 15:34:29 +00:00
|
|
|
virtual void setColors() {
|
|
|
|
const SkColor colors[SkPatchUtils::kNumCorners] = {
|
|
|
|
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorCYAN
|
|
|
|
};
|
|
|
|
memcpy(fColors, colors, SkPatchUtils::kNumCorners * sizeof(SkColor));
|
|
|
|
}
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2014-08-12 15:34:29 +00:00
|
|
|
virtual void setTexCoords() {
|
|
|
|
const SkPoint texCoords[SkPatchUtils::kNumCorners] = {
|
|
|
|
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f,1.0f}, {0.0f, 1.0f}
|
|
|
|
};
|
|
|
|
memcpy(fTexCoords, texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint));
|
|
|
|
}
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2014-08-12 15:34:29 +00:00
|
|
|
// override this method to change the shader
|
2016-03-14 19:22:10 +00:00
|
|
|
virtual sk_sp<SkShader> createShader() {
|
2014-08-12 15:34:29 +00:00
|
|
|
const SkColor colors[] = {
|
|
|
|
SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE,
|
|
|
|
SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW,
|
|
|
|
};
|
|
|
|
const SkPoint pts[] = { { 200.f / 4.f, 0.f }, { 3.f * 200.f / 4, 200.f } };
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2016-03-14 19:22:10 +00:00
|
|
|
return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
|
|
|
|
SkShader::kMirror_TileMode);
|
2014-08-12 15:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2014-08-12 15:34:29 +00:00
|
|
|
SkString vertexMode;
|
|
|
|
switch (fVertexMode) {
|
|
|
|
case kNone_VertexMode:
|
|
|
|
vertexMode.set("meshlines");
|
|
|
|
break;
|
|
|
|
case kColors_VertexMode:
|
|
|
|
vertexMode.set("colors");
|
|
|
|
break;
|
|
|
|
case kTexCoords_VertexMode:
|
|
|
|
vertexMode.set("texs");
|
|
|
|
break;
|
|
|
|
case kBoth_VertexMode:
|
2014-08-15 20:30:47 +00:00
|
|
|
vertexMode.set("colors_texs");
|
2014-08-12 15:34:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SkString type;
|
|
|
|
this->appendName(&type);
|
2016-08-29 20:33:04 +00:00
|
|
|
fName.printf("patch_%s_%s_%fx%f", type.c_str(), vertexMode.c_str(),
|
2014-08-12 15:34:29 +00:00
|
|
|
fScale.x(), fScale.y());
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2014-08-12 15:34:29 +00:00
|
|
|
this->setCubics();
|
|
|
|
this->setColors();
|
|
|
|
this->setTexCoords();
|
|
|
|
this->setupPaint(&fPaint);
|
|
|
|
switch (fVertexMode) {
|
|
|
|
case kTexCoords_VertexMode:
|
|
|
|
case kBoth_VertexMode:
|
2016-03-14 19:22:10 +00:00
|
|
|
fPaint.setShader(this->createShader());
|
2014-08-12 15:34:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-08-27 14:41:13 +00:00
|
|
|
fPaint.setShader(nullptr);
|
2014-08-12 15:34:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-08-15 20:30:47 +00:00
|
|
|
}
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2014-08-12 15:34:29 +00:00
|
|
|
canvas->scale(fScale.x(), fScale.y());
|
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
switch (fVertexMode) {
|
|
|
|
case kNone_VertexMode:
|
2016-10-28 19:42:34 +00:00
|
|
|
canvas->drawPatch(fCubics, nullptr, nullptr, fPaint);
|
2014-08-12 15:34:29 +00:00
|
|
|
break;
|
|
|
|
case kColors_VertexMode:
|
2016-10-28 19:42:34 +00:00
|
|
|
canvas->drawPatch(fCubics, fColors, nullptr, fPaint);
|
2014-08-12 15:34:29 +00:00
|
|
|
break;
|
|
|
|
case kTexCoords_VertexMode:
|
2016-10-28 19:42:34 +00:00
|
|
|
canvas->drawPatch(fCubics, nullptr, fTexCoords, fPaint);
|
2014-08-12 15:34:29 +00:00
|
|
|
break;
|
|
|
|
case kBoth_VertexMode:
|
2016-10-28 19:42:34 +00:00
|
|
|
canvas->drawPatch(fCubics, fColors, fTexCoords, fPaint);
|
2014-08-12 15:34:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint fPaint;
|
|
|
|
SkString fName;
|
|
|
|
SkVector fScale;
|
|
|
|
SkPoint fCubics[12];
|
|
|
|
SkPoint fTexCoords[4];
|
|
|
|
SkColor fColors[4];
|
|
|
|
VertexMode fVertexMode;
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2014-08-12 15:34:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SquarePatchBench : public PatchBench {
|
|
|
|
public:
|
|
|
|
SquarePatchBench(SkPoint scale, VertexMode vertexMode)
|
|
|
|
: INHERITED(scale, vertexMode) { }
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void appendName(SkString* name) override {
|
2014-08-12 15:34:29 +00:00
|
|
|
name->append("square");
|
|
|
|
}
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void setCubics() override {
|
2014-08-12 15:34:29 +00:00
|
|
|
const SkPoint points[SkPatchUtils::kNumCtrlPts] = {
|
|
|
|
//top points
|
|
|
|
{100,100},{150,100},{250,100}, {300,100},
|
|
|
|
//right points
|
|
|
|
{300, 150},{300,250},
|
|
|
|
//bottom points
|
|
|
|
{300,300},{250,300},{150,300},{100,300},
|
|
|
|
//left points
|
|
|
|
{100,250},{100,150}
|
|
|
|
};
|
|
|
|
memcpy(fCubics, points, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint));
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef PatchBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LODDiffPatchBench : public PatchBench {
|
|
|
|
public:
|
|
|
|
LODDiffPatchBench(SkPoint scale, VertexMode vertexMode)
|
|
|
|
: INHERITED(scale, vertexMode) { }
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void appendName(SkString* name) override {
|
2014-08-12 15:34:29 +00:00
|
|
|
name->append("LOD_Diff");
|
|
|
|
}
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void setCubics() override {
|
2014-08-12 15:34:29 +00:00
|
|
|
const SkPoint points[SkPatchUtils::kNumCtrlPts] = {
|
|
|
|
//top points
|
|
|
|
{100,175},{150,100},{250,100}, {300,0},
|
|
|
|
//right points
|
|
|
|
{300, 150},{300,250},
|
|
|
|
//bottom points
|
|
|
|
{300,400},{250,300},{150,300},{100,225},
|
|
|
|
//left points
|
|
|
|
{100,215},{100,185}
|
|
|
|
};
|
|
|
|
memcpy(fCubics, points, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint));
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef PatchBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LoopPatchBench : public PatchBench {
|
|
|
|
public:
|
|
|
|
LoopPatchBench(SkPoint scale, VertexMode vertexMode)
|
|
|
|
: INHERITED(scale, vertexMode) { }
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void appendName(SkString* name) override {
|
2014-08-12 15:34:29 +00:00
|
|
|
name->append("loop");
|
|
|
|
}
|
2014-08-13 17:41:16 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void setCubics() override {
|
2014-08-12 15:34:29 +00:00
|
|
|
const SkPoint points[SkPatchUtils::kNumCtrlPts] = {
|
|
|
|
//top points
|
|
|
|
{100,100},{300,200},{100,200}, {300,100},
|
|
|
|
//right points
|
|
|
|
{380, 400},{380,0},
|
|
|
|
//bottom points
|
|
|
|
{300,300},{250,250},{30,200},{100,300},
|
|
|
|
//left points
|
|
|
|
{140,325},{150,150}
|
|
|
|
};
|
|
|
|
memcpy(fCubics, points, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint));
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef PatchBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_BENCH( return new PatchBench(SkVector::Make(0.1f, 0.1f), PatchBench::kNone_VertexMode); )
|
|
|
|
DEF_BENCH( return new PatchBench(SkVector::Make(0.1f, 0.1f), PatchBench::kColors_VertexMode); )
|
|
|
|
DEF_BENCH( return new PatchBench(SkVector::Make(0.1f, 0.1f), PatchBench::kTexCoords_VertexMode); )
|
|
|
|
DEF_BENCH( return new PatchBench(SkVector::Make(0.1f, 0.1f), PatchBench::kBoth_VertexMode); )
|
|
|
|
DEF_BENCH( return new PatchBench(SkVector::Make(1.f, 1.0f), PatchBench::kNone_VertexMode); )
|
|
|
|
DEF_BENCH( return new PatchBench(SkVector::Make(1.0f, 1.0f), PatchBench::kColors_VertexMode); )
|
|
|
|
DEF_BENCH( return new PatchBench(SkVector::Make(1.0f, 1.0f), PatchBench::kTexCoords_VertexMode); )
|
|
|
|
DEF_BENCH( return new PatchBench(SkVector::Make(1.0f, 1.0f), PatchBench::kBoth_VertexMode); )
|
|
|
|
DEF_BENCH( return new PatchBench(SkVector::Make(3.0f, 3.0f), PatchBench::kNone_VertexMode); )
|
|
|
|
DEF_BENCH( return new PatchBench(SkVector::Make(3.0f, 3.0f), PatchBench::kColors_VertexMode); )
|
|
|
|
DEF_BENCH( return new PatchBench(SkVector::Make(3.0f, 3.0f), PatchBench::kTexCoords_VertexMode); )
|
|
|
|
DEF_BENCH( return new PatchBench(SkVector::Make(3.0f, 3.0f), PatchBench::kBoth_VertexMode); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new SquarePatchBench(SkVector::Make(0.1f, 0.1f),
|
|
|
|
PatchBench::kNone_VertexMode); )
|
|
|
|
DEF_BENCH( return new SquarePatchBench(SkVector::Make(0.1f, 0.1f),
|
|
|
|
PatchBench::kColors_VertexMode); )
|
|
|
|
DEF_BENCH( return new SquarePatchBench(SkVector::Make(0.1f, 0.1f),
|
|
|
|
PatchBench::kTexCoords_VertexMode); )
|
|
|
|
DEF_BENCH( return new SquarePatchBench(SkVector::Make(0.1f, 0.1f),
|
|
|
|
PatchBench::kBoth_VertexMode); )
|
|
|
|
DEF_BENCH( return new SquarePatchBench(SkVector::Make(1.f, 1.0f),
|
|
|
|
PatchBench::kNone_VertexMode); )
|
|
|
|
DEF_BENCH( return new SquarePatchBench(SkVector::Make(1.0f, 1.0f),
|
|
|
|
PatchBench::kColors_VertexMode); )
|
|
|
|
DEF_BENCH( return new SquarePatchBench(SkVector::Make(1.0f, 1.0f),
|
|
|
|
PatchBench::kTexCoords_VertexMode); )
|
|
|
|
DEF_BENCH( return new SquarePatchBench(SkVector::Make(1.0f, 1.0f),
|
|
|
|
PatchBench::kBoth_VertexMode); )
|
|
|
|
DEF_BENCH( return new SquarePatchBench(SkVector::Make(3.0f, 3.0f),
|
|
|
|
PatchBench::kNone_VertexMode); )
|
|
|
|
DEF_BENCH( return new SquarePatchBench(SkVector::Make(3.0f, 3.0f),
|
|
|
|
PatchBench::kColors_VertexMode); )
|
|
|
|
DEF_BENCH( return new SquarePatchBench(SkVector::Make(3.0f, 3.0f),
|
|
|
|
PatchBench::kTexCoords_VertexMode); )
|
|
|
|
DEF_BENCH( return new SquarePatchBench(SkVector::Make(3.0f, 3.0f),
|
|
|
|
PatchBench::kBoth_VertexMode); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(0.1f, 0.1f),
|
|
|
|
PatchBench::kNone_VertexMode); )
|
|
|
|
DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(0.1f, 0.1f),
|
|
|
|
PatchBench::kColors_VertexMode); )
|
|
|
|
DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(0.1f, 0.1f),
|
|
|
|
PatchBench::kTexCoords_VertexMode); )
|
|
|
|
DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(0.1f, 0.1f),
|
|
|
|
PatchBench::kBoth_VertexMode); )
|
|
|
|
DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(1.f, 1.0f),
|
|
|
|
PatchBench::kNone_VertexMode); )
|
|
|
|
DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(1.0f, 1.0f),
|
|
|
|
PatchBench::kColors_VertexMode); )
|
|
|
|
DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(1.0f, 1.0f),
|
|
|
|
PatchBench::kTexCoords_VertexMode); )
|
|
|
|
DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(1.0f, 1.0f),
|
|
|
|
PatchBench::kBoth_VertexMode); )
|
|
|
|
DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(3.0f, 3.0f),
|
|
|
|
PatchBench::kNone_VertexMode); )
|
|
|
|
DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(3.0f, 3.0f),
|
|
|
|
PatchBench::kColors_VertexMode); )
|
|
|
|
DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(3.0f, 3.0f),
|
|
|
|
PatchBench::kTexCoords_VertexMode); )
|
|
|
|
DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(3.0f, 3.0f),
|
|
|
|
PatchBench::kBoth_VertexMode); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new LoopPatchBench(SkVector::Make(0.1f, 0.1f),
|
|
|
|
PatchBench::kNone_VertexMode); )
|
|
|
|
DEF_BENCH( return new LoopPatchBench(SkVector::Make(0.1f, 0.1f),
|
|
|
|
PatchBench::kColors_VertexMode); )
|
|
|
|
DEF_BENCH( return new LoopPatchBench(SkVector::Make(0.1f, 0.1f),
|
|
|
|
PatchBench::kTexCoords_VertexMode); )
|
|
|
|
DEF_BENCH( return new LoopPatchBench(SkVector::Make(0.1f, 0.1f),
|
|
|
|
PatchBench::kBoth_VertexMode); )
|
|
|
|
DEF_BENCH( return new LoopPatchBench(SkVector::Make(1.f, 1.0f),
|
|
|
|
PatchBench::kNone_VertexMode); )
|
|
|
|
DEF_BENCH( return new LoopPatchBench(SkVector::Make(1.0f, 1.0f),
|
|
|
|
PatchBench::kColors_VertexMode); )
|
|
|
|
DEF_BENCH( return new LoopPatchBench(SkVector::Make(1.0f, 1.0f),
|
|
|
|
PatchBench::kTexCoords_VertexMode); )
|
|
|
|
DEF_BENCH( return new LoopPatchBench(SkVector::Make(1.0f, 1.0f),
|
|
|
|
PatchBench::kBoth_VertexMode); )
|
|
|
|
DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f),
|
|
|
|
PatchBench::kNone_VertexMode); )
|
|
|
|
DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f),
|
|
|
|
PatchBench::kColors_VertexMode); )
|
|
|
|
DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f),
|
|
|
|
PatchBench::kTexCoords_VertexMode); )
|
|
|
|
DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f),
|
|
|
|
PatchBench::kBoth_VertexMode); )
|