diff options
author | reed <reed@google.com> | 2016-08-01 11:24:14 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-01 11:24:14 -0700 |
commit | f1ac18229c3f0f813a128a10111766c991f9dfcf (patch) | |
tree | 0709fd5ca97bad6b19abfc7ecdd3fcd2190e8ef2 /tests/ShaderTest.cpp | |
parent | da574d17f864ed70323a1c0fc6e4e969153a4c98 (diff) |
implement isABitmap for imageshader, return localmatrix for bitmap's impl
For imageshader, I only return true if the image is explicitly raster-backed. I do not return true for texture, nor for generator (i.e. lazy/picture) backed. Is that ok?
BUG=skia:5592
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2197323002
Review-Url: https://codereview.chromium.org/2197323002
Diffstat (limited to 'tests/ShaderTest.cpp')
-rw-r--r-- | tests/ShaderTest.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/ShaderTest.cpp b/tests/ShaderTest.cpp new file mode 100644 index 0000000000..d3f74ffb3d --- /dev/null +++ b/tests/ShaderTest.cpp @@ -0,0 +1,60 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "Test.h" +#include "SkBitmap.h" +#include "SkImage.h" +#include "SkShader.h" +#include "SkSurface.h" +#include "SkData.h" + +static void check_isabitmap(skiatest::Reporter* reporter, SkShader* shader, + int expectedW, int expectedH, + SkShader::TileMode expectedX, SkShader::TileMode expectedY, + const SkMatrix& expectedM, + bool expectedImage) { + SkBitmap bm; + SkShader::TileMode tileModes[2]; + SkMatrix localM; + REPORTER_ASSERT(reporter, shader->isABitmap(&bm, &localM, tileModes)); + REPORTER_ASSERT(reporter, bm.width() == expectedW); + REPORTER_ASSERT(reporter, bm.height() == expectedH); + REPORTER_ASSERT(reporter, localM == expectedM); + REPORTER_ASSERT(reporter, tileModes[0] == expectedX); + REPORTER_ASSERT(reporter, tileModes[1] == expectedY); + + // wack these so we don't get a false positive + localM.setScale(9999, -9999); + tileModes[0] = tileModes[1] = (SkShader::TileMode)99; + + SkImage* image = shader->isAImage(&localM, tileModes); + REPORTER_ASSERT(reporter, (image != nullptr) == expectedImage); + if (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); + } +} + +DEF_TEST(Shader_isABitmap, reporter) { + 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); + const SkShader::TileMode tmx = SkShader::kRepeat_TileMode; + const SkShader::TileMode tmy = SkShader::kMirror_TileMode; + + auto shader0 = SkShader::MakeBitmapShader(bm, tmx, tmy, &localM); + auto shader1 = SkImage::MakeFromBitmap(bm)->makeShader(tmx, tmy, &localM); + + check_isabitmap(reporter, shader0.get(), W, H, tmx, tmy, localM, false); + check_isabitmap(reporter, shader1.get(), W, H, tmx, tmy, localM, true); +} |