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