• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/gpu/GrRenderTarget.h"
12 
13 #include "include/gpu/GrBackendSurface.h"
14 
15 #import <Metal/Metal.h>
16 
17 class GrMtlGpu;
18 
19 class GrMtlRenderTarget: public GrRenderTarget {
20 public:
21     static sk_sp<GrMtlRenderTarget> MakeWrappedRenderTarget(GrMtlGpu*,
22                                                             const GrSurfaceDesc&,
23                                                             int sampleCnt,
24                                                             id<MTLTexture>);
25 
26     ~GrMtlRenderTarget() override;
27 
28     // override of GrRenderTarget
getResolveType()29     ResolveType getResolveType() const override {
30         if (this->numSamples() > 1) {
31             return kCanResolve_ResolveType;
32         }
33         return kAutoResolves_ResolveType;
34     }
35 
canAttemptStencilAttachment()36     bool canAttemptStencilAttachment() const override {
37         return true;
38     }
39 
mtlColorTexture()40     id<MTLTexture> mtlColorTexture() const { return fColorTexture; }
mtlResolveTexture()41     id<MTLTexture> mtlResolveTexture() const { return fResolveTexture; }
42 
43     GrBackendRenderTarget getBackendRenderTarget() const override;
44 
45     GrBackendFormat backendFormat() const override;
46 
47 protected:
48     GrMtlRenderTarget(GrMtlGpu* gpu,
49                       const GrSurfaceDesc& desc,
50                       int sampleCnt,
51                       id<MTLTexture> colorTexture,
52                       id<MTLTexture> resolveTexture);
53 
54     GrMtlRenderTarget(GrMtlGpu* gpu,
55                       const GrSurfaceDesc& desc,
56                       id<MTLTexture> colorTexture);
57 
58     GrMtlGpu* getMtlGpu() const;
59 
60     void onAbandon() override;
61     void onRelease() override;
62 
63     // This accounts for the texture's memory and any MSAA renderbuffer's memory.
onGpuMemorySize()64     size_t onGpuMemorySize() const override {
65         int numColorSamples = this->numSamples();
66         // TODO: When used as render targets certain formats may actually have a larger size than
67         // the base format size. Check to make sure we are reporting the correct value here.
68         // The plus 1 is to account for the resolve texture or if not using msaa the RT itself
69         if (numColorSamples > 1) {
70             ++numColorSamples;
71         }
72         return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
73                                       numColorSamples, GrMipMapped::kNo);
74     }
75 
76     id<MTLTexture> fColorTexture;
77     id<MTLTexture> fResolveTexture;
78 
79 private:
80     // Extra param to disambiguate from constructor used by subclasses.
81     enum Wrapped { kWrapped };
82     GrMtlRenderTarget(GrMtlGpu* gpu,
83                       const GrSurfaceDesc& desc,
84                       int sampleCnt,
85                       id<MTLTexture> colorTexture,
86                       id<MTLTexture> resolveTexture,
87                       Wrapped);
88     GrMtlRenderTarget(GrMtlGpu* gpu,
89                       const GrSurfaceDesc& desc,
90                       id<MTLTexture> colorTexture,
91                       Wrapped);
92 
93     bool completeStencilAttachment() override;
94 
95     typedef GrRenderTarget INHERITED;
96 };
97 
98 
99 #endif
100 
101