epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | #include "SkPath.h" |
| 10 | #include "SkPaint.h" |
| 11 | |
| 12 | // found and fixed for webkit: mishandling when we hit recursion limit on |
| 13 | // mostly degenerate cubic flatness test |
| 14 | static void regression_cubic(skiatest::Reporter* reporter) { |
| 15 | SkPath path, stroke; |
| 16 | SkPaint paint; |
| 17 | |
reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 18 | path.moveTo(SkFloatToFixed(460.2881309415525f), |
| 19 | SkFloatToFixed(303.250847066498)); |
| 20 | path.cubicTo(SkFloatToFixed(463.36378422175284), |
| 21 | SkFloatToFixed(302.1169735073363), |
| 22 | SkFloatToFixed(456.32239330810046), |
| 23 | SkFloatToFixed(304.720354932878), |
| 24 | SkFloatToFixed(453.15255460013304), |
| 25 | SkFloatToFixed(305.788586869862)); |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 26 | |
| 27 | SkRect fillR, strokeR; |
| 28 | fillR = path.getBounds(); |
| 29 | |
| 30 | paint.setStyle(SkPaint::kStroke_Style); |
| 31 | paint.setStrokeWidth(SkIntToScalar(2)); |
| 32 | paint.getFillPath(path, &stroke); |
| 33 | strokeR = stroke.getBounds(); |
| 34 | |
| 35 | SkRect maxR = fillR; |
| 36 | SkScalar miter = SkMaxScalar(SK_Scalar1, paint.getStrokeMiter()); |
| 37 | SkScalar inset = paint.getStrokeJoin() == SkPaint::kMiter_Join ? |
| 38 | SkScalarMul(paint.getStrokeWidth(), miter) : |
| 39 | paint.getStrokeWidth(); |
| 40 | maxR.inset(-inset, -inset); |
| 41 | |
| 42 | // test that our stroke didn't explode |
| 43 | REPORTER_ASSERT(reporter, maxR.contains(strokeR)); |
| 44 | } |
| 45 | |
| 46 | static void TestPaint(skiatest::Reporter* reporter) { |
| 47 | // TODO add general paint tests |
| 48 | |
| 49 | // regression tests |
| 50 | regression_cubic(reporter); |
| 51 | } |
| 52 | |
| 53 | #include "TestClassDef.h" |
| 54 | DEFINE_TESTCLASS("Paint", TestPaintClass, TestPaint) |