gfx/skia/trunk/src/core/SkAntiRun.h

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 #ifndef SkAntiRun_DEFINED
michael@0 11 #define SkAntiRun_DEFINED
michael@0 12
michael@0 13 #include "SkBlitter.h"
michael@0 14
michael@0 15 /** Sparse array of run-length-encoded alpha (supersampling coverage) values.
michael@0 16 Sparseness allows us to independently compose several paths into the
michael@0 17 same SkAlphaRuns buffer.
michael@0 18 */
michael@0 19
michael@0 20 class SkAlphaRuns {
michael@0 21 public:
michael@0 22 int16_t* fRuns;
michael@0 23 uint8_t* fAlpha;
michael@0 24
michael@0 25 /// Returns true if the scanline contains only a single run,
michael@0 26 /// of alpha value 0.
michael@0 27 bool empty() const {
michael@0 28 SkASSERT(fRuns[0] > 0);
michael@0 29 return fAlpha[0] == 0 && fRuns[fRuns[0]] == 0;
michael@0 30 }
michael@0 31
michael@0 32 /// Reinitialize for a new scanline.
michael@0 33 void reset(int width);
michael@0 34
michael@0 35 /**
michael@0 36 * Insert into the buffer a run starting at (x-offsetX):
michael@0 37 * if startAlpha > 0
michael@0 38 * one pixel with value += startAlpha,
michael@0 39 * max 255
michael@0 40 * if middleCount > 0
michael@0 41 * middleCount pixels with value += maxValue
michael@0 42 * if stopAlpha > 0
michael@0 43 * one pixel with value += stopAlpha
michael@0 44 * Returns the offsetX value that should be passed on the next call,
michael@0 45 * assuming we're on the same scanline. If the caller is switching
michael@0 46 * scanlines, then offsetX should be 0 when this is called.
michael@0 47 */
michael@0 48 SK_ALWAYS_INLINE int add(int x, U8CPU startAlpha, int middleCount, U8CPU stopAlpha,
michael@0 49 U8CPU maxValue, int offsetX) {
michael@0 50 SkASSERT(middleCount >= 0);
michael@0 51 SkASSERT(x >= 0 && x + (startAlpha != 0) + middleCount + (stopAlpha != 0) <= fWidth);
michael@0 52
michael@0 53 SkASSERT(fRuns[offsetX] >= 0);
michael@0 54
michael@0 55 int16_t* runs = fRuns + offsetX;
michael@0 56 uint8_t* alpha = fAlpha + offsetX;
michael@0 57 uint8_t* lastAlpha = alpha;
michael@0 58 x -= offsetX;
michael@0 59
michael@0 60 if (startAlpha) {
michael@0 61 SkAlphaRuns::Break(runs, alpha, x, 1);
michael@0 62 /* I should be able to just add alpha[x] + startAlpha.
michael@0 63 However, if the trailing edge of the previous span and the leading
michael@0 64 edge of the current span round to the same super-sampled x value,
michael@0 65 I might overflow to 256 with this add, hence the funny subtract (crud).
michael@0 66 */
michael@0 67 unsigned tmp = alpha[x] + startAlpha;
michael@0 68 SkASSERT(tmp <= 256);
michael@0 69 alpha[x] = SkToU8(tmp - (tmp >> 8)); // was (tmp >> 7), but that seems wrong if we're trying to catch 256
michael@0 70
michael@0 71 runs += x + 1;
michael@0 72 alpha += x + 1;
michael@0 73 x = 0;
michael@0 74 lastAlpha += x; // we don't want the +1
michael@0 75 SkDEBUGCODE(this->validate();)
michael@0 76 }
michael@0 77
michael@0 78 if (middleCount) {
michael@0 79 SkAlphaRuns::Break(runs, alpha, x, middleCount);
michael@0 80 alpha += x;
michael@0 81 runs += x;
michael@0 82 x = 0;
michael@0 83 do {
michael@0 84 alpha[0] = SkToU8(alpha[0] + maxValue);
michael@0 85 int n = runs[0];
michael@0 86 SkASSERT(n <= middleCount);
michael@0 87 alpha += n;
michael@0 88 runs += n;
michael@0 89 middleCount -= n;
michael@0 90 } while (middleCount > 0);
michael@0 91 SkDEBUGCODE(this->validate();)
michael@0 92 lastAlpha = alpha;
michael@0 93 }
michael@0 94
michael@0 95 if (stopAlpha) {
michael@0 96 SkAlphaRuns::Break(runs, alpha, x, 1);
michael@0 97 alpha += x;
michael@0 98 alpha[0] = SkToU8(alpha[0] + stopAlpha);
michael@0 99 SkDEBUGCODE(this->validate();)
michael@0 100 lastAlpha = alpha;
michael@0 101 }
michael@0 102
michael@0 103 return SkToS32(lastAlpha - fAlpha); // new offsetX
michael@0 104 }
michael@0 105
michael@0 106 SkDEBUGCODE(void assertValid(int y, int maxStep) const;)
michael@0 107 SkDEBUGCODE(void dump() const;)
michael@0 108
michael@0 109 /**
michael@0 110 * Break the runs in the buffer at offsets x and x+count, properly
michael@0 111 * updating the runs to the right and left.
michael@0 112 * i.e. from the state AAAABBBB, run-length encoded as A4B4,
michael@0 113 * Break(..., 2, 5) would produce AAAABBBB rle as A2A2B3B1.
michael@0 114 * Allows add() to sum another run to some of the new sub-runs.
michael@0 115 * i.e. adding ..CCCCC. would produce AADDEEEB, rle as A2D2E3B1.
michael@0 116 */
michael@0 117 static void Break(int16_t runs[], uint8_t alpha[], int x, int count) {
michael@0 118 SkASSERT(count > 0 && x >= 0);
michael@0 119
michael@0 120 // SkAlphaRuns::BreakAt(runs, alpha, x);
michael@0 121 // SkAlphaRuns::BreakAt(&runs[x], &alpha[x], count);
michael@0 122
michael@0 123 int16_t* next_runs = runs + x;
michael@0 124 uint8_t* next_alpha = alpha + x;
michael@0 125
michael@0 126 while (x > 0) {
michael@0 127 int n = runs[0];
michael@0 128 SkASSERT(n > 0);
michael@0 129
michael@0 130 if (x < n) {
michael@0 131 alpha[x] = alpha[0];
michael@0 132 runs[0] = SkToS16(x);
michael@0 133 runs[x] = SkToS16(n - x);
michael@0 134 break;
michael@0 135 }
michael@0 136 runs += n;
michael@0 137 alpha += n;
michael@0 138 x -= n;
michael@0 139 }
michael@0 140
michael@0 141 runs = next_runs;
michael@0 142 alpha = next_alpha;
michael@0 143 x = count;
michael@0 144
michael@0 145 for (;;) {
michael@0 146 int n = runs[0];
michael@0 147 SkASSERT(n > 0);
michael@0 148
michael@0 149 if (x < n) {
michael@0 150 alpha[x] = alpha[0];
michael@0 151 runs[0] = SkToS16(x);
michael@0 152 runs[x] = SkToS16(n - x);
michael@0 153 break;
michael@0 154 }
michael@0 155 x -= n;
michael@0 156 if (x <= 0) {
michael@0 157 break;
michael@0 158 }
michael@0 159 runs += n;
michael@0 160 alpha += n;
michael@0 161 }
michael@0 162 }
michael@0 163
michael@0 164 /**
michael@0 165 * Cut (at offset x in the buffer) a run into two shorter runs with
michael@0 166 * matching alpha values.
michael@0 167 * Used by the RectClipBlitter to trim a RLE encoding to match the
michael@0 168 * clipping rectangle.
michael@0 169 */
michael@0 170 static void BreakAt(int16_t runs[], uint8_t alpha[], int x) {
michael@0 171 while (x > 0) {
michael@0 172 int n = runs[0];
michael@0 173 SkASSERT(n > 0);
michael@0 174
michael@0 175 if (x < n) {
michael@0 176 alpha[x] = alpha[0];
michael@0 177 runs[0] = SkToS16(x);
michael@0 178 runs[x] = SkToS16(n - x);
michael@0 179 break;
michael@0 180 }
michael@0 181 runs += n;
michael@0 182 alpha += n;
michael@0 183 x -= n;
michael@0 184 }
michael@0 185 }
michael@0 186
michael@0 187 private:
michael@0 188 SkDEBUGCODE(int fWidth;)
michael@0 189 SkDEBUGCODE(void validate() const;)
michael@0 190 };
michael@0 191
michael@0 192 #endif

mercurial