Home | History | Annotate | Download | only in core
      1 /* libs/graphics/sgl/SkScan.h
      2 **
      3 ** Copyright 2006, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #ifndef SkScan_DEFINED
     19 #define SkScan_DEFINED
     20 
     21 #include "SkRect.h"
     22 
     23 class SkRegion;
     24 class SkBlitter;
     25 class SkPath;
     26 
     27 /** Defines a fixed-point rectangle, identical to the integer SkIRect, but its
     28     coordinates are treated as SkFixed rather than int32_t.
     29 */
     30 typedef SkIRect SkXRect;
     31 
     32 class SkScan {
     33 public:
     34     static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
     35     static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
     36 
     37 #ifdef SK_SCALAR_IS_FIXED
     38     static void FillRect(const SkRect& rect, const SkRegion* clip,
     39                          SkBlitter* blitter) {
     40         SkScan::FillXRect(*(const SkXRect*)&rect, clip, blitter);
     41     }
     42 #else
     43     static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
     44 #endif
     45 
     46     static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
     47     static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
     48 
     49     static void FillTriangle(const SkPoint& a, const SkPoint& b,
     50                              const SkPoint& c, const SkRegion* clip,
     51                              SkBlitter* blitter) {
     52         SkPoint pts[3];
     53         pts[0] = a;
     54         pts[1] = b;
     55         pts[2] = c;
     56         FillTriangle(pts, clip, blitter);
     57     }
     58 
     59     static void HairLine(const SkPoint&, const SkPoint&, const SkRegion* clip, SkBlitter*);
     60     static void HairRect(const SkRect&, const SkRegion* clip, SkBlitter*);
     61     static void HairPath(const SkPath&, const SkRegion* clip, SkBlitter*);
     62 
     63     static void FrameRect(const SkRect&, SkScalar width, const SkRegion* clip, SkBlitter*);
     64 
     65     static void AntiFillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
     66 #ifdef SK_SCALAR_IS_FIXED
     67     static void AntiFillRect(const SkRect& rect, const SkRegion* clip,
     68                          SkBlitter* blitter) {
     69         SkScan::AntiFillXRect(*(const SkXRect*)&rect, clip, blitter);
     70     }
     71 #else
     72     static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
     73 #endif
     74 
     75     static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
     76 
     77     static void AntiHairLine(const SkPoint&, const SkPoint&, const SkRegion* clip, SkBlitter*);
     78     static void AntiHairRect(const SkRect&, const SkRegion* clip, SkBlitter*);
     79     static void AntiHairPath(const SkPath&, const SkRegion* clip, SkBlitter*);
     80 };
     81 
     82 /** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates
     83     from int to SkFixed. Does not check for overflow if the src coordinates
     84     exceed 32K
     85 */
     86 static inline void XRect_set(SkXRect* xr, const SkIRect& src) {
     87     xr->fLeft = SkIntToFixed(src.fLeft);
     88     xr->fTop = SkIntToFixed(src.fTop);
     89     xr->fRight = SkIntToFixed(src.fRight);
     90     xr->fBottom = SkIntToFixed(src.fBottom);
     91 }
     92 
     93 /** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates
     94     from SkScalar to SkFixed. Does not check for overflow if the src coordinates
     95     exceed 32K
     96 */
     97 static inline void XRect_set(SkXRect* xr, const SkRect& src) {
     98     xr->fLeft = SkScalarToFixed(src.fLeft);
     99     xr->fTop = SkScalarToFixed(src.fTop);
    100     xr->fRight = SkScalarToFixed(src.fRight);
    101     xr->fBottom = SkScalarToFixed(src.fBottom);
    102 }
    103 
    104 /** Round the SkXRect coordinates, and store the result in the SkIRect.
    105 */
    106 static inline void XRect_round(const SkXRect& xr, SkIRect* dst) {
    107     dst->fLeft = SkFixedRound(xr.fLeft);
    108     dst->fTop = SkFixedRound(xr.fTop);
    109     dst->fRight = SkFixedRound(xr.fRight);
    110     dst->fBottom = SkFixedRound(xr.fBottom);
    111 }
    112 
    113 /** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling
    114     for right/bottom), and store the result in the SkIRect.
    115 */
    116 static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) {
    117     dst->fLeft = SkFixedFloor(xr.fLeft);
    118     dst->fTop = SkFixedFloor(xr.fTop);
    119     dst->fRight = SkFixedCeil(xr.fRight);
    120     dst->fBottom = SkFixedCeil(xr.fBottom);
    121 }
    122 
    123 #endif
    124