| OLD | NEW |
| 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 GrTextureDesc rtDesc = desc; | 264 GrTextureDesc rtDesc = desc; |
| 265 rtDesc.fFlags = rtDesc.fFlags | | 265 rtDesc.fFlags = rtDesc.fFlags | |
| 266 kRenderTarget_GrTextureFlagBit | | 266 kRenderTarget_GrTextureFlagBit | |
| 267 kNoStencil_GrTextureFlagBit; | 267 kNoStencil_GrTextureFlagBit; |
| 268 | 268 |
| 269 GrTexture* result = sk_gr_allocate_texture(ctx, cache, params, bm, rtDesc, N
ULL, 0); | 269 GrTexture* result = sk_gr_allocate_texture(ctx, cache, params, bm, rtDesc, N
ULL, 0); |
| 270 | 270 |
| 271 GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL; | 271 GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL; |
| 272 if (renderTarget) { | 272 if (renderTarget) { |
| 273 SkAutoTUnref<GrEffect> yuvToRgbEffect(GrYUVtoRGBEffect::Create( | 273 SkAutoTUnref<GrFragmentProcessor> yuvToRgbProcessor(GrYUVtoRGBEffect::Cr
eate( |
| 274 yuvTextures[0].texture(), yuvTextures[1].texture(), yuvTextures[2].t
exture(), | 274 yuvTextures[0].texture(), yuvTextures[1].texture(), yuvTextures[2].t
exture(), |
| 275 colorSpace)); | 275 colorSpace)); |
| 276 GrPaint paint; | 276 GrPaint paint; |
| 277 paint.addColorEffect(yuvToRgbEffect); | 277 paint.addColorProcessor(yuvToRgbProcessor); |
| 278 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth), | 278 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth), |
| 279 SkIntToScalar(yuvSizes[0].fHeight)); | 279 SkIntToScalar(yuvSizes[0].fHeight)); |
| 280 GrContext::AutoRenderTarget autoRT(ctx, renderTarget); | 280 GrContext::AutoRenderTarget autoRT(ctx, renderTarget); |
| 281 GrContext::AutoMatrix am; | 281 GrContext::AutoMatrix am; |
| 282 am.setIdentity(ctx); | 282 am.setIdentity(ctx); |
| 283 GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip); | 283 GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip); |
| 284 ctx->drawRect(paint, r); | 284 ctx->drawRect(paint, r); |
| 285 } else { | 285 } else { |
| 286 SkSafeSetNull(result); | 286 SkSafeSetNull(result); |
| 287 } | 287 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
paintColor, | 464 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
paintColor, |
| 465 bool constantColor, GrPaint* grPaint) { | 465 bool constantColor, GrPaint* grPaint) { |
| 466 | 466 |
| 467 grPaint->setDither(skPaint.isDither()); | 467 grPaint->setDither(skPaint.isDither()); |
| 468 grPaint->setAntiAlias(skPaint.isAntiAlias()); | 468 grPaint->setAntiAlias(skPaint.isAntiAlias()); |
| 469 | 469 |
| 470 SkXfermode::Coeff sm; | 470 SkXfermode::Coeff sm; |
| 471 SkXfermode::Coeff dm; | 471 SkXfermode::Coeff dm; |
| 472 | 472 |
| 473 SkXfermode* mode = skPaint.getXfermode(); | 473 SkXfermode* mode = skPaint.getXfermode(); |
| 474 GrEffect* xferEffect = NULL; | 474 GrFragmentProcessor* xferProcessor = NULL; |
| 475 if (SkXfermode::AsNewEffectOrCoeff(mode, &xferEffect, &sm, &dm)) { | 475 if (SkXfermode::asFragmentProcessorOrCoeff(mode, &xferProcessor, &sm, &dm))
{ |
| 476 if (xferEffect) { | 476 if (xferProcessor) { |
| 477 grPaint->addColorEffect(xferEffect)->unref(); | 477 grPaint->addColorProcessor(xferProcessor)->unref(); |
| 478 sm = SkXfermode::kOne_Coeff; | 478 sm = SkXfermode::kOne_Coeff; |
| 479 dm = SkXfermode::kZero_Coeff; | 479 dm = SkXfermode::kZero_Coeff; |
| 480 } | 480 } |
| 481 } else { | 481 } else { |
| 482 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) | 482 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) |
| 483 // Fall back to src-over | 483 // Fall back to src-over |
| 484 sm = SkXfermode::kOne_Coeff; | 484 sm = SkXfermode::kOne_Coeff; |
| 485 dm = SkXfermode::kISA_Coeff; | 485 dm = SkXfermode::kISA_Coeff; |
| 486 } | 486 } |
| 487 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); | 487 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); |
| 488 | 488 |
| 489 //set the color of the paint to the one of the parameter | 489 //set the color of the paint to the one of the parameter |
| 490 grPaint->setColor(paintColor); | 490 grPaint->setColor(paintColor); |
| 491 | 491 |
| 492 SkColorFilter* colorFilter = skPaint.getColorFilter(); | 492 SkColorFilter* colorFilter = skPaint.getColorFilter(); |
| 493 if (colorFilter) { | 493 if (colorFilter) { |
| 494 // if the source color is a constant then apply the filter here once rat
her than per pixel | 494 // if the source color is a constant then apply the filter here once rat
her than per pixel |
| 495 // in a shader. | 495 // in a shader. |
| 496 if (constantColor) { | 496 if (constantColor) { |
| 497 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); | 497 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); |
| 498 grPaint->setColor(SkColor2GrColor(filtered)); | 498 grPaint->setColor(SkColor2GrColor(filtered)); |
| 499 } else { | 499 } else { |
| 500 SkAutoTUnref<GrEffect> effect(colorFilter->asNewEffect(context)); | 500 SkAutoTUnref<GrFragmentProcessor> fp(colorFilter->asFragmentProcesso
r(context)); |
| 501 if (effect.get()) { | 501 if (fp.get()) { |
| 502 grPaint->addColorEffect(effect); | 502 grPaint->addColorProcessor(fp); |
| 503 } | 503 } |
| 504 } | 504 } |
| 505 } | 505 } |
| 506 | 506 |
| 507 #ifndef SK_IGNORE_GPU_DITHER | 507 #ifndef SK_IGNORE_GPU_DITHER |
| 508 // If the dither flag is set, then we need to see if the underlying context | 508 // If the dither flag is set, then we need to see if the underlying context |
| 509 // supports it. If not, then install a dither effect. | 509 // supports it. If not, then install a dither effect. |
| 510 if (skPaint.isDither() && grPaint->numColorStages() > 0) { | 510 if (skPaint.isDither() && grPaint->numColorStages() > 0) { |
| 511 // What are we rendering into? | 511 // What are we rendering into? |
| 512 const GrRenderTarget *target = context->getRenderTarget(); | 512 const GrRenderTarget *target = context->getRenderTarget(); |
| 513 SkASSERT(target); | 513 SkASSERT(target); |
| 514 | 514 |
| 515 // Suspect the dithering flag has no effect on these configs, otherwise | 515 // Suspect the dithering flag has no effect on these configs, otherwise |
| 516 // fall back on setting the appropriate state. | 516 // fall back on setting the appropriate state. |
| 517 if (target->config() == kRGBA_8888_GrPixelConfig || | 517 if (target->config() == kRGBA_8888_GrPixelConfig || |
| 518 target->config() == kBGRA_8888_GrPixelConfig) { | 518 target->config() == kBGRA_8888_GrPixelConfig) { |
| 519 // The dither flag is set and the target is likely | 519 // The dither flag is set and the target is likely |
| 520 // not going to be dithered by the GPU. | 520 // not going to be dithered by the GPU. |
| 521 SkAutoTUnref<GrEffect> effect(GrDitherEffect::Create()); | 521 SkAutoTUnref<GrFragmentProcessor> fp(GrDitherEffect::Create()); |
| 522 if (effect.get()) { | 522 if (fp.get()) { |
| 523 grPaint->addColorEffect(effect); | 523 grPaint->addColorProcessor(fp); |
| 524 grPaint->setDither(false); | 524 grPaint->setDither(false); |
| 525 } | 525 } |
| 526 } | 526 } |
| 527 } | 527 } |
| 528 #endif | 528 #endif |
| 529 } | 529 } |
| 530 | 530 |
| 531 /** | 531 /** |
| 532 * Unlike GrContext::AutoMatrix, this doesn't require setting a new matrix. GrCo
ntext::AutoMatrix | 532 * Unlike GrContext::AutoMatrix, this doesn't require setting a new matrix. GrCo
ntext::AutoMatrix |
| 533 * likes to set the new matrix in its constructor because it is usually necessar
y to simulataneously | 533 * likes to set the new matrix in its constructor because it is usually necessar
y to simulataneously |
| (...skipping 19 matching lines...) Expand all Loading... |
| 553 SkShader* shader = skPaint.getShader(); | 553 SkShader* shader = skPaint.getShader(); |
| 554 if (NULL == shader) { | 554 if (NULL == shader) { |
| 555 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol
or()), | 555 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol
or()), |
| 556 constantColor, grPaint); | 556 constantColor, grPaint); |
| 557 return; | 557 return; |
| 558 } | 558 } |
| 559 | 559 |
| 560 GrColor paintColor = SkColor2GrColor(skPaint.getColor()); | 560 GrColor paintColor = SkColor2GrColor(skPaint.getColor()); |
| 561 | 561 |
| 562 // Start a new block here in order to preserve our context state after calli
ng | 562 // Start a new block here in order to preserve our context state after calli
ng |
| 563 // asNewEffect(). Since these calls get passed back to the client, we don't
really | 563 // asFragmentProcessor(). Since these calls get passed back to the client, w
e don't really |
| 564 // want them messing around with the context. | 564 // want them messing around with the context. |
| 565 { | 565 { |
| 566 // SkShader::asNewEffect() may do offscreen rendering. Save off the curr
ent RT, clip, and | 566 // SkShader::asFragmentProcessor() may do offscreen rendering. Save off
the current RT, |
| 567 // matrix. We don't reset the matrix on the context because SkShader::as
NewEffect may use | 567 // clip, and matrix. We don't reset the matrix on the context because |
| 568 // GrContext::getMatrix() to know the transformation from local coords t
o device space. | 568 // SkShader::asFragmentProcessor may use GrContext::getMatrix() to know
the transformation |
| 569 // from local coords to device space. |
| 569 GrContext::AutoRenderTarget art(context, NULL); | 570 GrContext::AutoRenderTarget art(context, NULL); |
| 570 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialCl
ip); | 571 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialCl
ip); |
| 571 AutoMatrix am(context); | 572 AutoMatrix am(context); |
| 572 | 573 |
| 573 // Allow the shader to modify paintColor and also create an effect to be
installed as | 574 // Allow the shader to modify paintColor and also create an effect to be
installed as |
| 574 // the first color effect on the GrPaint. | 575 // the first color effect on the GrPaint. |
| 575 GrEffect* effect = NULL; | 576 GrFragmentProcessor* fp = NULL; |
| 576 if (shader->asNewEffect(context, skPaint, NULL, &paintColor, &effect) &&
effect) { | 577 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { |
| 577 grPaint->addColorEffect(effect)->unref(); | 578 grPaint->addColorProcessor(fp)->unref(); |
| 578 constantColor = false; | 579 constantColor = false; |
| 579 } | 580 } |
| 580 } | 581 } |
| 581 | 582 |
| 582 // The grcolor is automatically set when calling asneweffect. | 583 // The grcolor is automatically set when calling asFragmentProcessor. |
| 583 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 584 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
| 584 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 585 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
| 585 } | 586 } |
| OLD | NEW |