epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2006 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #include "SkScan.h" |
| 11 | #include "SkBlitter.h" |
reed@google.com | da96563 | 2011-10-13 15:29:01 +0000 | [diff] [blame] | 12 | #include "SkRasterClip.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | |
| 14 | static inline void blitrect(SkBlitter* blitter, const SkIRect& r) { |
| 15 | blitter->blitRect(r.fLeft, r.fTop, r.width(), r.height()); |
| 16 | } |
| 17 | |
| 18 | void SkScan::FillIRect(const SkIRect& r, const SkRegion* clip, |
| 19 | SkBlitter* blitter) { |
| 20 | if (!r.isEmpty()) { |
| 21 | if (clip) { |
| 22 | if (clip->isRect()) { |
| 23 | const SkIRect& clipBounds = clip->getBounds(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 24 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | if (clipBounds.contains(r)) { |
| 26 | blitrect(blitter, r); |
| 27 | } else { |
| 28 | SkIRect rr = r; |
| 29 | if (rr.intersect(clipBounds)) { |
| 30 | blitrect(blitter, rr); |
| 31 | } |
| 32 | } |
| 33 | } else { |
| 34 | SkRegion::Cliperator cliper(*clip, r); |
| 35 | const SkIRect& rr = cliper.rect(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 36 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | while (!cliper.done()) { |
| 38 | blitrect(blitter, rr); |
| 39 | cliper.next(); |
| 40 | } |
| 41 | } |
| 42 | } else { |
| 43 | blitrect(blitter, r); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void SkScan::FillXRect(const SkXRect& xr, const SkRegion* clip, |
| 49 | SkBlitter* blitter) { |
| 50 | SkIRect r; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 51 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | XRect_round(xr, &r); |
| 53 | SkScan::FillIRect(r, clip, blitter); |
| 54 | } |
| 55 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | void SkScan::FillRect(const SkRect& r, const SkRegion* clip, |
| 57 | SkBlitter* blitter) { |
| 58 | SkIRect ir; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 59 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 60 | r.round(&ir); |
| 61 | SkScan::FillIRect(ir, clip, blitter); |
| 62 | } |
| 63 | |
reed@google.com | da96563 | 2011-10-13 15:29:01 +0000 | [diff] [blame] | 64 | /////////////////////////////////////////////////////////////////////////////// |
| 65 | |
| 66 | void SkScan::FillIRect(const SkIRect& r, const SkRasterClip& clip, |
| 67 | SkBlitter* blitter) { |
| 68 | if (clip.isEmpty() || r.isEmpty()) { |
| 69 | return; |
| 70 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 71 | |
reed@google.com | da96563 | 2011-10-13 15:29:01 +0000 | [diff] [blame] | 72 | if (clip.isBW()) { |
| 73 | FillIRect(r, &clip.bwRgn(), blitter); |
| 74 | return; |
| 75 | } |
| 76 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 77 | SkAAClipBlitterWrapper wrapper(clip, blitter); |
| 78 | FillIRect(r, &wrapper.getRgn(), wrapper.getBlitter()); |
reed@google.com | da96563 | 2011-10-13 15:29:01 +0000 | [diff] [blame] | 79 | } |
| 80 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 81 | void SkScan::FillXRect(const SkXRect& xr, const SkRasterClip& clip, |
| 82 | SkBlitter* blitter) { |
| 83 | if (clip.isEmpty() || xr.isEmpty()) { |
| 84 | return; |
| 85 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 86 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 87 | if (clip.isBW()) { |
| 88 | FillXRect(xr, &clip.bwRgn(), blitter); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | SkAAClipBlitterWrapper wrapper(clip, blitter); |
| 93 | FillXRect(xr, &wrapper.getRgn(), wrapper.getBlitter()); |
| 94 | } |
| 95 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 96 | void SkScan::FillRect(const SkRect& r, const SkRasterClip& clip, |
| 97 | SkBlitter* blitter) { |
| 98 | if (clip.isEmpty() || r.isEmpty()) { |
| 99 | return; |
| 100 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 101 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 102 | if (clip.isBW()) { |
| 103 | FillRect(r, &clip.bwRgn(), blitter); |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | SkAAClipBlitterWrapper wrapper(clip, blitter); |
| 108 | FillRect(r, &wrapper.getRgn(), wrapper.getBlitter()); |
| 109 | } |