blob: 4a691b81824dafeb5640dd1043e216834ecfda8e [file] [log] [blame]
Mike Reedd2849492018-01-10 14:31:18 -05001/*
2 * Copyright 2018 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 "gm.h"
9#include "SkCanvas.h"
10#include "SkPath.h"
Mike Reedb5e1f752018-03-07 14:16:52 -050011#include "SkSurface.h"
Mike Reedd2849492018-01-10 14:31:18 -050012
Mike Reed23e0cf22018-01-16 13:58:01 -050013DEF_SIMPLE_GM(path_huge_crbug_800804, canvas, 50, 600) {
Mike Reedd2849492018-01-10 14:31:18 -050014 SkPaint paint;
15 paint.setAntiAlias(true);
Mike Reedd2849492018-01-10 14:31:18 -050016 paint.setStyle(SkPaint::kStroke_Style);
Mike Reede2330262018-01-12 12:06:40 -050017
Mike Reed23e0cf22018-01-16 13:58:01 -050018 // exercise various special-cases (e.g. hairlines or not)
19 const float widths[] = { 0.9f, 1.0f, 1.1f };
20
21 SkPath path;
22 for (float w : widths) {
23 paint.setStrokeWidth(w);
24
25 path.reset();
26 path.moveTo(-1000,12345678901234567890.f);
27 path.lineTo(10.5f,200);
28 canvas->drawPath(path, paint);
29
30 path.reset();
31 path.moveTo(30.5f,400);
32 path.lineTo(1000,-9.8765432109876543210e+19f);
33 canvas->drawPath(path, paint);
34
35 canvas->translate(3, 0);
36 }
Mike Reedd2849492018-01-10 14:31:18 -050037}
38
Mike Reedb5e1f752018-03-07 14:16:52 -050039// Test that we can draw into a huge surface ( > 64K ) and still retain paths and antialiasing.
40DEF_SIMPLE_GM(path_huge_aa, canvas, 200, 200) {
41 auto proc = [](SkCanvas* canvas, int w, int h) {
42 SkAutoCanvasRestore acr(canvas, true);
43
44 auto surf = SkSurface::MakeRasterN32Premul(w, h);
45 auto can = surf->getCanvas();
46
47 SkPaint paint;
48 SkPath path;
49 path.addRoundRect(SkRect::MakeXYWH(4, 4, w - 8, h - 8), 12, 12);
50
51 canvas->save();
52 canvas->clipRect(SkRect::MakeXYWH(4, 4, 64, 64));
53 can->drawPath(path, paint);
54 surf->draw(canvas, 64 - w, 0, nullptr);
55 canvas->restore();
56
57 canvas->translate(80, 0);
58 canvas->save();
59 canvas->clipRect(SkRect::MakeXYWH(4, 4, 64, 64));
60 can->clear(0);
61 paint.setAntiAlias(true);
62 can->drawPath(path, paint);
63 surf->draw(canvas, 64 - w, 0, nullptr);
64 canvas->restore();
65 };
66
67 proc(canvas, 100, 60);
68 canvas->translate(0, 80);
69 proc(canvas, 100 * 1024, 60);
70}