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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/animator/SkDisplayAdd.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,245 @@
     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 "SkDisplayAdd.h"
    1.14 +#include "SkAnimateMaker.h"
    1.15 +#include "SkDisplayApply.h"
    1.16 +#include "SkDisplayList.h"
    1.17 +#include "SkDrawable.h"
    1.18 +#include "SkDrawGroup.h"
    1.19 +
    1.20 +#if SK_USE_CONDENSED_INFO == 0
    1.21 +
    1.22 +const SkMemberInfo SkAdd::fInfo[] = {
    1.23 +    SK_MEMBER(mode, AddMode),
    1.24 +    SK_MEMBER(offset, Int),
    1.25 +    SK_MEMBER(use, Drawable),
    1.26 +    SK_MEMBER(where, Drawable)
    1.27 +};
    1.28 +
    1.29 +#endif
    1.30 +
    1.31 +// start here;
    1.32 +// add onEndElement to turn where string into f_Where
    1.33 +// probably need new SkAnimateMaker::resolve flavor that takes
    1.34 +// where="id", where="event-target" or not-specified
    1.35 +// offset="#" (implements before, after, and index if no 'where')
    1.36 +
    1.37 +DEFINE_GET_MEMBER(SkAdd);
    1.38 +
    1.39 +SkAdd::SkAdd() : mode(kMode_indirect),
    1.40 +    offset(SK_MaxS32), use(NULL), where(NULL) {
    1.41 +}
    1.42 +
    1.43 +SkDisplayable* SkAdd::deepCopy(SkAnimateMaker* maker) {
    1.44 +    SkDrawable* saveUse = use;
    1.45 +    SkDrawable* saveWhere = where;
    1.46 +    use = NULL;
    1.47 +    where = NULL;
    1.48 +    SkAdd* copy = (SkAdd*) INHERITED::deepCopy(maker);
    1.49 +    copy->use = use = saveUse;
    1.50 +    copy->where = where = saveWhere;
    1.51 +    return copy;
    1.52 +}
    1.53 +
    1.54 +bool SkAdd::draw(SkAnimateMaker& maker) {
    1.55 +    SkASSERT(use);
    1.56 +    SkASSERT(use->isDrawable());
    1.57 +    if (mode == kMode_indirect)
    1.58 +        use->draw(maker);
    1.59 +    return false;
    1.60 +}
    1.61 +
    1.62 +#ifdef SK_DUMP_ENABLED
    1.63 +void SkAdd::dump(SkAnimateMaker* maker) {
    1.64 +    dumpBase(maker);
    1.65 +    dumpAttrs(maker);
    1.66 +    if (where)
    1.67 +        SkDebugf("where=\"%s\" ", where->id);
    1.68 +    if (mode == kMode_immediate)
    1.69 +        SkDebugf("mode=\"immediate\" ");
    1.70 +    SkDebugf(">\n");
    1.71 +    SkDisplayList::fIndent += 4;
    1.72 +    int save = SkDisplayList::fDumpIndex;
    1.73 +    if (use)    //just in case
    1.74 +        use->dump(maker);
    1.75 +    SkDisplayList::fIndent -= 4;
    1.76 +    SkDisplayList::fDumpIndex = save;
    1.77 +    dumpEnd(maker);
    1.78 +}
    1.79 +#endif
    1.80 +
    1.81 +bool SkAdd::enable(SkAnimateMaker& maker ) {
    1.82 +    SkDisplayTypes type = getType();
    1.83 +    SkDisplayList& displayList = maker.fDisplayList;
    1.84 +    SkTDDrawableArray* parentList = displayList.getDrawList();
    1.85 +    if (type == SkType_Add) {
    1.86 +        if (use == NULL) // not set in apply yet
    1.87 +            return true;
    1.88 +    }
    1.89 +    bool skipAddToParent = true;
    1.90 +    SkASSERT(type != SkType_Replace || where);
    1.91 +    SkTDDrawableArray* grandList SK_INIT_TO_AVOID_WARNING;
    1.92 +    SkGroup* parentGroup = NULL;
    1.93 +    SkGroup* thisGroup = NULL;
    1.94 +    int index = where ? displayList.findGroup(where, &parentList, &parentGroup,
    1.95 +        &thisGroup, &grandList) : 0;
    1.96 +    if (index < 0)
    1.97 +        return true;
    1.98 +    int max = parentList->count();
    1.99 +    if (where == NULL && type == SkType_Move)
   1.100 +        index = max;
   1.101 +    if (offset != SK_MaxS32) {
   1.102 +        index += offset;
   1.103 +        if (index > max) {
   1.104 +            maker.setErrorCode(SkDisplayXMLParserError::kIndexOutOfRange);
   1.105 +            return true;    // caller should not add
   1.106 +        }
   1.107 +    }
   1.108 +    if (offset < 0 && where == NULL)
   1.109 +        index += max + 1;
   1.110 +    switch (type) {
   1.111 +        case SkType_Add:
   1.112 +            if (offset == SK_MaxS32 && where == NULL) {
   1.113 +                if (use->isDrawable()) {
   1.114 +                    skipAddToParent = mode == kMode_immediate;
   1.115 +                    if (skipAddToParent) {
   1.116 +                        if (where == NULL) {
   1.117 +                            SkTDDrawableArray* useParentList;
   1.118 +                            index = displayList.findGroup(this, &useParentList, &parentGroup,
   1.119 +                                &thisGroup, &grandList);
   1.120 +                            if (index >= 0) {
   1.121 +                                parentGroup->markCopySize(index);
   1.122 +                                parentGroup->markCopySet(index);
   1.123 +                                useParentList->begin()[index] = use;
   1.124 +                                break;
   1.125 +                            }
   1.126 +                        }
   1.127 +                        *parentList->append() = use;
   1.128 +                    }
   1.129 +                }
   1.130 +                break;
   1.131 +            } else {
   1.132 +                if (thisGroup)
   1.133 +                    thisGroup->markCopySize(index);
   1.134 +                *parentList->insert(index) = use;
   1.135 +                if (thisGroup)
   1.136 +                    thisGroup->markCopySet(index);
   1.137 +                if (use->isApply())
   1.138 +                    ((SkApply*) use)->setEmbedded();
   1.139 +            }
   1.140 +            break;
   1.141 +        case SkType_Move: {
   1.142 +            int priorLocation = parentList->find(use);
   1.143 +            if (priorLocation < 0)
   1.144 +                break;
   1.145 +            *parentList->insert(index) = use;
   1.146 +            if (index < priorLocation)
   1.147 +                priorLocation++;
   1.148 +            parentList->remove(priorLocation);
   1.149 +            } break;
   1.150 +        case SkType_Remove: {
   1.151 +            SkDisplayable* old = (*parentList)[index];
   1.152 +            if (((SkRemove*)(this))->fDelete) {
   1.153 +                delete old;
   1.154 +                goto noHelperNeeded;
   1.155 +            }
   1.156 +            for (int inner = 0; inner < maker.fChildren.count(); inner++) {
   1.157 +                SkDisplayable* child = maker.fChildren[inner];
   1.158 +                if (child == old || child->contains(old))
   1.159 +                    goto noHelperNeeded;
   1.160 +            }
   1.161 +            if (maker.fHelpers.find(old) < 0)
   1.162 +                maker.helperAdd(old);
   1.163 +noHelperNeeded:
   1.164 +            parentList->remove(index);
   1.165 +            } break;
   1.166 +        case SkType_Replace:
   1.167 +            if (thisGroup) {
   1.168 +                thisGroup->markCopySize(index);
   1.169 +                if (thisGroup->markedForDelete(index)) {
   1.170 +                    SkDisplayable* old = (*parentList)[index];
   1.171 +                    if (maker.fHelpers.find(old) < 0)
   1.172 +                        maker.helperAdd(old);
   1.173 +                }
   1.174 +            }
   1.175 +            (*parentList)[index] = use;
   1.176 +            if (thisGroup)
   1.177 +                thisGroup->markCopySet(index);
   1.178 +            break;
   1.179 +        default:
   1.180 +            SkASSERT(0);
   1.181 +    }
   1.182 +    if (type == SkType_Remove)
   1.183 +        return true;
   1.184 +    if (use->hasEnable())
   1.185 +        use->enable(maker);
   1.186 +    return skipAddToParent; // append if indirect: *parentList->append() = this;
   1.187 +}
   1.188 +
   1.189 +bool SkAdd::hasEnable() const {
   1.190 +    return true;
   1.191 +}
   1.192 +
   1.193 +void SkAdd::initialize() {
   1.194 +    if (use)
   1.195 +        use->initialize();
   1.196 +}
   1.197 +
   1.198 +bool SkAdd::isDrawable() const {
   1.199 +    return getType() == SkType_Add && mode == kMode_indirect && offset == SK_MaxS32 &&
   1.200 +        where == NULL && use != NULL && use->isDrawable();
   1.201 +}
   1.202 +
   1.203 +//SkDisplayable* SkAdd::resolveTarget(SkAnimateMaker& maker) {
   1.204 +//  return use;
   1.205 +//}
   1.206 +
   1.207 +
   1.208 +bool SkClear::enable(SkAnimateMaker& maker ) {
   1.209 +    SkDisplayList& displayList = maker.fDisplayList;
   1.210 +    displayList.clear();
   1.211 +    return true;
   1.212 +}
   1.213 +
   1.214 +
   1.215 +#if SK_USE_CONDENSED_INFO == 0
   1.216 +
   1.217 +const SkMemberInfo SkMove::fInfo[] = {
   1.218 +    SK_MEMBER_INHERITED
   1.219 +};
   1.220 +
   1.221 +#endif
   1.222 +
   1.223 +DEFINE_GET_MEMBER(SkMove);
   1.224 +
   1.225 +#if SK_USE_CONDENSED_INFO == 0
   1.226 +
   1.227 +const SkMemberInfo SkRemove::fInfo[] = {
   1.228 +    SK_MEMBER_ALIAS(delete, fDelete, Boolean),  // !!! experimental
   1.229 +    SK_MEMBER(offset, Int),
   1.230 +    SK_MEMBER(where, Drawable)
   1.231 +};
   1.232 +
   1.233 +#endif
   1.234 +
   1.235 +DEFINE_GET_MEMBER(SkRemove);
   1.236 +
   1.237 +SkRemove::SkRemove() : fDelete(false) {
   1.238 +}
   1.239 +
   1.240 +#if SK_USE_CONDENSED_INFO == 0
   1.241 +
   1.242 +const SkMemberInfo SkReplace::fInfo[] = {
   1.243 +    SK_MEMBER_INHERITED
   1.244 +};
   1.245 +
   1.246 +#endif
   1.247 +
   1.248 +DEFINE_GET_MEMBER(SkReplace);

mercurial