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

Side by Side Diff: src/gpu/effects/GrCircleEdgeEffect.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, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/effects/GrCircleEdgeEffect.h ('k') | src/gpu/effects/GrEdgeEffect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrCircleEdgeEffect.h"
9 #include "gl/GrGLEffect.h"
10 #include "gl/GrGLSL.h"
11 #include "GrTBackendEffectFactory.h"
12
13 class GrGLCircleEdgeEffect : public GrGLEffect {
14 public:
15 GrGLCircleEdgeEffect(const GrBackendEffectFactory& factory, const GrDrawEffe ct&)
16 : INHERITED (factory) {}
17
18 virtual void emitCode(GrGLShaderBuilder* builder,
19 const GrDrawEffect& drawEffect,
20 EffectKey key,
21 const char* outputColor,
22 const char* inputColor,
23 const TextureSamplerArray& samplers) SK_OVERRIDE {
24 const GrCircleEdgeEffect& circleEffect = drawEffect.castEffect<GrCircleE dgeEffect>();
25 const char *vsName, *fsName;
26 builder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName);
27
28 const SkString* attrName =
29 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[ 0]);
30 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str());
31
32 builder->fsCodeAppendf("\tfloat d = distance(%s.xy, %s.xy);\n",
33 builder->fragmentPosition(), fsName);
34 builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0);\n ", fsName);
35 if (circleEffect.isStroked()) {
36 builder->fsCodeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0, 1. 0);\n", fsName);
37 builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n");
38 }
39 SkString modulate;
40 GrGLSLModulate4f(&modulate, inputColor, "edgeAlpha");
41 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str());
42 }
43
44 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap s&) {
45 const GrCircleEdgeEffect& circleEffect = drawEffect.castEffect<GrCircleE dgeEffect>();
46
47 return circleEffect.isStroked() ? 0x1 : 0x0;
48 }
49
50 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE {
51 }
52
53 private:
54 typedef GrGLEffect INHERITED;
55 };
56
57 ///////////////////////////////////////////////////////////////////////////////
58
59 GrCircleEdgeEffect::GrCircleEdgeEffect(bool stroke) : GrEffect() {
60 this->addVertexAttrib(kVec4f_GrSLType);
61 fStroke = stroke;
62 }
63
64 void GrCircleEdgeEffect::getConstantColorComponents(GrColor* color, uint32_t* va lidFlags) const {
65 *validFlags = 0;
66 }
67
68 const GrBackendEffectFactory& GrCircleEdgeEffect::getFactory() const {
69 return GrTBackendEffectFactory<GrCircleEdgeEffect>::getInstance();
70 }
71
72 ///////////////////////////////////////////////////////////////////////////////
73
74 GR_DEFINE_EFFECT_TEST(GrCircleEdgeEffect);
75
76 GrEffectRef* GrCircleEdgeEffect::TestCreate(SkMWCRandom* random,
77 GrContext* context,
78 const GrDrawTargetCaps&,
79 GrTexture* textures[]) {
80 return GrCircleEdgeEffect::Create(random->nextBool());
81 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrCircleEdgeEffect.h ('k') | src/gpu/effects/GrEdgeEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698