blob: 315b88e558992a213b23a274ff3f9575642baf00 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkPath.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040012#include "include/core/SkRect.h"
13#include "include/core/SkRefCnt.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/core/SkSurface.h"
Robert Phillips01f3be42023-06-16 13:22:18 -040015#include "include/core/SkTiledImageUtils.h"
Mike Reedd2849492018-01-10 14:31:18 -050016
Mike Reed23e0cf22018-01-16 13:58:01 -050017DEF_SIMPLE_GM(path_huge_crbug_800804, canvas, 50, 600) {
Mike Reedd2849492018-01-10 14:31:18 -050018 SkPaint paint;
19 paint.setAntiAlias(true);
Mike Reedd2849492018-01-10 14:31:18 -050020 paint.setStyle(SkPaint::kStroke_Style);
Mike Reede2330262018-01-12 12:06:40 -050021
Mike Reed23e0cf22018-01-16 13:58:01 -050022 // exercise various special-cases (e.g. hairlines or not)
23 const float widths[] = { 0.9f, 1.0f, 1.1f };
24
25 SkPath path;
26 for (float w : widths) {
27 paint.setStrokeWidth(w);
28
29 path.reset();
30 path.moveTo(-1000,12345678901234567890.f);
31 path.lineTo(10.5f,200);
32 canvas->drawPath(path, paint);
33
34 path.reset();
35 path.moveTo(30.5f,400);
36 path.lineTo(1000,-9.8765432109876543210e+19f);
37 canvas->drawPath(path, paint);
38
39 canvas->translate(3, 0);
40 }
Mike Reedd2849492018-01-10 14:31:18 -050041}
42
Mike Reedb5e1f752018-03-07 14:16:52 -050043// Test that we can draw into a huge surface ( > 64K ) and still retain paths and antialiasing.
Robert Phillips01f3be42023-06-16 13:22:18 -040044static void draw_huge_path(SkCanvas* canvas, int w, int h, bool manual) {
45 SkAutoCanvasRestore acr(canvas, true);
46
47 auto surf = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(w, h));
48 auto can = surf->getCanvas();
49
50 SkPaint paint;
51 SkPath path;
52 path.addRoundRect(SkRect::MakeXYWH(4, 4, w - 8, h - 8), 12, 12);
53
54 canvas->save();
55 canvas->clipRect(SkRect::MakeXYWH(4, 4, 64, 64));
56 can->drawPath(path, paint);
57 if (manual) {
58 SkTiledImageUtils::DrawImage(canvas, surf->makeImageSnapshot(), 64 - w, 0);
59 } else {
60 canvas->drawImage(surf->makeImageSnapshot(), 64 - w, 0);
61 }
62 canvas->restore();
63
64 canvas->translate(80, 0);
65 canvas->save();
66 canvas->clipRect(SkRect::MakeXYWH(4, 4, 64, 64));
67 can->clear(0);
68 paint.setAntiAlias(true);
69 can->drawPath(path, paint);
70 if (manual) {
71 SkTiledImageUtils::DrawImage(canvas, surf->makeImageSnapshot(), 64 - w, 0);
72 } else {
73 canvas->drawImage(surf->makeImageSnapshot(), 64 - w, 0);
74 }
75 canvas->restore();
76};
77
Mike Reedb5e1f752018-03-07 14:16:52 -050078DEF_SIMPLE_GM(path_huge_aa, canvas, 200, 200) {
Robert Phillips01f3be42023-06-16 13:22:18 -040079 draw_huge_path(canvas, 100, 60, /* manual= */ false);
Mike Reedb5e1f752018-03-07 14:16:52 -050080 canvas->translate(0, 80);
Robert Phillips01f3be42023-06-16 13:22:18 -040081 draw_huge_path(canvas, 100 * 1024, 60, /* manual= */ false);
82}
83
84DEF_SIMPLE_GM(path_huge_aa_manual, canvas, 200, 200) {
85 draw_huge_path(canvas, 100, 60, /* manual= */ true);
86 canvas->translate(0, 80);
87 draw_huge_path(canvas, 100 * 1024, 60, /* manual= */ true);
Mike Reedb5e1f752018-03-07 14:16:52 -050088}