blob: e446755f987dfb1bb09b2fb5d0b30bb54524b105 [file] [log] [blame]
reed@google.comdceecc72012-02-23 19:20:19 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "Test.h"
9#include "SkBitmap.h"
10#include "SkCanvas.h"
reed@google.com1df888b2012-04-24 22:47:21 +000011#include "SkDashPathEffect.h"
reed@google.comdceecc72012-02-23 19:20:19 +000012
13static SkCanvas* create(SkBitmap::Config config, int w, int h, int rb,
14 void* addr = NULL) {
15 SkBitmap bm;
16 bm.setConfig(config, w, h, rb);
17 if (addr) {
18 bm.setPixels(addr);
19 } else {
20 bm.allocPixels();
21 }
22 return new SkCanvas(bm);
23}
24
mike@reedtribe.org6093e652012-04-14 12:55:17 +000025static SkCanvas* new_canvas(int w, int h) {
26 return create(SkBitmap::kARGB_8888_Config, w, h, 0, NULL);
27}
28
reed@google.coma90aa532012-04-16 16:27:09 +000029///////////////////////////////////////////////////////////////////////////////
30
mike@reedtribe.org6093e652012-04-14 12:55:17 +000031static void test_bug533(skiatest::Reporter* reporter) {
32#ifdef SK_SCALAR_IS_FLOAT
33 /*
34 http://code.google.com/p/skia/issues/detail?id=533
35 This particular test/bug only applies to the float case, where the
36 coordinates are very large.
37 */
38 SkPath path;
39 path.moveTo(64, 3);
40 path.quadTo(-329936, -100000000, 1153, 330003);
41
42 SkPaint paint;
43 paint.setAntiAlias(true);
44
45 SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480));
46 canvas.get()->drawPath(path, paint);
47#endif
48}
49
reed@google.com1df888b2012-04-24 22:47:21 +000050static void test_crbug_124652(skiatest::Reporter* reporter) {
51#ifdef SK_SCALAR_IS_FLOAT
52 /*
53 http://code.google.com/p/chromium/issues/detail?id=124652
54 This particular test/bug only applies to the float case, where
55 large values can "swamp" small ones.
56 */
57 SkScalar intervals[2] = {837099584, 33450};
58 SkAutoTUnref<SkDashPathEffect> dash(
59 new SkDashPathEffect(intervals, 2, -10, false));
60#endif
61}
62
reed@google.coma90aa532012-04-16 16:27:09 +000063static void test_bigcubic(skiatest::Reporter* reporter) {
64#ifdef SK_SCALAR_IS_FLOAT
65 SkPath path;
66 path.moveTo(64, 3);
67 path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003);
68
69 SkPaint paint;
70 paint.setAntiAlias(true);
71
72 SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480));
73 canvas.get()->drawPath(path, paint);
74#endif
75}
76
reed@google.comdceecc72012-02-23 19:20:19 +000077// we used to assert if the bounds of the device (clip) was larger than 32K
78// even when the path itself was smaller. We just draw and hope in the debug
79// version to not assert.
80static void test_giantaa(skiatest::Reporter* reporter) {
81 const int W = 400;
82 const int H = 400;
mike@reedtribe.org6093e652012-04-14 12:55:17 +000083 SkAutoTUnref<SkCanvas> canvas(new_canvas(33000, 10));
84 canvas.get()->clear(0);
reed@google.comdceecc72012-02-23 19:20:19 +000085
86 SkPaint paint;
87 paint.setAntiAlias(true);
88 SkPath path;
89 path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H));
mike@reedtribe.org6093e652012-04-14 12:55:17 +000090 canvas.get()->drawPath(path, paint);
reed@google.comdceecc72012-02-23 19:20:19 +000091}
92
93static void TestDrawPath(skiatest::Reporter* reporter) {
94 test_giantaa(reporter);
mike@reedtribe.org6093e652012-04-14 12:55:17 +000095 test_bug533(reporter);
reed@google.coma90aa532012-04-16 16:27:09 +000096 test_bigcubic(reporter);
reed@google.com1df888b2012-04-24 22:47:21 +000097 test_crbug_124652(reporter);
reed@google.comdceecc72012-02-23 19:20:19 +000098}
99
100#include "TestClassDef.h"
101DEFINE_TESTCLASS("DrawPath", TestDrawPathClass, TestDrawPath)