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