1 /* 2 * Copyright 2023 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 skgpu_graphite_VulkanImageView_DEFINED 9 #define skgpu_graphite_VulkanImageView_DEFINED 10 11 #include "include/gpu/vk/VulkanTypes.h" 12 #include "src/gpu/graphite/Resource.h" 13 #include "src/gpu/graphite/vk/VulkanYcbcrConversion.h" 14 15 namespace skgpu::graphite { 16 17 class VulkanSharedContext; 18 class VulkanResourceProvider; 19 20 /* 21 * VulkanImageView is not derived from Resource as its lifetime is dependent on the lifetime of 22 * its associated VulkanTexture. Hence VulkanTexture will act as a container for its ImageViews 23 * w.r.t. the ResourceCache and CommandBuffer, and is responsible for deleting its ImageView 24 * children when freeGpuData() is called. 25 */ 26 class VulkanImageView { 27 public: 28 enum class Usage { 29 kShaderInput, 30 kAttachment 31 }; 32 33 static std::unique_ptr<const VulkanImageView> Make( 34 const VulkanSharedContext* sharedContext, 35 VkImage image, 36 VkFormat format, 37 Usage usage, 38 uint32_t miplevels, 39 sk_sp<VulkanYcbcrConversion>); 40 ~VulkanImageView(); 41 imageView()42 VkImageView imageView() const { return fImageView; } usage()43 Usage usage() const { return fUsage; } 44 45 private: 46 VulkanImageView(const VulkanSharedContext*, VkImageView, Usage, sk_sp<VulkanYcbcrConversion>); 47 48 // Since we're not derived from Resource we need to store the context for deletion later 49 const VulkanSharedContext* fSharedContext; 50 VkImageView fImageView; 51 Usage fUsage; 52 sk_sp<VulkanYcbcrConversion> fYcbcrConversion; 53 }; 54 55 } // namespace skgpu::graphite 56 57 #endif // skgpu_graphite_VulkanImageView_DEFINED 58