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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 "SkDrawGroup.h"
michael@0 11 #include "SkAnimateMaker.h"
michael@0 12 #include "SkAnimatorScript.h"
michael@0 13 #include "SkCanvas.h"
michael@0 14 #include "SkDisplayApply.h"
michael@0 15 #include "SkPaint.h"
michael@0 16 #ifdef SK_DEBUG
michael@0 17 #include "SkDisplayList.h"
michael@0 18 #endif
michael@0 19
michael@0 20 #if SK_USE_CONDENSED_INFO == 0
michael@0 21
michael@0 22 const SkMemberInfo SkGroup::fInfo[] = {
michael@0 23 SK_MEMBER(condition, String),
michael@0 24 SK_MEMBER(enableCondition, String)
michael@0 25 };
michael@0 26
michael@0 27 #endif
michael@0 28
michael@0 29 DEFINE_GET_MEMBER(SkGroup);
michael@0 30
michael@0 31 SkGroup::SkGroup() : fParentList(NULL), fOriginal(NULL) {
michael@0 32 }
michael@0 33
michael@0 34 SkGroup::~SkGroup() {
michael@0 35 if (fOriginal) // has been copied
michael@0 36 return;
michael@0 37 int index = 0;
michael@0 38 int max = fCopies.count() << 5;
michael@0 39 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 40 if (index >= max || markedForDelete(index))
michael@0 41 delete *ptr;
michael@0 42 // else {
michael@0 43 // SkApply* apply = (SkApply*) *ptr;
michael@0 44 // SkASSERT(apply->isApply());
michael@0 45 // SkASSERT(apply->getScope());
michael@0 46 // delete apply->getScope();
michael@0 47 // }
michael@0 48 index++;
michael@0 49 }
michael@0 50 }
michael@0 51
michael@0 52 bool SkGroup::addChild(SkAnimateMaker& , SkDisplayable* child) {
michael@0 53 SkASSERT(child);
michael@0 54 // SkASSERT(child->isDrawable());
michael@0 55 *fChildren.append() = (SkDrawable*) child;
michael@0 56 if (child->isGroup()) {
michael@0 57 SkGroup* groupie = (SkGroup*) child;
michael@0 58 SkASSERT(groupie->fParentList == NULL);
michael@0 59 groupie->fParentList = &fChildren;
michael@0 60 }
michael@0 61 return true;
michael@0 62 }
michael@0 63
michael@0 64 bool SkGroup::contains(SkDisplayable* match) {
michael@0 65 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 66 SkDrawable* drawable = *ptr;
michael@0 67 if (drawable == match || drawable->contains(match))
michael@0 68 return true;
michael@0 69 }
michael@0 70 return false;
michael@0 71 }
michael@0 72
michael@0 73 SkGroup* SkGroup::copy() {
michael@0 74 SkGroup* result = new SkGroup();
michael@0 75 result->fOriginal = this;
michael@0 76 result->fChildren = fChildren;
michael@0 77 return result;
michael@0 78 }
michael@0 79
michael@0 80 SkBool SkGroup::copySet(int index) {
michael@0 81 return (fCopies[index >> 5] & 1 << (index & 0x1f)) != 0;
michael@0 82 }
michael@0 83
michael@0 84 SkDisplayable* SkGroup::deepCopy(SkAnimateMaker* maker) {
michael@0 85 SkDisplayable* copy = INHERITED::deepCopy(maker);
michael@0 86 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 87 SkDisplayable* displayable = (SkDisplayable*)*ptr;
michael@0 88 SkDisplayable* deeperCopy = displayable->deepCopy(maker);
michael@0 89 ((SkGroup*)copy)->addChild(*maker, deeperCopy);
michael@0 90 }
michael@0 91 return copy;
michael@0 92 }
michael@0 93
michael@0 94 bool SkGroup::doEvent(SkDisplayEvent::Kind kind, SkEventState* state) {
michael@0 95 bool handled = false;
michael@0 96 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 97 SkDrawable* drawable = *ptr;
michael@0 98 if (drawable->isDrawable() == false)
michael@0 99 continue;
michael@0 100 handled |= drawable->doEvent(kind, state);
michael@0 101 }
michael@0 102 return handled;
michael@0 103 }
michael@0 104
michael@0 105 bool SkGroup::draw(SkAnimateMaker& maker) {
michael@0 106 bool conditionTrue = ifCondition(maker, this, condition);
michael@0 107 bool result = false;
michael@0 108 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 109 SkDrawable* drawable = *ptr;
michael@0 110 if (drawable->isDrawable() == false)
michael@0 111 continue;
michael@0 112 if (conditionTrue == false) {
michael@0 113 if (drawable->isApply())
michael@0 114 ((SkApply*) drawable)->disable();
michael@0 115 continue;
michael@0 116 }
michael@0 117 maker.validate();
michael@0 118 result |= drawable->draw(maker);
michael@0 119 maker.validate();
michael@0 120 }
michael@0 121 return result;
michael@0 122 }
michael@0 123
michael@0 124 #ifdef SK_DUMP_ENABLED
michael@0 125 void SkGroup::dump(SkAnimateMaker* maker) {
michael@0 126 dumpBase(maker);
michael@0 127 if (condition.size() > 0)
michael@0 128 SkDebugf("condition=\"%s\" ", condition.c_str());
michael@0 129 if (enableCondition.size() > 0)
michael@0 130 SkDebugf("enableCondition=\"%s\" ", enableCondition.c_str());
michael@0 131 dumpDrawables(maker);
michael@0 132 }
michael@0 133
michael@0 134 void SkGroup::dumpDrawables(SkAnimateMaker* maker) {
michael@0 135 SkDisplayList::fIndent += 4;
michael@0 136 int save = SkDisplayList::fDumpIndex;
michael@0 137 SkDisplayList::fDumpIndex = 0;
michael@0 138 bool closedYet = false;
michael@0 139 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 140 if (closedYet == false) {
michael@0 141 closedYet = true;
michael@0 142 SkDebugf(">\n");
michael@0 143 }
michael@0 144 SkDrawable* drawable = *ptr;
michael@0 145 drawable->dump(maker);
michael@0 146 SkDisplayList::fDumpIndex++;
michael@0 147 }
michael@0 148 SkDisplayList::fIndent -= 4;
michael@0 149 SkDisplayList::fDumpIndex = save;
michael@0 150 if (closedYet) //we had children, now it's time to close the group
michael@0 151 dumpEnd(maker);
michael@0 152 else //no children
michael@0 153 SkDebugf("/>\n");
michael@0 154 }
michael@0 155
michael@0 156 void SkGroup::dumpEvents() {
michael@0 157 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 158 SkDrawable* drawable = *ptr;
michael@0 159 drawable->dumpEvents();
michael@0 160 }
michael@0 161 }
michael@0 162 #endif
michael@0 163
michael@0 164 bool SkGroup::enable(SkAnimateMaker& maker ) {
michael@0 165 reset();
michael@0 166 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 167 SkDrawable* drawable = *ptr;
michael@0 168 if (ifCondition(maker, drawable, enableCondition) == false)
michael@0 169 continue;
michael@0 170 drawable->enable(maker);
michael@0 171 }
michael@0 172 return true; // skip add; already added so that scope is findable by children
michael@0 173 }
michael@0 174
michael@0 175 int SkGroup::findGroup(SkDrawable* match, SkTDDrawableArray** list,
michael@0 176 SkGroup** parent, SkGroup** found, SkTDDrawableArray** grandList) {
michael@0 177 *list = &fChildren;
michael@0 178 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 179 SkDrawable* drawable = *ptr;
michael@0 180 if (drawable->isGroup()) {
michael@0 181 SkGroup* childGroup = (SkGroup*) drawable;
michael@0 182 if (childGroup->fOriginal == match)
michael@0 183 goto foundMatch;
michael@0 184 }
michael@0 185 if (drawable == match) {
michael@0 186 foundMatch:
michael@0 187 *parent = this;
michael@0 188 return (int) (ptr - fChildren.begin());
michael@0 189 }
michael@0 190 }
michael@0 191 *grandList = &fChildren;
michael@0 192 return SkDisplayList::SearchForMatch(match, list, parent, found, grandList);
michael@0 193 }
michael@0 194
michael@0 195 bool SkGroup::hasEnable() const {
michael@0 196 return true;
michael@0 197 }
michael@0 198
michael@0 199 bool SkGroup::ifCondition(SkAnimateMaker& maker, SkDrawable*,
michael@0 200 SkString& conditionString) {
michael@0 201 if (conditionString.size() == 0)
michael@0 202 return true;
michael@0 203 int32_t result;
michael@0 204 bool success = SkAnimatorScript::EvaluateInt(maker, this, conditionString.c_str(), &result);
michael@0 205 #ifdef SK_DUMP_ENABLED
michael@0 206 if (maker.fDumpGConditions) {
michael@0 207 SkDebugf("group: ");
michael@0 208 dumpBase(&maker);
michael@0 209 SkDebugf("condition=%s ", conditionString.c_str());
michael@0 210 if (success == false)
michael@0 211 SkDebugf("(script failed)\n");
michael@0 212 else
michael@0 213 SkDebugf("success=%s\n", result != 0 ? "true" : "false");
michael@0 214 }
michael@0 215 #endif
michael@0 216 return success && result != 0;
michael@0 217 }
michael@0 218
michael@0 219 void SkGroup::initialize() {
michael@0 220 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 221 SkDrawable* drawable = *ptr;
michael@0 222 if (drawable->isDrawable() == false)
michael@0 223 continue;
michael@0 224 drawable->initialize();
michael@0 225 }
michael@0 226 }
michael@0 227
michael@0 228 void SkGroup::markCopyClear(int index) {
michael@0 229 if (index < 0)
michael@0 230 index = fChildren.count();
michael@0 231 fCopies[index >> 5] &= ~(1 << (index & 0x1f));
michael@0 232 }
michael@0 233
michael@0 234 void SkGroup::markCopySet(int index) {
michael@0 235 if (index < 0)
michael@0 236 index = fChildren.count();
michael@0 237 fCopies[index >> 5] |= 1 << (index & 0x1f);
michael@0 238 }
michael@0 239
michael@0 240 void SkGroup::markCopySize(int index) {
michael@0 241 if (index < 0)
michael@0 242 index = fChildren.count() + 1;
michael@0 243 int oldLongs = fCopies.count();
michael@0 244 int newLongs = (index >> 5) + 1;
michael@0 245 if (oldLongs < newLongs) {
michael@0 246 fCopies.setCount(newLongs);
michael@0 247 memset(&fCopies[oldLongs], 0, (newLongs - oldLongs) << 2);
michael@0 248 }
michael@0 249 }
michael@0 250
michael@0 251 void SkGroup::reset() {
michael@0 252 if (fOriginal) // has been copied
michael@0 253 return;
michael@0 254 int index = 0;
michael@0 255 int max = fCopies.count() << 5;
michael@0 256 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 257 if (index >= max || copySet(index) == false)
michael@0 258 continue;
michael@0 259 SkApply* apply = (SkApply*) *ptr;
michael@0 260 SkASSERT(apply->isApply());
michael@0 261 SkASSERT(apply->getScope());
michael@0 262 *ptr = apply->getScope();
michael@0 263 markCopyClear(index);
michael@0 264 index++;
michael@0 265 }
michael@0 266 }
michael@0 267
michael@0 268 bool SkGroup::resolveIDs(SkAnimateMaker& maker, SkDisplayable* orig, SkApply* apply) {
michael@0 269 SkGroup* original = (SkGroup*) orig;
michael@0 270 SkTDDrawableArray& originalChildren = original->fChildren;
michael@0 271 SkDrawable** originalPtr = originalChildren.begin();
michael@0 272 SkDrawable** ptr = fChildren.begin();
michael@0 273 SkDrawable** end = fChildren.end();
michael@0 274 SkDrawable** origChild = ((SkGroup*) orig)->fChildren.begin();
michael@0 275 while (ptr < end) {
michael@0 276 SkDrawable* drawable = *ptr++;
michael@0 277 maker.resolveID(drawable, *origChild++);
michael@0 278 if (drawable->resolveIDs(maker, *originalPtr++, apply) == true)
michael@0 279 return true; // failed
michael@0 280 }
michael@0 281 return false;
michael@0 282 }
michael@0 283
michael@0 284 void SkGroup::setSteps(int steps) {
michael@0 285 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 286 SkDrawable* drawable = *ptr;
michael@0 287 if (drawable->isDrawable() == false)
michael@0 288 continue;
michael@0 289 drawable->setSteps(steps);
michael@0 290 }
michael@0 291 }
michael@0 292
michael@0 293 #ifdef SK_DEBUG
michael@0 294 void SkGroup::validate() {
michael@0 295 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
michael@0 296 SkDrawable* drawable = *ptr;
michael@0 297 drawable->validate();
michael@0 298 }
michael@0 299 }
michael@0 300 #endif
michael@0 301
michael@0 302 #if SK_USE_CONDENSED_INFO == 0
michael@0 303
michael@0 304 const SkMemberInfo SkSave::fInfo[] = {
michael@0 305 SK_MEMBER_INHERITED
michael@0 306 };
michael@0 307
michael@0 308 #endif
michael@0 309
michael@0 310 DEFINE_GET_MEMBER(SkSave);
michael@0 311
michael@0 312 bool SkSave::draw(SkAnimateMaker& maker) {
michael@0 313 maker.fCanvas->save();
michael@0 314 SkPaint* save = maker.fPaint;
michael@0 315 SkPaint local = SkPaint(*maker.fPaint);
michael@0 316 maker.fPaint = &local;
michael@0 317 bool result = INHERITED::draw(maker);
michael@0 318 maker.fPaint = save;
michael@0 319 maker.fCanvas->restore();
michael@0 320 return result;
michael@0 321 }

mercurial