| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The Android Open Source Project | 2 * Copyright 2016 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 #include "SkAntiRun.h" | 8 #include "SkAntiRun.h" |
| 9 #include "SkBlitter.h" | 9 #include "SkBlitter.h" |
| 10 #include "SkEdge.h" | 10 #include "SkEdge.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 In summary, our algorithm has a higher quality because it generates ground- | 76 In summary, our algorithm has a higher quality because it generates ground- |
| 77 truth coverages analytically. It is also faster because it has much fewer | 77 truth coverages analytically. It is also faster because it has much fewer |
| 78 unnessasary horizontal scan lines. For example, given a triangle path, the | 78 unnessasary horizontal scan lines. For example, given a triangle path, the |
| 79 number of scan lines in our algorithm is only about 3 + H while the | 79 number of scan lines in our algorithm is only about 3 + H while the |
| 80 16-supersampling algorithm has about 4H scan lines. | 80 16-supersampling algorithm has about 4H scan lines. |
| 81 | 81 |
| 82 */ | 82 */ |
| 83 | 83 |
| 84 /////////////////////////////////////////////////////////////////////////////// | 84 /////////////////////////////////////////////////////////////////////////////// |
| 85 | 85 |
| 86 inline void addAlpha(SkAlpha& alpha, SkAlpha delta) { | 86 static inline void addAlpha(SkAlpha& alpha, SkAlpha delta) { |
| 87 SkASSERT(alpha + (int)delta <= 0xFF); | 87 SkASSERT(alpha + (int)delta <= 256); |
| 88 alpha += delta; | 88 alpha = SkAlphaRuns::CatchOverflow(alpha + (int)delta); |
| 89 } | 89 } |
| 90 | 90 |
| 91 class AdditiveBlitter : public SkBlitter { | 91 class AdditiveBlitter : public SkBlitter { |
| 92 public: | 92 public: |
| 93 virtual ~AdditiveBlitter() {} | 93 virtual ~AdditiveBlitter() {} |
| 94 | 94 |
| 95 virtual SkBlitter* getRealBlitter(bool forceRealBlitter = false) = 0; | 95 virtual SkBlitter* getRealBlitter(bool forceRealBlitter = false) = 0; |
| 96 | 96 |
| 97 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], int len) = 0
; | 97 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], int len) = 0
; |
| 98 virtual void blitAntiH(int x, int y, const SkAlpha alpha) = 0; | 98 virtual void blitAntiH(int x, int y, const SkAlpha alpha) = 0; |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 // return ((((a >> 8) * (a >> 8)) >> 8) * (b >> 8)) >> 1; | 474 // return ((((a >> 8) * (a >> 8)) >> 8) * (b >> 8)) >> 1; |
| 475 return (a >> 11) * (a >> 11) * (b >> 11); | 475 return (a >> 11) * (a >> 11) * (b >> 11); |
| 476 } | 476 } |
| 477 | 477 |
| 478 // The alpha of right-triangle (a, a*b) | 478 // The alpha of right-triangle (a, a*b) |
| 479 static inline SkAlpha partialTriangleToAlpha(SkFixed a, SkFixed b) { | 479 static inline SkAlpha partialTriangleToAlpha(SkFixed a, SkFixed b) { |
| 480 return partialTriangleToAlpha16(a, b) >> 8; | 480 return partialTriangleToAlpha16(a, b) >> 8; |
| 481 } | 481 } |
| 482 | 482 |
| 483 static inline SkAlpha getPartialAlpha(SkAlpha alpha, SkFixed partialHeight) { | 483 static inline SkAlpha getPartialAlpha(SkAlpha alpha, SkFixed partialHeight) { |
| 484 return (alpha * partialHeight) >> 16; | 484 return (alpha * partialHeight + SK_FixedHalf) >> 16; |
| 485 } | 485 } |
| 486 | 486 |
| 487 static inline SkAlpha getPartialAlpha(SkAlpha alpha, SkAlpha fullAlpha) { | 487 static inline SkAlpha getPartialAlpha(SkAlpha alpha, SkAlpha fullAlpha) { |
| 488 return ((uint16_t)alpha * fullAlpha) >> 8; | 488 return ((uint16_t)alpha * fullAlpha) >> 8; |
| 489 } | 489 } |
| 490 | 490 |
| 491 // For SkFixed that's close to SK_Fixed1, we can't convert it to alpha by just s
hifting right. | 491 // For SkFixed that's close to SK_Fixed1, we can't convert it to alpha by just s
hifting right. |
| 492 // For example, when f = SK_Fixed1, right shifting 8 will get 256, but we need 2
55. | 492 // For example, when f = SK_Fixed1, right shifting 8 will get 256, but we need 2
55. |
| 493 // This is rarely the problem so we'll only use this for blitting rectangles. | 493 // This is rarely the problem so we'll only use this for blitting rectangles. |
| 494 static inline SkAlpha f2a(SkFixed f) { | 494 static inline SkAlpha f2a(SkFixed f) { |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 AAAFillPath(path, clip.bwRgn(), blitter); | 1341 AAAFillPath(path, clip.bwRgn(), blitter); |
| 1342 } else { | 1342 } else { |
| 1343 SkRegion tmp; | 1343 SkRegion tmp; |
| 1344 SkAAClipBlitter aaBlitter; | 1344 SkAAClipBlitter aaBlitter; |
| 1345 | 1345 |
| 1346 tmp.setRect(clip.getBounds()); | 1346 tmp.setRect(clip.getBounds()); |
| 1347 aaBlitter.init(blitter, &clip.aaRgn()); | 1347 aaBlitter.init(blitter, &clip.aaRgn()); |
| 1348 AAAFillPath(path, tmp, &aaBlitter, true); | 1348 AAAFillPath(path, tmp, &aaBlitter, true); |
| 1349 } | 1349 } |
| 1350 } | 1350 } |
| OLD | NEW |