|
10 | 10 | #include "gl/GrGLUtil.h" |
11 | 11 |
|
12 | 12 | #ifdef SK_VULKAN |
| 13 | +#include "vk/GrVkImageLayout.h" |
13 | 14 | #include "vk/GrVkTypes.h" |
14 | 15 | #include "vk/GrVkUtil.h" |
15 | 16 | #endif |
@@ -67,13 +68,21 @@ const GrPixelConfig* GrBackendFormat::getMockFormat() const { |
67 | 68 | GrBackendTexture::GrBackendTexture(int width, |
68 | 69 | int height, |
69 | 70 | const GrVkImageInfo& vkInfo) |
| 71 | + : GrBackendTexture(width, height, vkInfo, |
| 72 | + sk_sp<GrVkImageLayout>(new GrVkImageLayout(vkInfo.fImageLayout))) {} |
| 73 | + |
| 74 | +GrBackendTexture::GrBackendTexture(int width, |
| 75 | + int height, |
| 76 | + const GrVkImageInfo& vkInfo, |
| 77 | + sk_sp<GrVkImageLayout> layout) |
70 | 78 | : fIsValid(true) |
71 | 79 | , fWidth(width) |
72 | 80 | , fHeight(height) |
73 | 81 | , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat)) |
74 | 82 | , fMipMapped(GrMipMapped(vkInfo.fLevelCount > 1)) |
75 | 83 | , fBackend(kVulkan_GrBackend) |
76 | | - , fVkInfo(vkInfo) {} |
| 84 | + , fVkInfo(vkInfo, layout.release()) { |
| 85 | +} |
77 | 86 | #endif |
78 | 87 |
|
79 | 88 | #if GR_TEST_UTILS |
@@ -122,47 +131,118 @@ GrBackendTexture::GrBackendTexture(int width, |
122 | 131 | , fBackend(kMock_GrBackend) |
123 | 132 | , fMockInfo(mockInfo) {} |
124 | 133 |
|
| 134 | +GrBackendTexture::~GrBackendTexture() { |
| 135 | + this->cleanup(); |
| 136 | +} |
| 137 | + |
| 138 | +void GrBackendTexture::cleanup() { |
125 | 139 | #ifdef SK_VULKAN |
126 | | -const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const { |
127 | 140 | if (this->isValid() && kVulkan_GrBackend == fBackend) { |
128 | | - return &fVkInfo; |
| 141 | + fVkInfo.cleanup(); |
| 142 | + } |
| 143 | +#endif |
| 144 | +} |
| 145 | + |
| 146 | +GrBackendTexture::GrBackendTexture(const GrBackendTexture& that) : fIsValid(false) { |
| 147 | + *this = that; |
| 148 | +} |
| 149 | + |
| 150 | +GrBackendTexture& GrBackendTexture::operator=(const GrBackendTexture& that) { |
| 151 | + if (!that.isValid()) { |
| 152 | + this->cleanup(); |
| 153 | + fIsValid = false; |
| 154 | + return *this; |
| 155 | + } |
| 156 | + fWidth = that.fWidth; |
| 157 | + fHeight = that.fHeight; |
| 158 | + fConfig = that.fConfig; |
| 159 | + fMipMapped = that.fMipMapped; |
| 160 | + fBackend = that.fBackend; |
| 161 | + |
| 162 | + switch (that.fBackend) { |
| 163 | + case kOpenGL_GrBackend: |
| 164 | + fGLInfo = that.fGLInfo; |
| 165 | + break; |
| 166 | +#ifdef SK_VULKAN |
| 167 | + case kVulkan_GrBackend: |
| 168 | + fVkInfo.assign(that.fVkInfo, this->isValid()); |
| 169 | + break; |
| 170 | +#endif |
| 171 | +#ifdef SK_METAL |
| 172 | + case kMetal_GrBackend: |
| 173 | + break; |
| 174 | +#endif |
| 175 | + case kMock_GrBackend: |
| 176 | + fMockInfo = that.fMockInfo; |
| 177 | + break; |
| 178 | + default: |
| 179 | + SK_ABORT("Unknown GrBackend"); |
| 180 | + } |
| 181 | + fIsValid = that.fIsValid; |
| 182 | + return *this; |
| 183 | +} |
| 184 | + |
| 185 | +#ifdef SK_VULKAN |
| 186 | +bool GrBackendTexture::getVkImageInfo(GrVkImageInfo* outInfo) const { |
| 187 | + if (this->isValid() && kVulkan_GrBackend == fBackend) { |
| 188 | + *outInfo = fVkInfo.snapImageInfo(); |
| 189 | + return true; |
| 190 | + } |
| 191 | + return false; |
| 192 | +} |
| 193 | + |
| 194 | +void GrBackendTexture::setVkImageLayout(VkImageLayout layout) { |
| 195 | + if (this->isValid() && kVulkan_GrBackend == fBackend) { |
| 196 | + fVkInfo.setImageLayout(layout); |
| 197 | + } |
| 198 | +} |
| 199 | + |
| 200 | +sk_sp<GrVkImageLayout> GrBackendTexture::getGrVkImageLayout() const { |
| 201 | + if (this->isValid() && kVulkan_GrBackend == fBackend) { |
| 202 | + return fVkInfo.getGrVkImageLayout(); |
129 | 203 | } |
130 | 204 | return nullptr; |
131 | 205 | } |
132 | 206 | #endif |
133 | 207 |
|
134 | | -const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const { |
| 208 | +bool GrBackendTexture::getGLTextureInfo(GrGLTextureInfo* outInfo) const { |
135 | 209 | if (this->isValid() && kOpenGL_GrBackend == fBackend) { |
136 | | - return &fGLInfo; |
| 210 | + *outInfo = fGLInfo; |
| 211 | + return true; |
137 | 212 | } |
138 | | - return nullptr; |
| 213 | + return false; |
139 | 214 | } |
140 | 215 |
|
141 | | -const GrMockTextureInfo* GrBackendTexture::getMockTextureInfo() const { |
| 216 | +bool GrBackendTexture::getMockTextureInfo(GrMockTextureInfo* outInfo) const { |
142 | 217 | if (this->isValid() && kMock_GrBackend == fBackend) { |
143 | | - return &fMockInfo; |
| 218 | + *outInfo = fMockInfo; |
| 219 | + return true; |
144 | 220 | } |
145 | | - return nullptr; |
| 221 | + return false; |
146 | 222 | } |
147 | 223 |
|
148 | 224 | GrBackendFormat GrBackendTexture::format() const { |
| 225 | + if (!this->isValid()) { |
| 226 | + return GrBackendFormat(); |
| 227 | + } |
| 228 | + |
149 | 229 | switch (this->backend()) { |
150 | 230 | #ifdef SK_VULKAN |
151 | 231 | case kVulkan_GrBackend: { |
152 | | - const GrVkImageInfo* vkInfo = this->getVkImageInfo(); |
153 | | - SkASSERT(vkInfo); |
154 | | - return GrBackendFormat::MakeVk(vkInfo->fFormat); |
| 232 | + GrVkImageInfo vkInfo; |
| 233 | + SkAssertResult(this->getVkImageInfo(&vkInfo)); |
| 234 | + return GrBackendFormat::MakeVk(vkInfo.fFormat); |
155 | 235 | } |
156 | 236 | #endif |
157 | 237 | case kOpenGL_GrBackend: { |
158 | | - const GrGLTextureInfo* glInfo = this->getGLTextureInfo(); |
159 | | - SkASSERT(glInfo); |
160 | | - return GrBackendFormat::MakeGL(glInfo->fFormat, glInfo->fTarget); |
| 238 | + GrGLTextureInfo glInfo; |
| 239 | + SkAssertResult(this->getGLTextureInfo(&glInfo)); |
| 240 | + return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget); |
161 | 241 | } |
162 | 242 | case kMock_GrBackend: { |
163 | | - const GrMockTextureInfo* mockInfo = this->getMockTextureInfo(); |
164 | | - SkASSERT(mockInfo); |
165 | | - return GrBackendFormat::MakeMock(mockInfo->fConfig); |
| 243 | + GrMockTextureInfo mockInfo; |
| 244 | + SkAssertResult(this->getMockTextureInfo(&mockInfo)); |
| 245 | + return GrBackendFormat::MakeMock(mockInfo.fConfig); |
166 | 246 | } |
167 | 247 | default: |
168 | 248 | return GrBackendFormat(); |
|
0 commit comments