hugepath.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include "gm/gm.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkPaint.h"
  10. #include "include/core/SkPath.h"
  11. #include "include/core/SkRect.h"
  12. #include "include/core/SkRefCnt.h"
  13. #include "include/core/SkSurface.h"
  14. DEF_SIMPLE_GM(path_huge_crbug_800804, canvas, 50, 600) {
  15. SkPaint paint;
  16. paint.setAntiAlias(true);
  17. paint.setStyle(SkPaint::kStroke_Style);
  18. // exercise various special-cases (e.g. hairlines or not)
  19. const float widths[] = { 0.9f, 1.0f, 1.1f };
  20. SkPath path;
  21. for (float w : widths) {
  22. paint.setStrokeWidth(w);
  23. path.reset();
  24. path.moveTo(-1000,12345678901234567890.f);
  25. path.lineTo(10.5f,200);
  26. canvas->drawPath(path, paint);
  27. path.reset();
  28. path.moveTo(30.5f,400);
  29. path.lineTo(1000,-9.8765432109876543210e+19f);
  30. canvas->drawPath(path, paint);
  31. canvas->translate(3, 0);
  32. }
  33. }
  34. // Test that we can draw into a huge surface ( > 64K ) and still retain paths and antialiasing.
  35. DEF_SIMPLE_GM(path_huge_aa, canvas, 200, 200) {
  36. auto proc = [](SkCanvas* canvas, int w, int h) {
  37. SkAutoCanvasRestore acr(canvas, true);
  38. auto surf = SkSurface::MakeRasterN32Premul(w, h);
  39. auto can = surf->getCanvas();
  40. SkPaint paint;
  41. SkPath path;
  42. path.addRoundRect(SkRect::MakeXYWH(4, 4, w - 8, h - 8), 12, 12);
  43. canvas->save();
  44. canvas->clipRect(SkRect::MakeXYWH(4, 4, 64, 64));
  45. can->drawPath(path, paint);
  46. surf->draw(canvas, 64 - w, 0, nullptr);
  47. canvas->restore();
  48. canvas->translate(80, 0);
  49. canvas->save();
  50. canvas->clipRect(SkRect::MakeXYWH(4, 4, 64, 64));
  51. can->clear(0);
  52. paint.setAntiAlias(true);
  53. can->drawPath(path, paint);
  54. surf->draw(canvas, 64 - w, 0, nullptr);
  55. canvas->restore();
  56. };
  57. proc(canvas, 100, 60);
  58. canvas->translate(0, 80);
  59. proc(canvas, 100 * 1024, 60);
  60. }