1/* 2 * Copyright 2017 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8#include "GrMtlRenderTarget.h" 9 10#include "GrMtlGpu.h" 11#include "GrMtlUtil.h" 12 13// Called for wrapped non-texture render targets. 14GrMtlRenderTarget::GrMtlRenderTarget(GrMtlGpu* gpu, 15 const GrSurfaceDesc& desc, 16 id<MTLTexture> renderTexture, 17 Wrapped) 18 : GrSurface(gpu, desc) 19 , GrRenderTarget(gpu, desc) 20 , fRenderTexture(renderTexture) 21 , fResolveTexture(nil) { 22 SkASSERT(1 == desc.fSampleCnt); 23 this->registerWithCacheWrapped(GrWrapCacheable::kNo); 24} 25 26// Called by subclass constructors. 27GrMtlRenderTarget::GrMtlRenderTarget(GrMtlGpu* gpu, 28 const GrSurfaceDesc& desc, 29 id<MTLTexture> renderTexture) 30 : GrSurface(gpu, desc) 31 , GrRenderTarget(gpu, desc) 32 , fRenderTexture(renderTexture) 33 , fResolveTexture(nil) { 34 SkASSERT(1 == desc.fSampleCnt); 35} 36 37sk_sp<GrMtlRenderTarget> 38GrMtlRenderTarget::MakeWrappedRenderTarget(GrMtlGpu* gpu, const GrSurfaceDesc& desc, 39 id<MTLTexture> renderTexture) { 40 SkASSERT(nil != renderTexture); 41 SkASSERT(1 == renderTexture.mipmapLevelCount); 42 SkASSERT(MTLTextureUsageRenderTarget & renderTexture.usage); 43 return sk_sp<GrMtlRenderTarget>(new GrMtlRenderTarget(gpu, desc, renderTexture, kWrapped)); 44} 45 46GrMtlRenderTarget::~GrMtlRenderTarget() { 47 SkASSERT(nil == fRenderTexture); 48 SkASSERT(nil == fResolveTexture); 49} 50 51GrBackendRenderTarget GrMtlRenderTarget::getBackendRenderTarget() const { 52 GrMtlTextureInfo info; 53 info.fTexture = GrGetPtrFromId(fRenderTexture); 54 return GrBackendRenderTarget(this->width(), this->height(), fRenderTexture.sampleCount, info); 55} 56 57GrBackendFormat GrMtlRenderTarget::backendFormat() const { 58 return GrBackendFormat::MakeMtl(fRenderTexture.pixelFormat); 59} 60 61GrMtlGpu* GrMtlRenderTarget::getMtlGpu() const { 62 SkASSERT(!this->wasDestroyed()); 63 return static_cast<GrMtlGpu*>(this->getGpu()); 64} 65 66void GrMtlRenderTarget::onAbandon() { 67 fRenderTexture = nil; 68 fResolveTexture = nil; 69} 70 71void GrMtlRenderTarget::onRelease() { 72 fRenderTexture = nil; 73 fResolveTexture = nil; 74} 75 76bool GrMtlRenderTarget::completeStencilAttachment() { 77 return true; 78} 79 80