2014-08-12 13:53:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkCanvas.h"
|
2018-03-14 17:01:17 +00:00
|
|
|
#include "SkMaskFilter.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
2014-08-12 13:53:09 +00:00
|
|
|
#include "SkShader.h"
|
2019-03-20 16:12:10 +00:00
|
|
|
#include "ToolUtils.h"
|
|
|
|
#include "gm.h"
|
2014-08-12 13:53:09 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stress test the GPU samplers by rendering a textured glyph with a mask and
|
|
|
|
* an AA clip
|
|
|
|
*/
|
|
|
|
class SamplerStressGM : public GM {
|
|
|
|
public:
|
|
|
|
SamplerStressGM()
|
|
|
|
: fTextureCreated(false)
|
2015-08-27 14:41:13 +00:00
|
|
|
, fMaskFilter(nullptr) {
|
2014-08-12 13:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-08-12 13:53:09 +00:00
|
|
|
return SkString("gpusamplerstress");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-08-12 13:53:09 +00:00
|
|
|
return SkISize::Make(640, 480);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a red & green stripes on black texture
|
|
|
|
*/
|
|
|
|
void createTexture() {
|
|
|
|
if (fTextureCreated) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int xSize = 16;
|
|
|
|
constexpr int ySize = 16;
|
2014-08-12 13:53:09 +00:00
|
|
|
|
|
|
|
fTexture.allocN32Pixels(xSize, ySize);
|
|
|
|
SkPMColor* addr = fTexture.getAddr32(0, 0);
|
|
|
|
|
|
|
|
for (int y = 0; y < ySize; ++y) {
|
|
|
|
for (int x = 0; x < xSize; ++x) {
|
|
|
|
addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorBLACK);
|
|
|
|
|
|
|
|
if ((y % 5) == 0) {
|
|
|
|
addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorRED);
|
|
|
|
}
|
|
|
|
if ((x % 7) == 0) {
|
|
|
|
addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorGREEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fTextureCreated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void createShader() {
|
2016-03-13 21:13:58 +00:00
|
|
|
if (fShader) {
|
2014-08-12 13:53:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
createTexture();
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
fShader = SkShader::MakeBitmapShader(fTexture, SkShader::kRepeat_TileMode,
|
|
|
|
SkShader::kRepeat_TileMode);
|
2014-08-12 13:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void createMaskFilter() {
|
2016-04-04 17:02:58 +00:00
|
|
|
if (fMaskFilter) {
|
2014-08-12 13:53:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SkScalar sigma = 1;
|
2018-03-14 17:01:17 +00:00
|
|
|
fMaskFilter = SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma);
|
2014-08-12 13:53:09 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-08-12 13:53:09 +00:00
|
|
|
createShader();
|
|
|
|
createMaskFilter();
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
|
|
|
|
// draw a letter "M" with a green & red striped texture and a
|
|
|
|
// stipple mask with a round rect soft clip
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2016-03-25 16:08:00 +00:00
|
|
|
paint.setShader(fShader);
|
2016-04-04 17:02:58 +00:00
|
|
|
paint.setMaskFilter(fMaskFilter);
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), 72);
|
2014-08-12 13:53:09 +00:00
|
|
|
|
|
|
|
SkRect temp;
|
|
|
|
temp.set(SkIntToScalar(115),
|
|
|
|
SkIntToScalar(75),
|
|
|
|
SkIntToScalar(144),
|
|
|
|
SkIntToScalar(110));
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.addRoundRect(temp, SkIntToScalar(5), SkIntToScalar(5));
|
|
|
|
|
2016-09-21 18:15:07 +00:00
|
|
|
canvas->clipPath(path, true); // AA is on
|
2014-08-12 13:53:09 +00:00
|
|
|
|
2019-01-08 14:38:02 +00:00
|
|
|
canvas->drawString("M", 100.0f, 100.0f, font, paint);
|
2014-08-12 13:53:09 +00:00
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// Now draw stroked versions of the "M" and the round rect so we can
|
|
|
|
// see what is going on
|
|
|
|
SkPaint paint2;
|
|
|
|
paint2.setColor(SK_ColorBLACK);
|
|
|
|
paint2.setAntiAlias(true);
|
|
|
|
paint2.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint2.setStrokeWidth(1);
|
2019-01-08 14:38:02 +00:00
|
|
|
canvas->drawString("M", 100.0f, 100.0f, font, paint2);
|
2014-08-12 13:53:09 +00:00
|
|
|
|
2018-08-16 14:17:03 +00:00
|
|
|
paint2.setColor(SK_ColorGRAY);
|
2014-08-12 13:53:09 +00:00
|
|
|
|
|
|
|
canvas->drawPath(path, paint2);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-03-13 21:13:58 +00:00
|
|
|
SkBitmap fTexture;
|
|
|
|
bool fTextureCreated;
|
|
|
|
sk_sp<SkShader> fShader;
|
2016-04-04 17:02:58 +00:00
|
|
|
sk_sp<SkMaskFilter> fMaskFilter;
|
2014-08-12 13:53:09 +00:00
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new SamplerStressGM; )
|
2014-08-12 13:53:09 +00:00
|
|
|
|
|
|
|
}
|