1 /* 2 * Copyright 2021 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 8 #ifndef skgpu_graphite_MtlGraphiteTypes_DEFINED 9 #define skgpu_graphite_MtlGraphiteTypes_DEFINED 10 11 #if __OBJC__ // <Metal/Metal.h> only works when compiled for Objective C 12 13 #include "include/core/SkTypes.h" 14 15 #include "include/gpu/graphite/GraphiteTypes.h" 16 #include "include/gpu/graphite/TextureInfo.h" 17 #include "include/gpu/graphite/mtl/MtlGraphiteTypes_cpp.h" 18 #include "include/private/base/SkAPI.h" 19 20 #import <CoreFoundation/CoreFoundation.h> 21 #import <Metal/Metal.h> 22 #import <TargetConditionals.h> 23 24 class SkStream; 25 class SkWStream; 26 27 namespace skgpu::graphite { 28 29 class SK_API MtlTextureInfo final : public TextureInfo::Data { 30 public: 31 MTLPixelFormat fFormat = MTLPixelFormatInvalid; 32 MTLTextureUsage fUsage = MTLTextureUsageUnknown; 33 MTLStorageMode fStorageMode = MTLStorageModeShared; 34 bool fFramebufferOnly = false; 35 36 MtlTextureInfo() = default; 37 MtlTextureInfo(CFTypeRef mtlTexture); MtlTextureInfo(uint32_t sampleCount,skgpu::Mipmapped mipmapped,MTLPixelFormat format,MTLTextureUsage usage,MTLStorageMode storageMode,bool framebufferOnly)38 MtlTextureInfo(uint32_t sampleCount, 39 skgpu::Mipmapped mipmapped, 40 MTLPixelFormat format, 41 MTLTextureUsage usage, 42 MTLStorageMode storageMode, 43 bool framebufferOnly) 44 : Data(sampleCount, mipmapped) 45 , fFormat(format) 46 , fUsage(usage) 47 , fStorageMode(storageMode) 48 , fFramebufferOnly(framebufferOnly) {} 49 50 private: 51 friend class TextureInfo; 52 friend class TextureInfoPriv; 53 54 // Non-virtual template API for TextureInfo::Data accessed directly when backend type is known. 55 static constexpr skgpu::BackendApi kBackend = skgpu::BackendApi::kMetal; 56 isProtected()57 Protected isProtected() const { return Protected::kNo; } 58 TextureFormat viewFormat() const; 59 60 bool serialize(SkWStream*) const; 61 bool deserialize(SkStream*); 62 63 // Virtual API when the specific backend type is not available. 64 SkString toBackendString() const override; 65 copyTo(TextureInfo::AnyTextureInfoData & dstData)66 void copyTo(TextureInfo::AnyTextureInfoData& dstData) const override { 67 dstData.emplace<MtlTextureInfo>(*this); 68 } 69 bool isCompatible(const TextureInfo& that, bool requireExact) const override; 70 }; 71 72 } // namespace skgpu::graphite 73 74 #endif // __OBJC__ 75 76 #endif // skgpu_graphite_MtlGraphiteTypes_DEFINED 77