gfx/skia/trunk/src/animator/SkDrawPath.cpp

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "SkDrawPath.h"
michael@0 11 #include "SkAnimateMaker.h"
michael@0 12 #include "SkCanvas.h"
michael@0 13 #include "SkMath.h"
michael@0 14 #include "SkMatrixParts.h"
michael@0 15 #include "SkPaint.h"
michael@0 16 #include "SkPathParts.h"
michael@0 17
michael@0 18 enum SkPath_Properties {
michael@0 19 SK_PROPERTY(fillType),
michael@0 20 SK_PROPERTY(length)
michael@0 21 };
michael@0 22
michael@0 23 #if SK_USE_CONDENSED_INFO == 0
michael@0 24
michael@0 25 const SkMemberInfo SkDrawPath::fInfo[] = {
michael@0 26 SK_MEMBER(d, String),
michael@0 27 SK_MEMBER_PROPERTY(fillType, FillType),
michael@0 28 SK_MEMBER_PROPERTY(length, Float)
michael@0 29 };
michael@0 30
michael@0 31 #endif
michael@0 32
michael@0 33 DEFINE_GET_MEMBER(SkDrawPath);
michael@0 34
michael@0 35 SkDrawPath::SkDrawPath()
michael@0 36 {
michael@0 37 fParent = NULL;
michael@0 38 fLength = SK_ScalarNaN;
michael@0 39 fChildHasID = false;
michael@0 40 fDirty = false;
michael@0 41 }
michael@0 42
michael@0 43 SkDrawPath::~SkDrawPath() {
michael@0 44 for (SkPathPart** part = fParts.begin(); part < fParts.end(); part++)
michael@0 45 delete *part;
michael@0 46 }
michael@0 47
michael@0 48 bool SkDrawPath::addChild(SkAnimateMaker& maker, SkDisplayable* child) {
michael@0 49 SkASSERT(child && child->isPathPart());
michael@0 50 SkPathPart* part = (SkPathPart*) child;
michael@0 51 *fParts.append() = part;
michael@0 52 if (part->add())
michael@0 53 maker.setErrorCode(SkDisplayXMLParserError::kErrorAddingToPath);
michael@0 54 fDirty = false;
michael@0 55 return true;
michael@0 56 }
michael@0 57
michael@0 58 bool SkDrawPath::childrenNeedDisposing() const {
michael@0 59 return false;
michael@0 60 }
michael@0 61
michael@0 62 void SkDrawPath::dirty() {
michael@0 63 fDirty = true;
michael@0 64 fLength = SK_ScalarNaN;
michael@0 65 if (fParent)
michael@0 66 fParent->dirty();
michael@0 67 }
michael@0 68
michael@0 69 bool SkDrawPath::draw(SkAnimateMaker& maker) {
michael@0 70 SkPath& path = getPath();
michael@0 71 SkBoundableAuto boundable(this, maker);
michael@0 72 maker.fCanvas->drawPath(path, *maker.fPaint);
michael@0 73 return false;
michael@0 74 }
michael@0 75
michael@0 76 SkDisplayable* SkDrawPath::getParent() const {
michael@0 77 return fParent;
michael@0 78 }
michael@0 79
michael@0 80 #ifdef SK_DUMP_ENABLED
michael@0 81 void SkDrawPath::dump(SkAnimateMaker* maker) {
michael@0 82 dumpBase(maker);
michael@0 83 dumpAttrs(maker);
michael@0 84 bool closedYet = false;
michael@0 85 SkDisplayList::fIndent += 4;
michael@0 86 for(SkPathPart** part = fParts.begin(); part < fParts.end(); part++) {
michael@0 87 if (closedYet == false) {
michael@0 88 SkDebugf(">\n");
michael@0 89 closedYet = true;
michael@0 90 }
michael@0 91 (*part)->dump(maker);
michael@0 92 }
michael@0 93 SkDisplayList::fIndent -= 4;
michael@0 94 if (closedYet)
michael@0 95 dumpEnd(maker);
michael@0 96 else
michael@0 97 SkDebugf("/>\n");
michael@0 98 }
michael@0 99 #endif
michael@0 100
michael@0 101 SkPath& SkDrawPath::getPath() {
michael@0 102 if (fDirty == false)
michael@0 103 return fPath;
michael@0 104 if (d.size() > 0)
michael@0 105 {
michael@0 106 parseSVG();
michael@0 107 d.reset();
michael@0 108 }
michael@0 109 else
michael@0 110 {
michael@0 111 fPath.reset();
michael@0 112 for (SkPathPart** part = fParts.begin(); part < fParts.end(); part++)
michael@0 113 (*part)->add();
michael@0 114 }
michael@0 115 fDirty = false;
michael@0 116 return fPath;
michael@0 117 }
michael@0 118
michael@0 119 void SkDrawPath::onEndElement(SkAnimateMaker& ) {
michael@0 120 if (d.size() > 0) {
michael@0 121 parseSVG();
michael@0 122 d.reset();
michael@0 123 fDirty = false;
michael@0 124 return;
michael@0 125 }
michael@0 126 if (fChildHasID == false) {
michael@0 127 for (SkPathPart** part = fParts.begin(); part < fParts.end(); part++)
michael@0 128 delete *part;
michael@0 129 fParts.reset();
michael@0 130 fDirty = false;
michael@0 131 }
michael@0 132 }
michael@0 133
michael@0 134 bool SkDrawPath::getProperty(int index, SkScriptValue* value) const {
michael@0 135 switch (index) {
michael@0 136 case SK_PROPERTY(length):
michael@0 137 if (SkScalarIsNaN(fLength)) {
michael@0 138 const SkPath& path = ((SkDrawPath*) this)->getPath();
michael@0 139 SkPathMeasure pathMeasure(path, false);
michael@0 140 fLength = pathMeasure.getLength();
michael@0 141 }
michael@0 142 value->fType = SkType_Float;
michael@0 143 value->fOperand.fScalar = fLength;
michael@0 144 break;
michael@0 145 case SK_PROPERTY(fillType):
michael@0 146 value->fType = SkType_FillType;
michael@0 147 value->fOperand.fS32 = (int) fPath.getFillType();
michael@0 148 break;
michael@0 149 default:
michael@0 150 SkASSERT(0);
michael@0 151 return false;
michael@0 152 }
michael@0 153 return true;
michael@0 154 }
michael@0 155
michael@0 156 void SkDrawPath::setChildHasID() {
michael@0 157 fChildHasID = true;
michael@0 158 }
michael@0 159
michael@0 160 bool SkDrawPath::setParent(SkDisplayable* parent) {
michael@0 161 fParent = parent;
michael@0 162 return false;
michael@0 163 }
michael@0 164
michael@0 165 bool SkDrawPath::setProperty(int index, SkScriptValue& value)
michael@0 166 {
michael@0 167 switch (index) {
michael@0 168 case SK_PROPERTY(fillType):
michael@0 169 SkASSERT(value.fType == SkType_FillType);
michael@0 170 SkASSERT(value.fOperand.fS32 >= SkPath::kWinding_FillType &&
michael@0 171 value.fOperand.fS32 <= SkPath::kEvenOdd_FillType);
michael@0 172 fPath.setFillType((SkPath::FillType) value.fOperand.fS32);
michael@0 173 break;
michael@0 174 default:
michael@0 175 SkASSERT(0);
michael@0 176 return false;
michael@0 177 }
michael@0 178 return true;
michael@0 179 }
michael@0 180
michael@0 181 #if SK_USE_CONDENSED_INFO == 0
michael@0 182
michael@0 183 const SkMemberInfo SkPolyline::fInfo[] = {
michael@0 184 SK_MEMBER_ARRAY(points, Float)
michael@0 185 };
michael@0 186
michael@0 187 #endif
michael@0 188
michael@0 189 DEFINE_GET_MEMBER(SkPolyline);
michael@0 190
michael@0 191 bool SkPolyline::addChild(SkAnimateMaker& , SkDisplayable*) {
michael@0 192 return false;
michael@0 193 }
michael@0 194
michael@0 195 void SkPolyline::onEndElement(SkAnimateMaker& maker) {
michael@0 196 INHERITED::onEndElement(maker);
michael@0 197 if (points.count() <= 0)
michael@0 198 return;
michael@0 199 fPath.reset();
michael@0 200 fPath.moveTo(points[0], points[1]);
michael@0 201 int count = points.count();
michael@0 202 for (int index = 2; index < count; index += 2)
michael@0 203 fPath.lineTo(points[index], points[index+1]);
michael@0 204 }
michael@0 205
michael@0 206
michael@0 207 #if SK_USE_CONDENSED_INFO == 0
michael@0 208
michael@0 209 const SkMemberInfo SkPolygon::fInfo[] = {
michael@0 210 SK_MEMBER_INHERITED
michael@0 211 };
michael@0 212
michael@0 213 #endif
michael@0 214
michael@0 215 DEFINE_GET_MEMBER(SkPolygon);
michael@0 216
michael@0 217 void SkPolygon::onEndElement(SkAnimateMaker& maker) {
michael@0 218 INHERITED::onEndElement(maker);
michael@0 219 fPath.close();
michael@0 220 }

mercurial