blob: 59ba3ec31fb39ea6ea98d894b1674003cee72966 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com8a1c16f2008-12-17 15:59:43 +00009#include "SkPathEffect.h"
10#include "SkPath.h"
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000011#include "SkFlattenableBuffers.h"
reed@google.comfd4be262012-05-25 01:04:12 +000012
13///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +000014
reed@google.com548a1f32012-12-18 16:12:09 +000015void SkPathEffect::computeFastBounds(SkRect* dst, const SkRect& src) const {
reed@google.come4f10a72012-05-15 20:47:50 +000016 *dst = src;
17}
18
skia.committer@gmail.com687c57c2012-11-29 02:01:19 +000019bool SkPathEffect::asPoints(PointData* results, const SkPath& src,
reed@google.com4bbdeac2013-01-24 21:03:11 +000020 const SkStrokeRec&, const SkMatrix&, const SkRect*) const {
robertphillips@google.com629ab542012-11-28 17:18:11 +000021 return false;
22}
23
reed@google.comfeb8cc82011-04-19 20:11:25 +000024///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +000025
26SkPairPathEffect::SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1)
reed@google.comfeb8cc82011-04-19 20:11:25 +000027 : fPE0(pe0), fPE1(pe1) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000028 SkASSERT(pe0);
29 SkASSERT(pe1);
30 fPE0->ref();
31 fPE1->ref();
32}
33
reed@google.comfeb8cc82011-04-19 20:11:25 +000034SkPairPathEffect::~SkPairPathEffect() {
reed@google.com6bac9472011-06-21 19:24:00 +000035 SkSafeUnref(fPE0);
36 SkSafeUnref(fPE1);
reed@android.com8a1c16f2008-12-17 15:59:43 +000037}
38
39/*
40 Format: [oe0-factory][pe1-factory][pe0-size][pe0-data][pe1-data]
41*/
djsollen@google.com54924242012-03-29 15:18:04 +000042void SkPairPathEffect::flatten(SkFlattenableWriteBuffer& buffer) const {
43 this->INHERITED::flatten(buffer);
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 buffer.writeFlattenable(fPE0);
45 buffer.writeFlattenable(fPE1);
46}
47
reed@google.comfeb8cc82011-04-19 20:11:25 +000048SkPairPathEffect::SkPairPathEffect(SkFlattenableReadBuffer& buffer) {
reed@google.com35348222013-10-16 13:05:06 +000049 fPE0 = buffer.readPathEffect();
50 fPE1 = buffer.readPathEffect();
reed@google.com6bac9472011-06-21 19:24:00 +000051 // either of these may fail, so we have to check for nulls later on
reed@android.com8a1c16f2008-12-17 15:59:43 +000052}
53
reed@google.comfeb8cc82011-04-19 20:11:25 +000054///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +000055
reed@google.comfeb8cc82011-04-19 20:11:25 +000056bool SkComposePathEffect::filterPath(SkPath* dst, const SkPath& src,
reed@google.com4bbdeac2013-01-24 21:03:11 +000057 SkStrokeRec* rec, const SkRect* cullRect) const {
reed@google.com6bac9472011-06-21 19:24:00 +000058 // we may have failed to unflatten these, so we have to check
59 if (!fPE0 || !fPE1) {
60 return false;
61 }
62
reed@android.com8a1c16f2008-12-17 15:59:43 +000063 SkPath tmp;
64 const SkPath* ptr = &src;
65
reed@google.com4bbdeac2013-01-24 21:03:11 +000066 if (fPE1->filterPath(&tmp, src, rec, cullRect)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000067 ptr = &tmp;
reed@google.comfeb8cc82011-04-19 20:11:25 +000068 }
reed@google.com4bbdeac2013-01-24 21:03:11 +000069 return fPE0->filterPath(dst, *ptr, rec, cullRect);
reed@android.com8a1c16f2008-12-17 15:59:43 +000070}
71
reed@google.comfeb8cc82011-04-19 20:11:25 +000072///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +000073
reed@google.comfeb8cc82011-04-19 20:11:25 +000074bool SkSumPathEffect::filterPath(SkPath* dst, const SkPath& src,
reed@google.com4bbdeac2013-01-24 21:03:11 +000075 SkStrokeRec* rec, const SkRect* cullRect) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000076 // use bit-or so that we always call both, even if the first one succeeds
reed@google.com4bbdeac2013-01-24 21:03:11 +000077 return fPE0->filterPath(dst, src, rec, cullRect) |
78 fPE1->filterPath(dst, src, rec, cullRect);
reed@android.com8a1c16f2008-12-17 15:59:43 +000079}