OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrVkImage_DEFINED | 8 #ifndef GrVkImage_DEFINED |
9 #define GrVkImage_DEFINED | 9 #define GrVkImage_DEFINED |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 , fIsBorrowed(kBorrowed_Wrapped == wrapped) { | 34 , fIsBorrowed(kBorrowed_Wrapped == wrapped) { |
35 if (kBorrowed_Wrapped == wrapped) { | 35 if (kBorrowed_Wrapped == wrapped) { |
36 fResource = new BorrowedResource(info.fImage, info.fAlloc); | 36 fResource = new BorrowedResource(info.fImage, info.fAlloc); |
37 } else { | 37 } else { |
38 fResource = new Resource(info.fImage, info.fAlloc); | 38 fResource = new Resource(info.fImage, info.fAlloc); |
39 } | 39 } |
40 } | 40 } |
41 virtual ~GrVkImage(); | 41 virtual ~GrVkImage(); |
42 | 42 |
43 VkImage image() const { return fInfo.fImage; } | 43 VkImage image() const { return fInfo.fImage; } |
44 VkDeviceMemory memory() const { return fInfo.fAlloc; } | 44 const GrVkAlloc& alloc() const { return fInfo.fAlloc; } |
45 VkFormat imageFormat() const { return fInfo.fFormat; } | 45 VkFormat imageFormat() const { return fInfo.fFormat; } |
46 const Resource* resource() const { return fResource; } | 46 const Resource* resource() const { return fResource; } |
47 bool isLinearTiled() const { | 47 bool isLinearTiled() const { |
48 return SkToBool(VK_IMAGE_TILING_LINEAR == fInfo.fImageTiling); | 48 return SkToBool(VK_IMAGE_TILING_LINEAR == fInfo.fImageTiling); |
49 } | 49 } |
50 | 50 |
51 VkImageLayout currentLayout() const { return fInfo.fImageLayout; } | 51 VkImageLayout currentLayout() const { return fInfo.fImageLayout; } |
52 | 52 |
53 void setImageLayout(const GrVkGpu* gpu, | 53 void setImageLayout(const GrVkGpu* gpu, |
54 VkImageLayout newLayout, | 54 VkImageLayout newLayout, |
(...skipping 25 matching lines...) Expand all Loading... |
80 }; | 80 }; |
81 | 81 |
82 static bool InitImageInfo(const GrVkGpu* gpu, const ImageDesc& imageDesc, Gr
VkImageInfo*); | 82 static bool InitImageInfo(const GrVkGpu* gpu, const ImageDesc& imageDesc, Gr
VkImageInfo*); |
83 // Destroys the internal VkImage and VkDeviceMemory in the GrVkImageInfo | 83 // Destroys the internal VkImage and VkDeviceMemory in the GrVkImageInfo |
84 static void DestroyImageInfo(const GrVkGpu* gpu, GrVkImageInfo*); | 84 static void DestroyImageInfo(const GrVkGpu* gpu, GrVkImageInfo*); |
85 | 85 |
86 protected: | 86 protected: |
87 void releaseImage(const GrVkGpu* gpu); | 87 void releaseImage(const GrVkGpu* gpu); |
88 void abandonImage(); | 88 void abandonImage(); |
89 | 89 |
90 void setNewResource(VkImage image, VkDeviceMemory alloc); | 90 void setNewResource(VkImage image, const GrVkAlloc& alloc); |
91 | 91 |
92 GrVkImageInfo fInfo; | 92 GrVkImageInfo fInfo; |
93 bool fIsBorrowed; | 93 bool fIsBorrowed; |
94 | 94 |
95 private: | 95 private: |
96 // unlike GrVkBuffer, this needs to be public so GrVkStencilAttachment can u
se it | 96 // unlike GrVkBuffer, this needs to be public so GrVkStencilAttachment can u
se it |
97 class Resource : public GrVkResource { | 97 class Resource : public GrVkResource { |
98 public: | 98 public: |
99 Resource() | 99 Resource() |
100 : INHERITED() | 100 : INHERITED() |
101 , fImage(VK_NULL_HANDLE) | 101 , fImage(VK_NULL_HANDLE) { |
102 , fAlloc(VK_NULL_HANDLE) { | 102 fAlloc.fMemory = VK_NULL_HANDLE; |
| 103 fAlloc.fOffset = 0; |
103 } | 104 } |
104 | 105 |
105 Resource(VkImage image, VkDeviceMemory alloc) : fImage(image), fAlloc(al
loc) {} | 106 Resource(VkImage image, const GrVkAlloc& alloc) |
| 107 : fImage(image), fAlloc(alloc) {} |
106 | 108 |
107 ~Resource() override {} | 109 ~Resource() override {} |
108 | 110 |
109 private: | 111 private: |
110 void freeGPUData(const GrVkGpu* gpu) const override; | 112 void freeGPUData(const GrVkGpu* gpu) const override; |
111 | 113 |
112 VkImage fImage; | 114 VkImage fImage; |
113 VkDeviceMemory fAlloc; | 115 GrVkAlloc fAlloc; |
114 | 116 |
115 typedef GrVkResource INHERITED; | 117 typedef GrVkResource INHERITED; |
116 }; | 118 }; |
117 | 119 |
118 // for wrapped textures | 120 // for wrapped textures |
119 class BorrowedResource : public Resource { | 121 class BorrowedResource : public Resource { |
120 public: | 122 public: |
121 BorrowedResource(VkImage image, VkDeviceMemory alloc) : Resource(image,
alloc) { | 123 BorrowedResource(VkImage image, const GrVkAlloc& alloc) |
| 124 : Resource(image, alloc) { |
122 } | 125 } |
123 private: | 126 private: |
124 void freeGPUData(const GrVkGpu* gpu) const override; | 127 void freeGPUData(const GrVkGpu* gpu) const override; |
125 }; | 128 }; |
126 | 129 |
127 const Resource* fResource; | 130 const Resource* fResource; |
128 | 131 |
129 friend class GrVkRenderTarget; | 132 friend class GrVkRenderTarget; |
130 }; | 133 }; |
131 | 134 |
132 #endif | 135 #endif |
OLD | NEW |