gfx/skia/trunk/src/core/SkBitmapProcState_matrix.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 2011 Google Inc.
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 #include "SkMath.h"
michael@0 10 #include "SkMathPriv.h"
michael@0 11
michael@0 12 #define SCALE_NOFILTER_NAME MAKENAME(_nofilter_scale)
michael@0 13 #define SCALE_FILTER_NAME MAKENAME(_filter_scale)
michael@0 14 #define AFFINE_NOFILTER_NAME MAKENAME(_nofilter_affine)
michael@0 15 #define AFFINE_FILTER_NAME MAKENAME(_filter_affine)
michael@0 16 #define PERSP_NOFILTER_NAME MAKENAME(_nofilter_persp)
michael@0 17 #define PERSP_FILTER_NAME MAKENAME(_filter_persp)
michael@0 18
michael@0 19 #define PACK_FILTER_X_NAME MAKENAME(_pack_filter_x)
michael@0 20 #define PACK_FILTER_Y_NAME MAKENAME(_pack_filter_y)
michael@0 21
michael@0 22 #ifndef PREAMBLE
michael@0 23 #define PREAMBLE(state)
michael@0 24 #define PREAMBLE_PARAM_X
michael@0 25 #define PREAMBLE_PARAM_Y
michael@0 26 #define PREAMBLE_ARG_X
michael@0 27 #define PREAMBLE_ARG_Y
michael@0 28 #endif
michael@0 29
michael@0 30 // declare functions externally to suppress warnings.
michael@0 31 void SCALE_NOFILTER_NAME(const SkBitmapProcState& s,
michael@0 32 uint32_t xy[], int count, int x, int y);
michael@0 33 void AFFINE_NOFILTER_NAME(const SkBitmapProcState& s,
michael@0 34 uint32_t xy[], int count, int x, int y);
michael@0 35 void PERSP_NOFILTER_NAME(const SkBitmapProcState& s,
michael@0 36 uint32_t* SK_RESTRICT xy,
michael@0 37 int count, int x, int y);
michael@0 38 void SCALE_FILTER_NAME(const SkBitmapProcState& s,
michael@0 39 uint32_t xy[], int count, int x, int y);
michael@0 40 void AFFINE_FILTER_NAME(const SkBitmapProcState& s,
michael@0 41 uint32_t xy[], int count, int x, int y);
michael@0 42 void PERSP_FILTER_NAME(const SkBitmapProcState& s,
michael@0 43 uint32_t* SK_RESTRICT xy, int count,
michael@0 44 int x, int y);
michael@0 45
michael@0 46 void SCALE_NOFILTER_NAME(const SkBitmapProcState& s,
michael@0 47 uint32_t xy[], int count, int x, int y) {
michael@0 48 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
michael@0 49 SkMatrix::kScale_Mask)) == 0);
michael@0 50
michael@0 51 PREAMBLE(s);
michael@0 52 // we store y, x, x, x, x, x
michael@0 53
michael@0 54 const unsigned maxX = s.fBitmap->width() - 1;
michael@0 55 SkFractionalInt fx;
michael@0 56 {
michael@0 57 SkPoint pt;
michael@0 58 s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf,
michael@0 59 SkIntToScalar(y) + SK_ScalarHalf, &pt);
michael@0 60 fx = SkScalarToFractionalInt(pt.fY);
michael@0 61 const unsigned maxY = s.fBitmap->height() - 1;
michael@0 62 *xy++ = TILEY_PROCF(SkFractionalIntToFixed(fx), maxY);
michael@0 63 fx = SkScalarToFractionalInt(pt.fX);
michael@0 64 }
michael@0 65
michael@0 66 if (0 == maxX) {
michael@0 67 // all of the following X values must be 0
michael@0 68 memset(xy, 0, count * sizeof(uint16_t));
michael@0 69 return;
michael@0 70 }
michael@0 71
michael@0 72 const SkFractionalInt dx = s.fInvSxFractionalInt;
michael@0 73
michael@0 74 #ifdef CHECK_FOR_DECAL
michael@0 75 if (can_truncate_to_fixed_for_decal(fx, dx, count, maxX)) {
michael@0 76 decal_nofilter_scale(xy, SkFractionalIntToFixed(fx),
michael@0 77 SkFractionalIntToFixed(dx), count);
michael@0 78 } else
michael@0 79 #endif
michael@0 80 {
michael@0 81 int i;
michael@0 82 for (i = (count >> 2); i > 0; --i) {
michael@0 83 unsigned a, b;
michael@0 84 a = TILEX_PROCF(SkFractionalIntToFixed(fx), maxX); fx += dx;
michael@0 85 b = TILEX_PROCF(SkFractionalIntToFixed(fx), maxX); fx += dx;
michael@0 86 #ifdef SK_CPU_BENDIAN
michael@0 87 *xy++ = (a << 16) | b;
michael@0 88 #else
michael@0 89 *xy++ = (b << 16) | a;
michael@0 90 #endif
michael@0 91 a = TILEX_PROCF(SkFractionalIntToFixed(fx), maxX); fx += dx;
michael@0 92 b = TILEX_PROCF(SkFractionalIntToFixed(fx), maxX); fx += dx;
michael@0 93 #ifdef SK_CPU_BENDIAN
michael@0 94 *xy++ = (a << 16) | b;
michael@0 95 #else
michael@0 96 *xy++ = (b << 16) | a;
michael@0 97 #endif
michael@0 98 }
michael@0 99 uint16_t* xx = (uint16_t*)xy;
michael@0 100 for (i = (count & 3); i > 0; --i) {
michael@0 101 *xx++ = TILEX_PROCF(SkFractionalIntToFixed(fx), maxX); fx += dx;
michael@0 102 }
michael@0 103 }
michael@0 104 }
michael@0 105
michael@0 106 // note: we could special-case on a matrix which is skewed in X but not Y.
michael@0 107 // this would require a more general setup thatn SCALE does, but could use
michael@0 108 // SCALE's inner loop that only looks at dx
michael@0 109
michael@0 110 void AFFINE_NOFILTER_NAME(const SkBitmapProcState& s,
michael@0 111 uint32_t xy[], int count, int x, int y) {
michael@0 112 SkASSERT(s.fInvType & SkMatrix::kAffine_Mask);
michael@0 113 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
michael@0 114 SkMatrix::kScale_Mask |
michael@0 115 SkMatrix::kAffine_Mask)) == 0);
michael@0 116
michael@0 117 PREAMBLE(s);
michael@0 118 SkPoint srcPt;
michael@0 119 s.fInvProc(s.fInvMatrix,
michael@0 120 SkIntToScalar(x) + SK_ScalarHalf,
michael@0 121 SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
michael@0 122
michael@0 123 SkFractionalInt fx = SkScalarToFractionalInt(srcPt.fX);
michael@0 124 SkFractionalInt fy = SkScalarToFractionalInt(srcPt.fY);
michael@0 125 SkFractionalInt dx = s.fInvSxFractionalInt;
michael@0 126 SkFractionalInt dy = s.fInvKyFractionalInt;
michael@0 127 int maxX = s.fBitmap->width() - 1;
michael@0 128 int maxY = s.fBitmap->height() - 1;
michael@0 129
michael@0 130 for (int i = count; i > 0; --i) {
michael@0 131 *xy++ = (TILEY_PROCF(SkFractionalIntToFixed(fy), maxY) << 16) |
michael@0 132 TILEX_PROCF(SkFractionalIntToFixed(fx), maxX);
michael@0 133 fx += dx; fy += dy;
michael@0 134 }
michael@0 135 }
michael@0 136
michael@0 137 void PERSP_NOFILTER_NAME(const SkBitmapProcState& s,
michael@0 138 uint32_t* SK_RESTRICT xy,
michael@0 139 int count, int x, int y) {
michael@0 140 SkASSERT(s.fInvType & SkMatrix::kPerspective_Mask);
michael@0 141
michael@0 142 PREAMBLE(s);
michael@0 143 int maxX = s.fBitmap->width() - 1;
michael@0 144 int maxY = s.fBitmap->height() - 1;
michael@0 145
michael@0 146 SkPerspIter iter(s.fInvMatrix,
michael@0 147 SkIntToScalar(x) + SK_ScalarHalf,
michael@0 148 SkIntToScalar(y) + SK_ScalarHalf, count);
michael@0 149
michael@0 150 while ((count = iter.next()) != 0) {
michael@0 151 const SkFixed* SK_RESTRICT srcXY = iter.getXY();
michael@0 152 while (--count >= 0) {
michael@0 153 *xy++ = (TILEY_PROCF(srcXY[1], maxY) << 16) |
michael@0 154 TILEX_PROCF(srcXY[0], maxX);
michael@0 155 srcXY += 2;
michael@0 156 }
michael@0 157 }
michael@0 158 }
michael@0 159
michael@0 160 //////////////////////////////////////////////////////////////////////////////
michael@0 161
michael@0 162 static inline uint32_t PACK_FILTER_Y_NAME(SkFixed f, unsigned max,
michael@0 163 SkFixed one PREAMBLE_PARAM_Y) {
michael@0 164 unsigned i = TILEY_PROCF(f, max);
michael@0 165 i = (i << 4) | TILEY_LOW_BITS(f, max);
michael@0 166 return (i << 14) | (TILEY_PROCF((f + one), max));
michael@0 167 }
michael@0 168
michael@0 169 static inline uint32_t PACK_FILTER_X_NAME(SkFixed f, unsigned max,
michael@0 170 SkFixed one PREAMBLE_PARAM_X) {
michael@0 171 unsigned i = TILEX_PROCF(f, max);
michael@0 172 i = (i << 4) | TILEX_LOW_BITS(f, max);
michael@0 173 return (i << 14) | (TILEX_PROCF((f + one), max));
michael@0 174 }
michael@0 175
michael@0 176 void SCALE_FILTER_NAME(const SkBitmapProcState& s,
michael@0 177 uint32_t xy[], int count, int x, int y) {
michael@0 178 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
michael@0 179 SkMatrix::kScale_Mask)) == 0);
michael@0 180 SkASSERT(s.fInvKy == 0);
michael@0 181
michael@0 182 PREAMBLE(s);
michael@0 183
michael@0 184 const unsigned maxX = s.fBitmap->width() - 1;
michael@0 185 const SkFixed one = s.fFilterOneX;
michael@0 186 const SkFractionalInt dx = s.fInvSxFractionalInt;
michael@0 187 SkFractionalInt fx;
michael@0 188
michael@0 189 {
michael@0 190 SkPoint pt;
michael@0 191 s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf,
michael@0 192 SkIntToScalar(y) + SK_ScalarHalf, &pt);
michael@0 193 const SkFixed fy = SkScalarToFixed(pt.fY) - (s.fFilterOneY >> 1);
michael@0 194 const unsigned maxY = s.fBitmap->height() - 1;
michael@0 195 // compute our two Y values up front
michael@0 196 *xy++ = PACK_FILTER_Y_NAME(fy, maxY, s.fFilterOneY PREAMBLE_ARG_Y);
michael@0 197 // now initialize fx
michael@0 198 fx = SkScalarToFractionalInt(pt.fX) - (SkFixedToFractionalInt(one) >> 1);
michael@0 199 }
michael@0 200
michael@0 201 #ifdef CHECK_FOR_DECAL
michael@0 202 if (can_truncate_to_fixed_for_decal(fx, dx, count, maxX)) {
michael@0 203 decal_filter_scale(xy, SkFractionalIntToFixed(fx),
michael@0 204 SkFractionalIntToFixed(dx), count);
michael@0 205 } else
michael@0 206 #endif
michael@0 207 {
michael@0 208 do {
michael@0 209 SkFixed fixedFx = SkFractionalIntToFixed(fx);
michael@0 210 *xy++ = PACK_FILTER_X_NAME(fixedFx, maxX, one PREAMBLE_ARG_X);
michael@0 211 fx += dx;
michael@0 212 } while (--count != 0);
michael@0 213 }
michael@0 214 }
michael@0 215
michael@0 216 void AFFINE_FILTER_NAME(const SkBitmapProcState& s,
michael@0 217 uint32_t xy[], int count, int x, int y) {
michael@0 218 SkASSERT(s.fInvType & SkMatrix::kAffine_Mask);
michael@0 219 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
michael@0 220 SkMatrix::kScale_Mask |
michael@0 221 SkMatrix::kAffine_Mask)) == 0);
michael@0 222
michael@0 223 PREAMBLE(s);
michael@0 224 SkPoint srcPt;
michael@0 225 s.fInvProc(s.fInvMatrix,
michael@0 226 SkIntToScalar(x) + SK_ScalarHalf,
michael@0 227 SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
michael@0 228
michael@0 229 SkFixed oneX = s.fFilterOneX;
michael@0 230 SkFixed oneY = s.fFilterOneY;
michael@0 231 SkFixed fx = SkScalarToFixed(srcPt.fX) - (oneX >> 1);
michael@0 232 SkFixed fy = SkScalarToFixed(srcPt.fY) - (oneY >> 1);
michael@0 233 SkFixed dx = s.fInvSx;
michael@0 234 SkFixed dy = s.fInvKy;
michael@0 235 unsigned maxX = s.fBitmap->width() - 1;
michael@0 236 unsigned maxY = s.fBitmap->height() - 1;
michael@0 237
michael@0 238 do {
michael@0 239 *xy++ = PACK_FILTER_Y_NAME(fy, maxY, oneY PREAMBLE_ARG_Y);
michael@0 240 fy += dy;
michael@0 241 *xy++ = PACK_FILTER_X_NAME(fx, maxX, oneX PREAMBLE_ARG_X);
michael@0 242 fx += dx;
michael@0 243 } while (--count != 0);
michael@0 244 }
michael@0 245
michael@0 246 void PERSP_FILTER_NAME(const SkBitmapProcState& s,
michael@0 247 uint32_t* SK_RESTRICT xy, int count,
michael@0 248 int x, int y) {
michael@0 249 SkASSERT(s.fInvType & SkMatrix::kPerspective_Mask);
michael@0 250
michael@0 251 PREAMBLE(s);
michael@0 252 unsigned maxX = s.fBitmap->width() - 1;
michael@0 253 unsigned maxY = s.fBitmap->height() - 1;
michael@0 254 SkFixed oneX = s.fFilterOneX;
michael@0 255 SkFixed oneY = s.fFilterOneY;
michael@0 256
michael@0 257 SkPerspIter iter(s.fInvMatrix,
michael@0 258 SkIntToScalar(x) + SK_ScalarHalf,
michael@0 259 SkIntToScalar(y) + SK_ScalarHalf, count);
michael@0 260
michael@0 261 while ((count = iter.next()) != 0) {
michael@0 262 const SkFixed* SK_RESTRICT srcXY = iter.getXY();
michael@0 263 do {
michael@0 264 *xy++ = PACK_FILTER_Y_NAME(srcXY[1] - (oneY >> 1), maxY,
michael@0 265 oneY PREAMBLE_ARG_Y);
michael@0 266 *xy++ = PACK_FILTER_X_NAME(srcXY[0] - (oneX >> 1), maxX,
michael@0 267 oneX PREAMBLE_ARG_X);
michael@0 268 srcXY += 2;
michael@0 269 } while (--count != 0);
michael@0 270 }
michael@0 271 }
michael@0 272
michael@0 273 static SkBitmapProcState::MatrixProc MAKENAME(_Procs)[] = {
michael@0 274 SCALE_NOFILTER_NAME,
michael@0 275 SCALE_FILTER_NAME,
michael@0 276 AFFINE_NOFILTER_NAME,
michael@0 277 AFFINE_FILTER_NAME,
michael@0 278 PERSP_NOFILTER_NAME,
michael@0 279 PERSP_FILTER_NAME
michael@0 280 };
michael@0 281
michael@0 282 #undef MAKENAME
michael@0 283 #undef TILEX_PROCF
michael@0 284 #undef TILEY_PROCF
michael@0 285 #ifdef CHECK_FOR_DECAL
michael@0 286 #undef CHECK_FOR_DECAL
michael@0 287 #endif
michael@0 288
michael@0 289 #undef SCALE_NOFILTER_NAME
michael@0 290 #undef SCALE_FILTER_NAME
michael@0 291 #undef AFFINE_NOFILTER_NAME
michael@0 292 #undef AFFINE_FILTER_NAME
michael@0 293 #undef PERSP_NOFILTER_NAME
michael@0 294 #undef PERSP_FILTER_NAME
michael@0 295
michael@0 296 #undef PREAMBLE
michael@0 297 #undef PREAMBLE_PARAM_X
michael@0 298 #undef PREAMBLE_PARAM_Y
michael@0 299 #undef PREAMBLE_ARG_X
michael@0 300 #undef PREAMBLE_ARG_Y
michael@0 301
michael@0 302 #undef TILEX_LOW_BITS
michael@0 303 #undef TILEY_LOW_BITS

mercurial