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>); |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 25 | |
| 26 | protected: |
| 27 | void onAbandon() override { |
| 28 | GrMtlRenderTarget::onAbandon(); |
| 29 | GrMtlTexture::onAbandon(); |
| 30 | } |
| 31 | |
| 32 | void onRelease() override { |
| 33 | GrMtlRenderTarget::onRelease(); |
| 34 | GrMtlTexture::onRelease(); |
| 35 | } |
| 36 | |
| 37 | private: |
| 38 | GrMtlTextureRenderTarget(GrMtlGpu* gpu, |
| 39 | SkBudgeted budgeted, |
| 40 | const GrSurfaceDesc& desc, |
| 41 | id<MTLTexture> renderTexture, |
| 42 | id<MTLTexture> resolveTexture, |
| 43 | GrMipMapsStatus); |
| 44 | |
| 45 | GrMtlTextureRenderTarget(GrMtlGpu* gpu, |
| 46 | SkBudgeted budgeted, |
| 47 | const GrSurfaceDesc& desc, |
| 48 | id<MTLTexture> renderTexture, |
| 49 | GrMipMapsStatus); |
| 50 | |
| 51 | GrMtlTextureRenderTarget(GrMtlGpu* gpu, |
| 52 | const GrSurfaceDesc& desc, |
| 53 | id<MTLTexture> renderTexture, |
| 54 | id<MTLTexture> resolveTexture, |
| 55 | GrMipMapsStatus); |
| 56 | |
| 57 | GrMtlTextureRenderTarget(GrMtlGpu* gpu, |
| 58 | const GrSurfaceDesc& desc, |
| 59 | id<MTLTexture> renderTexture, |
| 60 | GrMipMapsStatus); |
| 61 | |
| 62 | static sk_sp<GrMtlTextureRenderTarget> Make(GrMtlGpu*, |
| 63 | const GrSurfaceDesc&, |
| 64 | id<MTLTexture> resolveTexture, |
Timothy Liang | 58f153d | 2018-07-02 17:36:20 -0400 | [diff] [blame] | 65 | GrMipMapsStatus, |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 66 | SkBudgeted budgeted, |
| 67 | bool isWrapped); |
| 68 | |
| 69 | size_t onGpuMemorySize() const override { |
| 70 | // TODO: When used as render targets certain formats may actually have a larger size than |
| 71 | // the base format size. Check to make sure we are reporting the correct value here. |
| 72 | // The plus 1 is to account for the resolve texture or if not using msaa the RT itself |
| 73 | int numColorSamples = this->numColorSamples(); |
| 74 | if (numColorSamples > 1) { |
| 75 | ++numColorSamples; |
| 76 | } |
| 77 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
| 78 | numColorSamples, GrMipMapped::kNo, false); |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | #endif |