blob: 50022aff4e0337d512b211cc1fcb448b6f081b69 [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
Robert Phillipsb67821d2017-12-13 15:00:45 -050013#include "GrBackendSurface.h"
14
Greg Daniel51fd6d82017-08-18 09:34:40 -040015#import <Metal/Metal.h>
16
17class GrMtlGpu;
18
19class GrMtlRenderTarget: public GrRenderTarget {
20public:
Timothy Liange886e802018-07-02 16:03:28 -040021 static sk_sp<GrMtlRenderTarget> MakeWrappedRenderTarget(GrMtlGpu*,
22 const GrSurfaceDesc&,
23 id<MTLTexture>);
Greg Daniel51fd6d82017-08-18 09:34:40 -040024
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 Liangef21d7e2018-07-02 17:03:30 -040042 id<MTLTexture> mtlRenderTexture() const { return fRenderTexture; }
43
Timothy Liange886e802018-07-02 16:03:28 -040044 GrBackendRenderTarget getBackendRenderTarget() const override;
Robert Phillipsb67821d2017-12-13 15:00:45 -050045
Greg Daniel4065d452018-11-16 15:43:41 -050046 GrBackendFormat backendFormat() const override;
47
Greg Daniel51fd6d82017-08-18 09:34:40 -040048protected:
49 GrMtlRenderTarget(GrMtlGpu* gpu,
50 const GrSurfaceDesc& desc,
Greg Daniel51fd6d82017-08-18 09:34:40 -040051 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 Salomonbdecacf2018-02-02 20:32:49 -050060 int numColorSamples = this->numColorSamples();
Timothy Liange886e802018-07-02 16:03:28 -040061 // 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 Daniel51fd6d82017-08-18 09:34:40 -040063 // The plus 1 is to account for the resolve texture or if not using msaa the RT itself
Brian Salomonbdecacf2018-02-02 20:32:49 -050064 if (numColorSamples > 1) {
65 ++numColorSamples;
66 }
Greg Daniel51fd6d82017-08-18 09:34:40 -040067 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
Greg Daniele252f082017-10-23 16:05:23 -040068 numColorSamples, GrMipMapped::kNo);
Greg Daniel51fd6d82017-08-18 09:34:40 -040069 }
70
71 id<MTLTexture> fRenderTexture;
72 id<MTLTexture> fResolveTexture;
73
74private:
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050075 // Extra param to disambiguate from constructor used by subclasses.
76 enum Wrapped { kWrapped };
Greg Daniel51fd6d82017-08-18 09:34:40 -040077 GrMtlRenderTarget(GrMtlGpu* gpu,
Timothy Liange886e802018-07-02 16:03:28 -040078 const GrSurfaceDesc& desc,
Greg Daniel51fd6d82017-08-18 09:34:40 -040079 id<MTLTexture> renderTexture,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050080 Wrapped);
Greg Daniel51fd6d82017-08-18 09:34:40 -040081
82 bool completeStencilAttachment() override;
Greg Daniel2d35a1c2019-02-01 14:48:10 -050083
Greg Danielc91162d2019-02-05 09:40:21 -050084 typedef GrRenderTarget INHERITED;
Greg Daniel51fd6d82017-08-18 09:34:40 -040085};
86
87
88#endif
89