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 | |
Greg Daniel | 54bfb18 | 2018-11-20 17:12:36 -0500 | [diff] [blame] | 8 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 9 | #include "GrBackendSurface.h" |
| 10 | |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 11 | #include "gl/GrGLUtil.h" |
| 12 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 13 | #ifdef SK_VULKAN |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 14 | #include "vk/GrVkImageLayout.h" |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 15 | #include "vk/GrVkTypes.h" |
| 16 | #include "vk/GrVkUtil.h" |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 17 | #endif |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 18 | #ifdef SK_METAL |
| 19 | #include "mtl/GrMtlTypes.h" |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 20 | #include "mtl/GrMtlCppUtil.h" |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 21 | #endif |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 22 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 23 | GrBackendFormat::GrBackendFormat(GrGLenum format, GrGLenum target) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 24 | : fBackend(GrBackendApi::kOpenGL) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 25 | , fValid(true) |
| 26 | , fGLFormat(format) { |
| 27 | switch (target) { |
| 28 | case GR_GL_TEXTURE_2D: |
| 29 | fTextureType = GrTextureType::k2D; |
| 30 | break; |
| 31 | case GR_GL_TEXTURE_RECTANGLE: |
| 32 | fTextureType = GrTextureType::kRectangle; |
| 33 | break; |
| 34 | case GR_GL_TEXTURE_EXTERNAL: |
| 35 | fTextureType = GrTextureType::kExternal; |
| 36 | break; |
| 37 | default: |
| 38 | SK_ABORT("Unexpected texture target"); |
| 39 | } |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | const GrGLenum* GrBackendFormat::getGLFormat() const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 43 | if (this->isValid() && GrBackendApi::kOpenGL == fBackend) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 44 | return &fGLFormat; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 45 | } |
| 46 | return nullptr; |
| 47 | } |
| 48 | |
| 49 | const GrGLenum* GrBackendFormat::getGLTarget() const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 50 | if (this->isValid() && GrBackendApi::kOpenGL == fBackend) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 51 | static constexpr GrGLenum k2D = GR_GL_TEXTURE_2D; |
| 52 | static constexpr GrGLenum kRect = GR_GL_TEXTURE_RECTANGLE; |
| 53 | static constexpr GrGLenum kExternal = GR_GL_TEXTURE_EXTERNAL; |
| 54 | switch (fTextureType) { |
| 55 | case GrTextureType::k2D: |
| 56 | return &k2D; |
| 57 | case GrTextureType::kRectangle: |
| 58 | return &kRect; |
| 59 | case GrTextureType::kExternal: |
| 60 | return &kExternal; |
| 61 | } |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 62 | } |
| 63 | return nullptr; |
| 64 | } |
| 65 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 66 | GrBackendFormat GrBackendFormat::MakeVk(const GrVkYcbcrConversionInfo& ycbcrInfo) { |
| 67 | #ifdef SK_BUILD_FOR_ANDROID |
| 68 | return GrBackendFormat(VK_FORMAT_UNDEFINED, ycbcrInfo); |
| 69 | #else |
| 70 | return GrBackendFormat(); |
| 71 | #endif |
| 72 | } |
| 73 | |
| 74 | GrBackendFormat::GrBackendFormat(VkFormat vkFormat, const GrVkYcbcrConversionInfo& ycbcrInfo) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 75 | : fBackend(GrBackendApi::kVulkan) |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 76 | #ifdef SK_VULKAN |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 77 | , fValid(true) |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 78 | #else |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 79 | , fValid(false) |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 80 | #endif |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 81 | , fTextureType(GrTextureType::k2D) { |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 82 | fVk.fFormat = vkFormat; |
| 83 | fVk.fYcbcrConversionInfo = ycbcrInfo; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | const VkFormat* GrBackendFormat::getVkFormat() const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 87 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 88 | return &fVk.fFormat; |
| 89 | } |
| 90 | return nullptr; |
| 91 | } |
| 92 | |
| 93 | const GrVkYcbcrConversionInfo* GrBackendFormat::getVkYcbcrConversionInfo() const { |
| 94 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
| 95 | return &fVk.fYcbcrConversionInfo; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 96 | } |
| 97 | return nullptr; |
| 98 | } |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 99 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 100 | #ifdef SK_METAL |
| 101 | GrBackendFormat::GrBackendFormat(GrMTLPixelFormat mtlFormat) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 102 | : fBackend(GrBackendApi::kMetal) |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 103 | , fValid(true) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 104 | , fMtlFormat(mtlFormat) |
| 105 | , fTextureType(GrTextureType::k2D) { |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | const GrMTLPixelFormat* GrBackendFormat::getMtlFormat() const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 109 | if (this->isValid() && GrBackendApi::kMetal == fBackend) { |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 110 | return &fMtlFormat; |
| 111 | } |
| 112 | return nullptr; |
| 113 | } |
| 114 | #endif |
| 115 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 116 | GrBackendFormat::GrBackendFormat(GrPixelConfig config) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 117 | : fBackend(GrBackendApi::kMock) |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 118 | , fValid(true) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 119 | , fMockFormat(config) |
| 120 | , fTextureType(GrTextureType::k2D) { |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | const GrPixelConfig* GrBackendFormat::getMockFormat() const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 124 | if (this->isValid() && GrBackendApi::kMock == fBackend) { |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 125 | return &fMockFormat; |
| 126 | } |
| 127 | return nullptr; |
| 128 | } |
| 129 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 130 | GrBackendFormat GrBackendFormat::makeTexture2D() const { |
| 131 | // TODO: once we support ycbcr conversions in Vulkan we need to check if we are using an |
| 132 | // external format since they will not be able to be made into a Texture2D. |
| 133 | GrBackendFormat copy = *this; |
| 134 | copy.fTextureType = GrTextureType::k2D; |
| 135 | return copy; |
| 136 | } |
| 137 | |
Greg Daniel | 45723ac | 2018-11-30 10:12:43 -0500 | [diff] [blame] | 138 | bool GrBackendFormat::operator==(const GrBackendFormat& that) const { |
| 139 | // Invalid GrBackendFormats are never equal to anything. |
| 140 | if (!fValid || !that.fValid) { |
| 141 | return false; |
| 142 | } |
| 143 | |
| 144 | if (fBackend != that.fBackend) { |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | switch (fBackend) { |
| 149 | case GrBackendApi::kOpenGL: |
| 150 | return fGLFormat == that.fGLFormat; |
| 151 | case GrBackendApi::kVulkan: |
| 152 | #ifdef SK_VULKAN |
| 153 | return fVk.fFormat == that.fVk.fFormat && |
| 154 | fVk.fYcbcrConversionInfo == that.fVk.fYcbcrConversionInfo; |
| 155 | #endif |
| 156 | break; |
| 157 | #ifdef SK_METAL |
| 158 | case GrBackendApi::kMetal: |
| 159 | return fMtlFormat == that.fMtlFormat; |
| 160 | #endif |
| 161 | break; |
| 162 | case GrBackendApi::kMock: |
| 163 | return fMockFormat == that.fMockFormat; |
| 164 | default: |
| 165 | SK_ABORT("Unknown GrBackend"); |
| 166 | } |
| 167 | return false; |
| 168 | } |
| 169 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 170 | GrBackendTexture::GrBackendTexture(int width, |
| 171 | int height, |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 172 | const GrVkImageInfo& vkInfo) |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 173 | #ifdef SK_VULKAN |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 174 | : GrBackendTexture(width, height, vkInfo, |
| 175 | sk_sp<GrVkImageLayout>(new GrVkImageLayout(vkInfo.fImageLayout))) {} |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 176 | #else |
| 177 | : fIsValid(false) {} |
| 178 | #endif |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 179 | |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 180 | #ifdef SK_VULKAN |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 181 | GrBackendTexture::GrBackendTexture(int width, |
| 182 | int height, |
| 183 | const GrVkImageInfo& vkInfo, |
| 184 | sk_sp<GrVkImageLayout> layout) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 185 | : fIsValid(true) |
| 186 | , fWidth(width) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 187 | , fHeight(height) |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 188 | , fConfig(kUnknown_GrPixelConfig) |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 189 | , fMipMapped(GrMipMapped(vkInfo.fLevelCount > 1)) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 190 | , fBackend(GrBackendApi::kVulkan) |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 191 | , fVkInfo(vkInfo, layout.release()) { |
| 192 | } |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 193 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 194 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 195 | #ifdef SK_METAL |
| 196 | GrBackendTexture::GrBackendTexture(int width, |
| 197 | int height, |
| 198 | GrMipMapped mipMapped, |
| 199 | const GrMtlTextureInfo& mtlInfo) |
| 200 | : fIsValid(true) |
| 201 | , fWidth(width) |
| 202 | , fHeight(height) |
| 203 | , fConfig(GrPixelConfig::kUnknown_GrPixelConfig) |
| 204 | , fMipMapped(mipMapped) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 205 | , fBackend(GrBackendApi::kMetal) |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 206 | , fMtlInfo(mtlInfo) {} |
| 207 | #endif |
| 208 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 209 | GrBackendTexture::GrBackendTexture(int width, |
| 210 | int height, |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 211 | GrMipMapped mipMapped, |
| 212 | const GrGLTextureInfo& glInfo) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 213 | : fIsValid(true) |
| 214 | , fWidth(width) |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 215 | , fHeight(height) |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 216 | , fConfig(kUnknown_GrPixelConfig) |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 217 | , fMipMapped(mipMapped) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 218 | , fBackend(GrBackendApi::kOpenGL) |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 219 | , fGLInfo(glInfo) {} |
| 220 | |
| 221 | GrBackendTexture::GrBackendTexture(int width, |
| 222 | int height, |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 223 | GrMipMapped mipMapped, |
| 224 | const GrMockTextureInfo& mockInfo) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 225 | : fIsValid(true) |
| 226 | , fWidth(width) |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 227 | , fHeight(height) |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 228 | , fConfig(mockInfo.fConfig) |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 229 | , fMipMapped(mipMapped) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 230 | , fBackend(GrBackendApi::kMock) |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 231 | , fMockInfo(mockInfo) {} |
| 232 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 233 | GrBackendTexture::~GrBackendTexture() { |
| 234 | this->cleanup(); |
| 235 | } |
| 236 | |
| 237 | void GrBackendTexture::cleanup() { |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 238 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 239 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 240 | fVkInfo.cleanup(); |
| 241 | } |
| 242 | #endif |
| 243 | } |
| 244 | |
| 245 | GrBackendTexture::GrBackendTexture(const GrBackendTexture& that) : fIsValid(false) { |
| 246 | *this = that; |
| 247 | } |
| 248 | |
| 249 | GrBackendTexture& GrBackendTexture::operator=(const GrBackendTexture& that) { |
| 250 | if (!that.isValid()) { |
| 251 | this->cleanup(); |
| 252 | fIsValid = false; |
| 253 | return *this; |
| 254 | } |
| 255 | fWidth = that.fWidth; |
| 256 | fHeight = that.fHeight; |
| 257 | fConfig = that.fConfig; |
| 258 | fMipMapped = that.fMipMapped; |
| 259 | fBackend = that.fBackend; |
| 260 | |
| 261 | switch (that.fBackend) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 262 | case GrBackendApi::kOpenGL: |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 263 | fGLInfo = that.fGLInfo; |
| 264 | break; |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 265 | case GrBackendApi::kVulkan: |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 266 | #ifdef SK_VULKAN |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 267 | fVkInfo.assign(that.fVkInfo, this->isValid()); |
Mike Klein | a55e214 | 2018-10-03 16:34:11 +0000 | [diff] [blame] | 268 | #endif |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 269 | break; |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 270 | #ifdef SK_METAL |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 271 | case GrBackendApi::kMetal: |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 272 | fMtlInfo = that.fMtlInfo; |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 273 | break; |
| 274 | #endif |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 275 | case GrBackendApi::kMock: |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 276 | fMockInfo = that.fMockInfo; |
| 277 | break; |
| 278 | default: |
| 279 | SK_ABORT("Unknown GrBackend"); |
| 280 | } |
| 281 | fIsValid = that.fIsValid; |
| 282 | return *this; |
| 283 | } |
| 284 | |
Mike Klein | a55e214 | 2018-10-03 16:34:11 +0000 | [diff] [blame] | 285 | bool GrBackendTexture::getVkImageInfo(GrVkImageInfo* outInfo) const { |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 286 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 287 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 288 | *outInfo = fVkInfo.snapImageInfo(); |
| 289 | return true; |
| 290 | } |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 291 | #endif |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 292 | return false; |
| 293 | } |
| 294 | |
| 295 | void GrBackendTexture::setVkImageLayout(VkImageLayout layout) { |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 296 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 297 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 298 | fVkInfo.setImageLayout(layout); |
| 299 | } |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 300 | #endif |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 301 | } |
| 302 | |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 303 | // We need a stubbed version of GrVkImageLayout for non vulkan builds |
| 304 | #ifndef SK_VULKAN |
| 305 | class GrVkImageLayout : public SkRefCnt { |
| 306 | GrVkImageLayout(VkImageLayout layout) {} |
| 307 | }; |
| 308 | #endif |
| 309 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 310 | sk_sp<GrVkImageLayout> GrBackendTexture::getGrVkImageLayout() const { |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 311 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 312 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 313 | return fVkInfo.getGrVkImageLayout(); |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 314 | } |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 315 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 316 | return nullptr; |
| 317 | } |
| 318 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 319 | #ifdef SK_METAL |
| 320 | bool GrBackendTexture::getMtlTextureInfo(GrMtlTextureInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 321 | if (this->isValid() && GrBackendApi::kMetal == fBackend) { |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 322 | *outInfo = fMtlInfo; |
| 323 | return true; |
| 324 | } |
| 325 | return false; |
| 326 | } |
| 327 | #endif |
| 328 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 329 | bool GrBackendTexture::getGLTextureInfo(GrGLTextureInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 330 | if (this->isValid() && GrBackendApi::kOpenGL == fBackend) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 331 | *outInfo = fGLInfo; |
| 332 | return true; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 333 | } |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 334 | return false; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 335 | } |
| 336 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 337 | bool GrBackendTexture::getMockTextureInfo(GrMockTextureInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 338 | if (this->isValid() && GrBackendApi::kMock == fBackend) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 339 | *outInfo = fMockInfo; |
| 340 | return true; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 341 | } |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 342 | return false; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 343 | } |
| 344 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 345 | GrBackendFormat GrBackendTexture::getBackendFormat() const { |
| 346 | if (!this->isValid()) { |
| 347 | return GrBackendFormat(); |
| 348 | } |
| 349 | switch (fBackend) { |
| 350 | case GrBackendApi::kOpenGL: |
| 351 | return GrBackendFormat::MakeGL(fGLInfo.fFormat, fGLInfo.fTarget); |
| 352 | #ifdef SK_VULKAN |
| 353 | case GrBackendApi::kVulkan: { |
| 354 | auto info = fVkInfo.snapImageInfo(); |
| 355 | if (info.fYcbcrConversionInfo.isValid()) { |
| 356 | SkASSERT(info.fFormat == VK_FORMAT_UNDEFINED); |
| 357 | return GrBackendFormat::MakeVk(info.fYcbcrConversionInfo); |
| 358 | } |
| 359 | return GrBackendFormat::MakeVk(info.fFormat); |
| 360 | } |
| 361 | #endif |
| 362 | #ifdef SK_METAL |
| 363 | case GrBackendApi::kMetal: { |
| 364 | GrMtlTextureInfo mtlInfo; |
| 365 | SkAssertResult(this->getMtlTextureInfo(&mtlInfo)); |
| 366 | return GrBackendFormat::MakeMtl(GrGetMTLPixelFormatFromMtlTextureInfo(mtlInfo)); |
| 367 | } |
| 368 | #endif |
| 369 | case GrBackendApi::kMock: |
| 370 | return GrBackendFormat::MakeMock(fMockInfo.fConfig); |
| 371 | default: |
| 372 | return GrBackendFormat(); |
| 373 | } |
| 374 | } |
| 375 | |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 376 | #if GR_TEST_UTILS |
| 377 | bool GrBackendTexture::TestingOnly_Equals(const GrBackendTexture& t0, const GrBackendTexture& t1) { |
| 378 | if (!t0.isValid() || !t1.isValid()) { |
| 379 | return false; // two invalid backend textures are not considered equal |
| 380 | } |
| 381 | |
| 382 | if (t0.fWidth != t1.fWidth || |
| 383 | t0.fHeight != t1.fHeight || |
| 384 | t0.fConfig != t1.fConfig || |
| 385 | t0.fMipMapped != t1.fMipMapped || |
| 386 | t0.fBackend != t1.fBackend) { |
| 387 | return false; |
| 388 | } |
| 389 | |
| 390 | switch (t0.fBackend) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 391 | case GrBackendApi::kOpenGL: |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 392 | return t0.fGLInfo == t1.fGLInfo; |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 393 | case GrBackendApi::kMock: |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 394 | return t0.fMockInfo == t1.fMockInfo; |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 395 | case GrBackendApi::kVulkan: |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 396 | #ifdef SK_VULKAN |
| 397 | return t0.fVkInfo == t1.fVkInfo; |
| 398 | #else |
| 399 | // fall through |
| 400 | #endif |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 401 | case GrBackendApi::kMetal: |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 402 | #ifdef SK_METAL |
| 403 | return t0.fMtlInfo == t1.fMtlInfo; |
| 404 | #else |
| 405 | // fall through |
| 406 | #endif |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 407 | default: |
| 408 | return false; |
| 409 | } |
| 410 | |
| 411 | SkASSERT(0); |
| 412 | return false; |
| 413 | } |
| 414 | #endif |
| 415 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 416 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 417 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 418 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 419 | int height, |
| 420 | int sampleCnt, |
| 421 | int stencilBits, |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 422 | const GrVkImageInfo& vkInfo) |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 423 | : GrBackendRenderTarget(width, height, sampleCnt, vkInfo) { |
| 424 | // This is a deprecated constructor that takes a bogus stencil bits. |
| 425 | SkASSERT(0 == stencilBits); |
| 426 | } |
| 427 | |
| 428 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 429 | int height, |
| 430 | int sampleCnt, |
| 431 | const GrVkImageInfo& vkInfo) |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 432 | #ifdef SK_VULKAN |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 433 | : GrBackendRenderTarget(width, height, sampleCnt, vkInfo, |
| 434 | sk_sp<GrVkImageLayout>(new GrVkImageLayout(vkInfo.fImageLayout))) {} |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 435 | #else |
| 436 | : fIsValid(false) {} |
| 437 | #endif |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 438 | |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 439 | #ifdef SK_VULKAN |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 440 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 441 | int height, |
| 442 | int sampleCnt, |
| 443 | const GrVkImageInfo& vkInfo, |
| 444 | sk_sp<GrVkImageLayout> layout) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 445 | : fIsValid(true) |
| 446 | , fWidth(width) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 447 | , fHeight(height) |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 448 | , fSampleCnt(SkTMax(1, sampleCnt)) |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 449 | , fStencilBits(0) // We always create stencil buffers internally for vulkan |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 450 | , fConfig(kUnknown_GrPixelConfig) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 451 | , fBackend(GrBackendApi::kVulkan) |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 452 | , fVkInfo(vkInfo, layout.release()) {} |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 453 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 454 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 455 | #ifdef SK_METAL |
| 456 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 457 | int height, |
| 458 | int sampleCnt, |
| 459 | const GrMtlTextureInfo& mtlInfo) |
| 460 | : fIsValid(true) |
| 461 | , fWidth(width) |
| 462 | , fHeight(height) |
| 463 | , fSampleCnt(SkTMax(1, sampleCnt)) |
| 464 | , fStencilBits(0) |
| 465 | , fConfig(GrPixelConfig::kUnknown_GrPixelConfig) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 466 | , fBackend(GrBackendApi::kMetal) |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 467 | , fMtlInfo(mtlInfo) {} |
| 468 | #endif |
| 469 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 470 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 471 | int height, |
| 472 | int sampleCnt, |
| 473 | int stencilBits, |
| 474 | const GrGLFramebufferInfo& glInfo) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 475 | : fIsValid(true) |
| 476 | , fWidth(width) |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 477 | , fHeight(height) |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 478 | , fSampleCnt(SkTMax(1, sampleCnt)) |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 479 | , fStencilBits(stencilBits) |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 480 | , fConfig(kUnknown_GrPixelConfig) |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 481 | , fBackend(GrBackendApi::kOpenGL) |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 482 | , fGLInfo(glInfo) {} |
| 483 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 484 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 485 | int height, |
| 486 | int sampleCnt, |
| 487 | int stencilBits, |
| 488 | const GrMockRenderTargetInfo& mockInfo) |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 489 | : fIsValid(true) |
| 490 | , fWidth(width) |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 491 | , fHeight(height) |
| 492 | , fSampleCnt(SkTMax(1, sampleCnt)) |
| 493 | , fStencilBits(stencilBits) |
| 494 | , fConfig(mockInfo.fConfig) |
| 495 | , fMockInfo(mockInfo) {} |
| 496 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 497 | GrBackendRenderTarget::~GrBackendRenderTarget() { |
| 498 | this->cleanup(); |
| 499 | } |
| 500 | |
| 501 | void GrBackendRenderTarget::cleanup() { |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 502 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 503 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 504 | fVkInfo.cleanup(); |
| 505 | } |
| 506 | #endif |
| 507 | } |
| 508 | |
| 509 | GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTarget& that) : fIsValid(false) { |
| 510 | *this = that; |
| 511 | } |
| 512 | |
| 513 | GrBackendRenderTarget& GrBackendRenderTarget::operator=(const GrBackendRenderTarget& that) { |
| 514 | if (!that.isValid()) { |
| 515 | this->cleanup(); |
| 516 | fIsValid = false; |
| 517 | return *this; |
| 518 | } |
| 519 | fWidth = that.fWidth; |
| 520 | fHeight = that.fHeight; |
| 521 | fSampleCnt = that.fSampleCnt; |
| 522 | fStencilBits = that.fStencilBits; |
| 523 | fConfig = that.fConfig; |
| 524 | fBackend = that.fBackend; |
| 525 | |
| 526 | switch (that.fBackend) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 527 | case GrBackendApi::kOpenGL: |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 528 | fGLInfo = that.fGLInfo; |
| 529 | break; |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 530 | case GrBackendApi::kVulkan: |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 531 | #ifdef SK_VULKAN |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 532 | fVkInfo.assign(that.fVkInfo, this->isValid()); |
Mike Klein | a55e214 | 2018-10-03 16:34:11 +0000 | [diff] [blame] | 533 | #endif |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 534 | break; |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 535 | #ifdef SK_METAL |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 536 | case GrBackendApi::kMetal: |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 537 | fMtlInfo = that.fMtlInfo; |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 538 | break; |
| 539 | #endif |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 540 | case GrBackendApi::kMock: |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 541 | fMockInfo = that.fMockInfo; |
| 542 | break; |
| 543 | default: |
| 544 | SK_ABORT("Unknown GrBackend"); |
| 545 | } |
| 546 | fIsValid = that.fIsValid; |
| 547 | return *this; |
| 548 | } |
| 549 | |
Mike Klein | a55e214 | 2018-10-03 16:34:11 +0000 | [diff] [blame] | 550 | bool GrBackendRenderTarget::getVkImageInfo(GrVkImageInfo* outInfo) const { |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 551 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 552 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 553 | *outInfo = fVkInfo.snapImageInfo(); |
| 554 | return true; |
| 555 | } |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 556 | #endif |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 557 | return false; |
| 558 | } |
| 559 | |
| 560 | void GrBackendRenderTarget::setVkImageLayout(VkImageLayout layout) { |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 561 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 562 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 563 | fVkInfo.setImageLayout(layout); |
| 564 | } |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 565 | #endif |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | sk_sp<GrVkImageLayout> GrBackendRenderTarget::getGrVkImageLayout() const { |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 569 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 570 | if (this->isValid() && GrBackendApi::kVulkan == fBackend) { |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 571 | return fVkInfo.getGrVkImageLayout(); |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 572 | } |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 573 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 574 | return nullptr; |
| 575 | } |
| 576 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 577 | #ifdef SK_METAL |
| 578 | bool GrBackendRenderTarget::getMtlTextureInfo(GrMtlTextureInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 579 | if (this->isValid() && GrBackendApi::kMetal == fBackend) { |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 580 | *outInfo = fMtlInfo; |
| 581 | return true; |
| 582 | } |
| 583 | return false; |
| 584 | } |
| 585 | #endif |
| 586 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 587 | bool GrBackendRenderTarget::getGLFramebufferInfo(GrGLFramebufferInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 588 | if (this->isValid() && GrBackendApi::kOpenGL == fBackend) { |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 589 | *outInfo = fGLInfo; |
| 590 | return true; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 591 | } |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 592 | return false; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 593 | } |
| 594 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 595 | bool GrBackendRenderTarget::getMockRenderTargetInfo(GrMockRenderTargetInfo* outInfo) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 596 | if (this->isValid() && GrBackendApi::kMock == fBackend) { |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 597 | *outInfo = fMockInfo; |
| 598 | return true; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 599 | } |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 600 | return false; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 601 | } |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 602 | |
| 603 | #if GR_TEST_UTILS |
| 604 | bool GrBackendRenderTarget::TestingOnly_Equals(const GrBackendRenderTarget& r0, |
| 605 | const GrBackendRenderTarget& r1) { |
| 606 | if (!r0.isValid() || !r1.isValid()) { |
| 607 | return false; // two invalid backend rendertargets are not considered equal |
| 608 | } |
| 609 | |
| 610 | if (r0.fWidth != r1.fWidth || |
| 611 | r0.fHeight != r1.fHeight || |
| 612 | r0.fSampleCnt != r1.fSampleCnt || |
| 613 | r0.fStencilBits != r1.fStencilBits || |
| 614 | r0.fConfig != r1.fConfig || |
| 615 | r0.fBackend != r1.fBackend) { |
| 616 | return false; |
| 617 | } |
| 618 | |
| 619 | switch (r0.fBackend) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 620 | case GrBackendApi::kOpenGL: |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 621 | return r0.fGLInfo == r1.fGLInfo; |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 622 | case GrBackendApi::kMock: |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 623 | return r0.fMockInfo == r1.fMockInfo; |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 624 | case GrBackendApi::kVulkan: |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 625 | #ifdef SK_VULKAN |
| 626 | return r0.fVkInfo == r1.fVkInfo; |
| 627 | #else |
| 628 | // fall through |
| 629 | #endif |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 630 | case GrBackendApi::kMetal: |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 631 | #ifdef SK_METAL |
| 632 | return r0.fMtlInfo == r1.fMtlInfo; |
| 633 | #else |
| 634 | // fall through |
| 635 | #endif |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 636 | default: |
| 637 | return false; |
| 638 | } |
| 639 | |
| 640 | SkASSERT(0); |
| 641 | return false; |
| 642 | } |
| 643 | #endif |