epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
reed | 868074b | 2014-06-03 10:53:59 -0700 | [diff] [blame^] | 7 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #ifndef SkDrawProcs_DEFINED |
| 9 | #define SkDrawProcs_DEFINED |
| 10 | |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 11 | #include "SkBlitter.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkDraw.h" |
| 13 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 14 | class SkAAClip; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | class SkBlitter; |
| 16 | |
| 17 | struct SkDraw1Glyph { |
bungeman@google.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 18 | const SkDraw* fDraw; |
bungeman@google.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 19 | const SkRegion* fClip; |
| 20 | const SkAAClip* fAAClip; |
| 21 | SkBlitter* fBlitter; |
| 22 | SkGlyphCache* fCache; |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 23 | const SkPaint* fPaint; |
bungeman@google.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 24 | SkIRect fClipBounds; |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 25 | /** Half the sampling frequency of the rasterized glyph in x. */ |
| 26 | SkFixed fHalfSampleX; |
| 27 | /** Half the sampling frequency of the rasterized glyph in y. */ |
| 28 | SkFixed fHalfSampleY; |
bungeman@google.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 29 | |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 30 | /** Draws one glyph. |
| 31 | * |
| 32 | * The x and y are pre-biased, so implementations may just truncate them. |
| 33 | * i.e. half the sampling frequency has been added. |
| 34 | * e.g. 1/2 or 1/(2^(SkGlyph::kSubBits+1)) has already been added. |
| 35 | * This added bias can be found in fHalfSampleX,Y. |
| 36 | */ |
bungeman@google.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 37 | typedef void (*Proc)(const SkDraw1Glyph&, SkFixed x, SkFixed y, const SkGlyph&); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 38 | |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 39 | Proc init(const SkDraw* draw, SkBlitter* blitter, SkGlyphCache* cache, |
| 40 | const SkPaint&); |
| 41 | |
| 42 | // call this instead of fBlitter->blitMask() since this wrapper will handle |
| 43 | // the case when the mask is ARGB32_Format |
| 44 | // |
| 45 | void blitMask(const SkMask& mask, const SkIRect& clip) const { |
| 46 | if (SkMask::kARGB32_Format == mask.fFormat) { |
| 47 | this->blitMaskAsSprite(mask); |
| 48 | } else { |
| 49 | fBlitter->blitMask(mask, clip); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // mask must be kARGB32_Format |
| 54 | void blitMaskAsSprite(const SkMask& mask) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | struct SkDrawProcs { |
| 58 | SkDraw1Glyph::Proc fD1GProc; |
| 59 | }; |
| 60 | |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 61 | bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix&, |
| 62 | SkScalar* coverage); |
| 63 | |
reed@google.com | ecadf99 | 2011-09-19 19:18:18 +0000 | [diff] [blame] | 64 | /** |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 65 | * If the current paint is set to stroke and the stroke-width when applied to |
bsalomon@google.com | dd1be60 | 2012-01-18 20:34:00 +0000 | [diff] [blame] | 66 | * the matrix is <= 1.0, then this returns true, and sets coverage (simulating |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 67 | * a stroke by drawing a hairline with partial coverage). If any of these |
bsalomon@google.com | dd1be60 | 2012-01-18 20:34:00 +0000 | [diff] [blame] | 68 | * conditions are false, then this returns false and coverage is ignored. |
reed@google.com | ecadf99 | 2011-09-19 19:18:18 +0000 | [diff] [blame] | 69 | */ |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 70 | inline bool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix, |
| 71 | SkScalar* coverage) { |
| 72 | if (SkPaint::kStroke_Style != paint.getStyle()) { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | SkScalar strokeWidth = paint.getStrokeWidth(); |
| 77 | if (0 == strokeWidth) { |
| 78 | *coverage = SK_Scalar1; |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | if (!paint.isAntiAlias()) { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | return SkDrawTreatAAStrokeAsHairline(strokeWidth, matrix, coverage); |
| 87 | } |
reed@google.com | ecadf99 | 2011-09-19 19:18:18 +0000 | [diff] [blame] | 88 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 89 | #endif |