• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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*,
20                                               SkBudgeted budgeted,
21                                               SkISize,
22                                               MTLTextureDescriptor*,
23                                               GrMipMapsStatus);
24 
25     static sk_sp<GrMtlTexture> MakeWrappedTexture(GrMtlGpu*,
26                                                   SkISize,
27                                                   id<MTLTexture>,
28                                                   GrWrapCacheable,
29                                                   GrIOType);
30 
31     ~GrMtlTexture() override;
32 
mtlTexture()33     id<MTLTexture> mtlTexture() const { return fTexture; }
34 
35     GrBackendTexture getBackendTexture() const override;
36 
37     GrBackendFormat backendFormat() const override;
38 
textureParamsModified()39     void textureParamsModified() override {}
40 
41     bool reallocForMipmap(GrMtlGpu* gpu, uint32_t mipLevels);
42 
43 protected:
44     GrMtlTexture(GrMtlGpu*, SkISize, id<MTLTexture>, GrMipMapsStatus);
45 
46     GrMtlGpu* getMtlGpu() const;
47 
onAbandon()48     void onAbandon() override {
49         fTexture = nil;
50         INHERITED::onAbandon();
51     }
onRelease()52     void onRelease() override {
53         fTexture = nil;
54         INHERITED::onRelease();
55     }
56 
onStealBackendTexture(GrBackendTexture *,SkImage::BackendTextureReleaseProc *)57      bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override {
58          return false;
59      }
60 
61 private:
62     enum Wrapped { kWrapped };
63 
64     GrMtlTexture(GrMtlGpu*, SkBudgeted, SkISize, id<MTLTexture>, GrMipMapsStatus);
65 
66     GrMtlTexture(GrMtlGpu*,
67                  Wrapped,
68                  SkISize,
69                  id<MTLTexture>,
70                  GrMipMapsStatus,
71                  GrWrapCacheable,
72                  GrIOType);
73 
74     id<MTLTexture> fTexture;
75 
76     typedef GrTexture INHERITED;
77 };
78 
79 #endif
80