skia2/gm/imagefiltersgraph.cpp
senorblanco@chromium.org 985fa79141 Protect filter_texture() against render target change.
Fix blend filters when input textures are "sloppy" (approx scratch texture match)
Add a new test case to gm/imagefiltersgraph, and reduce its size.

NOTE:  this will require new baselines for the imagefiltersgraph GM.

BUG=950

Review URL: https://codereview.appspot.com/6769043

git-svn-id: http://skia.googlecode.com/svn/trunk@6073 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-10-24 15:14:26 +00:00

96 lines
3.2 KiB
C++

/*
* Copyright 2012 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 "SkBitmapSource.h"
#include "SkBlendImageFilter.h"
#include "SkBlurImageFilter.h"
#include "SkColorFilter.h"
#include "SkColorMatrixFilter.h"
#include "SkColorFilterImageFilter.h"
#include "SkMorphologyImageFilter.h"
#include "SkTestImageFilters.h"
///////////////////////////////////////////////////////////////////////////////
class ImageFiltersGraphGM : public skiagm::GM {
public:
ImageFiltersGraphGM() : fInitialized(false) {}
protected:
virtual SkString onShortName() {
return SkString("imagefiltersgraph");
}
void make_bitmap() {
fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
fBitmap.allocPixels();
SkDevice device(fBitmap);
SkCanvas canvas(&device);
canvas.clear(0x00000000);
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(0xFFFFFFFF);
paint.setTextSize(SkIntToScalar(96));
const char* str = "e";
canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint);
}
virtual SkISize onISize() { return SkISize::Make(200, 100); }
virtual void onDraw(SkCanvas* canvas) {
if (!fInitialized) {
this->make_bitmap();
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));
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> matrixFilter(new SkColorMatrixFilter(matrix));
SkAutoTUnref<SkImageFilter> colorMorph(new SkColorFilterImageFilter(matrixFilter, morph));
SkAutoTUnref<SkImageFilter> blendColor(new SkBlendImageFilter(SkBlendImageFilter::kNormal_Mode, colorMorph));
SkPaint paint;
paint.setImageFilter(blendColor);
canvas->drawBitmap(fBitmap, 100, 0, &paint);
}
}
private:
typedef GM INHERITED;
SkBitmap fBitmap;
bool fInitialized;
};
///////////////////////////////////////////////////////////////////////////////
static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; }
static skiagm::GMRegistry reg(MyFactory);