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#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING 53SkPairPathEffect::SkPairPathEffect(SkReadBuffer& buffer) { 54 fPE0 = buffer.readPathEffect(); 55 fPE1 = buffer.readPathEffect(); 56 // either of these may fail, so we have to check for nulls later on 57} 58#endif 59 60/////////////////////////////////////////////////////////////////////////////// 61 62SkFlattenable* SkComposePathEffect::CreateProc(SkReadBuffer& buffer) { 63 SkAutoTUnref<SkPathEffect> pe0(buffer.readPathEffect()); 64 SkAutoTUnref<SkPathEffect> pe1(buffer.readPathEffect()); 65 return SkComposePathEffect::Create(pe0, pe1); 66} 67 68bool SkComposePathEffect::filterPath(SkPath* dst, const SkPath& src, 69 SkStrokeRec* rec, const SkRect* cullRect) const { 70 // we may have failed to unflatten these, so we have to check 71 if (!fPE0 || !fPE1) { 72 return false; 73 } 74 75 SkPath tmp; 76 const SkPath* ptr = &src; 77 78 if (fPE1->filterPath(&tmp, src, rec, cullRect)) { 79 ptr = &tmp; 80 } 81 return fPE0->filterPath(dst, *ptr, rec, cullRect); 82} 83 84/////////////////////////////////////////////////////////////////////////////// 85 86SkFlattenable* SkSumPathEffect::CreateProc(SkReadBuffer& buffer) { 87 SkAutoTUnref<SkPathEffect> pe0(buffer.readPathEffect()); 88 SkAutoTUnref<SkPathEffect> pe1(buffer.readPathEffect()); 89 return SkSumPathEffect::Create(pe0, pe1); 90} 91 92bool SkSumPathEffect::filterPath(SkPath* dst, const SkPath& src, 93 SkStrokeRec* rec, const SkRect* cullRect) const { 94 // use bit-or so that we always call both, even if the first one succeeds 95 return fPE0->filterPath(dst, src, rec, cullRect) | 96 fPE1->filterPath(dst, src, rec, cullRect); 97} 98