1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/animator/SkDrawPath.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,220 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#include "SkDrawPath.h" 1.14 +#include "SkAnimateMaker.h" 1.15 +#include "SkCanvas.h" 1.16 +#include "SkMath.h" 1.17 +#include "SkMatrixParts.h" 1.18 +#include "SkPaint.h" 1.19 +#include "SkPathParts.h" 1.20 + 1.21 +enum SkPath_Properties { 1.22 + SK_PROPERTY(fillType), 1.23 + SK_PROPERTY(length) 1.24 +}; 1.25 + 1.26 +#if SK_USE_CONDENSED_INFO == 0 1.27 + 1.28 +const SkMemberInfo SkDrawPath::fInfo[] = { 1.29 + SK_MEMBER(d, String), 1.30 + SK_MEMBER_PROPERTY(fillType, FillType), 1.31 + SK_MEMBER_PROPERTY(length, Float) 1.32 +}; 1.33 + 1.34 +#endif 1.35 + 1.36 +DEFINE_GET_MEMBER(SkDrawPath); 1.37 + 1.38 +SkDrawPath::SkDrawPath() 1.39 +{ 1.40 + fParent = NULL; 1.41 + fLength = SK_ScalarNaN; 1.42 + fChildHasID = false; 1.43 + fDirty = false; 1.44 +} 1.45 + 1.46 +SkDrawPath::~SkDrawPath() { 1.47 + for (SkPathPart** part = fParts.begin(); part < fParts.end(); part++) 1.48 + delete *part; 1.49 +} 1.50 + 1.51 +bool SkDrawPath::addChild(SkAnimateMaker& maker, SkDisplayable* child) { 1.52 + SkASSERT(child && child->isPathPart()); 1.53 + SkPathPart* part = (SkPathPart*) child; 1.54 + *fParts.append() = part; 1.55 + if (part->add()) 1.56 + maker.setErrorCode(SkDisplayXMLParserError::kErrorAddingToPath); 1.57 + fDirty = false; 1.58 + return true; 1.59 +} 1.60 + 1.61 +bool SkDrawPath::childrenNeedDisposing() const { 1.62 + return false; 1.63 +} 1.64 + 1.65 +void SkDrawPath::dirty() { 1.66 + fDirty = true; 1.67 + fLength = SK_ScalarNaN; 1.68 + if (fParent) 1.69 + fParent->dirty(); 1.70 +} 1.71 + 1.72 +bool SkDrawPath::draw(SkAnimateMaker& maker) { 1.73 + SkPath& path = getPath(); 1.74 + SkBoundableAuto boundable(this, maker); 1.75 + maker.fCanvas->drawPath(path, *maker.fPaint); 1.76 + return false; 1.77 +} 1.78 + 1.79 +SkDisplayable* SkDrawPath::getParent() const { 1.80 + return fParent; 1.81 +} 1.82 + 1.83 +#ifdef SK_DUMP_ENABLED 1.84 +void SkDrawPath::dump(SkAnimateMaker* maker) { 1.85 + dumpBase(maker); 1.86 + dumpAttrs(maker); 1.87 + bool closedYet = false; 1.88 + SkDisplayList::fIndent += 4; 1.89 + for(SkPathPart** part = fParts.begin(); part < fParts.end(); part++) { 1.90 + if (closedYet == false) { 1.91 + SkDebugf(">\n"); 1.92 + closedYet = true; 1.93 + } 1.94 + (*part)->dump(maker); 1.95 + } 1.96 + SkDisplayList::fIndent -= 4; 1.97 + if (closedYet) 1.98 + dumpEnd(maker); 1.99 + else 1.100 + SkDebugf("/>\n"); 1.101 +} 1.102 +#endif 1.103 + 1.104 +SkPath& SkDrawPath::getPath() { 1.105 + if (fDirty == false) 1.106 + return fPath; 1.107 + if (d.size() > 0) 1.108 + { 1.109 + parseSVG(); 1.110 + d.reset(); 1.111 + } 1.112 + else 1.113 + { 1.114 + fPath.reset(); 1.115 + for (SkPathPart** part = fParts.begin(); part < fParts.end(); part++) 1.116 + (*part)->add(); 1.117 + } 1.118 + fDirty = false; 1.119 + return fPath; 1.120 +} 1.121 + 1.122 +void SkDrawPath::onEndElement(SkAnimateMaker& ) { 1.123 + if (d.size() > 0) { 1.124 + parseSVG(); 1.125 + d.reset(); 1.126 + fDirty = false; 1.127 + return; 1.128 + } 1.129 + if (fChildHasID == false) { 1.130 + for (SkPathPart** part = fParts.begin(); part < fParts.end(); part++) 1.131 + delete *part; 1.132 + fParts.reset(); 1.133 + fDirty = false; 1.134 + } 1.135 +} 1.136 + 1.137 +bool SkDrawPath::getProperty(int index, SkScriptValue* value) const { 1.138 + switch (index) { 1.139 + case SK_PROPERTY(length): 1.140 + if (SkScalarIsNaN(fLength)) { 1.141 + const SkPath& path = ((SkDrawPath*) this)->getPath(); 1.142 + SkPathMeasure pathMeasure(path, false); 1.143 + fLength = pathMeasure.getLength(); 1.144 + } 1.145 + value->fType = SkType_Float; 1.146 + value->fOperand.fScalar = fLength; 1.147 + break; 1.148 + case SK_PROPERTY(fillType): 1.149 + value->fType = SkType_FillType; 1.150 + value->fOperand.fS32 = (int) fPath.getFillType(); 1.151 + break; 1.152 + default: 1.153 + SkASSERT(0); 1.154 + return false; 1.155 + } 1.156 + return true; 1.157 +} 1.158 + 1.159 +void SkDrawPath::setChildHasID() { 1.160 + fChildHasID = true; 1.161 +} 1.162 + 1.163 +bool SkDrawPath::setParent(SkDisplayable* parent) { 1.164 + fParent = parent; 1.165 + return false; 1.166 +} 1.167 + 1.168 +bool SkDrawPath::setProperty(int index, SkScriptValue& value) 1.169 +{ 1.170 + switch (index) { 1.171 + case SK_PROPERTY(fillType): 1.172 + SkASSERT(value.fType == SkType_FillType); 1.173 + SkASSERT(value.fOperand.fS32 >= SkPath::kWinding_FillType && 1.174 + value.fOperand.fS32 <= SkPath::kEvenOdd_FillType); 1.175 + fPath.setFillType((SkPath::FillType) value.fOperand.fS32); 1.176 + break; 1.177 + default: 1.178 + SkASSERT(0); 1.179 + return false; 1.180 + } 1.181 + return true; 1.182 +} 1.183 + 1.184 +#if SK_USE_CONDENSED_INFO == 0 1.185 + 1.186 +const SkMemberInfo SkPolyline::fInfo[] = { 1.187 + SK_MEMBER_ARRAY(points, Float) 1.188 +}; 1.189 + 1.190 +#endif 1.191 + 1.192 +DEFINE_GET_MEMBER(SkPolyline); 1.193 + 1.194 +bool SkPolyline::addChild(SkAnimateMaker& , SkDisplayable*) { 1.195 + return false; 1.196 +} 1.197 + 1.198 +void SkPolyline::onEndElement(SkAnimateMaker& maker) { 1.199 + INHERITED::onEndElement(maker); 1.200 + if (points.count() <= 0) 1.201 + return; 1.202 + fPath.reset(); 1.203 + fPath.moveTo(points[0], points[1]); 1.204 + int count = points.count(); 1.205 + for (int index = 2; index < count; index += 2) 1.206 + fPath.lineTo(points[index], points[index+1]); 1.207 +} 1.208 + 1.209 + 1.210 +#if SK_USE_CONDENSED_INFO == 0 1.211 + 1.212 +const SkMemberInfo SkPolygon::fInfo[] = { 1.213 + SK_MEMBER_INHERITED 1.214 +}; 1.215 + 1.216 +#endif 1.217 + 1.218 +DEFINE_GET_MEMBER(SkPolygon); 1.219 + 1.220 +void SkPolygon::onEndElement(SkAnimateMaker& maker) { 1.221 + INHERITED::onEndElement(maker); 1.222 + fPath.close(); 1.223 +}