Debian Codegraph @

src/gpu/graphite/mtl/MtlTextureInfo.mm

raw
1 /*
2 * Copyright 2024 Google LLC
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 #include "include/core/SkStream.h"
8 #include "include/core/SkString.h"
9 #include "include/gpu/graphite/mtl/MtlGraphiteTypes.h"
10 #include "src/gpu/graphite/TextureInfoPriv.h"
11 #include "src/gpu/graphite/mtl/MtlGraphiteUtils.h"
12 #include "src/gpu/mtl/MtlUtilsPriv.h"
13
14 #include <cstdint>
15
16 #import <Metal/Metal.h>
17
18 class SkStream;
19
20 namespace skgpu::graphite {
21
22 MtlTextureInfo::MtlTextureInfo(CFTypeRef texture) {
23 SkASSERT(texture);
24 id<MTLTexture> mtlTex = (id<MTLTexture>)texture;
25
26 fSampleCount = ToSampleCount(mtlTex.sampleCount);
27 fMipmapped = mtlTex.mipmapLevelCount > 1 ? Mipmapped::kYes : Mipmapped::kNo;
28
29 fFormat = mtlTex.pixelFormat;
30 fUsage = mtlTex.usage;
31 fStorageMode = mtlTex.storageMode;
32 fFramebufferOnly = mtlTex.framebufferOnly;
33 }
34
35 TextureFormat MtlTextureInfo::viewFormat() const {
36 return MTLPixelFormatToTextureFormat(fFormat);
37 }
38
39 SkString MtlTextureInfo::toBackendString() const {
40 return SkStringPrintf("usage=0x%04X,storageMode=%u,framebufferOnly=%d",
41 (uint32_t)fUsage,
42 (uint32_t)fStorageMode,
43 fFramebufferOnly);
44 }
45
46 bool MtlTextureInfo::isCompatible(const TextureInfo& that, bool requireExact) const {
47 const auto& mt = TextureInfoPriv::Get<MtlTextureInfo>(that);
48 // The usages may match or the usage passed in may be a superset of the usage stored within.
49 const auto usageMask = requireExact ? mt.fUsage : fUsage;
50 return fFormat == mt.fFormat &&
51 fStorageMode == mt.fStorageMode &&
52 fFramebufferOnly == mt.fFramebufferOnly &&
53 (usageMask & mt.fUsage) == fUsage;
54 }
55
56 namespace TextureInfos {
57
58 skgpu::graphite::TextureInfo MakeMetal(CFTypeRef mtlTexture) {
59 return MakeMetal(MtlTextureInfo(mtlTexture));
60 }
61
62 skgpu::graphite::TextureInfo MakeMetal(const MtlTextureInfo& mtlInfo) {
63 return TextureInfoPriv::Make(mtlInfo);
64 }
65
66 bool GetMtlTextureInfo(const TextureInfo& info, MtlTextureInfo* out) {
67 return TextureInfoPriv::Copy(info, out);
68 }
69
70 } // namespace TextureInfos
71
72 } // namespace skgpu::graphite