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
16void SkPathEffect::computeFastBounds(SkRect* dst, const SkRect& src) const {
17    *dst = src;
18}
19
20bool SkPathEffect::asPoints(PointData* results, const SkPath& src,
21                    const SkStrokeRec&, const SkMatrix&, const SkRect*) const {
22    return false;
23}
24
25SkPathEffect::DashType SkPathEffect::asADash(DashInfo* info) const {
26    return kNone_DashType;
27}
28
29///////////////////////////////////////////////////////////////////////////////
30
31SkPairPathEffect::SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1)
32        : fPE0(pe0), fPE1(pe1) {
33    SkASSERT(pe0);
34    SkASSERT(pe1);
35    fPE0->ref();
36    fPE1->ref();
37}
38
39SkPairPathEffect::~SkPairPathEffect() {
40    SkSafeUnref(fPE0);
41    SkSafeUnref(fPE1);
42}
43
44/*
45    Format: [oe0-factory][pe1-factory][pe0-size][pe0-data][pe1-data]
46*/
47void SkPairPathEffect::flatten(SkWriteBuffer& buffer) const {
48    buffer.writeFlattenable(fPE0);
49    buffer.writeFlattenable(fPE1);
50}
51
52#ifndef SK_IGNORE_TO_STRING
53void 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
67SkFlattenable* SkComposePathEffect::CreateProc(SkReadBuffer& buffer) {
68    SkAutoTUnref<SkPathEffect> pe0(buffer.readPathEffect());
69    SkAutoTUnref<SkPathEffect> pe1(buffer.readPathEffect());
70    return SkComposePathEffect::Create(pe0, pe1);
71}
72
73bool SkComposePathEffect::filterPath(SkPath* dst, const SkPath& src,
74                             SkStrokeRec* rec, const SkRect* cullRect) const {
75    // we may have failed to unflatten these, so we have to check
76    if (!fPE0 || !fPE1) {
77        return false;
78    }
79
80    SkPath          tmp;
81    const SkPath*   ptr = &src;
82
83    if (fPE1->filterPath(&tmp, src, rec, cullRect)) {
84        ptr = &tmp;
85    }
86    return fPE0->filterPath(dst, *ptr, rec, cullRect);
87}
88
89
90#ifndef SK_IGNORE_TO_STRING
91void SkComposePathEffect::toString(SkString* str) const {
92    str->appendf("SkComposePathEffect: (");
93    this->INHERITED::toString(str);
94    str->appendf(")");
95}
96#endif
97
98///////////////////////////////////////////////////////////////////////////////
99
100SkFlattenable* SkSumPathEffect::CreateProc(SkReadBuffer& buffer) {
101    SkAutoTUnref<SkPathEffect> pe0(buffer.readPathEffect());
102    SkAutoTUnref<SkPathEffect> pe1(buffer.readPathEffect());
103    return SkSumPathEffect::Create(pe0, pe1);
104}
105
106bool SkSumPathEffect::filterPath(SkPath* dst, const SkPath& src,
107                             SkStrokeRec* rec, const SkRect* cullRect) const {
108    // use bit-or so that we always call both, even if the first one succeeds
109    return fPE0->filterPath(dst, src, rec, cullRect) |
110           fPE1->filterPath(dst, src, rec, cullRect);
111}
112
113
114#ifndef SK_IGNORE_TO_STRING
115void SkSumPathEffect::toString(SkString* str) const {
116    str->appendf("SkSumPathEffect: (");
117    this->INHERITED::toString(str);
118    str->appendf(")");
119}
120#endif
121