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 15 matching lines...) Expand all Loading... |
26 enum Wrapped { | 26 enum Wrapped { |
27 kNot_Wrapped, | 27 kNot_Wrapped, |
28 kAdopted_Wrapped, | 28 kAdopted_Wrapped, |
29 kBorrowed_Wrapped, | 29 kBorrowed_Wrapped, |
30 }; | 30 }; |
31 | 31 |
32 GrVkImage(const GrVkImageInfo& info, Wrapped wrapped) | 32 GrVkImage(const GrVkImageInfo& info, Wrapped wrapped) |
33 : fInfo(info) | 33 : fInfo(info) |
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, info.fIma
geTiling); |
37 } else { | 37 } else { |
38 fResource = new Resource(info.fImage, info.fAlloc); | 38 fResource = new Resource(info.fImage, info.fAlloc, info.fImageTiling
); |
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 const GrVkAlloc& alloc() 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); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after 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, const GrVkAlloc& alloc); | 90 void setNewResource(VkImage image, const GrVkAlloc& alloc, VkImageTiling til
ing); |
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 | |
97 class Resource : public GrVkResource { | 96 class Resource : public GrVkResource { |
98 public: | 97 public: |
99 Resource() | 98 Resource() |
100 : INHERITED() | 99 : INHERITED() |
101 , fImage(VK_NULL_HANDLE) { | 100 , fImage(VK_NULL_HANDLE) { |
102 fAlloc.fMemory = VK_NULL_HANDLE; | 101 fAlloc.fMemory = VK_NULL_HANDLE; |
103 fAlloc.fOffset = 0; | 102 fAlloc.fOffset = 0; |
104 } | 103 } |
105 | 104 |
106 Resource(VkImage image, const GrVkAlloc& alloc) | 105 Resource(VkImage image, const GrVkAlloc& alloc, VkImageTiling tiling) |
107 : fImage(image), fAlloc(alloc) {} | 106 : fImage(image), fAlloc(alloc), fImageTiling(tiling) {} |
108 | 107 |
109 ~Resource() override {} | 108 ~Resource() override {} |
110 | 109 |
111 private: | 110 private: |
112 void freeGPUData(const GrVkGpu* gpu) const override; | 111 void freeGPUData(const GrVkGpu* gpu) const override; |
113 | 112 |
114 VkImage fImage; | 113 VkImage fImage; |
115 GrVkAlloc fAlloc; | 114 GrVkAlloc fAlloc; |
| 115 VkImageTiling fImageTiling; |
116 | 116 |
117 typedef GrVkResource INHERITED; | 117 typedef GrVkResource INHERITED; |
118 }; | 118 }; |
119 | 119 |
120 // for wrapped textures | 120 // for wrapped textures |
121 class BorrowedResource : public Resource { | 121 class BorrowedResource : public Resource { |
122 public: | 122 public: |
123 BorrowedResource(VkImage image, const GrVkAlloc& alloc) | 123 BorrowedResource(VkImage image, const GrVkAlloc& alloc, VkImageTiling ti
ling) |
124 : Resource(image, alloc) { | 124 : Resource(image, alloc, tiling) { |
125 } | 125 } |
126 private: | 126 private: |
127 void freeGPUData(const GrVkGpu* gpu) const override; | 127 void freeGPUData(const GrVkGpu* gpu) const override; |
128 }; | 128 }; |
129 | 129 |
130 const Resource* fResource; | 130 const Resource* fResource; |
131 | 131 |
132 friend class GrVkRenderTarget; | 132 friend class GrVkRenderTarget; |
133 }; | 133 }; |
134 | 134 |
135 #endif | 135 #endif |
OLD | NEW |