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&, |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 24 | id<MTLTexture>); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame^] | 25 | GrBackendFormat backendFormat() const override { |
| 26 | return GrMtlTexture::backendFormat(); |
| 27 | } |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 28 | |
| 29 | protected: |
| 30 | void onAbandon() override { |
| 31 | GrMtlRenderTarget::onAbandon(); |
| 32 | GrMtlTexture::onAbandon(); |
| 33 | } |
| 34 | |
| 35 | void onRelease() override { |
| 36 | GrMtlRenderTarget::onRelease(); |
| 37 | GrMtlTexture::onRelease(); |
| 38 | } |
| 39 | |
| 40 | private: |
| 41 | GrMtlTextureRenderTarget(GrMtlGpu* gpu, |
| 42 | SkBudgeted budgeted, |
| 43 | const GrSurfaceDesc& desc, |
| 44 | id<MTLTexture> renderTexture, |
| 45 | id<MTLTexture> resolveTexture, |
| 46 | GrMipMapsStatus); |
| 47 | |
| 48 | GrMtlTextureRenderTarget(GrMtlGpu* gpu, |
| 49 | SkBudgeted budgeted, |
| 50 | const GrSurfaceDesc& desc, |
| 51 | id<MTLTexture> renderTexture, |
| 52 | GrMipMapsStatus); |
| 53 | |
| 54 | GrMtlTextureRenderTarget(GrMtlGpu* gpu, |
| 55 | const GrSurfaceDesc& desc, |
| 56 | id<MTLTexture> renderTexture, |
| 57 | id<MTLTexture> resolveTexture, |
| 58 | GrMipMapsStatus); |
| 59 | |
| 60 | GrMtlTextureRenderTarget(GrMtlGpu* gpu, |
| 61 | const GrSurfaceDesc& desc, |
| 62 | id<MTLTexture> renderTexture, |
| 63 | GrMipMapsStatus); |
| 64 | |
| 65 | static sk_sp<GrMtlTextureRenderTarget> Make(GrMtlGpu*, |
| 66 | const GrSurfaceDesc&, |
| 67 | id<MTLTexture> resolveTexture, |
Timothy Liang | 58f153d | 2018-07-02 17:36:20 -0400 | [diff] [blame] | 68 | GrMipMapsStatus, |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 69 | SkBudgeted budgeted, |
| 70 | bool isWrapped); |
| 71 | |
| 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->numColorSamples(); |
| 77 | if (numColorSamples > 1) { |
| 78 | ++numColorSamples; |
| 79 | } |
| 80 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
| 81 | numColorSamples, GrMipMapped::kNo, false); |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | #endif |