skia2/tests/ShaderImageFilterTest.cpp
Leandro Lovisolo 5f4055d03d Revert "Add public API support for SkImageFilters::RuntimeShader"
This reverts commit ad9d774c1f.

Reason for revert: Task Test-Debian10-Clang-NUC7i5BNK-GPU-IntelIris640-x86_64-Release-All-DDL3_TSAN has been failing since this CL landed.

Original change's description:
> Add public API support for SkImageFilters::RuntimeShader
>
> This new image filter constructor enables SkRuntimeEffects to be
> used as shaders within the ImageFilter DAG. The shader is created
> lazily using the SkRuntimeShaderBuilder enabling the resulting
> shader to consume the previous stage of the ImageFilter graph.
>
> Change-Id: I5d6917e34a8e5fdd053399f15a1e2cc7409e686f
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/470459
> Reviewed-by: Brian Osman <brianosman@google.com>
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Derek Sollenberger <djsollen@google.com>

Change-Id: I0367a5c480df109c6116eb168792fe3c2fc58807
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/475644
Auto-Submit: Leandro Lovisolo <lovisolo@google.com>
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Leandro Lovisolo <lovisolo@google.com>
2021-11-23 20:58:15 +00:00

117 lines
3.7 KiB
C++

/*
* 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 "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkShader.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkImageFilters.h"
#include "tests/Test.h"
static void test_unscaled(skiatest::Reporter* reporter) {
static const int kWidth = 10;
static const int kHeight = 10;
SkIRect ir = SkIRect::MakeWH(kWidth, kHeight);
SkBitmap filterResult, paintResult;
filterResult.allocN32Pixels(kWidth, kHeight);
SkCanvas canvasFilter(filterResult);
canvasFilter.clear(0x00000000);
paintResult.allocN32Pixels(kWidth, kHeight);
SkCanvas canvasPaint(paintResult);
canvasPaint.clear(0x00000000);
SkPoint center = SkPoint::Make(SkIntToScalar(5), SkIntToScalar(5));
SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN};
SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1};
SkScalar radius = SkIntToScalar(5);
sk_sp<SkShader> gradient = SkGradientShader::MakeRadial(
center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkTileMode::kClamp);
// Test using the image filter
{
SkPaint paint;
paint.setImageFilter(SkImageFilters::Shader(gradient, &ir));
canvasFilter.drawRect(SkRect::Make(ir), paint);
}
// Test using the paint directly
{
SkPaint paint;
paint.setShader(gradient);
canvasPaint.drawRect(SkRect::Make(ir), paint);
}
// Assert that both paths yielded the same result
for (int y = 0; y < kHeight; ++y) {
const SkPMColor* filterPtr = filterResult.getAddr32(0, y);
const SkPMColor* paintPtr = paintResult.getAddr32(0, y);
for (int x = 0; x < kWidth; ++x, ++filterPtr, ++paintPtr) {
REPORTER_ASSERT(reporter, *filterPtr == *paintPtr);
}
}
}
static void test_scaled(skiatest::Reporter* reporter) {
static const int kWidth = 10;
static const int kHeight = 10;
SkIRect ir = SkIRect::MakeWH(kWidth, kHeight);
SkBitmap filterResult, paintResult;
filterResult.allocN32Pixels(kWidth, kHeight);
SkCanvas canvasFilter(filterResult);
canvasFilter.clear(0x00000000);
paintResult.allocN32Pixels(kWidth, kHeight);
SkCanvas canvasPaint(paintResult);
canvasPaint.clear(0x00000000);
SkPoint center = SkPoint::Make(SkIntToScalar(5), SkIntToScalar(5));
SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN};
SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1};
SkScalar radius = SkIntToScalar(5);
sk_sp<SkShader> gradient = SkGradientShader::MakeRadial(
center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkTileMode::kClamp);
// Test using the image filter
{
SkPaint paint;
paint.setImageFilter(SkImageFilters::Shader(gradient, &ir));
canvasFilter.scale(SkIntToScalar(2), SkIntToScalar(2));
canvasFilter.drawRect(SkRect::Make(ir), paint);
}
// Test using the paint directly
{
SkPaint paint;
paint.setShader(gradient);
canvasPaint.scale(SkIntToScalar(2), SkIntToScalar(2));
canvasPaint.drawRect(SkRect::Make(ir), paint);
}
// Assert that both paths yielded the same result
for (int y = 0; y < kHeight; ++y) {
const SkPMColor* filterPtr = filterResult.getAddr32(0, y);
const SkPMColor* paintPtr = paintResult.getAddr32(0, y);
for (int x = 0; x < kWidth; ++x, ++filterPtr, ++paintPtr) {
REPORTER_ASSERT(reporter, *filterPtr == *paintPtr);
}
}
}
DEF_TEST(PaintImageFilter, reporter) {
test_unscaled(reporter);
test_scaled(reporter);
}