c0bd9f9fe5
Current strategy: everything from the top Things to look at first are the manual changes: - added tools/rewrite_includes.py - removed -Idirectives from BUILD.gn - various compile.sh simplifications - tweak tools/embed_resources.py - update gn/find_headers.py to write paths from the top - update gn/gn_to_bp.py SkUserConfig.h layout so that #include "include/config/SkUserConfig.h" always gets the header we want. No-Presubmit: true Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706 Commit-Queue: Mike Klein <mtklein@google.com> Reviewed-by: Hal Canary <halcanary@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
113 lines
3.6 KiB
C++
113 lines
3.6 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/SkPaintImageFilter.h"
|
|
#include "tests/Test.h"
|
|
|
|
static void test_unscaled(skiatest::Reporter* reporter) {
|
|
int w = 10, h = 10;
|
|
SkRect r = SkRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h));
|
|
|
|
SkBitmap filterResult, paintResult;
|
|
|
|
filterResult.allocN32Pixels(w, h);
|
|
SkCanvas canvasFilter(filterResult);
|
|
canvasFilter.clear(0x00000000);
|
|
|
|
paintResult.allocN32Pixels(w, h);
|
|
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);
|
|
|
|
SkPaint gradientPaint;
|
|
gradientPaint.setShader(SkGradientShader::MakeRadial(
|
|
center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkTileMode::kClamp));
|
|
|
|
// Test using the image filter
|
|
{
|
|
SkPaint paint;
|
|
SkImageFilter::CropRect cr(r);
|
|
paint.setImageFilter(SkPaintImageFilter::Make(gradientPaint, &cr));
|
|
canvasFilter.drawRect(r, paint);
|
|
}
|
|
|
|
// Test using the paint directly
|
|
{
|
|
canvasPaint.drawRect(r, gradientPaint);
|
|
}
|
|
|
|
// Assert that both paths yielded the same result
|
|
for (int y = 0; y < r.height(); ++y) {
|
|
const SkPMColor* filterPtr = filterResult.getAddr32(0, y);
|
|
const SkPMColor* paintPtr = paintResult.getAddr32(0, y);
|
|
for (int x = 0; x < r.width(); ++x, ++filterPtr, ++paintPtr) {
|
|
REPORTER_ASSERT(reporter, *filterPtr == *paintPtr);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void test_scaled(skiatest::Reporter* reporter) {
|
|
int w = 10, h = 10;
|
|
SkRect r = SkRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h));
|
|
|
|
SkBitmap filterResult, paintResult;
|
|
|
|
filterResult.allocN32Pixels(w, h);
|
|
SkCanvas canvasFilter(filterResult);
|
|
canvasFilter.clear(0x00000000);
|
|
|
|
paintResult.allocN32Pixels(w, h);
|
|
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);
|
|
|
|
SkPaint gradientPaint;
|
|
gradientPaint.setShader(SkGradientShader::MakeRadial(
|
|
center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkTileMode::kClamp));
|
|
|
|
// Test using the image filter
|
|
{
|
|
SkPaint paint;
|
|
SkImageFilter::CropRect cr(r);
|
|
paint.setImageFilter(SkPaintImageFilter::Make(gradientPaint, &cr));
|
|
canvasFilter.scale(SkIntToScalar(2), SkIntToScalar(2));
|
|
canvasFilter.drawRect(r, paint);
|
|
}
|
|
|
|
// Test using the paint directly
|
|
{
|
|
canvasPaint.scale(SkIntToScalar(2), SkIntToScalar(2));
|
|
canvasPaint.drawRect(r, gradientPaint);
|
|
}
|
|
|
|
// Assert that both paths yielded the same result
|
|
for (int y = 0; y < r.height(); ++y) {
|
|
const SkPMColor* filterPtr = filterResult.getAddr32(0, y);
|
|
const SkPMColor* paintPtr = paintResult.getAddr32(0, y);
|
|
for (int x = 0; x < r.width(); ++x, ++filterPtr, ++paintPtr) {
|
|
REPORTER_ASSERT(reporter, *filterPtr == *paintPtr);
|
|
}
|
|
}
|
|
}
|
|
|
|
DEF_TEST(PaintImageFilter, reporter) {
|
|
test_unscaled(reporter);
|
|
test_scaled(reporter);
|
|
}
|