daa.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/SkColor.h"
  10. #include "include/core/SkFont.h"
  11. #include "include/core/SkPaint.h"
  12. #include "include/core/SkPath.h"
  13. #include "include/core/SkPoint.h"
  14. #include "include/core/SkTypes.h"
  15. // This GM shows off a flaw in delta-based rasterizers (DAA, CCPR, etc.).
  16. // See also the bottom of dashing4 and skia:6886.
  17. static const int K = 49;
  18. DEF_SIMPLE_GM(daa, canvas, K+350, 5*K) {
  19. SkPaint paint;
  20. paint.setAntiAlias(true);
  21. {
  22. paint.setColor(SK_ColorBLACK);
  23. canvas->drawString("Should be a green square with no red showing through.",
  24. K*1.5f, K*0.5f, SkFont(), paint);
  25. paint.setColor(SK_ColorRED);
  26. canvas->drawRect({0,0,K,K}, paint);
  27. SkPath path;
  28. SkPoint tri1[] = {{0,0},{K,K},{0,K},{0,0}};
  29. SkPoint tri2[] = {{0,0},{K,K},{K,0},{0,0}};
  30. path.addPoly(tri1, SK_ARRAY_COUNT(tri1), false);
  31. path.addPoly(tri2, SK_ARRAY_COUNT(tri2), false);
  32. paint.setColor(SK_ColorGREEN);
  33. canvas->drawPath(path, paint);
  34. }
  35. canvas->translate(0,K);
  36. {
  37. paint.setColor(SK_ColorBLACK);
  38. canvas->drawString("Adjacent rects, two draws. Blue then green, no red?",
  39. K*1.5f, K*0.5f, SkFont(), paint);
  40. paint.setColor(SK_ColorRED);
  41. canvas->drawRect({0,0,K,K}, paint);
  42. {
  43. SkPath path;
  44. SkPoint rect1[] = {{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}};
  45. path.addPoly(rect1, SK_ARRAY_COUNT(rect1), false);
  46. paint.setColor(SK_ColorBLUE);
  47. canvas->drawPath(path, paint);
  48. }
  49. {
  50. SkPath path;
  51. SkPoint rect2[] = {{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}};
  52. path.addPoly(rect2, SK_ARRAY_COUNT(rect2), false);
  53. paint.setColor(SK_ColorGREEN);
  54. canvas->drawPath(path, paint);
  55. }
  56. }
  57. canvas->translate(0,K);
  58. {
  59. paint.setColor(SK_ColorBLACK);
  60. canvas->drawString("Adjacent rects, wound together. All green?",
  61. K*1.5f, K*0.5f, SkFont(), paint);
  62. paint.setColor(SK_ColorRED);
  63. canvas->drawRect({0,0,K,K}, paint);
  64. {
  65. SkPath path;
  66. SkPoint rect1[] = {{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}};
  67. SkPoint rect2[] = {{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}};
  68. path.addPoly(rect1, SK_ARRAY_COUNT(rect1), false);
  69. path.addPoly(rect2, SK_ARRAY_COUNT(rect2), false);
  70. paint.setColor(SK_ColorGREEN);
  71. canvas->drawPath(path, paint);
  72. }
  73. }
  74. canvas->translate(0,K);
  75. {
  76. paint.setColor(SK_ColorBLACK);
  77. canvas->drawString("Adjacent rects, wound opposite. All green?",
  78. K*1.5f, K*0.5f, SkFont(), paint);
  79. paint.setColor(SK_ColorRED);
  80. canvas->drawRect({0,0,K,K}, paint);
  81. {
  82. SkPath path;
  83. SkPoint rect1[] = {{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}};
  84. SkPoint rect2[] = {{K*0.5f,0},{K,0},{K,K},{K*0.5f,K}};
  85. path.addPoly(rect1, SK_ARRAY_COUNT(rect1), false);
  86. path.addPoly(rect2, SK_ARRAY_COUNT(rect2), false);
  87. paint.setColor(SK_ColorGREEN);
  88. canvas->drawPath(path, paint);
  89. }
  90. }
  91. canvas->translate(0,K);
  92. {
  93. paint.setColor(SK_ColorBLACK);
  94. canvas->drawString("One poly, wound opposite. All green?",
  95. K*1.5f, K*0.5f, SkFont(), paint);
  96. paint.setColor(SK_ColorRED);
  97. canvas->drawRect({0,0,K,K}, paint);
  98. {
  99. SkPath path;
  100. SkPoint poly[] = {{K*0.5f,0},{0,0},{0,K},{K*0.5f,K},{K*0.5f,0},{K,0},{K,K},{K*0.5f,K}};
  101. path.addPoly(poly, SK_ARRAY_COUNT(poly), false);
  102. paint.setColor(SK_ColorGREEN);
  103. canvas->drawPath(path, paint);
  104. }
  105. }
  106. }