2014-01-06 23:41:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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 "SkAlphaThresholdFilter.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
|
|
|
|
#define WIDTH 500
|
|
|
|
#define HEIGHT 500
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class ImageAlphaThresholdGM : public GM {
|
|
|
|
public:
|
|
|
|
ImageAlphaThresholdGM() {
|
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-01-06 23:41:14 +00:00
|
|
|
return SkString("imagealphathreshold");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(WIDTH, HEIGHT);
|
2014-01-06 23:41:14 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-01-06 23:41:14 +00:00
|
|
|
SkIRect rects[2];
|
|
|
|
rects[0] = SkIRect::MakeXYWH(0, 150, WIDTH, HEIGHT - 300);
|
|
|
|
rects[1] = SkIRect::MakeXYWH(150, 0, WIDTH - 300, HEIGHT);
|
|
|
|
SkRegion region;
|
|
|
|
region.setRects(rects, 2);
|
|
|
|
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.reset();
|
|
|
|
matrix.setTranslate(WIDTH * .1f, HEIGHT * .1f);
|
2014-01-07 16:04:01 +00:00
|
|
|
matrix.postScale(.8f, .8f);
|
2014-01-06 23:41:14 +00:00
|
|
|
|
|
|
|
canvas->concat(matrix);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setImageFilter(
|
|
|
|
SkAlphaThresholdFilter::Create(region, 0.2f, 0.7f))->unref();
|
|
|
|
canvas->saveLayer(NULL, &paint);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
|
|
|
SkPaint rect_paint;
|
|
|
|
rect_paint.setColor(0xFF0000FF);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(0, 0, WIDTH / 2, HEIGHT / 2),
|
|
|
|
rect_paint);
|
|
|
|
rect_paint.setColor(0xBFFF0000);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, 0, WIDTH / 2, HEIGHT / 2),
|
|
|
|
rect_paint);
|
|
|
|
rect_paint.setColor(0x3F00FF00);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(0, HEIGHT / 2, WIDTH / 2, HEIGHT / 2),
|
|
|
|
rect_paint);
|
|
|
|
rect_paint.setColor(0x00000000);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIGHT / 2),
|
|
|
|
rect_paint);
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new ImageAlphaThresholdGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|