gfx/skia/trunk/src/animator/SkDisplayList.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 "SkDisplayList.h"
michael@0 11 #include "SkAnimateActive.h"
michael@0 12 #include "SkAnimateBase.h"
michael@0 13 #include "SkAnimateMaker.h"
michael@0 14 #include "SkDisplayApply.h"
michael@0 15 #include "SkDrawable.h"
michael@0 16 #include "SkDrawGroup.h"
michael@0 17 #include "SkDrawMatrix.h"
michael@0 18 #include "SkInterpolator.h"
michael@0 19 #include "SkTime.h"
michael@0 20
michael@0 21 SkDisplayList::SkDisplayList() : fDrawBounds(true), fUnionBounds(false), fInTime(0) {
michael@0 22 }
michael@0 23
michael@0 24 SkDisplayList::~SkDisplayList() {
michael@0 25 }
michael@0 26
michael@0 27 void SkDisplayList::append(SkActive* active) {
michael@0 28 *fActiveList.append() = active;
michael@0 29 }
michael@0 30
michael@0 31 bool SkDisplayList::draw(SkAnimateMaker& maker, SkMSec inTime) {
michael@0 32 validate();
michael@0 33 fInTime = inTime;
michael@0 34 bool result = false;
michael@0 35 fInvalBounds.setEmpty();
michael@0 36 if (fDrawList.count()) {
michael@0 37 for (SkActive** activePtr = fActiveList.begin(); activePtr < fActiveList.end(); activePtr++) {
michael@0 38 SkActive* active = *activePtr;
michael@0 39 active->reset();
michael@0 40 }
michael@0 41 for (int index = 0; index < fDrawList.count(); index++) {
michael@0 42 SkDrawable* draw = fDrawList[index];
michael@0 43 draw->initialize(); // allow matrices to reset themselves
michael@0 44 SkASSERT(draw->isDrawable());
michael@0 45 validate();
michael@0 46 result |= draw->draw(maker);
michael@0 47 }
michael@0 48 }
michael@0 49 validate();
michael@0 50 return result;
michael@0 51 }
michael@0 52
michael@0 53 int SkDisplayList::findGroup(SkDrawable* match, SkTDDrawableArray** list,
michael@0 54 SkGroup** parent, SkGroup** found, SkTDDrawableArray**grandList) {
michael@0 55 *parent = NULL;
michael@0 56 *list = &fDrawList;
michael@0 57 *grandList = &fDrawList;
michael@0 58 return SearchForMatch(match, list, parent, found, grandList);
michael@0 59 }
michael@0 60
michael@0 61 void SkDisplayList::hardReset() {
michael@0 62 fDrawList.reset();
michael@0 63 fActiveList.reset();
michael@0 64 }
michael@0 65
michael@0 66 bool SkDisplayList::onIRect(const SkIRect& r) {
michael@0 67 fBounds = r;
michael@0 68 return fDrawBounds;
michael@0 69 }
michael@0 70
michael@0 71 int SkDisplayList::SearchForMatch(SkDrawable* match, SkTDDrawableArray** list,
michael@0 72 SkGroup** parent, SkGroup** found, SkTDDrawableArray**grandList) {
michael@0 73 *found = NULL;
michael@0 74 for (int index = 0; index < (*list)->count(); index++) {
michael@0 75 SkDrawable* draw = (**list)[index];
michael@0 76 if (draw == match)
michael@0 77 return index;
michael@0 78 if (draw->isApply()) {
michael@0 79 SkApply* apply = (SkApply*) draw;
michael@0 80 if (apply->scope == match)
michael@0 81 return index;
michael@0 82 if (apply->scope->isGroup() && SearchGroupForMatch(apply->scope, match, list, parent, found, grandList, index))
michael@0 83 return index;
michael@0 84 if (apply->mode == SkApply::kMode_create) {
michael@0 85 for (SkDrawable** ptr = apply->fScopes.begin(); ptr < apply->fScopes.end(); ptr++) {
michael@0 86 SkDrawable* scope = *ptr;
michael@0 87 if (scope == match)
michael@0 88 return index;
michael@0 89 //perhaps should call SearchGroupForMatch here as well (on scope)
michael@0 90 }
michael@0 91 }
michael@0 92 }
michael@0 93 if (draw->isGroup() && SearchGroupForMatch(draw, match, list, parent, found, grandList, index))
michael@0 94 return index;
michael@0 95
michael@0 96 }
michael@0 97 return -1;
michael@0 98 }
michael@0 99
michael@0 100 bool SkDisplayList::SearchGroupForMatch(SkDrawable* draw, SkDrawable* match, SkTDDrawableArray** list,
michael@0 101 SkGroup** parent, SkGroup** found, SkTDDrawableArray** grandList, int &index) {
michael@0 102 SkGroup* group = (SkGroup*) draw;
michael@0 103 if (group->getOriginal() == match)
michael@0 104 return true;
michael@0 105 SkTDDrawableArray* saveList = *list;
michael@0 106 int groupIndex = group->findGroup(match, list, parent, found, grandList);
michael@0 107 if (groupIndex >= 0) {
michael@0 108 *found = group;
michael@0 109 index = groupIndex;
michael@0 110 return true;
michael@0 111 }
michael@0 112 *list = saveList;
michael@0 113 return false;
michael@0 114 }
michael@0 115
michael@0 116 void SkDisplayList::reset() {
michael@0 117 for (int index = 0; index < fDrawList.count(); index++) {
michael@0 118 SkDrawable* draw = fDrawList[index];
michael@0 119 if (draw->isApply() == false)
michael@0 120 continue;
michael@0 121 SkApply* apply = (SkApply*) draw;
michael@0 122 apply->reset();
michael@0 123 }
michael@0 124 }
michael@0 125
michael@0 126 void SkDisplayList::remove(SkActive* active) {
michael@0 127 int index = fActiveList.find(active);
michael@0 128 SkASSERT(index >= 0);
michael@0 129 fActiveList.remove(index); // !!! could use shuffle instead
michael@0 130 SkASSERT(fActiveList.find(active) < 0);
michael@0 131 }
michael@0 132
michael@0 133 #ifdef SK_DUMP_ENABLED
michael@0 134 int SkDisplayList::fDumpIndex;
michael@0 135 int SkDisplayList::fIndent;
michael@0 136
michael@0 137 void SkDisplayList::dump(SkAnimateMaker* maker) {
michael@0 138 fIndent = 0;
michael@0 139 dumpInner(maker);
michael@0 140 }
michael@0 141
michael@0 142 void SkDisplayList::dumpInner(SkAnimateMaker* maker) {
michael@0 143 for (int index = 0; index < fDrawList.count(); index++) {
michael@0 144 fDumpIndex = index;
michael@0 145 fDrawList[fDumpIndex]->dump(maker);
michael@0 146 }
michael@0 147 }
michael@0 148
michael@0 149 #endif
michael@0 150
michael@0 151 #ifdef SK_DEBUG
michael@0 152 void SkDisplayList::validate() {
michael@0 153 for (int index = 0; index < fDrawList.count(); index++) {
michael@0 154 SkDrawable* draw = fDrawList[index];
michael@0 155 draw->validate();
michael@0 156 }
michael@0 157 }
michael@0 158 #endif

mercurial