2012-02-14 16:12:49 +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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2012-02-14 16:12:49 +00:00
|
|
|
|
2016-03-09 17:50:50 +00:00
|
|
|
static sk_sp<SkShader> make_heatGradient(const SkPoint pts[2]) {
|
2012-02-14 16:12:49 +00:00
|
|
|
const SkColor bw[] = { SK_ColorBLACK, SK_ColorWHITE };
|
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
return SkGradientShader::MakeLinear(pts, bw, nullptr, SK_ARRAY_COUNT(bw), SkTileMode::kClamp);
|
2012-02-14 16:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Test a set of clipping problems discovered while writing blitAntiRect,
|
|
|
|
and test all the code paths through the clipping blitters.
|
|
|
|
Each region should show as a blue center surrounded by a 2px green
|
|
|
|
border, with no red.
|
|
|
|
*/
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-02-14 16:12:49 +00:00
|
|
|
#define HEIGHT 480
|
|
|
|
|
2014-08-22 15:30:20 +00:00
|
|
|
class GammaTextGM : public skiagm::GM {
|
2012-02-14 16:12:49 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2019-03-08 17:11:55 +00:00
|
|
|
return SkString("gammatext");
|
2012-02-14 16:12:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(1024, HEIGHT);
|
2012-02-14 16:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void drawGrad(SkCanvas* canvas) {
|
2016-03-09 17:50:50 +00:00
|
|
|
const SkPoint pts[] = { { 0, 0 }, { 0, SkIntToScalar(HEIGHT) } };
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-02-14 16:12:49 +00:00
|
|
|
canvas->clear(SK_ColorRED);
|
|
|
|
SkPaint paint;
|
2016-03-09 17:50:50 +00:00
|
|
|
paint.setShader(make_heatGradient(pts));
|
2012-04-17 21:46:18 +00:00
|
|
|
SkRect r = { 0, 0, SkIntToScalar(1024), SkIntToScalar(HEIGHT) };
|
2012-02-14 16:12:49 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2012-02-14 16:12:49 +00:00
|
|
|
drawGrad(canvas);
|
|
|
|
|
|
|
|
const SkColor fg[] = {
|
|
|
|
0xFFFFFFFF,
|
|
|
|
0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF,
|
|
|
|
0xFFFF0000, 0xFF00FF00, 0xFF0000FF,
|
|
|
|
0xFF000000,
|
|
|
|
};
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-02-14 16:12:49 +00:00
|
|
|
const char* text = "Hamburgefons";
|
|
|
|
|
|
|
|
SkPaint paint;
|
2019-01-07 21:01:22 +00:00
|
|
|
SkFont font(nullptr, 16);
|
|
|
|
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
2012-02-14 16:12:49 +00:00
|
|
|
|
2012-04-17 21:46:18 +00:00
|
|
|
SkScalar x = SkIntToScalar(10);
|
2012-02-14 16:12:49 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) {
|
|
|
|
paint.setColor(fg[i]);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-04-17 21:46:18 +00:00
|
|
|
SkScalar y = SkIntToScalar(40);
|
|
|
|
SkScalar stopy = SkIntToScalar(HEIGHT);
|
2012-02-14 16:12:49 +00:00
|
|
|
while (y < stopy) {
|
2019-01-07 21:01:22 +00:00
|
|
|
canvas->drawString(text, x, y, font, paint);
|
|
|
|
y += font.getSize() * 2;
|
2012-02-14 16:12:49 +00:00
|
|
|
}
|
|
|
|
x += SkIntToScalar(1024) / SK_ARRAY_COUNT(fg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-08-22 15:30:20 +00:00
|
|
|
typedef skiagm::GM INHERITED;
|
2012-02-14 16:12:49 +00:00
|
|
|
};
|
|
|
|
|
2015-02-19 15:45:14 +00:00
|
|
|
DEF_GM( return new GammaTextGM; )
|
2014-08-22 15:30:20 +00:00
|
|
|
|
2012-02-14 16:12:49 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-03-09 17:50:50 +00:00
|
|
|
static sk_sp<SkShader> make_gradient(SkColor c) {
|
2014-08-22 15:30:20 +00:00
|
|
|
const SkPoint pts[] = { { 0, 0 }, { 240, 0 } };
|
|
|
|
SkColor colors[2];
|
|
|
|
colors[0] = c;
|
|
|
|
colors[1] = SkColorSetA(c, 0);
|
2019-04-03 14:27:45 +00:00
|
|
|
return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
|
2014-08-22 15:30:20 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 21:01:22 +00:00
|
|
|
static void draw_pair(SkCanvas* canvas, const SkFont& font, SkColor color,
|
|
|
|
const sk_sp<SkShader>& shader) {
|
|
|
|
static const char text[] = "Now is the time for all good";
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(color);
|
|
|
|
canvas->drawString(text, 10, 20, font, paint);
|
2019-04-09 17:55:36 +00:00
|
|
|
paint.setShader(SkShaders::Color(paint.getColor()));
|
2019-01-07 21:01:22 +00:00
|
|
|
canvas->drawString(text, 10, 40, font, paint);
|
|
|
|
paint.setShader(shader);
|
|
|
|
canvas->drawString(text, 10, 60, font, paint);
|
2012-02-14 16:12:49 +00:00
|
|
|
}
|
2014-08-22 15:30:20 +00:00
|
|
|
|
|
|
|
class GammaShaderTextGM : public skiagm::GM {
|
2016-03-09 17:50:50 +00:00
|
|
|
sk_sp<SkShader> fShaders[3];
|
2014-08-22 15:30:20 +00:00
|
|
|
SkColor fColors[3];
|
|
|
|
|
|
|
|
public:
|
|
|
|
GammaShaderTextGM() {
|
|
|
|
const SkColor colors[] = { SK_ColorBLACK, SK_ColorRED, SK_ColorBLUE };
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
|
|
|
|
fColors[i] = colors[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-08-22 15:30:20 +00:00
|
|
|
return SkString("gammagradienttext");
|
|
|
|
}
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-08-22 15:30:20 +00:00
|
|
|
return SkISize::Make(300, 300);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2014-08-22 15:30:20 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
|
|
|
|
fShaders[i] = make_gradient(fColors[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-08-22 15:30:20 +00:00
|
|
|
SkPaint paint;
|
2019-01-08 19:07:50 +00:00
|
|
|
paint.setAntiAlias(true);
|
2019-01-07 21:01:22 +00:00
|
|
|
SkFont font(SkTypeface::MakeFromName("serif", SkFontStyle::Italic()), 18);
|
|
|
|
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
2014-08-22 15:30:20 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
|
2019-01-07 21:01:22 +00:00
|
|
|
draw_pair(canvas, font, fColors[i], fShaders[i]);
|
2014-08-22 15:30:20 +00:00
|
|
|
canvas->translate(0, 80);
|
|
|
|
}
|
|
|
|
}
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2014-08-22 15:30:20 +00:00
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM( return new GammaShaderTextGM; )
|