blob: 9bbb88f7e8c6b67d3fce166a3dd6e9df55aa0b1b [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"
11
12static SkCanvas* create(SkBitmap::Config config, int w, int h, int rb,
13 void* addr = NULL) {
14 SkBitmap bm;
15 bm.setConfig(config, w, h, rb);
16 if (addr) {
17 bm.setPixels(addr);
18 } else {
19 bm.allocPixels();
20 }
21 return new SkCanvas(bm);
22}
23
mike@reedtribe.org6093e652012-04-14 12:55:17 +000024static SkCanvas* new_canvas(int w, int h) {
25 return create(SkBitmap::kARGB_8888_Config, w, h, 0, NULL);
26}
27
reed@google.coma90aa532012-04-16 16:27:09 +000028///////////////////////////////////////////////////////////////////////////////
29
mike@reedtribe.org6093e652012-04-14 12:55:17 +000030static void test_bug533(skiatest::Reporter* reporter) {
31#ifdef SK_SCALAR_IS_FLOAT
32 /*
33 http://code.google.com/p/skia/issues/detail?id=533
34 This particular test/bug only applies to the float case, where the
35 coordinates are very large.
36 */
37 SkPath path;
38 path.moveTo(64, 3);
39 path.quadTo(-329936, -100000000, 1153, 330003);
40
41 SkPaint paint;
42 paint.setAntiAlias(true);
43
44 SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480));
45 canvas.get()->drawPath(path, paint);
46#endif
47}
48
reed@google.coma90aa532012-04-16 16:27:09 +000049static void test_bigcubic(skiatest::Reporter* reporter) {
50#ifdef SK_SCALAR_IS_FLOAT
51 SkPath path;
52 path.moveTo(64, 3);
53 path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003);
54
55 SkPaint paint;
56 paint.setAntiAlias(true);
57
58 SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480));
59 canvas.get()->drawPath(path, paint);
60#endif
61}
62
reed@google.comdceecc72012-02-23 19:20:19 +000063// we used to assert if the bounds of the device (clip) was larger than 32K
64// even when the path itself was smaller. We just draw and hope in the debug
65// version to not assert.
66static void test_giantaa(skiatest::Reporter* reporter) {
67 const int W = 400;
68 const int H = 400;
mike@reedtribe.org6093e652012-04-14 12:55:17 +000069 SkAutoTUnref<SkCanvas> canvas(new_canvas(33000, 10));
70 canvas.get()->clear(0);
reed@google.comdceecc72012-02-23 19:20:19 +000071
72 SkPaint paint;
73 paint.setAntiAlias(true);
74 SkPath path;
75 path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H));
mike@reedtribe.org6093e652012-04-14 12:55:17 +000076 canvas.get()->drawPath(path, paint);
reed@google.comdceecc72012-02-23 19:20:19 +000077}
78
79static void TestDrawPath(skiatest::Reporter* reporter) {
80 test_giantaa(reporter);
mike@reedtribe.org6093e652012-04-14 12:55:17 +000081 test_bug533(reporter);
reed@google.coma90aa532012-04-16 16:27:09 +000082 test_bigcubic(reporter);
reed@google.comdceecc72012-02-23 19:20:19 +000083}
84
85#include "TestClassDef.h"
86DEFINE_TESTCLASS("DrawPath", TestDrawPathClass, TestDrawPath)