blob: 4e6cc83e5c348ab4ac7c7aebaf28318a2be7ba27 [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#include "GrMtlRenderTarget.h"
9
10#include "GrMtlGpu.h"
11#include "GrMtlUtil.h"
12
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050013// Called for wrapped non-texture render targets.
Timothy Liang2df9b452018-06-27 14:58:12 -040014GrMtlRenderTarget::GrMtlRenderTarget(GrMtlGpu* gpu,
Timothy Liange886e802018-07-02 16:03:28 -040015 const GrSurfaceDesc& desc,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050016 id<MTLTexture> renderTexture,
17 Wrapped)
Timothy Liang2df9b452018-06-27 14:58:12 -040018 : GrSurface(gpu, desc)
19 , GrRenderTarget(gpu, desc)
20 , fRenderTexture(renderTexture)
21 , fResolveTexture(nil) {
22 SkASSERT(1 == desc.fSampleCnt);
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050023 this->registerWithCacheWrapped(GrWrapCacheable::kNo);
Timothy Liang2df9b452018-06-27 14:58:12 -040024}
25
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050026// Called by subclass constructors.
Timothy Liang2df9b452018-06-27 14:58:12 -040027GrMtlRenderTarget::GrMtlRenderTarget(GrMtlGpu* gpu,
28 const GrSurfaceDesc& desc,
29 id<MTLTexture> renderTexture)
30 : GrSurface(gpu, desc)
31 , GrRenderTarget(gpu, desc)
32 , fRenderTexture(renderTexture)
33 , fResolveTexture(nil) {
34 SkASSERT(1 == desc.fSampleCnt);
35}
36
Timothy Liange886e802018-07-02 16:03:28 -040037sk_sp<GrMtlRenderTarget>
38GrMtlRenderTarget::MakeWrappedRenderTarget(GrMtlGpu* gpu, const GrSurfaceDesc& desc,
39 id<MTLTexture> renderTexture) {
40 SkASSERT(nil != renderTexture);
41 SkASSERT(1 == renderTexture.mipmapLevelCount);
42 SkASSERT(MTLTextureUsageRenderTarget & renderTexture.usage);
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050043 return sk_sp<GrMtlRenderTarget>(new GrMtlRenderTarget(gpu, desc, renderTexture, kWrapped));
Greg Daniel51fd6d82017-08-18 09:34:40 -040044}
45
Greg Daniel51fd6d82017-08-18 09:34:40 -040046GrMtlRenderTarget::~GrMtlRenderTarget() {
47 SkASSERT(nil == fRenderTexture);
48 SkASSERT(nil == fResolveTexture);
49}
50
Timothy Liange886e802018-07-02 16:03:28 -040051GrBackendRenderTarget GrMtlRenderTarget::getBackendRenderTarget() const {
52 GrMtlTextureInfo info;
53 info.fTexture = GrGetPtrFromId(fRenderTexture);
54 return GrBackendRenderTarget(this->width(), this->height(), fRenderTexture.sampleCount, info);
55}
56
Greg Daniel4065d452018-11-16 15:43:41 -050057GrBackendFormat GrMtlRenderTarget::backendFormat() const {
58 return GrBackendFormat::MakeMtl(fRenderTexture.pixelFormat);
59}
60
Greg Daniel51fd6d82017-08-18 09:34:40 -040061GrMtlGpu* GrMtlRenderTarget::getMtlGpu() const {
62 SkASSERT(!this->wasDestroyed());
63 return static_cast<GrMtlGpu*>(this->getGpu());
64}
65
Greg Daniel51fd6d82017-08-18 09:34:40 -040066void GrMtlRenderTarget::onAbandon() {
67 fRenderTexture = nil;
68 fResolveTexture = nil;
Greg Danielc91162d2019-02-05 09:40:21 -050069 INHERITED::onAbandon();
Greg Daniel51fd6d82017-08-18 09:34:40 -040070}
71
72void GrMtlRenderTarget::onRelease() {
73 fRenderTexture = nil;
74 fResolveTexture = nil;
Greg Danielc91162d2019-02-05 09:40:21 -050075 INHERITED::onRelease();
Greg Daniel51fd6d82017-08-18 09:34:40 -040076}
77
Timothy Liang2df9b452018-06-27 14:58:12 -040078bool GrMtlRenderTarget::completeStencilAttachment() {
Greg Daniel51fd6d82017-08-18 09:34:40 -040079 return true;
80}
81