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, |
| 26 | GrMipMapsStatus mipMapsStatus) |
| 27 | : GrSurface(gpu, desc) |
| 28 | , GrMtlTexture(gpu, desc, renderTexture, mipMapsStatus) |
| 29 | , GrMtlRenderTarget(gpu, desc, renderTexture) { |
| 30 | this->registerWithCacheWrapped(); |
| 31 | } |
| 32 | |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 33 | sk_sp<GrMtlTextureRenderTarget> |
| 34 | GrMtlTextureRenderTarget::Make(GrMtlGpu* gpu, |
| 35 | const GrSurfaceDesc& desc, |
| 36 | id<MTLTexture> renderTexture, |
Timothy Liang | 58f153d | 2018-07-02 17:36:20 -0400 | [diff] [blame] | 37 | GrMipMapsStatus mipMapsStatus, |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 38 | SkBudgeted budgeted, |
| 39 | bool isWrapped) { |
| 40 | SkASSERT(nil != renderTexture); |
| 41 | if (desc.fSampleCnt > 1) { |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 42 | return nullptr; |
| 43 | } |
Timothy Liang | 58f153d | 2018-07-02 17:36:20 -0400 | [diff] [blame] | 44 | SkASSERT((MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget) & renderTexture.usage); |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 45 | if (!isWrapped) { |
| 46 | return sk_sp<GrMtlTextureRenderTarget>(new GrMtlTextureRenderTarget(gpu, |
| 47 | budgeted, |
| 48 | desc, |
| 49 | renderTexture, |
| 50 | mipMapsStatus)); |
| 51 | } else { |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 52 | return sk_sp<GrMtlTextureRenderTarget>(new GrMtlTextureRenderTarget(gpu, |
| 53 | desc, |
| 54 | renderTexture, |
| 55 | mipMapsStatus)); |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
| 59 | |
| 60 | sk_sp<GrMtlTextureRenderTarget> |
| 61 | GrMtlTextureRenderTarget::CreateNewTextureRenderTarget(GrMtlGpu* gpu, |
| 62 | SkBudgeted budgeted, |
| 63 | const GrSurfaceDesc& desc, |
Timothy Liang | 58f153d | 2018-07-02 17:36:20 -0400 | [diff] [blame] | 64 | MTLTextureDescriptor* texDesc, |
| 65 | GrMipMapsStatus mipMapsStatus) { |
| 66 | id<MTLTexture> texture = [gpu->device() newTextureWithDescriptor:texDesc]; |
| 67 | return Make(gpu, desc, texture, mipMapsStatus, budgeted, false); |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | sk_sp<GrMtlTextureRenderTarget> |
| 71 | GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(GrMtlGpu* gpu, |
| 72 | const GrSurfaceDesc& desc, |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 73 | id<MTLTexture> texture) { |
| 74 | |
| 75 | SkASSERT(nil != texture); |
Timothy Liang | 58f153d | 2018-07-02 17:36:20 -0400 | [diff] [blame] | 76 | GrMipMapsStatus mipMapsStatus = texture.mipmapLevelCount > 1 ? GrMipMapsStatus::kDirty |
| 77 | : GrMipMapsStatus::kNotAllocated; |
| 78 | return Make(gpu, desc, texture, mipMapsStatus, SkBudgeted::kNo, true); |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 79 | } |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 80 | |