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