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