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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/animator/SkMatrixParts.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,292 @@
     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 "SkMatrixParts.h"
    1.14 +#include "SkAnimateMaker.h"
    1.15 +#include "SkDrawMatrix.h"
    1.16 +#include "SkDrawRectangle.h"
    1.17 +#include "SkDrawPath.h"
    1.18 +
    1.19 +SkMatrixPart::SkMatrixPart() : fMatrix(NULL) {
    1.20 +}
    1.21 +
    1.22 +void SkMatrixPart::dirty() {
    1.23 +    fMatrix->dirty();
    1.24 +}
    1.25 +
    1.26 +SkDisplayable* SkMatrixPart::getParent() const {
    1.27 +    return fMatrix;
    1.28 +}
    1.29 +
    1.30 +bool SkMatrixPart::setParent(SkDisplayable* parent) {
    1.31 +    SkASSERT(parent != NULL);
    1.32 +    if (parent->isMatrix() == false)
    1.33 +        return true;
    1.34 +    fMatrix = (SkDrawMatrix*) parent;
    1.35 +    return false;
    1.36 +}
    1.37 +
    1.38 +
    1.39 +#if SK_USE_CONDENSED_INFO == 0
    1.40 +
    1.41 +const SkMemberInfo SkRotate::fInfo[] = {
    1.42 +    SK_MEMBER(center, Point),
    1.43 +    SK_MEMBER(degrees, Float)
    1.44 +};
    1.45 +
    1.46 +#endif
    1.47 +
    1.48 +DEFINE_GET_MEMBER(SkRotate);
    1.49 +
    1.50 +SkRotate::SkRotate() : degrees(0) {
    1.51 +    center.fX = center.fY = 0;
    1.52 +}
    1.53 +
    1.54 +bool SkRotate::add() {
    1.55 +    fMatrix->rotate(degrees, center);
    1.56 +    return false;
    1.57 +}
    1.58 +
    1.59 +
    1.60 +#if SK_USE_CONDENSED_INFO == 0
    1.61 +
    1.62 +const SkMemberInfo SkScale::fInfo[] = {
    1.63 +    SK_MEMBER(center, Point),
    1.64 +    SK_MEMBER(x, Float),
    1.65 +    SK_MEMBER(y, Float)
    1.66 +};
    1.67 +
    1.68 +#endif
    1.69 +
    1.70 +DEFINE_GET_MEMBER(SkScale);
    1.71 +
    1.72 +SkScale::SkScale() : x(SK_Scalar1), y(SK_Scalar1) {
    1.73 +    center.fX = center.fY = 0;
    1.74 +}
    1.75 +
    1.76 +bool SkScale::add() {
    1.77 +    fMatrix->scale(x, y, center);
    1.78 +    return false;
    1.79 +}
    1.80 +
    1.81 +
    1.82 +#if SK_USE_CONDENSED_INFO == 0
    1.83 +
    1.84 +const SkMemberInfo SkSkew::fInfo[] = {
    1.85 +    SK_MEMBER(center, Point),
    1.86 +    SK_MEMBER(x, Float),
    1.87 +    SK_MEMBER(y, Float)
    1.88 +};
    1.89 +
    1.90 +#endif
    1.91 +
    1.92 +DEFINE_GET_MEMBER(SkSkew);
    1.93 +
    1.94 +SkSkew::SkSkew() : x(0), y(0) {
    1.95 +    center.fX = center.fY = 0;
    1.96 +}
    1.97 +
    1.98 +bool SkSkew::add() {
    1.99 +    fMatrix->skew(x, y, center);
   1.100 +    return false;
   1.101 +}
   1.102 +
   1.103 +
   1.104 +#if SK_USE_CONDENSED_INFO == 0
   1.105 +
   1.106 +const SkMemberInfo SkTranslate::fInfo[] = {
   1.107 +    SK_MEMBER(x, Float),
   1.108 +    SK_MEMBER(y, Float)
   1.109 +};
   1.110 +
   1.111 +#endif
   1.112 +
   1.113 +DEFINE_GET_MEMBER(SkTranslate);
   1.114 +
   1.115 +SkTranslate::SkTranslate() : x(0), y(0) {
   1.116 +}
   1.117 +
   1.118 +bool SkTranslate::add() {
   1.119 +    fMatrix->translate(x, y);
   1.120 +    return false;
   1.121 +}
   1.122 +
   1.123 +
   1.124 +#if SK_USE_CONDENSED_INFO == 0
   1.125 +
   1.126 +const SkMemberInfo SkFromPath::fInfo[] = {
   1.127 +    SK_MEMBER(mode, FromPathMode),
   1.128 +    SK_MEMBER(offset, Float),
   1.129 +    SK_MEMBER(path, Path)
   1.130 +};
   1.131 +
   1.132 +#endif
   1.133 +
   1.134 +DEFINE_GET_MEMBER(SkFromPath);
   1.135 +
   1.136 +SkFromPath::SkFromPath() :
   1.137 +    mode(0), offset(0), path(NULL) {
   1.138 +}
   1.139 +
   1.140 +SkFromPath::~SkFromPath() {
   1.141 +}
   1.142 +
   1.143 +bool SkFromPath::add() {
   1.144 +    if (path == NULL)
   1.145 +        return true;
   1.146 +    static const uint8_t gFlags[] = {
   1.147 +        SkPathMeasure::kGetPosAndTan_MatrixFlag,    // normal
   1.148 +        SkPathMeasure::kGetTangent_MatrixFlag,      // angle
   1.149 +        SkPathMeasure::kGetPosition_MatrixFlag      // position
   1.150 +    };
   1.151 +    if ((unsigned)mode >= SK_ARRAY_COUNT(gFlags))
   1.152 +        return true;
   1.153 +    SkMatrix result;
   1.154 +    fPathMeasure.setPath(&path->getPath(), false);
   1.155 +    if (fPathMeasure.getMatrix(offset, &result, (SkPathMeasure::MatrixFlags)gFlags[mode]))
   1.156 +        fMatrix->set(result);
   1.157 +    return false;
   1.158 +}
   1.159 +
   1.160 +
   1.161 +#if SK_USE_CONDENSED_INFO == 0
   1.162 +
   1.163 +const SkMemberInfo SkRectToRect::fInfo[] = {
   1.164 +    SK_MEMBER(destination, Rect),
   1.165 +    SK_MEMBER(source, Rect)
   1.166 +};
   1.167 +
   1.168 +#endif
   1.169 +
   1.170 +DEFINE_GET_MEMBER(SkRectToRect);
   1.171 +
   1.172 +SkRectToRect::SkRectToRect() :
   1.173 +    source(NULL), destination(NULL) {
   1.174 +}
   1.175 +
   1.176 +SkRectToRect::~SkRectToRect() {
   1.177 +}
   1.178 +
   1.179 +bool SkRectToRect::add() {
   1.180 +    if (source == NULL || destination == NULL)
   1.181 +        return true;
   1.182 +    SkMatrix temp;
   1.183 +    temp.setRectToRect(source->fRect, destination->fRect,
   1.184 +                       SkMatrix::kFill_ScaleToFit);
   1.185 +    fMatrix->set(temp);
   1.186 +    return false;
   1.187 +}
   1.188 +
   1.189 +#ifdef SK_DUMP_ENABLED
   1.190 +void SkRectToRect::dump(SkAnimateMaker* maker) {
   1.191 +    dumpBase(maker);
   1.192 +    SkDebugf("/>\n");
   1.193 +    SkDisplayList::fIndent += 4;
   1.194 +    if (source) {
   1.195 +        SkDebugf("%*s<source>\n", SkDisplayList::fIndent, "");
   1.196 +        SkDisplayList::fIndent += 4;
   1.197 +        source->dump(maker);
   1.198 +        SkDisplayList::fIndent -= 4;
   1.199 +        SkDebugf("%*s</source>\n", SkDisplayList::fIndent, "");
   1.200 +    }
   1.201 +    if (destination) {
   1.202 +        SkDebugf("%*s<destination>\n", SkDisplayList::fIndent, "");
   1.203 +        SkDisplayList::fIndent += 4;
   1.204 +        destination->dump(maker);
   1.205 +        SkDisplayList::fIndent -= 4;
   1.206 +        SkDebugf("%*s</destination>\n", SkDisplayList::fIndent, "");
   1.207 +    }
   1.208 +    SkDisplayList::fIndent -= 4;
   1.209 +    dumpEnd(maker);
   1.210 +}
   1.211 +#endif
   1.212 +
   1.213 +const SkMemberInfo* SkRectToRect::preferredChild(SkDisplayTypes ) {
   1.214 +    if (source == NULL)
   1.215 +        return getMember("source"); // !!! cwap! need to refer to member through enum like kScope instead
   1.216 +    else {
   1.217 +        SkASSERT(destination == NULL);
   1.218 +        return getMember("destination");
   1.219 +    }
   1.220 +}
   1.221 +
   1.222 +
   1.223 +#if SK_USE_CONDENSED_INFO == 0
   1.224 +
   1.225 +const SkMemberInfo SkPolyToPoly::fInfo[] = {
   1.226 +    SK_MEMBER(destination, Polygon),
   1.227 +    SK_MEMBER(source, Polygon)
   1.228 +};
   1.229 +
   1.230 +#endif
   1.231 +
   1.232 +DEFINE_GET_MEMBER(SkPolyToPoly);
   1.233 +
   1.234 +SkPolyToPoly::SkPolyToPoly() : source(NULL), destination(NULL) {
   1.235 +}
   1.236 +
   1.237 +SkPolyToPoly::~SkPolyToPoly() {
   1.238 +}
   1.239 +
   1.240 +bool SkPolyToPoly::add() {
   1.241 +    SkASSERT(source);
   1.242 +    SkASSERT(destination);
   1.243 +    SkPoint src[4];
   1.244 +    SkPoint dst[4];
   1.245 +    SkPath& sourcePath = source->getPath();
   1.246 +    int srcPts = sourcePath.getPoints(src, 4);
   1.247 +    SkPath& destPath = destination->getPath();
   1.248 +    int dstPts = destPath.getPoints(dst, 4);
   1.249 +    if (srcPts != dstPts)
   1.250 +        return true;
   1.251 +    SkMatrix temp;
   1.252 +    temp.setPolyToPoly(src, dst, srcPts);
   1.253 +    fMatrix->set(temp);
   1.254 +    return false;
   1.255 +}
   1.256 +
   1.257 +#ifdef SK_DUMP_ENABLED
   1.258 +void SkPolyToPoly::dump(SkAnimateMaker* maker) {
   1.259 +    dumpBase(maker);
   1.260 +    SkDebugf("/>\n");
   1.261 +    SkDisplayList::fIndent += 4;
   1.262 +    if (source) {
   1.263 +        SkDebugf("%*s<source>\n", SkDisplayList::fIndent, "");
   1.264 +        SkDisplayList::fIndent += 4;
   1.265 +        source->dump(maker);
   1.266 +        SkDisplayList::fIndent -= 4;
   1.267 +        SkDebugf("%*s</source>\n", SkDisplayList::fIndent, "");
   1.268 +    }
   1.269 +    if (destination) {
   1.270 +        SkDebugf("%*s<destination>\n", SkDisplayList::fIndent, "");
   1.271 +        SkDisplayList::fIndent += 4;
   1.272 +        destination->dump(maker);
   1.273 +        SkDisplayList::fIndent -= 4;
   1.274 +        SkDebugf("%*s</destination>\n", SkDisplayList::fIndent, "");
   1.275 +    }
   1.276 +    SkDisplayList::fIndent -= 4;
   1.277 +    dumpEnd(maker);
   1.278 +}
   1.279 +#endif
   1.280 +
   1.281 +void SkPolyToPoly::onEndElement(SkAnimateMaker& ) {
   1.282 +    SkASSERT(source);
   1.283 +    SkASSERT(destination);
   1.284 +    if (source->childHasID() || destination->childHasID())
   1.285 +        fMatrix->setChildHasID();
   1.286 +}
   1.287 +
   1.288 +const SkMemberInfo* SkPolyToPoly::preferredChild(SkDisplayTypes ) {
   1.289 +    if (source == NULL)
   1.290 +        return getMember("source"); // !!! cwap! need to refer to member through enum like kScope instead
   1.291 +    else {
   1.292 +        SkASSERT(destination == NULL);
   1.293 +        return getMember("destination");
   1.294 +    }
   1.295 +}

mercurial