Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 GrMtlRenderTarget_DEFINED |
| 9 | #define GrMtlRenderTarget_DEFINED |
| 10 | |
| 11 | #include "GrRenderTarget.h" |
| 12 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 13 | #include "GrBackendSurface.h" |
| 14 | |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 15 | #import <Metal/Metal.h> |
| 16 | |
| 17 | class GrMtlGpu; |
| 18 | |
| 19 | class GrMtlRenderTarget: public GrRenderTarget { |
| 20 | public: |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 21 | static sk_sp<GrMtlRenderTarget> MakeWrappedRenderTarget(GrMtlGpu*, |
| 22 | const GrSurfaceDesc&, |
| 23 | id<MTLTexture>); |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 24 | |
| 25 | ~GrMtlRenderTarget() override; |
| 26 | |
| 27 | // override of GrRenderTarget |
| 28 | ResolveType getResolveType() const override { |
| 29 | return kCantResolve_ResolveType; |
| 30 | #if 0 // TODO figure this once we support msaa |
| 31 | if (this->numColorSamples() > 1) { |
| 32 | return kCanResolve_ResolveType; |
| 33 | } |
| 34 | return kAutoResolves_ResolveType; |
| 35 | #endif |
| 36 | } |
| 37 | |
| 38 | bool canAttemptStencilAttachment() const override { |
| 39 | return true; |
| 40 | } |
| 41 | |
Timothy Liang | ef21d7e | 2018-07-02 17:03:30 -0400 | [diff] [blame] | 42 | id<MTLTexture> mtlRenderTexture() const { return fRenderTexture; } |
| 43 | |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 44 | GrBackendRenderTarget getBackendRenderTarget() const override; |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 45 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 46 | GrBackendFormat backendFormat() const override; |
| 47 | |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 48 | protected: |
| 49 | GrMtlRenderTarget(GrMtlGpu* gpu, |
| 50 | const GrSurfaceDesc& desc, |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 51 | id<MTLTexture> renderTexture); |
| 52 | |
| 53 | GrMtlGpu* getMtlGpu() const; |
| 54 | |
| 55 | void onAbandon() override; |
| 56 | void onRelease() override; |
| 57 | |
| 58 | // This accounts for the texture's memory and any MSAA renderbuffer's memory. |
| 59 | size_t onGpuMemorySize() const override { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 60 | int numColorSamples = this->numColorSamples(); |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 61 | // TODO: When used as render targets certain formats may actually have a larger size than |
| 62 | // the base format size. Check to make sure we are reporting the correct value here. |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 63 | // The plus 1 is to account for the resolve texture or if not using msaa the RT itself |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 64 | if (numColorSamples > 1) { |
| 65 | ++numColorSamples; |
| 66 | } |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 67 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 68 | numColorSamples, GrMipMapped::kNo); |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | id<MTLTexture> fRenderTexture; |
| 72 | id<MTLTexture> fResolveTexture; |
| 73 | |
| 74 | private: |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 75 | // Extra param to disambiguate from constructor used by subclasses. |
| 76 | enum Wrapped { kWrapped }; |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 77 | GrMtlRenderTarget(GrMtlGpu* gpu, |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 78 | const GrSurfaceDesc& desc, |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 79 | id<MTLTexture> renderTexture, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 80 | Wrapped); |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 81 | |
| 82 | bool completeStencilAttachment() override; |
Greg Daniel | 2d35a1c | 2019-02-01 14:48:10 -0500 | [diff] [blame] | 83 | |
Greg Daniel | c91162d | 2019-02-05 09:40:21 -0500 | [diff] [blame] | 84 | typedef GrRenderTarget INHERITED; |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | |
| 88 | #endif |
| 89 | |