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: |
| 21 | static sk_sp<GrMtlRenderTarget> CreateNewRenderTarget(GrMtlGpu*, const GrSurfaceDesc&, |
| 22 | SkBudgeted); |
| 23 | |
| 24 | static sk_sp<GrMtlRenderTarget> MakeWrappedRenderTarget(GrMtlGpu*, const GrSurfaceDesc&); |
| 25 | |
| 26 | ~GrMtlRenderTarget() override; |
| 27 | |
| 28 | // override of GrRenderTarget |
| 29 | ResolveType getResolveType() const override { |
| 30 | return kCantResolve_ResolveType; |
| 31 | #if 0 // TODO figure this once we support msaa |
| 32 | if (this->numColorSamples() > 1) { |
| 33 | return kCanResolve_ResolveType; |
| 34 | } |
| 35 | return kAutoResolves_ResolveType; |
| 36 | #endif |
| 37 | } |
| 38 | |
| 39 | bool canAttemptStencilAttachment() const override { |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | GrBackendObject getRenderTargetHandle() const override; |
| 44 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame^] | 45 | GrBackendRenderTarget getBackendRenderTarget() const override { |
| 46 | return GrBackendRenderTarget(); // invalid |
| 47 | } |
| 48 | |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 49 | protected: |
| 50 | GrMtlRenderTarget(GrMtlGpu* gpu, |
| 51 | const GrSurfaceDesc& desc, |
| 52 | id<MTLTexture> renderTexture, |
| 53 | id<MTLTexture> resolveTexture); |
| 54 | |
| 55 | GrMtlRenderTarget(GrMtlGpu* gpu, |
| 56 | const GrSurfaceDesc& desc, |
| 57 | id<MTLTexture> renderTexture); |
| 58 | |
| 59 | GrMtlGpu* getMtlGpu() const; |
| 60 | |
| 61 | void onAbandon() override; |
| 62 | void onRelease() override; |
| 63 | |
| 64 | // This accounts for the texture's memory and any MSAA renderbuffer's memory. |
| 65 | size_t onGpuMemorySize() const override { |
| 66 | // The plus 1 is to account for the resolve texture or if not using msaa the RT itself |
| 67 | int numColorSamples = this->numColorSamples() + 1; |
| 68 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 69 | numColorSamples, GrMipMapped::kNo); |
Greg Daniel | 51fd6d8 | 2017-08-18 09:34:40 -0400 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | id<MTLTexture> fRenderTexture; |
| 73 | id<MTLTexture> fResolveTexture; |
| 74 | |
| 75 | private: |
| 76 | GrMtlRenderTarget(GrMtlGpu* gpu, |
| 77 | const GrSurfaceDesc& desc, |
| 78 | SkBudgeted, |
| 79 | id<MTLTexture> renderTexture, |
| 80 | id<MTLTexture> resolveTexture); |
| 81 | |
| 82 | GrMtlRenderTarget(GrMtlGpu* gpu, |
| 83 | const GrSurfaceDesc& desc, |
| 84 | SkBudgeted, |
| 85 | id<MTLTexture> renderTexture); |
| 86 | |
| 87 | static sk_sp<GrMtlRenderTarget> Make(GrMtlGpu*, |
| 88 | const GrSurfaceDesc&, |
| 89 | SkBudgeted, |
| 90 | id<MTLTexture> renderTexture, |
| 91 | bool isWrapped); |
| 92 | |
| 93 | bool completeStencilAttachment() override; |
| 94 | }; |
| 95 | |
| 96 | |
| 97 | #endif |
| 98 | |