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

Side by Side Diff: src/effects/gradients/SkRadialGradient.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
« no previous file with comments | « src/effects/gradients/SkLinearGradient.cpp ('k') | src/effects/gradients/SkSweepGradient.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkRadialGradient.h" 8 #include "SkRadialGradient.h"
9 #include "SkNx.h" 9 #include "SkNx.h"
10 10
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 235 }
236 236
237 ///////////////////////////////////////////////////////////////////// 237 /////////////////////////////////////////////////////////////////////
238 238
239 #if SK_SUPPORT_GPU 239 #if SK_SUPPORT_GPU
240 240
241 #include "SkGr.h" 241 #include "SkGr.h"
242 #include "glsl/GrGLSLCaps.h" 242 #include "glsl/GrGLSLCaps.h"
243 #include "glsl/GrGLSLFragmentShaderBuilder.h" 243 #include "glsl/GrGLSLFragmentShaderBuilder.h"
244 244
245 class GrGLRadialGradient : public GrGLGradientEffect {
246 public:
247
248 GrGLRadialGradient(const GrProcessor&) {}
249 virtual ~GrGLRadialGradient() { }
250
251 virtual void emitCode(EmitArgs&) override;
252
253 static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProces sorKeyBuilder* b) {
254 b->add32(GenBaseGradientKey(processor));
255 }
256
257 private:
258
259 typedef GrGLGradientEffect INHERITED;
260
261 };
262
263 /////////////////////////////////////////////////////////////////////
264
265 class GrRadialGradient : public GrGradientEffect { 245 class GrRadialGradient : public GrGradientEffect {
266 public: 246 public:
247 class GLSLRadialProcessor;
248
267 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, 249 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx,
268 const SkRadialGradient& shader, 250 const SkRadialGradient& shader,
269 const SkMatrix& matrix, 251 const SkMatrix& matrix,
270 SkShader::TileMode tm) { 252 SkShader::TileMode tm) {
271 return sk_sp<GrFragmentProcessor>(new GrRadialGradient(ctx, shader, matr ix, tm)); 253 return sk_sp<GrFragmentProcessor>(new GrRadialGradient(ctx, shader, matr ix, tm));
272 } 254 }
273 255
274 virtual ~GrRadialGradient() { } 256 virtual ~GrRadialGradient() { }
275 257
276 const char* name() const override { return "Radial Gradient"; } 258 const char* name() const override { return "Radial Gradient"; }
277 259
278 private: 260 private:
279 GrRadialGradient(GrContext* ctx, 261 GrRadialGradient(GrContext* ctx,
280 const SkRadialGradient& shader, 262 const SkRadialGradient& shader,
281 const SkMatrix& matrix, 263 const SkMatrix& matrix,
282 SkShader::TileMode tm) 264 SkShader::TileMode tm)
283 : INHERITED(ctx, shader, matrix, tm) { 265 : INHERITED(ctx, shader, matrix, tm) {
284 this->initClassID<GrRadialGradient>(); 266 this->initClassID<GrRadialGradient>();
285 } 267 }
286 268
287 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { 269 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
288 return new GrGLRadialGradient(*this);
289 }
290 270
291 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps, 271 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps,
292 GrProcessorKeyBuilder* b) const override { 272 GrProcessorKeyBuilder* b) const override;
293 GrGLRadialGradient::GenKey(*this, caps, b);
294 }
295 273
296 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 274 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
297 275
298 typedef GrGradientEffect INHERITED; 276 typedef GrGradientEffect INHERITED;
299 }; 277 };
300 278
301 ///////////////////////////////////////////////////////////////////// 279 /////////////////////////////////////////////////////////////////////
302 280
281 class GrRadialGradient::GLSLRadialProcessor : public GrGradientEffect::GLSLProce ssor {
282 public:
283 GLSLRadialProcessor(const GrProcessor&) {}
284 virtual ~GLSLRadialProcessor() { }
285
286 virtual void emitCode(EmitArgs&) override;
287
288 static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProces sorKeyBuilder* b) {
289 b->add32(GenBaseGradientKey(processor));
290 }
291
292 private:
293 typedef GrGradientEffect::GLSLProcessor INHERITED;
294
295 };
296
297 /////////////////////////////////////////////////////////////////////
298
299 GrGLSLFragmentProcessor* GrRadialGradient::onCreateGLSLInstance() const {
300 return new GrRadialGradient::GLSLRadialProcessor(*this);
301 }
302
303 void GrRadialGradient::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
304 GrProcessorKeyBuilder* b) const {
305 GrRadialGradient::GLSLRadialProcessor::GenKey(*this, caps, b);
306 }
307
308 /////////////////////////////////////////////////////////////////////
309
303 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRadialGradient); 310 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRadialGradient);
304 311
305 sk_sp<GrFragmentProcessor> GrRadialGradient::TestCreate(GrProcessorTestData* d) { 312 sk_sp<GrFragmentProcessor> GrRadialGradient::TestCreate(GrProcessorTestData* d) {
306 SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; 313 SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()};
307 SkScalar radius = d->fRandom->nextUScalar1(); 314 SkScalar radius = d->fRandom->nextUScalar1();
308 315
309 SkColor colors[kMaxRandomGradientColors]; 316 SkColor colors[kMaxRandomGradientColors];
310 SkScalar stopsArray[kMaxRandomGradientColors]; 317 SkScalar stopsArray[kMaxRandomGradientColors];
311 SkScalar* stops = stopsArray; 318 SkScalar* stops = stopsArray;
312 SkShader::TileMode tm; 319 SkShader::TileMode tm;
313 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); 320 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm);
314 auto shader = SkGradientShader::MakeRadial(center, radius, colors, stops, co lorCount, tm); 321 auto shader = SkGradientShader::MakeRadial(center, radius, colors, stops, co lorCount, tm);
315 SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom); 322 SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
316 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPAr gs( 323 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPAr gs(
317 d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, nullptr, 324 d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, nullptr,
318 SkSourceGammaTreatment::kRespect)); 325 SkSourceGammaTreatment::kRespect));
319 GrAlwaysAssert(fp); 326 GrAlwaysAssert(fp);
320 return fp; 327 return fp;
321 } 328 }
322 329
323 ///////////////////////////////////////////////////////////////////// 330 /////////////////////////////////////////////////////////////////////
324 331
325 void GrGLRadialGradient::emitCode(EmitArgs& args) { 332 void GrRadialGradient::GLSLRadialProcessor::emitCode(EmitArgs& args) {
326 const GrRadialGradient& ge = args.fFp.cast<GrRadialGradient>(); 333 const GrRadialGradient& ge = args.fFp.cast<GrRadialGradient>();
327 this->emitUniforms(args.fUniformHandler, ge); 334 this->emitUniforms(args.fUniformHandler, ge);
328 SkString t("length("); 335 SkString t("length(");
329 t.append(args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0)); 336 t.append(args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0));
330 t.append(")"); 337 t.append(")");
331 this->emitColor(args.fFragBuilder, 338 this->emitColor(args.fFragBuilder,
332 args.fUniformHandler, 339 args.fUniformHandler,
333 args.fGLSLCaps, 340 args.fGLSLCaps,
334 ge, t.c_str(), 341 ge, t.c_str(),
335 args.fOutputColor, 342 args.fOutputColor,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 str->appendScalar(fCenter.fY); 378 str->appendScalar(fCenter.fY);
372 str->append(") radius: "); 379 str->append(") radius: ");
373 str->appendScalar(fRadius); 380 str->appendScalar(fRadius);
374 str->append(" "); 381 str->append(" ");
375 382
376 this->INHERITED::toString(str); 383 this->INHERITED::toString(str);
377 384
378 str->append(")"); 385 str->append(")");
379 } 386 }
380 #endif 387 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkLinearGradient.cpp ('k') | src/effects/gradients/SkSweepGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698