| 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 | class GrBackendSurfaceMutableStateImpl; |
| 15 | |
| 16 | // This struct is to used to store the the actual information about the vulkan backend image on the |
| 17 | // GrBackendTexture and GrBackendRenderTarget. When a client calls getVkImageInfo on a |
| 18 | // GrBackendTexture/RenderTarget, we use the GrVkBackendSurfaceInfo to create a snapshot |
| 19 | // GrVkImgeInfo object. Internally, this uses a ref count GrVkImageLayout object to track the |
| 20 | // current VkImageLayout which can be shared with an internal GrVkImage so that layout updates can |
| 21 | // be seen by all users of the image. |
| 22 | struct GrVkBackendSurfaceInfo { |
| 23 | GrVkBackendSurfaceInfo(GrVkImageInfo info) : fImageInfo(info) {} |
| 24 | |
| 25 | void cleanup(); |
| 26 | |
| 27 | GrVkBackendSurfaceInfo& operator=(const GrVkBackendSurfaceInfo&) = delete; |
| 28 | |
| 29 | // Assigns the passed in GrVkBackendSurfaceInfo to this object. if isValid is true we will also |
| 30 | // attempt to unref the old fLayout on this object. |
| 31 | void assign(const GrVkBackendSurfaceInfo&, bool isValid); |
| 32 | |
| 33 | GrVkImageInfo snapImageInfo(const GrBackendSurfaceMutableStateImpl*) const; |
| 34 | |
| 35 | bool isProtected() const { return fImageInfo.fProtected == GrProtected::kYes; } |
| 36 | #if GR_TEST_UTILS |
| 37 | bool operator==(const GrVkBackendSurfaceInfo& that) const; |
| 38 | #endif |
| 39 | |
| 40 | private: |
| 41 | GrVkImageInfo fImageInfo; |
| 42 | }; |
| 43 | |
| 44 | class GrVkSharedImageInfo { |
| 45 | public: |
| 46 | GrVkSharedImageInfo(VkImageLayout layout, uint32_t queueFamilyIndex) |
| 47 | : fLayout(layout) |
| 48 | , fQueueFamilyIndex(queueFamilyIndex) {} |
| 49 | |
| 50 | GrVkSharedImageInfo& operator=(const GrVkSharedImageInfo& that) { |
| 51 | fLayout = that.getImageLayout(); |
| 52 | fQueueFamilyIndex = that.getQueueFamilyIndex(); |
| 53 | return *this; |
| 54 | } |
| 55 | |
| 56 | void setImageLayout(VkImageLayout layout) { |
| 57 | // Defaulting to use std::memory_order_seq_cst |
| 58 | fLayout.store(layout); |
| 59 | } |
| 60 | |
| 61 | VkImageLayout getImageLayout() const { |
| 62 | // Defaulting to use std::memory_order_seq_cst |
| 63 | return fLayout.load(); |
| 64 | } |
| 65 | |
| 66 | void setQueueFamilyIndex(uint32_t queueFamilyIndex) { |
| 67 | // Defaulting to use std::memory_order_seq_cst |
| 68 | fQueueFamilyIndex.store(queueFamilyIndex); |
| 69 | } |
| 70 | |
| 71 | uint32_t getQueueFamilyIndex() const { |
| 72 | // Defaulting to use std::memory_order_seq_cst |
| 73 | return fQueueFamilyIndex.load(); |
| 74 | } |
| 75 | |
| 76 | private: |
| 77 | std::atomic<VkImageLayout> fLayout; |
| 78 | std::atomic<uint32_t> fQueueFamilyIndex; |
| 79 | }; |
| 80 | |
| 81 | #endif |
| 82 |