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