diff options
author | sugoi@google.com <sugoi@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-12-17 21:16:45 +0000 |
---|---|---|
committer | sugoi@google.com <sugoi@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-12-17 21:16:45 +0000 |
commit | 5f74cf8c49701f514b69dc6f1a8b5c0ffd78af0a (patch) | |
tree | 3cec664355e570c921cd903dda21146806279185 /include | |
parent | 9f6a557548b4aec8aa0d3345488089b3d75f471c (diff) |
Follow up on the previous patch :
- Moved the SkStrokeRec class in its own file
- Replaced SkStroke by SkStrokeRec in Ganesh
- Moved path stroking to the Ganesh level in some cases (everytime it isn't required to do it directly in SkGpuDevice). PathEffect and MaskFilter still require path stroking at the SkGpuDevice for now.
- Renamed static functions in SkPath with proper names
* No functionality shold have changed with this patch. This is a step towards enabling Ganesh Path Renderers to decide whether or not to stroke the path rather than always receiving the stroked path as an input argument.
BUG=chromium:135111
TEST=Try path rendering tests from the gm
Review URL: https://codereview.appspot.com/6946072
git-svn-id: http://skia.googlecode.com/svn/trunk@6861 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkPath.h | 16 | ||||
-rw-r--r-- | include/core/SkPathEffect.h | 79 | ||||
-rw-r--r-- | include/core/SkStrokeRec.h | 92 | ||||
-rw-r--r-- | include/gpu/GrContext.h | 10 | ||||
-rw-r--r-- | include/gpu/GrPathRendererChain.h | 4 |
5 files changed, 113 insertions, 88 deletions
diff --git a/include/core/SkPath.h b/include/core/SkPath.h index 98d775222b..9d7e6a13f6 100644 --- a/include/core/SkPath.h +++ b/include/core/SkPath.h @@ -89,7 +89,7 @@ public: } /** Returns true if the filltype is one of the Inverse variants */ - bool isInverseFillType() const { return IsInverseFill((FillType)fFillType); } + bool isInverseFillType() const { return IsInverseFillType((FillType)fFillType); } /** * Toggle between inverse and normal filltypes. This reverse the return @@ -524,8 +524,13 @@ public: /** * Returns whether or not a fill type is inverted + * + * kWinding_FillType -> false + * kEvenOdd_FillType -> false + * kInverseWinding_FillType -> true + * kInverseEvenOdd_FillType -> true */ - static bool IsInverseFill(FillType fill) { + static bool IsInverseFillType(FillType fill) { SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch); SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch); SK_COMPILE_ASSERT(2 == kInverseWinding_FillType, fill_type_mismatch); @@ -535,8 +540,13 @@ public: /** * Returns the equivalent non-inverted fill type to the given fill type + * + * kWinding_FillType -> kWinding_FillType + * kEvenOdd_FillType -> kEvenOdd_FillType + * kInverseWinding_FillType -> kWinding_FillType + * kInverseEvenOdd_FillType -> kEvenOdd_FillType */ - static FillType NonInverseFill(FillType fill) { + static FillType ConvertToNonInverseFillType(FillType fill) { SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch); SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch); SK_COMPILE_ASSERT(2 == kInverseWinding_FillType, fill_type_mismatch); diff --git a/include/core/SkPathEffect.h b/include/core/SkPathEffect.h index fa29a34f73..736ea9895d 100644 --- a/include/core/SkPathEffect.h +++ b/include/core/SkPathEffect.h @@ -11,91 +11,14 @@ #define SkPathEffect_DEFINED #include "SkFlattenable.h" -#include "SkPaint.h" #include "SkPath.h" #include "SkPoint.h" #include "SkRect.h" +#include "SkStrokeRec.h" #include "SkTDArray.h" class SkPath; -class SkStrokeRec { -public: - enum InitStyle { - kHairline_InitStyle, - kFill_InitStyle - }; - SkStrokeRec(InitStyle style); - - SkStrokeRec(const SkStrokeRec&); - explicit SkStrokeRec(const SkPaint&); - - enum Style { - kHairline_Style, - kFill_Style, - kStroke_Style, - kStrokeAndFill_Style - }; - - Style getStyle() const; - SkScalar getWidth() const { return fWidth; } - SkScalar getMiter() const { return fMiterLimit; } - SkPaint::Cap getCap() const { return fCap; } - SkPaint::Join getJoin() const { return fJoin; } - - bool isHairlineStyle() const { - return kHairline_Style == this->getStyle(); - } - - bool isFillStyle() const { - return kFill_Style == this->getStyle(); - } - - void setFillStyle(); - void setHairlineStyle(); - /** - * Specify the strokewidth, and optionally if you want stroke + fill. - * Note, if width==0, then this request is taken to mean: - * strokeAndFill==true -> new style will be Fill - * strokeAndFill==false -> new style will be Hairline - */ - void setStrokeStyle(SkScalar width, bool strokeAndFill = false); - - void setStrokeParams(SkPaint::Cap cap, SkPaint::Join join, SkScalar miterLimit) { - fCap = cap; - fJoin = join; - fMiterLimit = miterLimit; - } - - /** - * Returns true if this specifes any thick stroking, i.e. applyToPath() - * will return true. - */ - bool needToApply() const { - Style style = this->getStyle(); - return (kStroke_Style == style) || (kStrokeAndFill_Style == style); - } - - /** - * Apply these stroke parameters to the src path, returning the result - * in dst. - * - * If there was no change (i.e. style == hairline or fill) this returns - * false and dst is unchanged. Otherwise returns true and the result is - * stored in dst. - * - * src and dst may be the same path. - */ - bool applyToPath(SkPath* dst, const SkPath& src) const; - -private: - SkScalar fWidth; - SkScalar fMiterLimit; - SkPaint::Cap fCap; - SkPaint::Join fJoin; - bool fStrokeAndFill; -}; - /** \class SkPathEffect SkPathEffect is the base class for objects in the SkPaint that affect diff --git a/include/core/SkStrokeRec.h b/include/core/SkStrokeRec.h new file mode 100644 index 0000000000..c5b47c25dd --- /dev/null +++ b/include/core/SkStrokeRec.h @@ -0,0 +1,92 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkStrokeRec_DEFINED +#define SkStrokeRec_DEFINED + +#include "SkPaint.h" + +class SkPath; + +class SkStrokeRec { +public: + enum InitStyle { + kHairline_InitStyle, + kFill_InitStyle + }; + SkStrokeRec(InitStyle style); + + SkStrokeRec(const SkStrokeRec&); + explicit SkStrokeRec(const SkPaint&); + + enum Style { + kHairline_Style, + kFill_Style, + kStroke_Style, + kStrokeAndFill_Style + }; + + Style getStyle() const; + SkScalar getWidth() const { return fWidth; } + SkScalar getMiter() const { return fMiterLimit; } + SkPaint::Cap getCap() const { return fCap; } + SkPaint::Join getJoin() const { return fJoin; } + + bool isHairlineStyle() const { + return kHairline_Style == this->getStyle(); + } + + bool isFillStyle() const { + return kFill_Style == this->getStyle(); + } + + void setFillStyle(); + void setHairlineStyle(); + /** + * Specify the strokewidth, and optionally if you want stroke + fill. + * Note, if width==0, then this request is taken to mean: + * strokeAndFill==true -> new style will be Fill + * strokeAndFill==false -> new style will be Hairline + */ + void setStrokeStyle(SkScalar width, bool strokeAndFill = false); + + void setStrokeParams(SkPaint::Cap cap, SkPaint::Join join, SkScalar miterLimit) { + fCap = cap; + fJoin = join; + fMiterLimit = miterLimit; + } + + /** + * Returns true if this specifes any thick stroking, i.e. applyToPath() + * will return true. + */ + bool needToApply() const { + Style style = this->getStyle(); + return (kStroke_Style == style) || (kStrokeAndFill_Style == style); + } + + /** + * Apply these stroke parameters to the src path, returning the result + * in dst. + * + * If there was no change (i.e. style == hairline or fill) this returns + * false and dst is unchanged. Otherwise returns true and the result is + * stored in dst. + * + * src and dst may be the same path. + */ + bool applyToPath(SkPath* dst, const SkPath& src) const; + +private: + SkScalar fWidth; + SkScalar fMiterLimit; + SkPaint::Cap fCap; + SkPaint::Join fJoin; + bool fStrokeAndFill; +}; + +#endif diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 8f2ed62710..06d26829d3 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -39,7 +39,7 @@ class GrTextureParams; class GrVertexBuffer; class GrVertexBufferAllocPool; class GrSoftwarePathRenderer; -class SkStroke; +class SkStrokeRec; class GR_API GrContext : public GrRefCnt { public: @@ -411,9 +411,9 @@ public: * * @param paint describes how to color pixels. * @param path the path to draw - * @param doHairLine whether the stroke can be optimized as a hairline + * @param stroke the stroke information (width, join, cap) */ - void drawPath(const GrPaint& paint, const SkPath& path, bool doHairLine); + void drawPath(const GrPaint& paint, const SkPath& path, const SkStrokeRec& stroke); /** * Draws vertices with a paint. @@ -846,7 +846,7 @@ public: GrPathRenderer* getPathRenderer( const SkPath& path, - const SkStroke& stroke, + const SkStrokeRec& stroke, const GrDrawTarget* target, bool allowSW, GrPathRendererChain::DrawType drawType = GrPathRendererChain::kColor_DrawType, @@ -910,7 +910,7 @@ private: /// draw state is left unmodified. GrDrawTarget* prepareToDraw(const GrPaint*, BufferedDraw); - void internalDrawPath(const GrPaint& paint, const SkPath& path, const SkStroke& stroke); + void internalDrawPath(const GrPaint& paint, const SkPath& path, const SkStrokeRec& stroke); GrTexture* createResizedTexture(const GrTextureDesc& desc, const GrCacheData& cacheData, diff --git a/include/gpu/GrPathRendererChain.h b/include/gpu/GrPathRendererChain.h index 1032240745..d51a4bbf15 100644 --- a/include/gpu/GrPathRendererChain.h +++ b/include/gpu/GrPathRendererChain.h @@ -17,7 +17,7 @@ class GrContext; class GrDrawTarget; class GrPathRenderer; class SkPath; -class SkStroke; +class SkStrokeRec; /** * Keeps track of an ordered list of path renderers. When a path needs to be @@ -58,7 +58,7 @@ public: whether the path can be rendered with arbitrary stencil rules or not. See comments on StencilSupport in GrPathRenderer.h. */ GrPathRenderer* getPathRenderer(const SkPath& path, - const SkStroke& stroke, + const SkStrokeRec& rec, const GrDrawTarget* target, DrawType drawType, StencilSupport* stencilSupport); |