1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkDrawProcs.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 +#ifndef SkDrawProcs_DEFINED 1.12 +#define SkDrawProcs_DEFINED 1.13 + 1.14 +#include "SkBlitter.h" 1.15 +#include "SkDraw.h" 1.16 + 1.17 +class SkAAClip; 1.18 +class SkBlitter; 1.19 + 1.20 +struct SkDraw1Glyph { 1.21 + const SkDraw* fDraw; 1.22 + SkBounder* fBounder; 1.23 + const SkRegion* fClip; 1.24 + const SkAAClip* fAAClip; 1.25 + SkBlitter* fBlitter; 1.26 + SkGlyphCache* fCache; 1.27 + const SkPaint* fPaint; 1.28 + SkIRect fClipBounds; 1.29 + /** Half the sampling frequency of the rasterized glyph in x. */ 1.30 + SkFixed fHalfSampleX; 1.31 + /** Half the sampling frequency of the rasterized glyph in y. */ 1.32 + SkFixed fHalfSampleY; 1.33 + 1.34 + /** Draws one glyph. 1.35 + * 1.36 + * The x and y are pre-biased, so implementations may just truncate them. 1.37 + * i.e. half the sampling frequency has been added. 1.38 + * e.g. 1/2 or 1/(2^(SkGlyph::kSubBits+1)) has already been added. 1.39 + * This added bias can be found in fHalfSampleX,Y. 1.40 + */ 1.41 + typedef void (*Proc)(const SkDraw1Glyph&, SkFixed x, SkFixed y, const SkGlyph&); 1.42 + 1.43 + Proc init(const SkDraw* draw, SkBlitter* blitter, SkGlyphCache* cache, 1.44 + const SkPaint&); 1.45 + 1.46 + // call this instead of fBlitter->blitMask() since this wrapper will handle 1.47 + // the case when the mask is ARGB32_Format 1.48 + // 1.49 + void blitMask(const SkMask& mask, const SkIRect& clip) const { 1.50 + if (SkMask::kARGB32_Format == mask.fFormat) { 1.51 + this->blitMaskAsSprite(mask); 1.52 + } else { 1.53 + fBlitter->blitMask(mask, clip); 1.54 + } 1.55 + } 1.56 + 1.57 + // mask must be kARGB32_Format 1.58 + void blitMaskAsSprite(const SkMask& mask) const; 1.59 +}; 1.60 + 1.61 +struct SkDrawProcs { 1.62 + SkDraw1Glyph::Proc fD1GProc; 1.63 +}; 1.64 + 1.65 +bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix&, 1.66 + SkScalar* coverage); 1.67 + 1.68 +/** 1.69 + * If the current paint is set to stroke and the stroke-width when applied to 1.70 + * the matrix is <= 1.0, then this returns true, and sets coverage (simulating 1.71 + * a stroke by drawing a hairline with partial coverage). If any of these 1.72 + * conditions are false, then this returns false and coverage is ignored. 1.73 + */ 1.74 +inline bool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix, 1.75 + SkScalar* coverage) { 1.76 + if (SkPaint::kStroke_Style != paint.getStyle()) { 1.77 + return false; 1.78 + } 1.79 + 1.80 + SkScalar strokeWidth = paint.getStrokeWidth(); 1.81 + if (0 == strokeWidth) { 1.82 + *coverage = SK_Scalar1; 1.83 + return true; 1.84 + } 1.85 + 1.86 + if (!paint.isAntiAlias()) { 1.87 + return false; 1.88 + } 1.89 + 1.90 + return SkDrawTreatAAStrokeAsHairline(strokeWidth, matrix, coverage); 1.91 +} 1.92 + 1.93 +#endif