blob: 186f70379268463c55f882142826a8a59827636a [file] [log] [blame]
Greg Daniel51fd6d82017-08-18 09:34:40 -04001/*
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
13#import <Metal/Metal.h>
14
15class GrMtlGpu;
16
17class GrMtlRenderTarget: public GrRenderTarget {
18public:
19 static sk_sp<GrMtlRenderTarget> CreateNewRenderTarget(GrMtlGpu*, const GrSurfaceDesc&,
20 SkBudgeted);
21
22 static sk_sp<GrMtlRenderTarget> MakeWrappedRenderTarget(GrMtlGpu*, const GrSurfaceDesc&);
23
24 ~GrMtlRenderTarget() override;
25
26 // override of GrRenderTarget
27 ResolveType getResolveType() const override {
28 return kCantResolve_ResolveType;
29#if 0 // TODO figure this once we support msaa
30 if (this->numColorSamples() > 1) {
31 return kCanResolve_ResolveType;
32 }
33 return kAutoResolves_ResolveType;
34#endif
35 }
36
37 bool canAttemptStencilAttachment() const override {
38 return true;
39 }
40
41 GrBackendObject getRenderTargetHandle() const override;
42
43protected:
44 GrMtlRenderTarget(GrMtlGpu* gpu,
45 const GrSurfaceDesc& desc,
46 id<MTLTexture> renderTexture,
47 id<MTLTexture> resolveTexture);
48
49 GrMtlRenderTarget(GrMtlGpu* gpu,
50 const GrSurfaceDesc& desc,
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 {
60 // The plus 1 is to account for the resolve texture or if not using msaa the RT itself
61 int numColorSamples = this->numColorSamples() + 1;
62 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
Greg Daniele252f082017-10-23 16:05:23 -040063 numColorSamples, GrMipMapped::kNo);
Greg Daniel51fd6d82017-08-18 09:34:40 -040064 }
65
66 id<MTLTexture> fRenderTexture;
67 id<MTLTexture> fResolveTexture;
68
69private:
70 GrMtlRenderTarget(GrMtlGpu* gpu,
71 const GrSurfaceDesc& desc,
72 SkBudgeted,
73 id<MTLTexture> renderTexture,
74 id<MTLTexture> resolveTexture);
75
76 GrMtlRenderTarget(GrMtlGpu* gpu,
77 const GrSurfaceDesc& desc,
78 SkBudgeted,
79 id<MTLTexture> renderTexture);
80
81 static sk_sp<GrMtlRenderTarget> Make(GrMtlGpu*,
82 const GrSurfaceDesc&,
83 SkBudgeted,
84 id<MTLTexture> renderTexture,
85 bool isWrapped);
86
87 bool completeStencilAttachment() override;
88};
89
90
91#endif
92