| Index: src/gpu/GrContext.cpp
|
| diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
|
| index bd4ca40a34b05139fa2ea39565c447bc07255456..37355a13ddac3259b42df0acca0a384270449d7e 100644
|
| --- a/src/gpu/GrContext.cpp
|
| +++ b/src/gpu/GrContext.cpp
|
| @@ -22,6 +22,8 @@
|
|
|
| #include "effects/GrConfigConversionEffect.h"
|
|
|
| +class GrDrawTarget;
|
| +
|
| #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
|
| #define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; }
|
| #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return false; }
|
| @@ -118,14 +120,14 @@ GrContext::~GrContext() {
|
|
|
| void GrContext::abandonContext() {
|
| fResourceProvider->abandon();
|
| +
|
| + fDrawingManager->abandon();
|
| // abandon first to so destructors
|
| // don't try to free the resources in the API.
|
| fResourceCache->abandonAll();
|
|
|
| fGpu->contextAbandoned();
|
|
|
| - fDrawingManager->abandon();
|
| -
|
| fBatchFontCache->freeAll();
|
| fLayerCache->freeAll();
|
| fTextBlobCache->freeAll();
|
| @@ -138,6 +140,8 @@ void GrContext::resetContext(uint32_t state) {
|
| void GrContext::freeGpuResources() {
|
| this->flush();
|
|
|
| + //fDrawingMgr.purgeResources1();
|
| +
|
| fBatchFontCache->freeAll();
|
| fLayerCache->freeAll();
|
|
|
| @@ -210,7 +214,7 @@ bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t
|
| return srcPI.convertPixelsTo(&dstPI, width, height);
|
| }
|
|
|
| -bool GrContext::writeSurfacePixels(GrSurface* surface,
|
| +bool GrContext::writeSurfacePixels(GrDrawContext* surfaceDC, GrSurface* surface,
|
| int left, int top, int width, int height,
|
| GrPixelConfig srcConfig, const void* buffer, size_t rowBytes,
|
| uint32_t pixelOpsFlags) {
|
| @@ -275,8 +279,8 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
|
| textureMatrix.setIDiv(tempTexture->width(), tempTexture->height());
|
| GrPaint paint;
|
| if (applyPremulToSrc) {
|
| - fp.reset(this->createUPMToPMEffect(tempTexture, tempDrawInfo.fSwapRAndB,
|
| - textureMatrix));
|
| + fp.reset(this->createUPMToPMEffect(tempTexture,
|
| + tempDrawInfo.fSwapRAndB, textureMatrix, surface->asRenderTarget()));
|
| // If premultiplying was the only reason for the draw, fall back to a straight write.
|
| if (!fp) {
|
| if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference) {
|
| @@ -287,15 +291,16 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
|
| }
|
| }
|
| if (tempTexture) {
|
| + GrRenderTarget* renderTarget = surface->asRenderTarget();
|
| + SkASSERT(renderTarget);
|
| if (!fp) {
|
| - fp.reset(GrConfigConversionEffect::Create(tempTexture, tempDrawInfo.fSwapRAndB,
|
| - GrConfigConversionEffect::kNone_PMConversion, textureMatrix));
|
| + fp.reset(GrConfigConversionEffect::Create(
|
| + tempTexture, tempDrawInfo.fSwapRAndB,
|
| + GrConfigConversionEffect::kNone_PMConversion, textureMatrix, renderTarget));
|
| if (!fp) {
|
| return false;
|
| }
|
| }
|
| - GrRenderTarget* renderTarget = surface->asRenderTarget();
|
| - SkASSERT(renderTarget);
|
| if (tempTexture->surfacePriv().hasPendingIO()) {
|
| this->flush();
|
| }
|
| @@ -315,8 +320,13 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
|
| rowBytes)) {
|
| return false;
|
| }
|
| + if (buffer) {
|
| + tempTexture->setFromRawPixels(true);
|
| + tempTexture->setException(true);
|
| + }
|
| SkMatrix matrix;
|
| matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
|
| +
|
| SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(renderTarget));
|
| if (!drawContext) {
|
| return false;
|
| @@ -344,6 +354,7 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
|
| }
|
| return fGpu->writePixels(surface, left, top, width, height, srcConfig, buffer, rowBytes);
|
| }
|
| +
|
| return true;
|
| }
|
|
|
| @@ -412,8 +423,9 @@ bool GrContext::readSurfacePixels(GrSurface* src,
|
| GrPaint paint;
|
| SkAutoTUnref<const GrFragmentProcessor> fp;
|
| if (unpremul) {
|
| - fp.reset(this->createPMToUPMEffect(src->asTexture(), tempDrawInfo.fSwapRAndB,
|
| - textureMatrix));
|
| + fp.reset(this->createPMToUPMEffect(
|
| + src->asTexture(), tempDrawInfo.fSwapRAndB,
|
| + textureMatrix, temp->asRenderTarget()));
|
| if (fp) {
|
| unpremul = false; // we no longer need to do this on CPU after the read back.
|
| } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference) {
|
| @@ -423,8 +435,9 @@ bool GrContext::readSurfacePixels(GrSurface* src,
|
| }
|
| }
|
| if (!fp && temp) {
|
| - fp.reset(GrConfigConversionEffect::Create(src->asTexture(), tempDrawInfo.fSwapRAndB,
|
| - GrConfigConversionEffect::kNone_PMConversion, textureMatrix));
|
| + fp.reset(GrConfigConversionEffect::Create(
|
| + src->asTexture(), tempDrawInfo.fSwapRAndB,
|
| + GrConfigConversionEffect::kNone_PMConversion, textureMatrix, temp->asRenderTarget()));
|
| }
|
| if (fp) {
|
| paint.addColorFragmentProcessor(fp);
|
| @@ -572,13 +585,15 @@ void GrContext::testPMConversionsIfNecessary(uint32_t flags) {
|
|
|
| const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture,
|
| bool swapRAndB,
|
| - const SkMatrix& matrix) const {
|
| + const SkMatrix& matrix,
|
| + GrRenderTarget* dst) const {
|
| // We should have already called this->testPMConversionsIfNecessary().
|
| SkASSERT(fDidTestPMConversions);
|
| GrConfigConversionEffect::PMConversion pmToUPM =
|
| static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion);
|
| if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) {
|
| - return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM, matrix);
|
| + return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM,
|
| + matrix, dst);
|
| } else {
|
| return nullptr;
|
| }
|
| @@ -586,13 +601,14 @@ const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture,
|
|
|
| const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture,
|
| bool swapRAndB,
|
| - const SkMatrix& matrix) const {
|
| + const SkMatrix& matrix, GrRenderTarget* dst) const {
|
| // We should have already called this->testPMConversionsIfNecessary().
|
| SkASSERT(fDidTestPMConversions);
|
| GrConfigConversionEffect::PMConversion upmToPM =
|
| static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion);
|
| if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) {
|
| - return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, matrix);
|
| + return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM,
|
| + matrix, dst);
|
| } else {
|
| return nullptr;
|
| }
|
|
|