| 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 |
|
| 8 |
#include "gm/gm.h" |
| 9 |
#include "include/core/SkCanvas.h" |
| 10 |
#include "include/core/SkPaint.h" |
| 11 |
#include "include/core/SkPath.h" |
| 12 |
#include "include/core/SkRect.h" |
| 13 |
#include "include/core/SkRefCnt.h" |
| 14 |
#include "include/core/SkSurface.h" |
| 15 |
#include "include/core/SkTiledImageUtils.h" |
| 16 |
|
| 17 |
DEF_SIMPLE_GM(path_huge_crbug_800804, canvas, 50, 600) { |
| 18 |
SkPaint paint; |
| 19 |
paint.setAntiAlias(true); |
| 20 |
paint.setStyle(SkPaint::kStroke_Style); |
| 21 |
|
| 22 |
// exercise various special-cases (e.g. hairlines or not) |
| 23 |
const float widths[] = { 0.9f, 1.0f, 1.1f }; |
| 24 |
|
| 25 |
for (float w : widths) { |
| 26 |
paint.setStrokeWidth(w); |
| 27 |
|
| 28 |
SkPath path = SkPath::Line({-1000,12345678901234567890.f}, {10.5f,200}); |
| 29 |
canvas->drawPath(path, paint); |
| 30 |
|
| 31 |
path = SkPath::Line({30.5f,400}, {1000,-9.8765432109876543210e+19f}); |
| 32 |
canvas->drawPath(path, paint); |
| 33 |
|
| 34 |
canvas->translate(3, 0); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
// Test that we can draw into a huge surface ( > 64K ) and still retain paths and antialiasing. |
| 39 |
static void draw_huge_path(SkCanvas* canvas, int w, int h, bool manual) { |
| 40 |
SkAutoCanvasRestore acr(canvas, true); |
| 41 |
|
| 42 |
auto surf = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(w, h)); |
| 43 |
auto can = surf->getCanvas(); |
| 44 |
|
| 45 |
SkPaint paint; |
| 46 |
SkPath path = SkPath::RRect(SkRect::MakeXYWH(4, 4, w - 8, h - 8), 12, 12); |
| 47 |
|
| 48 |
canvas->save(); |
| 49 |
canvas->clipRect(SkRect::MakeXYWH(4, 4, 64, 64)); |
| 50 |
can->drawPath(path, paint); |
| 51 |
if (manual) { |
| 52 |
SkTiledImageUtils::DrawImage(canvas, surf->makeImageSnapshot(), 64 - w, 0); |
| 53 |
} else { |
| 54 |
canvas->drawImage(surf->makeImageSnapshot(), 64 - w, 0); |
| 55 |
} |
| 56 |
canvas->restore(); |
| 57 |
|
| 58 |
canvas->translate(80, 0); |
| 59 |
canvas->save(); |
| 60 |
canvas->clipRect(SkRect::MakeXYWH(4, 4, 64, 64)); |
| 61 |
can->clear(0); |
| 62 |
paint.setAntiAlias(true); |
| 63 |
can->drawPath(path, paint); |
| 64 |
if (manual) { |
| 65 |
SkTiledImageUtils::DrawImage(canvas, surf->makeImageSnapshot(), 64 - w, 0); |
| 66 |
} else { |
| 67 |
canvas->drawImage(surf->makeImageSnapshot(), 64 - w, 0); |
| 68 |
} |
| 69 |
canvas->restore(); |
| 70 |
} |
| 71 |
|
| 72 |
DEF_SIMPLE_GM(path_huge_aa, canvas, 200, 200) { |
| 73 |
draw_huge_path(canvas, 100, 60, /* manual= */ false); |
| 74 |
canvas->translate(0, 80); |
| 75 |
draw_huge_path(canvas, 100 * 1024, 60, /* manual= */ false); |
| 76 |
} |
| 77 |
|
| 78 |
DEF_SIMPLE_GM(path_huge_aa_manual, canvas, 200, 200) { |
| 79 |
draw_huge_path(canvas, 100, 60, /* manual= */ true); |
| 80 |
canvas->translate(0, 80); |
| 81 |
draw_huge_path(canvas, 100 * 1024, 60, /* manual= */ true); |
| 82 |
} |