1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 #include "SkPathEffect.h"
10 #include "SkPath.h"
11 #include "SkReadBuffer.h"
12 #include "SkWriteBuffer.h"
13 
14 ///////////////////////////////////////////////////////////////////////////////
15 
computeFastBounds(SkRect * dst,const SkRect & src) const16 void SkPathEffect::computeFastBounds(SkRect* dst, const SkRect& src) const {
17     *dst = src;
18 }
19 
asPoints(PointData * results,const SkPath & src,const SkStrokeRec &,const SkMatrix &,const SkRect *) const20 bool SkPathEffect::asPoints(PointData* results, const SkPath& src,
21                     const SkStrokeRec&, const SkMatrix&, const SkRect*) const {
22     return false;
23 }
24 
asADash(DashInfo * info) const25 SkPathEffect::DashType SkPathEffect::asADash(DashInfo* info) const {
26     return kNone_DashType;
27 }
28 
29 ///////////////////////////////////////////////////////////////////////////////
30 
SkPairPathEffect(SkPathEffect * pe0,SkPathEffect * pe1)31 SkPairPathEffect::SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1)
32         : fPE0(pe0), fPE1(pe1) {
33     SkASSERT(pe0);
34     SkASSERT(pe1);
35     fPE0->ref();
36     fPE1->ref();
37 }
38 
~SkPairPathEffect()39 SkPairPathEffect::~SkPairPathEffect() {
40     SkSafeUnref(fPE0);
41     SkSafeUnref(fPE1);
42 }
43 
44 /*
45     Format: [oe0-factory][pe1-factory][pe0-size][pe0-data][pe1-data]
46 */
flatten(SkWriteBuffer & buffer) const47 void SkPairPathEffect::flatten(SkWriteBuffer& buffer) const {
48     buffer.writeFlattenable(fPE0);
49     buffer.writeFlattenable(fPE1);
50 }
51 
52 #ifndef SK_IGNORE_TO_STRING
toString(SkString * str) const53 void SkPairPathEffect::toString(SkString* str) const {
54     str->appendf("first: ");
55     if (fPE0) {
56         fPE0->toString(str);
57     }
58     str->appendf(" second: ");
59     if (fPE1) {
60         fPE1->toString(str);
61     }
62 }
63 #endif
64 
65 ///////////////////////////////////////////////////////////////////////////////
66 
CreateProc(SkReadBuffer & buffer)67 SkFlattenable* SkComposePathEffect::CreateProc(SkReadBuffer& buffer) {
68     SkAutoTUnref<SkPathEffect> pe0(buffer.readPathEffect());
69     SkAutoTUnref<SkPathEffect> pe1(buffer.readPathEffect());
70     if (pe0 && pe1) {
71         return SkComposePathEffect::Create(pe0, pe1);
72     } else {
73         return nullptr;
74     }
75 }
76 
filterPath(SkPath * dst,const SkPath & src,SkStrokeRec * rec,const SkRect * cullRect) const77 bool SkComposePathEffect::filterPath(SkPath* dst, const SkPath& src,
78                              SkStrokeRec* rec, const SkRect* cullRect) const {
79     // we may have failed to unflatten these, so we have to check
80     if (!fPE0 || !fPE1) {
81         return false;
82     }
83 
84     SkPath          tmp;
85     const SkPath*   ptr = &src;
86 
87     if (fPE1->filterPath(&tmp, src, rec, cullRect)) {
88         ptr = &tmp;
89     }
90     return fPE0->filterPath(dst, *ptr, rec, cullRect);
91 }
92 
93 
94 #ifndef SK_IGNORE_TO_STRING
toString(SkString * str) const95 void SkComposePathEffect::toString(SkString* str) const {
96     str->appendf("SkComposePathEffect: (");
97     this->INHERITED::toString(str);
98     str->appendf(")");
99 }
100 #endif
101 
102 ///////////////////////////////////////////////////////////////////////////////
103 
CreateProc(SkReadBuffer & buffer)104 SkFlattenable* SkSumPathEffect::CreateProc(SkReadBuffer& buffer) {
105     SkAutoTUnref<SkPathEffect> pe0(buffer.readPathEffect());
106     SkAutoTUnref<SkPathEffect> pe1(buffer.readPathEffect());
107     if (pe0 && pe1) {
108         return SkSumPathEffect::Create(pe0, pe1);
109     } else {
110         return nullptr;
111     }
112 }
113 
filterPath(SkPath * dst,const SkPath & src,SkStrokeRec * rec,const SkRect * cullRect) const114 bool SkSumPathEffect::filterPath(SkPath* dst, const SkPath& src,
115                              SkStrokeRec* rec, const SkRect* cullRect) const {
116     // use bit-or so that we always call both, even if the first one succeeds
117     return fPE0->filterPath(dst, src, rec, cullRect) |
118            fPE1->filterPath(dst, src, rec, cullRect);
119 }
120 
121 
122 #ifndef SK_IGNORE_TO_STRING
toString(SkString * str) const123 void SkSumPathEffect::toString(SkString* str) const {
124     str->appendf("SkSumPathEffect: (");
125     this->INHERITED::toString(str);
126     str->appendf(")");
127 }
128 #endif
129