Sat, 03 Jan 2015 20:18:00 +0100
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 "SkComposeShader.h" |
michael@0 | 11 | #include "SkColorFilter.h" |
michael@0 | 12 | #include "SkColorPriv.h" |
michael@0 | 13 | #include "SkColorShader.h" |
michael@0 | 14 | #include "SkReadBuffer.h" |
michael@0 | 15 | #include "SkWriteBuffer.h" |
michael@0 | 16 | #include "SkXfermode.h" |
michael@0 | 17 | #include "SkString.h" |
michael@0 | 18 | |
michael@0 | 19 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 20 | |
michael@0 | 21 | SkComposeShader::SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode) { |
michael@0 | 22 | fShaderA = sA; sA->ref(); |
michael@0 | 23 | fShaderB = sB; sB->ref(); |
michael@0 | 24 | // mode may be null |
michael@0 | 25 | fMode = mode; |
michael@0 | 26 | SkSafeRef(mode); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | SkComposeShader::SkComposeShader(SkReadBuffer& buffer) : |
michael@0 | 30 | INHERITED(buffer) { |
michael@0 | 31 | fShaderA = buffer.readShader(); |
michael@0 | 32 | if (NULL == fShaderA) { |
michael@0 | 33 | fShaderA = SkNEW_ARGS(SkColorShader, (0)); |
michael@0 | 34 | } |
michael@0 | 35 | fShaderB = buffer.readShader(); |
michael@0 | 36 | if (NULL == fShaderB) { |
michael@0 | 37 | fShaderB = SkNEW_ARGS(SkColorShader, (0)); |
michael@0 | 38 | } |
michael@0 | 39 | fMode = buffer.readXfermode(); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | SkComposeShader::~SkComposeShader() { |
michael@0 | 43 | SkSafeUnref(fMode); |
michael@0 | 44 | fShaderB->unref(); |
michael@0 | 45 | fShaderA->unref(); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | class SkAutoAlphaRestore { |
michael@0 | 49 | public: |
michael@0 | 50 | SkAutoAlphaRestore(SkPaint* paint, uint8_t newAlpha) { |
michael@0 | 51 | fAlpha = paint->getAlpha(); |
michael@0 | 52 | fPaint = paint; |
michael@0 | 53 | paint->setAlpha(newAlpha); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | ~SkAutoAlphaRestore() { |
michael@0 | 57 | fPaint->setAlpha(fAlpha); |
michael@0 | 58 | } |
michael@0 | 59 | private: |
michael@0 | 60 | SkPaint* fPaint; |
michael@0 | 61 | uint8_t fAlpha; |
michael@0 | 62 | }; |
michael@0 | 63 | #define SkAutoAlphaRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoAlphaRestore) |
michael@0 | 64 | |
michael@0 | 65 | void SkComposeShader::flatten(SkWriteBuffer& buffer) const { |
michael@0 | 66 | this->INHERITED::flatten(buffer); |
michael@0 | 67 | buffer.writeFlattenable(fShaderA); |
michael@0 | 68 | buffer.writeFlattenable(fShaderB); |
michael@0 | 69 | buffer.writeFlattenable(fMode); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | /* We call setContext on our two worker shaders. However, we |
michael@0 | 73 | always let them see opaque alpha, and if the paint really |
michael@0 | 74 | is translucent, then we apply that after the fact. |
michael@0 | 75 | |
michael@0 | 76 | We need to keep the calls to setContext/endContext balanced, since if we |
michael@0 | 77 | return false, our endContext() will not be called. |
michael@0 | 78 | */ |
michael@0 | 79 | bool SkComposeShader::setContext(const SkBitmap& device, |
michael@0 | 80 | const SkPaint& paint, |
michael@0 | 81 | const SkMatrix& matrix) { |
michael@0 | 82 | if (!this->INHERITED::setContext(device, paint, matrix)) { |
michael@0 | 83 | return false; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | // we preconcat our localMatrix (if any) with the device matrix |
michael@0 | 87 | // before calling our sub-shaders |
michael@0 | 88 | |
michael@0 | 89 | SkMatrix tmpM; |
michael@0 | 90 | |
michael@0 | 91 | tmpM.setConcat(matrix, this->getLocalMatrix()); |
michael@0 | 92 | |
michael@0 | 93 | SkAutoAlphaRestore restore(const_cast<SkPaint*>(&paint), 0xFF); |
michael@0 | 94 | |
michael@0 | 95 | bool setContextA = fShaderA->setContext(device, paint, tmpM); |
michael@0 | 96 | bool setContextB = fShaderB->setContext(device, paint, tmpM); |
michael@0 | 97 | if (!setContextA || !setContextB) { |
michael@0 | 98 | if (setContextB) { |
michael@0 | 99 | fShaderB->endContext(); |
michael@0 | 100 | } |
michael@0 | 101 | else if (setContextA) { |
michael@0 | 102 | fShaderA->endContext(); |
michael@0 | 103 | } |
michael@0 | 104 | this->INHERITED::endContext(); |
michael@0 | 105 | return false; |
michael@0 | 106 | } |
michael@0 | 107 | return true; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | void SkComposeShader::endContext() { |
michael@0 | 111 | fShaderB->endContext(); |
michael@0 | 112 | fShaderA->endContext(); |
michael@0 | 113 | this->INHERITED::endContext(); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | // larger is better (fewer times we have to loop), but we shouldn't |
michael@0 | 117 | // take up too much stack-space (each element is 4 bytes) |
michael@0 | 118 | #define TMP_COLOR_COUNT 64 |
michael@0 | 119 | |
michael@0 | 120 | void SkComposeShader::shadeSpan(int x, int y, SkPMColor result[], int count) { |
michael@0 | 121 | SkShader* shaderA = fShaderA; |
michael@0 | 122 | SkShader* shaderB = fShaderB; |
michael@0 | 123 | SkXfermode* mode = fMode; |
michael@0 | 124 | unsigned scale = SkAlpha255To256(this->getPaintAlpha()); |
michael@0 | 125 | |
michael@0 | 126 | SkPMColor tmp[TMP_COLOR_COUNT]; |
michael@0 | 127 | |
michael@0 | 128 | if (NULL == mode) { // implied SRC_OVER |
michael@0 | 129 | // TODO: when we have a good test-case, should use SkBlitRow::Proc32 |
michael@0 | 130 | // for these loops |
michael@0 | 131 | do { |
michael@0 | 132 | int n = count; |
michael@0 | 133 | if (n > TMP_COLOR_COUNT) { |
michael@0 | 134 | n = TMP_COLOR_COUNT; |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | shaderA->shadeSpan(x, y, result, n); |
michael@0 | 138 | shaderB->shadeSpan(x, y, tmp, n); |
michael@0 | 139 | |
michael@0 | 140 | if (256 == scale) { |
michael@0 | 141 | for (int i = 0; i < n; i++) { |
michael@0 | 142 | result[i] = SkPMSrcOver(tmp[i], result[i]); |
michael@0 | 143 | } |
michael@0 | 144 | } else { |
michael@0 | 145 | for (int i = 0; i < n; i++) { |
michael@0 | 146 | result[i] = SkAlphaMulQ(SkPMSrcOver(tmp[i], result[i]), |
michael@0 | 147 | scale); |
michael@0 | 148 | } |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | result += n; |
michael@0 | 152 | x += n; |
michael@0 | 153 | count -= n; |
michael@0 | 154 | } while (count > 0); |
michael@0 | 155 | } else { // use mode for the composition |
michael@0 | 156 | do { |
michael@0 | 157 | int n = count; |
michael@0 | 158 | if (n > TMP_COLOR_COUNT) { |
michael@0 | 159 | n = TMP_COLOR_COUNT; |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | shaderA->shadeSpan(x, y, result, n); |
michael@0 | 163 | shaderB->shadeSpan(x, y, tmp, n); |
michael@0 | 164 | mode->xfer32(result, tmp, n, NULL); |
michael@0 | 165 | |
michael@0 | 166 | if (256 == scale) { |
michael@0 | 167 | for (int i = 0; i < n; i++) { |
michael@0 | 168 | result[i] = SkAlphaMulQ(result[i], scale); |
michael@0 | 169 | } |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | result += n; |
michael@0 | 173 | x += n; |
michael@0 | 174 | count -= n; |
michael@0 | 175 | } while (count > 0); |
michael@0 | 176 | } |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | #ifndef SK_IGNORE_TO_STRING |
michael@0 | 180 | void SkComposeShader::toString(SkString* str) const { |
michael@0 | 181 | str->append("SkComposeShader: ("); |
michael@0 | 182 | |
michael@0 | 183 | str->append("ShaderA: "); |
michael@0 | 184 | fShaderA->toString(str); |
michael@0 | 185 | str->append(" ShaderB: "); |
michael@0 | 186 | fShaderB->toString(str); |
michael@0 | 187 | str->append(" Xfermode: "); |
michael@0 | 188 | fMode->toString(str); |
michael@0 | 189 | |
michael@0 | 190 | this->INHERITED::toString(str); |
michael@0 | 191 | |
michael@0 | 192 | str->append(")"); |
michael@0 | 193 | } |
michael@0 | 194 | #endif |