| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkShader.h" | 10 #include "SkShader.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 SkPoint center = SkPoint::Make(SkIntToScalar(5), SkIntToScalar(5)); | 30 SkPoint center = SkPoint::Make(SkIntToScalar(5), SkIntToScalar(5)); |
| 31 SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN}; | 31 SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN}; |
| 32 SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1}; | 32 SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1}; |
| 33 SkScalar radius = SkIntToScalar(5); | 33 SkScalar radius = SkIntToScalar(5); |
| 34 | 34 |
| 35 // Test using the image filter | 35 // Test using the image filter |
| 36 { | 36 { |
| 37 SkShader* s = SkGradientShader::CreateRadial( | 37 SkShader* s = SkGradientShader::CreateRadial( |
| 38 center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClam
p_TileMode); | 38 center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClam
p_TileMode); |
| 39 SkPaint paint; | 39 SkPaint paint; |
| 40 paint.setImageFilter(SkRectShaderImageFilter::Create(s, r))->unref(); | 40 SkImageFilter::CropRect cr(r); |
| 41 paint.setImageFilter(SkRectShaderImageFilter::Create(s, &cr))->unref(); |
| 41 canvasFilter.drawRect(r, paint); | 42 canvasFilter.drawRect(r, paint); |
| 42 s->unref(); | 43 s->unref(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 // Test using the shader directly | 46 // Test using the shader directly |
| 46 { | 47 { |
| 47 SkShader* s = SkGradientShader::CreateRadial( | 48 SkShader* s = SkGradientShader::CreateRadial( |
| 48 center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClam
p_TileMode); | 49 center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClam
p_TileMode); |
| 49 SkPaint paint; | 50 SkPaint paint; |
| 50 paint.setShader(s)->unref(); | 51 paint.setShader(s)->unref(); |
| 51 canvasShader.drawRect(r, paint); | 52 canvasShader.drawRect(r, paint); |
| 52 } | 53 } |
| 53 | 54 |
| 54 // Assert that both paths yielded the same result | 55 // Assert that both paths yielded the same result |
| 55 for (int y = 0; y < r.height(); ++y) { | 56 for (int y = 0; y < r.height(); ++y) { |
| 56 const SkPMColor* filterPtr = filterResult.getAddr32(0, y); | 57 const SkPMColor* filterPtr = filterResult.getAddr32(0, y); |
| 57 const SkPMColor* shaderPtr = shaderResult.getAddr32(0, y); | 58 const SkPMColor* shaderPtr = shaderResult.getAddr32(0, y); |
| 58 for (int x = 0; x < r.width(); ++x, ++filterPtr, ++shaderPtr) { | 59 for (int x = 0; x < r.width(); ++x, ++filterPtr, ++shaderPtr) { |
| 59 REPORTER_ASSERT(reporter, *filterPtr == *shaderPtr); | 60 REPORTER_ASSERT(reporter, *filterPtr == *shaderPtr); |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 } | 63 } |
| 63 | 64 |
| 64 #include "TestClassDef.h" | 65 #include "TestClassDef.h" |
| 65 DEFINE_TESTCLASS("ShaderImageFilter", ShaderImageFilterTestClass, test_asShaderM
ode) | 66 DEFINE_TESTCLASS("ShaderImageFilter", ShaderImageFilterTestClass, test_asShaderM
ode) |
| OLD | NEW |