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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/animator/SkDisplayList.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,158 @@
     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 "SkDisplayList.h"
    1.14 +#include "SkAnimateActive.h"
    1.15 +#include "SkAnimateBase.h"
    1.16 +#include "SkAnimateMaker.h"
    1.17 +#include "SkDisplayApply.h"
    1.18 +#include "SkDrawable.h"
    1.19 +#include "SkDrawGroup.h"
    1.20 +#include "SkDrawMatrix.h"
    1.21 +#include "SkInterpolator.h"
    1.22 +#include "SkTime.h"
    1.23 +
    1.24 +SkDisplayList::SkDisplayList() : fDrawBounds(true), fUnionBounds(false), fInTime(0) {
    1.25 +}
    1.26 +
    1.27 +SkDisplayList::~SkDisplayList() {
    1.28 +}
    1.29 +
    1.30 +void SkDisplayList::append(SkActive* active) {
    1.31 +    *fActiveList.append() = active;
    1.32 +}
    1.33 +
    1.34 +bool SkDisplayList::draw(SkAnimateMaker& maker, SkMSec inTime) {
    1.35 +    validate();
    1.36 +    fInTime = inTime;
    1.37 +    bool result = false;
    1.38 +    fInvalBounds.setEmpty();
    1.39 +    if (fDrawList.count()) {
    1.40 +        for (SkActive** activePtr = fActiveList.begin(); activePtr < fActiveList.end(); activePtr++) {
    1.41 +            SkActive* active = *activePtr;
    1.42 +            active->reset();
    1.43 +        }
    1.44 +        for (int index = 0; index < fDrawList.count(); index++) {
    1.45 +            SkDrawable* draw = fDrawList[index];
    1.46 +            draw->initialize(); // allow matrices to reset themselves
    1.47 +            SkASSERT(draw->isDrawable());
    1.48 +            validate();
    1.49 +            result |= draw->draw(maker);
    1.50 +        }
    1.51 +    }
    1.52 +    validate();
    1.53 +    return result;
    1.54 +}
    1.55 +
    1.56 +int SkDisplayList::findGroup(SkDrawable* match, SkTDDrawableArray** list,
    1.57 +        SkGroup** parent, SkGroup** found, SkTDDrawableArray**grandList) {
    1.58 +    *parent = NULL;
    1.59 +    *list = &fDrawList;
    1.60 +    *grandList = &fDrawList;
    1.61 +    return SearchForMatch(match, list, parent, found, grandList);
    1.62 +}
    1.63 +
    1.64 +void SkDisplayList::hardReset() {
    1.65 +    fDrawList.reset();
    1.66 +    fActiveList.reset();
    1.67 +}
    1.68 +
    1.69 +bool SkDisplayList::onIRect(const SkIRect& r) {
    1.70 +    fBounds = r;
    1.71 +    return fDrawBounds;
    1.72 +}
    1.73 +
    1.74 +int SkDisplayList::SearchForMatch(SkDrawable* match, SkTDDrawableArray** list,
    1.75 +        SkGroup** parent, SkGroup** found, SkTDDrawableArray**grandList) {
    1.76 +    *found = NULL;
    1.77 +    for (int index = 0; index < (*list)->count(); index++) {
    1.78 +        SkDrawable* draw = (**list)[index];
    1.79 +        if (draw == match)
    1.80 +            return index;
    1.81 +        if (draw->isApply()) {
    1.82 +            SkApply* apply = (SkApply*) draw;
    1.83 +            if (apply->scope == match)
    1.84 +                return index;
    1.85 +            if (apply->scope->isGroup() && SearchGroupForMatch(apply->scope, match, list, parent, found, grandList, index))
    1.86 +                return index;
    1.87 +            if (apply->mode == SkApply::kMode_create) {
    1.88 +                for (SkDrawable** ptr = apply->fScopes.begin(); ptr < apply->fScopes.end(); ptr++) {
    1.89 +                    SkDrawable* scope = *ptr;
    1.90 +                    if (scope == match)
    1.91 +                        return index;
    1.92 +                    //perhaps should call SearchGroupForMatch here as well (on scope)
    1.93 +                }
    1.94 +            }
    1.95 +        }
    1.96 +        if (draw->isGroup() && SearchGroupForMatch(draw, match, list, parent, found, grandList, index))
    1.97 +            return index;
    1.98 +
    1.99 +    }
   1.100 +    return -1;
   1.101 +}
   1.102 +
   1.103 +bool SkDisplayList::SearchGroupForMatch(SkDrawable* draw, SkDrawable* match, SkTDDrawableArray** list,
   1.104 +        SkGroup** parent, SkGroup** found, SkTDDrawableArray** grandList, int &index) {
   1.105 +            SkGroup* group = (SkGroup*) draw;
   1.106 +            if (group->getOriginal() == match)
   1.107 +                return true;
   1.108 +            SkTDDrawableArray* saveList = *list;
   1.109 +            int groupIndex = group->findGroup(match, list, parent, found, grandList);
   1.110 +            if (groupIndex >= 0) {
   1.111 +                *found = group;
   1.112 +                index = groupIndex;
   1.113 +                return true;
   1.114 +            }
   1.115 +            *list = saveList;
   1.116 +            return false;
   1.117 +        }
   1.118 +
   1.119 +void SkDisplayList::reset() {
   1.120 +    for (int index = 0; index < fDrawList.count(); index++) {
   1.121 +        SkDrawable* draw = fDrawList[index];
   1.122 +        if (draw->isApply() == false)
   1.123 +            continue;
   1.124 +        SkApply* apply = (SkApply*) draw;
   1.125 +        apply->reset();
   1.126 +    }
   1.127 +}
   1.128 +
   1.129 +void SkDisplayList::remove(SkActive* active) {
   1.130 +    int index = fActiveList.find(active);
   1.131 +    SkASSERT(index >= 0);
   1.132 +    fActiveList.remove(index);  // !!! could use shuffle instead
   1.133 +    SkASSERT(fActiveList.find(active) < 0);
   1.134 +}
   1.135 +
   1.136 +#ifdef SK_DUMP_ENABLED
   1.137 +int SkDisplayList::fDumpIndex;
   1.138 +int SkDisplayList::fIndent;
   1.139 +
   1.140 +void SkDisplayList::dump(SkAnimateMaker* maker) {
   1.141 +    fIndent = 0;
   1.142 +    dumpInner(maker);
   1.143 +}
   1.144 +
   1.145 +void SkDisplayList::dumpInner(SkAnimateMaker* maker) {
   1.146 +    for (int index = 0; index < fDrawList.count(); index++) {
   1.147 +        fDumpIndex = index;
   1.148 +        fDrawList[fDumpIndex]->dump(maker);
   1.149 +    }
   1.150 +}
   1.151 +
   1.152 +#endif
   1.153 +
   1.154 +#ifdef SK_DEBUG
   1.155 +void SkDisplayList::validate() {
   1.156 +    for (int index = 0; index < fDrawList.count(); index++) {
   1.157 +        SkDrawable* draw = fDrawList[index];
   1.158 +        draw->validate();
   1.159 +    }
   1.160 +}
   1.161 +#endif

mercurial