Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 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 | #include "GrMtlTextureRenderTarget.h" |
| 9 | #include "GrMtlGpu.h" |
| 10 | #include "GrMtlUtil.h" |
| 11 | |
| 12 | GrMtlTextureRenderTarget::GrMtlTextureRenderTarget(GrMtlGpu* gpu, |
| 13 | SkBudgeted budgeted, |
| 14 | const GrSurfaceDesc& desc, |
| 15 | id<MTLTexture> renderTexture, |
| 16 | GrMipMapsStatus mipMapsStatus) |
| 17 | : GrSurface(gpu, desc) |
| 18 | , GrMtlTexture(gpu, desc, renderTexture, mipMapsStatus) |
| 19 | , GrMtlRenderTarget(gpu, desc, renderTexture) { |
| 20 | this->registerWithCache(budgeted); |
| 21 | } |
| 22 | |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 23 | GrMtlTextureRenderTarget::GrMtlTextureRenderTarget(GrMtlGpu* gpu, |
| 24 | const GrSurfaceDesc& desc, |
| 25 | id<MTLTexture> renderTexture, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 26 | GrMipMapsStatus mipMapsStatus, |
| 27 | GrWrapCacheable cacheable) |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 28 | : GrSurface(gpu, desc) |
| 29 | , GrMtlTexture(gpu, desc, renderTexture, mipMapsStatus) |
| 30 | , GrMtlRenderTarget(gpu, desc, renderTexture) { |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 31 | this->registerWithCacheWrapped(cacheable); |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 34 | sk_sp<GrMtlTextureRenderTarget> |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 35 | GrMtlTextureRenderTarget::CreateNewTextureRenderTarget(GrMtlGpu* gpu, |
| 36 | SkBudgeted budgeted, |
| 37 | const GrSurfaceDesc& desc, |
Timothy Liang | 58f153d | 2018-07-02 17:36:20 -0400 | [diff] [blame] | 38 | MTLTextureDescriptor* texDesc, |
| 39 | GrMipMapsStatus mipMapsStatus) { |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 40 | id<MTLTexture> renderTexture = [gpu->device() newTextureWithDescriptor:texDesc]; |
| 41 | SkASSERT(nil != renderTexture); |
| 42 | if (desc.fSampleCnt > 1) { |
| 43 | return nullptr; |
| 44 | } |
| 45 | SkASSERT((MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget) & renderTexture.usage); |
| 46 | return sk_sp<GrMtlTextureRenderTarget>( |
| 47 | new GrMtlTextureRenderTarget(gpu, budgeted, desc, renderTexture, mipMapsStatus)); |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 48 | } |
| 49 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 50 | sk_sp<GrMtlTextureRenderTarget> GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget( |
| 51 | GrMtlGpu* gpu, |
| 52 | const GrSurfaceDesc& desc, |
| 53 | id<MTLTexture> renderTexture, |
| 54 | GrWrapCacheable cacheable) { |
| 55 | SkASSERT(nil != renderTexture); |
| 56 | GrMipMapsStatus mipMapsStatus = renderTexture.mipmapLevelCount > 1 |
| 57 | ? GrMipMapsStatus::kDirty |
| 58 | : GrMipMapsStatus::kNotAllocated; |
| 59 | if (desc.fSampleCnt > 1) { |
| 60 | return nullptr; |
| 61 | } |
| 62 | SkASSERT((MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget) & renderTexture.usage); |
| 63 | return sk_sp<GrMtlTextureRenderTarget>( |
| 64 | new GrMtlTextureRenderTarget(gpu, desc, renderTexture, mipMapsStatus, cacheable)); |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 65 | } |