Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / core / SkPathEffect.cpp
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 "SkFlattenableBuffers.h"
12
13 ///////////////////////////////////////////////////////////////////////////////
14
15 void SkPathEffect::computeFastBounds(SkRect* dst, const SkRect& src) const {
16     *dst = src;
17 }
18
19 bool SkPathEffect::asPoints(PointData* results, const SkPath& src,
20                     const SkStrokeRec&, const SkMatrix&, const SkRect*) const {
21     return false;
22 }
23
24 ///////////////////////////////////////////////////////////////////////////////
25
26 SkPairPathEffect::SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1)
27         : fPE0(pe0), fPE1(pe1) {
28     SkASSERT(pe0);
29     SkASSERT(pe1);
30     fPE0->ref();
31     fPE1->ref();
32 }
33
34 SkPairPathEffect::~SkPairPathEffect() {
35     SkSafeUnref(fPE0);
36     SkSafeUnref(fPE1);
37 }
38
39 /*
40     Format: [oe0-factory][pe1-factory][pe0-size][pe0-data][pe1-data]
41 */
42 void SkPairPathEffect::flatten(SkFlattenableWriteBuffer& buffer) const {
43     this->INHERITED::flatten(buffer);
44     buffer.writeFlattenable(fPE0);
45     buffer.writeFlattenable(fPE1);
46 }
47
48 SkPairPathEffect::SkPairPathEffect(SkFlattenableReadBuffer& buffer) {
49     fPE0 = buffer.readPathEffect();
50     fPE1 = buffer.readPathEffect();
51     // either of these may fail, so we have to check for nulls later on
52 }
53
54 ///////////////////////////////////////////////////////////////////////////////
55
56 bool SkComposePathEffect::filterPath(SkPath* dst, const SkPath& src,
57                              SkStrokeRec* rec, const SkRect* cullRect) const {
58     // we may have failed to unflatten these, so we have to check
59     if (!fPE0 || !fPE1) {
60         return false;
61     }
62
63     SkPath          tmp;
64     const SkPath*   ptr = &src;
65
66     if (fPE1->filterPath(&tmp, src, rec, cullRect)) {
67         ptr = &tmp;
68     }
69     return fPE0->filterPath(dst, *ptr, rec, cullRect);
70 }
71
72 ///////////////////////////////////////////////////////////////////////////////
73
74 bool SkSumPathEffect::filterPath(SkPath* dst, const SkPath& src,
75                              SkStrokeRec* rec, const SkRect* cullRect) const {
76     // use bit-or so that we always call both, even if the first one succeeds
77     return fPE0->filterPath(dst, src, rec, cullRect) |
78            fPE1->filterPath(dst, src, rec, cullRect);
79 }