2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrStrokeInfo_DEFINED
9 #define GrStrokeInfo_DEFINED
11 #include "SkStrokeRec.h"
12 #include "SkPathEffect.h"
15 * GrStrokeInfo encapsulates the data objects that hold all the pertinent infomation
16 * regarding the stroke. The two objects are SkStrokeRec which holds information on fill style,
17 * width, miter, cap, and join. The second object is DashInfo. This holds information about the
18 * dash like intervals, count, and phase.
22 GrStrokeInfo(SkStrokeRec::InitStyle style) :
23 fStroke(style), fDashType(SkPathEffect::kNone_DashType) {}
25 GrStrokeInfo(const GrStrokeInfo& src, bool includeDash = true) : fStroke(src.fStroke) {
27 fDashInfo = src.fDashInfo;
28 fDashType = src.fDashType;
29 fIntervals.reset(src.dashCount());
30 memcpy(fIntervals.get(), src.fIntervals.get(), src.dashCount() * sizeof(SkScalar));
32 fDashType = SkPathEffect::kNone_DashType;
36 GrStrokeInfo(const SkPaint& paint, SkPaint::Style styleOverride) :
37 fStroke(paint, styleOverride), fDashType(SkPathEffect::kNone_DashType) {
42 explicit GrStrokeInfo(const SkPaint& paint) :
43 fStroke(paint), fDashType(SkPathEffect::kNone_DashType) {
47 const SkStrokeRec& getStrokeRec() const { return fStroke; }
49 SkStrokeRec* getStrokeRecPtr() { return &fStroke; }
51 void setFillStyle() { fStroke.setFillStyle(); }
54 * This functions takes in a patheffect and fills in fDashInfo with the various dashing
55 * information if the path effect is a Dash type. Returns true if the path effect is a
56 * dashed effect and we are stroking, otherwise it retruns false.
58 bool setDashInfo(const SkPathEffect* pe) {
59 if (NULL != pe && !fStroke.isFillStyle()) {
60 fDashInfo.fIntervals = NULL;
61 fDashType = pe->asADash(&fDashInfo);
62 if (SkPathEffect::kDash_DashType == fDashType) {
63 fIntervals.reset(fDashInfo.fCount);
64 fDashInfo.fIntervals = fIntervals.get();
65 pe->asADash(&fDashInfo);
72 bool isDashed() const {
73 return (!fStroke.isFillStyle() && SkPathEffect::kDash_DashType == fDashType);
76 int32_t dashCount() const {
77 return fDashInfo.fCount;
81 fDashType = SkPathEffect::kNone_DashType;
84 const SkPathEffect::DashInfo& getDashInfo() const { return fDashInfo; }
88 void init(const SkPaint& paint) {
89 const SkPathEffect* pe = paint.getPathEffect();
90 this->setDashInfo(pe);
94 SkPathEffect::DashType fDashType;
95 SkPathEffect::DashInfo fDashInfo;
96 SkAutoSTArray<2, SkScalar> fIntervals;