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 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 | |
michael@0 | 10 | #ifndef GrPaint_DEFINED |
michael@0 | 11 | #define GrPaint_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "GrColor.h" |
michael@0 | 14 | #include "GrEffectStage.h" |
michael@0 | 15 | |
michael@0 | 16 | #include "SkXfermode.h" |
michael@0 | 17 | |
michael@0 | 18 | /** |
michael@0 | 19 | * The paint describes how color and coverage are computed at each pixel by GrContext draw |
michael@0 | 20 | * functions and the how color is blended with the destination pixel. |
michael@0 | 21 | * |
michael@0 | 22 | * The paint allows installation of custom color and coverage stages. New types of stages are |
michael@0 | 23 | * created by subclassing GrEffect. |
michael@0 | 24 | * |
michael@0 | 25 | * The primitive color computation starts with the color specified by setColor(). This color is the |
michael@0 | 26 | * input to the first color stage. Each color stage feeds its output to the next color stage. The |
michael@0 | 27 | * final color stage's output color is input to the color filter specified by |
michael@0 | 28 | * setXfermodeColorFilter which produces the final source color, S. |
michael@0 | 29 | * |
michael@0 | 30 | * Fractional pixel coverage follows a similar flow. The coverage is initially the value specified |
michael@0 | 31 | * by setCoverage(). This is input to the first coverage stage. Coverage stages are chained |
michael@0 | 32 | * together in the same manner as color stages. The output of the last stage is modulated by any |
michael@0 | 33 | * fractional coverage produced by anti-aliasing. This last step produces the final coverage, C. |
michael@0 | 34 | * |
michael@0 | 35 | * setBlendFunc() specifies blending coefficients for S (described above) and D, the initial value |
michael@0 | 36 | * of the destination pixel, labeled Bs and Bd respectively. The final value of the destination |
michael@0 | 37 | * pixel is then D' = (1-C)*D + C*(Bd*D + Bs*S). |
michael@0 | 38 | * |
michael@0 | 39 | * Note that the coverage is applied after the blend. This is why they are computed as distinct |
michael@0 | 40 | * values. |
michael@0 | 41 | * |
michael@0 | 42 | * TODO: Encapsulate setXfermodeColorFilter in a GrEffect and remove from GrPaint. |
michael@0 | 43 | */ |
michael@0 | 44 | class GrPaint { |
michael@0 | 45 | public: |
michael@0 | 46 | GrPaint() { this->reset(); } |
michael@0 | 47 | |
michael@0 | 48 | GrPaint(const GrPaint& paint) { *this = paint; } |
michael@0 | 49 | |
michael@0 | 50 | ~GrPaint() {} |
michael@0 | 51 | |
michael@0 | 52 | /** |
michael@0 | 53 | * Sets the blending coefficients to use to blend the final primitive color with the |
michael@0 | 54 | * destination color. Defaults to kOne for src and kZero for dst (i.e. src mode). |
michael@0 | 55 | */ |
michael@0 | 56 | void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { |
michael@0 | 57 | fSrcBlendCoeff = srcCoeff; |
michael@0 | 58 | fDstBlendCoeff = dstCoeff; |
michael@0 | 59 | } |
michael@0 | 60 | GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlendCoeff; } |
michael@0 | 61 | GrBlendCoeff getDstBlendCoeff() const { return fDstBlendCoeff; } |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * The initial color of the drawn primitive. Defaults to solid white. |
michael@0 | 65 | */ |
michael@0 | 66 | void setColor(GrColor color) { fColor = color; } |
michael@0 | 67 | GrColor getColor() const { return fColor; } |
michael@0 | 68 | |
michael@0 | 69 | /** |
michael@0 | 70 | * Applies fractional coverage to the entire drawn primitive. Defaults to 0xff. |
michael@0 | 71 | */ |
michael@0 | 72 | void setCoverage(uint8_t coverage) { fCoverage = coverage; } |
michael@0 | 73 | uint8_t getCoverage() const { return fCoverage; } |
michael@0 | 74 | |
michael@0 | 75 | /** |
michael@0 | 76 | * Should primitives be anti-aliased or not. Defaults to false. |
michael@0 | 77 | */ |
michael@0 | 78 | void setAntiAlias(bool aa) { fAntiAlias = aa; } |
michael@0 | 79 | bool isAntiAlias() const { return fAntiAlias; } |
michael@0 | 80 | |
michael@0 | 81 | /** |
michael@0 | 82 | * Should dithering be applied. Defaults to false. |
michael@0 | 83 | */ |
michael@0 | 84 | void setDither(bool dither) { fDither = dither; } |
michael@0 | 85 | bool isDither() const { return fDither; } |
michael@0 | 86 | |
michael@0 | 87 | /** |
michael@0 | 88 | * Appends an additional color effect to the color computation. |
michael@0 | 89 | */ |
michael@0 | 90 | const GrEffectRef* addColorEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) { |
michael@0 | 91 | SkASSERT(NULL != effect); |
michael@0 | 92 | if (!(*effect)->willUseInputColor()) { |
michael@0 | 93 | fColorStages.reset(); |
michael@0 | 94 | } |
michael@0 | 95 | SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, attr1)); |
michael@0 | 96 | return effect; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | /** |
michael@0 | 100 | * Appends an additional coverage effect to the coverage computation. |
michael@0 | 101 | */ |
michael@0 | 102 | const GrEffectRef* addCoverageEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) { |
michael@0 | 103 | SkASSERT(NULL != effect); |
michael@0 | 104 | if (!(*effect)->willUseInputColor()) { |
michael@0 | 105 | fCoverageStages.reset(); |
michael@0 | 106 | } |
michael@0 | 107 | SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1)); |
michael@0 | 108 | return effect; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | /** |
michael@0 | 112 | * Helpers for adding color or coverage effects that sample a texture. The matrix is applied |
michael@0 | 113 | * to the src space position to compute texture coordinates. |
michael@0 | 114 | */ |
michael@0 | 115 | void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix); |
michael@0 | 116 | void addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matrix); |
michael@0 | 117 | |
michael@0 | 118 | void addColorTextureEffect(GrTexture* texture, |
michael@0 | 119 | const SkMatrix& matrix, |
michael@0 | 120 | const GrTextureParams& params); |
michael@0 | 121 | void addCoverageTextureEffect(GrTexture* texture, |
michael@0 | 122 | const SkMatrix& matrix, |
michael@0 | 123 | const GrTextureParams& params); |
michael@0 | 124 | |
michael@0 | 125 | int numColorStages() const { return fColorStages.count(); } |
michael@0 | 126 | int numCoverageStages() const { return fCoverageStages.count(); } |
michael@0 | 127 | int numTotalStages() const { return this->numColorStages() + this->numCoverageStages(); } |
michael@0 | 128 | |
michael@0 | 129 | const GrEffectStage& getColorStage(int s) const { return fColorStages[s]; } |
michael@0 | 130 | const GrEffectStage& getCoverageStage(int s) const { return fCoverageStages[s]; } |
michael@0 | 131 | |
michael@0 | 132 | GrPaint& operator=(const GrPaint& paint) { |
michael@0 | 133 | fSrcBlendCoeff = paint.fSrcBlendCoeff; |
michael@0 | 134 | fDstBlendCoeff = paint.fDstBlendCoeff; |
michael@0 | 135 | fAntiAlias = paint.fAntiAlias; |
michael@0 | 136 | fDither = paint.fDither; |
michael@0 | 137 | |
michael@0 | 138 | fColor = paint.fColor; |
michael@0 | 139 | fCoverage = paint.fCoverage; |
michael@0 | 140 | |
michael@0 | 141 | fColorStages = paint.fColorStages; |
michael@0 | 142 | fCoverageStages = paint.fCoverageStages; |
michael@0 | 143 | |
michael@0 | 144 | return *this; |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | /** |
michael@0 | 148 | * Resets the paint to the defaults. |
michael@0 | 149 | */ |
michael@0 | 150 | void reset() { |
michael@0 | 151 | this->resetBlend(); |
michael@0 | 152 | this->resetOptions(); |
michael@0 | 153 | this->resetColor(); |
michael@0 | 154 | this->resetCoverage(); |
michael@0 | 155 | this->resetStages(); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | /** |
michael@0 | 159 | * Determines whether the drawing with this paint is opaque with respect to both color blending |
michael@0 | 160 | * and fractional coverage. It does not consider whether AA has been enabled on the paint or |
michael@0 | 161 | * not. Depending upon whether multisampling or coverage-based AA is in use, AA may make the |
michael@0 | 162 | * result only apply to the interior of primitives. |
michael@0 | 163 | * |
michael@0 | 164 | */ |
michael@0 | 165 | bool isOpaque() const; |
michael@0 | 166 | |
michael@0 | 167 | /** |
michael@0 | 168 | * Returns true if isOpaque would return true and the paint represents a solid constant color |
michael@0 | 169 | * draw. If the result is true, constantColor will be updated to contain the constant color. |
michael@0 | 170 | */ |
michael@0 | 171 | bool isOpaqueAndConstantColor(GrColor* constantColor) const; |
michael@0 | 172 | |
michael@0 | 173 | private: |
michael@0 | 174 | |
michael@0 | 175 | /** |
michael@0 | 176 | * Helper for isOpaque and isOpaqueAndConstantColor. |
michael@0 | 177 | */ |
michael@0 | 178 | bool getOpaqueAndKnownColor(GrColor* solidColor, uint32_t* solidColorKnownComponents) const; |
michael@0 | 179 | |
michael@0 | 180 | /** |
michael@0 | 181 | * Called when the source coord system from which geometry is rendered changes. It ensures that |
michael@0 | 182 | * the local coordinates seen by effects remains unchanged. oldToNew gives the transformation |
michael@0 | 183 | * from the previous coord system to the new coord system. |
michael@0 | 184 | */ |
michael@0 | 185 | void localCoordChange(const SkMatrix& oldToNew) { |
michael@0 | 186 | for (int i = 0; i < fColorStages.count(); ++i) { |
michael@0 | 187 | fColorStages[i].localCoordChange(oldToNew); |
michael@0 | 188 | } |
michael@0 | 189 | for (int i = 0; i < fCoverageStages.count(); ++i) { |
michael@0 | 190 | fCoverageStages[i].localCoordChange(oldToNew); |
michael@0 | 191 | } |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | bool localCoordChangeInverse(const SkMatrix& newToOld) { |
michael@0 | 195 | SkMatrix oldToNew; |
michael@0 | 196 | bool computed = false; |
michael@0 | 197 | for (int i = 0; i < fColorStages.count(); ++i) { |
michael@0 | 198 | if (!computed && !newToOld.invert(&oldToNew)) { |
michael@0 | 199 | return false; |
michael@0 | 200 | } else { |
michael@0 | 201 | computed = true; |
michael@0 | 202 | } |
michael@0 | 203 | fColorStages[i].localCoordChange(oldToNew); |
michael@0 | 204 | } |
michael@0 | 205 | for (int i = 0; i < fCoverageStages.count(); ++i) { |
michael@0 | 206 | if (!computed && !newToOld.invert(&oldToNew)) { |
michael@0 | 207 | return false; |
michael@0 | 208 | } else { |
michael@0 | 209 | computed = true; |
michael@0 | 210 | } |
michael@0 | 211 | fCoverageStages[i].localCoordChange(oldToNew); |
michael@0 | 212 | } |
michael@0 | 213 | return true; |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | friend class GrContext; // To access above two functions |
michael@0 | 217 | |
michael@0 | 218 | SkSTArray<4, GrEffectStage> fColorStages; |
michael@0 | 219 | SkSTArray<2, GrEffectStage> fCoverageStages; |
michael@0 | 220 | |
michael@0 | 221 | GrBlendCoeff fSrcBlendCoeff; |
michael@0 | 222 | GrBlendCoeff fDstBlendCoeff; |
michael@0 | 223 | bool fAntiAlias; |
michael@0 | 224 | bool fDither; |
michael@0 | 225 | |
michael@0 | 226 | GrColor fColor; |
michael@0 | 227 | uint8_t fCoverage; |
michael@0 | 228 | |
michael@0 | 229 | void resetBlend() { |
michael@0 | 230 | fSrcBlendCoeff = kOne_GrBlendCoeff; |
michael@0 | 231 | fDstBlendCoeff = kZero_GrBlendCoeff; |
michael@0 | 232 | } |
michael@0 | 233 | |
michael@0 | 234 | void resetOptions() { |
michael@0 | 235 | fAntiAlias = false; |
michael@0 | 236 | fDither = false; |
michael@0 | 237 | } |
michael@0 | 238 | |
michael@0 | 239 | void resetColor() { |
michael@0 | 240 | fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff); |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | void resetCoverage() { |
michael@0 | 244 | fCoverage = 0xff; |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | void resetStages() { |
michael@0 | 248 | fColorStages.reset(); |
michael@0 | 249 | fCoverageStages.reset(); |
michael@0 | 250 | } |
michael@0 | 251 | }; |
michael@0 | 252 | |
michael@0 | 253 | #endif |