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 "gm.h"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
2014-08-12 13:53:09 +00:00
|
|
|
#include "SkCanvas.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
2014-08-12 13:53:09 +00:00
|
|
|
#include "SkShader.h"
|
|
|
|
|
|
|
|
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;
|
2016-04-04 17:02:58 +00:00
|
|
|
fMaskFilter = SkBlurMaskFilter::Make(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);
|
|
|
|
paint.setTextSize(72);
|
2016-03-25 16:08:00 +00:00
|
|
|
paint.setShader(fShader);
|
2016-04-04 17:02:58 +00:00
|
|
|
paint.setMaskFilter(fMaskFilter);
|
2015-07-28 17:37:53 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&paint);
|
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
|
|
|
|
|
|
|
canvas->drawText("M", 1,
|
|
|
|
SkIntToScalar(100), SkIntToScalar(100),
|
|
|
|
paint);
|
|
|
|
|
|
|
|
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.setTextSize(72);
|
|
|
|
paint2.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint2.setStrokeWidth(1);
|
2015-07-28 18:22:48 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&paint2);
|
2014-08-12 13:53:09 +00:00
|
|
|
canvas->drawText("M", 1,
|
|
|
|
SkIntToScalar(100), SkIntToScalar(100),
|
|
|
|
paint2);
|
|
|
|
|
2015-07-28 17:37:53 +00:00
|
|
|
paint2.setColor(sk_tool_utils::color_to_565(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;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new SamplerStressGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|