Greg Daniel | 4a081e2 | 2017-08-04 09:34:44 -0400 | [diff] [blame] | 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 "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> CreateNewTexture(GrMtlGpu*, SkBudgeted budgeted, |
Timothy Liang | 58f153d | 2018-07-02 17:36:20 -0400 | [diff] [blame] | 20 | const GrSurfaceDesc&, |
| 21 | MTLTextureDescriptor*, |
| 22 | GrMipMapsStatus); |
Greg Daniel | 4a081e2 | 2017-08-04 09:34:44 -0400 | [diff] [blame] | 23 | |
| 24 | static sk_sp<GrMtlTexture> MakeWrappedTexture(GrMtlGpu*, const GrSurfaceDesc&, |
Greg Daniel | 2268ad2 | 2018-11-15 09:27:38 -0500 | [diff] [blame^] | 25 | id<MTLTexture>, bool purgeImmediately); |
Greg Daniel | 4a081e2 | 2017-08-04 09:34:44 -0400 | [diff] [blame] | 26 | |
| 27 | ~GrMtlTexture() override; |
| 28 | |
| 29 | id<MTLTexture> mtlTexture() const { return fTexture; } |
| 30 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 31 | GrBackendTexture getBackendTexture() const override; |
Greg Daniel | 4a081e2 | 2017-08-04 09:34:44 -0400 | [diff] [blame] | 32 | |
| 33 | void textureParamsModified() override {} |
| 34 | |
| 35 | bool reallocForMipmap(GrMtlGpu* gpu, uint32_t mipLevels); |
| 36 | |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 37 | void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override { |
Greg Daniel | 4a081e2 | 2017-08-04 09:34:44 -0400 | [diff] [blame] | 38 | // Since all MTLResources are inherently ref counted, we can call the Release proc when we |
| 39 | // delete the GrMtlTexture without worry of the MTLTexture getting deleted before it is done |
| 40 | // on the GPU. |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 41 | fReleaseHelper = std::move(releaseHelper); |
Greg Daniel | 4a081e2 | 2017-08-04 09:34:44 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | protected: |
Timothy Liang | 2df9b45 | 2018-06-27 14:58:12 -0400 | [diff] [blame] | 45 | GrMtlTexture(GrMtlGpu*, const GrSurfaceDesc&, id<MTLTexture>, GrMipMapsStatus); |
Greg Daniel | 4a081e2 | 2017-08-04 09:34:44 -0400 | [diff] [blame] | 46 | |
| 47 | GrMtlGpu* getMtlGpu() const; |
| 48 | |
| 49 | void onAbandon() override { |
| 50 | fTexture = nil; |
| 51 | } |
| 52 | void onRelease() override { |
| 53 | fTexture = nil; |
| 54 | } |
| 55 | |
Brian Salomon | 3727136 | 2017-10-13 12:52:17 -0400 | [diff] [blame] | 56 | bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override { |
| 57 | return false; |
| 58 | } |
| 59 | |
Greg Daniel | 4a081e2 | 2017-08-04 09:34:44 -0400 | [diff] [blame] | 60 | private: |
| 61 | enum Wrapped { kWrapped }; |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 62 | GrMtlTexture(GrMtlGpu*, SkBudgeted, const GrSurfaceDesc&, id<MTLTexture>, |
| 63 | GrMipMapsStatus); |
| 64 | |
Greg Daniel | 2268ad2 | 2018-11-15 09:27:38 -0500 | [diff] [blame^] | 65 | GrMtlTexture(GrMtlGpu*, Wrapped, const GrSurfaceDesc&, id<MTLTexture>, GrMipMapsStatus, |
| 66 | bool purgeImmediately); |
Greg Daniel | 4a081e2 | 2017-08-04 09:34:44 -0400 | [diff] [blame] | 67 | |
| 68 | id<MTLTexture> fTexture; |
| 69 | |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 70 | sk_sp<GrReleaseProcHelper> fReleaseHelper; |
Greg Daniel | 4a081e2 | 2017-08-04 09:34:44 -0400 | [diff] [blame] | 71 | |
| 72 | typedef GrTexture INHERITED; |
| 73 | }; |
| 74 | |
| 75 | #endif |