From e30739a1e1d90183bc6bf7414e409e89016881f5 Mon Sep 17 00:00:00 2001 From: Timothy Liang Date: Tue, 31 Jul 2018 10:51:17 -0400 Subject: implemented copy surface as draw for metal gpu backend Bug: skia: Change-Id: Ie61bd6ad9f288b8a025d44f887a0954101a7d710 Reviewed-on: https://skia-review.googlesource.com/142687 Commit-Queue: Timothy Liang Reviewed-by: Greg Daniel --- src/gpu/mtl/GrMtlGpu.mm | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) (limited to 'src/gpu/mtl/GrMtlGpu.mm') diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm index 79eeb3ad6b..2c47c3c7aa 100644 --- a/src/gpu/mtl/GrMtlGpu.mm +++ b/src/gpu/mtl/GrMtlGpu.mm @@ -13,6 +13,9 @@ #include "GrMtlUtil.h" #include "GrTexturePriv.h" #include "SkConvertPixels.h" +#include "SkSLCompiler.h" + +#import #if !__has_feature(objc_arc) #error This file must be compiled with Arc. Use -fobjc-arc flag @@ -90,7 +93,10 @@ GrMtlGpu::GrMtlGpu(GrContext* context, const GrContextOptions& options, id device, id queue, MTLFeatureSet featureSet) : INHERITED(context) , fDevice(device) - , fQueue(queue) { + , fQueue(queue) + , fCompiler(new SkSL::Compiler()) + , fCopyManager(this) + , fResourceProvider(this) { fMtlCaps.reset(new GrMtlCaps(options, fDevice, featureSet)); fCaps = fMtlCaps; @@ -527,28 +533,6 @@ void GrMtlGpu::testingOnly_flushGpuAndSync() { } #endif // GR_TEST_UTILS -id get_mtl_texture_from_surface(GrSurface* surface, bool doResolve) { - id mtlTexture = nil; - - GrMtlRenderTarget* renderTarget = static_cast(surface->asRenderTarget()); - GrMtlTexture* texture; - if (renderTarget) { - if (doResolve) { - // TODO: do resolve and set mtlTexture to resolved texture. As of now, we shouldn't - // have any multisampled render targets. - SkASSERT(false); - } else { - mtlTexture = renderTarget->mtlRenderTexture(); - } - } else { - texture = static_cast(surface->asTexture()); - if (texture) { - mtlTexture = texture->mtlTexture(); - } - } - return mtlTexture; -} - static int get_surface_sample_cnt(GrSurface* surf) { if (const GrRenderTarget* rt = surf->asRenderTarget()) { return rt->numColorSamples(); @@ -566,8 +550,8 @@ bool GrMtlGpu::copySurfaceAsBlit(GrSurface* dst, GrSurfaceOrigin dstOrigin, src->config(), srcSampleCnt, srcOrigin, srcRect, dstPoint, dst == src)); #endif - id dstTex = get_mtl_texture_from_surface(dst, false); - id srcTex = get_mtl_texture_from_surface(src, false); + id dstTex = GrGetMTLTextureFromSurface(dst, false); + id srcTex = GrGetMTLTextureFromSurface(src, false); // Flip rect if necessary SkIRect srcMtlRect; @@ -625,9 +609,13 @@ bool GrMtlGpu::onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin, } bool success = false; - if (this->mtlCaps().canCopyAsBlit(dstConfig, dstSampleCnt, dstOrigin, - srcConfig, srcSampleCnt, srcOrigin, - srcRect, dstPoint, dst == src)) { + if (this->mtlCaps().canCopyAsDraw(dst->config(), SkToBool(dst->asRenderTarget()), + src->config(), SkToBool(src->asTexture()))) { + success = fCopyManager.copySurfaceAsDraw(dst, dstOrigin, src, srcOrigin, srcRect, dstPoint, + canDiscardOutsideDstRect); + } else if (this->mtlCaps().canCopyAsBlit(dstConfig, dstSampleCnt, dstOrigin, + srcConfig, srcSampleCnt, srcOrigin, + srcRect, dstPoint, dst == src)) { success = this->copySurfaceAsBlit(dst, dstOrigin, src, srcOrigin, srcRect, dstPoint); } if (success) { @@ -668,7 +656,7 @@ bool GrMtlGpu::onReadPixels(GrSurface* surface, int left, int top, int width, in } bool doResolve = get_surface_sample_cnt(surface) > 1; - id mtlTexture = get_mtl_texture_from_surface(surface, doResolve); + id mtlTexture = GrGetMTLTextureFromSurface(surface, doResolve); if (!mtlTexture) { return false; } -- cgit v1.2.3