blob: b15d2896c07f8590e3dad51a65fabf65d2723e5c [file] [log] [blame]
Timothy Liang2df9b452018-06-27 14:58:12 -04001/*
2 * Copyright 2018 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 GrMtlTextureRenderTarget_DEFINED
9#define GrMtlTextureRenderTarget_DEFINED
10
11#include "GrMtlRenderTarget.h"
12#include "GrMtlTexture.h"
13
14class GrMtlTextureRenderTarget: public GrMtlTexture, public GrMtlRenderTarget {
15public:
16 static sk_sp<GrMtlTextureRenderTarget> CreateNewTextureRenderTarget(GrMtlGpu*,
17 SkBudgeted,
18 const GrSurfaceDesc&,
Timothy Liang58f153d2018-07-02 17:36:20 -040019 MTLTextureDescriptor*,
20 GrMipMapsStatus);
Timothy Liang2df9b452018-06-27 14:58:12 -040021
22 static sk_sp<GrMtlTextureRenderTarget> MakeWrappedTextureRenderTarget(GrMtlGpu*,
23 const GrSurfaceDesc&,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050024 id<MTLTexture>,
25 GrWrapCacheable);
Greg Daniel4065d452018-11-16 15:43:41 -050026 GrBackendFormat backendFormat() const override {
27 return GrMtlTexture::backendFormat();
28 }
Timothy Liang2df9b452018-06-27 14:58:12 -040029
30protected:
31 void onAbandon() override {
32 GrMtlRenderTarget::onAbandon();
33 GrMtlTexture::onAbandon();
34 }
35
36 void onRelease() override {
37 GrMtlRenderTarget::onRelease();
38 GrMtlTexture::onRelease();
39 }
40
41private:
42 GrMtlTextureRenderTarget(GrMtlGpu* gpu,
43 SkBudgeted budgeted,
44 const GrSurfaceDesc& desc,
45 id<MTLTexture> renderTexture,
46 id<MTLTexture> resolveTexture,
47 GrMipMapsStatus);
48
49 GrMtlTextureRenderTarget(GrMtlGpu* gpu,
50 SkBudgeted budgeted,
51 const GrSurfaceDesc& desc,
52 id<MTLTexture> renderTexture,
53 GrMipMapsStatus);
54
55 GrMtlTextureRenderTarget(GrMtlGpu* gpu,
56 const GrSurfaceDesc& desc,
57 id<MTLTexture> renderTexture,
58 id<MTLTexture> resolveTexture,
59 GrMipMapsStatus);
60
61 GrMtlTextureRenderTarget(GrMtlGpu* gpu,
62 const GrSurfaceDesc& desc,
63 id<MTLTexture> renderTexture,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050064 GrMipMapsStatus,
65 GrWrapCacheable cacheable);
Timothy Liang2df9b452018-06-27 14:58:12 -040066
67 size_t onGpuMemorySize() const override {
68 // TODO: When used as render targets certain formats may actually have a larger size than
69 // the base format size. Check to make sure we are reporting the correct value here.
70 // The plus 1 is to account for the resolve texture or if not using msaa the RT itself
71 int numColorSamples = this->numColorSamples();
72 if (numColorSamples > 1) {
73 ++numColorSamples;
74 }
75 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
76 numColorSamples, GrMipMapped::kNo, false);
77 }
Greg Daniel2d35a1c2019-02-01 14:48:10 -050078
79 void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {}
Timothy Liang2df9b452018-06-27 14:58:12 -040080};
81
82#endif