1 /* 2 * Copyright 2018 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 GrVkTypesPriv_DEFINED 9 #define GrVkTypesPriv_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/gpu/vk/GrVkTypes.h" 13 14 namespace skgpu { 15 class MutableTextureStateRef; 16 } 17 18 19 // This struct is to used to store the the actual information about the vulkan backend image on the 20 // GrBackendTexture and GrBackendRenderTarget. When a client calls getVkImageInfo on a 21 // GrBackendTexture/RenderTarget, we use the GrVkBackendSurfaceInfo to create a snapshot 22 // GrVkImgeInfo object. Internally, this uses a ref count GrVkImageLayout object to track the 23 // current VkImageLayout which can be shared with an internal GrVkImage so that layout updates can 24 // be seen by all users of the image. 25 struct GrVkBackendSurfaceInfo { GrVkBackendSurfaceInfoGrVkBackendSurfaceInfo26 GrVkBackendSurfaceInfo(GrVkImageInfo info) : fImageInfo(info) {} 27 28 void cleanup(); 29 30 GrVkBackendSurfaceInfo& operator=(const GrVkBackendSurfaceInfo&) = delete; 31 32 // Assigns the passed in GrVkBackendSurfaceInfo to this object. if isValid is true we will also 33 // attempt to unref the old fLayout on this object. 34 void assign(const GrVkBackendSurfaceInfo&, bool isValid); 35 36 GrVkImageInfo snapImageInfo(const skgpu::MutableTextureStateRef*) const; 37 isProtectedGrVkBackendSurfaceInfo38 bool isProtected() const { return fImageInfo.fProtected == GrProtected::kYes; } 39 #if GR_TEST_UTILS 40 bool operator==(const GrVkBackendSurfaceInfo& that) const; 41 #endif 42 43 private: 44 GrVkImageInfo fImageInfo; 45 }; 46 47 struct GrVkImageSpec { GrVkImageSpecGrVkImageSpec48 GrVkImageSpec() 49 : fImageTiling(VK_IMAGE_TILING_OPTIMAL) 50 , fFormat(VK_FORMAT_UNDEFINED) 51 , fImageUsageFlags(0) 52 , fSharingMode(VK_SHARING_MODE_EXCLUSIVE) {} 53 GrVkImageSpecGrVkImageSpec54 GrVkImageSpec(const GrVkSurfaceInfo& info) 55 : fImageTiling(info.fImageTiling) 56 , fFormat(info.fFormat) 57 , fImageUsageFlags(info.fImageUsageFlags) 58 , fYcbcrConversionInfo(info.fYcbcrConversionInfo) 59 , fSharingMode(info.fSharingMode) {} 60 61 VkImageTiling fImageTiling; 62 VkFormat fFormat; 63 VkImageUsageFlags fImageUsageFlags; 64 GrVkYcbcrConversionInfo fYcbcrConversionInfo; 65 VkSharingMode fSharingMode; 66 }; 67 68 GrVkSurfaceInfo GrVkImageSpecToSurfaceInfo(const GrVkImageSpec& vkSpec, 69 uint32_t sampleCount, 70 uint32_t levelCount, 71 GrProtected isProtected); 72 73 #endif 74