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

Side by Side Diff: src/gpu/SkGr.cpp

Issue 318923005: SkShader::asNewEffect Refactoring (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: added macros to check for gpu support Created 6 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/gpu/SkGpuDevice.cpp ('k') | no next file » | 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 2010 Google Inc. 2 * Copyright 2010 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 "SkGr.h" 8 #include "SkGr.h"
9 #include "SkColorFilter.h" 9 #include "SkColorFilter.h"
10 #include "SkConfig8888.h" 10 #include "SkConfig8888.h"
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 return false; 409 return false;
410 } 410 }
411 if (ctOut) { 411 if (ctOut) {
412 *ctOut = ct; 412 *ctOut = ct;
413 } 413 }
414 return true; 414 return true;
415 } 415 }
416 416
417 /////////////////////////////////////////////////////////////////////////////// 417 ///////////////////////////////////////////////////////////////////////////////
418 418
419 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, bool ju stAlpha, 419 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor grColor,
420 bool constantColor, GrPaint* grPaint) { 420 bool constantColor, GrPaint* grPaint) {
421 421
422 grPaint->setDither(skPaint.isDither()); 422 grPaint->setDither(skPaint.isDither());
423 grPaint->setAntiAlias(skPaint.isAntiAlias()); 423 grPaint->setAntiAlias(skPaint.isAntiAlias());
424 424
425 SkXfermode::Coeff sm; 425 SkXfermode::Coeff sm;
426 SkXfermode::Coeff dm; 426 SkXfermode::Coeff dm;
427 427
428 SkXfermode* mode = skPaint.getXfermode(); 428 SkXfermode* mode = skPaint.getXfermode();
429 GrEffectRef* xferEffect = NULL; 429 GrEffectRef* xferEffect = NULL;
430 if (SkXfermode::AsNewEffectOrCoeff(mode, &xferEffect, &sm, &dm)) { 430 if (SkXfermode::AsNewEffectOrCoeff(mode, &xferEffect, &sm, &dm)) {
431 if (NULL != xferEffect) { 431 if (NULL != xferEffect) {
432 grPaint->addColorEffect(xferEffect)->unref(); 432 grPaint->addColorEffect(xferEffect)->unref();
433 sm = SkXfermode::kOne_Coeff; 433 sm = SkXfermode::kOne_Coeff;
434 dm = SkXfermode::kZero_Coeff; 434 dm = SkXfermode::kZero_Coeff;
435 } 435 }
436 } else { 436 } else {
437 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) 437 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");)
438 // Fall back to src-over 438 // Fall back to src-over
439 sm = SkXfermode::kOne_Coeff; 439 sm = SkXfermode::kOne_Coeff;
440 dm = SkXfermode::kISA_Coeff; 440 dm = SkXfermode::kISA_Coeff;
441 } 441 }
442 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); 442 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm));
443 443
444 if (justAlpha) { 444 //set the color of the paint to the one of the parameter
445 uint8_t alpha = skPaint.getAlpha(); 445 grPaint->setColor(grColor);
446 grPaint->setColor(GrColorPackRGBA(alpha, alpha, alpha, alpha));
447 // justAlpha is currently set to true only if there is a texture,
448 // so constantColor should not also be true.
449 SkASSERT(!constantColor);
450 } else {
451 grPaint->setColor(SkColor2GrColor(skPaint.getColor()));
452 }
453 446
454 SkColorFilter* colorFilter = skPaint.getColorFilter(); 447 SkColorFilter* colorFilter = skPaint.getColorFilter();
455 if (NULL != colorFilter) { 448 if (NULL != colorFilter) {
456 // if the source color is a constant then apply the filter here once rat her than per pixel 449 // if the source color is a constant then apply the filter here once rat her than per pixel
457 // in a shader. 450 // in a shader.
458 if (constantColor) { 451 if (constantColor) {
459 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); 452 SkColor filtered = colorFilter->filterColor(skPaint.getColor());
460 grPaint->setColor(SkColor2GrColor(filtered)); 453 grPaint->setColor(SkColor2GrColor(filtered));
461 } else { 454 } else {
462 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context)); 455 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context));
(...skipping 21 matching lines...) Expand all
484 } 477 }
485 private: 478 private:
486 GrContext* fContext; 479 GrContext* fContext;
487 SkMatrix fMatrix; 480 SkMatrix fMatrix;
488 }; 481 };
489 482
490 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, 483 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
491 bool constantColor, GrPaint* grPaint) { 484 bool constantColor, GrPaint* grPaint) {
492 SkShader* shader = skPaint.getShader(); 485 SkShader* shader = skPaint.getShader();
493 if (NULL == shader) { 486 if (NULL == shader) {
494 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPaint) ; 487 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol or()),
488 constantColor, grPaint);
495 return; 489 return;
496 } 490 }
497 491
498 // SkShader::asNewEffect() may do offscreen rendering. Save off the current RT, clip, and 492 // SkShader::asNewEffect() may do offscreen rendering. Save off the current RT, clip, and
499 // matrix. We don't reset the matrix on the context because SkShader::asNewE ffect may use 493 // matrix. We don't reset the matrix on the context because SkShader::asNewE ffect may use
500 // GrContext::getMatrix() to know the transformation from local coords to de vice space. 494 // GrContext::getMatrix() to know the transformation from local coords to de vice space.
501 GrContext::AutoRenderTarget art(context, NULL); 495 GrContext::AutoRenderTarget art(context, NULL);
502 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip); 496 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip);
503 AutoMatrix am(context); 497 AutoMatrix am(context);
504 498
505 // setup the shader as the first color effect on the paint 499 // setup the shader as the first color effect on the paint
506 SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(context, skPaint, NULL) ); 500 // the default grColor is the paint's color
507 if (NULL != effect.get()) { 501 GrColor grColor = SkColor2GrColor(skPaint.getColor());
502 GrEffectRef* grEffect = NULL;
503 if (shader->asNewEffect(context, skPaint, NULL, &grColor, &grEffect) && NULL != grEffect) {
504 SkAutoTUnref<GrEffectRef> effect(grEffect);
508 grPaint->addColorEffect(effect); 505 grPaint->addColorEffect(effect);
509 // Now setup the rest of the paint. 506 constantColor = false;
510 SkPaint2GrPaintNoShader(context, skPaint, true, false, grPaint);
511 } else {
512 // We still don't have SkColorShader::asNewEffect() implemented.
513 SkShader::GradientInfo info;
514 SkColor color;
515
516 info.fColors = &color;
517 info.fColorOffsets = NULL;
518 info.fColorCount = 1;
519 if (SkShader::kColor_GradientType == shader->asAGradient(&info)) {
520 SkPaint copy(skPaint);
521 copy.setShader(NULL);
522 // modulate the paint alpha by the shader's solid color alpha
523 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha());
524 copy.setColor(SkColorSetA(color, newA));
525 SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint );
526 } else {
527 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPa int);
528 }
529 } 507 }
508 // The grcolor is automatically set when calling asneweffect.
509 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint.
510 SkPaint2GrPaintNoShader(context, skPaint, grColor, constantColor, grPaint);
530 } 511 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698