Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2006 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 
      8 
      9 #include "SkScan.h"
     10 #include "SkBlitter.h"
     11 #include "SkRasterClip.h"
     12 
     13 #ifdef SK_NO_ANALYTIC_AA
     14     std::atomic<bool> gSkUseAnalyticAA{false};
     15 #else
     16     std::atomic<bool> gSkUseAnalyticAA{true};
     17 #endif
     18 
     19 std::atomic<bool> gSkForceAnalyticAA{false};
     20 
     21 static inline void blitrect(SkBlitter* blitter, const SkIRect& r) {
     22     blitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
     23 }
     24 
     25 void SkScan::FillIRect(const SkIRect& r, const SkRegion* clip,
     26                        SkBlitter* blitter) {
     27     if (!r.isEmpty()) {
     28         if (clip) {
     29             if (clip->isRect()) {
     30                 const SkIRect& clipBounds = clip->getBounds();
     31 
     32                 if (clipBounds.contains(r)) {
     33                     blitrect(blitter, r);
     34                 } else {
     35                     SkIRect rr = r;
     36                     if (rr.intersect(clipBounds)) {
     37                         blitrect(blitter, rr);
     38                     }
     39                 }
     40             } else {
     41                 SkRegion::Cliperator    cliper(*clip, r);
     42                 const SkIRect&          rr = cliper.rect();
     43 
     44                 while (!cliper.done()) {
     45                     blitrect(blitter, rr);
     46                     cliper.next();
     47                 }
     48             }
     49         } else {
     50             blitrect(blitter, r);
     51         }
     52     }
     53 }
     54 
     55 void SkScan::FillXRect(const SkXRect& xr, const SkRegion* clip,
     56                        SkBlitter* blitter) {
     57     SkIRect r;
     58 
     59     XRect_round(xr, &r);
     60     SkScan::FillIRect(r, clip, blitter);
     61 }
     62 
     63 void SkScan::FillRect(const SkRect& r, const SkRegion* clip,
     64                        SkBlitter* blitter) {
     65     SkIRect ir;
     66 
     67     r.round(&ir);
     68     SkScan::FillIRect(ir, clip, blitter);
     69 }
     70 
     71 ///////////////////////////////////////////////////////////////////////////////
     72 
     73 void SkScan::FillIRect(const SkIRect& r, const SkRasterClip& clip,
     74                        SkBlitter* blitter) {
     75     if (clip.isEmpty() || r.isEmpty()) {
     76         return;
     77     }
     78 
     79     if (clip.isBW()) {
     80         FillIRect(r, &clip.bwRgn(), blitter);
     81         return;
     82     }
     83 
     84     SkAAClipBlitterWrapper wrapper(clip, blitter);
     85     FillIRect(r, &wrapper.getRgn(), wrapper.getBlitter());
     86 }
     87 
     88 void SkScan::FillXRect(const SkXRect& xr, const SkRasterClip& clip,
     89                        SkBlitter* blitter) {
     90     if (clip.isEmpty() || xr.isEmpty()) {
     91         return;
     92     }
     93 
     94     if (clip.isBW()) {
     95         FillXRect(xr, &clip.bwRgn(), blitter);
     96         return;
     97     }
     98 
     99     SkAAClipBlitterWrapper wrapper(clip, blitter);
    100     FillXRect(xr, &wrapper.getRgn(), wrapper.getBlitter());
    101 }
    102 
    103 void SkScan::FillRect(const SkRect& r, const SkRasterClip& clip,
    104                       SkBlitter* blitter) {
    105     if (clip.isEmpty() || r.isEmpty()) {
    106         return;
    107     }
    108 
    109     if (clip.isBW()) {
    110         FillRect(r, &clip.bwRgn(), blitter);
    111         return;
    112     }
    113 
    114     SkAAClipBlitterWrapper wrapper(clip, blitter);
    115     FillRect(r, &wrapper.getRgn(), wrapper.getBlitter());
    116 }
    117