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