2015-12-18 15:14:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkAlphaThresholdFilter.h"
|
|
|
|
#include "SkImage.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
static void test_flattenable(skiatest::Reporter* r,
|
|
|
|
const SkFlattenable* f,
|
|
|
|
const char* desc) {
|
|
|
|
if (f) {
|
|
|
|
SkFlattenable::Factory factory = f->getFactory();
|
|
|
|
REPORTER_ASSERT(r, factory);
|
|
|
|
if (factory) {
|
|
|
|
if (!SkFlattenable::FactoryToName(factory)) {
|
|
|
|
ERRORF(r, "SkFlattenable::FactoryToName() fails with %s.", desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(FlattenableFactoryToName, r) {
|
|
|
|
SkIRect rects[2];
|
|
|
|
rects[0] = SkIRect::MakeXYWH(0, 150, 500, 200);
|
|
|
|
rects[1] = SkIRect::MakeXYWH(150, 0, 200, 500);
|
|
|
|
SkRegion region;
|
|
|
|
region.setRects(rects, 2);
|
|
|
|
SkAutoTUnref<SkImageFilter> filter( SkAlphaThresholdFilter::Create(region, 0.2f, 0.7f));
|
|
|
|
test_flattenable(r, filter, "SkAlphaThresholdFilter()");
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(8, 8);
|
|
|
|
bm.eraseColor(SK_ColorCYAN);
|
|
|
|
SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bm));
|
2016-03-09 22:47:34 +00:00
|
|
|
auto shader = image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
|
|
|
|
test_flattenable(r, shader.get(), "SkImage::newShader()");
|
2015-12-18 15:14:24 +00:00
|
|
|
}
|