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

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

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. Created 4 years, 6 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/SkRadialGradient.h ('k') | src/effects/gradients/SkSweepGradient.h » ('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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 private: 257 private:
258 258
259 typedef GrGLGradientEffect INHERITED; 259 typedef GrGLGradientEffect INHERITED;
260 260
261 }; 261 };
262 262
263 ///////////////////////////////////////////////////////////////////// 263 /////////////////////////////////////////////////////////////////////
264 264
265 class GrRadialGradient : public GrGradientEffect { 265 class GrRadialGradient : public GrGradientEffect {
266 public: 266 public:
267 static GrFragmentProcessor* Create(GrContext* ctx, 267 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx,
268 const SkRadialGradient& shader, 268 const SkRadialGradient& shader,
269 const SkMatrix& matrix, 269 const SkMatrix& matrix,
270 SkShader::TileMode tm) { 270 SkShader::TileMode tm) {
271 return new GrRadialGradient(ctx, shader, matrix, tm); 271 return sk_sp<GrFragmentProcessor>(new GrRadialGradient(ctx, shader, matr ix, tm));
272 } 272 }
273 273
274 virtual ~GrRadialGradient() { } 274 virtual ~GrRadialGradient() { }
275 275
276 const char* name() const override { return "Radial Gradient"; } 276 const char* name() const override { return "Radial Gradient"; }
277 277
278 private: 278 private:
279 GrRadialGradient(GrContext* ctx, 279 GrRadialGradient(GrContext* ctx,
280 const SkRadialGradient& shader, 280 const SkRadialGradient& shader,
281 const SkMatrix& matrix, 281 const SkMatrix& matrix,
(...skipping 13 matching lines...) Expand all
295 295
296 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 296 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
297 297
298 typedef GrGradientEffect INHERITED; 298 typedef GrGradientEffect INHERITED;
299 }; 299 };
300 300
301 ///////////////////////////////////////////////////////////////////// 301 /////////////////////////////////////////////////////////////////////
302 302
303 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRadialGradient); 303 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRadialGradient);
304 304
305 const GrFragmentProcessor* GrRadialGradient::TestCreate(GrProcessorTestData* d) { 305 sk_sp<GrFragmentProcessor> GrRadialGradient::TestCreate(GrProcessorTestData* d) {
306 SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; 306 SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()};
307 SkScalar radius = d->fRandom->nextUScalar1(); 307 SkScalar radius = d->fRandom->nextUScalar1();
308 308
309 SkColor colors[kMaxRandomGradientColors]; 309 SkColor colors[kMaxRandomGradientColors];
310 SkScalar stopsArray[kMaxRandomGradientColors]; 310 SkScalar stopsArray[kMaxRandomGradientColors];
311 SkScalar* stops = stopsArray; 311 SkScalar* stops = stopsArray;
312 SkShader::TileMode tm; 312 SkShader::TileMode tm;
313 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); 313 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm);
314 auto shader = SkGradientShader::MakeRadial(center, radius, colors, stops, co lorCount, tm); 314 auto shader = SkGradientShader::MakeRadial(center, radius, colors, stops, co lorCount, tm);
315 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, 315 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(d->fContext,
316 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, 316 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality,
317 SkSourceGammaTreatment::kRespect); 317 SkSourceGammaTreatment::kRespect);
318 GrAlwaysAssert(fp); 318 GrAlwaysAssert(fp);
319 return fp; 319 return fp;
320 } 320 }
321 321
322 ///////////////////////////////////////////////////////////////////// 322 /////////////////////////////////////////////////////////////////////
323 323
324 void GrGLRadialGradient::emitCode(EmitArgs& args) { 324 void GrGLRadialGradient::emitCode(EmitArgs& args) {
325 const GrRadialGradient& ge = args.fFp.cast<GrRadialGradient>(); 325 const GrRadialGradient& ge = args.fFp.cast<GrRadialGradient>();
326 this->emitUniforms(args.fUniformHandler, ge); 326 this->emitUniforms(args.fUniformHandler, ge);
327 SkString t("length("); 327 SkString t("length(");
328 t.append(args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0)); 328 t.append(args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0));
329 t.append(")"); 329 t.append(")");
330 this->emitColor(args.fFragBuilder, 330 this->emitColor(args.fFragBuilder,
331 args.fUniformHandler, 331 args.fUniformHandler,
332 args.fGLSLCaps, 332 args.fGLSLCaps,
333 ge, t.c_str(), 333 ge, t.c_str(),
334 args.fOutputColor, 334 args.fOutputColor,
335 args.fInputColor, 335 args.fInputColor,
336 args.fTexSamplers); 336 args.fTexSamplers);
337 } 337 }
338 338
339 ///////////////////////////////////////////////////////////////////// 339 /////////////////////////////////////////////////////////////////////
340 340
341 const GrFragmentProcessor* SkRadialGradient::asFragmentProcessor( 341 sk_sp<GrFragmentProcessor> SkRadialGradient::asFragmentProcessor(
342 GrContext* context, 342 GrContext* context,
343 const SkMatrix& viewM, 343 const SkMatrix& viewM,
344 const SkMatrix* localMatrix, 344 const SkMatrix* localMatrix,
345 SkFilterQuality, 345 SkFilterQuality,
346 SkSourceGammaTreatment) const { 346 SkSourceGammaTreatment) const {
347 SkASSERT(context); 347 SkASSERT(context);
348 348
349 SkMatrix matrix; 349 SkMatrix matrix;
350 if (!this->getLocalMatrix().invert(&matrix)) { 350 if (!this->getLocalMatrix().invert(&matrix)) {
351 return nullptr; 351 return nullptr;
352 } 352 }
353 if (localMatrix) { 353 if (localMatrix) {
354 SkMatrix inv; 354 SkMatrix inv;
355 if (!localMatrix->invert(&inv)) { 355 if (!localMatrix->invert(&inv)) {
356 return nullptr; 356 return nullptr;
357 } 357 }
358 matrix.postConcat(inv); 358 matrix.postConcat(inv);
359 } 359 }
360 matrix.postConcat(fPtsToUnit); 360 matrix.postConcat(fPtsToUnit);
361 SkAutoTUnref<const GrFragmentProcessor> inner( 361 sk_sp<GrFragmentProcessor> inner(GrRadialGradient::Make(context, *this, matr ix, fTileMode));
362 GrRadialGradient::Create(context, *this, matrix, fTileMode)); 362 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
363 return GrFragmentProcessor::MulOutputByInputAlpha(inner);
364 } 363 }
365 364
366 #endif 365 #endif
367 366
368 #ifndef SK_IGNORE_TO_STRING 367 #ifndef SK_IGNORE_TO_STRING
369 void SkRadialGradient::toString(SkString* str) const { 368 void SkRadialGradient::toString(SkString* str) const {
370 str->append("SkRadialGradient: ("); 369 str->append("SkRadialGradient: (");
371 370
372 str->append("center: ("); 371 str->append("center: (");
373 str->appendScalar(fCenter.fX); 372 str->appendScalar(fCenter.fX);
374 str->append(", "); 373 str->append(", ");
375 str->appendScalar(fCenter.fY); 374 str->appendScalar(fCenter.fY);
376 str->append(") radius: "); 375 str->append(") radius: ");
377 str->appendScalar(fRadius); 376 str->appendScalar(fRadius);
378 str->append(" "); 377 str->append(" ");
379 378
380 this->INHERITED::toString(str); 379 this->INHERITED::toString(str);
381 380
382 str->append(")"); 381 str->append(")");
383 } 382 }
384 #endif 383 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkRadialGradient.h ('k') | src/effects/gradients/SkSweepGradient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698