Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Unified Diff: src/gpu/effects/GrEllipseEdgeEffect.cpp

Issue 13344002: Move edge GrEffects to locally defined classes (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: rebase to head revision Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/effects/GrEllipseEdgeEffect.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/effects/GrEllipseEdgeEffect.cpp
===================================================================
--- src/gpu/effects/GrEllipseEdgeEffect.cpp (revision 8491)
+++ src/gpu/effects/GrEllipseEdgeEffect.cpp (working copy)
@@ -1,102 +0,0 @@
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrEllipseEdgeEffect.h"
-#include "gl/GrGLEffect.h"
-#include "gl/GrGLSL.h"
-#include "GrTBackendEffectFactory.h"
-
-class GrGLEllipseEdgeEffect : public GrGLEffect {
-public:
- GrGLEllipseEdgeEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
- : INHERITED (factory) {}
-
- virtual void emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect& drawEffect,
- EffectKey key,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray& samplers) SK_OVERRIDE {
- const GrEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<GrEllipseEdgeEffect>();
-
- const char *vsCenterName, *fsCenterName;
- const char *vsEdgeName, *fsEdgeName;
-
- builder->addVarying(kVec2f_GrSLType, "EllipseCenter", &vsCenterName, &fsCenterName);
- const SkString* attr0Name =
- builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]);
- builder->vsCodeAppendf("\t%s = %s;\n", vsCenterName, attr0Name->c_str());
-
- builder->addVarying(kVec4f_GrSLType, "EllipseEdge", &vsEdgeName, &fsEdgeName);
- const SkString* attr1Name =
- builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[1]);
- builder->vsCodeAppendf("\t%s = %s;\n", vsEdgeName, attr1Name->c_str());
-
- // translate to origin
- builder->fsCodeAppendf("\tvec2 outerOffset = (%s.xy - %s.xy);\n",
- builder->fragmentPosition(), fsCenterName);
- builder->fsCodeAppend("\tvec2 innerOffset = outerOffset;\n");
- // scale y by xRadius/yRadius
- builder->fsCodeAppendf("\touterOffset.y *= %s.y;\n", fsEdgeName);
- builder->fsCodeAppend("\tfloat dOuter = length(outerOffset);\n");
- // compare outer lengths against xOuterRadius
- builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.x-dOuter, 0.0, 1.0);\n", fsEdgeName);
-
- if (ellipseEffect.isStroked()) {
- builder->fsCodeAppendf("\tinnerOffset.y *= %s.w;\n", fsEdgeName);
- builder->fsCodeAppend("\tfloat dInner = length(innerOffset);\n");
-
- // compare inner lengths against xInnerRadius
- builder->fsCodeAppendf("\tfloat innerAlpha = clamp(dInner-%s.z, 0.0, 1.0);\n", fsEdgeName);
- builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n");
- }
-
- SkString modulate;
- GrGLSLModulate4f(&modulate, inputColor, "edgeAlpha");
- builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str());
- }
-
- static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- const GrEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<GrEllipseEdgeEffect>();
-
- return ellipseEffect.isStroked() ? 0x1 : 0x0;
- }
-
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {
- }
-
-private:
- typedef GrGLEffect INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-GrEllipseEdgeEffect::GrEllipseEdgeEffect(bool stroke) : GrEffect() {
- this->addVertexAttrib(kVec2f_GrSLType);
- this->addVertexAttrib(kVec4f_GrSLType);
-
- fStroke = stroke;
-}
-
-void GrEllipseEdgeEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
- *validFlags = 0;
-}
-
-const GrBackendEffectFactory& GrEllipseEdgeEffect::getFactory() const {
- return GrTBackendEffectFactory<GrEllipseEdgeEffect>::getInstance();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-GR_DEFINE_EFFECT_TEST(GrEllipseEdgeEffect);
-
-GrEffectRef* GrEllipseEdgeEffect::TestCreate(SkMWCRandom* random,
- GrContext* context,
- const GrDrawTargetCaps&,
- GrTexture* textures[]) {
- return GrEllipseEdgeEffect::Create(random->nextBool());
-}
« no previous file with comments | « src/gpu/effects/GrEllipseEdgeEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698