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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/gpu/GrBackendSurface.h" |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 9 | |
Brian Salomon | d6584bd | 2021-05-18 16:29:09 -0400 | [diff] [blame] | 10 | #include "include/private/GrTypesPriv.h" |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrBackendSurfaceMutableStateImpl.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/gl/GrGLUtil.h" |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 13 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 14 | #ifdef SK_DAWN |
| 15 | #include "include/gpu/dawn/GrDawnTypes.h" |
| 16 | #include "src/gpu/dawn/GrDawnUtil.h" |
| 17 | #endif |
| 18 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 19 | #ifdef SK_VULKAN |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "include/gpu/vk/GrVkTypes.h" |
| 21 | #include "src/gpu/vk/GrVkImageLayout.h" |
| 22 | #include "src/gpu/vk/GrVkUtil.h" |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 23 | #endif |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 24 | #ifdef SK_METAL |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "include/gpu/mtl/GrMtlTypes.h" |
| 26 | #include "src/gpu/mtl/GrMtlCppUtil.h" |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 27 | #endif |
Jim Van Verth | c86c83c | 2020-02-27 15:48:24 -0500 | [diff] [blame] | 28 | #ifdef SK_DIRECT3D |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 29 | #include "include/gpu/d3d/GrD3DTypes.h" |
| 30 | #include "src/gpu/d3d/GrD3DResourceState.h" |
| 31 | #include "src/gpu/d3d/GrD3DUtil.h" |
Jim Van Verth | c86c83c | 2020-02-27 15:48:24 -0500 | [diff] [blame] | 32 | #endif |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 33 | |
Robert Phillips | b2adbef | 2019-07-02 16:33:05 -0400 | [diff] [blame] | 34 | GrBackendFormat::GrBackendFormat(const GrBackendFormat& that) |
| 35 | : fBackend(that.fBackend) |
| 36 | , fValid(that.fValid) |
| 37 | , fTextureType(that.fTextureType) { |
| 38 | if (!fValid) { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | switch (fBackend) { |
| 43 | #ifdef SK_GL |
| 44 | case GrBackendApi::kOpenGL: |
| 45 | fGLFormat = that.fGLFormat; |
| 46 | break; |
| 47 | #endif |
| 48 | #ifdef SK_VULKAN |
| 49 | case GrBackendApi::kVulkan: |
| 50 | fVk = that.fVk; |
| 51 | break; |
| 52 | #endif |
| 53 | #ifdef SK_METAL |
| 54 | case GrBackendApi::kMetal: |
| 55 | fMtlFormat = that.fMtlFormat; |
| 56 | break; |
| 57 | #endif |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 58 | #ifdef SK_DIRECT3D |
| 59 | case GrBackendApi::kDirect3D: |
Jim Van Verth | c86c83c | 2020-02-27 15:48:24 -0500 | [diff] [blame] | 60 | fDxgiFormat = that.fDxgiFormat; |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 61 | break; |
| 62 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 63 | #ifdef SK_DAWN |
| 64 | case GrBackendApi::kDawn: |
| 65 | fDawnFormat = that.fDawnFormat; |
| 66 | break; |
| 67 | #endif |
Robert Phillips | b2adbef | 2019-07-02 16:33:05 -0400 | [diff] [blame] | 68 | case GrBackendApi::kMock: |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 69 | fMock = that.fMock; |
Robert Phillips | b2adbef | 2019-07-02 16:33:05 -0400 | [diff] [blame] | 70 | break; |
| 71 | default: |
| 72 | SK_ABORT("Unknown GrBackend"); |
| 73 | } |
| 74 | } |
| 75 | |
Ben Wagner | 833313b | 2020-03-23 17:22:24 -0400 | [diff] [blame] | 76 | GrBackendFormat& GrBackendFormat::operator=(const GrBackendFormat& that) { |
| 77 | if (this != &that) { |
| 78 | this->~GrBackendFormat(); |
| 79 | new (this) GrBackendFormat(that); |
| 80 | } |
| 81 | return *this; |
| 82 | } |
| 83 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 84 | #ifdef SK_GL |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 85 | |
| 86 | static GrTextureType gl_target_to_gr_target(GrGLenum target) { |
| 87 | switch (target) { |
| 88 | case GR_GL_TEXTURE_NONE: |
| 89 | return GrTextureType::kNone; |
| 90 | case GR_GL_TEXTURE_2D: |
| 91 | return GrTextureType::k2D; |
| 92 | case GR_GL_TEXTURE_RECTANGLE: |
| 93 | return GrTextureType::kRectangle; |
| 94 | case GR_GL_TEXTURE_EXTERNAL: |
| 95 | return GrTextureType::kExternal; |
| 96 | default: |
| 97 | SkUNREACHABLE; |
| 98 | } |
| 99 | } |
| 100 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 101 | GrBackendFormat::GrBackendFormat(GrGLenum format, GrGLenum target) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 102 | : fBackend(GrBackendApi::kOpenGL) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 103 | , fValid(true) |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 104 | , fGLFormat(format) |
| 105 | , fTextureType(gl_target_to_gr_target(target)) {} |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 106 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 107 | GrGLFormat GrBackendFormat::asGLFormat() const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 108 | if (this->isValid() && GrBackendApi::kOpenGL == fBackend) { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 109 | return GrGLFormatFromGLEnum(fGLFormat); |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 110 | } |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 111 | return GrGLFormat::kUnknown; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 112 | } |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 113 | #endif |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 114 | |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 115 | #ifdef SK_VULKAN |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 116 | GrBackendFormat GrBackendFormat::MakeVk(const GrVkYcbcrConversionInfo& ycbcrInfo) { |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 117 | SkASSERT(ycbcrInfo.isValid()); |
| 118 | return GrBackendFormat(ycbcrInfo.fFormat, ycbcrInfo); |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | GrBackendFormat::GrBackendFormat(VkFormat vkFormat, const GrVkYcbcrConversionInfo& ycbcrInfo) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 122 | : fBackend(GrBackendApi::kVulkan) |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 123 | , fValid(true) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 124 | , fTextureType(GrTextureType::k2D) { |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 125 | fVk.fFormat = vkFormat; |
| 126 | fVk.fYcbcrConversionInfo = ycbcrInfo; |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 127 | if (fVk.fYcbcrConversionInfo.isValid() && fVk.fYcbcrConversionInfo.fExternalFormat) { |
Greg Daniel | 387ec9a | 2019-03-07 16:44:54 -0500 | [diff] [blame] | 128 | fTextureType = GrTextureType::kExternal; |
| 129 | } |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 130 | } |
| 131 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 132 | bool GrBackendFormat::asVkFormat(VkFormat* format) const { |
| 133 | SkASSERT(format); |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 134 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 135 | *format = fVk.fFormat; |
| 136 | return true; |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 137 | } |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 138 | return false; |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | const GrVkYcbcrConversionInfo* GrBackendFormat::getVkYcbcrConversionInfo() const { |
| 142 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
| 143 | return &fVk.fYcbcrConversionInfo; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 144 | } |
| 145 | return nullptr; |
| 146 | } |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 147 | #endif |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 148 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 149 | #ifdef SK_DAWN |
Stephen White | 3cc8d4f | 2019-10-30 09:56:23 -0400 | [diff] [blame] | 150 | GrBackendFormat::GrBackendFormat(wgpu::TextureFormat format) |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 151 | : fBackend(GrBackendApi::kDawn) |
| 152 | , fValid(true) |
| 153 | , fDawnFormat(format) |
| 154 | , fTextureType(GrTextureType::k2D) { |
| 155 | } |
| 156 | |
Stephen White | 3cc8d4f | 2019-10-30 09:56:23 -0400 | [diff] [blame] | 157 | bool GrBackendFormat::asDawnFormat(wgpu::TextureFormat* format) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 158 | SkASSERT(format); |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 159 | if (this->isValid() && GrBackendApi::kDawn == fBackend) { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 160 | *format = fDawnFormat; |
| 161 | return true; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 162 | } |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 163 | return false; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 164 | } |
| 165 | #endif |
| 166 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 167 | #ifdef SK_METAL |
| 168 | GrBackendFormat::GrBackendFormat(GrMTLPixelFormat mtlFormat) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 169 | : fBackend(GrBackendApi::kMetal) |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 170 | , fValid(true) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 171 | , fMtlFormat(mtlFormat) |
| 172 | , fTextureType(GrTextureType::k2D) { |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 173 | } |
| 174 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 175 | GrMTLPixelFormat GrBackendFormat::asMtlFormat() const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 176 | if (this->isValid() && GrBackendApi::kMetal == fBackend) { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 177 | return fMtlFormat; |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 178 | } |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 179 | // MTLPixelFormatInvalid == 0 |
| 180 | return GrMTLPixelFormat(0); |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 181 | } |
| 182 | #endif |
| 183 | |
Jim Van Verth | c86c83c | 2020-02-27 15:48:24 -0500 | [diff] [blame] | 184 | #ifdef SK_DIRECT3D |
| 185 | GrBackendFormat::GrBackendFormat(DXGI_FORMAT dxgiFormat) |
| 186 | : fBackend(GrBackendApi::kDirect3D) |
| 187 | , fValid(true) |
| 188 | , fDxgiFormat(dxgiFormat) |
| 189 | , fTextureType(GrTextureType::k2D) { |
| 190 | } |
| 191 | |
| 192 | bool GrBackendFormat::asDxgiFormat(DXGI_FORMAT* dxgiFormat) const { |
| 193 | if (this->isValid() && GrBackendApi::kDirect3D == fBackend) { |
| 194 | *dxgiFormat = fDxgiFormat; |
| 195 | return true; |
| 196 | } |
| 197 | return false; |
| 198 | } |
| 199 | #endif |
| 200 | |
Greg Daniel | a7f69c2 | 2020-10-07 13:04:15 -0400 | [diff] [blame] | 201 | GrBackendFormat::GrBackendFormat(GrColorType colorType, SkImage::CompressionType compression, |
| 202 | bool isStencilFormat) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 203 | : fBackend(GrBackendApi::kMock) |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 204 | , fValid(true) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 205 | , fTextureType(GrTextureType::k2D) { |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 206 | fMock.fColorType = colorType; |
| 207 | fMock.fCompressionType = compression; |
Greg Daniel | a7f69c2 | 2020-10-07 13:04:15 -0400 | [diff] [blame] | 208 | fMock.fIsStencilFormat = isStencilFormat; |
| 209 | SkASSERT(this->validateMock()); |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 210 | } |
| 211 | |
Brian Salomon | dc8fcdb | 2020-03-26 16:45:05 -0400 | [diff] [blame] | 212 | uint32_t GrBackendFormat::channelMask() const { |
| 213 | if (!this->isValid()) { |
| 214 | return 0; |
| 215 | } |
| 216 | switch (fBackend) { |
| 217 | #ifdef SK_GL |
| 218 | case GrBackendApi::kOpenGL: |
| 219 | return GrGLFormatChannels(GrGLFormatFromGLEnum(fGLFormat)); |
| 220 | #endif |
| 221 | #ifdef SK_VULKAN |
| 222 | case GrBackendApi::kVulkan: |
| 223 | return GrVkFormatChannels(fVk.fFormat); |
| 224 | #endif |
| 225 | #ifdef SK_METAL |
| 226 | case GrBackendApi::kMetal: |
| 227 | return GrMtlFormatChannels(fMtlFormat); |
| 228 | #endif |
| 229 | #ifdef SK_DAWN |
| 230 | case GrBackendApi::kDawn: |
| 231 | return GrDawnFormatChannels(fDawnFormat); |
| 232 | #endif |
| 233 | #ifdef SK_DIRECT3D |
| 234 | case GrBackendApi::kDirect3D: |
| 235 | return GrDxgiFormatChannels(fDxgiFormat); |
| 236 | #endif |
| 237 | case GrBackendApi::kMock: |
| 238 | return GrColorTypeChannelFlags(fMock.fColorType); |
| 239 | |
| 240 | default: |
| 241 | return 0; |
| 242 | } |
| 243 | } |
| 244 | |
Brian Salomon | d6584bd | 2021-05-18 16:29:09 -0400 | [diff] [blame] | 245 | GrColorFormatDesc GrBackendFormat::desc() const { |
| 246 | if (!this->isValid()) { |
| 247 | return GrColorFormatDesc::MakeInvalid(); |
| 248 | } |
| 249 | switch (fBackend) { |
| 250 | #ifdef SK_GL |
| 251 | case GrBackendApi::kOpenGL: |
| 252 | return GrGLFormatDesc(GrGLFormatFromGLEnum(fGLFormat)); |
| 253 | #endif |
| 254 | #ifdef SK_VULKAN |
| 255 | case GrBackendApi::kVulkan: |
| 256 | return GrVkFormatDesc(fVk.fFormat); |
| 257 | #endif |
| 258 | #ifdef SK_METAL |
| 259 | case GrBackendApi::kMetal: |
| 260 | return GrMtlFormatDesc(fMtlFormat); |
| 261 | #endif |
| 262 | #ifdef SK_DAWN |
| 263 | case GrBackendApi::kDawn: |
| 264 | return GrDawnFormatDesc(fDawnFormat); |
| 265 | #endif |
| 266 | #ifdef SK_DIRECT3D |
| 267 | case GrBackendApi::kDirect3D: |
| 268 | return GrDxgiFormatDesc(fDxgiFormat); |
| 269 | #endif |
| 270 | case GrBackendApi::kMock: |
| 271 | return GrGetColorTypeDesc(fMock.fColorType); |
| 272 | |
| 273 | default: |
| 274 | return GrColorFormatDesc::MakeInvalid(); |
| 275 | } |
| 276 | } |
| 277 | |
Greg Daniel | a7f69c2 | 2020-10-07 13:04:15 -0400 | [diff] [blame] | 278 | #ifdef SK_DEBUG |
| 279 | bool GrBackendFormat::validateMock() const { |
| 280 | int trueStates = 0; |
| 281 | if (fMock.fCompressionType != SkImage::CompressionType::kNone) { |
| 282 | trueStates++; |
| 283 | } |
| 284 | if (fMock.fColorType != GrColorType::kUnknown) { |
| 285 | trueStates++; |
| 286 | } |
| 287 | if (fMock.fIsStencilFormat) { |
| 288 | trueStates++; |
| 289 | } |
| 290 | return trueStates == 1; |
| 291 | } |
| 292 | #endif |
| 293 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 294 | GrColorType GrBackendFormat::asMockColorType() const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 295 | if (this->isValid() && GrBackendApi::kMock == fBackend) { |
Greg Daniel | a7f69c2 | 2020-10-07 13:04:15 -0400 | [diff] [blame] | 296 | SkASSERT(this->validateMock()); |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 297 | return fMock.fColorType; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 298 | } |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 299 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 300 | return GrColorType::kUnknown; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 301 | } |
| 302 | |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 303 | SkImage::CompressionType GrBackendFormat::asMockCompressionType() const { |
| 304 | if (this->isValid() && GrBackendApi::kMock == fBackend) { |
Greg Daniel | a7f69c2 | 2020-10-07 13:04:15 -0400 | [diff] [blame] | 305 | SkASSERT(this->validateMock()); |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 306 | return fMock.fCompressionType; |
| 307 | } |
| 308 | |
| 309 | return SkImage::CompressionType::kNone; |
| 310 | } |
| 311 | |
Greg Daniel | a7f69c2 | 2020-10-07 13:04:15 -0400 | [diff] [blame] | 312 | bool GrBackendFormat::isMockStencilFormat() const { |
| 313 | if (this->isValid() && GrBackendApi::kMock == fBackend) { |
| 314 | SkASSERT(this->validateMock()); |
| 315 | return fMock.fIsStencilFormat; |
| 316 | } |
| 317 | |
| 318 | return false; |
| 319 | } |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 320 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 321 | GrBackendFormat GrBackendFormat::makeTexture2D() const { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 322 | GrBackendFormat copy = *this; |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 323 | #ifdef SK_VULKAN |
Greg Daniel | 387ec9a | 2019-03-07 16:44:54 -0500 | [diff] [blame] | 324 | if (const GrVkYcbcrConversionInfo* ycbcrInfo = this->getVkYcbcrConversionInfo()) { |
| 325 | if (ycbcrInfo->isValid()) { |
| 326 | // If we have a ycbcr we remove it from the backend format and set the VkFormat to |
| 327 | // R8G8B8A8_UNORM |
| 328 | SkASSERT(copy.fBackend == GrBackendApi::kVulkan); |
| 329 | copy.fVk.fYcbcrConversionInfo = GrVkYcbcrConversionInfo(); |
| 330 | copy.fVk.fFormat = VK_FORMAT_R8G8B8A8_UNORM; |
| 331 | } |
| 332 | } |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 333 | #endif |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 334 | copy.fTextureType = GrTextureType::k2D; |
| 335 | return copy; |
| 336 | } |
| 337 | |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 338 | GrBackendFormat GrBackendFormat::MakeMock(GrColorType colorType, |
Greg Daniel | a7f69c2 | 2020-10-07 13:04:15 -0400 | [diff] [blame] | 339 | SkImage::CompressionType compression, |
| 340 | bool isStencilFormat) { |
| 341 | return GrBackendFormat(colorType, compression, isStencilFormat); |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 342 | } |
| 343 | |
Greg Daniel | 45723ac | 2018-11-30 10:12:43 -0500 | [diff] [blame] | 344 | bool GrBackendFormat::operator==(const GrBackendFormat& that) const { |
| 345 | // Invalid GrBackendFormats are never equal to anything. |
| 346 | if (!fValid || !that.fValid) { |
| 347 | return false; |
| 348 | } |
| 349 | |
| 350 | if (fBackend != that.fBackend) { |
| 351 | return false; |
| 352 | } |
| 353 | |
| 354 | switch (fBackend) { |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 355 | #ifdef SK_GL |
Greg Daniel | 45723ac | 2018-11-30 10:12:43 -0500 | [diff] [blame] | 356 | case GrBackendApi::kOpenGL: |
| 357 | return fGLFormat == that.fGLFormat; |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 358 | break; |
| 359 | #endif |
Robert Phillips | 0efc01d | 2019-11-06 17:19:30 +0000 | [diff] [blame] | 360 | #ifdef SK_VULKAN |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 361 | case GrBackendApi::kVulkan: |
Greg Daniel | 45723ac | 2018-11-30 10:12:43 -0500 | [diff] [blame] | 362 | return fVk.fFormat == that.fVk.fFormat && |
| 363 | fVk.fYcbcrConversionInfo == that.fVk.fYcbcrConversionInfo; |
Robert Phillips | 0efc01d | 2019-11-06 17:19:30 +0000 | [diff] [blame] | 364 | break; |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 365 | #endif |
Greg Daniel | 45723ac | 2018-11-30 10:12:43 -0500 | [diff] [blame] | 366 | #ifdef SK_METAL |
| 367 | case GrBackendApi::kMetal: |
| 368 | return fMtlFormat == that.fMtlFormat; |
Robert Phillips | 0efc01d | 2019-11-06 17:19:30 +0000 | [diff] [blame] | 369 | break; |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 370 | #endif |
Robert Phillips | 0efc01d | 2019-11-06 17:19:30 +0000 | [diff] [blame] | 371 | #ifdef SK_DAWN |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 372 | case GrBackendApi::kDawn: |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 373 | return fDawnFormat == that.fDawnFormat; |
Robert Phillips | 0efc01d | 2019-11-06 17:19:30 +0000 | [diff] [blame] | 374 | break; |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 375 | #endif |
Greg Daniel | 45723ac | 2018-11-30 10:12:43 -0500 | [diff] [blame] | 376 | case GrBackendApi::kMock: |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 377 | return fMock.fColorType == that.fMock.fColorType && |
| 378 | fMock.fCompressionType == that.fMock.fCompressionType; |
Greg Daniel | 85da336 | 2020-03-09 15:18:35 -0400 | [diff] [blame] | 379 | #ifdef SK_DIRECT3D |
| 380 | case GrBackendApi::kDirect3D: |
| 381 | return fDxgiFormat == that.fDxgiFormat; |
| 382 | #endif |
Greg Daniel | 45723ac | 2018-11-30 10:12:43 -0500 | [diff] [blame] | 383 | default: |
| 384 | SK_ABORT("Unknown GrBackend"); |
| 385 | } |
| 386 | return false; |
| 387 | } |
| 388 | |
Robert Phillips | 8e54a6e | 2020-08-17 14:31:02 -0400 | [diff] [blame] | 389 | #if defined(SK_DEBUG) || GR_TEST_UTILS |
Robert Phillips | bac4672 | 2019-08-01 15:09:17 -0400 | [diff] [blame] | 390 | #include "include/core/SkString.h" |
Robert Phillips | bac4672 | 2019-08-01 15:09:17 -0400 | [diff] [blame] | 391 | |
| 392 | #ifdef SK_GL |
| 393 | #include "src/gpu/gl/GrGLUtil.h" |
| 394 | #endif |
| 395 | #ifdef SK_VULKAN |
| 396 | #include "src/gpu/vk/GrVkUtil.h" |
| 397 | #endif |
| 398 | |
| 399 | SkString GrBackendFormat::toStr() const { |
| 400 | SkString str; |
| 401 | |
| 402 | if (!fValid) { |
| 403 | str.append("invalid"); |
| 404 | return str; |
| 405 | } |
| 406 | |
| 407 | str.appendf("%s-", GrBackendApiToStr(fBackend)); |
| 408 | |
| 409 | switch (fBackend) { |
| 410 | case GrBackendApi::kOpenGL: |
| 411 | #ifdef SK_GL |
| 412 | str.append(GrGLFormatToStr(fGLFormat)); |
| 413 | #endif |
| 414 | break; |
| 415 | case GrBackendApi::kVulkan: |
| 416 | #ifdef SK_VULKAN |
| 417 | str.append(GrVkFormatToStr(fVk.fFormat)); |
| 418 | #endif |
| 419 | break; |
| 420 | case GrBackendApi::kMetal: |
| 421 | #ifdef SK_METAL |
| 422 | str.append(GrMtlFormatToStr(fMtlFormat)); |
| 423 | #endif |
| 424 | break; |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 425 | case GrBackendApi::kDirect3D: |
| 426 | #ifdef SK_DIRECT3D |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 427 | str.append(GrDxgiFormatToStr(fDxgiFormat)); |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 428 | #endif |
| 429 | break; |
Robert Phillips | bac4672 | 2019-08-01 15:09:17 -0400 | [diff] [blame] | 430 | case GrBackendApi::kDawn: |
| 431 | #ifdef SK_DAWN |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 432 | str.append(GrDawnFormatToStr(fDawnFormat)); |
Robert Phillips | bac4672 | 2019-08-01 15:09:17 -0400 | [diff] [blame] | 433 | #endif |
| 434 | break; |
| 435 | case GrBackendApi::kMock: |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 436 | str.append(GrColorTypeToStr(fMock.fColorType)); |
| 437 | str.appendf("-"); |
| 438 | str.append(GrCompressionTypeToStr(fMock.fCompressionType)); |
Robert Phillips | bac4672 | 2019-08-01 15:09:17 -0400 | [diff] [blame] | 439 | break; |
| 440 | } |
| 441 | |
| 442 | return str; |
| 443 | } |
| 444 | #endif |
| 445 | |
| 446 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 447 | GrBackendTexture::GrBackendTexture() : fIsValid(false) {} |
| 448 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 449 | #ifdef SK_DAWN |
| 450 | GrBackendTexture::GrBackendTexture(int width, |
| 451 | int height, |
Stephen White | f03c116 | 2020-01-28 12:39:45 -0500 | [diff] [blame] | 452 | const GrDawnTextureInfo& dawnInfo) |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 453 | : fIsValid(true) |
| 454 | , fWidth(width) |
| 455 | , fHeight(height) |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 456 | , fMipmapped(GrMipmapped(dawnInfo.fLevelCount > 1)) |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 457 | , fBackend(GrBackendApi::kDawn) |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 458 | , fTextureType(GrTextureType::k2D) |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 459 | , fDawnInfo(dawnInfo) {} |
| 460 | #endif |
| 461 | |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 462 | #ifdef SK_VULKAN |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 463 | GrBackendTexture::GrBackendTexture(int width, int height, const GrVkImageInfo& vkInfo) |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 464 | : GrBackendTexture(width, height, vkInfo, |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 465 | sk_sp<GrBackendSurfaceMutableStateImpl>( |
| 466 | new GrBackendSurfaceMutableStateImpl( |
| 467 | vkInfo.fImageLayout, vkInfo.fCurrentQueueFamily))) {} |
| 468 | |
Greg Daniel | 7b62dca | 2020-08-21 11:26:12 -0400 | [diff] [blame] | 469 | static const VkImageUsageFlags kDefaultUsageFlags = |
| 470 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 471 | |
| 472 | // We don't know if the backend texture is made renderable or not, so we default the usage flags |
| 473 | // to include color attachment as well. |
| 474 | static const VkImageUsageFlags kDefaultTexRTUsageFlags = |
| 475 | kDefaultUsageFlags | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 476 | |
| 477 | static GrVkImageInfo apply_default_usage_flags(const GrVkImageInfo& info, |
| 478 | VkImageUsageFlags defaultFlags) { |
| 479 | if (info.fImageUsageFlags == 0) { |
| 480 | GrVkImageInfo newInfo = info; |
| 481 | newInfo.fImageUsageFlags = defaultFlags; |
| 482 | return newInfo; |
| 483 | } |
| 484 | return info; |
| 485 | } |
| 486 | |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 487 | static GrTextureType vk_image_info_to_texture_type(const GrVkImageInfo& info) { |
| 488 | if (info.fYcbcrConversionInfo.isValid() && info.fYcbcrConversionInfo.fExternalFormat != 0) { |
| 489 | return GrTextureType::kExternal; |
| 490 | } |
| 491 | return GrTextureType::k2D; |
| 492 | } |
| 493 | |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 494 | GrBackendTexture::GrBackendTexture(int width, |
| 495 | int height, |
| 496 | const GrVkImageInfo& vkInfo, |
| 497 | sk_sp<GrBackendSurfaceMutableStateImpl> mutableState) |
| 498 | : fIsValid(true) |
| 499 | , fWidth(width) |
| 500 | , fHeight(height) |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 501 | , fMipmapped(GrMipmapped(vkInfo.fLevelCount > 1)) |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 502 | , fBackend(GrBackendApi::kVulkan) |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 503 | , fTextureType(vk_image_info_to_texture_type(vkInfo)) |
Greg Daniel | 7b62dca | 2020-08-21 11:26:12 -0400 | [diff] [blame] | 504 | , fVkInfo(apply_default_usage_flags(vkInfo, kDefaultTexRTUsageFlags)) |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 505 | , fMutableState(std::move(mutableState)) {} |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 506 | #endif |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 507 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 508 | #ifdef SK_GL |
| 509 | GrBackendTexture::GrBackendTexture(int width, |
| 510 | int height, |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 511 | GrMipmapped mipmapped, |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 512 | const GrGLTextureInfo glInfo, |
| 513 | sk_sp<GrGLTextureParameters> params) |
| 514 | : fIsValid(true) |
| 515 | , fWidth(width) |
| 516 | , fHeight(height) |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 517 | , fMipmapped(mipmapped) |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 518 | , fBackend(GrBackendApi::kOpenGL) |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 519 | , fTextureType(gl_target_to_gr_target(glInfo.fTarget)) |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 520 | , fGLInfo(glInfo, params.release()) {} |
| 521 | |
| 522 | sk_sp<GrGLTextureParameters> GrBackendTexture::getGLTextureParams() const { |
| 523 | if (fBackend != GrBackendApi::kOpenGL) { |
| 524 | return nullptr; |
| 525 | } |
| 526 | return fGLInfo.refParameters(); |
| 527 | } |
| 528 | #endif |
| 529 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 530 | #ifdef SK_METAL |
| 531 | GrBackendTexture::GrBackendTexture(int width, |
| 532 | int height, |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 533 | GrMipmapped mipmapped, |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 534 | const GrMtlTextureInfo& mtlInfo) |
| 535 | : fIsValid(true) |
| 536 | , fWidth(width) |
| 537 | , fHeight(height) |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 538 | , fMipmapped(mipmapped) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 539 | , fBackend(GrBackendApi::kMetal) |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 540 | , fTextureType(GrTextureType::k2D) |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 541 | , fMtlInfo(mtlInfo) {} |
| 542 | #endif |
| 543 | |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 544 | #ifdef SK_DIRECT3D |
Jim Van Verth | 6ec5688 | 2020-03-26 11:47:26 -0400 | [diff] [blame] | 545 | GrBackendTexture::GrBackendTexture(int width, int height, const GrD3DTextureResourceInfo& d3dInfo) |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 546 | : GrBackendTexture( |
| 547 | width, height, d3dInfo, |
| 548 | sk_sp<GrD3DResourceState>(new GrD3DResourceState( |
| 549 | static_cast<D3D12_RESOURCE_STATES>(d3dInfo.fResourceState)))) {} |
| 550 | |
| 551 | GrBackendTexture::GrBackendTexture(int width, |
| 552 | int height, |
Jim Van Verth | 6ec5688 | 2020-03-26 11:47:26 -0400 | [diff] [blame] | 553 | const GrD3DTextureResourceInfo& d3dInfo, |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 554 | sk_sp<GrD3DResourceState> state) |
| 555 | : fIsValid(true) |
| 556 | , fWidth(width) |
| 557 | , fHeight(height) |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 558 | , fMipmapped(GrMipmapped(d3dInfo.fLevelCount > 1)) |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 559 | , fBackend(GrBackendApi::kDirect3D) |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 560 | , fTextureType(GrTextureType::k2D) |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 561 | , fD3DInfo(d3dInfo, state.release()) {} |
| 562 | #endif |
| 563 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 564 | #ifdef SK_GL |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 565 | GrBackendTexture::GrBackendTexture(int width, |
| 566 | int height, |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 567 | GrMipmapped mipmapped, |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 568 | const GrGLTextureInfo& glInfo) |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 569 | : GrBackendTexture(width, height, mipmapped, glInfo, sk_make_sp<GrGLTextureParameters>()) { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 570 | // Make no assumptions about client's texture's parameters. |
| 571 | this->glTextureParametersModified(); |
| 572 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 573 | #endif |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 574 | |
| 575 | GrBackendTexture::GrBackendTexture(int width, |
| 576 | int height, |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 577 | GrMipmapped mipmapped, |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 578 | const GrMockTextureInfo& mockInfo) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 579 | : fIsValid(true) |
| 580 | , fWidth(width) |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 581 | , fHeight(height) |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 582 | , fMipmapped(mipmapped) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 583 | , fBackend(GrBackendApi::kMock) |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 584 | , fTextureType(GrTextureType::k2D) |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 585 | , fMockInfo(mockInfo) {} |
| 586 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 587 | GrBackendTexture::~GrBackendTexture() { |
| 588 | this->cleanup(); |
| 589 | } |
| 590 | |
| 591 | void GrBackendTexture::cleanup() { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 592 | #ifdef SK_GL |
| 593 | if (this->isValid() && GrBackendApi::kOpenGL == fBackend) { |
| 594 | fGLInfo.cleanup(); |
| 595 | } |
| 596 | #endif |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 597 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 598 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 599 | fVkInfo.cleanup(); |
| 600 | } |
| 601 | #endif |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 602 | #ifdef SK_DIRECT3D |
| 603 | if (this->isValid() && GrBackendApi::kDirect3D == fBackend) { |
| 604 | fD3DInfo.cleanup(); |
| 605 | } |
| 606 | #endif |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | GrBackendTexture::GrBackendTexture(const GrBackendTexture& that) : fIsValid(false) { |
| 610 | *this = that; |
| 611 | } |
| 612 | |
| 613 | GrBackendTexture& GrBackendTexture::operator=(const GrBackendTexture& that) { |
| 614 | if (!that.isValid()) { |
| 615 | this->cleanup(); |
| 616 | fIsValid = false; |
| 617 | return *this; |
Ben Wagner | a797cc9 | 2019-06-05 23:59:46 -0400 | [diff] [blame] | 618 | } else if (fIsValid && this->fBackend != that.fBackend) { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 619 | this->cleanup(); |
| 620 | fIsValid = false; |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 621 | } |
| 622 | fWidth = that.fWidth; |
| 623 | fHeight = that.fHeight; |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 624 | fMipmapped = that.fMipmapped; |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 625 | fBackend = that.fBackend; |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 626 | fTextureType = that.fTextureType; |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 627 | |
| 628 | switch (that.fBackend) { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 629 | #ifdef SK_GL |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 630 | case GrBackendApi::kOpenGL: |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 631 | fGLInfo.assign(that.fGLInfo, this->isValid()); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 632 | break; |
Mike Klein | a55e214 | 2018-10-03 16:34:11 +0000 | [diff] [blame] | 633 | #endif |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 634 | #ifdef SK_VULKAN |
| 635 | case GrBackendApi::kVulkan: |
| 636 | fVkInfo.assign(that.fVkInfo, this->isValid()); |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 637 | break; |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 638 | #endif |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 639 | #ifdef SK_METAL |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 640 | case GrBackendApi::kMetal: |
Jim Van Verth | 7730d7c | 2019-05-28 03:03:45 +0000 | [diff] [blame] | 641 | fMtlInfo = that.fMtlInfo; |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 642 | break; |
| 643 | #endif |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 644 | #ifdef SK_DIRECT3D |
| 645 | case GrBackendApi::kDirect3D: |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 646 | fD3DInfo.assign(that.fD3DInfo, this->isValid()); |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 647 | break; |
| 648 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 649 | #ifdef SK_DAWN |
| 650 | case GrBackendApi::kDawn: |
| 651 | fDawnInfo = that.fDawnInfo; |
| 652 | break; |
| 653 | #endif |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 654 | case GrBackendApi::kMock: |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 655 | fMockInfo = that.fMockInfo; |
| 656 | break; |
| 657 | default: |
| 658 | SK_ABORT("Unknown GrBackend"); |
| 659 | } |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 660 | fMutableState = that.fMutableState; |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 661 | fIsValid = true; |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 662 | return *this; |
| 663 | } |
| 664 | |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 665 | sk_sp<GrBackendSurfaceMutableStateImpl> GrBackendTexture::getMutableState() const { |
| 666 | return fMutableState; |
| 667 | } |
| 668 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 669 | #ifdef SK_DAWN |
Stephen White | f03c116 | 2020-01-28 12:39:45 -0500 | [diff] [blame] | 670 | bool GrBackendTexture::getDawnTextureInfo(GrDawnTextureInfo* outInfo) const { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 671 | if (this->isValid() && GrBackendApi::kDawn == fBackend) { |
| 672 | *outInfo = fDawnInfo; |
| 673 | return true; |
| 674 | } |
| 675 | return false; |
| 676 | } |
| 677 | #endif |
| 678 | |
Jim Van Verth | 2f7ee02 | 2021-09-18 16:33:57 +0000 | [diff] [blame] | 679 | #ifdef SK_VULKAN |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 680 | bool GrBackendTexture::getVkImageInfo(GrVkImageInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 681 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 682 | *outInfo = fVkInfo.snapImageInfo(fMutableState.get()); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 683 | return true; |
| 684 | } |
| 685 | return false; |
| 686 | } |
| 687 | |
| 688 | void GrBackendTexture::setVkImageLayout(VkImageLayout layout) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 689 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 690 | fMutableState->setImageLayout(layout); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 691 | } |
Jim Van Verth | 2f7ee02 | 2021-09-18 16:33:57 +0000 | [diff] [blame] | 692 | } |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 693 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 694 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 695 | #ifdef SK_METAL |
| 696 | bool GrBackendTexture::getMtlTextureInfo(GrMtlTextureInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 697 | if (this->isValid() && GrBackendApi::kMetal == fBackend) { |
Jim Van Verth | 7730d7c | 2019-05-28 03:03:45 +0000 | [diff] [blame] | 698 | *outInfo = fMtlInfo; |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 699 | return true; |
| 700 | } |
| 701 | return false; |
| 702 | } |
| 703 | #endif |
| 704 | |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 705 | #ifdef SK_DIRECT3D |
Jim Van Verth | 6ec5688 | 2020-03-26 11:47:26 -0400 | [diff] [blame] | 706 | bool GrBackendTexture::getD3DTextureResourceInfo(GrD3DTextureResourceInfo* outInfo) const { |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 707 | if (this->isValid() && GrBackendApi::kDirect3D == fBackend) { |
Jim Van Verth | 6ec5688 | 2020-03-26 11:47:26 -0400 | [diff] [blame] | 708 | *outInfo = fD3DInfo.snapTextureResourceInfo(); |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 709 | return true; |
| 710 | } |
| 711 | return false; |
| 712 | } |
| 713 | |
| 714 | void GrBackendTexture::setD3DResourceState(GrD3DResourceStateEnum state) { |
| 715 | if (this->isValid() && GrBackendApi::kDirect3D == fBackend) { |
| 716 | fD3DInfo.setResourceState(state); |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | sk_sp<GrD3DResourceState> GrBackendTexture::getGrD3DResourceState() const { |
| 721 | if (this->isValid() && GrBackendApi::kDirect3D == fBackend) { |
| 722 | return fD3DInfo.getGrD3DResourceState(); |
| 723 | } |
| 724 | return nullptr; |
| 725 | } |
| 726 | #endif |
| 727 | |
Jim Van Verth | 2f7ee02 | 2021-09-18 16:33:57 +0000 | [diff] [blame] | 728 | #ifdef SK_GL |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 729 | bool GrBackendTexture::getGLTextureInfo(GrGLTextureInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 730 | if (this->isValid() && GrBackendApi::kOpenGL == fBackend) { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 731 | *outInfo = fGLInfo.info(); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 732 | return true; |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 733 | } |
| 734 | else if (this->isValid() && GrBackendApi::kMock == fBackend) { |
Brian Osman | a7ef3a0 | 2019-03-27 15:54:14 -0400 | [diff] [blame] | 735 | // Hack! This allows some blink unit tests to work when using the Mock GrContext. |
| 736 | // Specifically, tests that rely on CanvasResourceProviderTextureGpuMemoryBuffer. |
| 737 | // If that code ever goes away (or ideally becomes backend-agnostic), this can go away. |
| 738 | *outInfo = GrGLTextureInfo{ GR_GL_TEXTURE_2D, |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 739 | static_cast<GrGLuint>(fMockInfo.id()), |
Brian Osman | a7ef3a0 | 2019-03-27 15:54:14 -0400 | [diff] [blame] | 740 | GR_GL_RGBA8 }; |
| 741 | return true; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 742 | } |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 743 | return false; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 744 | } |
| 745 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 746 | void GrBackendTexture::glTextureParametersModified() { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 747 | if (this->isValid() && fBackend == GrBackendApi::kOpenGL) { |
| 748 | fGLInfo.parameters()->invalidate(); |
| 749 | } |
Jim Van Verth | 2f7ee02 | 2021-09-18 16:33:57 +0000 | [diff] [blame] | 750 | } |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 751 | #endif |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 752 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 753 | bool GrBackendTexture::getMockTextureInfo(GrMockTextureInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 754 | if (this->isValid() && GrBackendApi::kMock == fBackend) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 755 | *outInfo = fMockInfo; |
| 756 | return true; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 757 | } |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 758 | return false; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 759 | } |
| 760 | |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 761 | void GrBackendTexture::setMutableState(const GrBackendSurfaceMutableState& state) { |
| 762 | fMutableState->set(state); |
| 763 | } |
| 764 | |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 765 | bool GrBackendTexture::isProtected() const { |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 766 | if (!this->isValid()) { |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 767 | return false; |
| 768 | } |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 769 | #ifdef SK_VULKAN |
| 770 | if (this->backend() == GrBackendApi::kVulkan) { |
| 771 | return fVkInfo.isProtected(); |
| 772 | } |
| 773 | #endif |
| 774 | return false; |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 775 | } |
| 776 | |
Brian Salomon | aad8315 | 2019-05-24 10:16:35 -0400 | [diff] [blame] | 777 | bool GrBackendTexture::isSameTexture(const GrBackendTexture& that) { |
| 778 | if (!this->isValid() || !that.isValid()) { |
| 779 | return false; |
| 780 | } |
| 781 | if (fBackend != that.fBackend) { |
| 782 | return false; |
| 783 | } |
| 784 | switch (fBackend) { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 785 | #ifdef SK_GL |
Brian Salomon | aad8315 | 2019-05-24 10:16:35 -0400 | [diff] [blame] | 786 | case GrBackendApi::kOpenGL: |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 787 | return fGLInfo.info().fID == that.fGLInfo.info().fID; |
| 788 | #endif |
Brian Salomon | aad8315 | 2019-05-24 10:16:35 -0400 | [diff] [blame] | 789 | #ifdef SK_VULKAN |
| 790 | case GrBackendApi::kVulkan: |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 791 | return fVkInfo.snapImageInfo(fMutableState.get()).fImage == |
| 792 | that.fVkInfo.snapImageInfo(that.fMutableState.get()).fImage; |
Brian Salomon | aad8315 | 2019-05-24 10:16:35 -0400 | [diff] [blame] | 793 | #endif |
| 794 | #ifdef SK_METAL |
| 795 | case GrBackendApi::kMetal: |
Jim Van Verth | 7730d7c | 2019-05-28 03:03:45 +0000 | [diff] [blame] | 796 | return this->fMtlInfo.fTexture == that.fMtlInfo.fTexture; |
Brian Salomon | aad8315 | 2019-05-24 10:16:35 -0400 | [diff] [blame] | 797 | #endif |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 798 | #ifdef SK_DIRECT3D |
| 799 | case GrBackendApi::kDirect3D: |
Jim Van Verth | de175ab | 2020-06-10 16:12:25 -0400 | [diff] [blame] | 800 | return fD3DInfo.snapTextureResourceInfo().fResource == |
| 801 | that.fD3DInfo.snapTextureResourceInfo().fResource; |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 802 | #endif |
Stephen White | d4b8bf9 | 2020-06-08 15:38:29 -0400 | [diff] [blame] | 803 | #ifdef SK_DAWN |
| 804 | case GrBackendApi::kDawn: { |
| 805 | return this->fDawnInfo.fTexture.Get() == that.fDawnInfo.fTexture.Get(); |
| 806 | } |
| 807 | #endif |
Brian Salomon | aad8315 | 2019-05-24 10:16:35 -0400 | [diff] [blame] | 808 | case GrBackendApi::kMock: |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 809 | return fMockInfo.id() == that.fMockInfo.id(); |
Brian Salomon | aad8315 | 2019-05-24 10:16:35 -0400 | [diff] [blame] | 810 | default: |
| 811 | return false; |
| 812 | } |
| 813 | } |
| 814 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 815 | GrBackendFormat GrBackendTexture::getBackendFormat() const { |
| 816 | if (!this->isValid()) { |
| 817 | return GrBackendFormat(); |
| 818 | } |
| 819 | switch (fBackend) { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 820 | #ifdef SK_GL |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 821 | case GrBackendApi::kOpenGL: |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 822 | return GrBackendFormat::MakeGL(fGLInfo.info().fFormat, fGLInfo.info().fTarget); |
| 823 | #endif |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 824 | #ifdef SK_VULKAN |
| 825 | case GrBackendApi::kVulkan: { |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 826 | auto info = fVkInfo.snapImageInfo(fMutableState.get()); |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 827 | if (info.fYcbcrConversionInfo.isValid()) { |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 828 | SkASSERT(info.fFormat == info.fYcbcrConversionInfo.fFormat); |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 829 | return GrBackendFormat::MakeVk(info.fYcbcrConversionInfo); |
| 830 | } |
| 831 | return GrBackendFormat::MakeVk(info.fFormat); |
| 832 | } |
| 833 | #endif |
| 834 | #ifdef SK_METAL |
| 835 | case GrBackendApi::kMetal: { |
| 836 | GrMtlTextureInfo mtlInfo; |
| 837 | SkAssertResult(this->getMtlTextureInfo(&mtlInfo)); |
| 838 | return GrBackendFormat::MakeMtl(GrGetMTLPixelFormatFromMtlTextureInfo(mtlInfo)); |
| 839 | } |
| 840 | #endif |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 841 | #ifdef SK_DIRECT3D |
| 842 | case GrBackendApi::kDirect3D: { |
Jim Van Verth | 6ec5688 | 2020-03-26 11:47:26 -0400 | [diff] [blame] | 843 | auto d3dInfo = fD3DInfo.snapTextureResourceInfo(); |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 844 | return GrBackendFormat::MakeDxgi(d3dInfo.fFormat); |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 845 | } |
| 846 | #endif |
| 847 | #ifdef SK_DAWN |
| 848 | case GrBackendApi::kDawn: { |
| 849 | return GrBackendFormat::MakeDawn(fDawnInfo.fFormat); |
| 850 | } |
| 851 | #endif |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 852 | case GrBackendApi::kMock: |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 853 | return fMockInfo.getBackendFormat(); |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 854 | default: |
| 855 | return GrBackendFormat(); |
| 856 | } |
| 857 | } |
| 858 | |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 859 | #if GR_TEST_UTILS |
| 860 | bool GrBackendTexture::TestingOnly_Equals(const GrBackendTexture& t0, const GrBackendTexture& t1) { |
| 861 | if (!t0.isValid() || !t1.isValid()) { |
| 862 | return false; // two invalid backend textures are not considered equal |
| 863 | } |
| 864 | |
| 865 | if (t0.fWidth != t1.fWidth || |
| 866 | t0.fHeight != t1.fHeight || |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 867 | t0.fMipmapped != t1.fMipmapped || |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 868 | t0.fBackend != t1.fBackend) { |
| 869 | return false; |
| 870 | } |
| 871 | |
Greg Daniel | 7f3408b | 2020-06-03 13:31:00 -0400 | [diff] [blame] | 872 | // For our tests when checking equality we are assuming the both backendTexture objects will |
| 873 | // be using the same mutable state object. |
| 874 | if (t0.fMutableState != t1.fMutableState) { |
| 875 | return false; |
| 876 | } |
| 877 | |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 878 | switch (t0.fBackend) { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 879 | #ifdef SK_GL |
| 880 | case GrBackendApi::kOpenGL: |
| 881 | return t0.fGLInfo.info() == t1.fGLInfo.info(); |
| 882 | #endif |
| 883 | case GrBackendApi::kMock: |
| 884 | return t0.fMockInfo == t1.fMockInfo; |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 885 | #ifdef SK_VULKAN |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 886 | case GrBackendApi::kVulkan: |
| 887 | return t0.fVkInfo == t1.fVkInfo; |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 888 | #endif |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 889 | #ifdef SK_METAL |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 890 | case GrBackendApi::kMetal: |
| 891 | return t0.fMtlInfo == t1.fMtlInfo; |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 892 | #endif |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 893 | #ifdef SK_DIRECT3D |
| 894 | case GrBackendApi::kDirect3D: |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 895 | return t0.fD3DInfo == t1.fD3DInfo; |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 896 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 897 | #ifdef SK_DAWN |
| 898 | case GrBackendApi::kDawn: |
| 899 | return t0.fDawnInfo == t1.fDawnInfo; |
| 900 | #endif |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 901 | default: |
| 902 | return false; |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 903 | } |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 904 | } |
| 905 | #endif |
| 906 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 907 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 908 | |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 909 | GrBackendRenderTarget::GrBackendRenderTarget() : fIsValid(false) {} |
| 910 | |
| 911 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 912 | #ifdef SK_DAWN |
| 913 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 914 | int height, |
| 915 | int sampleCnt, |
| 916 | int stencilBits, |
Stephen White | f03c116 | 2020-01-28 12:39:45 -0500 | [diff] [blame] | 917 | const GrDawnRenderTargetInfo& dawnInfo) |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 918 | : fIsValid(true) |
Stephen White | 3c0a50f | 2020-01-16 18:19:54 -0500 | [diff] [blame] | 919 | , fFramebufferOnly(true) |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 920 | , fWidth(width) |
| 921 | , fHeight(height) |
| 922 | , fSampleCnt(sampleCnt) |
| 923 | , fStencilBits(stencilBits) |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 924 | , fBackend(GrBackendApi::kDawn) |
| 925 | , fDawnInfo(dawnInfo) {} |
| 926 | #endif |
| 927 | |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 928 | #ifdef SK_VULKAN |
Brian Salomon | 57fd923 | 2020-09-28 17:02:49 -0400 | [diff] [blame] | 929 | static GrVkImageInfo resolve_vkii_sample_count(const GrVkImageInfo& vkII, int sidebandSampleCnt) { |
| 930 | auto result = vkII; |
| 931 | result.fSampleCount = std::max({vkII.fSampleCount, |
| 932 | static_cast<uint32_t>(sidebandSampleCnt), |
| 933 | 1U}); |
| 934 | return result; |
| 935 | } |
| 936 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 937 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 938 | int height, |
| 939 | int sampleCnt, |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 940 | const GrVkImageInfo& vkInfo) |
Brian Salomon | 57fd923 | 2020-09-28 17:02:49 -0400 | [diff] [blame] | 941 | : GrBackendRenderTarget(width, height, resolve_vkii_sample_count(vkInfo, sampleCnt)) {} |
| 942 | |
| 943 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 944 | int height, |
| 945 | const GrVkImageInfo& vkInfo) |
| 946 | : GrBackendRenderTarget(width, height, vkInfo, |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 947 | sk_sp<GrBackendSurfaceMutableStateImpl>( |
| 948 | new GrBackendSurfaceMutableStateImpl( |
Brian Salomon | 57fd923 | 2020-09-28 17:02:49 -0400 | [diff] [blame] | 949 | vkInfo.fImageLayout, vkInfo.fCurrentQueueFamily))) {} |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 950 | |
Greg Daniel | 7b62dca | 2020-08-21 11:26:12 -0400 | [diff] [blame] | 951 | static const VkImageUsageFlags kDefaultRTUsageFlags = |
| 952 | kDefaultUsageFlags | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 953 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 954 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 955 | int height, |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 956 | const GrVkImageInfo& vkInfo, |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 957 | sk_sp<GrBackendSurfaceMutableStateImpl> mutableState) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 958 | : fIsValid(true) |
| 959 | , fWidth(width) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 960 | , fHeight(height) |
Brian Salomon | 57fd923 | 2020-09-28 17:02:49 -0400 | [diff] [blame] | 961 | , fSampleCnt(std::max(1U, vkInfo.fSampleCount)) |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 962 | , fStencilBits(0) // We always create stencil buffers internally for vulkan |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 963 | , fBackend(GrBackendApi::kVulkan) |
Greg Daniel | 7b62dca | 2020-08-21 11:26:12 -0400 | [diff] [blame] | 964 | , fVkInfo(apply_default_usage_flags(vkInfo, kDefaultRTUsageFlags)) |
Brian Salomon | 57fd923 | 2020-09-28 17:02:49 -0400 | [diff] [blame] | 965 | , fMutableState(mutableState) {} |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 966 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 967 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 968 | #ifdef SK_METAL |
Brian Salomon | 8e0aa44 | 2020-09-30 13:50:18 -0400 | [diff] [blame] | 969 | GrBackendRenderTarget::GrBackendRenderTarget(int width, int height, const GrMtlTextureInfo& mtlInfo) |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 970 | : fIsValid(true) |
Brian Salomon | 8e0aa44 | 2020-09-30 13:50:18 -0400 | [diff] [blame] | 971 | , fFramebufferOnly(false) // TODO: set this from mtlInfo.fTexture->framebufferOnly |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 972 | , fWidth(width) |
| 973 | , fHeight(height) |
Brian Salomon | 8e0aa44 | 2020-09-30 13:50:18 -0400 | [diff] [blame] | 974 | , fSampleCnt(std::max(1, GrMtlTextureInfoSampleCount(mtlInfo))) |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 975 | , fStencilBits(0) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 976 | , fBackend(GrBackendApi::kMetal) |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 977 | , fMtlInfo(mtlInfo) {} |
Brian Salomon | 8e0aa44 | 2020-09-30 13:50:18 -0400 | [diff] [blame] | 978 | |
| 979 | GrBackendRenderTarget::GrBackendRenderTarget(int width, int height, |
| 980 | int sampleCount, |
| 981 | const GrMtlTextureInfo& mtlInfo) |
Jim Van Verth | d2567de | 2021-05-12 17:12:17 -0400 | [diff] [blame] | 982 | : GrBackendRenderTarget(width, height, mtlInfo) { |
| 983 | fSampleCnt = sampleCount; |
| 984 | } |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 985 | #endif |
| 986 | |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 987 | #ifdef SK_DIRECT3D |
Brian Salomon | 718ae76 | 2020-09-29 16:52:49 -0400 | [diff] [blame] | 988 | GrBackendRenderTarget::GrBackendRenderTarget(int width, int height, |
Jim Van Verth | 6ec5688 | 2020-03-26 11:47:26 -0400 | [diff] [blame] | 989 | const GrD3DTextureResourceInfo& d3dInfo) |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 990 | : GrBackendRenderTarget( |
Brian Salomon | 718ae76 | 2020-09-29 16:52:49 -0400 | [diff] [blame] | 991 | width, height, d3dInfo, |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 992 | sk_sp<GrD3DResourceState>(new GrD3DResourceState( |
| 993 | static_cast<D3D12_RESOURCE_STATES>(d3dInfo.fResourceState)))) {} |
| 994 | |
| 995 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 996 | int height, |
Jim Van Verth | 6ec5688 | 2020-03-26 11:47:26 -0400 | [diff] [blame] | 997 | const GrD3DTextureResourceInfo& d3dInfo, |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 998 | sk_sp<GrD3DResourceState> state) |
| 999 | : fIsValid(true) |
| 1000 | , fWidth(width) |
| 1001 | , fHeight(height) |
Brian Salomon | 718ae76 | 2020-09-29 16:52:49 -0400 | [diff] [blame] | 1002 | , fSampleCnt(std::max(1U, d3dInfo.fSampleCount)) |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 1003 | , fStencilBits(0) |
| 1004 | , fBackend(GrBackendApi::kDirect3D) |
| 1005 | , fD3DInfo(d3dInfo, state.release()) {} |
| 1006 | #endif |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 1007 | #ifdef SK_GL |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 1008 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 1009 | int height, |
| 1010 | int sampleCnt, |
| 1011 | int stencilBits, |
| 1012 | const GrGLFramebufferInfo& glInfo) |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 1013 | : fWidth(width) |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 1014 | , fHeight(height) |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1015 | , fSampleCnt(std::max(1, sampleCnt)) |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 1016 | , fStencilBits(stencilBits) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 1017 | , fBackend(GrBackendApi::kOpenGL) |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 1018 | , fGLInfo(glInfo) { |
| 1019 | fIsValid = SkToBool(glInfo.fFormat); // the glInfo must have a valid format |
| 1020 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 1021 | #endif |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 1022 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 1023 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 1024 | int height, |
| 1025 | int sampleCnt, |
| 1026 | int stencilBits, |
| 1027 | const GrMockRenderTargetInfo& mockInfo) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 1028 | : fIsValid(true) |
| 1029 | , fWidth(width) |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 1030 | , fHeight(height) |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1031 | , fSampleCnt(std::max(1, sampleCnt)) |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 1032 | , fStencilBits(stencilBits) |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 1033 | , fMockInfo(mockInfo) {} |
| 1034 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1035 | GrBackendRenderTarget::~GrBackendRenderTarget() { |
| 1036 | this->cleanup(); |
| 1037 | } |
| 1038 | |
| 1039 | void GrBackendRenderTarget::cleanup() { |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 1040 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 1041 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1042 | fVkInfo.cleanup(); |
| 1043 | } |
| 1044 | #endif |
Jim Van Verth | 682a2f4 | 2020-05-13 16:54:09 -0400 | [diff] [blame] | 1045 | #ifdef SK_DIRECT3D |
| 1046 | if (this->isValid() && GrBackendApi::kDirect3D == fBackend) { |
| 1047 | fD3DInfo.cleanup(); |
| 1048 | } |
| 1049 | #endif |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTarget& that) : fIsValid(false) { |
| 1053 | *this = that; |
| 1054 | } |
| 1055 | |
| 1056 | GrBackendRenderTarget& GrBackendRenderTarget::operator=(const GrBackendRenderTarget& that) { |
| 1057 | if (!that.isValid()) { |
| 1058 | this->cleanup(); |
| 1059 | fIsValid = false; |
| 1060 | return *this; |
Ben Wagner | a797cc9 | 2019-06-05 23:59:46 -0400 | [diff] [blame] | 1061 | } else if (fIsValid && this->fBackend != that.fBackend) { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 1062 | this->cleanup(); |
| 1063 | fIsValid = false; |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1064 | } |
| 1065 | fWidth = that.fWidth; |
| 1066 | fHeight = that.fHeight; |
| 1067 | fSampleCnt = that.fSampleCnt; |
| 1068 | fStencilBits = that.fStencilBits; |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1069 | fBackend = that.fBackend; |
| 1070 | |
| 1071 | switch (that.fBackend) { |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 1072 | #ifdef SK_GL |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 1073 | case GrBackendApi::kOpenGL: |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1074 | fGLInfo = that.fGLInfo; |
| 1075 | break; |
John Rosasco | 078cf3e | 2019-10-31 16:21:39 -0700 | [diff] [blame] | 1076 | #endif |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 1077 | #ifdef SK_VULKAN |
| 1078 | case GrBackendApi::kVulkan: |
| 1079 | fVkInfo.assign(that.fVkInfo, this->isValid()); |
Robert Phillips | 0efc01d | 2019-11-06 17:19:30 +0000 | [diff] [blame] | 1080 | break; |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 1081 | #endif |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1082 | #ifdef SK_METAL |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 1083 | case GrBackendApi::kMetal: |
Jim Van Verth | 7730d7c | 2019-05-28 03:03:45 +0000 | [diff] [blame] | 1084 | fMtlInfo = that.fMtlInfo; |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1085 | break; |
| 1086 | #endif |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 1087 | #ifdef SK_DIRECT3D |
| 1088 | case GrBackendApi::kDirect3D: |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 1089 | fD3DInfo.assign(that.fD3DInfo, this->isValid()); |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 1090 | break; |
| 1091 | #endif |
| 1092 | #ifdef SK_DAWN |
| 1093 | case GrBackendApi::kDawn: |
| 1094 | fDawnInfo = that.fDawnInfo; |
| 1095 | break; |
| 1096 | #endif |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 1097 | case GrBackendApi::kMock: |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1098 | fMockInfo = that.fMockInfo; |
| 1099 | break; |
| 1100 | default: |
| 1101 | SK_ABORT("Unknown GrBackend"); |
| 1102 | } |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 1103 | fMutableState = that.fMutableState; |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1104 | fIsValid = that.fIsValid; |
| 1105 | return *this; |
| 1106 | } |
| 1107 | |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 1108 | sk_sp<GrBackendSurfaceMutableStateImpl> GrBackendRenderTarget::getMutableState() const { |
| 1109 | return fMutableState; |
| 1110 | } |
| 1111 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1112 | #ifdef SK_DAWN |
Stephen White | f03c116 | 2020-01-28 12:39:45 -0500 | [diff] [blame] | 1113 | bool GrBackendRenderTarget::getDawnRenderTargetInfo(GrDawnRenderTargetInfo* outInfo) const { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1114 | if (this->isValid() && GrBackendApi::kDawn == fBackend) { |
| 1115 | *outInfo = fDawnInfo; |
| 1116 | return true; |
| 1117 | } |
| 1118 | return false; |
| 1119 | } |
| 1120 | #endif |
| 1121 | |
Jim Van Verth | 2f7ee02 | 2021-09-18 16:33:57 +0000 | [diff] [blame] | 1122 | #ifdef SK_VULKAN |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 1123 | bool GrBackendRenderTarget::getVkImageInfo(GrVkImageInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 1124 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 1125 | *outInfo = fVkInfo.snapImageInfo(fMutableState.get()); |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1126 | return true; |
| 1127 | } |
| 1128 | return false; |
| 1129 | } |
| 1130 | |
| 1131 | void GrBackendRenderTarget::setVkImageLayout(VkImageLayout layout) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 1132 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 1133 | fMutableState->setImageLayout(layout); |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1134 | } |
Jim Van Verth | 2f7ee02 | 2021-09-18 16:33:57 +0000 | [diff] [blame] | 1135 | } |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 1136 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 1137 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 1138 | #ifdef SK_METAL |
| 1139 | bool GrBackendRenderTarget::getMtlTextureInfo(GrMtlTextureInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 1140 | if (this->isValid() && GrBackendApi::kMetal == fBackend) { |
Jim Van Verth | 7730d7c | 2019-05-28 03:03:45 +0000 | [diff] [blame] | 1141 | *outInfo = fMtlInfo; |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 1142 | return true; |
| 1143 | } |
| 1144 | return false; |
| 1145 | } |
| 1146 | #endif |
| 1147 | |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 1148 | #ifdef SK_DIRECT3D |
Jim Van Verth | aa90dad | 2020-03-30 15:00:39 -0400 | [diff] [blame] | 1149 | bool GrBackendRenderTarget::getD3DTextureResourceInfo(GrD3DTextureResourceInfo* outInfo) const { |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 1150 | if (this->isValid() && GrBackendApi::kDirect3D == fBackend) { |
Jim Van Verth | 6ec5688 | 2020-03-26 11:47:26 -0400 | [diff] [blame] | 1151 | *outInfo = fD3DInfo.snapTextureResourceInfo(); |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 1152 | return true; |
| 1153 | } |
| 1154 | return false; |
| 1155 | } |
| 1156 | |
| 1157 | void GrBackendRenderTarget::setD3DResourceState(GrD3DResourceStateEnum state) { |
| 1158 | if (this->isValid() && GrBackendApi::kDirect3D == fBackend) { |
| 1159 | fD3DInfo.setResourceState(state); |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | sk_sp<GrD3DResourceState> GrBackendRenderTarget::getGrD3DResourceState() const { |
| 1164 | if (this->isValid() && GrBackendApi::kDirect3D == fBackend) { |
| 1165 | return fD3DInfo.getGrD3DResourceState(); |
| 1166 | } |
| 1167 | return nullptr; |
| 1168 | } |
| 1169 | #endif |
| 1170 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 1171 | #ifdef SK_GL |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1172 | bool GrBackendRenderTarget::getGLFramebufferInfo(GrGLFramebufferInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 1173 | if (this->isValid() && GrBackendApi::kOpenGL == fBackend) { |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1174 | *outInfo = fGLInfo; |
| 1175 | return true; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 1176 | } |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1177 | return false; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 1178 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 1179 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 1180 | |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 1181 | GrBackendFormat GrBackendRenderTarget::getBackendFormat() const { |
| 1182 | if (!this->isValid()) { |
| 1183 | return GrBackendFormat(); |
| 1184 | } |
| 1185 | switch (fBackend) { |
| 1186 | #ifdef SK_GL |
| 1187 | case GrBackendApi::kOpenGL: |
| 1188 | return GrBackendFormat::MakeGL(fGLInfo.fFormat, GR_GL_TEXTURE_NONE); |
| 1189 | #endif |
| 1190 | #ifdef SK_VULKAN |
| 1191 | case GrBackendApi::kVulkan: { |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 1192 | auto info = fVkInfo.snapImageInfo(fMutableState.get()); |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 1193 | if (info.fYcbcrConversionInfo.isValid()) { |
Sergey Ulanov | 2739fd2 | 2019-08-11 22:46:33 -0700 | [diff] [blame] | 1194 | SkASSERT(info.fFormat == info.fYcbcrConversionInfo.fFormat); |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 1195 | return GrBackendFormat::MakeVk(info.fYcbcrConversionInfo); |
| 1196 | } |
| 1197 | return GrBackendFormat::MakeVk(info.fFormat); |
| 1198 | } |
| 1199 | #endif |
| 1200 | #ifdef SK_METAL |
| 1201 | case GrBackendApi::kMetal: { |
| 1202 | GrMtlTextureInfo mtlInfo; |
| 1203 | SkAssertResult(this->getMtlTextureInfo(&mtlInfo)); |
| 1204 | return GrBackendFormat::MakeMtl(GrGetMTLPixelFormatFromMtlTextureInfo(mtlInfo)); |
| 1205 | } |
| 1206 | #endif |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 1207 | #ifdef SK_DIRECT3D |
| 1208 | case GrBackendApi::kDirect3D: { |
Jim Van Verth | 6ec5688 | 2020-03-26 11:47:26 -0400 | [diff] [blame] | 1209 | auto info = fD3DInfo.snapTextureResourceInfo(); |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 1210 | return GrBackendFormat::MakeDxgi(info.fFormat); |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 1211 | } |
| 1212 | #endif |
Stephen White | f03c116 | 2020-01-28 12:39:45 -0500 | [diff] [blame] | 1213 | #ifdef SK_DAWN |
| 1214 | case GrBackendApi::kDawn: { |
| 1215 | GrDawnRenderTargetInfo dawnInfo; |
| 1216 | SkAssertResult(this->getDawnRenderTargetInfo(&dawnInfo)); |
| 1217 | return GrBackendFormat::MakeDawn(dawnInfo.fFormat); |
| 1218 | } |
| 1219 | #endif |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 1220 | case GrBackendApi::kMock: |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 1221 | return fMockInfo.getBackendFormat(); |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 1222 | default: |
| 1223 | return GrBackendFormat(); |
| 1224 | } |
| 1225 | } |
| 1226 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1227 | bool GrBackendRenderTarget::getMockRenderTargetInfo(GrMockRenderTargetInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 1228 | if (this->isValid() && GrBackendApi::kMock == fBackend) { |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1229 | *outInfo = fMockInfo; |
| 1230 | return true; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 1231 | } |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 1232 | return false; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 1233 | } |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 1234 | |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 1235 | void GrBackendRenderTarget::setMutableState(const GrBackendSurfaceMutableState& state) { |
| 1236 | fMutableState->set(state); |
| 1237 | } |
| 1238 | |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 1239 | bool GrBackendRenderTarget::isProtected() const { |
| 1240 | if (!this->isValid() || this->backend() != GrBackendApi::kVulkan) { |
| 1241 | return false; |
| 1242 | } |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 1243 | #ifdef SK_VULKAN |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 1244 | return fVkInfo.isProtected(); |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 1245 | #else |
| 1246 | return false; |
| 1247 | #endif |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 1248 | } |
| 1249 | |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 1250 | #if GR_TEST_UTILS |
| 1251 | bool GrBackendRenderTarget::TestingOnly_Equals(const GrBackendRenderTarget& r0, |
| 1252 | const GrBackendRenderTarget& r1) { |
| 1253 | if (!r0.isValid() || !r1.isValid()) { |
| 1254 | return false; // two invalid backend rendertargets are not considered equal |
| 1255 | } |
| 1256 | |
| 1257 | if (r0.fWidth != r1.fWidth || |
| 1258 | r0.fHeight != r1.fHeight || |
| 1259 | r0.fSampleCnt != r1.fSampleCnt || |
| 1260 | r0.fStencilBits != r1.fStencilBits || |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 1261 | r0.fBackend != r1.fBackend) { |
| 1262 | return false; |
| 1263 | } |
| 1264 | |
| 1265 | switch (r0.fBackend) { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 1266 | #ifdef SK_GL |
| 1267 | case GrBackendApi::kOpenGL: |
| 1268 | return r0.fGLInfo == r1.fGLInfo; |
| 1269 | #endif |
| 1270 | case GrBackendApi::kMock: |
| 1271 | return r0.fMockInfo == r1.fMockInfo; |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 1272 | #ifdef SK_VULKAN |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 1273 | case GrBackendApi::kVulkan: |
| 1274 | return r0.fVkInfo == r1.fVkInfo; |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 1275 | #endif |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 1276 | #ifdef SK_METAL |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 1277 | case GrBackendApi::kMetal: |
| 1278 | return r0.fMtlInfo == r1.fMtlInfo; |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 1279 | #endif |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 1280 | #ifdef SK_DIRECT3D |
| 1281 | case GrBackendApi::kDirect3D: |
Jim Van Verth | 05d0919 | 2020-03-20 11:23:39 -0400 | [diff] [blame] | 1282 | return r0.fD3DInfo == r1.fD3DInfo; |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 1283 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1284 | #ifdef SK_DAWN |
| 1285 | case GrBackendApi::kDawn: |
| 1286 | return r0.fDawnInfo == r1.fDawnInfo; |
| 1287 | #endif |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 1288 | default: |
| 1289 | return false; |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | SkASSERT(0); |
| 1293 | return false; |
| 1294 | } |
| 1295 | #endif |