blob: 412af7bf2ebe2b49bfdd36954195f9aa100a0d39 [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&,
Timothy Liange886e802018-07-02 16:03:28 -040024 id<MTLTexture>);
Greg Daniel4065d452018-11-16 15:43:41 -050025 GrBackendFormat backendFormat() const override {
26 return GrMtlTexture::backendFormat();
27 }
Timothy Liang2df9b452018-06-27 14:58:12 -040028
29protected:
30 void onAbandon() override {
31 GrMtlRenderTarget::onAbandon();
32 GrMtlTexture::onAbandon();
33 }
34
35 void onRelease() override {
36 GrMtlRenderTarget::onRelease();
37 GrMtlTexture::onRelease();
38 }
39
40private:
41 GrMtlTextureRenderTarget(GrMtlGpu* gpu,
42 SkBudgeted budgeted,
43 const GrSurfaceDesc& desc,
44 id<MTLTexture> renderTexture,
45 id<MTLTexture> resolveTexture,
46 GrMipMapsStatus);
47
48 GrMtlTextureRenderTarget(GrMtlGpu* gpu,
49 SkBudgeted budgeted,
50 const GrSurfaceDesc& desc,
51 id<MTLTexture> renderTexture,
52 GrMipMapsStatus);
53
54 GrMtlTextureRenderTarget(GrMtlGpu* gpu,
55 const GrSurfaceDesc& desc,
56 id<MTLTexture> renderTexture,
57 id<MTLTexture> resolveTexture,
58 GrMipMapsStatus);
59
60 GrMtlTextureRenderTarget(GrMtlGpu* gpu,
61 const GrSurfaceDesc& desc,
62 id<MTLTexture> renderTexture,
63 GrMipMapsStatus);
64
65 static sk_sp<GrMtlTextureRenderTarget> Make(GrMtlGpu*,
66 const GrSurfaceDesc&,
67 id<MTLTexture> resolveTexture,
Timothy Liang58f153d2018-07-02 17:36:20 -040068 GrMipMapsStatus,
Timothy Liang2df9b452018-06-27 14:58:12 -040069 SkBudgeted budgeted,
70 bool isWrapped);
71
72 size_t onGpuMemorySize() const override {
73 // TODO: When used as render targets certain formats may actually have a larger size than
74 // the base format size. Check to make sure we are reporting the correct value here.
75 // The plus 1 is to account for the resolve texture or if not using msaa the RT itself
76 int numColorSamples = this->numColorSamples();
77 if (numColorSamples > 1) {
78 ++numColorSamples;
79 }
80 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
81 numColorSamples, GrMipMapped::kNo, false);
82 }
83};
84
85#endif