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