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 | * 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 | #ifndef GrBezierEffect_DEFINED |
michael@0 | 9 | #define GrBezierEffect_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "GrDrawTargetCaps.h" |
michael@0 | 12 | #include "GrEffect.h" |
michael@0 | 13 | #include "GrVertexEffect.h" |
michael@0 | 14 | #include "GrTypesPriv.h" |
michael@0 | 15 | |
michael@0 | 16 | /** |
michael@0 | 17 | * Shader is based off of Loop-Blinn Quadratic GPU Rendering |
michael@0 | 18 | * The output of this effect is a hairline edge for conics. |
michael@0 | 19 | * Conics specified by implicit equation K^2 - LM. |
michael@0 | 20 | * K, L, and M, are the first three values of the vertex attribute, |
michael@0 | 21 | * the fourth value is not used. Distance is calculated using a |
michael@0 | 22 | * first order approximation from the taylor series. |
michael@0 | 23 | * Coverage for AA is max(0, 1-distance). |
michael@0 | 24 | * |
michael@0 | 25 | * Test were also run using a second order distance approximation. |
michael@0 | 26 | * There were two versions of the second order approx. The first version |
michael@0 | 27 | * is of roughly the form: |
michael@0 | 28 | * f(q) = |f(p)| - ||f'(p)||*||q-p|| - ||f''(p)||*||q-p||^2. |
michael@0 | 29 | * The second is similar: |
michael@0 | 30 | * f(q) = |f(p)| + ||f'(p)||*||q-p|| + ||f''(p)||*||q-p||^2. |
michael@0 | 31 | * The exact version of the equations can be found in the paper |
michael@0 | 32 | * "Distance Approximations for Rasterizing Implicit Curves" by Gabriel Taubin |
michael@0 | 33 | * |
michael@0 | 34 | * In both versions we solve the quadratic for ||q-p||. |
michael@0 | 35 | * Version 1: |
michael@0 | 36 | * gFM is magnitude of first partials and gFM2 is magnitude of 2nd partials (as derived from paper) |
michael@0 | 37 | * builder->fsCodeAppend("\t\tedgeAlpha = (sqrt(gFM*gFM+4.0*func*gF2M) - gFM)/(2.0*gF2M);\n"); |
michael@0 | 38 | * Version 2: |
michael@0 | 39 | * builder->fsCodeAppend("\t\tedgeAlpha = (gFM - sqrt(gFM*gFM-4.0*func*gF2M))/(2.0*gF2M);\n"); |
michael@0 | 40 | * |
michael@0 | 41 | * Also note that 2nd partials of k,l,m are zero |
michael@0 | 42 | * |
michael@0 | 43 | * When comparing the two second order approximations to the first order approximations, |
michael@0 | 44 | * the following results were found. Version 1 tends to underestimate the distances, thus it |
michael@0 | 45 | * basically increases all the error that we were already seeing in the first order |
michael@0 | 46 | * approx. So this version is not the one to use. Version 2 has the opposite effect |
michael@0 | 47 | * and tends to overestimate the distances. This is much closer to what we are |
michael@0 | 48 | * looking for. It is able to render ellipses (even thin ones) without the need to chop. |
michael@0 | 49 | * However, it can not handle thin hyperbolas well and thus would still rely on |
michael@0 | 50 | * chopping to tighten the clipping. Another side effect of the overestimating is |
michael@0 | 51 | * that the curves become much thinner and "ropey". If all that was ever rendered |
michael@0 | 52 | * were "not too thin" curves and ellipses then 2nd order may have an advantage since |
michael@0 | 53 | * only one geometry would need to be rendered. However no benches were run comparing |
michael@0 | 54 | * chopped first order and non chopped 2nd order. |
michael@0 | 55 | */ |
michael@0 | 56 | class GrGLConicEffect; |
michael@0 | 57 | |
michael@0 | 58 | class GrConicEffect : public GrVertexEffect { |
michael@0 | 59 | public: |
michael@0 | 60 | static GrEffectRef* Create(const GrEffectEdgeType edgeType, const GrDrawTargetCaps& caps) { |
michael@0 | 61 | GR_CREATE_STATIC_EFFECT(gConicFillAA, GrConicEffect, (kFillAA_GrEffectEdgeType)); |
michael@0 | 62 | GR_CREATE_STATIC_EFFECT(gConicHairAA, GrConicEffect, (kHairlineAA_GrEffectEdgeType)); |
michael@0 | 63 | GR_CREATE_STATIC_EFFECT(gConicFillBW, GrConicEffect, (kFillBW_GrEffectEdgeType)); |
michael@0 | 64 | switch (edgeType) { |
michael@0 | 65 | case kFillAA_GrEffectEdgeType: |
michael@0 | 66 | if (!caps.shaderDerivativeSupport()) { |
michael@0 | 67 | return NULL; |
michael@0 | 68 | } |
michael@0 | 69 | gConicFillAA->ref(); |
michael@0 | 70 | return gConicFillAA; |
michael@0 | 71 | case kHairlineAA_GrEffectEdgeType: |
michael@0 | 72 | if (!caps.shaderDerivativeSupport()) { |
michael@0 | 73 | return NULL; |
michael@0 | 74 | } |
michael@0 | 75 | gConicHairAA->ref(); |
michael@0 | 76 | return gConicHairAA; |
michael@0 | 77 | case kFillBW_GrEffectEdgeType: |
michael@0 | 78 | gConicFillBW->ref(); |
michael@0 | 79 | return gConicFillBW; |
michael@0 | 80 | default: |
michael@0 | 81 | return NULL; |
michael@0 | 82 | } |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | virtual ~GrConicEffect(); |
michael@0 | 86 | |
michael@0 | 87 | static const char* Name() { return "Conic"; } |
michael@0 | 88 | |
michael@0 | 89 | inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType); } |
michael@0 | 90 | inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } |
michael@0 | 91 | inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
michael@0 | 92 | |
michael@0 | 93 | typedef GrGLConicEffect GLEffect; |
michael@0 | 94 | |
michael@0 | 95 | virtual void getConstantColorComponents(GrColor* color, |
michael@0 | 96 | uint32_t* validFlags) const SK_OVERRIDE { |
michael@0 | 97 | *validFlags = 0; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
michael@0 | 101 | |
michael@0 | 102 | private: |
michael@0 | 103 | GrConicEffect(GrEffectEdgeType); |
michael@0 | 104 | |
michael@0 | 105 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
michael@0 | 106 | |
michael@0 | 107 | GrEffectEdgeType fEdgeType; |
michael@0 | 108 | |
michael@0 | 109 | GR_DECLARE_EFFECT_TEST; |
michael@0 | 110 | |
michael@0 | 111 | typedef GrVertexEffect INHERITED; |
michael@0 | 112 | }; |
michael@0 | 113 | |
michael@0 | 114 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 115 | /** |
michael@0 | 116 | * The output of this effect is a hairline edge for quadratics. |
michael@0 | 117 | * Quadratic specified by 0=u^2-v canonical coords. u and v are the first |
michael@0 | 118 | * two components of the vertex attribute. At the three control points that define |
michael@0 | 119 | * the Quadratic, u, v have the values {0,0}, {1/2, 0}, and {1, 1} respectively. |
michael@0 | 120 | * Coverage for AA is min(0, 1-distance). 3rd & 4th cimponent unused. |
michael@0 | 121 | * Requires shader derivative instruction support. |
michael@0 | 122 | */ |
michael@0 | 123 | class GrGLQuadEffect; |
michael@0 | 124 | |
michael@0 | 125 | class GrQuadEffect : public GrVertexEffect { |
michael@0 | 126 | public: |
michael@0 | 127 | static GrEffectRef* Create(const GrEffectEdgeType edgeType, const GrDrawTargetCaps& caps) { |
michael@0 | 128 | GR_CREATE_STATIC_EFFECT(gQuadFillAA, GrQuadEffect, (kFillAA_GrEffectEdgeType)); |
michael@0 | 129 | GR_CREATE_STATIC_EFFECT(gQuadHairAA, GrQuadEffect, (kHairlineAA_GrEffectEdgeType)); |
michael@0 | 130 | GR_CREATE_STATIC_EFFECT(gQuadFillBW, GrQuadEffect, (kFillBW_GrEffectEdgeType)); |
michael@0 | 131 | switch (edgeType) { |
michael@0 | 132 | case kFillAA_GrEffectEdgeType: |
michael@0 | 133 | if (!caps.shaderDerivativeSupport()) { |
michael@0 | 134 | return NULL; |
michael@0 | 135 | } |
michael@0 | 136 | gQuadFillAA->ref(); |
michael@0 | 137 | return gQuadFillAA; |
michael@0 | 138 | case kHairlineAA_GrEffectEdgeType: |
michael@0 | 139 | if (!caps.shaderDerivativeSupport()) { |
michael@0 | 140 | return NULL; |
michael@0 | 141 | } |
michael@0 | 142 | gQuadHairAA->ref(); |
michael@0 | 143 | return gQuadHairAA; |
michael@0 | 144 | case kFillBW_GrEffectEdgeType: |
michael@0 | 145 | gQuadFillBW->ref(); |
michael@0 | 146 | return gQuadFillBW; |
michael@0 | 147 | default: |
michael@0 | 148 | return NULL; |
michael@0 | 149 | } |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | virtual ~GrQuadEffect(); |
michael@0 | 153 | |
michael@0 | 154 | static const char* Name() { return "Quad"; } |
michael@0 | 155 | |
michael@0 | 156 | inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType); } |
michael@0 | 157 | inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } |
michael@0 | 158 | inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
michael@0 | 159 | |
michael@0 | 160 | typedef GrGLQuadEffect GLEffect; |
michael@0 | 161 | |
michael@0 | 162 | virtual void getConstantColorComponents(GrColor* color, |
michael@0 | 163 | uint32_t* validFlags) const SK_OVERRIDE { |
michael@0 | 164 | *validFlags = 0; |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
michael@0 | 168 | |
michael@0 | 169 | private: |
michael@0 | 170 | GrQuadEffect(GrEffectEdgeType); |
michael@0 | 171 | |
michael@0 | 172 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
michael@0 | 173 | |
michael@0 | 174 | GrEffectEdgeType fEdgeType; |
michael@0 | 175 | |
michael@0 | 176 | GR_DECLARE_EFFECT_TEST; |
michael@0 | 177 | |
michael@0 | 178 | typedef GrVertexEffect INHERITED; |
michael@0 | 179 | }; |
michael@0 | 180 | |
michael@0 | 181 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 182 | /** |
michael@0 | 183 | * Shader is based off of "Resolution Independent Curve Rendering using |
michael@0 | 184 | * Programmable Graphics Hardware" by Loop and Blinn. |
michael@0 | 185 | * The output of this effect is a hairline edge for non rational cubics. |
michael@0 | 186 | * Cubics are specified by implicit equation K^3 - LM. |
michael@0 | 187 | * K, L, and M, are the first three values of the vertex attribute, |
michael@0 | 188 | * the fourth value is not used. Distance is calculated using a |
michael@0 | 189 | * first order approximation from the taylor series. |
michael@0 | 190 | * Coverage for AA is max(0, 1-distance). |
michael@0 | 191 | */ |
michael@0 | 192 | class GrGLCubicEffect; |
michael@0 | 193 | |
michael@0 | 194 | class GrCubicEffect : public GrVertexEffect { |
michael@0 | 195 | public: |
michael@0 | 196 | static GrEffectRef* Create(const GrEffectEdgeType edgeType, const GrDrawTargetCaps& caps) { |
michael@0 | 197 | GR_CREATE_STATIC_EFFECT(gCubicFillAA, GrCubicEffect, (kFillAA_GrEffectEdgeType)); |
michael@0 | 198 | GR_CREATE_STATIC_EFFECT(gCubicHairAA, GrCubicEffect, (kHairlineAA_GrEffectEdgeType)); |
michael@0 | 199 | GR_CREATE_STATIC_EFFECT(gCubicFillBW, GrCubicEffect, (kFillBW_GrEffectEdgeType)); |
michael@0 | 200 | switch (edgeType) { |
michael@0 | 201 | case kFillAA_GrEffectEdgeType: |
michael@0 | 202 | if (!caps.shaderDerivativeSupport()) { |
michael@0 | 203 | return NULL; |
michael@0 | 204 | } |
michael@0 | 205 | gCubicFillAA->ref(); |
michael@0 | 206 | return gCubicFillAA; |
michael@0 | 207 | case kHairlineAA_GrEffectEdgeType: |
michael@0 | 208 | if (!caps.shaderDerivativeSupport()) { |
michael@0 | 209 | return NULL; |
michael@0 | 210 | } |
michael@0 | 211 | gCubicHairAA->ref(); |
michael@0 | 212 | return gCubicHairAA; |
michael@0 | 213 | case kFillBW_GrEffectEdgeType: |
michael@0 | 214 | gCubicFillBW->ref(); |
michael@0 | 215 | return gCubicFillBW; |
michael@0 | 216 | default: |
michael@0 | 217 | return NULL; |
michael@0 | 218 | } |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | virtual ~GrCubicEffect(); |
michael@0 | 222 | |
michael@0 | 223 | static const char* Name() { return "Cubic"; } |
michael@0 | 224 | |
michael@0 | 225 | inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType); } |
michael@0 | 226 | inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } |
michael@0 | 227 | inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
michael@0 | 228 | |
michael@0 | 229 | typedef GrGLCubicEffect GLEffect; |
michael@0 | 230 | |
michael@0 | 231 | virtual void getConstantColorComponents(GrColor* color, |
michael@0 | 232 | uint32_t* validFlags) const SK_OVERRIDE { |
michael@0 | 233 | *validFlags = 0; |
michael@0 | 234 | } |
michael@0 | 235 | |
michael@0 | 236 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
michael@0 | 237 | |
michael@0 | 238 | private: |
michael@0 | 239 | GrCubicEffect(GrEffectEdgeType); |
michael@0 | 240 | |
michael@0 | 241 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
michael@0 | 242 | |
michael@0 | 243 | GrEffectEdgeType fEdgeType; |
michael@0 | 244 | |
michael@0 | 245 | GR_DECLARE_EFFECT_TEST; |
michael@0 | 246 | |
michael@0 | 247 | typedef GrVertexEffect INHERITED; |
michael@0 | 248 | }; |
michael@0 | 249 | |
michael@0 | 250 | #endif |