#include "gm.h"
#include "SkBitmapSource.h"
+#include "SkBlendImageFilter.h"
#include "SkBlurImageFilter.h"
#include "SkColorFilter.h"
+#include "SkColorMatrixFilter.h"
#include "SkColorFilterImageFilter.h"
#include "SkMorphologyImageFilter.h"
canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint);
}
- virtual SkISize onISize() { return SkISize::Make(500, 500); }
+ virtual SkISize onISize() { return SkISize::Make(200, 100); }
virtual void onDraw(SkCanvas* canvas) {
if (!fInitialized) {
fInitialized = true;
}
canvas->clear(0x00000000);
+ {
+ SkAutoTUnref<SkImageFilter> bitmapSource(new SkBitmapSource(fBitmap));
+ SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
+ SkXfermode::kSrcIn_Mode));
+ SkAutoTUnref<SkImageFilter> blur(new SkBlurImageFilter(4.0f, 4.0f, bitmapSource));
+ SkAutoTUnref<SkImageFilter> erode(new SkErodeImageFilter(4, 4, blur));
+ SkAutoTUnref<SkImageFilter> color(new SkColorFilterImageFilter(cf, erode));
+ SkAutoTUnref<SkImageFilter> merge(new SkMergeImageFilter(blur, color));
+
+ SkPaint paint;
+ paint.setImageFilter(merge);
+ canvas->drawPaint(paint);
+ }
+ {
+ SkAutoTUnref<SkImageFilter> morph(new SkDilateImageFilter(5, 5));
- SkAutoTUnref<SkImageFilter> bitmapSource(new SkBitmapSource(fBitmap));
+ SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
+ 0, SK_Scalar1, 0, 0, 0,
+ 0, 0, SK_Scalar1, 0, 0,
+ 0, 0, 0, SkFloatToScalar(0.5f), 0 };
- SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
- SkXfermode::kSrcIn_Mode));
- SkAutoTUnref<SkImageFilter> blur(new SkBlurImageFilter(4.0f, 4.0f, bitmapSource));
- SkAutoTUnref<SkImageFilter> erode(new SkErodeImageFilter(4, 4, blur));
- SkAutoTUnref<SkImageFilter> color(new SkColorFilterImageFilter(cf, erode));
- SkAutoTUnref<SkImageFilter> merge(new SkMergeImageFilter(blur, color));
+ SkAutoTUnref<SkColorFilter> matrixFilter(new SkColorMatrixFilter(matrix));
+ SkAutoTUnref<SkImageFilter> colorMorph(new SkColorFilterImageFilter(matrixFilter, morph));
+ SkAutoTUnref<SkImageFilter> blendColor(new SkBlendImageFilter(SkBlendImageFilter::kNormal_Mode, colorMorph));
- SkPaint paint;
- paint.setImageFilter(merge);
- canvas->drawPaint(paint);
+ SkPaint paint;
+ paint.setImageFilter(blendColor);
+ canvas->drawBitmap(fBitmap, 100, 0, &paint);
+ }
}
private:
GrContext::AutoRenderTarget art(context, dst->asRenderTarget());
GrContext::AutoClip ac(context, rect);
- GrMatrix sampleM;
- sampleM.setIDiv(background->width(), background->height());
+ GrMatrix backgroundTexMatrix, foregroundTexMatrix;
+ backgroundTexMatrix.setIDiv(background->width(), background->height());
+ foregroundTexMatrix.setIDiv(foreground->width(), foreground->height());
GrPaint paint;
- paint.colorSampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (background.get())), sampleM)->unref();
- paint.colorSampler(1)->setCustomStage(SkNEW_ARGS(GrBlendEffect, (fMode, foreground.get())), sampleM)->unref();
+ paint.colorSampler(0)->setCustomStage(
+ SkNEW_ARGS(GrSingleTextureEffect, (background.get())), backgroundTexMatrix)->unref();
+ paint.colorSampler(1)->setCustomStage(
+ SkNEW_ARGS(GrBlendEffect, (fMode, foreground.get())), foregroundTexMatrix)->unref();
context->drawRect(paint, rect);
return dst;
}