skia2/gm/texteffects.cpp

220 lines
6.2 KiB
C++
Raw Normal View History

Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
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.
*/
#include "gm.h"
#include "SkBlurMask.h"
#include "SkBlurMaskFilter.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
#include "SkLayerRasterizer.h"
static void r0(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
p.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(3))))->unref();
rastBuilder->addLayer(p, SkIntToScalar(3), SkIntToScalar(3));
p.setMaskFilter(NULL);
p.setStyle(SkPaint::kStroke_Style);
p.setStrokeWidth(SK_Scalar1);
rastBuilder->addLayer(p);
p.setAlpha(0x11);
p.setStyle(SkPaint::kFill_Style);
p.setXfermodeMode(SkXfermode::kSrc_Mode);
rastBuilder->addLayer(p);
}
static void r1(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
rastBuilder->addLayer(p);
p.setAlpha(0x40);
p.setXfermodeMode(SkXfermode::kSrc_Mode);
p.setStyle(SkPaint::kStroke_Style);
p.setStrokeWidth(SK_Scalar1*2);
rastBuilder->addLayer(p);
}
static void r2(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
p.setStyle(SkPaint::kStrokeAndFill_Style);
p.setStrokeWidth(SK_Scalar1*4);
rastBuilder->addLayer(p);
p.setStyle(SkPaint::kStroke_Style);
p.setStrokeWidth(SK_Scalar1*3/2);
p.setXfermodeMode(SkXfermode::kClear_Mode);
rastBuilder->addLayer(p);
}
static void r3(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
p.setStyle(SkPaint::kStroke_Style);
p.setStrokeWidth(SK_Scalar1*3);
rastBuilder->addLayer(p);
p.setAlpha(0x20);
p.setStyle(SkPaint::kFill_Style);
p.setXfermodeMode(SkXfermode::kSrc_Mode);
rastBuilder->addLayer(p);
}
static void r4(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
p.setAlpha(0x60);
rastBuilder->addLayer(p, SkIntToScalar(3), SkIntToScalar(3));
p.setAlpha(0xFF);
p.setXfermodeMode(SkXfermode::kClear_Mode);
rastBuilder->addLayer(p, SK_Scalar1*3/2, SK_Scalar1*3/2);
p.setXfermode(NULL);
rastBuilder->addLayer(p);
}
#include "SkDiscretePathEffect.h"
static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
rastBuilder->addLayer(p);
p.setPathEffect(SkDiscretePathEffect::Create(SK_Scalar1*4, SK_Scalar1*3))->unref();
p.setXfermodeMode(SkXfermode::kSrcOut_Mode);
rastBuilder->addLayer(p);
}
static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
rastBuilder->addLayer(p);
p.setAntiAlias(false);
SkLayerRasterizer::Builder rastBuilder2;
r5(&rastBuilder2, p);
p.setRasterizer(rastBuilder2.detachRasterizer())->unref();
p.setXfermodeMode(SkXfermode::kClear_Mode);
rastBuilder->addLayer(p);
}
#include "Sk2DPathEffect.h"
static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) {
SkPath path;
path.addCircle(0, 0, radius);
return SkPath2DPathEffect::Create(matrix, path);
}
static void r7(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref();
rastBuilder->addLayer(p);
}
static void r8(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
rastBuilder->addLayer(p);
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice))->unref();
p.setXfermodeMode(SkXfermode::kClear_Mode);
rastBuilder->addLayer(p);
p.setPathEffect(NULL);
p.setXfermode(NULL);
p.setStyle(SkPaint::kStroke_Style);
p.setStrokeWidth(SK_Scalar1);
rastBuilder->addLayer(p);
}
static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
rastBuilder->addLayer(p);
SkMatrix lattice;
lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0);
lattice.postRotate(SkIntToScalar(30), 0, 0);
p.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1*2, lattice))->unref();
p.setXfermodeMode(SkXfermode::kClear_Mode);
rastBuilder->addLayer(p);
p.setPathEffect(NULL);
p.setXfermode(NULL);
p.setStyle(SkPaint::kStroke_Style);
p.setStrokeWidth(SK_Scalar1);
rastBuilder->addLayer(p);
}
typedef void (*raster_proc)(SkLayerRasterizer::Builder*, SkPaint&);
static const raster_proc gRastProcs[] = {
r0, r1, r2, r3, r4, r5, r6, r7, r8, r9
};
#include "SkXfermode.h"
static void apply_shader(SkPaint* paint, int index) {
raster_proc proc = gRastProcs[index];
if (proc)
{
SkPaint p;
SkLayerRasterizer::Builder rastBuilder;
p.setAntiAlias(true);
proc(&rastBuilder, p);
paint->setRasterizer(rastBuilder.detachRasterizer())->unref();
}
#if 0
SkScalar dir[] = { SK_Scalar1, SK_Scalar1, SK_Scalar1 };
paint->setMaskFilter(SkBlurMaskFilter::CreateEmboss(dir, SK_Scalar1/4, SkIntToScalar(4), SkIntToScalar(3)))->unref();
#endif
paint->setColor(SK_ColorBLUE);
}
class TextEffectsGM : public skiagm::GM {
public:
TextEffectsGM() {}
protected:
virtual SkString onShortName() SK_OVERRIDE {
return SkString("texteffects");
}
virtual SkISize onISize() SK_OVERRIDE {
return SkISize::Make(460, 680);
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
canvas->save();
SkPaint paint;
paint.setAntiAlias(true);
paint.setTextSize(SkIntToScalar(56));
SkScalar x = SkIntToScalar(20);
SkScalar y = paint.getTextSize();
SkString str("Hamburgefons");
for (int i = 0; i < static_cast<int>(SK_ARRAY_COUNT(gRastProcs)); i++) {
apply_shader(&paint, i);
// paint.setMaskFilter(NULL);
// paint.setColor(SK_ColorBLACK);
canvas->drawText(str.c_str(), str.size(), x, y, paint);
y += paint.getFontSpacing();
}
canvas->restore();
}
private:
typedef skiagm::GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static skiagm::GM* MyFactory(void*) { return new TextEffectsGM; }
static skiagm::GMRegistry reg(MyFactory);