SkScan.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright 2011 The Android Open Source Project
  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. #ifndef SkScan_DEFINED
  8. #define SkScan_DEFINED
  9. #include "include/core/SkRect.h"
  10. #include "include/private/SkFixed.h"
  11. #include <atomic>
  12. class SkRasterClip;
  13. class SkRegion;
  14. class SkBlitter;
  15. class SkPath;
  16. /** Defines a fixed-point rectangle, identical to the integer SkIRect, but its
  17. coordinates are treated as SkFixed rather than int32_t.
  18. */
  19. typedef SkIRect SkXRect;
  20. extern std::atomic<bool> gSkUseAnalyticAA;
  21. extern std::atomic<bool> gSkForceAnalyticAA;
  22. class AdditiveBlitter;
  23. class SkScan {
  24. public:
  25. /*
  26. * Draws count-1 line segments, one at a time:
  27. * line(pts[0], pts[1])
  28. * line(pts[1], pts[2])
  29. * line(......, pts[count - 1])
  30. */
  31. typedef void (*HairRgnProc)(const SkPoint[], int count, const SkRegion*, SkBlitter*);
  32. typedef void (*HairRCProc)(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
  33. static void FillPath(const SkPath&, const SkIRect&, SkBlitter*);
  34. ///////////////////////////////////////////////////////////////////////////
  35. // rasterclip
  36. static void FillIRect(const SkIRect&, const SkRasterClip&, SkBlitter*);
  37. static void FillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
  38. static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
  39. static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
  40. static void AntiFillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
  41. static void FillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
  42. static void AntiFillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
  43. static void FrameRect(const SkRect&, const SkPoint& strokeSize,
  44. const SkRasterClip&, SkBlitter*);
  45. static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
  46. const SkRasterClip&, SkBlitter*);
  47. static void FillTriangle(const SkPoint pts[], const SkRasterClip&, SkBlitter*);
  48. static void HairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
  49. static void AntiHairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
  50. static void HairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
  51. static void AntiHairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
  52. static void HairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
  53. static void AntiHairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
  54. static void HairSquarePath(const SkPath&, const SkRasterClip&, SkBlitter*);
  55. static void AntiHairSquarePath(const SkPath&, const SkRasterClip&, SkBlitter*);
  56. static void HairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
  57. static void AntiHairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
  58. // Needed by do_fill_path in SkScanPriv.h
  59. static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
  60. private:
  61. friend class SkAAClip;
  62. friend class SkRegion;
  63. static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
  64. static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
  65. static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
  66. static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
  67. static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*);
  68. static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*, bool forceRLE);
  69. static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
  70. static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
  71. const SkRegion*, SkBlitter*);
  72. static void HairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
  73. static void AntiHairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
  74. static void AAAFillPath(const SkPath& path, SkBlitter* blitter, const SkIRect& pathIR,
  75. const SkIRect& clipBounds, bool forceRLE);
  76. static void SAAFillPath(const SkPath& path, SkBlitter* blitter, const SkIRect& pathIR,
  77. const SkIRect& clipBounds, bool forceRLE);
  78. };
  79. /** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates
  80. from int to SkFixed. Does not check for overflow if the src coordinates
  81. exceed 32K
  82. */
  83. static inline void XRect_set(SkXRect* xr, const SkIRect& src) {
  84. xr->fLeft = SkIntToFixed(src.fLeft);
  85. xr->fTop = SkIntToFixed(src.fTop);
  86. xr->fRight = SkIntToFixed(src.fRight);
  87. xr->fBottom = SkIntToFixed(src.fBottom);
  88. }
  89. /** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates
  90. from SkScalar to SkFixed. Does not check for overflow if the src coordinates
  91. exceed 32K
  92. */
  93. static inline void XRect_set(SkXRect* xr, const SkRect& src) {
  94. xr->fLeft = SkScalarToFixed(src.fLeft);
  95. xr->fTop = SkScalarToFixed(src.fTop);
  96. xr->fRight = SkScalarToFixed(src.fRight);
  97. xr->fBottom = SkScalarToFixed(src.fBottom);
  98. }
  99. /** Round the SkXRect coordinates, and store the result in the SkIRect.
  100. */
  101. static inline void XRect_round(const SkXRect& xr, SkIRect* dst) {
  102. dst->fLeft = SkFixedRoundToInt(xr.fLeft);
  103. dst->fTop = SkFixedRoundToInt(xr.fTop);
  104. dst->fRight = SkFixedRoundToInt(xr.fRight);
  105. dst->fBottom = SkFixedRoundToInt(xr.fBottom);
  106. }
  107. /** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling
  108. for right/bottom), and store the result in the SkIRect.
  109. */
  110. static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) {
  111. dst->fLeft = SkFixedFloorToInt(xr.fLeft);
  112. dst->fTop = SkFixedFloorToInt(xr.fTop);
  113. dst->fRight = SkFixedCeilToInt(xr.fRight);
  114. dst->fBottom = SkFixedCeilToInt(xr.fBottom);
  115. }
  116. #endif