blob: 62fd2abf1247413a53e5d399c85ff50038523784 [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#include "GrMtlTextureRenderTarget.h"
9#include "GrMtlGpu.h"
10#include "GrMtlUtil.h"
11
12GrMtlTextureRenderTarget::GrMtlTextureRenderTarget(GrMtlGpu* gpu,
13 SkBudgeted budgeted,
14 const GrSurfaceDesc& desc,
15 id<MTLTexture> renderTexture,
16 GrMipMapsStatus mipMapsStatus)
17 : GrSurface(gpu, desc)
18 , GrMtlTexture(gpu, desc, renderTexture, mipMapsStatus)
19 , GrMtlRenderTarget(gpu, desc, renderTexture) {
20 this->registerWithCache(budgeted);
21}
22
Timothy Liange886e802018-07-02 16:03:28 -040023GrMtlTextureRenderTarget::GrMtlTextureRenderTarget(GrMtlGpu* gpu,
24 const GrSurfaceDesc& desc,
25 id<MTLTexture> renderTexture,
26 GrMipMapsStatus mipMapsStatus)
27 : GrSurface(gpu, desc)
28 , GrMtlTexture(gpu, desc, renderTexture, mipMapsStatus)
29 , GrMtlRenderTarget(gpu, desc, renderTexture) {
30 this->registerWithCacheWrapped();
31}
32
Timothy Liang2df9b452018-06-27 14:58:12 -040033sk_sp<GrMtlTextureRenderTarget>
34GrMtlTextureRenderTarget::Make(GrMtlGpu* gpu,
35 const GrSurfaceDesc& desc,
36 id<MTLTexture> renderTexture,
Timothy Liang58f153d2018-07-02 17:36:20 -040037 GrMipMapsStatus mipMapsStatus,
Timothy Liang2df9b452018-06-27 14:58:12 -040038 SkBudgeted budgeted,
39 bool isWrapped) {
40 SkASSERT(nil != renderTexture);
41 if (desc.fSampleCnt > 1) {
Timothy Liang2df9b452018-06-27 14:58:12 -040042 return nullptr;
43 }
Timothy Liang58f153d2018-07-02 17:36:20 -040044 SkASSERT((MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget) & renderTexture.usage);
Timothy Liang2df9b452018-06-27 14:58:12 -040045 if (!isWrapped) {
46 return sk_sp<GrMtlTextureRenderTarget>(new GrMtlTextureRenderTarget(gpu,
47 budgeted,
48 desc,
49 renderTexture,
50 mipMapsStatus));
51 } else {
Timothy Liange886e802018-07-02 16:03:28 -040052 return sk_sp<GrMtlTextureRenderTarget>(new GrMtlTextureRenderTarget(gpu,
53 desc,
54 renderTexture,
55 mipMapsStatus));
Timothy Liang2df9b452018-06-27 14:58:12 -040056 }
57}
58
59
60sk_sp<GrMtlTextureRenderTarget>
61GrMtlTextureRenderTarget::CreateNewTextureRenderTarget(GrMtlGpu* gpu,
62 SkBudgeted budgeted,
63 const GrSurfaceDesc& desc,
Timothy Liang58f153d2018-07-02 17:36:20 -040064 MTLTextureDescriptor* texDesc,
65 GrMipMapsStatus mipMapsStatus) {
66 id<MTLTexture> texture = [gpu->device() newTextureWithDescriptor:texDesc];
67 return Make(gpu, desc, texture, mipMapsStatus, budgeted, false);
Timothy Liang2df9b452018-06-27 14:58:12 -040068}
69
70sk_sp<GrMtlTextureRenderTarget>
71GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(GrMtlGpu* gpu,
72 const GrSurfaceDesc& desc,
Timothy Liange886e802018-07-02 16:03:28 -040073 id<MTLTexture> texture) {
74
75 SkASSERT(nil != texture);
Timothy Liang58f153d2018-07-02 17:36:20 -040076 GrMipMapsStatus mipMapsStatus = texture.mipmapLevelCount > 1 ? GrMipMapsStatus::kDirty
77 : GrMipMapsStatus::kNotAllocated;
78 return Make(gpu, desc, texture, mipMapsStatus, SkBudgeted::kNo, true);
Timothy Liang2df9b452018-06-27 14:58:12 -040079}
Timothy Liange886e802018-07-02 16:03:28 -040080