OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrContext.h" | 9 #include "GrContext.h" |
10 | 10 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 return false; | 375 return false; |
376 } | 376 } |
377 | 377 |
378 SkAutoTUnref<const GrFragmentProcessor> fp; | 378 SkAutoTUnref<const GrFragmentProcessor> fp; |
379 SkMatrix textureMatrix; | 379 SkMatrix textureMatrix; |
380 textureMatrix.setIDiv(texture->width(), texture->height()); | 380 textureMatrix.setIDiv(texture->width(), texture->height()); |
381 | 381 |
382 // allocate a tmp buffer and sw convert the pixels to premul | 382 // allocate a tmp buffer and sw convert the pixels to premul |
383 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); | 383 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
384 | 384 |
| 385 GrPaint paint; |
385 if (kUnpremul_PixelOpsFlag & pixelOpsFlags) { | 386 if (kUnpremul_PixelOpsFlag & pixelOpsFlags) { |
386 if (!GrPixelConfigIs8888(srcConfig)) { | 387 if (!GrPixelConfigIs8888(srcConfig)) { |
387 return false; | 388 return false; |
388 } | 389 } |
389 fp.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix)); | 390 fp.reset(this->createUPMToPMEffect(paint.getProcessorDataManager(), text
ure, swapRAndB, |
| 391 textureMatrix)); |
390 // handle the unpremul step on the CPU if we couldn't create an effect t
o do it. | 392 // handle the unpremul step on the CPU if we couldn't create an effect t
o do it. |
391 if (!fp) { | 393 if (!fp) { |
392 size_t tmpRowBytes = 4 * width; | 394 size_t tmpRowBytes = 4 * width; |
393 tmpPixels.reset(width * height); | 395 tmpPixels.reset(width * height); |
394 if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer
, tmpRowBytes, | 396 if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer
, tmpRowBytes, |
395 tmpPixels.get())) { | 397 tmpPixels.get())) { |
396 return false; | 398 return false; |
397 } | 399 } |
398 rowBytes = tmpRowBytes; | 400 rowBytes = tmpRowBytes; |
399 buffer = tmpPixels.get(); | 401 buffer = tmpPixels.get(); |
400 } | 402 } |
401 } | 403 } |
| 404 |
402 if (!fp) { | 405 if (!fp) { |
403 fp.reset(GrConfigConversionEffect::Create(texture, | 406 fp.reset(GrConfigConversionEffect::Create(paint.getProcessorDataManager(
), |
| 407 texture, |
404 swapRAndB, | 408 swapRAndB, |
405 GrConfigConversionEffect::kNon
e_PMConversion, | 409 GrConfigConversionEffect::kNon
e_PMConversion, |
406 textureMatrix)); | 410 textureMatrix)); |
407 } | 411 } |
408 | 412 |
409 // Even if the client told us not to flush, we still flush here. The client
may have known that | 413 // Even if the client told us not to flush, we still flush here. The client
may have known that |
410 // writes to the original surface caused no data hazards, but they can't kno
w that the scratch | 414 // writes to the original surface caused no data hazards, but they can't kno
w that the scratch |
411 // we just got is safe. | 415 // we just got is safe. |
412 if (texture->surfacePriv().hasPendingIO()) { | 416 if (texture->surfacePriv().hasPendingIO()) { |
413 this->flush(); | 417 this->flush(); |
414 } | 418 } |
415 if (!fGpu->writeTexturePixels(texture, 0, 0, width, height, | 419 if (!fGpu->writeTexturePixels(texture, 0, 0, width, height, |
416 writeConfig, buffer, rowBytes)) { | 420 writeConfig, buffer, rowBytes)) { |
417 return false; | 421 return false; |
418 } | 422 } |
419 | 423 |
420 SkMatrix matrix; | 424 SkMatrix matrix; |
421 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 425 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
422 | 426 |
423 GrDrawContext* drawContext = this->drawContext(); | 427 GrDrawContext* drawContext = this->drawContext(); |
424 if (!drawContext) { | 428 if (!drawContext) { |
425 return false; | 429 return false; |
426 } | 430 } |
427 | 431 |
428 GrPaint paint; | |
429 paint.addColorProcessor(fp); | 432 paint.addColorProcessor(fp); |
430 | 433 |
431 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); | 434 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
432 | 435 |
433 drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, matrix, rect,
NULL); | 436 drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, matrix, rect,
NULL); |
434 | 437 |
435 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 438 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
436 this->flushSurfaceWrites(surface); | 439 this->flushSurfaceWrites(surface); |
437 } | 440 } |
438 | 441 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 fGpu->fullReadPixelsIsFasterThanPartial()) { | 519 fGpu->fullReadPixelsIsFasterThanPartial()) { |
517 match = GrTextureProvider::kExact_ScratchTexMatch; | 520 match = GrTextureProvider::kExact_ScratchTexMatch; |
518 } | 521 } |
519 tempTexture.reset(this->textureProvider()->refScratchTexture(desc, match
)); | 522 tempTexture.reset(this->textureProvider()->refScratchTexture(desc, match
)); |
520 if (tempTexture) { | 523 if (tempTexture) { |
521 // compute a matrix to perform the draw | 524 // compute a matrix to perform the draw |
522 SkMatrix textureMatrix; | 525 SkMatrix textureMatrix; |
523 textureMatrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top); | 526 textureMatrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top); |
524 textureMatrix.postIDiv(src->width(), src->height()); | 527 textureMatrix.postIDiv(src->width(), src->height()); |
525 | 528 |
| 529 GrPaint paint; |
526 SkAutoTUnref<const GrFragmentProcessor> fp; | 530 SkAutoTUnref<const GrFragmentProcessor> fp; |
527 if (unpremul) { | 531 if (unpremul) { |
528 fp.reset(this->createPMToUPMEffect(src, swapRAndB, textureMatrix
)); | 532 fp.reset(this->createPMToUPMEffect(paint.getProcessorDataManager
(), src, swapRAndB, |
| 533 textureMatrix)); |
529 if (fp) { | 534 if (fp) { |
530 unpremul = false; // we no longer need to do this on CPU aft
er the read back. | 535 unpremul = false; // we no longer need to do this on CPU aft
er the read back. |
531 } | 536 } |
532 } | 537 } |
533 // If we failed to create a PM->UPM effect and have no other convers
ions to perform then | 538 // If we failed to create a PM->UPM effect and have no other convers
ions to perform then |
534 // there is no longer any point to using the scratch. | 539 // there is no longer any point to using the scratch. |
535 if (fp || flipY || swapRAndB) { | 540 if (fp || flipY || swapRAndB) { |
536 if (!fp) { | 541 if (!fp) { |
537 fp.reset(GrConfigConversionEffect::Create( | 542 fp.reset(GrConfigConversionEffect::Create(paint.getProcessor
DataManager(), |
538 src, swapRAndB, GrConfigConversionEffect::kNone_PMCo
nversion, | 543 src, swapRAndB, GrConfigConversionEffect::kNone_PMCo
nversion, |
539 textureMatrix)); | 544 textureMatrix)); |
540 } | 545 } |
541 swapRAndB = false; // we will handle the swap in the draw. | 546 swapRAndB = false; // we will handle the swap in the draw. |
542 | 547 |
543 // We protect the existing geometry here since it may not be | 548 // We protect the existing geometry here since it may not be |
544 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) | 549 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) |
545 // can be invoked in this method | 550 // can be invoked in this method |
546 { | 551 { |
547 GrDrawContext* drawContext = this->drawContext(); | 552 GrDrawContext* drawContext = this->drawContext(); |
548 if (!drawContext) { | 553 if (!drawContext) { |
549 return false; | 554 return false; |
550 } | 555 } |
551 | 556 |
552 GrPaint paint; | |
553 paint.addColorProcessor(fp); | 557 paint.addColorProcessor(fp); |
554 | 558 |
555 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToSc
alar(height)); | 559 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToSc
alar(height)); |
556 | 560 |
557 drawContext->drawRect(tempTexture->asRenderTarget(), GrClip:
:WideOpen(), paint, | 561 drawContext->drawRect(tempTexture->asRenderTarget(), GrClip:
:WideOpen(), paint, |
558 SkMatrix::I(), rect, NULL);
| 562 SkMatrix::I(), rect, NULL);
|
559 | 563 |
560 // we want to read back from the scratch's origin | 564 // we want to read back from the scratch's origin |
561 left = 0; | 565 left = 0; |
562 top = 0; | 566 top = 0; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 namespace { | 702 namespace { |
699 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { | 703 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
700 GrConfigConversionEffect::PMConversion pmToUPM; | 704 GrConfigConversionEffect::PMConversion pmToUPM; |
701 GrConfigConversionEffect::PMConversion upmToPM; | 705 GrConfigConversionEffect::PMConversion upmToPM; |
702 GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upm
ToPM); | 706 GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upm
ToPM); |
703 *pmToUPMValue = pmToUPM; | 707 *pmToUPMValue = pmToUPM; |
704 *upmToPMValue = upmToPM; | 708 *upmToPMValue = upmToPM; |
705 } | 709 } |
706 } | 710 } |
707 | 711 |
708 const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture, | 712 const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrProcessorDataManager
* procDataManager, |
| 713 GrTexture* texture, |
709 bool swapRAndB, | 714 bool swapRAndB, |
710 const SkMatrix& matrix
) { | 715 const SkMatrix& matrix
) { |
711 if (!fDidTestPMConversions) { | 716 if (!fDidTestPMConversions) { |
712 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); | 717 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
713 fDidTestPMConversions = true; | 718 fDidTestPMConversions = true; |
714 } | 719 } |
715 GrConfigConversionEffect::PMConversion pmToUPM = | 720 GrConfigConversionEffect::PMConversion pmToUPM = |
716 static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); | 721 static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); |
717 if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { | 722 if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { |
718 return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM, mat
rix); | 723 return GrConfigConversionEffect::Create(procDataManager, texture, swapRA
ndB, pmToUPM, |
| 724 matrix); |
719 } else { | 725 } else { |
720 return NULL; | 726 return NULL; |
721 } | 727 } |
722 } | 728 } |
723 | 729 |
724 const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture, | 730 const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrProcessorDataManager
* procDataManager, |
| 731 GrTexture* texture, |
725 bool swapRAndB, | 732 bool swapRAndB, |
726 const SkMatrix& matrix
) { | 733 const SkMatrix& matrix
) { |
727 if (!fDidTestPMConversions) { | 734 if (!fDidTestPMConversions) { |
728 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); | 735 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
729 fDidTestPMConversions = true; | 736 fDidTestPMConversions = true; |
730 } | 737 } |
731 GrConfigConversionEffect::PMConversion upmToPM = | 738 GrConfigConversionEffect::PMConversion upmToPM = |
732 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); | 739 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); |
733 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { | 740 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { |
734 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat
rix); | 741 return GrConfigConversionEffect::Create(procDataManager, texture, swapRA
ndB, upmToPM, |
| 742 matrix); |
735 } else { | 743 } else { |
736 return NULL; | 744 return NULL; |
737 } | 745 } |
738 } | 746 } |
739 | 747 |
740 ////////////////////////////////////////////////////////////////////////////// | 748 ////////////////////////////////////////////////////////////////////////////// |
741 | 749 |
742 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes
) const { | 750 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes
) const { |
743 if (maxTextures) { | 751 if (maxTextures) { |
744 *maxTextures = fResourceCache->getMaxResourceCount(); | 752 *maxTextures = fResourceCache->getMaxResourceCount(); |
(...skipping 10 matching lines...) Expand all Loading... |
755 ////////////////////////////////////////////////////////////////////////////// | 763 ////////////////////////////////////////////////////////////////////////////// |
756 | 764 |
757 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { | 765 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
758 fGpu->addGpuTraceMarker(marker); | 766 fGpu->addGpuTraceMarker(marker); |
759 } | 767 } |
760 | 768 |
761 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 769 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
762 fGpu->removeGpuTraceMarker(marker); | 770 fGpu->removeGpuTraceMarker(marker); |
763 } | 771 } |
764 | 772 |
OLD | NEW |