skia2/tests/FlattenableFactoryToName.cpp
robertphillips f7142e71d7 Split AlphaThresholdEffect out into its own file
Mainly mechanical although I did:
   convert Create method to sk_sp Make version
   rm extra '\t's and '\n's in emitCode

TBR=reed@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1893193002

Review URL: https://codereview.chromium.org/1893193002
2016-04-18 07:20:05 -07:00

43 lines
1.3 KiB
C++

/*
* 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 "SkRegion.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);
sk_sp<SkImageFilter> filter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, nullptr));
test_flattenable(r, filter.get(), "SkAlphaThresholdFilter()");
SkBitmap bm;
bm.allocN32Pixels(8, 8);
bm.eraseColor(SK_ColorCYAN);
sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
auto shader = image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
test_flattenable(r, shader.get(), "SkImage::newShader()");
}