gfx/skia/trunk/src/gpu/effects/GrBezierEffect.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 #include "GrBezierEffect.h"
michael@0 9
michael@0 10 #include "gl/GrGLEffect.h"
michael@0 11 #include "gl/GrGLSL.h"
michael@0 12 #include "gl/GrGLVertexEffect.h"
michael@0 13 #include "GrTBackendEffectFactory.h"
michael@0 14
michael@0 15 class GrGLConicEffect : public GrGLVertexEffect {
michael@0 16 public:
michael@0 17 GrGLConicEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
michael@0 18
michael@0 19 virtual void emitCode(GrGLFullShaderBuilder* builder,
michael@0 20 const GrDrawEffect& drawEffect,
michael@0 21 EffectKey key,
michael@0 22 const char* outputColor,
michael@0 23 const char* inputColor,
michael@0 24 const TransformedCoordsArray&,
michael@0 25 const TextureSamplerArray&) SK_OVERRIDE;
michael@0 26
michael@0 27 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
michael@0 28
michael@0 29 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {}
michael@0 30
michael@0 31 private:
michael@0 32 GrEffectEdgeType fEdgeType;
michael@0 33
michael@0 34 typedef GrGLVertexEffect INHERITED;
michael@0 35 };
michael@0 36
michael@0 37 GrGLConicEffect::GrGLConicEffect(const GrBackendEffectFactory& factory,
michael@0 38 const GrDrawEffect& drawEffect)
michael@0 39 : INHERITED (factory) {
michael@0 40 const GrConicEffect& ce = drawEffect.castEffect<GrConicEffect>();
michael@0 41 fEdgeType = ce.getEdgeType();
michael@0 42 }
michael@0 43
michael@0 44 void GrGLConicEffect::emitCode(GrGLFullShaderBuilder* builder,
michael@0 45 const GrDrawEffect& drawEffect,
michael@0 46 EffectKey key,
michael@0 47 const char* outputColor,
michael@0 48 const char* inputColor,
michael@0 49 const TransformedCoordsArray&,
michael@0 50 const TextureSamplerArray& samplers) {
michael@0 51 const char *vsName, *fsName;
michael@0 52
michael@0 53 builder->addVarying(kVec4f_GrSLType, "ConicCoeffs",
michael@0 54 &vsName, &fsName);
michael@0 55 const SkString* attr0Name =
michael@0 56 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]);
michael@0 57 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str());
michael@0 58
michael@0 59 builder->fsCodeAppend("\t\tfloat edgeAlpha;\n");
michael@0 60
michael@0 61 switch (fEdgeType) {
michael@0 62 case kHairlineAA_GrEffectEdgeType: {
michael@0 63 SkAssertResult(builder->enableFeature(
michael@0 64 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature));
michael@0 65 builder->fsCodeAppendf("\t\tvec3 dklmdx = dFdx(%s.xyz);\n", fsName);
michael@0 66 builder->fsCodeAppendf("\t\tvec3 dklmdy = dFdy(%s.xyz);\n", fsName);
michael@0 67 builder->fsCodeAppendf("\t\tfloat dfdx =\n"
michael@0 68 "\t\t\t2.0*%s.x*dklmdx.x - %s.y*dklmdx.z - %s.z*dklmdx.y;\n",
michael@0 69 fsName, fsName, fsName);
michael@0 70 builder->fsCodeAppendf("\t\tfloat dfdy =\n"
michael@0 71 "\t\t\t2.0*%s.x*dklmdy.x - %s.y*dklmdy.z - %s.z*dklmdy.y;\n",
michael@0 72 fsName, fsName, fsName);
michael@0 73 builder->fsCodeAppend("\t\tvec2 gF = vec2(dfdx, dfdy);\n");
michael@0 74 builder->fsCodeAppend("\t\tfloat gFM = sqrt(dot(gF, gF));\n");
michael@0 75 builder->fsCodeAppendf("\t\tfloat func = %s.x*%s.x - %s.y*%s.z;\n", fsName, fsName,
michael@0 76 fsName, fsName);
michael@0 77 builder->fsCodeAppend("\t\tfunc = abs(func);\n");
michael@0 78 builder->fsCodeAppend("\t\tedgeAlpha = func / gFM;\n");
michael@0 79 builder->fsCodeAppend("\t\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n");
michael@0 80 // Add line below for smooth cubic ramp
michael@0 81 // builder->fsCodeAppend("\t\tedgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);\n");
michael@0 82 break;
michael@0 83 }
michael@0 84 case kFillAA_GrEffectEdgeType: {
michael@0 85 SkAssertResult(builder->enableFeature(
michael@0 86 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature));
michael@0 87 builder->fsCodeAppendf("\t\tvec3 dklmdx = dFdx(%s.xyz);\n", fsName);
michael@0 88 builder->fsCodeAppendf("\t\tvec3 dklmdy = dFdy(%s.xyz);\n", fsName);
michael@0 89 builder->fsCodeAppendf("\t\tfloat dfdx =\n"
michael@0 90 "\t\t\t2.0*%s.x*dklmdx.x - %s.y*dklmdx.z - %s.z*dklmdx.y;\n",
michael@0 91 fsName, fsName, fsName);
michael@0 92 builder->fsCodeAppendf("\t\tfloat dfdy =\n"
michael@0 93 "\t\t\t2.0*%s.x*dklmdy.x - %s.y*dklmdy.z - %s.z*dklmdy.y;\n",
michael@0 94 fsName, fsName, fsName);
michael@0 95 builder->fsCodeAppend("\t\tvec2 gF = vec2(dfdx, dfdy);\n");
michael@0 96 builder->fsCodeAppend("\t\tfloat gFM = sqrt(dot(gF, gF));\n");
michael@0 97 builder->fsCodeAppendf("\t\tfloat func = %s.x*%s.x - %s.y*%s.z;\n", fsName, fsName,
michael@0 98 fsName, fsName);
michael@0 99 builder->fsCodeAppend("\t\tedgeAlpha = func / gFM;\n");
michael@0 100 builder->fsCodeAppend("\t\tedgeAlpha = clamp(1.0 - edgeAlpha, 0.0, 1.0);\n");
michael@0 101 // Add line below for smooth cubic ramp
michael@0 102 // builder->fsCodeAppend("\t\tedgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);\n");
michael@0 103 break;
michael@0 104 }
michael@0 105 case kFillBW_GrEffectEdgeType: {
michael@0 106 builder->fsCodeAppendf("\t\tedgeAlpha = %s.x*%s.x - %s.y*%s.z;\n", fsName, fsName,
michael@0 107 fsName, fsName);
michael@0 108 builder->fsCodeAppend("\t\tedgeAlpha = float(edgeAlpha < 0.0);\n");
michael@0 109 break;
michael@0 110 }
michael@0 111 default:
michael@0 112 GrCrash("Shouldn't get here");
michael@0 113 }
michael@0 114
michael@0 115 builder->fsCodeAppendf("\t%s = %s;\n", outputColor,
michael@0 116 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeAlpha")).c_str());
michael@0 117 }
michael@0 118
michael@0 119 GrGLEffect::EffectKey GrGLConicEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
michael@0 120 const GrConicEffect& ce = drawEffect.castEffect<GrConicEffect>();
michael@0 121 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
michael@0 122 }
michael@0 123
michael@0 124 //////////////////////////////////////////////////////////////////////////////
michael@0 125
michael@0 126 GrConicEffect::~GrConicEffect() {}
michael@0 127
michael@0 128 const GrBackendEffectFactory& GrConicEffect::getFactory() const {
michael@0 129 return GrTBackendEffectFactory<GrConicEffect>::getInstance();
michael@0 130 }
michael@0 131
michael@0 132 GrConicEffect::GrConicEffect(GrEffectEdgeType edgeType) : GrVertexEffect() {
michael@0 133 this->addVertexAttrib(kVec4f_GrSLType);
michael@0 134 fEdgeType = edgeType;
michael@0 135 }
michael@0 136
michael@0 137 bool GrConicEffect::onIsEqual(const GrEffect& other) const {
michael@0 138 const GrConicEffect& ce = CastEffect<GrConicEffect>(other);
michael@0 139 return (ce.fEdgeType == fEdgeType);
michael@0 140 }
michael@0 141
michael@0 142 //////////////////////////////////////////////////////////////////////////////
michael@0 143
michael@0 144 GR_DEFINE_EFFECT_TEST(GrConicEffect);
michael@0 145
michael@0 146 GrEffectRef* GrConicEffect::TestCreate(SkRandom* random,
michael@0 147 GrContext*,
michael@0 148 const GrDrawTargetCaps& caps,
michael@0 149 GrTexture*[]) {
michael@0 150 GrEffectRef* effect;
michael@0 151 do {
michael@0 152 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(
michael@0 153 random->nextULessThan(kGrEffectEdgeTypeCnt));
michael@0 154 effect = GrConicEffect::Create(edgeType, caps);
michael@0 155 } while (NULL == effect);
michael@0 156 return effect;
michael@0 157 }
michael@0 158
michael@0 159 //////////////////////////////////////////////////////////////////////////////
michael@0 160 // Quad
michael@0 161 //////////////////////////////////////////////////////////////////////////////
michael@0 162
michael@0 163 class GrGLQuadEffect : public GrGLVertexEffect {
michael@0 164 public:
michael@0 165 GrGLQuadEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
michael@0 166
michael@0 167 virtual void emitCode(GrGLFullShaderBuilder* builder,
michael@0 168 const GrDrawEffect& drawEffect,
michael@0 169 EffectKey key,
michael@0 170 const char* outputColor,
michael@0 171 const char* inputColor,
michael@0 172 const TransformedCoordsArray&,
michael@0 173 const TextureSamplerArray&) SK_OVERRIDE;
michael@0 174
michael@0 175 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
michael@0 176
michael@0 177 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {}
michael@0 178
michael@0 179 private:
michael@0 180 GrEffectEdgeType fEdgeType;
michael@0 181
michael@0 182 typedef GrGLVertexEffect INHERITED;
michael@0 183 };
michael@0 184
michael@0 185 GrGLQuadEffect::GrGLQuadEffect(const GrBackendEffectFactory& factory,
michael@0 186 const GrDrawEffect& drawEffect)
michael@0 187 : INHERITED (factory) {
michael@0 188 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>();
michael@0 189 fEdgeType = ce.getEdgeType();
michael@0 190 }
michael@0 191
michael@0 192 void GrGLQuadEffect::emitCode(GrGLFullShaderBuilder* builder,
michael@0 193 const GrDrawEffect& drawEffect,
michael@0 194 EffectKey key,
michael@0 195 const char* outputColor,
michael@0 196 const char* inputColor,
michael@0 197 const TransformedCoordsArray&,
michael@0 198 const TextureSamplerArray& samplers) {
michael@0 199 const char *vsName, *fsName;
michael@0 200
michael@0 201 const SkString* attrName =
michael@0 202 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]);
michael@0 203 builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n");
michael@0 204
michael@0 205 builder->addVarying(kVec4f_GrSLType, "HairQuadEdge", &vsName, &fsName);
michael@0 206
michael@0 207 switch (fEdgeType) {
michael@0 208 case kHairlineAA_GrEffectEdgeType: {
michael@0 209 SkAssertResult(builder->enableFeature(
michael@0 210 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature));
michael@0 211 builder->fsCodeAppendf("\t\tvec2 duvdx = dFdx(%s.xy);\n", fsName);
michael@0 212 builder->fsCodeAppendf("\t\tvec2 duvdy = dFdy(%s.xy);\n", fsName);
michael@0 213 builder->fsCodeAppendf("\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,\n"
michael@0 214 "\t\t 2.0*%s.x*duvdy.x - duvdy.y);\n",
michael@0 215 fsName, fsName);
michael@0 216 builder->fsCodeAppendf("\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName,
michael@0 217 fsName);
michael@0 218 builder->fsCodeAppend("\t\tedgeAlpha = sqrt(edgeAlpha*edgeAlpha / dot(gF, gF));\n");
michael@0 219 builder->fsCodeAppend("\t\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n");
michael@0 220 // Add line below for smooth cubic ramp
michael@0 221 // builder->fsCodeAppend("\t\tedgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);\n");
michael@0 222 break;
michael@0 223 }
michael@0 224 case kFillAA_GrEffectEdgeType: {
michael@0 225 SkAssertResult(builder->enableFeature(
michael@0 226 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature));
michael@0 227 builder->fsCodeAppendf("\t\tvec2 duvdx = dFdx(%s.xy);\n", fsName);
michael@0 228 builder->fsCodeAppendf("\t\tvec2 duvdy = dFdy(%s.xy);\n", fsName);
michael@0 229 builder->fsCodeAppendf("\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,\n"
michael@0 230 "\t\t 2.0*%s.x*duvdy.x - duvdy.y);\n",
michael@0 231 fsName, fsName);
michael@0 232 builder->fsCodeAppendf("\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName,
michael@0 233 fsName);
michael@0 234 builder->fsCodeAppend("\t\tedgeAlpha = edgeAlpha / sqrt(dot(gF, gF));\n");
michael@0 235 builder->fsCodeAppend("\t\tedgeAlpha = clamp(1.0 - edgeAlpha, 0.0, 1.0);\n");
michael@0 236 // Add line below for smooth cubic ramp
michael@0 237 // builder->fsCodeAppend("\t\tedgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);\n");
michael@0 238 break;
michael@0 239 }
michael@0 240 case kFillBW_GrEffectEdgeType: {
michael@0 241 builder->fsCodeAppendf("\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName,
michael@0 242 fsName);
michael@0 243 builder->fsCodeAppend("\t\tedgeAlpha = float(edgeAlpha < 0.0);\n");
michael@0 244 break;
michael@0 245 }
michael@0 246 default:
michael@0 247 GrCrash("Shouldn't get here");
michael@0 248 }
michael@0 249
michael@0 250 builder->fsCodeAppendf("\t%s = %s;\n", outputColor,
michael@0 251 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeAlpha")).c_str());
michael@0 252
michael@0 253
michael@0 254 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str());
michael@0 255 }
michael@0 256
michael@0 257 GrGLEffect::EffectKey GrGLQuadEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
michael@0 258 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>();
michael@0 259 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
michael@0 260 }
michael@0 261
michael@0 262 //////////////////////////////////////////////////////////////////////////////
michael@0 263
michael@0 264 GrQuadEffect::~GrQuadEffect() {}
michael@0 265
michael@0 266 const GrBackendEffectFactory& GrQuadEffect::getFactory() const {
michael@0 267 return GrTBackendEffectFactory<GrQuadEffect>::getInstance();
michael@0 268 }
michael@0 269
michael@0 270 GrQuadEffect::GrQuadEffect(GrEffectEdgeType edgeType) : GrVertexEffect() {
michael@0 271 this->addVertexAttrib(kVec4f_GrSLType);
michael@0 272 fEdgeType = edgeType;
michael@0 273 }
michael@0 274
michael@0 275 bool GrQuadEffect::onIsEqual(const GrEffect& other) const {
michael@0 276 const GrQuadEffect& ce = CastEffect<GrQuadEffect>(other);
michael@0 277 return (ce.fEdgeType == fEdgeType);
michael@0 278 }
michael@0 279
michael@0 280 //////////////////////////////////////////////////////////////////////////////
michael@0 281
michael@0 282 GR_DEFINE_EFFECT_TEST(GrQuadEffect);
michael@0 283
michael@0 284 GrEffectRef* GrQuadEffect::TestCreate(SkRandom* random,
michael@0 285 GrContext*,
michael@0 286 const GrDrawTargetCaps& caps,
michael@0 287 GrTexture*[]) {
michael@0 288 GrEffectRef* effect;
michael@0 289 do {
michael@0 290 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(
michael@0 291 random->nextULessThan(kGrEffectEdgeTypeCnt));
michael@0 292 effect = GrQuadEffect::Create(edgeType, caps);
michael@0 293 } while (NULL == effect);
michael@0 294 return effect;
michael@0 295 }
michael@0 296
michael@0 297 //////////////////////////////////////////////////////////////////////////////
michael@0 298 // Cubic
michael@0 299 //////////////////////////////////////////////////////////////////////////////
michael@0 300
michael@0 301 class GrGLCubicEffect : public GrGLVertexEffect {
michael@0 302 public:
michael@0 303 GrGLCubicEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
michael@0 304
michael@0 305 virtual void emitCode(GrGLFullShaderBuilder* builder,
michael@0 306 const GrDrawEffect& drawEffect,
michael@0 307 EffectKey key,
michael@0 308 const char* outputColor,
michael@0 309 const char* inputColor,
michael@0 310 const TransformedCoordsArray&,
michael@0 311 const TextureSamplerArray&) SK_OVERRIDE;
michael@0 312
michael@0 313 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
michael@0 314
michael@0 315 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {}
michael@0 316
michael@0 317 private:
michael@0 318 GrEffectEdgeType fEdgeType;
michael@0 319
michael@0 320 typedef GrGLVertexEffect INHERITED;
michael@0 321 };
michael@0 322
michael@0 323 GrGLCubicEffect::GrGLCubicEffect(const GrBackendEffectFactory& factory,
michael@0 324 const GrDrawEffect& drawEffect)
michael@0 325 : INHERITED (factory) {
michael@0 326 const GrCubicEffect& ce = drawEffect.castEffect<GrCubicEffect>();
michael@0 327 fEdgeType = ce.getEdgeType();
michael@0 328 }
michael@0 329
michael@0 330 void GrGLCubicEffect::emitCode(GrGLFullShaderBuilder* builder,
michael@0 331 const GrDrawEffect& drawEffect,
michael@0 332 EffectKey key,
michael@0 333 const char* outputColor,
michael@0 334 const char* inputColor,
michael@0 335 const TransformedCoordsArray&,
michael@0 336 const TextureSamplerArray& samplers) {
michael@0 337 const char *vsName, *fsName;
michael@0 338
michael@0 339 builder->addVarying(kVec4f_GrSLType, "CubicCoeffs",
michael@0 340 &vsName, &fsName);
michael@0 341 const SkString* attr0Name =
michael@0 342 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]);
michael@0 343 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str());
michael@0 344
michael@0 345 builder->fsCodeAppend("\t\tfloat edgeAlpha;\n");
michael@0 346
michael@0 347 switch (fEdgeType) {
michael@0 348 case kHairlineAA_GrEffectEdgeType: {
michael@0 349 SkAssertResult(builder->enableFeature(
michael@0 350 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature));
michael@0 351 builder->fsCodeAppendf("\t\tvec3 dklmdx = dFdx(%s.xyz);\n", fsName);
michael@0 352 builder->fsCodeAppendf("\t\tvec3 dklmdy = dFdy(%s.xyz);\n", fsName);
michael@0 353 builder->fsCodeAppendf("\t\tfloat dfdx =\n"
michael@0 354 "\t\t3.0*%s.x*%s.x*dklmdx.x - %s.y*dklmdx.z - %s.z*dklmdx.y;\n",
michael@0 355 fsName, fsName, fsName, fsName);
michael@0 356 builder->fsCodeAppendf("\t\tfloat dfdy =\n"
michael@0 357 "\t\t3.0*%s.x*%s.x*dklmdy.x - %s.y*dklmdy.z - %s.z*dklmdy.y;\n",
michael@0 358 fsName, fsName, fsName, fsName);
michael@0 359 builder->fsCodeAppend("\t\tvec2 gF = vec2(dfdx, dfdy);\n");
michael@0 360 builder->fsCodeAppend("\t\tfloat gFM = sqrt(dot(gF, gF));\n");
michael@0 361 builder->fsCodeAppendf("\t\tfloat func = %s.x*%s.x*%s.x - %s.y*%s.z;\n",
michael@0 362 fsName, fsName, fsName, fsName, fsName);
michael@0 363 builder->fsCodeAppend("\t\tfunc = abs(func);\n");
michael@0 364 builder->fsCodeAppend("\t\tedgeAlpha = func / gFM;\n");
michael@0 365 builder->fsCodeAppend("\t\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n");
michael@0 366 // Add line below for smooth cubic ramp
michael@0 367 // builder->fsCodeAppend("\t\tedgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);\n");
michael@0 368 break;
michael@0 369 }
michael@0 370 case kFillAA_GrEffectEdgeType: {
michael@0 371 SkAssertResult(builder->enableFeature(
michael@0 372 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature));
michael@0 373 builder->fsCodeAppendf("\t\tvec3 dklmdx = dFdx(%s.xyz);\n", fsName);
michael@0 374 builder->fsCodeAppendf("\t\tvec3 dklmdy = dFdy(%s.xyz);\n", fsName);
michael@0 375 builder->fsCodeAppendf("\t\tfloat dfdx =\n"
michael@0 376 "\t\t3.0*%s.x*%s.x*dklmdx.x - %s.y*dklmdx.z - %s.z*dklmdx.y;\n",
michael@0 377 fsName, fsName, fsName, fsName);
michael@0 378 builder->fsCodeAppendf("\t\tfloat dfdy =\n"
michael@0 379 "\t\t3.0*%s.x*%s.x*dklmdy.x - %s.y*dklmdy.z - %s.z*dklmdy.y;\n",
michael@0 380 fsName, fsName, fsName, fsName);
michael@0 381 builder->fsCodeAppend("\t\tvec2 gF = vec2(dfdx, dfdy);\n");
michael@0 382 builder->fsCodeAppend("\t\tfloat gFM = sqrt(dot(gF, gF));\n");
michael@0 383 builder->fsCodeAppendf("\t\tfloat func = %s.x*%s.x*%s.x - %s.y*%s.z;\n",
michael@0 384 fsName, fsName, fsName, fsName, fsName);
michael@0 385 builder->fsCodeAppend("\t\tedgeAlpha = func / gFM;\n");
michael@0 386 builder->fsCodeAppend("\t\tedgeAlpha = clamp(1.0 - edgeAlpha, 0.0, 1.0);\n");
michael@0 387 // Add line below for smooth cubic ramp
michael@0 388 // builder->fsCodeAppend("\t\tedgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);\n");
michael@0 389 break;
michael@0 390 }
michael@0 391 case kFillBW_GrEffectEdgeType: {
michael@0 392 builder->fsCodeAppendf("\t\tedgeAlpha = %s.x*%s.x*%s.x - %s.y*%s.z;\n",
michael@0 393 fsName, fsName, fsName, fsName, fsName);
michael@0 394 builder->fsCodeAppend("\t\tedgeAlpha = float(edgeAlpha < 0.0);\n");
michael@0 395 break;
michael@0 396 }
michael@0 397 default:
michael@0 398 GrCrash("Shouldn't get here");
michael@0 399 }
michael@0 400
michael@0 401 builder->fsCodeAppendf("\t%s = %s;\n", outputColor,
michael@0 402 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeAlpha")).c_str());
michael@0 403 }
michael@0 404
michael@0 405 GrGLEffect::EffectKey GrGLCubicEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
michael@0 406 const GrCubicEffect& ce = drawEffect.castEffect<GrCubicEffect>();
michael@0 407 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
michael@0 408 }
michael@0 409
michael@0 410 //////////////////////////////////////////////////////////////////////////////
michael@0 411
michael@0 412 GrCubicEffect::~GrCubicEffect() {}
michael@0 413
michael@0 414 const GrBackendEffectFactory& GrCubicEffect::getFactory() const {
michael@0 415 return GrTBackendEffectFactory<GrCubicEffect>::getInstance();
michael@0 416 }
michael@0 417
michael@0 418 GrCubicEffect::GrCubicEffect(GrEffectEdgeType edgeType) : GrVertexEffect() {
michael@0 419 this->addVertexAttrib(kVec4f_GrSLType);
michael@0 420 fEdgeType = edgeType;
michael@0 421 }
michael@0 422
michael@0 423 bool GrCubicEffect::onIsEqual(const GrEffect& other) const {
michael@0 424 const GrCubicEffect& ce = CastEffect<GrCubicEffect>(other);
michael@0 425 return (ce.fEdgeType == fEdgeType);
michael@0 426 }
michael@0 427
michael@0 428 //////////////////////////////////////////////////////////////////////////////
michael@0 429
michael@0 430 GR_DEFINE_EFFECT_TEST(GrCubicEffect);
michael@0 431
michael@0 432 GrEffectRef* GrCubicEffect::TestCreate(SkRandom* random,
michael@0 433 GrContext*,
michael@0 434 const GrDrawTargetCaps& caps,
michael@0 435 GrTexture*[]) {
michael@0 436 GrEffectRef* effect;
michael@0 437 do {
michael@0 438 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(
michael@0 439 random->nextULessThan(kGrEffectEdgeTypeCnt));
michael@0 440 effect = GrCubicEffect::Create(edgeType, caps);
michael@0 441 } while (NULL == effect);
michael@0 442 return effect;
michael@0 443 }

mercurial