michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: #ifndef SkDrawProcs_DEFINED michael@0: #define SkDrawProcs_DEFINED michael@0: michael@0: #include "SkBlitter.h" michael@0: #include "SkDraw.h" michael@0: michael@0: class SkAAClip; michael@0: class SkBlitter; michael@0: michael@0: struct SkDraw1Glyph { michael@0: const SkDraw* fDraw; michael@0: SkBounder* fBounder; michael@0: const SkRegion* fClip; michael@0: const SkAAClip* fAAClip; michael@0: SkBlitter* fBlitter; michael@0: SkGlyphCache* fCache; michael@0: const SkPaint* fPaint; michael@0: SkIRect fClipBounds; michael@0: /** Half the sampling frequency of the rasterized glyph in x. */ michael@0: SkFixed fHalfSampleX; michael@0: /** Half the sampling frequency of the rasterized glyph in y. */ michael@0: SkFixed fHalfSampleY; michael@0: michael@0: /** Draws one glyph. michael@0: * michael@0: * The x and y are pre-biased, so implementations may just truncate them. michael@0: * i.e. half the sampling frequency has been added. michael@0: * e.g. 1/2 or 1/(2^(SkGlyph::kSubBits+1)) has already been added. michael@0: * This added bias can be found in fHalfSampleX,Y. michael@0: */ michael@0: typedef void (*Proc)(const SkDraw1Glyph&, SkFixed x, SkFixed y, const SkGlyph&); michael@0: michael@0: Proc init(const SkDraw* draw, SkBlitter* blitter, SkGlyphCache* cache, michael@0: const SkPaint&); michael@0: michael@0: // call this instead of fBlitter->blitMask() since this wrapper will handle michael@0: // the case when the mask is ARGB32_Format michael@0: // michael@0: void blitMask(const SkMask& mask, const SkIRect& clip) const { michael@0: if (SkMask::kARGB32_Format == mask.fFormat) { michael@0: this->blitMaskAsSprite(mask); michael@0: } else { michael@0: fBlitter->blitMask(mask, clip); michael@0: } michael@0: } michael@0: michael@0: // mask must be kARGB32_Format michael@0: void blitMaskAsSprite(const SkMask& mask) const; michael@0: }; michael@0: michael@0: struct SkDrawProcs { michael@0: SkDraw1Glyph::Proc fD1GProc; michael@0: }; michael@0: michael@0: bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix&, michael@0: SkScalar* coverage); michael@0: michael@0: /** michael@0: * If the current paint is set to stroke and the stroke-width when applied to michael@0: * the matrix is <= 1.0, then this returns true, and sets coverage (simulating michael@0: * a stroke by drawing a hairline with partial coverage). If any of these michael@0: * conditions are false, then this returns false and coverage is ignored. michael@0: */ michael@0: inline bool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix, michael@0: SkScalar* coverage) { michael@0: if (SkPaint::kStroke_Style != paint.getStyle()) { michael@0: return false; michael@0: } michael@0: michael@0: SkScalar strokeWidth = paint.getStrokeWidth(); michael@0: if (0 == strokeWidth) { michael@0: *coverage = SK_Scalar1; michael@0: return true; michael@0: } michael@0: michael@0: if (!paint.isAntiAlias()) { michael@0: return false; michael@0: } michael@0: michael@0: return SkDrawTreatAAStrokeAsHairline(strokeWidth, matrix, coverage); michael@0: } michael@0: michael@0: #endif