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 2007 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 SkBitmapProcState_DEFINED |
michael@0 | 11 | #define SkBitmapProcState_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "SkBitmap.h" |
michael@0 | 14 | #include "SkBitmapFilter.h" |
michael@0 | 15 | #include "SkMatrix.h" |
michael@0 | 16 | #include "SkPaint.h" |
michael@0 | 17 | #include "SkScaledImageCache.h" |
michael@0 | 18 | |
michael@0 | 19 | #define FractionalInt_IS_64BIT |
michael@0 | 20 | |
michael@0 | 21 | #ifdef FractionalInt_IS_64BIT |
michael@0 | 22 | typedef SkFixed48 SkFractionalInt; |
michael@0 | 23 | #define SkScalarToFractionalInt(x) SkScalarToFixed48(x) |
michael@0 | 24 | #define SkFractionalIntToFixed(x) SkFixed48ToFixed(x) |
michael@0 | 25 | #define SkFixedToFractionalInt(x) SkFixedToFixed48(x) |
michael@0 | 26 | #define SkFractionalIntToInt(x) SkFixed48ToInt(x) |
michael@0 | 27 | #else |
michael@0 | 28 | typedef SkFixed SkFractionalInt; |
michael@0 | 29 | #define SkScalarToFractionalInt(x) SkScalarToFixed(x) |
michael@0 | 30 | #define SkFractionalIntToFixed(x) (x) |
michael@0 | 31 | #define SkFixedToFractionalInt(x) (x) |
michael@0 | 32 | #define SkFractionalIntToInt(x) ((x) >> 16) |
michael@0 | 33 | #endif |
michael@0 | 34 | |
michael@0 | 35 | class SkPaint; |
michael@0 | 36 | struct SkConvolutionProcs; |
michael@0 | 37 | |
michael@0 | 38 | struct SkBitmapProcState { |
michael@0 | 39 | |
michael@0 | 40 | SkBitmapProcState(): fScaledCacheID(NULL), fBitmapFilter(NULL) {} |
michael@0 | 41 | ~SkBitmapProcState(); |
michael@0 | 42 | |
michael@0 | 43 | typedef void (*ShaderProc32)(const SkBitmapProcState&, int x, int y, |
michael@0 | 44 | SkPMColor[], int count); |
michael@0 | 45 | |
michael@0 | 46 | typedef void (*ShaderProc16)(const SkBitmapProcState&, int x, int y, |
michael@0 | 47 | uint16_t[], int count); |
michael@0 | 48 | |
michael@0 | 49 | typedef void (*MatrixProc)(const SkBitmapProcState&, |
michael@0 | 50 | uint32_t bitmapXY[], |
michael@0 | 51 | int count, |
michael@0 | 52 | int x, int y); |
michael@0 | 53 | |
michael@0 | 54 | typedef void (*SampleProc32)(const SkBitmapProcState&, |
michael@0 | 55 | const uint32_t[], |
michael@0 | 56 | int count, |
michael@0 | 57 | SkPMColor colors[]); |
michael@0 | 58 | |
michael@0 | 59 | typedef void (*SampleProc16)(const SkBitmapProcState&, |
michael@0 | 60 | const uint32_t[], |
michael@0 | 61 | int count, |
michael@0 | 62 | uint16_t colors[]); |
michael@0 | 63 | |
michael@0 | 64 | typedef U16CPU (*FixedTileProc)(SkFixed); // returns 0..0xFFFF |
michael@0 | 65 | typedef U16CPU (*FixedTileLowBitsProc)(SkFixed, int); // returns 0..0xF |
michael@0 | 66 | typedef U16CPU (*IntTileProc)(int value, int count); // returns 0..count-1 |
michael@0 | 67 | |
michael@0 | 68 | const SkBitmap* fBitmap; // chooseProcs - orig or scaled |
michael@0 | 69 | SkMatrix fInvMatrix; // chooseProcs |
michael@0 | 70 | SkMatrix::MapXYProc fInvProc; // chooseProcs |
michael@0 | 71 | |
michael@0 | 72 | SkFractionalInt fInvSxFractionalInt; |
michael@0 | 73 | SkFractionalInt fInvKyFractionalInt; |
michael@0 | 74 | |
michael@0 | 75 | FixedTileProc fTileProcX; // chooseProcs |
michael@0 | 76 | FixedTileProc fTileProcY; // chooseProcs |
michael@0 | 77 | FixedTileLowBitsProc fTileLowBitsProcX; // chooseProcs |
michael@0 | 78 | FixedTileLowBitsProc fTileLowBitsProcY; // chooseProcs |
michael@0 | 79 | IntTileProc fIntTileProcY; // chooseProcs |
michael@0 | 80 | SkFixed fFilterOneX; |
michael@0 | 81 | SkFixed fFilterOneY; |
michael@0 | 82 | |
michael@0 | 83 | SkPMColor fPaintPMColor; // chooseProcs - A8 config |
michael@0 | 84 | SkFixed fInvSx; // chooseProcs |
michael@0 | 85 | SkFixed fInvKy; // chooseProcs |
michael@0 | 86 | uint16_t fAlphaScale; // chooseProcs |
michael@0 | 87 | uint8_t fInvType; // chooseProcs |
michael@0 | 88 | uint8_t fTileModeX; // CONSTRUCTOR |
michael@0 | 89 | uint8_t fTileModeY; // CONSTRUCTOR |
michael@0 | 90 | uint8_t fFilterLevel; // chooseProcs |
michael@0 | 91 | |
michael@0 | 92 | /** The shader will let us know when we can release some of our resources |
michael@0 | 93 | * like scaled bitmaps. |
michael@0 | 94 | */ |
michael@0 | 95 | |
michael@0 | 96 | void endContext(); |
michael@0 | 97 | |
michael@0 | 98 | /** Platforms implement this, and can optionally overwrite only the |
michael@0 | 99 | following fields: |
michael@0 | 100 | |
michael@0 | 101 | fShaderProc32 |
michael@0 | 102 | fShaderProc16 |
michael@0 | 103 | fMatrixProc |
michael@0 | 104 | fSampleProc32 |
michael@0 | 105 | fSampleProc32 |
michael@0 | 106 | |
michael@0 | 107 | They will already have valid function pointers, so a platform that does |
michael@0 | 108 | not have an accelerated version can just leave that field as is. A valid |
michael@0 | 109 | implementation can do nothing (see SkBitmapProcState_opts_none.cpp) |
michael@0 | 110 | */ |
michael@0 | 111 | void platformProcs(); |
michael@0 | 112 | |
michael@0 | 113 | /** Platforms can also optionally overwrite the convolution functions |
michael@0 | 114 | if we have SIMD versions of them. |
michael@0 | 115 | */ |
michael@0 | 116 | |
michael@0 | 117 | void platformConvolutionProcs(SkConvolutionProcs*); |
michael@0 | 118 | |
michael@0 | 119 | /** Given the byte size of the index buffer to be passed to the matrix proc, |
michael@0 | 120 | return the maximum number of resulting pixels that can be computed |
michael@0 | 121 | (i.e. the number of SkPMColor values to be written by the sample proc). |
michael@0 | 122 | This routine takes into account that filtering and scale-vs-affine |
michael@0 | 123 | affect the amount of buffer space needed. |
michael@0 | 124 | |
michael@0 | 125 | Only valid to call after chooseProcs (setContext) has been called. It is |
michael@0 | 126 | safe to call this inside the shader's shadeSpan() method. |
michael@0 | 127 | */ |
michael@0 | 128 | int maxCountForBufferSize(size_t bufferSize) const; |
michael@0 | 129 | |
michael@0 | 130 | // If a shader proc is present, then the corresponding matrix/sample procs |
michael@0 | 131 | // are ignored |
michael@0 | 132 | ShaderProc32 getShaderProc32() const { return fShaderProc32; } |
michael@0 | 133 | ShaderProc16 getShaderProc16() const { return fShaderProc16; } |
michael@0 | 134 | |
michael@0 | 135 | SkBitmapFilter* getBitmapFilter() const { return fBitmapFilter; } |
michael@0 | 136 | |
michael@0 | 137 | #ifdef SK_DEBUG |
michael@0 | 138 | MatrixProc getMatrixProc() const; |
michael@0 | 139 | #else |
michael@0 | 140 | MatrixProc getMatrixProc() const { return fMatrixProc; } |
michael@0 | 141 | #endif |
michael@0 | 142 | SampleProc32 getSampleProc32() const { return fSampleProc32; } |
michael@0 | 143 | SampleProc16 getSampleProc16() const { return fSampleProc16; } |
michael@0 | 144 | |
michael@0 | 145 | private: |
michael@0 | 146 | friend class SkBitmapProcShader; |
michael@0 | 147 | |
michael@0 | 148 | ShaderProc32 fShaderProc32; // chooseProcs |
michael@0 | 149 | ShaderProc16 fShaderProc16; // chooseProcs |
michael@0 | 150 | // These are used if the shaderproc is NULL |
michael@0 | 151 | MatrixProc fMatrixProc; // chooseProcs |
michael@0 | 152 | SampleProc32 fSampleProc32; // chooseProcs |
michael@0 | 153 | SampleProc16 fSampleProc16; // chooseProcs |
michael@0 | 154 | |
michael@0 | 155 | SkBitmap fOrigBitmap; // CONSTRUCTOR |
michael@0 | 156 | SkBitmap fScaledBitmap; // chooseProcs |
michael@0 | 157 | |
michael@0 | 158 | SkScaledImageCache::ID* fScaledCacheID; |
michael@0 | 159 | |
michael@0 | 160 | MatrixProc chooseMatrixProc(bool trivial_matrix); |
michael@0 | 161 | bool chooseProcs(const SkMatrix& inv, const SkPaint&); |
michael@0 | 162 | ShaderProc32 chooseShaderProc32(); |
michael@0 | 163 | |
michael@0 | 164 | // returns false if we did not try to scale the image. In that case, we |
michael@0 | 165 | // will need to "lock" its pixels some other way. |
michael@0 | 166 | bool possiblyScaleImage(); |
michael@0 | 167 | |
michael@0 | 168 | // returns false if we failed to "lock" the pixels at all. Typically this |
michael@0 | 169 | // means we have to abort the shader. |
michael@0 | 170 | bool lockBaseBitmap(); |
michael@0 | 171 | |
michael@0 | 172 | SkBitmapFilter* fBitmapFilter; |
michael@0 | 173 | |
michael@0 | 174 | // If supported, sets fShaderProc32 and fShaderProc16 and returns true, |
michael@0 | 175 | // otherwise returns false. |
michael@0 | 176 | bool setBitmapFilterProcs(); |
michael@0 | 177 | |
michael@0 | 178 | // Return false if we failed to setup for fast translate (e.g. overflow) |
michael@0 | 179 | bool setupForTranslate(); |
michael@0 | 180 | |
michael@0 | 181 | #ifdef SK_DEBUG |
michael@0 | 182 | static void DebugMatrixProc(const SkBitmapProcState&, |
michael@0 | 183 | uint32_t[], int count, int x, int y); |
michael@0 | 184 | #endif |
michael@0 | 185 | }; |
michael@0 | 186 | |
michael@0 | 187 | /* Macros for packing and unpacking pairs of 16bit values in a 32bit uint. |
michael@0 | 188 | Used to allow access to a stream of uint16_t either one at a time, or |
michael@0 | 189 | 2 at a time by unpacking a uint32_t |
michael@0 | 190 | */ |
michael@0 | 191 | #ifdef SK_CPU_BENDIAN |
michael@0 | 192 | #define PACK_TWO_SHORTS(pri, sec) ((pri) << 16 | (sec)) |
michael@0 | 193 | #define UNPACK_PRIMARY_SHORT(packed) ((uint32_t)(packed) >> 16) |
michael@0 | 194 | #define UNPACK_SECONDARY_SHORT(packed) ((packed) & 0xFFFF) |
michael@0 | 195 | #else |
michael@0 | 196 | #define PACK_TWO_SHORTS(pri, sec) ((pri) | ((sec) << 16)) |
michael@0 | 197 | #define UNPACK_PRIMARY_SHORT(packed) ((packed) & 0xFFFF) |
michael@0 | 198 | #define UNPACK_SECONDARY_SHORT(packed) ((uint32_t)(packed) >> 16) |
michael@0 | 199 | #endif |
michael@0 | 200 | |
michael@0 | 201 | #ifdef SK_DEBUG |
michael@0 | 202 | static inline uint32_t pack_two_shorts(U16CPU pri, U16CPU sec) { |
michael@0 | 203 | SkASSERT((uint16_t)pri == pri); |
michael@0 | 204 | SkASSERT((uint16_t)sec == sec); |
michael@0 | 205 | return PACK_TWO_SHORTS(pri, sec); |
michael@0 | 206 | } |
michael@0 | 207 | #else |
michael@0 | 208 | #define pack_two_shorts(pri, sec) PACK_TWO_SHORTS(pri, sec) |
michael@0 | 209 | #endif |
michael@0 | 210 | |
michael@0 | 211 | // These functions are generated via macros, but are exposed here so that |
michael@0 | 212 | // platformProcs may test for them by name. |
michael@0 | 213 | void S32_opaque_D32_filter_DX(const SkBitmapProcState& s, const uint32_t xy[], |
michael@0 | 214 | int count, SkPMColor colors[]); |
michael@0 | 215 | void S32_alpha_D32_filter_DX(const SkBitmapProcState& s, const uint32_t xy[], |
michael@0 | 216 | int count, SkPMColor colors[]); |
michael@0 | 217 | void S32_opaque_D32_filter_DXDY(const SkBitmapProcState& s, |
michael@0 | 218 | const uint32_t xy[], int count, SkPMColor colors[]); |
michael@0 | 219 | void S32_alpha_D32_filter_DXDY(const SkBitmapProcState& s, |
michael@0 | 220 | const uint32_t xy[], int count, SkPMColor colors[]); |
michael@0 | 221 | void ClampX_ClampY_filter_scale(const SkBitmapProcState& s, uint32_t xy[], |
michael@0 | 222 | int count, int x, int y); |
michael@0 | 223 | void ClampX_ClampY_nofilter_scale(const SkBitmapProcState& s, uint32_t xy[], |
michael@0 | 224 | int count, int x, int y); |
michael@0 | 225 | void ClampX_ClampY_filter_affine(const SkBitmapProcState& s, |
michael@0 | 226 | uint32_t xy[], int count, int x, int y); |
michael@0 | 227 | void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s, |
michael@0 | 228 | uint32_t xy[], int count, int x, int y); |
michael@0 | 229 | void S32_D16_filter_DX(const SkBitmapProcState& s, |
michael@0 | 230 | const uint32_t* xy, int count, uint16_t* colors); |
michael@0 | 231 | |
michael@0 | 232 | void highQualityFilter32(const SkBitmapProcState &s, int x, int y, |
michael@0 | 233 | SkPMColor *SK_RESTRICT colors, int count); |
michael@0 | 234 | void highQualityFilter16(const SkBitmapProcState &s, int x, int y, |
michael@0 | 235 | uint16_t *SK_RESTRICT colors, int count); |
michael@0 | 236 | |
michael@0 | 237 | |
michael@0 | 238 | #endif |