/* * Copyright 2017 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "GrMtlRenderTarget.h" #include "GrMtlGpu.h" #include "GrMtlUtil.h" // Called for wrapped non-texture render targets. GrMtlRenderTarget::GrMtlRenderTarget(GrMtlGpu* gpu, const GrSurfaceDesc& desc, id renderTexture, Wrapped) : GrSurface(gpu, desc) , GrRenderTarget(gpu, desc) , fRenderTexture(renderTexture) , fResolveTexture(nil) { SkASSERT(1 == desc.fSampleCnt); this->registerWithCacheWrapped(GrWrapCacheable::kNo); } // Called by subclass constructors. GrMtlRenderTarget::GrMtlRenderTarget(GrMtlGpu* gpu, const GrSurfaceDesc& desc, id renderTexture) : GrSurface(gpu, desc) , GrRenderTarget(gpu, desc) , fRenderTexture(renderTexture) , fResolveTexture(nil) { SkASSERT(1 == desc.fSampleCnt); } sk_sp GrMtlRenderTarget::MakeWrappedRenderTarget(GrMtlGpu* gpu, const GrSurfaceDesc& desc, id renderTexture) { SkASSERT(nil != renderTexture); SkASSERT(1 == renderTexture.mipmapLevelCount); SkASSERT(MTLTextureUsageRenderTarget & renderTexture.usage); return sk_sp(new GrMtlRenderTarget(gpu, desc, renderTexture, kWrapped)); } GrMtlRenderTarget::~GrMtlRenderTarget() { SkASSERT(nil == fRenderTexture); SkASSERT(nil == fResolveTexture); } GrBackendRenderTarget GrMtlRenderTarget::getBackendRenderTarget() const { GrMtlTextureInfo info; info.fTexture = GrGetPtrFromId(fRenderTexture); return GrBackendRenderTarget(this->width(), this->height(), fRenderTexture.sampleCount, info); } GrBackendFormat GrMtlRenderTarget::backendFormat() const { return GrBackendFormat::MakeMtl(fRenderTexture.pixelFormat); } GrMtlGpu* GrMtlRenderTarget::getMtlGpu() const { SkASSERT(!this->wasDestroyed()); return static_cast(this->getGpu()); } void GrMtlRenderTarget::onAbandon() { fRenderTexture = nil; fResolveTexture = nil; INHERITED::onAbandon(); } void GrMtlRenderTarget::onRelease() { fRenderTexture = nil; fResolveTexture = nil; INHERITED::onRelease(); } bool GrMtlRenderTarget::completeStencilAttachment() { return true; }