2012-10-12 19:26:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-05-22 12:27:41 +00:00
|
|
|
|
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"
|
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"
|
|
|
|
#include "include/core/SkFontTypes.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2012-10-12 19:26:15 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-10-12 19:26:15 +00:00
|
|
|
namespace skiagm {
|
|
|
|
|
2014-02-17 21:21:46 +00:00
|
|
|
static void makebm(SkBitmap* bm, int w, int h) {
|
|
|
|
bm->allocN32Pixels(w, h);
|
2012-12-06 21:47:40 +00:00
|
|
|
bm->eraseColor(SK_ColorTRANSPARENT);
|
2012-10-12 19:26:15 +00:00
|
|
|
|
|
|
|
SkCanvas canvas(*bm);
|
2020-02-06 16:25:43 +00:00
|
|
|
SkScalar s = SkIntToScalar(std::min(w, h));
|
2016-09-01 18:24:54 +00:00
|
|
|
const SkPoint kPts0[] = { { 0, 0 }, { s, s } };
|
|
|
|
const SkPoint kPts1[] = { { s/2, 0 }, { s/2, s } };
|
|
|
|
const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
|
|
|
|
const SkColor kColors0[] = {0x80F00080, 0xF0F08000, 0x800080F0 };
|
|
|
|
const SkColor kColors1[] = {0xF08000F0, 0x8080F000, 0xF000F080 };
|
2012-10-13 02:01:56 +00:00
|
|
|
|
2012-10-12 19:26:15 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
paint.setShader(SkGradientShader::MakeLinear(kPts0, kColors0, kPos,
|
2019-04-03 14:27:45 +00:00
|
|
|
SK_ARRAY_COUNT(kColors0), SkTileMode::kClamp));
|
2012-10-12 19:26:15 +00:00
|
|
|
canvas.drawPaint(paint);
|
2016-03-13 21:13:58 +00:00
|
|
|
paint.setShader(SkGradientShader::MakeLinear(kPts1, kColors1, kPos,
|
2019-04-03 14:27:45 +00:00
|
|
|
SK_ARRAY_COUNT(kColors1), SkTileMode::kClamp));
|
2012-10-12 19:26:15 +00:00
|
|
|
canvas.drawPaint(paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
struct LabeledMatrix {
|
|
|
|
SkMatrix fMatrix;
|
|
|
|
const char* fLabel;
|
|
|
|
};
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int kPointSize = 300;
|
2014-03-26 21:21:40 +00:00
|
|
|
|
2012-10-12 19:26:15 +00:00
|
|
|
class ShaderText3GM : public GM {
|
|
|
|
public:
|
|
|
|
ShaderText3GM() {
|
2018-08-16 14:17:03 +00:00
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2012-10-12 19:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2012-10-12 19:26:15 +00:00
|
|
|
return SkString("shadertext3");
|
|
|
|
}
|
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(820, 930); }
|
2012-10-12 19:26:15 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2014-03-26 21:21:40 +00:00
|
|
|
makebm(&fBmp, kPointSize / 4, kPointSize / 4);
|
|
|
|
}
|
2012-10-12 19:26:15 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2012-10-13 02:01:56 +00:00
|
|
|
|
2012-10-12 19:26:15 +00:00
|
|
|
SkPaint bmpPaint;
|
|
|
|
bmpPaint.setAntiAlias(true);
|
2019-02-15 21:13:57 +00:00
|
|
|
bmpPaint.setAlphaf(0.5f);
|
2021-01-25 00:49:21 +00:00
|
|
|
SkSamplingOptions sampling(SkFilterMode::kLinear);
|
|
|
|
|
|
|
|
canvas->drawImage(fBmp.asImage(), 5.f, 5.f, sampling, &bmpPaint);
|
2012-10-12 19:26:15 +00:00
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), SkIntToScalar(kPointSize));
|
2012-10-12 19:26:15 +00:00
|
|
|
SkPaint outlinePaint;
|
|
|
|
outlinePaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
outlinePaint.setStrokeWidth(0.f);
|
2012-10-13 02:01:56 +00:00
|
|
|
|
2012-10-12 19:26:15 +00:00
|
|
|
canvas->translate(15.f, 15.f);
|
2012-10-13 02:01:56 +00:00
|
|
|
|
2012-10-12 19:26:15 +00:00
|
|
|
// draw glyphs scaled up
|
|
|
|
canvas->scale(2.f, 2.f);
|
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
constexpr SkTileMode kTileModes[] = {
|
|
|
|
SkTileMode::kRepeat,
|
|
|
|
SkTileMode::kMirror,
|
2012-10-12 19:26:15 +00:00
|
|
|
};
|
2012-10-13 02:01:56 +00:00
|
|
|
|
2012-10-12 19:26:15 +00:00
|
|
|
// position the baseline of the first run
|
|
|
|
canvas->translate(0.f, 0.75f * kPointSize);
|
2012-10-13 02:01:56 +00:00
|
|
|
|
2012-10-12 19:26:15 +00:00
|
|
|
canvas->save();
|
|
|
|
int i = 0;
|
2012-10-13 02:01:56 +00:00
|
|
|
for (size_t tm0 = 0; tm0 < SK_ARRAY_COUNT(kTileModes); ++tm0) {
|
2012-10-12 19:26:15 +00:00
|
|
|
for (size_t tm1 = 0; tm1 < SK_ARRAY_COUNT(kTileModes); ++tm1) {
|
|
|
|
SkMatrix localM;
|
|
|
|
localM.setTranslate(5.f, 5.f);
|
|
|
|
localM.postRotate(20);
|
|
|
|
localM.postScale(1.15f, .85f);
|
2014-04-28 14:55:39 +00:00
|
|
|
|
2012-10-12 19:26:15 +00:00
|
|
|
SkPaint fillPaint;
|
|
|
|
fillPaint.setAntiAlias(true);
|
2020-12-12 19:31:25 +00:00
|
|
|
fillPaint.setShader(fBmp.makeShader(kTileModes[tm0], kTileModes[tm1],
|
2021-01-25 00:49:21 +00:00
|
|
|
sampling, localM));
|
2012-10-12 19:26:15 +00:00
|
|
|
|
2019-01-08 14:38:02 +00:00
|
|
|
constexpr char kText[] = "B";
|
|
|
|
canvas->drawString(kText, 0, 0, font, fillPaint);
|
|
|
|
canvas->drawString(kText, 0, 0, font, outlinePaint);
|
2019-05-07 19:38:46 +00:00
|
|
|
SkScalar w = font.measureText(kText, strlen(kText), SkTextEncoding::kUTF8);
|
2012-10-12 19:26:15 +00:00
|
|
|
canvas->translate(w + 10.f, 0.f);
|
|
|
|
++i;
|
|
|
|
if (!(i % 2)) {
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, 0.75f * kPointSize);
|
|
|
|
canvas->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-03-26 21:21:40 +00:00
|
|
|
SkBitmap fBmp;
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2012-10-12 19:26:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new ShaderText3GM; )
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|