gfx/skia/trunk/src/effects/SkLerpXfermode.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 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #include "SkLerpXfermode.h"
michael@0 9 #include "SkColorPriv.h"
michael@0 10 #include "SkReadBuffer.h"
michael@0 11 #include "SkWriteBuffer.h"
michael@0 12 #include "SkString.h"
michael@0 13
michael@0 14 SkXfermode* SkLerpXfermode::Create(SkScalar scale) {
michael@0 15 int scale256 = SkScalarRoundToInt(scale * 256);
michael@0 16 if (scale256 >= 256) {
michael@0 17 return SkXfermode::Create(SkXfermode::kSrc_Mode);
michael@0 18 } else if (scale256 <= 0) {
michael@0 19 return SkXfermode::Create(SkXfermode::kDst_Mode);
michael@0 20 }
michael@0 21 return SkNEW_ARGS(SkLerpXfermode, (scale256));
michael@0 22 }
michael@0 23
michael@0 24 SkLerpXfermode::SkLerpXfermode(unsigned scale256) : fScale256(scale256) {}
michael@0 25
michael@0 26 SkLerpXfermode::SkLerpXfermode(SkReadBuffer& buffer)
michael@0 27 : INHERITED(buffer) {
michael@0 28 fScale256 = buffer.readUInt();
michael@0 29 }
michael@0 30
michael@0 31 void SkLerpXfermode::flatten(SkWriteBuffer& buffer) const {
michael@0 32 this->INHERITED::flatten(buffer);
michael@0 33 buffer.writeUInt(fScale256);
michael@0 34 }
michael@0 35
michael@0 36 void SkLerpXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count,
michael@0 37 const SkAlpha aa[]) const {
michael@0 38 const int scale = fScale256;
michael@0 39
michael@0 40 if (aa) {
michael@0 41 for (int i = 0; i < count; ++i) {
michael@0 42 unsigned a = aa[i];
michael@0 43 if (a) {
michael@0 44 SkPMColor dstC = dst[i];
michael@0 45 SkPMColor resC = SkFastFourByteInterp256(src[i], dstC, scale);
michael@0 46 if (a < 255) {
michael@0 47 resC = SkFastFourByteInterp256(resC, dstC, a + (a >> 7));
michael@0 48 }
michael@0 49 dst[i] = resC;
michael@0 50 }
michael@0 51 }
michael@0 52 } else {
michael@0 53 for (int i = 0; i < count; ++i) {
michael@0 54 dst[i] = SkFastFourByteInterp256(src[i], dst[i], scale);
michael@0 55 }
michael@0 56 }
michael@0 57 }
michael@0 58
michael@0 59 void SkLerpXfermode::xfer16(uint16_t dst[], const SkPMColor src[], int count,
michael@0 60 const SkAlpha aa[]) const {
michael@0 61 const int scale = fScale256;
michael@0 62
michael@0 63 if (aa) {
michael@0 64 for (int i = 0; i < count; ++i) {
michael@0 65 unsigned a = aa[i];
michael@0 66 if (a) {
michael@0 67 SkPMColor dstC = SkPixel16ToPixel32(dst[i]);
michael@0 68 SkPMColor resC = SkFastFourByteInterp256(src[i], dstC, scale);
michael@0 69 if (a < 255) {
michael@0 70 resC = SkFastFourByteInterp256(resC, dstC, a + (a >> 7));
michael@0 71 }
michael@0 72 dst[i] = SkPixel32ToPixel16(resC);
michael@0 73 }
michael@0 74 }
michael@0 75 } else {
michael@0 76 for (int i = 0; i < count; ++i) {
michael@0 77 SkPMColor dstC = SkPixel16ToPixel32(dst[i]);
michael@0 78 SkPMColor resC = SkFastFourByteInterp256(src[i], dstC, scale);
michael@0 79 dst[i] = SkPixel32ToPixel16(resC);
michael@0 80 }
michael@0 81 }
michael@0 82 }
michael@0 83
michael@0 84 void SkLerpXfermode::xferA8(SkAlpha dst[], const SkPMColor src[], int count,
michael@0 85 const SkAlpha aa[]) const {
michael@0 86 const int scale = fScale256;
michael@0 87
michael@0 88 if (aa) {
michael@0 89 for (int i = 0; i < count; ++i) {
michael@0 90 unsigned a = aa[i];
michael@0 91 if (a) {
michael@0 92 unsigned dstA = dst[i];
michael@0 93 unsigned resA = SkAlphaBlend(SkGetPackedA32(src[i]), dstA, scale);
michael@0 94 if (a < 255) {
michael@0 95 resA = SkAlphaBlend(resA, dstA, a + (a >> 7));
michael@0 96 }
michael@0 97 dst[i] = resA;
michael@0 98 }
michael@0 99 }
michael@0 100 } else {
michael@0 101 for (int i = 0; i < count; ++i) {
michael@0 102 dst[i] = SkAlphaBlend(SkGetPackedA32(src[i]), dst[i], scale);
michael@0 103 }
michael@0 104 }
michael@0 105 }
michael@0 106
michael@0 107 #ifndef SK_IGNORE_TO_STRING
michael@0 108 void SkLerpXfermode::toString(SkString* str) const {
michael@0 109 str->printf("SkLerpXfermode: scale: %g", fScale256 / 256.0);
michael@0 110 }
michael@0 111 #endif

mercurial