Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | #include "GrBackendSurface.h" |
| 9 | |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 10 | #include "gl/GrGLUtil.h" |
| 11 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 12 | #ifdef SK_VULKAN |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 13 | #include "vk/GrVkImageLayout.h" |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 14 | #include "vk/GrVkTypes.h" |
| 15 | #include "vk/GrVkUtil.h" |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 16 | #endif |
| 17 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 18 | GrBackendFormat::GrBackendFormat(GrGLenum format, GrGLenum target) |
| 19 | : fBackend(kOpenGL_GrBackend) |
| 20 | , fValid(true) { |
| 21 | fGL.fTarget = target; |
| 22 | fGL.fFormat = format; |
| 23 | } |
| 24 | |
| 25 | const GrGLenum* GrBackendFormat::getGLFormat() const { |
| 26 | if (this->isValid() && kOpenGL_GrBackend == fBackend) { |
| 27 | return &fGL.fFormat; |
| 28 | } |
| 29 | return nullptr; |
| 30 | } |
| 31 | |
| 32 | const GrGLenum* GrBackendFormat::getGLTarget() const { |
| 33 | if (this->isValid() && kOpenGL_GrBackend == fBackend) { |
| 34 | return &fGL.fTarget; |
| 35 | } |
| 36 | return nullptr; |
| 37 | } |
| 38 | |
| 39 | #ifdef SK_VULKAN |
| 40 | GrBackendFormat::GrBackendFormat(VkFormat vkFormat) |
| 41 | : fBackend(kVulkan_GrBackend) |
| 42 | , fValid(true) |
| 43 | , fVkFormat(vkFormat) { |
| 44 | } |
| 45 | |
| 46 | const VkFormat* GrBackendFormat::getVkFormat() const { |
| 47 | if (this->isValid() && kVulkan_GrBackend == fBackend) { |
| 48 | return &fVkFormat; |
| 49 | } |
| 50 | return nullptr; |
| 51 | } |
| 52 | #endif |
| 53 | |
| 54 | GrBackendFormat::GrBackendFormat(GrPixelConfig config) |
| 55 | : fBackend(kMock_GrBackend) |
| 56 | , fValid(true) |
| 57 | , fMockFormat(config) { |
| 58 | } |
| 59 | |
| 60 | const GrPixelConfig* GrBackendFormat::getMockFormat() const { |
| 61 | if (this->isValid() && kMock_GrBackend == fBackend) { |
| 62 | return &fMockFormat; |
| 63 | } |
| 64 | return nullptr; |
| 65 | } |
| 66 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 67 | #ifdef SK_VULKAN |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 68 | GrBackendTexture::GrBackendTexture(int width, |
| 69 | int height, |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 70 | const GrVkImageInfo& vkInfo) |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 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) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 78 | : fIsValid(true) |
| 79 | , fWidth(width) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 80 | , fHeight(height) |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 81 | , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat)) |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 82 | , fMipMapped(GrMipMapped(vkInfo.fLevelCount > 1)) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 83 | , fBackend(kVulkan_GrBackend) |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 84 | , fVkInfo(vkInfo, layout.release()) { |
| 85 | } |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 86 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 87 | |
Brian Salomon | 34df0d3 | 2018-03-23 18:23:23 -0400 | [diff] [blame] | 88 | #if GR_TEST_UTILS |
| 89 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 90 | GrBackendTexture::GrBackendTexture(int width, |
| 91 | int height, |
| 92 | GrPixelConfig config, |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 93 | const GrGLTextureInfo& glInfo) |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 94 | : GrBackendTexture(width, height, config, GrMipMapped::kNo, glInfo) {} |
| 95 | |
| 96 | GrBackendTexture::GrBackendTexture(int width, |
| 97 | int height, |
| 98 | GrPixelConfig config, |
| 99 | GrMipMapped mipMapped, |
| 100 | const GrGLTextureInfo& glInfo) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 101 | : fIsValid(true) |
| 102 | , fWidth(width) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 103 | , fHeight(height) |
| 104 | , fConfig(config) |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 105 | , fMipMapped(mipMapped) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 106 | , fBackend(kOpenGL_GrBackend) |
| 107 | , fGLInfo(glInfo) {} |
Brian Salomon | 34df0d3 | 2018-03-23 18:23:23 -0400 | [diff] [blame] | 108 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 109 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 110 | GrBackendTexture::GrBackendTexture(int width, |
| 111 | int height, |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 112 | GrMipMapped mipMapped, |
| 113 | const GrGLTextureInfo& glInfo) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 114 | : fIsValid(true) |
| 115 | , fWidth(width) |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 116 | , fHeight(height) |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 117 | , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat)) |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 118 | , fMipMapped(mipMapped) |
| 119 | , fBackend(kOpenGL_GrBackend) |
| 120 | , fGLInfo(glInfo) {} |
| 121 | |
| 122 | GrBackendTexture::GrBackendTexture(int width, |
| 123 | int height, |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 124 | GrMipMapped mipMapped, |
| 125 | const GrMockTextureInfo& mockInfo) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 126 | : fIsValid(true) |
| 127 | , fWidth(width) |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 128 | , fHeight(height) |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 129 | , fConfig(mockInfo.fConfig) |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 130 | , fMipMapped(mipMapped) |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 131 | , fBackend(kMock_GrBackend) |
| 132 | , fMockInfo(mockInfo) {} |
| 133 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 134 | GrBackendTexture::~GrBackendTexture() { |
| 135 | this->cleanup(); |
| 136 | } |
| 137 | |
| 138 | void GrBackendTexture::cleanup() { |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 139 | #ifdef SK_VULKAN |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 140 | if (this->isValid() && kVulkan_GrBackend == fBackend) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 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(); |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 203 | } |
| 204 | return nullptr; |
| 205 | } |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 206 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 207 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 208 | bool GrBackendTexture::getGLTextureInfo(GrGLTextureInfo* outInfo) const { |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 209 | if (this->isValid() && kOpenGL_GrBackend == fBackend) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 210 | *outInfo = fGLInfo; |
| 211 | return true; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 212 | } |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 213 | return false; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 214 | } |
| 215 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 216 | bool GrBackendTexture::getMockTextureInfo(GrMockTextureInfo* outInfo) const { |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 217 | if (this->isValid() && kMock_GrBackend == fBackend) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 218 | *outInfo = fMockInfo; |
| 219 | return true; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 220 | } |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 221 | return false; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 222 | } |
| 223 | |
Robert Phillips | 7f44196 | 2018-03-15 11:15:19 -0400 | [diff] [blame] | 224 | GrBackendFormat GrBackendTexture::format() const { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 225 | if (!this->isValid()) { |
| 226 | return GrBackendFormat(); |
| 227 | } |
| 228 | |
Robert Phillips | 7f44196 | 2018-03-15 11:15:19 -0400 | [diff] [blame] | 229 | switch (this->backend()) { |
| 230 | #ifdef SK_VULKAN |
| 231 | case kVulkan_GrBackend: { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 232 | GrVkImageInfo vkInfo; |
| 233 | SkAssertResult(this->getVkImageInfo(&vkInfo)); |
| 234 | return GrBackendFormat::MakeVk(vkInfo.fFormat); |
Robert Phillips | 7f44196 | 2018-03-15 11:15:19 -0400 | [diff] [blame] | 235 | } |
| 236 | #endif |
| 237 | case kOpenGL_GrBackend: { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 238 | GrGLTextureInfo glInfo; |
| 239 | SkAssertResult(this->getGLTextureInfo(&glInfo)); |
| 240 | return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget); |
Robert Phillips | 7f44196 | 2018-03-15 11:15:19 -0400 | [diff] [blame] | 241 | } |
| 242 | case kMock_GrBackend: { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 243 | GrMockTextureInfo mockInfo; |
| 244 | SkAssertResult(this->getMockTextureInfo(&mockInfo)); |
| 245 | return GrBackendFormat::MakeMock(mockInfo.fConfig); |
Robert Phillips | 7f44196 | 2018-03-15 11:15:19 -0400 | [diff] [blame] | 246 | } |
| 247 | default: |
| 248 | return GrBackendFormat(); |
| 249 | } |
| 250 | } |
| 251 | |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 252 | #if GR_TEST_UTILS |
| 253 | bool GrBackendTexture::TestingOnly_Equals(const GrBackendTexture& t0, const GrBackendTexture& t1) { |
| 254 | if (!t0.isValid() || !t1.isValid()) { |
| 255 | return false; // two invalid backend textures are not considered equal |
| 256 | } |
| 257 | |
| 258 | if (t0.fWidth != t1.fWidth || |
| 259 | t0.fHeight != t1.fHeight || |
| 260 | t0.fConfig != t1.fConfig || |
| 261 | t0.fMipMapped != t1.fMipMapped || |
| 262 | t0.fBackend != t1.fBackend) { |
| 263 | return false; |
| 264 | } |
| 265 | |
| 266 | switch (t0.fBackend) { |
| 267 | case kOpenGL_GrBackend: |
| 268 | return t0.fGLInfo == t1.fGLInfo; |
| 269 | case kMock_GrBackend: |
| 270 | return t0.fMockInfo == t1.fMockInfo; |
| 271 | case kVulkan_GrBackend: |
| 272 | #ifdef SK_VULKAN |
| 273 | return t0.fVkInfo == t1.fVkInfo; |
| 274 | #else |
| 275 | // fall through |
| 276 | #endif |
| 277 | case kMetal_GrBackend: // fall through |
| 278 | default: |
| 279 | return false; |
| 280 | } |
| 281 | |
| 282 | SkASSERT(0); |
| 283 | return false; |
| 284 | } |
| 285 | #endif |
| 286 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 287 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 288 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 289 | #ifdef SK_VULKAN |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 290 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 291 | int height, |
| 292 | int sampleCnt, |
| 293 | int stencilBits, |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 294 | const GrVkImageInfo& vkInfo) |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 295 | : GrBackendRenderTarget(width, height, sampleCnt, vkInfo) { |
| 296 | // This is a deprecated constructor that takes a bogus stencil bits. |
| 297 | SkASSERT(0 == stencilBits); |
| 298 | } |
| 299 | |
| 300 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 301 | int height, |
| 302 | int sampleCnt, |
| 303 | const GrVkImageInfo& vkInfo) |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame^] | 304 | : GrBackendRenderTarget(width, height, sampleCnt, vkInfo, |
| 305 | sk_sp<GrVkImageLayout>(new GrVkImageLayout(vkInfo.fImageLayout))) {} |
| 306 | |
| 307 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 308 | int height, |
| 309 | int sampleCnt, |
| 310 | const GrVkImageInfo& vkInfo, |
| 311 | sk_sp<GrVkImageLayout> layout) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 312 | : fIsValid(true) |
| 313 | , fWidth(width) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 314 | , fHeight(height) |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 315 | , fSampleCnt(SkTMax(1, sampleCnt)) |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 316 | , fStencilBits(0) // We always create stencil buffers internally for vulkan |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 317 | , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat)) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 318 | , fBackend(kVulkan_GrBackend) |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame^] | 319 | , fVkInfo(vkInfo, layout.release()) {} |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 320 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 321 | |
Brian Salomon | 34df0d3 | 2018-03-23 18:23:23 -0400 | [diff] [blame] | 322 | #if GR_TEST_UTILS |
| 323 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 324 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 325 | int height, |
| 326 | int sampleCnt, |
| 327 | int stencilBits, |
| 328 | GrPixelConfig config, |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 329 | const GrGLFramebufferInfo& glInfo) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 330 | : fIsValid(true) |
| 331 | , fWidth(width) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 332 | , fHeight(height) |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 333 | , fSampleCnt(SkTMax(1, sampleCnt)) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 334 | , fStencilBits(stencilBits) |
| 335 | , fConfig(config) |
| 336 | , fBackend(kOpenGL_GrBackend) |
| 337 | , fGLInfo(glInfo) {} |
Brian Salomon | 34df0d3 | 2018-03-23 18:23:23 -0400 | [diff] [blame] | 338 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 339 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 340 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 341 | int height, |
| 342 | int sampleCnt, |
| 343 | int stencilBits, |
| 344 | const GrGLFramebufferInfo& glInfo) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 345 | : fIsValid(true) |
| 346 | , fWidth(width) |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 347 | , fHeight(height) |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 348 | , fSampleCnt(SkTMax(1, sampleCnt)) |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 349 | , fStencilBits(stencilBits) |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 350 | , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat)) |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 351 | , fBackend(kOpenGL_GrBackend) |
| 352 | , fGLInfo(glInfo) {} |
| 353 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 354 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 355 | int height, |
| 356 | int sampleCnt, |
| 357 | int stencilBits, |
| 358 | const GrMockRenderTargetInfo& mockInfo) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 359 | : fIsValid(true) |
| 360 | , fWidth(width) |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 361 | , fHeight(height) |
| 362 | , fSampleCnt(SkTMax(1, sampleCnt)) |
| 363 | , fStencilBits(stencilBits) |
| 364 | , fConfig(mockInfo.fConfig) |
| 365 | , fMockInfo(mockInfo) {} |
| 366 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame^] | 367 | GrBackendRenderTarget::~GrBackendRenderTarget() { |
| 368 | this->cleanup(); |
| 369 | } |
| 370 | |
| 371 | void GrBackendRenderTarget::cleanup() { |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 372 | #ifdef SK_VULKAN |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame^] | 373 | if (this->isValid() && kVulkan_GrBackend == fBackend) { |
| 374 | fVkInfo.cleanup(); |
| 375 | } |
| 376 | #endif |
| 377 | } |
| 378 | |
| 379 | GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTarget& that) : fIsValid(false) { |
| 380 | *this = that; |
| 381 | } |
| 382 | |
| 383 | GrBackendRenderTarget& GrBackendRenderTarget::operator=(const GrBackendRenderTarget& that) { |
| 384 | if (!that.isValid()) { |
| 385 | this->cleanup(); |
| 386 | fIsValid = false; |
| 387 | return *this; |
| 388 | } |
| 389 | fWidth = that.fWidth; |
| 390 | fHeight = that.fHeight; |
| 391 | fSampleCnt = that.fSampleCnt; |
| 392 | fStencilBits = that.fStencilBits; |
| 393 | fConfig = that.fConfig; |
| 394 | fBackend = that.fBackend; |
| 395 | |
| 396 | switch (that.fBackend) { |
| 397 | case kOpenGL_GrBackend: |
| 398 | fGLInfo = that.fGLInfo; |
| 399 | break; |
| 400 | #ifdef SK_VULKAN |
| 401 | case kVulkan_GrBackend: |
| 402 | fVkInfo.assign(that.fVkInfo, this->isValid()); |
| 403 | break; |
| 404 | #endif |
| 405 | #ifdef SK_METAL |
| 406 | case kMetal_GrBackend: |
| 407 | break; |
| 408 | #endif |
| 409 | case kMock_GrBackend: |
| 410 | fMockInfo = that.fMockInfo; |
| 411 | break; |
| 412 | default: |
| 413 | SK_ABORT("Unknown GrBackend"); |
| 414 | } |
| 415 | fIsValid = that.fIsValid; |
| 416 | return *this; |
| 417 | } |
| 418 | |
| 419 | #ifdef SK_VULKAN |
| 420 | bool GrBackendRenderTarget::getVkImageInfo(GrVkImageInfo* outInfo) const { |
| 421 | if (this->isValid() && kVulkan_GrBackend == fBackend) { |
| 422 | *outInfo = fVkInfo.snapImageInfo(); |
| 423 | return true; |
| 424 | } |
| 425 | return false; |
| 426 | } |
| 427 | |
| 428 | void GrBackendRenderTarget::setVkImageLayout(VkImageLayout layout) { |
| 429 | if (this->isValid() && kVulkan_GrBackend == fBackend) { |
| 430 | fVkInfo.setImageLayout(layout); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | sk_sp<GrVkImageLayout> GrBackendRenderTarget::getGrVkImageLayout() const { |
| 435 | if (this->isValid() && kVulkan_GrBackend == fBackend) { |
| 436 | return fVkInfo.getGrVkImageLayout(); |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 437 | } |
| 438 | return nullptr; |
| 439 | } |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 440 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 441 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame^] | 442 | bool GrBackendRenderTarget::getGLFramebufferInfo(GrGLFramebufferInfo* outInfo) const { |
| 443 | if (this->isValid() && kOpenGL_GrBackend == fBackend) { |
| 444 | *outInfo = fGLInfo; |
| 445 | return true; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 446 | } |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame^] | 447 | return false; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 448 | } |
| 449 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame^] | 450 | bool GrBackendRenderTarget::getMockRenderTargetInfo(GrMockRenderTargetInfo* outInfo) const { |
| 451 | if (this->isValid() && kMock_GrBackend == fBackend) { |
| 452 | *outInfo = fMockInfo; |
| 453 | return true; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 454 | } |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame^] | 455 | return false; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 456 | } |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 457 | |
| 458 | #if GR_TEST_UTILS |
| 459 | bool GrBackendRenderTarget::TestingOnly_Equals(const GrBackendRenderTarget& r0, |
| 460 | const GrBackendRenderTarget& r1) { |
| 461 | if (!r0.isValid() || !r1.isValid()) { |
| 462 | return false; // two invalid backend rendertargets are not considered equal |
| 463 | } |
| 464 | |
| 465 | if (r0.fWidth != r1.fWidth || |
| 466 | r0.fHeight != r1.fHeight || |
| 467 | r0.fSampleCnt != r1.fSampleCnt || |
| 468 | r0.fStencilBits != r1.fStencilBits || |
| 469 | r0.fConfig != r1.fConfig || |
| 470 | r0.fBackend != r1.fBackend) { |
| 471 | return false; |
| 472 | } |
| 473 | |
| 474 | switch (r0.fBackend) { |
| 475 | case kOpenGL_GrBackend: |
| 476 | return r0.fGLInfo == r1.fGLInfo; |
| 477 | case kMock_GrBackend: |
| 478 | return r0.fMockInfo == r1.fMockInfo; |
| 479 | case kVulkan_GrBackend: |
| 480 | #ifdef SK_VULKAN |
| 481 | return r0.fVkInfo == r1.fVkInfo; |
| 482 | #else |
| 483 | // fall through |
| 484 | #endif |
| 485 | case kMetal_GrBackend: // fall through |
| 486 | default: |
| 487 | return false; |
| 488 | } |
| 489 | |
| 490 | SkASSERT(0); |
| 491 | return false; |
| 492 | } |
| 493 | #endif |