gfx/skia/trunk/src/animator/SkScriptDecompile.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 "SkScript2.h"
michael@0 11
michael@0 12 #ifdef SK_DEBUG
michael@0 13
michael@0 14 #define TypeOpName(op) {SkScriptEngine2::op, #op }
michael@0 15
michael@0 16 static const struct OpName {
michael@0 17 SkScriptEngine2::TypeOp fOp;
michael@0 18 const char* fName;
michael@0 19 } gOpNames[] = {
michael@0 20 TypeOpName(kNop), // should never get generated
michael@0 21 TypeOpName(kAccumulatorPop),
michael@0 22 TypeOpName(kAccumulatorPush),
michael@0 23 TypeOpName(kAddInt),
michael@0 24 TypeOpName(kAddScalar),
michael@0 25 TypeOpName(kAddString), // string concat
michael@0 26 TypeOpName(kArrayIndex),
michael@0 27 TypeOpName(kArrayParam),
michael@0 28 TypeOpName(kArrayToken),
michael@0 29 TypeOpName(kBitAndInt),
michael@0 30 TypeOpName(kBitNotInt),
michael@0 31 TypeOpName(kBitOrInt),
michael@0 32 TypeOpName(kBoxToken),
michael@0 33 TypeOpName(kCallback),
michael@0 34 TypeOpName(kDivideInt),
michael@0 35 TypeOpName(kDivideScalar),
michael@0 36 TypeOpName(kDotOperator),
michael@0 37 TypeOpName(kElseOp),
michael@0 38 TypeOpName(kEnd),
michael@0 39 TypeOpName(kEqualInt),
michael@0 40 TypeOpName(kEqualScalar),
michael@0 41 TypeOpName(kEqualString),
michael@0 42 TypeOpName(kFunctionCall),
michael@0 43 TypeOpName(kFlipOpsOp),
michael@0 44 TypeOpName(kFunctionToken),
michael@0 45 TypeOpName(kGreaterEqualInt),
michael@0 46 TypeOpName(kGreaterEqualScalar),
michael@0 47 TypeOpName(kGreaterEqualString),
michael@0 48 TypeOpName(kIfOp),
michael@0 49 TypeOpName(kIntToScalar),
michael@0 50 TypeOpName(kIntToScalar2),
michael@0 51 TypeOpName(kIntToString),
michael@0 52 TypeOpName(kIntToString2),
michael@0 53 TypeOpName(kIntegerAccumulator),
michael@0 54 TypeOpName(kIntegerOperand),
michael@0 55 TypeOpName(kLogicalAndInt),
michael@0 56 TypeOpName(kLogicalNotInt),
michael@0 57 TypeOpName(kLogicalOrInt),
michael@0 58 TypeOpName(kMemberOp),
michael@0 59 TypeOpName(kMinusInt),
michael@0 60 TypeOpName(kMinusScalar),
michael@0 61 TypeOpName(kModuloInt),
michael@0 62 TypeOpName(kModuloScalar),
michael@0 63 TypeOpName(kMultiplyInt),
michael@0 64 TypeOpName(kMultiplyScalar),
michael@0 65 TypeOpName(kPropertyOp),
michael@0 66 TypeOpName(kScalarAccumulator),
michael@0 67 TypeOpName(kScalarOperand),
michael@0 68 TypeOpName(kScalarToInt),
michael@0 69 TypeOpName(kScalarToInt2),
michael@0 70 TypeOpName(kScalarToString),
michael@0 71 TypeOpName(kScalarToString2),
michael@0 72 TypeOpName(kShiftLeftInt),
michael@0 73 TypeOpName(kShiftRightInt), // signed
michael@0 74 TypeOpName(kStringAccumulator),
michael@0 75 TypeOpName(kStringOperand),
michael@0 76 TypeOpName(kStringToInt),
michael@0 77 TypeOpName(kStringToScalar),
michael@0 78 TypeOpName(kStringToScalar2),
michael@0 79 TypeOpName(kStringTrack),
michael@0 80 TypeOpName(kSubtractInt),
michael@0 81 TypeOpName(kSubtractScalar),
michael@0 82 TypeOpName(kToBool),
michael@0 83 TypeOpName(kUnboxToken),
michael@0 84 TypeOpName(kUnboxToken2),
michael@0 85 TypeOpName(kXorInt)
michael@0 86 };
michael@0 87
michael@0 88 static size_t gOpNamesSize = sizeof(gOpNames) / sizeof(gOpNames[0]);
michael@0 89
michael@0 90 #define OperandName(op) {SkOperand2::op, #op }
michael@0 91
michael@0 92 static const struct OperName {
michael@0 93 SkOperand2::OpType fType;
michael@0 94 const char* fName;
michael@0 95 } gOperandNames[] = {
michael@0 96 OperandName(kNoType),
michael@0 97 OperandName(kS32),
michael@0 98 OperandName(kScalar),
michael@0 99 OperandName(kString),
michael@0 100 OperandName(kArray),
michael@0 101 OperandName(kObject)
michael@0 102 };
michael@0 103
michael@0 104 static size_t gOperandNamesSize = sizeof(gOperandNames) / sizeof(gOperandNames[0]);
michael@0 105
michael@0 106 // check to see that there are no missing or duplicate entries
michael@0 107 void SkScriptEngine2::ValidateDecompileTable() {
michael@0 108 SkScriptEngine2::TypeOp op = SkScriptEngine2::kNop;
michael@0 109 size_t index;
michael@0 110 for (index = 0; index < gOpNamesSize; index++) {
michael@0 111 SkASSERT(gOpNames[index].fOp == op);
michael@0 112 op = (SkScriptEngine2::TypeOp) (op + 1);
michael@0 113 }
michael@0 114 index = 0;
michael@0 115 SkOperand2::OpType type = SkOperand2::kNoType;
michael@0 116 SkASSERT(gOperandNames[index].fType == type);
michael@0 117 for (; index < gOperandNamesSize - 1; ) {
michael@0 118 type = (SkOperand2::OpType) (1 << index);
michael@0 119 SkASSERT(gOperandNames[++index].fType == type);
michael@0 120 }
michael@0 121 }
michael@0 122
michael@0 123 void SkScriptEngine2::decompile(const unsigned char* start, size_t length) {
michael@0 124 SkASSERT(length > 0);
michael@0 125 const unsigned char* opCode = start;
michael@0 126 do {
michael@0 127 SkASSERT((size_t)(opCode - start) < length);
michael@0 128 SkScriptEngine2::TypeOp op = (SkScriptEngine2::TypeOp) *opCode++;
michael@0 129 SkASSERT((size_t)op < gOpNamesSize);
michael@0 130 SkDebugf("%d: %s", opCode - start - 1, gOpNames[op].fName);
michael@0 131 switch (op) {
michael@0 132 case SkScriptEngine2::kCallback: {
michael@0 133 int index;
michael@0 134 memcpy(&index, opCode, sizeof(index));
michael@0 135 opCode += sizeof(index);
michael@0 136 SkDebugf(" index: %d", index);
michael@0 137 } break;
michael@0 138 case SkScriptEngine2::kFunctionCall:
michael@0 139 case SkScriptEngine2::kMemberOp:
michael@0 140 case SkScriptEngine2::kPropertyOp: {
michael@0 141 size_t ref;
michael@0 142 memcpy(&ref, opCode, sizeof(ref));
michael@0 143 opCode += sizeof(ref);
michael@0 144 SkDebugf(" ref: %d", ref);
michael@0 145 } break;
michael@0 146 case SkScriptEngine2::kIntegerAccumulator:
michael@0 147 case SkScriptEngine2::kIntegerOperand: {
michael@0 148 int32_t integer;
michael@0 149 memcpy(&integer, opCode, sizeof(integer));
michael@0 150 opCode += sizeof(int32_t);
michael@0 151 SkDebugf(" integer: %d", integer);
michael@0 152 } break;
michael@0 153 case SkScriptEngine2::kScalarAccumulator:
michael@0 154 case SkScriptEngine2::kScalarOperand: {
michael@0 155 SkScalar scalar;
michael@0 156 memcpy(&scalar, opCode, sizeof(scalar));
michael@0 157 opCode += sizeof(SkScalar);
michael@0 158 SkDebugf(" scalar: %g", SkScalarToFloat(scalar));
michael@0 159 } break;
michael@0 160 case SkScriptEngine2::kStringAccumulator:
michael@0 161 case SkScriptEngine2::kStringOperand: {
michael@0 162 int size;
michael@0 163 SkString* strPtr = new SkString();
michael@0 164 memcpy(&size, opCode, sizeof(size));
michael@0 165 opCode += sizeof(size);
michael@0 166 strPtr->set((char*) opCode, size);
michael@0 167 opCode += size;
michael@0 168 SkDebugf(" string: %s", strPtr->c_str());
michael@0 169 delete strPtr;
michael@0 170 } break;
michael@0 171 case SkScriptEngine2::kBoxToken: {
michael@0 172 SkOperand2::OpType type;
michael@0 173 memcpy(&type, opCode, sizeof(type));
michael@0 174 opCode += sizeof(type);
michael@0 175 size_t index = 0;
michael@0 176 if (type == 0)
michael@0 177 SkDebugf(" type: %s", gOperandNames[index].fName);
michael@0 178 else {
michael@0 179 while (type != 0) {
michael@0 180 SkASSERT(index + 1 < gOperandNamesSize);
michael@0 181 if (type & (1 << index)) {
michael@0 182 type = (SkOperand2::OpType) (type & ~(1 << index));
michael@0 183 SkDebugf(" type: %s", gOperandNames[index + 1].fName);
michael@0 184 }
michael@0 185 index++;
michael@0 186 }
michael@0 187 }
michael@0 188 } break;
michael@0 189 case SkScriptEngine2::kIfOp:
michael@0 190 case SkScriptEngine2::kLogicalAndInt:
michael@0 191 case SkScriptEngine2::kElseOp:
michael@0 192 case SkScriptEngine2::kLogicalOrInt: {
michael@0 193 int size;
michael@0 194 memcpy(&size, opCode, sizeof(size));
michael@0 195 opCode += sizeof(size);
michael@0 196 SkDebugf(" offset (address): %d (%d)", size, opCode - start + size);
michael@0 197 } break;
michael@0 198 case SkScriptEngine2::kEnd:
michael@0 199 goto done;
michael@0 200 case SkScriptEngine2::kNop:
michael@0 201 SkASSERT(0);
michael@0 202 default:
michael@0 203 break;
michael@0 204 }
michael@0 205 SkDebugf("\n");
michael@0 206 } while (true);
michael@0 207 done:
michael@0 208 SkDebugf("\n");
michael@0 209 }
michael@0 210
michael@0 211 #endif

mercurial