Flutter Engine
The Flutter Engine
GrMtlRenderTarget.h
Go to the documentation of this file.
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
12
17
18#import <Metal/Metal.h>
19
20class GrMtlGpu;
21
23public:
24 // If sampleCnt is greater than 1 and the texture is single sampled, then a MSAA texture
25 // is created that will resolve to the wrapped single sample texture.
27 SkISize,
28 int sampleCnt,
29 id<MTLTexture>);
30
31 ~GrMtlRenderTarget() override;
32
33 bool canAttemptStencilAttachment(bool useMSAASurface) const override {
34 SkASSERT(useMSAASurface == (this->numSamples() > 1));
35 return true;
36 }
37
39 id<MTLTexture> colorMTLTexture() const { return fColorAttachment->mtlTexture(); }
41 id<MTLTexture> resolveMTLTexture() const { return fResolveAttachment->mtlTexture(); }
42
43 // Returns the GrMtlAttachment of the non-msaa attachment. If the color attachment has 1 sample,
44 // then the color attachment will be returned. Otherwise, the resolve attachment is returned.
46 if (fColorAttachment->numSamples() == 1) {
47 return fColorAttachment.get();
48 } else {
49 return fResolveAttachment.get();
50 }
51 }
52
54
55 GrBackendFormat backendFormat() const override;
56
57 const GrMtlFramebuffer* getFramebuffer(bool withResolve,
58 bool withStencil);
59
60protected:
62 SkISize,
65 std::string_view label);
66
67 GrMtlGpu* getMtlGpu() const;
68
69 void onAbandon() override;
70 void onRelease() override;
71
72 // This returns zero since the memory should all be handled by the attachments
73 size_t onGpuMemorySize() const override { return 0; }
74
75 void onSetLabel() override;
76
79
80private:
81 // Extra param to disambiguate from constructor used by subclasses.
82 enum Wrapped { kWrapped };
84 SkISize,
87 Wrapped,
88 std::string_view label);
89
90 bool completeStencilAttachment(GrAttachment* stencil, bool useMSAASurface) override;
91
92 // We can have a renderpass with and without resolve attachment or stencil attachment,
93 // both of these being completely orthogonal. Thus we have a total of 4 types of render passes.
94 // We then cache a framebuffer for each type of these render passes.
95 // TODO: add support for other flags if needed
96 inline static constexpr int kNumCachedFramebuffers = 4;
97
98 sk_sp<const GrMtlFramebuffer> fCachedFramebuffers[kNumCachedFramebuffers];
99
100
101 using INHERITED = GrRenderTarget;
102};
103
104
105#endif
106
#define SkASSERT(cond)
Definition: SkAssert.h:116
int numSamples() const
Definition: GrAttachment.h:38
id< MTLTexture > mtlTexture() const
~GrMtlRenderTarget() override
GrMtlAttachment * colorAttachment() const
GrMtlAttachment * nonMSAAAttachment() const
GrMtlGpu * getMtlGpu() const
id< MTLTexture > colorMTLTexture() const
void onSetLabel() override
size_t onGpuMemorySize() const override
bool canAttemptStencilAttachment(bool useMSAASurface) const override
static sk_sp< GrMtlRenderTarget > MakeWrappedRenderTarget(GrMtlGpu *, SkISize, int sampleCnt, id< MTLTexture >)
sk_sp< GrMtlAttachment > fColorAttachment
id< MTLTexture > resolveMTLTexture() const
sk_sp< GrMtlAttachment > fResolveAttachment
const GrMtlFramebuffer * getFramebuffer(bool withResolve, bool withStencil)
GrBackendFormat backendFormat() const override
GrBackendRenderTarget getBackendRenderTarget() const override
void onAbandon() override
GrMtlAttachment * resolveAttachment() const
GrMtlRenderTarget(GrMtlGpu *gpu, SkISize, sk_sp< GrMtlAttachment > colorAttachment, sk_sp< GrMtlAttachment > resolveAttachment, std::string_view label)
void onRelease() override
int numSamples() const
GrRenderTarget(GrGpu *, const SkISize &, int sampleCount, GrProtected, std::string_view label, sk_sp< GrAttachment > stenicl=nullptr)
T * get() const
Definition: SkRefCnt.h:303
Definition: SkSize.h:16