Thu, 15 Jan 2015 15:55:04 +0100
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 "SkMatrixParts.h" |
michael@0 | 11 | #include "SkAnimateMaker.h" |
michael@0 | 12 | #include "SkDrawMatrix.h" |
michael@0 | 13 | #include "SkDrawRectangle.h" |
michael@0 | 14 | #include "SkDrawPath.h" |
michael@0 | 15 | |
michael@0 | 16 | SkMatrixPart::SkMatrixPart() : fMatrix(NULL) { |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | void SkMatrixPart::dirty() { |
michael@0 | 20 | fMatrix->dirty(); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | SkDisplayable* SkMatrixPart::getParent() const { |
michael@0 | 24 | return fMatrix; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | bool SkMatrixPart::setParent(SkDisplayable* parent) { |
michael@0 | 28 | SkASSERT(parent != NULL); |
michael@0 | 29 | if (parent->isMatrix() == false) |
michael@0 | 30 | return true; |
michael@0 | 31 | fMatrix = (SkDrawMatrix*) parent; |
michael@0 | 32 | return false; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | |
michael@0 | 36 | #if SK_USE_CONDENSED_INFO == 0 |
michael@0 | 37 | |
michael@0 | 38 | const SkMemberInfo SkRotate::fInfo[] = { |
michael@0 | 39 | SK_MEMBER(center, Point), |
michael@0 | 40 | SK_MEMBER(degrees, Float) |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | #endif |
michael@0 | 44 | |
michael@0 | 45 | DEFINE_GET_MEMBER(SkRotate); |
michael@0 | 46 | |
michael@0 | 47 | SkRotate::SkRotate() : degrees(0) { |
michael@0 | 48 | center.fX = center.fY = 0; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | bool SkRotate::add() { |
michael@0 | 52 | fMatrix->rotate(degrees, center); |
michael@0 | 53 | return false; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | |
michael@0 | 57 | #if SK_USE_CONDENSED_INFO == 0 |
michael@0 | 58 | |
michael@0 | 59 | const SkMemberInfo SkScale::fInfo[] = { |
michael@0 | 60 | SK_MEMBER(center, Point), |
michael@0 | 61 | SK_MEMBER(x, Float), |
michael@0 | 62 | SK_MEMBER(y, Float) |
michael@0 | 63 | }; |
michael@0 | 64 | |
michael@0 | 65 | #endif |
michael@0 | 66 | |
michael@0 | 67 | DEFINE_GET_MEMBER(SkScale); |
michael@0 | 68 | |
michael@0 | 69 | SkScale::SkScale() : x(SK_Scalar1), y(SK_Scalar1) { |
michael@0 | 70 | center.fX = center.fY = 0; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | bool SkScale::add() { |
michael@0 | 74 | fMatrix->scale(x, y, center); |
michael@0 | 75 | return false; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | |
michael@0 | 79 | #if SK_USE_CONDENSED_INFO == 0 |
michael@0 | 80 | |
michael@0 | 81 | const SkMemberInfo SkSkew::fInfo[] = { |
michael@0 | 82 | SK_MEMBER(center, Point), |
michael@0 | 83 | SK_MEMBER(x, Float), |
michael@0 | 84 | SK_MEMBER(y, Float) |
michael@0 | 85 | }; |
michael@0 | 86 | |
michael@0 | 87 | #endif |
michael@0 | 88 | |
michael@0 | 89 | DEFINE_GET_MEMBER(SkSkew); |
michael@0 | 90 | |
michael@0 | 91 | SkSkew::SkSkew() : x(0), y(0) { |
michael@0 | 92 | center.fX = center.fY = 0; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | bool SkSkew::add() { |
michael@0 | 96 | fMatrix->skew(x, y, center); |
michael@0 | 97 | return false; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | |
michael@0 | 101 | #if SK_USE_CONDENSED_INFO == 0 |
michael@0 | 102 | |
michael@0 | 103 | const SkMemberInfo SkTranslate::fInfo[] = { |
michael@0 | 104 | SK_MEMBER(x, Float), |
michael@0 | 105 | SK_MEMBER(y, Float) |
michael@0 | 106 | }; |
michael@0 | 107 | |
michael@0 | 108 | #endif |
michael@0 | 109 | |
michael@0 | 110 | DEFINE_GET_MEMBER(SkTranslate); |
michael@0 | 111 | |
michael@0 | 112 | SkTranslate::SkTranslate() : x(0), y(0) { |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | bool SkTranslate::add() { |
michael@0 | 116 | fMatrix->translate(x, y); |
michael@0 | 117 | return false; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | |
michael@0 | 121 | #if SK_USE_CONDENSED_INFO == 0 |
michael@0 | 122 | |
michael@0 | 123 | const SkMemberInfo SkFromPath::fInfo[] = { |
michael@0 | 124 | SK_MEMBER(mode, FromPathMode), |
michael@0 | 125 | SK_MEMBER(offset, Float), |
michael@0 | 126 | SK_MEMBER(path, Path) |
michael@0 | 127 | }; |
michael@0 | 128 | |
michael@0 | 129 | #endif |
michael@0 | 130 | |
michael@0 | 131 | DEFINE_GET_MEMBER(SkFromPath); |
michael@0 | 132 | |
michael@0 | 133 | SkFromPath::SkFromPath() : |
michael@0 | 134 | mode(0), offset(0), path(NULL) { |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | SkFromPath::~SkFromPath() { |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | bool SkFromPath::add() { |
michael@0 | 141 | if (path == NULL) |
michael@0 | 142 | return true; |
michael@0 | 143 | static const uint8_t gFlags[] = { |
michael@0 | 144 | SkPathMeasure::kGetPosAndTan_MatrixFlag, // normal |
michael@0 | 145 | SkPathMeasure::kGetTangent_MatrixFlag, // angle |
michael@0 | 146 | SkPathMeasure::kGetPosition_MatrixFlag // position |
michael@0 | 147 | }; |
michael@0 | 148 | if ((unsigned)mode >= SK_ARRAY_COUNT(gFlags)) |
michael@0 | 149 | return true; |
michael@0 | 150 | SkMatrix result; |
michael@0 | 151 | fPathMeasure.setPath(&path->getPath(), false); |
michael@0 | 152 | if (fPathMeasure.getMatrix(offset, &result, (SkPathMeasure::MatrixFlags)gFlags[mode])) |
michael@0 | 153 | fMatrix->set(result); |
michael@0 | 154 | return false; |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | |
michael@0 | 158 | #if SK_USE_CONDENSED_INFO == 0 |
michael@0 | 159 | |
michael@0 | 160 | const SkMemberInfo SkRectToRect::fInfo[] = { |
michael@0 | 161 | SK_MEMBER(destination, Rect), |
michael@0 | 162 | SK_MEMBER(source, Rect) |
michael@0 | 163 | }; |
michael@0 | 164 | |
michael@0 | 165 | #endif |
michael@0 | 166 | |
michael@0 | 167 | DEFINE_GET_MEMBER(SkRectToRect); |
michael@0 | 168 | |
michael@0 | 169 | SkRectToRect::SkRectToRect() : |
michael@0 | 170 | source(NULL), destination(NULL) { |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | SkRectToRect::~SkRectToRect() { |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | bool SkRectToRect::add() { |
michael@0 | 177 | if (source == NULL || destination == NULL) |
michael@0 | 178 | return true; |
michael@0 | 179 | SkMatrix temp; |
michael@0 | 180 | temp.setRectToRect(source->fRect, destination->fRect, |
michael@0 | 181 | SkMatrix::kFill_ScaleToFit); |
michael@0 | 182 | fMatrix->set(temp); |
michael@0 | 183 | return false; |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | #ifdef SK_DUMP_ENABLED |
michael@0 | 187 | void SkRectToRect::dump(SkAnimateMaker* maker) { |
michael@0 | 188 | dumpBase(maker); |
michael@0 | 189 | SkDebugf("/>\n"); |
michael@0 | 190 | SkDisplayList::fIndent += 4; |
michael@0 | 191 | if (source) { |
michael@0 | 192 | SkDebugf("%*s<source>\n", SkDisplayList::fIndent, ""); |
michael@0 | 193 | SkDisplayList::fIndent += 4; |
michael@0 | 194 | source->dump(maker); |
michael@0 | 195 | SkDisplayList::fIndent -= 4; |
michael@0 | 196 | SkDebugf("%*s</source>\n", SkDisplayList::fIndent, ""); |
michael@0 | 197 | } |
michael@0 | 198 | if (destination) { |
michael@0 | 199 | SkDebugf("%*s<destination>\n", SkDisplayList::fIndent, ""); |
michael@0 | 200 | SkDisplayList::fIndent += 4; |
michael@0 | 201 | destination->dump(maker); |
michael@0 | 202 | SkDisplayList::fIndent -= 4; |
michael@0 | 203 | SkDebugf("%*s</destination>\n", SkDisplayList::fIndent, ""); |
michael@0 | 204 | } |
michael@0 | 205 | SkDisplayList::fIndent -= 4; |
michael@0 | 206 | dumpEnd(maker); |
michael@0 | 207 | } |
michael@0 | 208 | #endif |
michael@0 | 209 | |
michael@0 | 210 | const SkMemberInfo* SkRectToRect::preferredChild(SkDisplayTypes ) { |
michael@0 | 211 | if (source == NULL) |
michael@0 | 212 | return getMember("source"); // !!! cwap! need to refer to member through enum like kScope instead |
michael@0 | 213 | else { |
michael@0 | 214 | SkASSERT(destination == NULL); |
michael@0 | 215 | return getMember("destination"); |
michael@0 | 216 | } |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | |
michael@0 | 220 | #if SK_USE_CONDENSED_INFO == 0 |
michael@0 | 221 | |
michael@0 | 222 | const SkMemberInfo SkPolyToPoly::fInfo[] = { |
michael@0 | 223 | SK_MEMBER(destination, Polygon), |
michael@0 | 224 | SK_MEMBER(source, Polygon) |
michael@0 | 225 | }; |
michael@0 | 226 | |
michael@0 | 227 | #endif |
michael@0 | 228 | |
michael@0 | 229 | DEFINE_GET_MEMBER(SkPolyToPoly); |
michael@0 | 230 | |
michael@0 | 231 | SkPolyToPoly::SkPolyToPoly() : source(NULL), destination(NULL) { |
michael@0 | 232 | } |
michael@0 | 233 | |
michael@0 | 234 | SkPolyToPoly::~SkPolyToPoly() { |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | bool SkPolyToPoly::add() { |
michael@0 | 238 | SkASSERT(source); |
michael@0 | 239 | SkASSERT(destination); |
michael@0 | 240 | SkPoint src[4]; |
michael@0 | 241 | SkPoint dst[4]; |
michael@0 | 242 | SkPath& sourcePath = source->getPath(); |
michael@0 | 243 | int srcPts = sourcePath.getPoints(src, 4); |
michael@0 | 244 | SkPath& destPath = destination->getPath(); |
michael@0 | 245 | int dstPts = destPath.getPoints(dst, 4); |
michael@0 | 246 | if (srcPts != dstPts) |
michael@0 | 247 | return true; |
michael@0 | 248 | SkMatrix temp; |
michael@0 | 249 | temp.setPolyToPoly(src, dst, srcPts); |
michael@0 | 250 | fMatrix->set(temp); |
michael@0 | 251 | return false; |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | #ifdef SK_DUMP_ENABLED |
michael@0 | 255 | void SkPolyToPoly::dump(SkAnimateMaker* maker) { |
michael@0 | 256 | dumpBase(maker); |
michael@0 | 257 | SkDebugf("/>\n"); |
michael@0 | 258 | SkDisplayList::fIndent += 4; |
michael@0 | 259 | if (source) { |
michael@0 | 260 | SkDebugf("%*s<source>\n", SkDisplayList::fIndent, ""); |
michael@0 | 261 | SkDisplayList::fIndent += 4; |
michael@0 | 262 | source->dump(maker); |
michael@0 | 263 | SkDisplayList::fIndent -= 4; |
michael@0 | 264 | SkDebugf("%*s</source>\n", SkDisplayList::fIndent, ""); |
michael@0 | 265 | } |
michael@0 | 266 | if (destination) { |
michael@0 | 267 | SkDebugf("%*s<destination>\n", SkDisplayList::fIndent, ""); |
michael@0 | 268 | SkDisplayList::fIndent += 4; |
michael@0 | 269 | destination->dump(maker); |
michael@0 | 270 | SkDisplayList::fIndent -= 4; |
michael@0 | 271 | SkDebugf("%*s</destination>\n", SkDisplayList::fIndent, ""); |
michael@0 | 272 | } |
michael@0 | 273 | SkDisplayList::fIndent -= 4; |
michael@0 | 274 | dumpEnd(maker); |
michael@0 | 275 | } |
michael@0 | 276 | #endif |
michael@0 | 277 | |
michael@0 | 278 | void SkPolyToPoly::onEndElement(SkAnimateMaker& ) { |
michael@0 | 279 | SkASSERT(source); |
michael@0 | 280 | SkASSERT(destination); |
michael@0 | 281 | if (source->childHasID() || destination->childHasID()) |
michael@0 | 282 | fMatrix->setChildHasID(); |
michael@0 | 283 | } |
michael@0 | 284 | |
michael@0 | 285 | const SkMemberInfo* SkPolyToPoly::preferredChild(SkDisplayTypes ) { |
michael@0 | 286 | if (source == NULL) |
michael@0 | 287 | return getMember("source"); // !!! cwap! need to refer to member through enum like kScope instead |
michael@0 | 288 | else { |
michael@0 | 289 | SkASSERT(destination == NULL); |
michael@0 | 290 | return getMember("destination"); |
michael@0 | 291 | } |
michael@0 | 292 | } |