epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | #include "SkPathEffect.h" |
| 10 | #include "SkPath.h" |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 11 | #include "SkFlattenableBuffers.h" |
reed@google.com | fd4be26 | 2012-05-25 01:04:12 +0000 | [diff] [blame] | 12 | |
| 13 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | |
reed@google.com | 548a1f3 | 2012-12-18 16:12:09 +0000 | [diff] [blame] | 15 | void SkPathEffect::computeFastBounds(SkRect* dst, const SkRect& src) const { |
reed@google.com | e4f10a7 | 2012-05-15 20:47:50 +0000 | [diff] [blame] | 16 | *dst = src; |
| 17 | } |
| 18 | |
skia.committer@gmail.com | 687c57c | 2012-11-29 02:01:19 +0000 | [diff] [blame] | 19 | bool SkPathEffect::asPoints(PointData* results, const SkPath& src, |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 20 | const SkStrokeRec&, const SkMatrix&, const SkRect*) const { |
robertphillips@google.com | 629ab54 | 2012-11-28 17:18:11 +0000 | [diff] [blame] | 21 | return false; |
| 22 | } |
| 23 | |
reed@google.com | feb8cc8 | 2011-04-19 20:11:25 +0000 | [diff] [blame] | 24 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | |
| 26 | SkPairPathEffect::SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1) |
reed@google.com | feb8cc8 | 2011-04-19 20:11:25 +0000 | [diff] [blame] | 27 | : fPE0(pe0), fPE1(pe1) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | SkASSERT(pe0); |
| 29 | SkASSERT(pe1); |
| 30 | fPE0->ref(); |
| 31 | fPE1->ref(); |
| 32 | } |
| 33 | |
reed@google.com | feb8cc8 | 2011-04-19 20:11:25 +0000 | [diff] [blame] | 34 | SkPairPathEffect::~SkPairPathEffect() { |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 35 | SkSafeUnref(fPE0); |
| 36 | SkSafeUnref(fPE1); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /* |
| 40 | Format: [oe0-factory][pe1-factory][pe0-size][pe0-data][pe1-data] |
| 41 | */ |
djsollen@google.com | 5492424 | 2012-03-29 15:18:04 +0000 | [diff] [blame] | 42 | void SkPairPathEffect::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 43 | this->INHERITED::flatten(buffer); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | buffer.writeFlattenable(fPE0); |
| 45 | buffer.writeFlattenable(fPE1); |
| 46 | } |
| 47 | |
reed@google.com | feb8cc8 | 2011-04-19 20:11:25 +0000 | [diff] [blame] | 48 | SkPairPathEffect::SkPairPathEffect(SkFlattenableReadBuffer& buffer) { |
reed@google.com | 3534822 | 2013-10-16 13:05:06 +0000 | [diff] [blame] | 49 | fPE0 = buffer.readPathEffect(); |
| 50 | fPE1 = buffer.readPathEffect(); |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 51 | // either of these may fail, so we have to check for nulls later on |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | } |
| 53 | |
reed@google.com | feb8cc8 | 2011-04-19 20:11:25 +0000 | [diff] [blame] | 54 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | |
reed@google.com | feb8cc8 | 2011-04-19 20:11:25 +0000 | [diff] [blame] | 56 | bool SkComposePathEffect::filterPath(SkPath* dst, const SkPath& src, |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 57 | SkStrokeRec* rec, const SkRect* cullRect) const { |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 58 | // we may have failed to unflatten these, so we have to check |
| 59 | if (!fPE0 || !fPE1) { |
| 60 | return false; |
| 61 | } |
| 62 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 63 | SkPath tmp; |
| 64 | const SkPath* ptr = &src; |
| 65 | |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 66 | if (fPE1->filterPath(&tmp, src, rec, cullRect)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 67 | ptr = &tmp; |
reed@google.com | feb8cc8 | 2011-04-19 20:11:25 +0000 | [diff] [blame] | 68 | } |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 69 | return fPE0->filterPath(dst, *ptr, rec, cullRect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 70 | } |
| 71 | |
reed@google.com | feb8cc8 | 2011-04-19 20:11:25 +0000 | [diff] [blame] | 72 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | |
reed@google.com | feb8cc8 | 2011-04-19 20:11:25 +0000 | [diff] [blame] | 74 | bool SkSumPathEffect::filterPath(SkPath* dst, const SkPath& src, |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 75 | SkStrokeRec* rec, const SkRect* cullRect) const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 76 | // use bit-or so that we always call both, even if the first one succeeds |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 77 | return fPE0->filterPath(dst, src, rec, cullRect) | |
| 78 | fPE1->filterPath(dst, src, rec, cullRect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 79 | } |