| 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 | 9 |
| 10 #include "GrDrawTargetCaps.h" | 10 #include "GrDrawTargetCaps.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 276 |
| 277 GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL; | 277 GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL; |
| 278 if (renderTarget) { | 278 if (renderTarget) { |
| 279 SkAutoTUnref<GrFragmentProcessor> yuvToRgbProcessor( | 279 SkAutoTUnref<GrFragmentProcessor> yuvToRgbProcessor( |
| 280 GrYUVtoRGBEffect::Create(yuvTextures[0], yuvTextures[1], yuvTextures
[2], colorSpace)); | 280 GrYUVtoRGBEffect::Create(yuvTextures[0], yuvTextures[1], yuvTextures
[2], colorSpace)); |
| 281 GrPaint paint; | 281 GrPaint paint; |
| 282 paint.addColorProcessor(yuvToRgbProcessor); | 282 paint.addColorProcessor(yuvToRgbProcessor); |
| 283 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth), | 283 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth), |
| 284 SkIntToScalar(yuvSizes[0].fHeight)); | 284 SkIntToScalar(yuvSizes[0].fHeight)); |
| 285 GrContext::AutoRenderTarget autoRT(ctx, renderTarget); | 285 GrContext::AutoRenderTarget autoRT(ctx, renderTarget); |
| 286 GrContext::AutoMatrix am; | |
| 287 am.setIdentity(ctx); | |
| 288 GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip); | 286 GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip); |
| 289 ctx->drawRect(paint, r); | 287 ctx->drawRect(paint, SkMatrix::I(), r); |
| 290 } else { | 288 } else { |
| 291 SkSafeSetNull(result); | 289 SkSafeSetNull(result); |
| 292 } | 290 } |
| 293 | 291 |
| 294 return result; | 292 return result; |
| 295 } | 293 } |
| 296 | 294 |
| 297 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, | 295 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, |
| 298 bool cache, | 296 bool cache, |
| 299 const GrTextureParams* params, | 297 const GrTextureParams* params, |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 SkAutoTUnref<GrFragmentProcessor> fp(GrDitherEffect::Create()); | 513 SkAutoTUnref<GrFragmentProcessor> fp(GrDitherEffect::Create()); |
| 516 if (fp.get()) { | 514 if (fp.get()) { |
| 517 grPaint->addColorProcessor(fp); | 515 grPaint->addColorProcessor(fp); |
| 518 grPaint->setDither(false); | 516 grPaint->setDither(false); |
| 519 } | 517 } |
| 520 } | 518 } |
| 521 } | 519 } |
| 522 #endif | 520 #endif |
| 523 } | 521 } |
| 524 | 522 |
| 525 /** | 523 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, const SkM
atrix& viewM, |
| 526 * Unlike GrContext::AutoMatrix, this doesn't require setting a new matrix. GrCo
ntext::AutoMatrix | |
| 527 * likes to set the new matrix in its constructor because it is usually necessar
y to simulataneously | |
| 528 * update a GrPaint. This AutoMatrix is used while initially setting up GrPaint,
however. | |
| 529 */ | |
| 530 class AutoMatrix { | |
| 531 public: | |
| 532 AutoMatrix(GrContext* context) { | |
| 533 fMatrix = context->getMatrix(); | |
| 534 fContext = context; | |
| 535 } | |
| 536 ~AutoMatrix() { | |
| 537 SkASSERT(fContext); | |
| 538 fContext->setMatrix(fMatrix); | |
| 539 } | |
| 540 private: | |
| 541 GrContext* fContext; | |
| 542 SkMatrix fMatrix; | |
| 543 }; | |
| 544 | |
| 545 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, | |
| 546 bool constantColor, GrPaint* grPaint) { | 524 bool constantColor, GrPaint* grPaint) { |
| 547 SkShader* shader = skPaint.getShader(); | 525 SkShader* shader = skPaint.getShader(); |
| 548 if (NULL == shader) { | 526 if (NULL == shader) { |
| 549 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol
or()), | 527 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol
or()), |
| 550 constantColor, grPaint); | 528 constantColor, grPaint); |
| 551 return; | 529 return; |
| 552 } | 530 } |
| 553 | 531 |
| 554 GrColor paintColor = SkColor2GrColor(skPaint.getColor()); | 532 GrColor paintColor = SkColor2GrColor(skPaint.getColor()); |
| 555 | 533 |
| 556 // Start a new block here in order to preserve our context state after calli
ng | 534 // Start a new block here in order to preserve our context state after calli
ng |
| 557 // asFragmentProcessor(). Since these calls get passed back to the client, w
e don't really | 535 // asFragmentProcessor(). Since these calls get passed back to the client, w
e don't really |
| 558 // want them messing around with the context. | 536 // want them messing around with the context. |
| 559 { | 537 { |
| 560 // SkShader::asFragmentProcessor() may do offscreen rendering. Save off
the current RT, | 538 // SkShader::asFragmentProcessor() may do offscreen rendering. Save off
the current RT, |
| 561 // clip, and matrix. We don't reset the matrix on the context because | 539 // and clip |
| 562 // SkShader::asFragmentProcessor may use GrContext::getMatrix() to know
the transformation | |
| 563 // from local coords to device space. | |
| 564 GrContext::AutoRenderTarget art(context, NULL); | 540 GrContext::AutoRenderTarget art(context, NULL); |
| 565 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialCl
ip); | 541 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialCl
ip); |
| 566 AutoMatrix am(context); | |
| 567 | 542 |
| 568 // Allow the shader to modify paintColor and also create an effect to be
installed as | 543 // Allow the shader to modify paintColor and also create an effect to be
installed as |
| 569 // the first color effect on the GrPaint. | 544 // the first color effect on the GrPaint. |
| 570 GrFragmentProcessor* fp = NULL; | 545 GrFragmentProcessor* fp = NULL; |
| 571 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { | 546 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol
or, &fp) && fp) { |
| 572 grPaint->addColorProcessor(fp)->unref(); | 547 grPaint->addColorProcessor(fp)->unref(); |
| 573 constantColor = false; | 548 constantColor = false; |
| 574 } | 549 } |
| 575 } | 550 } |
| 576 | 551 |
| 577 // The grcolor is automatically set when calling asFragmentProcessor. | 552 // The grcolor is automatically set when calling asFragmentProcessor. |
| 578 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 553 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
| 579 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 554 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
| 580 } | 555 } |
| OLD | NEW |