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 2012 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 GrTextureDomainEffect_DEFINED |
michael@0 | 9 | #define GrTextureDomainEffect_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "GrSingleTextureEffect.h" |
michael@0 | 12 | #include "gl/GrGLEffect.h" |
michael@0 | 13 | |
michael@0 | 14 | class GrGLShaderBuilder; |
michael@0 | 15 | struct SkRect; |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * Limits a texture's lookup coordinates to a domain. Samples outside the domain are either clamped |
michael@0 | 19 | * the edge of the domain or result in a vec4 of zeros (decal mode). The domain is clipped to |
michael@0 | 20 | * normalized texture coords ([0,1]x[0,1] square). Bilinear filtering can cause texels outside the |
michael@0 | 21 | * domain to affect the read value unless the caller considers this when calculating the domain. |
michael@0 | 22 | */ |
michael@0 | 23 | class GrTextureDomain { |
michael@0 | 24 | public: |
michael@0 | 25 | enum Mode { |
michael@0 | 26 | kIgnore_Mode, // Ignore the texture domain rectangle. |
michael@0 | 27 | kClamp_Mode, // Clamp texture coords to the domain rectangle. |
michael@0 | 28 | kDecal_Mode, // Treat the area outside the domain rectangle as fully transparent. |
michael@0 | 29 | |
michael@0 | 30 | kLastMode = kDecal_Mode |
michael@0 | 31 | }; |
michael@0 | 32 | static const int kModeCount = kLastMode + 1; |
michael@0 | 33 | |
michael@0 | 34 | static const GrTextureDomain& IgnoredDomain() { |
michael@0 | 35 | static const SkRect gDummyRect = {0, 0, 0, 0}; |
michael@0 | 36 | static const GrTextureDomain gDomain(gDummyRect, kIgnore_Mode); |
michael@0 | 37 | return gDomain; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | /** |
michael@0 | 41 | * @param index Pass a value >= 0 if using multiple texture domains in the same effect. |
michael@0 | 42 | * It is used to keep inserted variables from causing name collisions. |
michael@0 | 43 | */ |
michael@0 | 44 | GrTextureDomain(const SkRect& domain, Mode, int index = -1); |
michael@0 | 45 | |
michael@0 | 46 | const SkRect& domain() const { return fDomain; } |
michael@0 | 47 | Mode mode() const { return fMode; } |
michael@0 | 48 | |
michael@0 | 49 | /* Computes a domain that bounds all the texels in texelRect. Note that with bilerp enabled |
michael@0 | 50 | texels neighboring the domain may be read. */ |
michael@0 | 51 | static const SkRect MakeTexelDomain(const GrTexture* texture, const SkIRect& texelRect) { |
michael@0 | 52 | SkScalar wInv = SK_Scalar1 / texture->width(); |
michael@0 | 53 | SkScalar hInv = SK_Scalar1 / texture->height(); |
michael@0 | 54 | SkRect result = { |
michael@0 | 55 | texelRect.fLeft * wInv, |
michael@0 | 56 | texelRect.fTop * hInv, |
michael@0 | 57 | texelRect.fRight * wInv, |
michael@0 | 58 | texelRect.fBottom * hInv |
michael@0 | 59 | }; |
michael@0 | 60 | return result; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | bool operator== (const GrTextureDomain& that) const { |
michael@0 | 64 | return fMode == that.fMode && fDomain == that.fDomain; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | /** |
michael@0 | 68 | * A GrGLEffect subclass that corresponds to a GrEffect subclass that uses GrTextureDomain |
michael@0 | 69 | * should include this helper. It generates the texture domain GLSL, produces the part of the |
michael@0 | 70 | * effect key that reflects the texture domain code, and performs the uniform uploads necessary |
michael@0 | 71 | * for texture domains. |
michael@0 | 72 | */ |
michael@0 | 73 | class GLDomain { |
michael@0 | 74 | public: |
michael@0 | 75 | GLDomain() { |
michael@0 | 76 | fPrevDomain[0] = SK_FloatNaN; |
michael@0 | 77 | SkDEBUGCODE(fMode = (Mode) -1;) |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * Call this from GrGLEffect::emitCode() to sample the texture W.R.T. the domain and mode. |
michael@0 | 82 | * |
michael@0 | 83 | * @param outcolor name of vec4 variable to hold the sampled color. |
michael@0 | 84 | * @param inCoords name of vec2 variable containing the coords to be used with the domain. |
michael@0 | 85 | * It is assumed that this is a variable and not an expression. |
michael@0 | 86 | * @param inModulateColor if non-NULL the sampled color will be modulated with this |
michael@0 | 87 | * expression before being written to outColor. |
michael@0 | 88 | */ |
michael@0 | 89 | void sampleTexture(GrGLShaderBuilder* builder, |
michael@0 | 90 | const GrTextureDomain& textureDomain, |
michael@0 | 91 | const char* outColor, |
michael@0 | 92 | const SkString& inCoords, |
michael@0 | 93 | const GrGLEffect::TextureSampler sampler, |
michael@0 | 94 | const char* inModulateColor = NULL); |
michael@0 | 95 | |
michael@0 | 96 | /** |
michael@0 | 97 | * Call this from GrGLEffect::setData() to upload uniforms necessary for the texture domain. |
michael@0 | 98 | * The rectangle is automatically adjusted to account for the texture's origin. |
michael@0 | 99 | */ |
michael@0 | 100 | void setData(const GrGLUniformManager& uman, const GrTextureDomain& textureDomain, |
michael@0 | 101 | GrSurfaceOrigin textureOrigin); |
michael@0 | 102 | |
michael@0 | 103 | enum { |
michael@0 | 104 | kDomainKeyBits = 2, // See DomainKey(). |
michael@0 | 105 | }; |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * GrGLEffect::GenKey() must call this and include the returned value in it's computed key. |
michael@0 | 109 | * The returned will be limited to the lower kDomainKeyBits bits. |
michael@0 | 110 | */ |
michael@0 | 111 | static GrGLEffect::EffectKey DomainKey(const GrTextureDomain& domain) { |
michael@0 | 112 | GR_STATIC_ASSERT(kModeCount <= 4); |
michael@0 | 113 | return domain.mode(); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | private: |
michael@0 | 117 | SkDEBUGCODE(Mode fMode;) |
michael@0 | 118 | GrGLUniformManager::UniformHandle fDomainUni; |
michael@0 | 119 | SkString fDomainName; |
michael@0 | 120 | GrGLfloat fPrevDomain[4]; |
michael@0 | 121 | }; |
michael@0 | 122 | |
michael@0 | 123 | protected: |
michael@0 | 124 | Mode fMode; |
michael@0 | 125 | SkRect fDomain; |
michael@0 | 126 | int fIndex; |
michael@0 | 127 | |
michael@0 | 128 | typedef GrSingleTextureEffect INHERITED; |
michael@0 | 129 | }; |
michael@0 | 130 | |
michael@0 | 131 | class GrGLTextureDomainEffect; |
michael@0 | 132 | |
michael@0 | 133 | /** |
michael@0 | 134 | * A basic texture effect that uses GrTextureDomain. |
michael@0 | 135 | */ |
michael@0 | 136 | class GrTextureDomainEffect : public GrSingleTextureEffect { |
michael@0 | 137 | |
michael@0 | 138 | public: |
michael@0 | 139 | static GrEffectRef* Create(GrTexture*, |
michael@0 | 140 | const SkMatrix&, |
michael@0 | 141 | const SkRect& domain, |
michael@0 | 142 | GrTextureDomain::Mode, |
michael@0 | 143 | GrTextureParams::FilterMode filterMode, |
michael@0 | 144 | GrCoordSet = kLocal_GrCoordSet); |
michael@0 | 145 | |
michael@0 | 146 | virtual ~GrTextureDomainEffect(); |
michael@0 | 147 | |
michael@0 | 148 | static const char* Name() { return "TextureDomain"; } |
michael@0 | 149 | |
michael@0 | 150 | typedef GrGLTextureDomainEffect GLEffect; |
michael@0 | 151 | |
michael@0 | 152 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
michael@0 | 153 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
michael@0 | 154 | |
michael@0 | 155 | const GrTextureDomain& textureDomain() const { return fTextureDomain; } |
michael@0 | 156 | |
michael@0 | 157 | protected: |
michael@0 | 158 | GrTextureDomain fTextureDomain; |
michael@0 | 159 | |
michael@0 | 160 | private: |
michael@0 | 161 | GrTextureDomainEffect(GrTexture*, |
michael@0 | 162 | const SkMatrix&, |
michael@0 | 163 | const SkRect& domain, |
michael@0 | 164 | GrTextureDomain::Mode, |
michael@0 | 165 | GrTextureParams::FilterMode, |
michael@0 | 166 | GrCoordSet); |
michael@0 | 167 | |
michael@0 | 168 | virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
michael@0 | 169 | |
michael@0 | 170 | GR_DECLARE_EFFECT_TEST; |
michael@0 | 171 | |
michael@0 | 172 | typedef GrSingleTextureEffect INHERITED; |
michael@0 | 173 | }; |
michael@0 | 174 | |
michael@0 | 175 | #endif |