Mike Reed | d284949 | 2018-01-10 14:31:18 -0500 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkPaint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkPath.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 12 | #include "include/core/SkRect.h" |
| 13 | #include "include/core/SkRefCnt.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkSurface.h" |
Mike Reed | d284949 | 2018-01-10 14:31:18 -0500 | [diff] [blame] | 15 | |
Mike Reed | 23e0cf2 | 2018-01-16 13:58:01 -0500 | [diff] [blame] | 16 | DEF_SIMPLE_GM(path_huge_crbug_800804, canvas, 50, 600) { |
Mike Reed | d284949 | 2018-01-10 14:31:18 -0500 | [diff] [blame] | 17 | SkPaint paint; |
| 18 | paint.setAntiAlias(true); |
Mike Reed | d284949 | 2018-01-10 14:31:18 -0500 | [diff] [blame] | 19 | paint.setStyle(SkPaint::kStroke_Style); |
Mike Reed | e233026 | 2018-01-12 12:06:40 -0500 | [diff] [blame] | 20 | |
Mike Reed | 23e0cf2 | 2018-01-16 13:58:01 -0500 | [diff] [blame] | 21 | // exercise various special-cases (e.g. hairlines or not) |
| 22 | const float widths[] = { 0.9f, 1.0f, 1.1f }; |
| 23 | |
| 24 | SkPath path; |
| 25 | for (float w : widths) { |
| 26 | paint.setStrokeWidth(w); |
| 27 | |
| 28 | path.reset(); |
| 29 | path.moveTo(-1000,12345678901234567890.f); |
| 30 | path.lineTo(10.5f,200); |
| 31 | canvas->drawPath(path, paint); |
| 32 | |
| 33 | path.reset(); |
| 34 | path.moveTo(30.5f,400); |
| 35 | path.lineTo(1000,-9.8765432109876543210e+19f); |
| 36 | canvas->drawPath(path, paint); |
| 37 | |
| 38 | canvas->translate(3, 0); |
| 39 | } |
Mike Reed | d284949 | 2018-01-10 14:31:18 -0500 | [diff] [blame] | 40 | } |
| 41 | |
Mike Reed | b5e1f75 | 2018-03-07 14:16:52 -0500 | [diff] [blame] | 42 | // Test that we can draw into a huge surface ( > 64K ) and still retain paths and antialiasing. |
| 43 | DEF_SIMPLE_GM(path_huge_aa, canvas, 200, 200) { |
| 44 | auto proc = [](SkCanvas* canvas, int w, int h) { |
| 45 | SkAutoCanvasRestore acr(canvas, true); |
| 46 | |
| 47 | auto surf = SkSurface::MakeRasterN32Premul(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); |
Mike Reed | b746b1f | 2021-01-06 08:43:51 -0500 | [diff] [blame] | 57 | surf->draw(canvas, 64 - w, 0); |
Mike Reed | b5e1f75 | 2018-03-07 14:16:52 -0500 | [diff] [blame] | 58 | canvas->restore(); |
| 59 | |
| 60 | canvas->translate(80, 0); |
| 61 | canvas->save(); |
| 62 | canvas->clipRect(SkRect::MakeXYWH(4, 4, 64, 64)); |
| 63 | can->clear(0); |
| 64 | paint.setAntiAlias(true); |
| 65 | can->drawPath(path, paint); |
Mike Reed | b746b1f | 2021-01-06 08:43:51 -0500 | [diff] [blame] | 66 | surf->draw(canvas, 64 - w, 0); |
Mike Reed | b5e1f75 | 2018-03-07 14:16:52 -0500 | [diff] [blame] | 67 | canvas->restore(); |
| 68 | }; |
| 69 | |
| 70 | proc(canvas, 100, 60); |
| 71 | canvas->translate(0, 80); |
| 72 | proc(canvas, 100 * 1024, 60); |
| 73 | } |