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 | #include "GrBicubicEffect.h" |
michael@0 | 2 | |
michael@0 | 3 | #define DS(x) SkDoubleToScalar(x) |
michael@0 | 4 | |
michael@0 | 5 | const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = { |
michael@0 | 6 | DS( 1.0 / 18.0), DS(-9.0 / 18.0), DS( 15.0 / 18.0), DS( -7.0 / 18.0), |
michael@0 | 7 | DS(16.0 / 18.0), DS( 0.0 / 18.0), DS(-36.0 / 18.0), DS( 21.0 / 18.0), |
michael@0 | 8 | DS( 1.0 / 18.0), DS( 9.0 / 18.0), DS( 27.0 / 18.0), DS(-21.0 / 18.0), |
michael@0 | 9 | DS( 0.0 / 18.0), DS( 0.0 / 18.0), DS( -6.0 / 18.0), DS( 7.0 / 18.0), |
michael@0 | 10 | }; |
michael@0 | 11 | |
michael@0 | 12 | |
michael@0 | 13 | class GrGLBicubicEffect : public GrGLEffect { |
michael@0 | 14 | public: |
michael@0 | 15 | GrGLBicubicEffect(const GrBackendEffectFactory& factory, |
michael@0 | 16 | const GrDrawEffect&); |
michael@0 | 17 | |
michael@0 | 18 | virtual void emitCode(GrGLShaderBuilder*, |
michael@0 | 19 | const GrDrawEffect&, |
michael@0 | 20 | EffectKey, |
michael@0 | 21 | const char* outputColor, |
michael@0 | 22 | const char* inputColor, |
michael@0 | 23 | const TransformedCoordsArray&, |
michael@0 | 24 | const TextureSamplerArray&) SK_OVERRIDE; |
michael@0 | 25 | |
michael@0 | 26 | virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE; |
michael@0 | 27 | |
michael@0 | 28 | static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) { |
michael@0 | 29 | const GrTextureDomain& domain = drawEffect.castEffect<GrBicubicEffect>().domain(); |
michael@0 | 30 | return GrTextureDomain::GLDomain::DomainKey(domain); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | private: |
michael@0 | 34 | typedef GrGLUniformManager::UniformHandle UniformHandle; |
michael@0 | 35 | |
michael@0 | 36 | UniformHandle fCoefficientsUni; |
michael@0 | 37 | UniformHandle fImageIncrementUni; |
michael@0 | 38 | GrTextureDomain::GLDomain fDomain; |
michael@0 | 39 | |
michael@0 | 40 | typedef GrGLEffect INHERITED; |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
michael@0 | 44 | : INHERITED(factory) { |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder, |
michael@0 | 48 | const GrDrawEffect& drawEffect, |
michael@0 | 49 | EffectKey key, |
michael@0 | 50 | const char* outputColor, |
michael@0 | 51 | const char* inputColor, |
michael@0 | 52 | const TransformedCoordsArray& coords, |
michael@0 | 53 | const TextureSamplerArray& samplers) { |
michael@0 | 54 | const GrTextureDomain& domain = drawEffect.castEffect<GrBicubicEffect>().domain(); |
michael@0 | 55 | |
michael@0 | 56 | SkString coords2D = builder->ensureFSCoords2D(coords, 0); |
michael@0 | 57 | fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
michael@0 | 58 | kMat44f_GrSLType, "Coefficients"); |
michael@0 | 59 | fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
michael@0 | 60 | kVec2f_GrSLType, "ImageIncrement"); |
michael@0 | 61 | |
michael@0 | 62 | const char* imgInc = builder->getUniformCStr(fImageIncrementUni); |
michael@0 | 63 | const char* coeff = builder->getUniformCStr(fCoefficientsUni); |
michael@0 | 64 | |
michael@0 | 65 | SkString cubicBlendName; |
michael@0 | 66 | |
michael@0 | 67 | static const GrGLShaderVar gCubicBlendArgs[] = { |
michael@0 | 68 | GrGLShaderVar("coefficients", kMat44f_GrSLType), |
michael@0 | 69 | GrGLShaderVar("t", kFloat_GrSLType), |
michael@0 | 70 | GrGLShaderVar("c0", kVec4f_GrSLType), |
michael@0 | 71 | GrGLShaderVar("c1", kVec4f_GrSLType), |
michael@0 | 72 | GrGLShaderVar("c2", kVec4f_GrSLType), |
michael@0 | 73 | GrGLShaderVar("c3", kVec4f_GrSLType), |
michael@0 | 74 | }; |
michael@0 | 75 | builder->fsEmitFunction(kVec4f_GrSLType, |
michael@0 | 76 | "cubicBlend", |
michael@0 | 77 | SK_ARRAY_COUNT(gCubicBlendArgs), |
michael@0 | 78 | gCubicBlendArgs, |
michael@0 | 79 | "\tvec4 ts = vec4(1.0, t, t * t, t * t * t);\n" |
michael@0 | 80 | "\tvec4 c = coefficients * ts;\n" |
michael@0 | 81 | "\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3;\n", |
michael@0 | 82 | &cubicBlendName); |
michael@0 | 83 | builder->fsCodeAppendf("\tvec2 coord = %s - %s * vec2(0.5);\n", coords2D.c_str(), imgInc); |
michael@0 | 84 | // We unnormalize the coord in order to determine our fractional offset (f) within the texel |
michael@0 | 85 | // We then snap coord to a texel center and renormalize. The snap prevents cases where the |
michael@0 | 86 | // starting coords are near a texel boundary and accumulations of imgInc would cause us to skip/ |
michael@0 | 87 | // double hit a texel. |
michael@0 | 88 | builder->fsCodeAppendf("\tcoord /= %s;\n", imgInc); |
michael@0 | 89 | builder->fsCodeAppend("\tvec2 f = fract(coord);\n"); |
michael@0 | 90 | builder->fsCodeAppendf("\tcoord = (coord - f + vec2(0.5)) * %s;\n", imgInc); |
michael@0 | 91 | builder->fsCodeAppend("\tvec4 rowColors[4];\n"); |
michael@0 | 92 | for (int y = 0; y < 4; ++y) { |
michael@0 | 93 | for (int x = 0; x < 4; ++x) { |
michael@0 | 94 | SkString coord; |
michael@0 | 95 | coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1); |
michael@0 | 96 | SkString sampleVar; |
michael@0 | 97 | sampleVar.printf("rowColors[%d]", x); |
michael@0 | 98 | fDomain.sampleTexture(builder, domain, sampleVar.c_str(), coord, samplers[0]); |
michael@0 | 99 | } |
michael@0 | 100 | builder->fsCodeAppendf("\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors[1], rowColors[2], rowColors[3]);\n", y, cubicBlendName.c_str(), coeff); |
michael@0 | 101 | } |
michael@0 | 102 | SkString bicubicColor; |
michael@0 | 103 | bicubicColor.printf("%s(%s, f.y, s0, s1, s2, s3)", cubicBlendName.c_str(), coeff); |
michael@0 | 104 | builder->fsCodeAppendf("\t%s = %s;\n", outputColor, (GrGLSLExpr4(bicubicColor.c_str()) * GrGLSLExpr4(inputColor)).c_str()); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | void GrGLBicubicEffect::setData(const GrGLUniformManager& uman, |
michael@0 | 108 | const GrDrawEffect& drawEffect) { |
michael@0 | 109 | const GrBicubicEffect& effect = drawEffect.castEffect<GrBicubicEffect>(); |
michael@0 | 110 | const GrTexture& texture = *effect.texture(0); |
michael@0 | 111 | float imageIncrement[2]; |
michael@0 | 112 | imageIncrement[0] = 1.0f / texture.width(); |
michael@0 | 113 | imageIncrement[1] = 1.0f / texture.height(); |
michael@0 | 114 | uman.set2fv(fImageIncrementUni, 1, imageIncrement); |
michael@0 | 115 | uman.setMatrix4f(fCoefficientsUni, effect.coefficients()); |
michael@0 | 116 | fDomain.setData(uman, effect.domain(), texture.origin()); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | static inline void convert_row_major_scalar_coeffs_to_column_major_floats(float dst[16], |
michael@0 | 120 | const SkScalar src[16]) { |
michael@0 | 121 | for (int y = 0; y < 4; y++) { |
michael@0 | 122 | for (int x = 0; x < 4; x++) { |
michael@0 | 123 | dst[x * 4 + y] = SkScalarToFloat(src[y * 4 + x]); |
michael@0 | 124 | } |
michael@0 | 125 | } |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | GrBicubicEffect::GrBicubicEffect(GrTexture* texture, |
michael@0 | 129 | const SkScalar coefficients[16], |
michael@0 | 130 | const SkMatrix &matrix, |
michael@0 | 131 | const SkShader::TileMode tileModes[2]) |
michael@0 | 132 | : INHERITED(texture, matrix, GrTextureParams(tileModes, GrTextureParams::kNone_FilterMode)) |
michael@0 | 133 | , fDomain(GrTextureDomain::IgnoredDomain()) { |
michael@0 | 134 | convert_row_major_scalar_coeffs_to_column_major_floats(fCoefficients, coefficients); |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | GrBicubicEffect::GrBicubicEffect(GrTexture* texture, |
michael@0 | 138 | const SkScalar coefficients[16], |
michael@0 | 139 | const SkMatrix &matrix, |
michael@0 | 140 | const SkRect& domain) |
michael@0 | 141 | : INHERITED(texture, matrix, GrTextureParams(SkShader::kClamp_TileMode, |
michael@0 | 142 | GrTextureParams::kNone_FilterMode)) |
michael@0 | 143 | , fDomain(domain, GrTextureDomain::kClamp_Mode) { |
michael@0 | 144 | convert_row_major_scalar_coeffs_to_column_major_floats(fCoefficients, coefficients); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | GrBicubicEffect::~GrBicubicEffect() { |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | const GrBackendEffectFactory& GrBicubicEffect::getFactory() const { |
michael@0 | 151 | return GrTBackendEffectFactory<GrBicubicEffect>::getInstance(); |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | bool GrBicubicEffect::onIsEqual(const GrEffect& sBase) const { |
michael@0 | 155 | const GrBicubicEffect& s = CastEffect<GrBicubicEffect>(sBase); |
michael@0 | 156 | return this->textureAccess(0) == s.textureAccess(0) && |
michael@0 | 157 | !memcmp(fCoefficients, s.coefficients(), 16); |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | void GrBicubicEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { |
michael@0 | 161 | // FIXME: Perhaps we can do better. |
michael@0 | 162 | *validFlags = 0; |
michael@0 | 163 | return; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | GR_DEFINE_EFFECT_TEST(GrBicubicEffect); |
michael@0 | 167 | |
michael@0 | 168 | GrEffectRef* GrBicubicEffect::TestCreate(SkRandom* random, |
michael@0 | 169 | GrContext* context, |
michael@0 | 170 | const GrDrawTargetCaps&, |
michael@0 | 171 | GrTexture* textures[]) { |
michael@0 | 172 | int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : |
michael@0 | 173 | GrEffectUnitTest::kAlphaTextureIdx; |
michael@0 | 174 | SkScalar coefficients[16]; |
michael@0 | 175 | for (int i = 0; i < 16; i++) { |
michael@0 | 176 | coefficients[i] = random->nextSScalar1(); |
michael@0 | 177 | } |
michael@0 | 178 | return GrBicubicEffect::Create(textures[texIdx], coefficients); |
michael@0 | 179 | } |