| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #ifndef SkAntiRun_DEFINED | 9 #ifndef SkAntiRun_DEFINED |
| 10 #define SkAntiRun_DEFINED | 10 #define SkAntiRun_DEFINED |
| 11 | 11 |
| 12 #include "SkBlitter.h" | 12 #include "SkBlitter.h" |
| 13 | 13 |
| 14 /** Sparse array of run-length-encoded alpha (supersampling coverage) values. | 14 /** Sparse array of run-length-encoded alpha (supersampling coverage) values. |
| 15 Sparseness allows us to independently compose several paths into the | 15 Sparseness allows us to independently compose several paths into the |
| 16 same SkAlphaRuns buffer. | 16 same SkAlphaRuns buffer. |
| 17 */ | 17 */ |
| 18 | 18 |
| 19 class SkAlphaRuns { | 19 class SkAlphaRuns { |
| 20 public: | 20 public: |
| 21 int16_t* fRuns; | 21 int16_t* fRuns; |
| 22 uint8_t* fAlpha; | 22 uint8_t* fAlpha; |
| 23 | 23 |
| 24 // Return 0-255 given 0-256 |
| 25 static inline SkAlpha CatchOverflow(int alpha) { |
| 26 return alpha - (alpha >> 8); |
| 27 } |
| 28 |
| 24 /// Returns true if the scanline contains only a single run, | 29 /// Returns true if the scanline contains only a single run, |
| 25 /// of alpha value 0. | 30 /// of alpha value 0. |
| 26 bool empty() const { | 31 bool empty() const { |
| 27 SkASSERT(fRuns[0] > 0); | 32 SkASSERT(fRuns[0] > 0); |
| 28 return fAlpha[0] == 0 && fRuns[fRuns[0]] == 0; | 33 return fAlpha[0] == 0 && fRuns[fRuns[0]] == 0; |
| 29 } | 34 } |
| 30 | 35 |
| 31 /// Reinitialize for a new scanline. | 36 /// Reinitialize for a new scanline. |
| 32 void reset(int width); | 37 void reset(int width); |
| 33 | 38 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 x = 0; | 77 x = 0; |
| 73 SkDEBUGCODE(this->validate();) | 78 SkDEBUGCODE(this->validate();) |
| 74 } | 79 } |
| 75 | 80 |
| 76 if (middleCount) { | 81 if (middleCount) { |
| 77 SkAlphaRuns::Break(runs, alpha, x, middleCount); | 82 SkAlphaRuns::Break(runs, alpha, x, middleCount); |
| 78 alpha += x; | 83 alpha += x; |
| 79 runs += x; | 84 runs += x; |
| 80 x = 0; | 85 x = 0; |
| 81 do { | 86 do { |
| 82 alpha[0] = SkToU8(alpha[0] + maxValue); | 87 alpha[0] = SkToU8(CatchOverflow(alpha[0] + maxValue)); |
| 83 int n = runs[0]; | 88 int n = runs[0]; |
| 84 SkASSERT(n <= middleCount); | 89 SkASSERT(n <= middleCount); |
| 85 alpha += n; | 90 alpha += n; |
| 86 runs += n; | 91 runs += n; |
| 87 middleCount -= n; | 92 middleCount -= n; |
| 88 } while (middleCount > 0); | 93 } while (middleCount > 0); |
| 89 SkDEBUGCODE(this->validate();) | 94 SkDEBUGCODE(this->validate();) |
| 90 lastAlpha = alpha; | 95 lastAlpha = alpha; |
| 91 } | 96 } |
| 92 | 97 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 x -= n; | 186 x -= n; |
| 182 } | 187 } |
| 183 } | 188 } |
| 184 | 189 |
| 185 private: | 190 private: |
| 186 SkDEBUGCODE(int fWidth;) | 191 SkDEBUGCODE(int fWidth;) |
| 187 SkDEBUGCODE(void validate() const;) | 192 SkDEBUGCODE(void validate() const;) |
| 188 }; | 193 }; |
| 189 | 194 |
| 190 #endif | 195 #endif |
| OLD | NEW |