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