1 /* 2 * Copyright 2018 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 #ifndef GrMtlTextureRenderTarget_DEFINED 9 #define GrMtlTextureRenderTarget_DEFINED 10 11 #include "src/gpu/mtl/GrMtlRenderTarget.h" 12 #include "src/gpu/mtl/GrMtlTexture.h" 13 14 class GrMtlTextureRenderTarget: public GrMtlTexture, public GrMtlRenderTarget { 15 public: 16 static sk_sp<GrMtlTextureRenderTarget> MakeNewTextureRenderTarget(GrMtlGpu*, 17 SkBudgeted, 18 const GrSurfaceDesc&, 19 int sampleCnt, 20 MTLTextureDescriptor*, 21 GrMipMapsStatus); 22 23 static sk_sp<GrMtlTextureRenderTarget> MakeWrappedTextureRenderTarget(GrMtlGpu*, 24 const GrSurfaceDesc&, 25 int sampleCnt, 26 id<MTLTexture>, 27 GrWrapCacheable); backendFormat()28 GrBackendFormat backendFormat() const override { 29 return GrMtlTexture::backendFormat(); 30 } 31 32 protected: onAbandon()33 void onAbandon() override { 34 GrMtlRenderTarget::onAbandon(); 35 GrMtlTexture::onAbandon(); 36 } 37 onRelease()38 void onRelease() override { 39 GrMtlRenderTarget::onRelease(); 40 GrMtlTexture::onRelease(); 41 } 42 43 private: 44 GrMtlTextureRenderTarget(GrMtlGpu* gpu, 45 SkBudgeted budgeted, 46 const GrSurfaceDesc& desc, 47 int sampleCnt, 48 id<MTLTexture> colorTexture, 49 id<MTLTexture> resolveTexture, 50 GrMipMapsStatus); 51 52 GrMtlTextureRenderTarget(GrMtlGpu* gpu, 53 SkBudgeted budgeted, 54 const GrSurfaceDesc& desc, 55 id<MTLTexture> colorTexture, 56 GrMipMapsStatus); 57 58 GrMtlTextureRenderTarget(GrMtlGpu* gpu, 59 const GrSurfaceDesc& desc, 60 int sampleCnt, 61 id<MTLTexture> colorTexture, 62 id<MTLTexture> resolveTexture, 63 GrMipMapsStatus, 64 GrWrapCacheable cacheable); 65 66 GrMtlTextureRenderTarget(GrMtlGpu* gpu, 67 const GrSurfaceDesc& desc, 68 id<MTLTexture> colorTexture, 69 GrMipMapsStatus, 70 GrWrapCacheable cacheable); 71 onGpuMemorySize()72 size_t onGpuMemorySize() const override { 73 // TODO: When used as render targets certain formats may actually have a larger size than 74 // the base format size. Check to make sure we are reporting the correct value here. 75 // The plus 1 is to account for the resolve texture or if not using msaa the RT itself 76 int numColorSamples = this->numSamples(); 77 if (numColorSamples > 1) { 78 ++numColorSamples; 79 } 80 const GrCaps& caps = *this->getGpu()->caps(); 81 return GrSurface::ComputeSize(caps, this->backendFormat(), this->width(), this->height(), 82 numColorSamples, GrMipMapped::kNo); 83 } 84 }; 85 86 #endif 87