2016-08-01 18:24:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkRRect.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/effects/SkPerlinNoiseShader.h"
|
|
|
|
#include "tests/Test.h"
|
2016-08-01 18:24:14 +00:00
|
|
|
|
2018-10-15 16:39:03 +00:00
|
|
|
static void check_isaimage(skiatest::Reporter* reporter, SkShader* shader,
|
|
|
|
int expectedW, int expectedH,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode expectedX, SkTileMode expectedY,
|
2018-10-15 16:39:03 +00:00
|
|
|
const SkMatrix& expectedM) {
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tileModes[2];
|
2016-08-01 18:24:14 +00:00
|
|
|
SkMatrix localM;
|
2016-09-28 21:13:38 +00:00
|
|
|
|
2016-08-01 18:24:14 +00:00
|
|
|
// wack these so we don't get a false positive
|
|
|
|
localM.setScale(9999, -9999);
|
2019-04-03 14:27:45 +00:00
|
|
|
tileModes[0] = tileModes[1] = (SkTileMode)99;
|
2016-08-01 18:24:14 +00:00
|
|
|
|
|
|
|
SkImage* image = shader->isAImage(&localM, tileModes);
|
2016-08-02 13:12:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, image);
|
|
|
|
REPORTER_ASSERT(reporter, image->width() == expectedW);
|
|
|
|
REPORTER_ASSERT(reporter, image->height() == expectedH);
|
|
|
|
REPORTER_ASSERT(reporter, localM == expectedM);
|
|
|
|
REPORTER_ASSERT(reporter, tileModes[0] == expectedX);
|
|
|
|
REPORTER_ASSERT(reporter, tileModes[1] == expectedY);
|
2016-08-01 18:24:14 +00:00
|
|
|
}
|
|
|
|
|
2018-10-15 16:39:03 +00:00
|
|
|
DEF_TEST(Shader_isAImage, reporter) {
|
2016-08-01 18:24:14 +00:00
|
|
|
const int W = 100;
|
|
|
|
const int H = 100;
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(W, H);
|
|
|
|
auto img = SkImage::MakeFromBitmap(bm);
|
|
|
|
const SkMatrix localM = SkMatrix::MakeScale(2, 3);
|
2019-04-03 14:27:45 +00:00
|
|
|
const SkTileMode tmx = SkTileMode::kRepeat;
|
|
|
|
const SkTileMode tmy = SkTileMode::kMirror;
|
2016-08-01 18:24:14 +00:00
|
|
|
|
2019-04-08 17:20:23 +00:00
|
|
|
auto shader0 = bm.makeShader(tmx, tmy, &localM);
|
2016-08-01 18:24:14 +00:00
|
|
|
auto shader1 = SkImage::MakeFromBitmap(bm)->makeShader(tmx, tmy, &localM);
|
|
|
|
|
2018-10-15 16:39:03 +00:00
|
|
|
check_isaimage(reporter, shader0.get(), W, H, tmx, tmy, localM);
|
|
|
|
check_isaimage(reporter, shader1.get(), W, H, tmx, tmy, localM);
|
2016-08-01 18:24:14 +00:00
|
|
|
}
|
2017-02-28 16:14:47 +00:00
|
|
|
|
|
|
|
// Make sure things are ok with just a single leg.
|
|
|
|
DEF_TEST(ComposeShaderSingle, reporter) {
|
|
|
|
SkBitmap srcBitmap;
|
|
|
|
srcBitmap.allocN32Pixels(10, 10);
|
|
|
|
srcBitmap.eraseColor(SK_ColorRED);
|
|
|
|
SkCanvas canvas(srcBitmap);
|
|
|
|
SkPaint p;
|
|
|
|
p.setShader(
|
2019-04-09 17:55:36 +00:00
|
|
|
SkShaders::Blend(SkBlendMode::kClear,
|
|
|
|
SkShaders::Empty(),
|
|
|
|
SkPerlinNoiseShader::MakeFractalNoise(1.0f, 1.0f, 2, 0.0f)));
|
2017-02-28 16:14:47 +00:00
|
|
|
SkRRect rr;
|
|
|
|
SkVector rd[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
|
|
|
|
rr.setRectRadii({0, 0, 0, 0}, rd);
|
|
|
|
canvas.drawRRect(rr, p);
|
|
|
|
}
|