SkPathEffect.h revision 8a1c16ff38322f0210116fa7293eb8817c7e477e
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Copyright (C) 2006 The Android Open Source Project 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Licensed under the Apache License, Version 2.0 (the "License"); 58a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * you may not use this file except in compliance with the License. 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * You may obtain a copy of the License at 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * http://www.apache.org/licenses/LICENSE-2.0 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Unless required by applicable law or agreed to in writing, software 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * distributed under the License is distributed on an "AS IS" BASIS, 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * See the License for the specific language governing permissions and 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * limitations under the License. 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkPathEffect_DEFINED 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkPathEffect_DEFINED 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkFlattenable.h" 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPath; 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkPathEffect 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathEffect is the base class for objects in the SkPaint that affect 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the geometry of a drawing primitive before it is transformed by the 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com canvas' matrix and drawn. 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Dashing is implemented as a subclass of SkPathEffect. 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPathEffect : public SkFlattenable { 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // This method is not exported to java. 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathEffect() {} 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Given a src path and a width value, return true if the patheffect 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com has produced a new path (dst) and a new width value. If false is returned, 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ignore dst and width. 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com On input, width >= 0 means the src should be stroked 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com On output, width >= 0 means the dst should be stroked 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width) = 0; 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // illegal 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathEffect(const SkPathEffect&); 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathEffect& operator=(const SkPathEffect&); 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkPairPathEffect 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Common baseclass for Compose and Sum. This subclass manages two pathEffects, 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com including flattening them. It does nothing in filterPath, and is only useful 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for managing the lifetimes of its two arguments. 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPairPathEffect : public SkPathEffect { 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1); 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkPairPathEffect(); 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPairPathEffect(SkFlattenableReadBuffer&); 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void flatten(SkFlattenableWriteBuffer&); 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // these are visible to our subclasses 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathEffect* fPE0, *fPE1; 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkPathEffect INHERITED; 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkComposePathEffect 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This subclass of SkPathEffect composes its two arguments, to create 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com a compound pathEffect. 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkComposePathEffect : public SkPairPathEffect { 788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Construct a pathEffect whose effect is to apply first the inner pathEffect 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and the the outer pathEffect (e.g. outer(inner(path))) 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The reference counts for outer and inner are both incremented in the constructor, 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and decremented in the destructor. 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner) 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : INHERITED(outer, inner) {} 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // overrides 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // This method is not exported to java. 908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width); 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual Factory getFactory() { return CreateProc; } 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkNEW_ARGS(SkComposePathEffect, (buffer)); 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkComposePathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // illegal 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkComposePathEffect(const SkComposePathEffect&); 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkComposePathEffect& operator=(const SkComposePathEffect&); 1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkPairPathEffect INHERITED; 1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkSumPathEffect 1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This subclass of SkPathEffect applies two pathEffects, one after the other. 1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Its filterPath() returns true if either of the effects succeeded. 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkSumPathEffect : public SkPairPathEffect { 1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Construct a pathEffect whose effect is to apply two effects, in sequence. 1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (e.g. first(path) + second(path)) 1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The reference counts for first and second are both incremented in the constructor, 1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and decremented in the destructor. 1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkSumPathEffect(SkPathEffect* first, SkPathEffect* second) 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : INHERITED(first, second) {} 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // overrides 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // This method is not exported to java. 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width); 1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual Factory getFactory() { return CreateProc; } 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkNEW_ARGS(SkSumPathEffect, (buffer)); 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkSumPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // illegal 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkSumPathEffect(const SkSumPathEffect&); 1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkSumPathEffect& operator=(const SkSumPathEffect&); 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkPairPathEffect INHERITED; 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 145