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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkBlurTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFont.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkMaskFilter.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkShader.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/ToolUtils.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();
|
|
|
|
|
2020-12-12 19:31:25 +00:00
|
|
|
fShader = fTexture.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
|
|
|
SkSamplingOptions());
|
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;
|
2019-08-24 23:39:13 +00:00
|
|
|
temp.setLTRB(115, 75, 144, 110);
|
2014-08-12 13:53:09 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2014-08-12 13:53:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new SamplerStressGM; )
|
2014-08-12 13:53:09 +00:00
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|