1 /* 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 GrMtlAttachment_DEFINED 9 #define GrMtlAttachment_DEFINED 10 11 #include "include/gpu/mtl/GrMtlTypes.h" 12 #include "src/gpu/GrAttachment.h" 13 14 #import <Metal/Metal.h> 15 16 class GrMtlGpu; 17 18 class GrMtlAttachment : public GrAttachment { 19 public: 20 static sk_sp<GrMtlAttachment> MakeStencil(GrMtlGpu* gpu, 21 SkISize dimensions, 22 int sampleCnt, 23 MTLPixelFormat format); 24 25 static sk_sp<GrMtlAttachment> MakeMSAA(GrMtlGpu* gpu, 26 SkISize dimensions, 27 int sampleCnt, 28 MTLPixelFormat format); 29 30 static sk_sp<GrMtlAttachment> MakeTexture(GrMtlGpu* gpu, 31 SkISize dimensions, 32 MTLPixelFormat format, 33 uint32_t mipLevels, 34 GrRenderable renderable, 35 int numSamples, 36 SkBudgeted budgeted); 37 38 static sk_sp<GrMtlAttachment> MakeWrapped(GrMtlGpu* gpu, 39 SkISize dimensions, 40 id<MTLTexture>, 41 UsageFlags attachmentUsages, 42 GrWrapCacheable); 43 44 ~GrMtlAttachment() override; 45 backendFormat()46 GrBackendFormat backendFormat() const override { 47 return GrBackendFormat::MakeMtl(fTexture.pixelFormat); 48 } 49 mtlFormat()50 MTLPixelFormat mtlFormat() const { return fTexture.pixelFormat; } 51 mtlTexture()52 id<MTLTexture> mtlTexture() const { return fTexture; } 53 sampleCount()54 unsigned int sampleCount() const { return fTexture.sampleCount; } 55 framebufferOnly()56 bool framebufferOnly() const { return fTexture.framebufferOnly; } 57 58 protected: 59 void onRelease() override; 60 void onAbandon() override; 61 62 private: 63 static sk_sp<GrMtlAttachment> Make(GrMtlGpu* gpu, 64 SkISize dimensions, 65 UsageFlags attachmentUsages, 66 int sampleCnt, 67 MTLPixelFormat format, 68 uint32_t mipLevels, 69 int mtlTextureUsage, 70 int mtlStorageMode, 71 SkBudgeted); 72 73 GrMtlAttachment(GrMtlGpu* gpu, 74 SkISize dimensions, 75 UsageFlags supportedUsages, 76 id<MTLTexture> texture, 77 SkBudgeted); 78 79 GrMtlAttachment(GrMtlGpu* gpu, 80 SkISize dimensions, 81 UsageFlags supportedUsages, 82 id<MTLTexture> texture, 83 GrWrapCacheable); 84 85 GrMtlGpu* getMtlGpu() const; 86 87 id<MTLTexture> fTexture; 88 }; 89 90 #endif 91