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