1 /* 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 #ifndef GrMtlTexture_DEFINED 9 #define GrMtlTexture_DEFINED 10 11 #include "include/gpu/GrTexture.h" 12 13 #import <Metal/Metal.h> 14 15 class GrMtlGpu; 16 17 class GrMtlTexture : public GrTexture { 18 public: 19 static sk_sp<GrMtlTexture> MakeNewTexture(GrMtlGpu*, SkBudgeted budgeted, 20 const GrSurfaceDesc&, 21 MTLTextureDescriptor*, 22 GrMipMapsStatus); 23 24 static sk_sp<GrMtlTexture> MakeWrappedTexture(GrMtlGpu*, const GrSurfaceDesc&, id<MTLTexture>, 25 GrWrapCacheable, GrIOType); 26 27 ~GrMtlTexture() override; 28 mtlTexture()29 id<MTLTexture> mtlTexture() const { return fTexture; } 30 31 GrBackendTexture getBackendTexture() const override; 32 33 GrBackendFormat backendFormat() const override; 34 textureParamsModified()35 void textureParamsModified() override {} 36 37 bool reallocForMipmap(GrMtlGpu* gpu, uint32_t mipLevels); 38 39 protected: 40 GrMtlTexture(GrMtlGpu*, const GrSurfaceDesc&, id<MTLTexture>, GrMipMapsStatus); 41 42 GrMtlGpu* getMtlGpu() const; 43 onAbandon()44 void onAbandon() override { 45 fTexture = nil; 46 INHERITED::onAbandon(); 47 } onRelease()48 void onRelease() override { 49 fTexture = nil; 50 INHERITED::onRelease(); 51 } 52 onStealBackendTexture(GrBackendTexture *,SkImage::BackendTextureReleaseProc *)53 bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override { 54 return false; 55 } 56 57 private: 58 enum Wrapped { kWrapped }; 59 60 GrMtlTexture(GrMtlGpu*, SkBudgeted, const GrSurfaceDesc&, id<MTLTexture>, 61 GrMipMapsStatus); 62 63 GrMtlTexture(GrMtlGpu*, Wrapped, const GrSurfaceDesc&, id<MTLTexture>, GrMipMapsStatus, 64 GrWrapCacheable, GrIOType); 65 66 id<MTLTexture> fTexture; 67 68 typedef GrTexture INHERITED; 69 }; 70 71 #endif 72