skia2/tests/ShaderImageFilterTest.cpp
tfarina@chromium.org 8f6884aab8 Cleanup: Sanitize the order of includes under tests/
Initially this was to make sure Test.h appeared after the Sk*.h includes.

Patch generated by the following command line:

$ ~/chromium/src/tools/sort-headers.py tests/*.cpp

BUG=None
TEST=tests
R=robertphillips@google.com

Review URL: https://codereview.chromium.org/145313004

git-svn-id: http://skia.googlecode.com/svn/trunk@13177 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-24 20:56:26 +00:00

64 lines
2.1 KiB
C++

/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkCanvas.h"
#include "SkGradientShader.h"
#include "SkRectShaderImageFilter.h"
#include "SkShader.h"
#include "Test.h"
DEF_TEST(ShaderImageFilter, reporter) {
int w = 10, h = 10;
SkRect r = SkRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h)); // Make small 10x10 gradient
SkBitmap filterResult, shaderResult;
filterResult.setConfig(SkBitmap::kARGB_8888_Config, w, h);
filterResult.allocPixels();
SkCanvas canvasFilter(filterResult);
canvasFilter.clear(0x00000000);
shaderResult.setConfig(SkBitmap::kARGB_8888_Config, w, h);
shaderResult.allocPixels();
SkCanvas canvasShader(shaderResult);
canvasShader.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);
// Test using the image filter
{
SkShader* s = SkGradientShader::CreateRadial(
center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode);
SkPaint paint;
SkImageFilter::CropRect cr(r);
paint.setImageFilter(SkRectShaderImageFilter::Create(s, &cr))->unref();
canvasFilter.drawRect(r, paint);
s->unref();
}
// Test using the shader directly
{
SkShader* s = SkGradientShader::CreateRadial(
center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode);
SkPaint paint;
paint.setShader(s)->unref();
canvasShader.drawRect(r, paint);
}
// 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* shaderPtr = shaderResult.getAddr32(0, y);
for (int x = 0; x < r.width(); ++x, ++filterPtr, ++shaderPtr) {
REPORTER_ASSERT(reporter, *filterPtr == *shaderPtr);
}
}
}