Home | History | Annotate | Download | only in mtl
      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.
     14 GrMtlRenderTarget::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.
     27 GrMtlRenderTarget::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 
     37 sk_sp<GrMtlRenderTarget>
     38 GrMtlRenderTarget::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 
     46 GrMtlRenderTarget::~GrMtlRenderTarget() {
     47     SkASSERT(nil == fRenderTexture);
     48     SkASSERT(nil == fResolveTexture);
     49 }
     50 
     51 GrBackendRenderTarget GrMtlRenderTarget::getBackendRenderTarget() const {
     52     GrMtlTextureInfo info;
     53     info.fTexture = GrGetPtrFromId(fRenderTexture);
     54     return GrBackendRenderTarget(this->width(), this->height(), fRenderTexture.sampleCount, info);
     55 }
     56 
     57 GrBackendFormat GrMtlRenderTarget::backendFormat() const {
     58     return GrBackendFormat::MakeMtl(fRenderTexture.pixelFormat);
     59 }
     60 
     61 GrMtlGpu* GrMtlRenderTarget::getMtlGpu() const {
     62     SkASSERT(!this->wasDestroyed());
     63     return static_cast<GrMtlGpu*>(this->getGpu());
     64 }
     65 
     66 void GrMtlRenderTarget::onAbandon() {
     67     fRenderTexture = nil;
     68     fResolveTexture = nil;
     69     INHERITED::onAbandon();
     70 }
     71 
     72 void GrMtlRenderTarget::onRelease() {
     73     fRenderTexture = nil;
     74     fResolveTexture = nil;
     75     INHERITED::onRelease();
     76 }
     77 
     78 bool GrMtlRenderTarget::completeStencilAttachment() {
     79     return true;
     80 }
     81 
     82