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 15class SkRasterClip; 16class SkRegion; 17class SkBlitter; 18class 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*/ 23typedef SkIRect SkXRect; 24 25class SkScan { 26public: 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#ifdef SK_SCALAR_IS_FIXED 35 static void FillRect(const SkRect& rect, const SkRasterClip& clip, 36 SkBlitter* blitter) { 37 SkScan::FillXRect(*(const SkXRect*)&rect, clip, blitter); 38 } 39 static void AntiFillRect(const SkRect& rect, const SkRasterClip& clip, 40 SkBlitter* blitter) { 41 SkScan::AntiFillXRect(*(const SkXRect*)&rect, clip, blitter); 42 } 43#else 44 static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*); 45 static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*); 46#endif 47 static void AntiFillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*); 48 static void FillPath(const SkPath&, const SkRasterClip&, SkBlitter*); 49 static void AntiFillPath(const SkPath&, const SkRasterClip&, SkBlitter*); 50 static void FrameRect(const SkRect&, const SkPoint& strokeSize, 51 const SkRasterClip&, SkBlitter*); 52 static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize, 53 const SkRasterClip&, SkBlitter*); 54 static void FillTriangle(const SkPoint pts[], const SkRasterClip&, SkBlitter*); 55 static void HairLine(const SkPoint&, const SkPoint&, const SkRasterClip&, 56 SkBlitter*); 57 static void AntiHairLine(const SkPoint&, const SkPoint&, const SkRasterClip&, 58 SkBlitter*); 59 static void HairRect(const SkRect&, const SkRasterClip&, SkBlitter*); 60 static void AntiHairRect(const SkRect&, const SkRasterClip&, SkBlitter*); 61 static void HairPath(const SkPath&, const SkRasterClip&, SkBlitter*); 62 static void AntiHairPath(const SkPath&, const SkRasterClip&, SkBlitter*); 63 64private: 65 friend class SkAAClip; 66 friend class SkRegion; 67 68 static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*); 69 static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*); 70#ifdef SK_SCALAR_IS_FIXED 71 static void FillRect(const SkRect& rect, const SkRegion* clip, 72 SkBlitter* blitter) { 73 SkScan::FillXRect(*(const SkXRect*)&rect, clip, blitter); 74 } 75 static void AntiFillRect(const SkRect& rect, const SkRegion* clip, 76 SkBlitter* blitter) { 77 SkScan::AntiFillXRect(*(const SkXRect*)&rect, clip, blitter); 78 } 79#else 80 static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*); 81 static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*); 82#endif 83 static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*); 84 static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*); 85 static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*, 86 bool forceRLE = false); 87 static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*); 88 89 static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize, 90 const SkRegion*, SkBlitter*); 91 static void HairLineRgn(const SkPoint&, const SkPoint&, const SkRegion*, 92 SkBlitter*); 93 static void AntiHairLineRgn(const SkPoint&, const SkPoint&, const SkRegion*, 94 SkBlitter*); 95}; 96 97/** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates 98 from int to SkFixed. Does not check for overflow if the src coordinates 99 exceed 32K 100*/ 101static inline void XRect_set(SkXRect* xr, const SkIRect& src) { 102 xr->fLeft = SkIntToFixed(src.fLeft); 103 xr->fTop = SkIntToFixed(src.fTop); 104 xr->fRight = SkIntToFixed(src.fRight); 105 xr->fBottom = SkIntToFixed(src.fBottom); 106} 107 108/** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates 109 from SkScalar to SkFixed. Does not check for overflow if the src coordinates 110 exceed 32K 111*/ 112static inline void XRect_set(SkXRect* xr, const SkRect& src) { 113 xr->fLeft = SkScalarToFixed(src.fLeft); 114 xr->fTop = SkScalarToFixed(src.fTop); 115 xr->fRight = SkScalarToFixed(src.fRight); 116 xr->fBottom = SkScalarToFixed(src.fBottom); 117} 118 119/** Round the SkXRect coordinates, and store the result in the SkIRect. 120*/ 121static inline void XRect_round(const SkXRect& xr, SkIRect* dst) { 122 dst->fLeft = SkFixedRound(xr.fLeft); 123 dst->fTop = SkFixedRound(xr.fTop); 124 dst->fRight = SkFixedRound(xr.fRight); 125 dst->fBottom = SkFixedRound(xr.fBottom); 126} 127 128/** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling 129 for right/bottom), and store the result in the SkIRect. 130*/ 131static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) { 132 dst->fLeft = SkFixedFloor(xr.fLeft); 133 dst->fTop = SkFixedFloor(xr.fTop); 134 dst->fRight = SkFixedCeil(xr.fRight); 135 dst->fBottom = SkFixedCeil(xr.fBottom); 136} 137 138#endif 139