2011-07-28 14:26:00 +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.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-08-13 00:52:07 +00:00
|
|
|
#include "gm.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
|
|
|
#include "SkBlurMaskFilter.h"
|
2014-01-30 18:58:24 +00:00
|
|
|
#include "SkReadBuffer.h"
|
|
|
|
#include "SkWriteBuffer.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkLayerRasterizer.h"
|
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
static void r0(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
|
2014-04-28 16:25:35 +00:00
|
|
|
p.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
|
2013-09-06 14:16:12 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(3))))->unref();
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p, SkIntToScalar(3), SkIntToScalar(3));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setMaskFilter(NULL);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(SK_Scalar1);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setAlpha(0x11);
|
|
|
|
p.setStyle(SkPaint::kFill_Style);
|
2009-06-24 12:41:42 +00:00
|
|
|
p.setXfermodeMode(SkXfermode::kSrc_Mode);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
static void r1(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
|
|
|
|
rastBuilder->addLayer(p);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setAlpha(0x40);
|
2009-06-24 12:41:42 +00:00
|
|
|
p.setXfermodeMode(SkXfermode::kSrc_Mode);
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(SK_Scalar1*2);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2011-02-07 15:30:46 +00:00
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
static void r2(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
p.setStrokeWidth(SK_Scalar1*4);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(SK_Scalar1*3/2);
|
2009-06-24 12:41:42 +00:00
|
|
|
p.setXfermodeMode(SkXfermode::kClear_Mode);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
static void r3(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(SK_Scalar1*3);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setAlpha(0x20);
|
|
|
|
p.setStyle(SkPaint::kFill_Style);
|
2009-06-24 12:41:42 +00:00
|
|
|
p.setXfermodeMode(SkXfermode::kSrc_Mode);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
static void r4(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setAlpha(0x60);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p, SkIntToScalar(3), SkIntToScalar(3));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setAlpha(0xFF);
|
2009-06-24 12:41:42 +00:00
|
|
|
p.setXfermodeMode(SkXfermode::kClear_Mode);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p, SK_Scalar1*3/2, SK_Scalar1*3/2);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setXfermode(NULL);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "SkDiscretePathEffect.h"
|
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
|
|
|
|
rastBuilder->addLayer(p);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2014-02-20 20:40:19 +00:00
|
|
|
p.setPathEffect(SkDiscretePathEffect::Create(SK_Scalar1*4, SK_Scalar1*3))->unref();
|
2009-06-24 12:41:42 +00:00
|
|
|
p.setXfermodeMode(SkXfermode::kSrcOut_Mode);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
|
|
|
|
rastBuilder->addLayer(p);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setAntiAlias(false);
|
2014-02-26 13:27:37 +00:00
|
|
|
SkLayerRasterizer::Builder rastBuilder2;
|
|
|
|
r5(&rastBuilder2, p);
|
|
|
|
p.setRasterizer(rastBuilder2.detachRasterizer())->unref();
|
2009-06-24 12:41:42 +00:00
|
|
|
p.setXfermodeMode(SkXfermode::kClear_Mode);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "Sk2DPathEffect.h"
|
|
|
|
|
2011-08-09 18:47:40 +00:00
|
|
|
static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) {
|
|
|
|
SkPath path;
|
|
|
|
path.addCircle(0, 0, radius);
|
2014-02-20 20:40:19 +00:00
|
|
|
return SkPath2DPathEffect::Create(matrix, path);
|
2011-08-09 18:47:40 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
static void r7(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkMatrix lattice;
|
|
|
|
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
|
|
|
|
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
|
2011-08-09 18:47:40 +00:00
|
|
|
p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref();
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
static void r8(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
|
|
|
|
rastBuilder->addLayer(p);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkMatrix lattice;
|
|
|
|
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
|
|
|
|
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
|
2011-08-09 18:47:40 +00:00
|
|
|
p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice))->unref();
|
2009-06-24 12:41:42 +00:00
|
|
|
p.setXfermodeMode(SkXfermode::kClear_Mode);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setPathEffect(NULL);
|
|
|
|
p.setXfermode(NULL);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(SK_Scalar1);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
|
|
|
|
rastBuilder->addLayer(p);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkMatrix lattice;
|
|
|
|
lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0);
|
|
|
|
lattice.postRotate(SkIntToScalar(30), 0, 0);
|
2014-02-20 20:40:19 +00:00
|
|
|
p.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1*2, lattice))->unref();
|
2009-06-24 12:41:42 +00:00
|
|
|
p.setXfermodeMode(SkXfermode::kClear_Mode);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setPathEffect(NULL);
|
|
|
|
p.setXfermode(NULL);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(SK_Scalar1);
|
2014-02-26 13:27:37 +00:00
|
|
|
rastBuilder->addLayer(p);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
typedef void (*raster_proc)(SkLayerRasterizer::Builder*, SkPaint&);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
static const raster_proc gRastProcs[] = {
|
|
|
|
r0, r1, r2, r3, r4, r5, r6, r7, r8, r9
|
|
|
|
};
|
|
|
|
|
|
|
|
#include "SkXfermode.h"
|
|
|
|
|
2011-04-22 14:10:48 +00:00
|
|
|
static void apply_shader(SkPaint* paint, int index) {
|
2008-12-17 15:59:43 +00:00
|
|
|
raster_proc proc = gRastProcs[index];
|
|
|
|
if (proc)
|
|
|
|
{
|
|
|
|
SkPaint p;
|
2014-02-26 13:27:37 +00:00
|
|
|
SkLayerRasterizer::Builder rastBuilder;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p.setAntiAlias(true);
|
2014-02-26 13:27:37 +00:00
|
|
|
proc(&rastBuilder, p);
|
|
|
|
paint->setRasterizer(rastBuilder.detachRasterizer())->unref();
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#if 0
|
|
|
|
SkScalar dir[] = { SK_Scalar1, SK_Scalar1, SK_Scalar1 };
|
2011-02-07 15:30:46 +00:00
|
|
|
paint->setMaskFilter(SkBlurMaskFilter::CreateEmboss(dir, SK_Scalar1/4, SkIntToScalar(4), SkIntToScalar(3)))->unref();
|
2008-12-17 15:59:43 +00:00
|
|
|
#endif
|
|
|
|
paint->setColor(SK_ColorBLUE);
|
|
|
|
}
|
|
|
|
|
2012-08-13 00:52:07 +00:00
|
|
|
class TextEffectsGM : public skiagm::GM {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
TextEffectsGM() {}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
2012-08-13 00:52:07 +00:00
|
|
|
virtual SkString onShortName() SK_OVERRIDE {
|
|
|
|
return SkString("texteffects");
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-08-13 00:52:07 +00:00
|
|
|
virtual SkISize onISize() SK_OVERRIDE {
|
2012-08-13 01:13:38 +00:00
|
|
|
return SkISize::Make(460, 680);
|
2012-08-13 00:52:07 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-08-13 00:52:07 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->save();
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2010-05-17 14:50:04 +00:00
|
|
|
paint.setTextSize(SkIntToScalar(56));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2010-05-17 14:50:04 +00:00
|
|
|
SkScalar x = SkIntToScalar(20);
|
|
|
|
SkScalar y = paint.getTextSize();
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-08-13 00:52:07 +00:00
|
|
|
SkString str("Hamburgefons");
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2013-10-16 17:48:11 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(SK_ARRAY_COUNT(gRastProcs)); i++) {
|
2008-12-17 15:59:43 +00:00
|
|
|
apply_shader(&paint, i);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-08-13 00:52:07 +00:00
|
|
|
// paint.setMaskFilter(NULL);
|
|
|
|
// paint.setColor(SK_ColorBLACK);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->drawText(str.c_str(), str.size(), x, y, paint);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
y += paint.getFontSpacing();
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
2012-08-13 01:57:05 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
2012-08-13 00:52:07 +00:00
|
|
|
typedef skiagm::GM INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-08-13 00:52:07 +00:00
|
|
|
static skiagm::GM* MyFactory(void*) { return new TextEffectsGM; }
|
|
|
|
static skiagm::GMRegistry reg(MyFactory);
|