labrynth.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright 2019 Google LLC.
  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/SkPath.h"
  10. #include "include/core/SkPaint.h"
  11. /**
  12. * Repro case for https://bugs.chromium.org/p/chromium/issues/detail?id=913223
  13. *
  14. * The original bug was filed against square caps, but here we also draw the labyrinth using round
  15. * and butt caps.
  16. *
  17. * Square and round caps expose over-coverage on overlaps when using coverage counting.
  18. *
  19. * Butt caps expose under-coverage on abutted strokes when using a 'max()' coverage function.
  20. */
  21. static void draw_labyrinth(SkCanvas* canvas, SkPaint::Cap cap) {
  22. constexpr static bool kRows[11][12] = {
  23. {1,1,1,1,1,1,1,1,1,1,1,1},
  24. {0,1,0,1,0,1,0,0,0,0,1,1},
  25. {0,0,0,0,1,0,0,0,0,1,1,1},
  26. {1,0,1,0,0,0,0,1,0,0,0,0},
  27. {0,1,1,0,0,0,0,0,0,1,1,1},
  28. {1,0,0,1,0,0,0,0,1,1,1,0},
  29. {0,1,0,1,1,1,0,0,1,1,1,0},
  30. {1,0,1,0,1,1,1,1,0,1,1,1},
  31. {0,0,1,0,0,1,0,0,0,0,0,1},
  32. {0,1,1,1,0,0,1,1,1,1,0,0},
  33. {1,1,1,1,1,1,1,1,1,1,1,1},
  34. };
  35. constexpr static bool kCols[13][10] = {
  36. {1,1,1,1,0,1,1,1,1,1},
  37. {0,0,1,0,0,0,1,1,1,0},
  38. {0,1,1,0,1,1,1,0,0,1},
  39. {1,1,0,0,0,0,1,0,1,0},
  40. {0,0,1,0,1,0,0,0,0,1},
  41. {0,0,1,1,1,0,0,0,1,0},
  42. {0,1,0,1,1,1,0,0,0,0},
  43. {1,1,1,0,1,1,1,0,1,0},
  44. {1,1,0,1,1,0,0,0,1,0},
  45. {0,0,1,0,0,0,0,0,0,1},
  46. {0,0,1,1,0,0,0,0,1,0},
  47. {0,0,0,0,0,0,1,0,0,1},
  48. {1,1,1,1,1,1,0,1,1,1},
  49. };
  50. SkPath maze;
  51. for (size_t y = 0; y < SK_ARRAY_COUNT(kRows); ++y) {
  52. for (size_t x = 0; x < SK_ARRAY_COUNT(kRows[0]); ++x) {
  53. if (kRows[y][x]) {
  54. maze.moveTo(x, y);
  55. maze.lineTo(x+1, y);
  56. }
  57. }
  58. }
  59. for (size_t x = 0; x < SK_ARRAY_COUNT(kCols); ++x) {
  60. for (size_t y = 0; y < SK_ARRAY_COUNT(kCols[0]); ++y) {
  61. if (kCols[x][y]) {
  62. maze.moveTo(x, y);
  63. maze.lineTo(x, y+1);
  64. }
  65. }
  66. }
  67. SkPaint paint;
  68. paint.setStyle(SkPaint::kStroke_Style);
  69. paint.setStrokeWidth(.1f);
  70. paint.setColor(0xff406060);
  71. paint.setAntiAlias(true);
  72. paint.setStrokeCap(cap);
  73. canvas->translate(10.5, 10.5);
  74. canvas->scale(40, 40);
  75. canvas->drawPath(maze, paint);
  76. }
  77. constexpr static int kWidth = 500;
  78. constexpr static int kHeight = 420;
  79. DEF_SIMPLE_GM(labyrinth_square, canvas, kWidth, kHeight) {
  80. draw_labyrinth(canvas, SkPaint::kSquare_Cap);
  81. }
  82. DEF_SIMPLE_GM(labyrinth_round, canvas, kWidth, kHeight) {
  83. draw_labyrinth(canvas, SkPaint::kRound_Cap);
  84. }
  85. DEF_SIMPLE_GM(labyrinth_butt, canvas, kWidth, kHeight) {
  86. draw_labyrinth(canvas, SkPaint::kButt_Cap);
  87. }