| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrContext.h" | 8 #include "GrContext.h" |
| 9 #include "GrContextOptions.h" | 9 #include "GrContextOptions.h" |
| 10 #include "GrDrawingManager.h" | 10 #include "GrDrawingManager.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 tempTexture.reset( | 310 tempTexture.reset( |
| 311 this->textureProvider()->createApproxTexture(tempDrawInfo.fTempSurfa
ceDesc)); | 311 this->textureProvider()->createApproxTexture(tempDrawInfo.fTempSurfa
ceDesc)); |
| 312 if (!tempTexture && GrGpu::kRequireDraw_DrawPreference == drawPreference
) { | 312 if (!tempTexture && GrGpu::kRequireDraw_DrawPreference == drawPreference
) { |
| 313 return false; | 313 return false; |
| 314 } | 314 } |
| 315 } | 315 } |
| 316 | 316 |
| 317 // temp buffer for doing sw premul conversion, if needed. | 317 // temp buffer for doing sw premul conversion, if needed. |
| 318 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); | 318 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
| 319 if (tempTexture) { | 319 if (tempTexture) { |
| 320 SkAutoTUnref<const GrFragmentProcessor> fp; | 320 sk_sp<GrFragmentProcessor> fp; |
| 321 SkMatrix textureMatrix; | 321 SkMatrix textureMatrix; |
| 322 textureMatrix.setIDiv(tempTexture->width(), tempTexture->height()); | 322 textureMatrix.setIDiv(tempTexture->width(), tempTexture->height()); |
| 323 if (applyPremulToSrc) { | 323 if (applyPremulToSrc) { |
| 324 fp.reset(this->createUPMToPMEffect(tempTexture, tempDrawInfo.fSwizzl
e, | 324 fp = this->createUPMToPMEffect(tempTexture, tempDrawInfo.fSwizzle, t
extureMatrix); |
| 325 textureMatrix)); | |
| 326 // If premultiplying was the only reason for the draw, fall back to
a straight write. | 325 // If premultiplying was the only reason for the draw, fall back to
a straight write. |
| 327 if (!fp) { | 326 if (!fp) { |
| 328 if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference)
{ | 327 if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference)
{ |
| 329 tempTexture.reset(nullptr); | 328 tempTexture.reset(nullptr); |
| 330 } | 329 } |
| 331 } else { | 330 } else { |
| 332 applyPremulToSrc = false; | 331 applyPremulToSrc = false; |
| 333 } | 332 } |
| 334 } | 333 } |
| 335 if (tempTexture) { | 334 if (tempTexture) { |
| 336 if (!fp) { | 335 if (!fp) { |
| 337 fp.reset(GrConfigConversionEffect::Create(tempTexture, tempDrawI
nfo.fSwizzle, | 336 fp = GrConfigConversionEffect::Make(tempTexture, tempDrawInfo.fS
wizzle, |
| 338 GrConfigConversionEffect::kNone_PMConversion, textureMatrix)
); | 337 GrConfigConversionEffect::kN
one_PMConversion, |
| 338 textureMatrix); |
| 339 if (!fp) { | 339 if (!fp) { |
| 340 return false; | 340 return false; |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 GrRenderTarget* renderTarget = surface->asRenderTarget(); | 343 GrRenderTarget* renderTarget = surface->asRenderTarget(); |
| 344 SkASSERT(renderTarget); | 344 SkASSERT(renderTarget); |
| 345 if (tempTexture->surfacePriv().hasPendingIO()) { | 345 if (tempTexture->surfacePriv().hasPendingIO()) { |
| 346 this->flush(); | 346 this->flush(); |
| 347 } | 347 } |
| 348 if (applyPremulToSrc) { | 348 if (applyPremulToSrc) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 361 rowBytes)) { | 361 rowBytes)) { |
| 362 return false; | 362 return false; |
| 363 } | 363 } |
| 364 SkMatrix matrix; | 364 SkMatrix matrix; |
| 365 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 365 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 366 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(renderT
arget))); | 366 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(renderT
arget))); |
| 367 if (!drawContext) { | 367 if (!drawContext) { |
| 368 return false; | 368 return false; |
| 369 } | 369 } |
| 370 GrPaint paint; | 370 GrPaint paint; |
| 371 paint.addColorFragmentProcessor(fp); | 371 paint.addColorFragmentProcessor(std::move(fp)); |
| 372 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 372 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 373 paint.setAllowSRGBInputs(true); | 373 paint.setAllowSRGBInputs(true); |
| 374 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); | 374 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); |
| 375 drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); | 375 drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); |
| 376 | 376 |
| 377 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 377 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 378 this->flushSurfaceWrites(surface); | 378 this->flushSurfaceWrites(surface); |
| 379 } | 379 } |
| 380 } | 380 } |
| 381 } | 381 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 if (tempDrawInfo.fUseExactScratch) { | 454 if (tempDrawInfo.fUseExactScratch) { |
| 455 temp.reset(this->textureProvider()->createTexture(tempDrawInfo.fTemp
SurfaceDesc, | 455 temp.reset(this->textureProvider()->createTexture(tempDrawInfo.fTemp
SurfaceDesc, |
| 456 SkBudgeted::kYes))
; | 456 SkBudgeted::kYes))
; |
| 457 } else { | 457 } else { |
| 458 temp.reset(this->textureProvider()->createApproxTexture(tempDrawInfo
.fTempSurfaceDesc)); | 458 temp.reset(this->textureProvider()->createApproxTexture(tempDrawInfo
.fTempSurfaceDesc)); |
| 459 } | 459 } |
| 460 if (temp) { | 460 if (temp) { |
| 461 SkMatrix textureMatrix; | 461 SkMatrix textureMatrix; |
| 462 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 462 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 463 textureMatrix.postIDiv(src->width(), src->height()); | 463 textureMatrix.postIDiv(src->width(), src->height()); |
| 464 SkAutoTUnref<const GrFragmentProcessor> fp; | 464 sk_sp<GrFragmentProcessor> fp; |
| 465 if (unpremul) { | 465 if (unpremul) { |
| 466 fp.reset(this->createPMToUPMEffect(src->asTexture(), tempDrawInf
o.fSwizzle, | 466 fp = this->createPMToUPMEffect(src->asTexture(), tempDrawInfo.fS
wizzle, |
| 467 textureMatrix)); | 467 textureMatrix); |
| 468 if (fp) { | 468 if (fp) { |
| 469 unpremul = false; // we no longer need to do this on CPU aft
er the read back. | 469 unpremul = false; // we no longer need to do this on CPU aft
er the read back. |
| 470 } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPrefe
rence) { | 470 } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPrefe
rence) { |
| 471 // We only wanted to do the draw in order to perform the unp
remul so don't | 471 // We only wanted to do the draw in order to perform the unp
remul so don't |
| 472 // bother. | 472 // bother. |
| 473 temp.reset(nullptr); | 473 temp.reset(nullptr); |
| 474 } | 474 } |
| 475 } | 475 } |
| 476 if (!fp && temp) { | 476 if (!fp && temp) { |
| 477 fp.reset(GrConfigConversionEffect::Create(src->asTexture(), temp
DrawInfo.fSwizzle, | 477 fp = GrConfigConversionEffect::Make(src->asTexture(), tempDrawIn
fo.fSwizzle, |
| 478 GrConfigConversionEffect::kNone_PMConversion, textureMatrix)
); | 478 GrConfigConversionEffect::kN
one_PMConversion, |
| 479 textureMatrix); |
| 479 } | 480 } |
| 480 if (fp) { | 481 if (fp) { |
| 481 GrPaint paint; | 482 GrPaint paint; |
| 482 paint.addColorFragmentProcessor(fp); | 483 paint.addColorFragmentProcessor(std::move(fp)); |
| 483 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 484 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 484 paint.setAllowSRGBInputs(true); | 485 paint.setAllowSRGBInputs(true); |
| 485 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); | 486 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); |
| 486 sk_sp<GrDrawContext> drawContext( | 487 sk_sp<GrDrawContext> drawContext( |
| 487 this->drawContext(sk_ref_sp(temp->as
RenderTarget()))); | 488 this->drawContext(sk_ref_sp(temp->as
RenderTarget()))); |
| 488 drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect, nu
llptr); | 489 drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect, nu
llptr); |
| 489 surfaceToRead.reset(SkRef(temp.get())); | 490 surfaceToRead.reset(SkRef(temp.get())); |
| 490 left = 0; | 491 left = 0; |
| 491 top = 0; | 492 top = 0; |
| 492 didTempDraw = true; | 493 didTempDraw = true; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag, | 544 SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag, |
| 544 SkSurfaceProps::kLegacyFontHost_InitType); | 545 SkSurfaceProps::kLegacyFontHost_InitType); |
| 545 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), &props)); | 546 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), &props)); |
| 546 if (!drawContext) { | 547 if (!drawContext) { |
| 547 return false; | 548 return false; |
| 548 } | 549 } |
| 549 | 550 |
| 550 GrPaint paint; | 551 GrPaint paint; |
| 551 paint.addColorTextureProcessor(src, GrCoordTransform::MakeDivByTextureWHMatr
ix(src)); | 552 paint.addColorTextureProcessor(src, GrCoordTransform::MakeDivByTextureWHMatr
ix(src)); |
| 552 if (!SkScalarNearlyEqual(gamma, 1.0f)) { | 553 if (!SkScalarNearlyEqual(gamma, 1.0f)) { |
| 553 paint.addColorFragmentProcessor(GrGammaEffect::Create(gamma))->unref(); | 554 paint.addColorFragmentProcessor(GrGammaEffect::Make(gamma)); |
| 554 } | 555 } |
| 555 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 556 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 556 paint.setGammaCorrect(true); | 557 paint.setGammaCorrect(true); |
| 557 | 558 |
| 558 SkRect rect; | 559 SkRect rect; |
| 559 src->getBoundsRect(&rect); | 560 src->getBoundsRect(&rect); |
| 560 drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect); | 561 drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect); |
| 561 | 562 |
| 562 this->flushSurfaceWrites(dst); | 563 this->flushSurfaceWrites(dst); |
| 563 return true; | 564 return true; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 ASSERT_SINGLE_OWNER | 703 ASSERT_SINGLE_OWNER |
| 703 if (SkToBool(kUnpremul_PixelOpsFlag & flags)) { | 704 if (SkToBool(kUnpremul_PixelOpsFlag & flags)) { |
| 704 SkAutoMutexAcquire ama(fTestPMConversionsMutex); | 705 SkAutoMutexAcquire ama(fTestPMConversionsMutex); |
| 705 if (!fDidTestPMConversions) { | 706 if (!fDidTestPMConversions) { |
| 706 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); | 707 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
| 707 fDidTestPMConversions = true; | 708 fDidTestPMConversions = true; |
| 708 } | 709 } |
| 709 } | 710 } |
| 710 } | 711 } |
| 711 | 712 |
| 712 const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture, | 713 sk_sp<GrFragmentProcessor> GrContext::createPMToUPMEffect(GrTexture* texture, |
| 713 const GrSwizzle& swizz
le, | 714 const GrSwizzle& swizz
le, |
| 714 const SkMatrix& matrix
) const { | 715 const SkMatrix& matrix
) const { |
| 715 ASSERT_SINGLE_OWNER | 716 ASSERT_SINGLE_OWNER |
| 716 // We should have already called this->testPMConversionsIfNecessary(). | 717 // We should have already called this->testPMConversionsIfNecessary(). |
| 717 SkASSERT(fDidTestPMConversions); | 718 SkASSERT(fDidTestPMConversions); |
| 718 GrConfigConversionEffect::PMConversion pmToUPM = | 719 GrConfigConversionEffect::PMConversion pmToUPM = |
| 719 static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); | 720 static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); |
| 720 if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { | 721 if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { |
| 721 return GrConfigConversionEffect::Create(texture, swizzle, pmToUPM, matri
x); | 722 return GrConfigConversionEffect::Make(texture, swizzle, pmToUPM, matrix)
; |
| 722 } else { | 723 } else { |
| 723 return nullptr; | 724 return nullptr; |
| 724 } | 725 } |
| 725 } | 726 } |
| 726 | 727 |
| 727 const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture, | 728 sk_sp<GrFragmentProcessor> GrContext::createUPMToPMEffect(GrTexture* texture, |
| 728 const GrSwizzle& swizz
le, | 729 const GrSwizzle& swizz
le, |
| 729 const SkMatrix& matrix
) const { | 730 const SkMatrix& matrix
) const { |
| 730 ASSERT_SINGLE_OWNER | 731 ASSERT_SINGLE_OWNER |
| 731 // We should have already called this->testPMConversionsIfNecessary(). | 732 // We should have already called this->testPMConversionsIfNecessary(). |
| 732 SkASSERT(fDidTestPMConversions); | 733 SkASSERT(fDidTestPMConversions); |
| 733 GrConfigConversionEffect::PMConversion upmToPM = | 734 GrConfigConversionEffect::PMConversion upmToPM = |
| 734 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); | 735 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); |
| 735 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { | 736 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { |
| 736 return GrConfigConversionEffect::Create(texture, swizzle, upmToPM, matri
x); | 737 return GrConfigConversionEffect::Make(texture, swizzle, upmToPM, matrix)
; |
| 737 } else { | 738 } else { |
| 738 return nullptr; | 739 return nullptr; |
| 739 } | 740 } |
| 740 } | 741 } |
| 741 | 742 |
| 742 bool GrContext::didFailPMUPMConversionTest() const { | 743 bool GrContext::didFailPMUPMConversionTest() const { |
| 743 ASSERT_SINGLE_OWNER | 744 ASSERT_SINGLE_OWNER |
| 744 // We should have already called this->testPMConversionsIfNecessary(). | 745 // We should have already called this->testPMConversionsIfNecessary(). |
| 745 SkASSERT(fDidTestPMConversions); | 746 SkASSERT(fDidTestPMConversions); |
| 746 // The PM<->UPM tests fail or succeed together so we only need to check one. | 747 // The PM<->UPM tests fail or succeed together so we only need to check one. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 763 ASSERT_SINGLE_OWNER | 764 ASSERT_SINGLE_OWNER |
| 764 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 765 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| 765 } | 766 } |
| 766 | 767 |
| 767 ////////////////////////////////////////////////////////////////////////////// | 768 ////////////////////////////////////////////////////////////////////////////// |
| 768 | 769 |
| 769 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 770 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 770 ASSERT_SINGLE_OWNER | 771 ASSERT_SINGLE_OWNER |
| 771 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 772 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 772 } | 773 } |
| OLD | NEW |