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
This commit is contained in:
bsalomon 2016-07-19 07:24:40 -07:00 committed by Commit bot
parent 23c4f1acbc
commit b117ff194f
4 changed files with 17 additions and 20 deletions

View File

@ -437,21 +437,20 @@ bool GrContext::readSurfacePixels(GrSurface* src,
SkAutoTUnref<GrSurface> surfaceToRead(SkRef(src)); SkAutoTUnref<GrSurface> surfaceToRead(SkRef(src));
bool didTempDraw = false; bool didTempDraw = false;
if (GrGpu::kNoDraw_DrawPreference != drawPreference) { 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 // 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. // many odd ball texture sizes and trash the cache.
if (width != src->width() || height != src->height()) { if (width != src->width() || height != src->height()) {
tempDrawInfo.fUseExactScratch = false; tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox;
} }
} }
SkAutoTUnref<GrTexture> temp; sk_sp<GrDrawContext> tempDC = this->newDrawContext(tempDrawInfo.fTempSurfaceFit,
if (tempDrawInfo.fUseExactScratch) { tempDrawInfo.fTempSurfaceDesc.fWidth,
temp.reset(this->textureProvider()->createTexture(tempDrawInfo.fTempSurfaceDesc, tempDrawInfo.fTempSurfaceDesc.fHeight,
SkBudgeted::kYes)); tempDrawInfo.fTempSurfaceDesc.fConfig,
} else { tempDrawInfo.fTempSurfaceDesc.fSampleCnt,
temp.reset(this->textureProvider()->createApproxTexture(tempDrawInfo.fTempSurfaceDesc)); tempDrawInfo.fTempSurfaceDesc.fOrigin);
} if (tempDC) {
if (temp) {
SkMatrix textureMatrix; SkMatrix textureMatrix;
textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
textureMatrix.postIDiv(src->width(), src->height()); textureMatrix.postIDiv(src->width(), src->height());
@ -464,10 +463,10 @@ bool GrContext::readSurfacePixels(GrSurface* src,
} else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference) { } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference) {
// We only wanted to do the draw in order to perform the unpremul so don't // We only wanted to do the draw in order to perform the unpremul so don't
// bother. // bother.
temp.reset(nullptr); tempDC.reset(nullptr);
} }
} }
if (!fp && temp) { if (!fp && tempDC) {
fp = GrConfigConversionEffect::Make(src->asTexture(), tempDrawInfo.fSwizzle, fp = GrConfigConversionEffect::Make(src->asTexture(), tempDrawInfo.fSwizzle,
GrConfigConversionEffect::kNone_PMConversion, GrConfigConversionEffect::kNone_PMConversion,
textureMatrix); textureMatrix);
@ -478,10 +477,8 @@ bool GrContext::readSurfacePixels(GrSurface* src,
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
paint.setAllowSRGBInputs(true); paint.setAllowSRGBInputs(true);
SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
sk_sp<GrDrawContext> drawContext( tempDC->drawRect(GrNoClip(), paint, SkMatrix::I(), rect, nullptr);
this->drawContext(sk_ref_sp(temp->asRenderTarget()))); surfaceToRead.reset(tempDC->asTexture().release());
drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect, nullptr);
surfaceToRead.reset(SkRef(temp.get()));
left = 0; left = 0;
top = 0; top = 0;
didTempDraw = true; didTempDraw = true;

View File

@ -170,7 +170,7 @@ public:
GrSurfaceDesc fTempSurfaceDesc; GrSurfaceDesc fTempSurfaceDesc;
/** Indicates whether there is a performance advantage to using an exact match texture /** 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. */ (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 /** Swizzle to apply during the draw. This is used to compensate for either feature or
performance limitations in the underlying 3D API. */ performance limitations in the underlying 3D API. */
GrSwizzle fSwizzle; GrSwizzle fSwizzle;

View File

@ -2328,8 +2328,8 @@ bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height,
tempDrawInfo->fTempSurfaceDesc.fHeight = height; tempDrawInfo->fTempSurfaceDesc.fHeight = height;
tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0;
tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU y-flip for TL. 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. // For now assume no swizzling, we may change that below.
tempDrawInfo->fSwizzle = GrSwizzle::RGBA(); tempDrawInfo->fSwizzle = GrSwizzle::RGBA();

View File

@ -1388,7 +1388,7 @@ bool GrVkGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height,
tempDrawInfo->fTempSurfaceDesc.fHeight = height; tempDrawInfo->fTempSurfaceDesc.fHeight = height;
tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0;
tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU y-flip for TL. 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. // For now assume no swizzling, we may change that below.
tempDrawInfo->fSwizzle = GrSwizzle::RGBA(); tempDrawInfo->fSwizzle = GrSwizzle::RGBA();