| 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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 430 |
| 431 GrGpu::ReadPixelTempDrawInfo tempDrawInfo; | 431 GrGpu::ReadPixelTempDrawInfo tempDrawInfo; |
| 432 if (!fGpu->getReadPixelsInfo(src, width, height, rowBytes, dstConfig, &drawP
reference, | 432 if (!fGpu->getReadPixelsInfo(src, width, height, rowBytes, dstConfig, &drawP
reference, |
| 433 &tempDrawInfo)) { | 433 &tempDrawInfo)) { |
| 434 return false; | 434 return false; |
| 435 } | 435 } |
| 436 | 436 |
| 437 SkAutoTUnref<GrSurface> surfaceToRead(SkRef(src)); | 437 SkAutoTUnref<GrSurface> surfaceToRead(SkRef(src)); |
| 438 bool didTempDraw = false; | 438 bool didTempDraw = false; |
| 439 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { | 439 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
| 440 if (tempDrawInfo.fUseExactScratch) { | 440 if (SkBackingFit::kExact == tempDrawInfo.fTempSurfaceFit) { |
| 441 // We only respect this when the entire src is being read. Otherwise
we can trigger too | 441 // We only respect this when the entire src is being read. Otherwise
we can trigger too |
| 442 // many odd ball texture sizes and trash the cache. | 442 // many odd ball texture sizes and trash the cache. |
| 443 if (width != src->width() || height != src->height()) { | 443 if (width != src->width() || height != src->height()) { |
| 444 tempDrawInfo.fUseExactScratch = false; | 444 tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox; |
| 445 } | 445 } |
| 446 } | 446 } |
| 447 SkAutoTUnref<GrTexture> temp; | 447 sk_sp<GrDrawContext> tempDC = this->newDrawContext(tempDrawInfo.fTempSur
faceFit, |
| 448 if (tempDrawInfo.fUseExactScratch) { | 448 tempDrawInfo.fTempSur
faceDesc.fWidth, |
| 449 temp.reset(this->textureProvider()->createTexture(tempDrawInfo.fTemp
SurfaceDesc, | 449 tempDrawInfo.fTempSur
faceDesc.fHeight, |
| 450 SkBudgeted::kYes))
; | 450 tempDrawInfo.fTempSur
faceDesc.fConfig, |
| 451 } else { | 451 tempDrawInfo.fTempSur
faceDesc.fSampleCnt, |
| 452 temp.reset(this->textureProvider()->createApproxTexture(tempDrawInfo
.fTempSurfaceDesc)); | 452 tempDrawInfo.fTempSur
faceDesc.fOrigin); |
| 453 } | 453 if (tempDC) { |
| 454 if (temp) { | |
| 455 SkMatrix textureMatrix; | 454 SkMatrix textureMatrix; |
| 456 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 455 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 457 textureMatrix.postIDiv(src->width(), src->height()); | 456 textureMatrix.postIDiv(src->width(), src->height()); |
| 458 sk_sp<GrFragmentProcessor> fp; | 457 sk_sp<GrFragmentProcessor> fp; |
| 459 if (unpremul) { | 458 if (unpremul) { |
| 460 fp = this->createPMToUPMEffect(src->asTexture(), tempDrawInfo.fS
wizzle, | 459 fp = this->createPMToUPMEffect(src->asTexture(), tempDrawInfo.fS
wizzle, |
| 461 textureMatrix); | 460 textureMatrix); |
| 462 if (fp) { | 461 if (fp) { |
| 463 unpremul = false; // we no longer need to do this on CPU aft
er the read back. | 462 unpremul = false; // we no longer need to do this on CPU aft
er the read back. |
| 464 } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPrefe
rence) { | 463 } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPrefe
rence) { |
| 465 // We only wanted to do the draw in order to perform the unp
remul so don't | 464 // We only wanted to do the draw in order to perform the unp
remul so don't |
| 466 // bother. | 465 // bother. |
| 467 temp.reset(nullptr); | 466 tempDC.reset(nullptr); |
| 468 } | 467 } |
| 469 } | 468 } |
| 470 if (!fp && temp) { | 469 if (!fp && tempDC) { |
| 471 fp = GrConfigConversionEffect::Make(src->asTexture(), tempDrawIn
fo.fSwizzle, | 470 fp = GrConfigConversionEffect::Make(src->asTexture(), tempDrawIn
fo.fSwizzle, |
| 472 GrConfigConversionEffect::kN
one_PMConversion, | 471 GrConfigConversionEffect::kN
one_PMConversion, |
| 473 textureMatrix); | 472 textureMatrix); |
| 474 } | 473 } |
| 475 if (fp) { | 474 if (fp) { |
| 476 GrPaint paint; | 475 GrPaint paint; |
| 477 paint.addColorFragmentProcessor(std::move(fp)); | 476 paint.addColorFragmentProcessor(std::move(fp)); |
| 478 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 477 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 479 paint.setAllowSRGBInputs(true); | 478 paint.setAllowSRGBInputs(true); |
| 480 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); | 479 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); |
| 481 sk_sp<GrDrawContext> drawContext( | 480 tempDC->drawRect(GrNoClip(), paint, SkMatrix::I(), rect, nullptr
); |
| 482 this->drawContext(sk_ref_sp(temp->as
RenderTarget()))); | 481 surfaceToRead.reset(tempDC->asTexture().release()); |
| 483 drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect, nu
llptr); | |
| 484 surfaceToRead.reset(SkRef(temp.get())); | |
| 485 left = 0; | 482 left = 0; |
| 486 top = 0; | 483 top = 0; |
| 487 didTempDraw = true; | 484 didTempDraw = true; |
| 488 } | 485 } |
| 489 } | 486 } |
| 490 } | 487 } |
| 491 | 488 |
| 492 if (GrGpu::kRequireDraw_DrawPreference == drawPreference && !didTempDraw) { | 489 if (GrGpu::kRequireDraw_DrawPreference == drawPreference && !didTempDraw) { |
| 493 return false; | 490 return false; |
| 494 } | 491 } |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 ASSERT_SINGLE_OWNER | 755 ASSERT_SINGLE_OWNER |
| 759 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 756 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| 760 } | 757 } |
| 761 | 758 |
| 762 ////////////////////////////////////////////////////////////////////////////// | 759 ////////////////////////////////////////////////////////////////////////////// |
| 763 | 760 |
| 764 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 761 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 765 ASSERT_SINGLE_OWNER | 762 ASSERT_SINGLE_OWNER |
| 766 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 763 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 767 } | 764 } |
| OLD | NEW |