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

Side by Side Diff: src/effects/gradients/SkSweepGradient.cpp

Issue 2221133002: Refactor various gradient effect classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Brian's suggestions Created 4 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkSweepGradient.h" 8 #include "SkSweepGradient.h"
9 9
10 static SkMatrix translate(SkScalar dx, SkScalar dy) { 10 static SkMatrix translate(SkScalar dx, SkScalar dy) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 ///////////////////////////////////////////////////////////////////// 119 /////////////////////////////////////////////////////////////////////
120 120
121 #if SK_SUPPORT_GPU 121 #if SK_SUPPORT_GPU
122 122
123 #include "SkGr.h" 123 #include "SkGr.h"
124 #include "gl/GrGLContext.h" 124 #include "gl/GrGLContext.h"
125 #include "glsl/GrGLSLCaps.h" 125 #include "glsl/GrGLSLCaps.h"
126 #include "glsl/GrGLSLFragmentShaderBuilder.h" 126 #include "glsl/GrGLSLFragmentShaderBuilder.h"
127 127
128 class GrGLSweepGradient : public GrGLGradientEffect {
129 public:
130
131 GrGLSweepGradient(const GrProcessor&) {}
132 virtual ~GrGLSweepGradient() { }
133
134 virtual void emitCode(EmitArgs&) override;
135
136 static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProces sorKeyBuilder* b) {
137 b->add32(GenBaseGradientKey(processor));
138 }
139
140 private:
141
142 typedef GrGLGradientEffect INHERITED;
143
144 };
145
146 /////////////////////////////////////////////////////////////////////
147
148 class GrSweepGradient : public GrGradientEffect { 128 class GrSweepGradient : public GrGradientEffect {
149 public: 129 public:
130 class GLSLSweepProcessor;
131
150 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, const SkSweepGradient & shader, 132 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, const SkSweepGradient & shader,
151 const SkMatrix& m) { 133 const SkMatrix& m) {
152 return sk_sp<GrFragmentProcessor>(new GrSweepGradient(ctx, shader, m)); 134 return sk_sp<GrFragmentProcessor>(new GrSweepGradient(ctx, shader, m));
153 } 135 }
154 virtual ~GrSweepGradient() { } 136 virtual ~GrSweepGradient() { }
155 137
156 const char* name() const override { return "Sweep Gradient"; } 138 const char* name() const override { return "Sweep Gradient"; }
157 139
158 private: 140 private:
159 GrSweepGradient(GrContext* ctx, 141 GrSweepGradient(GrContext* ctx,
160 const SkSweepGradient& shader, 142 const SkSweepGradient& shader,
161 const SkMatrix& matrix) 143 const SkMatrix& matrix)
162 : INHERITED(ctx, shader, matrix, SkShader::kClamp_TileMode) { 144 : INHERITED(ctx, shader, matrix, SkShader::kClamp_TileMode) {
163 this->initClassID<GrSweepGradient>(); 145 this->initClassID<GrSweepGradient>();
164 } 146 }
165 147
166 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { 148 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
167 return new GrGLSweepGradient(*this);
168 }
169 149
170 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps, 150 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps,
171 GrProcessorKeyBuilder* b) const override { 151 GrProcessorKeyBuilder* b) const override;
172 GrGLSweepGradient::GenKey(*this, caps, b);
173 }
174 152
175 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 153 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
176 154
177 typedef GrGradientEffect INHERITED; 155 typedef GrGradientEffect INHERITED;
178 }; 156 };
179 157
180 ///////////////////////////////////////////////////////////////////// 158 /////////////////////////////////////////////////////////////////////
181 159
160 class GrSweepGradient::GLSLSweepProcessor : public GrGradientEffect::GLSLProcess or {
161 public:
162 GLSLSweepProcessor(const GrProcessor&) {}
163 virtual ~GLSLSweepProcessor() { }
164
165 virtual void emitCode(EmitArgs&) override;
166
167 static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProces sorKeyBuilder* b) {
168 b->add32(GenBaseGradientKey(processor));
169 }
170
171 private:
172 typedef GrGradientEffect::GLSLProcessor INHERITED;
173
174 };
175
176 /////////////////////////////////////////////////////////////////////
177
178 GrGLSLFragmentProcessor* GrSweepGradient::onCreateGLSLInstance() const {
179 return new GrSweepGradient::GLSLSweepProcessor(*this);
180 }
181
182 void GrSweepGradient::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
183 GrProcessorKeyBuilder* b) const {
184 GrSweepGradient::GLSLSweepProcessor::GenKey(*this, caps, b);
185 }
186
187
188 /////////////////////////////////////////////////////////////////////
189
182 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSweepGradient); 190 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSweepGradient);
183 191
184 sk_sp<GrFragmentProcessor> GrSweepGradient::TestCreate(GrProcessorTestData* d) { 192 sk_sp<GrFragmentProcessor> GrSweepGradient::TestCreate(GrProcessorTestData* d) {
185 SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; 193 SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()};
186 194
187 SkColor colors[kMaxRandomGradientColors]; 195 SkColor colors[kMaxRandomGradientColors];
188 SkScalar stopsArray[kMaxRandomGradientColors]; 196 SkScalar stopsArray[kMaxRandomGradientColors];
189 SkScalar* stops = stopsArray; 197 SkScalar* stops = stopsArray;
190 SkShader::TileMode tmIgnored; 198 SkShader::TileMode tmIgnored;
191 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tmIgnored ); 199 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tmIgnored );
192 sk_sp<SkShader> shader(SkGradientShader::MakeSweep(center.fX, center.fY, co lors, stops, 200 sk_sp<SkShader> shader(SkGradientShader::MakeSweep(center.fX, center.fY, co lors, stops,
193 colorCount)); 201 colorCount));
194 SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom); 202 SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
195 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPAr gs( 203 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPAr gs(
196 d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, nullptr, 204 d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, nullptr,
197 SkSourceGammaTreatment::kRespect)); 205 SkSourceGammaTreatment::kRespect));
198 GrAlwaysAssert(fp); 206 GrAlwaysAssert(fp);
199 return fp; 207 return fp;
200 } 208 }
201 209
202 ///////////////////////////////////////////////////////////////////// 210 /////////////////////////////////////////////////////////////////////
203 211
204 void GrGLSweepGradient::emitCode(EmitArgs& args) { 212 void GrSweepGradient::GLSLSweepProcessor::emitCode(EmitArgs& args) {
205 const GrSweepGradient& ge = args.fFp.cast<GrSweepGradient>(); 213 const GrSweepGradient& ge = args.fFp.cast<GrSweepGradient>();
206 this->emitUniforms(args.fUniformHandler, ge); 214 this->emitUniforms(args.fUniformHandler, ge);
207 SkString coords2D = args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0); 215 SkString coords2D = args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0);
208 SkString t; 216 SkString t;
209 // 0.1591549430918 is 1/(2*pi), used since atan returns values [-pi, pi] 217 // 0.1591549430918 is 1/(2*pi), used since atan returns values [-pi, pi]
210 // On Intel GPU there is an issue where it reads the second arguement to ata n "- %s.x" as an int 218 // On Intel GPU there is an issue where it reads the second arguement to ata n "- %s.x" as an int
211 // thus must us -1.0 * %s.x to work correctly 219 // thus must us -1.0 * %s.x to work correctly
212 if (args.fGLSLCaps->mustForceNegatedAtanParamToFloat()){ 220 if (args.fGLSLCaps->mustForceNegatedAtanParamToFloat()){
213 t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5", 221 t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5",
214 coords2D.c_str(), coords2D.c_str()); 222 coords2D.c_str(), coords2D.c_str());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 str->appendScalar(fCenter.fX); 264 str->appendScalar(fCenter.fX);
257 str->append(", "); 265 str->append(", ");
258 str->appendScalar(fCenter.fY); 266 str->appendScalar(fCenter.fY);
259 str->append(") "); 267 str->append(") ");
260 268
261 this->INHERITED::toString(str); 269 this->INHERITED::toString(str);
262 270
263 str->append(")"); 271 str->append(")");
264 } 272 }
265 #endif 273 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkRadialGradient.cpp ('k') | src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698