OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkScanPriv.h" | 10 #include "SkScanPriv.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 | 102 |
103 /// Run-length-encoded supersampling antialiased blitter. | 103 /// Run-length-encoded supersampling antialiased blitter. |
104 class SuperBlitter : public BaseSuperBlitter { | 104 class SuperBlitter : public BaseSuperBlitter { |
105 public: | 105 public: |
106 SuperBlitter(SkBlitter* realBlitter, const SkIRect& ir, | 106 SuperBlitter(SkBlitter* realBlitter, const SkIRect& ir, |
107 const SkRegion& clip); | 107 const SkRegion& clip); |
108 | 108 |
109 virtual ~SuperBlitter() { | 109 virtual ~SuperBlitter() { |
110 this->flush(); | 110 this->flush(); |
111 sk_free(fRuns.fRuns); | 111 sk_free(fRunsBuffer); |
112 } | 112 } |
113 | 113 |
114 /// Once fRuns contains a complete supersampled row, flush() blits | 114 /// Once fRuns contains a complete supersampled row, flush() blits |
115 /// it out through the wrapped blitter. | 115 /// it out through the wrapped blitter. |
116 void flush(); | 116 void flush(); |
117 | 117 |
118 /// Blits a row of pixels, with location and width specified | 118 /// Blits a row of pixels, with location and width specified |
119 /// in supersampled coordinates. | 119 /// in supersampled coordinates. |
120 virtual void blitH(int x, int y, int width) SK_OVERRIDE; | 120 virtual void blitH(int x, int y, int width) SK_OVERRIDE; |
121 /// Blits a rectangle of pixels, with location and size specified | 121 /// Blits a rectangle of pixels, with location and size specified |
122 /// in supersampled coordinates. | 122 /// in supersampled coordinates. |
123 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; | 123 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; |
124 | 124 |
125 private: | 125 private: |
| 126 // The next three variables are used to track a circular buffer that |
| 127 // contains the values used in SkAlphaRuns. These variables should only |
| 128 // ever be updated in advanceRuns(), and fRuns should always point to |
| 129 // a valid SkAlphaRuns... |
| 130 int fRunsToBuffer; |
| 131 void* fRunsBuffer; |
| 132 int fCurrentRun; |
126 SkAlphaRuns fRuns; | 133 SkAlphaRuns fRuns; |
| 134 |
| 135 // extra one to store the zero at the end |
| 136 int getRunsSz() const { return (fWidth + 1 + (fWidth + 2)/2) * sizeof(int16_
t); } |
| 137 |
| 138 // This function updates the fRuns variable to point to the next buffer spac
e |
| 139 // with adequate storage for a SkAlphaRuns. It mostly just advances fCurrent
Run |
| 140 // and resets fRuns to point to an empty scanline. |
| 141 void advanceRuns() { |
| 142 const size_t kRunsSz = this->getRunsSz(); |
| 143 fCurrentRun = (fCurrentRun + 1) % fRunsToBuffer; |
| 144 fRuns.fRuns = reinterpret_cast<int16_t*>( |
| 145 reinterpret_cast<uint8_t*>(fRunsBuffer) + fCurrentRun * kRunsSz); |
| 146 fRuns.fAlpha = reinterpret_cast<SkAlpha*>(fRuns.fRuns + fWidth + 1); |
| 147 fRuns.reset(fWidth); |
| 148 } |
| 149 |
127 int fOffsetX; | 150 int fOffsetX; |
128 }; | 151 }; |
129 | 152 |
130 SuperBlitter::SuperBlitter(SkBlitter* realBlitter, const SkIRect& ir, | 153 SuperBlitter::SuperBlitter(SkBlitter* realBlitter, const SkIRect& ir, |
131 const SkRegion& clip) | 154 const SkRegion& clip) |
132 : BaseSuperBlitter(realBlitter, ir, clip) { | 155 : BaseSuperBlitter(realBlitter, ir, clip) { |
133 const int width = fWidth; | 156 fRunsToBuffer = realBlitter->requestRowsPreserved(); |
| 157 fRunsBuffer = sk_malloc_throw(fRunsToBuffer * this->getRunsSz()); |
| 158 fCurrentRun = -1; |
134 | 159 |
135 // extra one to store the zero at the end | 160 this->advanceRuns(); |
136 fRuns.fRuns = (int16_t*)sk_malloc_throw((width + 1 + (width + 2)/2) * sizeof
(int16_t)); | |
137 fRuns.fAlpha = (uint8_t*)(fRuns.fRuns + width + 1); | |
138 fRuns.reset(width); | |
139 | 161 |
140 fOffsetX = 0; | 162 fOffsetX = 0; |
141 } | 163 } |
142 | 164 |
143 void SuperBlitter::flush() { | 165 void SuperBlitter::flush() { |
144 if (fCurrIY >= fTop) { | 166 if (fCurrIY >= fTop) { |
| 167 |
| 168 SkASSERT(fCurrentRun < fRunsToBuffer); |
145 if (!fRuns.empty()) { | 169 if (!fRuns.empty()) { |
146 // SkDEBUGCODE(fRuns.dump();) | 170 // SkDEBUGCODE(fRuns.dump();) |
147 fRealBlitter->blitAntiH(fLeft, fCurrIY, fRuns.fAlpha, fRuns.fRuns); | 171 fRealBlitter->blitAntiH(fLeft, fCurrIY, fRuns.fAlpha, fRuns.fRuns); |
148 fRuns.reset(fWidth); | 172 this->advanceRuns(); |
149 fOffsetX = 0; | 173 fOffsetX = 0; |
150 } | 174 } |
| 175 |
151 fCurrIY = fTop - 1; | 176 fCurrIY = fTop - 1; |
152 SkDEBUGCODE(fCurrX = -1;) | 177 SkDEBUGCODE(fCurrX = -1;) |
153 } | 178 } |
154 } | 179 } |
155 | 180 |
156 /** coverage_to_partial_alpha() is being used by SkAlphaRuns, which | 181 /** coverage_to_partial_alpha() is being used by SkAlphaRuns, which |
157 *accumulates* SCALE pixels worth of "alpha" in [0,(256/SCALE)] | 182 *accumulates* SCALE pixels worth of "alpha" in [0,(256/SCALE)] |
158 to produce a final value in [0, 255] and handles clamping 256->255 | 183 to produce a final value in [0, 255] and handles clamping 256->255 |
159 itself, with the same (alpha - (alpha >> 8)) correction as | 184 itself, with the same (alpha - (alpha >> 8)) correction as |
160 coverage_to_exact_alpha(). | 185 coverage_to_exact_alpha(). |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 AntiFillPath(path, clip.bwRgn(), blitter); | 757 AntiFillPath(path, clip.bwRgn(), blitter); |
733 } else { | 758 } else { |
734 SkRegion tmp; | 759 SkRegion tmp; |
735 SkAAClipBlitter aaBlitter; | 760 SkAAClipBlitter aaBlitter; |
736 | 761 |
737 tmp.setRect(clip.getBounds()); | 762 tmp.setRect(clip.getBounds()); |
738 aaBlitter.init(blitter, &clip.aaRgn()); | 763 aaBlitter.init(blitter, &clip.aaRgn()); |
739 SkScan::AntiFillPath(path, tmp, &aaBlitter, true); | 764 SkScan::AntiFillPath(path, tmp, &aaBlitter, true); |
740 } | 765 } |
741 } | 766 } |
OLD | NEW |