diff options
author | 2016-07-19 07:24:40 -0700 | |
---|---|---|
committer | 2016-07-19 07:24:40 -0700 | |
commit | b117ff194ff888ef9107a4797aad053b0d76be30 (patch) | |
tree | f2ede1f27f7d2513450c5ec45856210fef1c11f3 /src/gpu | |
parent | 23c4f1acbcbb72f5a5f380bedc3eed0c1c387a04 (diff) |
Convert readSurfacePixels to use a draw context instead of a texture
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2165523003
Review-Url: https://codereview.chromium.org/2165523003
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrContext.cpp | 29 | ||||
-rw-r--r-- | src/gpu/GrGpu.h | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 4 | ||||
-rw-r--r-- | src/gpu/vk/GrVkGpu.cpp | 2 |
4 files changed, 17 insertions, 20 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 4a2b2b0228..4cb90c658e 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -437,21 +437,20 @@ bool GrContext::readSurfacePixels(GrSurface* src, SkAutoTUnref<GrSurface> surfaceToRead(SkRef(src)); bool didTempDraw = false; if (GrGpu::kNoDraw_DrawPreference != drawPreference) { - if (tempDrawInfo.fUseExactScratch) { + if (SkBackingFit::kExact == tempDrawInfo.fTempSurfaceFit) { // We only respect this when the entire src is being read. Otherwise we can trigger too // many odd ball texture sizes and trash the cache. if (width != src->width() || height != src->height()) { - tempDrawInfo.fUseExactScratch = false; + tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox; } } - SkAutoTUnref<GrTexture> temp; - if (tempDrawInfo.fUseExactScratch) { - temp.reset(this->textureProvider()->createTexture(tempDrawInfo.fTempSurfaceDesc, - SkBudgeted::kYes)); - } else { - temp.reset(this->textureProvider()->createApproxTexture(tempDrawInfo.fTempSurfaceDesc)); - } - if (temp) { + sk_sp<GrDrawContext> tempDC = this->newDrawContext(tempDrawInfo.fTempSurfaceFit, + tempDrawInfo.fTempSurfaceDesc.fWidth, + tempDrawInfo.fTempSurfaceDesc.fHeight, + tempDrawInfo.fTempSurfaceDesc.fConfig, + tempDrawInfo.fTempSurfaceDesc.fSampleCnt, + tempDrawInfo.fTempSurfaceDesc.fOrigin); + if (tempDC) { SkMatrix textureMatrix; textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); textureMatrix.postIDiv(src->width(), src->height()); @@ -464,10 +463,10 @@ bool GrContext::readSurfacePixels(GrSurface* src, } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference) { // We only wanted to do the draw in order to perform the unpremul so don't // bother. - temp.reset(nullptr); + tempDC.reset(nullptr); } } - if (!fp && temp) { + if (!fp && tempDC) { fp = GrConfigConversionEffect::Make(src->asTexture(), tempDrawInfo.fSwizzle, GrConfigConversionEffect::kNone_PMConversion, textureMatrix); @@ -478,10 +477,8 @@ bool GrContext::readSurfacePixels(GrSurface* src, paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); paint.setAllowSRGBInputs(true); SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); - sk_sp<GrDrawContext> drawContext( - this->drawContext(sk_ref_sp(temp->asRenderTarget()))); - drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect, nullptr); - surfaceToRead.reset(SkRef(temp.get())); + tempDC->drawRect(GrNoClip(), paint, SkMatrix::I(), rect, nullptr); + surfaceToRead.reset(tempDC->asTexture().release()); left = 0; top = 0; didTempDraw = true; diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index dce41fd4c2..37427b5739 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -170,7 +170,7 @@ public: GrSurfaceDesc fTempSurfaceDesc; /** Indicates whether there is a performance advantage to using an exact match texture (in terms of width and height) for the intermediate texture instead of approximate. */ - bool fUseExactScratch; + SkBackingFit fTempSurfaceFit; /** Swizzle to apply during the draw. This is used to compensate for either feature or performance limitations in the underlying 3D API. */ GrSwizzle fSwizzle; diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 8b9242cd05..ae38ed8779 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -2328,8 +2328,8 @@ bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height, tempDrawInfo->fTempSurfaceDesc.fHeight = height; tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU y-flip for TL. - tempDrawInfo->fUseExactScratch = this->glCaps().partialFBOReadIsSlow(); - + tempDrawInfo->fTempSurfaceFit = this->glCaps().partialFBOReadIsSlow() ? SkBackingFit::kExact + : SkBackingFit::kApprox; // For now assume no swizzling, we may change that below. tempDrawInfo->fSwizzle = GrSwizzle::RGBA(); diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index e779bac99b..a09a805e3c 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -1388,7 +1388,7 @@ bool GrVkGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height, tempDrawInfo->fTempSurfaceDesc.fHeight = height; tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU y-flip for TL. - tempDrawInfo->fUseExactScratch = false; + tempDrawInfo->fTempSurfaceFit = SkBackingFit::kApprox; // For now assume no swizzling, we may change that below. tempDrawInfo->fSwizzle = GrSwizzle::RGBA(); |