blob: 22d2f2313517e27135e9b01d9f47ecde1a68f7ef [file] [log] [blame]
Greg Daniel94403452017-04-18 15:52:36 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/gpu/GrBackendSurface.h"
Greg Daniel94403452017-04-18 15:52:36 -04009
Greg Daniel6c6caf42020-05-29 12:11:05 -040010#include "src/gpu/GrBackendSurfaceMutableStateImpl.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/gl/GrGLUtil.h"
Greg Daniele7d8da42017-12-04 11:23:19 -050012
Stephen White985741a2019-07-18 11:43:45 -040013#ifdef SK_DAWN
14#include "include/gpu/dawn/GrDawnTypes.h"
15#include "src/gpu/dawn/GrDawnUtil.h"
16#endif
17
Greg Daniel94403452017-04-18 15:52:36 -040018#ifdef SK_VULKAN
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "include/gpu/vk/GrVkTypes.h"
20#include "src/gpu/vk/GrVkImageLayout.h"
21#include "src/gpu/vk/GrVkUtil.h"
Greg Daniel7ef28f32017-04-20 16:41:55 +000022#endif
Timothy Liang4e85e802018-06-28 16:37:18 -040023#ifdef SK_METAL
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "include/gpu/mtl/GrMtlTypes.h"
25#include "src/gpu/mtl/GrMtlCppUtil.h"
Timothy Liang4e85e802018-06-28 16:37:18 -040026#endif
Jim Van Verthc86c83c2020-02-27 15:48:24 -050027#ifdef SK_DIRECT3D
Jim Van Verth05d09192020-03-20 11:23:39 -040028#include "include/gpu/d3d/GrD3DTypes.h"
29#include "src/gpu/d3d/GrD3DResourceState.h"
30#include "src/gpu/d3d/GrD3DUtil.h"
Jim Van Verthc86c83c2020-02-27 15:48:24 -050031#endif
Greg Daniel7ef28f32017-04-20 16:41:55 +000032
Robert Phillipsb2adbef2019-07-02 16:33:05 -040033GrBackendFormat::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 Verthb01e12b2020-02-18 14:34:38 -050057#ifdef SK_DIRECT3D
58 case GrBackendApi::kDirect3D:
Jim Van Verthc86c83c2020-02-27 15:48:24 -050059 fDxgiFormat = that.fDxgiFormat;
Jim Van Verthb01e12b2020-02-18 14:34:38 -050060 break;
61#endif
Stephen White985741a2019-07-18 11:43:45 -040062#ifdef SK_DAWN
63 case GrBackendApi::kDawn:
64 fDawnFormat = that.fDawnFormat;
65 break;
66#endif
Robert Phillipsb2adbef2019-07-02 16:33:05 -040067 case GrBackendApi::kMock:
Robert Phillipsa27d6252019-12-10 14:48:36 -050068 fMock = that.fMock;
Robert Phillipsb2adbef2019-07-02 16:33:05 -040069 break;
70 default:
71 SK_ABORT("Unknown GrBackend");
72 }
73}
74
Ben Wagner833313b2020-03-23 17:22:24 -040075GrBackendFormat& GrBackendFormat::operator=(const GrBackendFormat& that) {
76 if (this != &that) {
77 this->~GrBackendFormat();
78 new (this) GrBackendFormat(that);
79 }
80 return *this;
81}
82
John Rosascoa9b348f2019-11-08 13:18:15 -080083#ifdef SK_GL
Robert Phillipsfc711a22018-02-13 17:03:00 -050084GrBackendFormat::GrBackendFormat(GrGLenum format, GrGLenum target)
Greg Danielbdf12ad2018-10-12 09:31:11 -040085 : fBackend(GrBackendApi::kOpenGL)
Greg Daniel4065d452018-11-16 15:43:41 -050086 , fValid(true)
87 , fGLFormat(format) {
88 switch (target) {
Robert Phillipsf209e882019-06-25 15:59:50 -040089 case GR_GL_TEXTURE_NONE:
90 fTextureType = GrTextureType::kNone;
91 break;
Greg Daniel4065d452018-11-16 15:43:41 -050092 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 Phillipsfc711a22018-02-13 17:03:00 -0500104}
Brian Salomonf4ba4ec2020-03-19 15:54:28 -0400105#endif
Robert Phillipsfc711a22018-02-13 17:03:00 -0500106
Brian Salomond4764a12019-08-08 12:08:24 -0400107GrGLFormat GrBackendFormat::asGLFormat() const {
Greg Danielbdf12ad2018-10-12 09:31:11 -0400108 if (this->isValid() && GrBackendApi::kOpenGL == fBackend) {
Brian Salomond4764a12019-08-08 12:08:24 -0400109 return GrGLFormatFromGLEnum(fGLFormat);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500110 }
Brian Salomond4764a12019-08-08 12:08:24 -0400111 return GrGLFormat::kUnknown;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500112}
113
Greg Daniel7e000222018-12-03 10:08:21 -0500114GrBackendFormat GrBackendFormat::MakeVk(const GrVkYcbcrConversionInfo& ycbcrInfo) {
Sergey Ulanov2739fd22019-08-11 22:46:33 -0700115 SkASSERT(ycbcrInfo.isValid());
116 return GrBackendFormat(ycbcrInfo.fFormat, ycbcrInfo);
Greg Daniel7e000222018-12-03 10:08:21 -0500117}
118
119GrBackendFormat::GrBackendFormat(VkFormat vkFormat, const GrVkYcbcrConversionInfo& ycbcrInfo)
Greg Danielbdf12ad2018-10-12 09:31:11 -0400120 : fBackend(GrBackendApi::kVulkan)
Greg Danielb4d89562018-10-03 18:44:49 +0000121#ifdef SK_VULKAN
Robert Phillipsfc711a22018-02-13 17:03:00 -0500122 , fValid(true)
Greg Danielb4d89562018-10-03 18:44:49 +0000123#else
Greg Daniel4065d452018-11-16 15:43:41 -0500124 , fValid(false)
Greg Danielb4d89562018-10-03 18:44:49 +0000125#endif
Greg Daniel4065d452018-11-16 15:43:41 -0500126 , fTextureType(GrTextureType::k2D) {
Greg Daniel7e000222018-12-03 10:08:21 -0500127 fVk.fFormat = vkFormat;
128 fVk.fYcbcrConversionInfo = ycbcrInfo;
Sergey Ulanov2739fd22019-08-11 22:46:33 -0700129 if (fVk.fYcbcrConversionInfo.isValid() && fVk.fYcbcrConversionInfo.fExternalFormat) {
Greg Daniel387ec9a2019-03-07 16:44:54 -0500130 fTextureType = GrTextureType::kExternal;
131 }
Robert Phillipsfc711a22018-02-13 17:03:00 -0500132}
133
Brian Salomond4764a12019-08-08 12:08:24 -0400134bool GrBackendFormat::asVkFormat(VkFormat* format) const {
135 SkASSERT(format);
Greg Danielbdf12ad2018-10-12 09:31:11 -0400136 if (this->isValid() && GrBackendApi::kVulkan == fBackend) {
Brian Salomond4764a12019-08-08 12:08:24 -0400137 *format = fVk.fFormat;
138 return true;
Greg Daniel7e000222018-12-03 10:08:21 -0500139 }
Brian Salomond4764a12019-08-08 12:08:24 -0400140 return false;
Greg Daniel7e000222018-12-03 10:08:21 -0500141}
142
143const GrVkYcbcrConversionInfo* GrBackendFormat::getVkYcbcrConversionInfo() const {
144 if (this->isValid() && GrBackendApi::kVulkan == fBackend) {
145 return &fVk.fYcbcrConversionInfo;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500146 }
147 return nullptr;
148}
Robert Phillipsfc711a22018-02-13 17:03:00 -0500149
Stephen White985741a2019-07-18 11:43:45 -0400150#ifdef SK_DAWN
Stephen White3cc8d4f2019-10-30 09:56:23 -0400151GrBackendFormat::GrBackendFormat(wgpu::TextureFormat format)
Stephen White985741a2019-07-18 11:43:45 -0400152 : fBackend(GrBackendApi::kDawn)
153 , fValid(true)
154 , fDawnFormat(format)
155 , fTextureType(GrTextureType::k2D) {
156}
157
Stephen White3cc8d4f2019-10-30 09:56:23 -0400158bool GrBackendFormat::asDawnFormat(wgpu::TextureFormat* format) const {
Brian Salomond4764a12019-08-08 12:08:24 -0400159 SkASSERT(format);
Stephen White985741a2019-07-18 11:43:45 -0400160 if (this->isValid() && GrBackendApi::kDawn == fBackend) {
Brian Salomond4764a12019-08-08 12:08:24 -0400161 *format = fDawnFormat;
162 return true;
Stephen White985741a2019-07-18 11:43:45 -0400163 }
Brian Salomond4764a12019-08-08 12:08:24 -0400164 return false;
Stephen White985741a2019-07-18 11:43:45 -0400165}
166#endif
167
Timothy Liang4e85e802018-06-28 16:37:18 -0400168#ifdef SK_METAL
169GrBackendFormat::GrBackendFormat(GrMTLPixelFormat mtlFormat)
Greg Danielbdf12ad2018-10-12 09:31:11 -0400170 : fBackend(GrBackendApi::kMetal)
Timothy Liang4e85e802018-06-28 16:37:18 -0400171 , fValid(true)
Greg Daniel4065d452018-11-16 15:43:41 -0500172 , fMtlFormat(mtlFormat)
173 , fTextureType(GrTextureType::k2D) {
Timothy Liang4e85e802018-06-28 16:37:18 -0400174}
175
Brian Salomond4764a12019-08-08 12:08:24 -0400176GrMTLPixelFormat GrBackendFormat::asMtlFormat() const {
Greg Danielbdf12ad2018-10-12 09:31:11 -0400177 if (this->isValid() && GrBackendApi::kMetal == fBackend) {
Brian Salomond4764a12019-08-08 12:08:24 -0400178 return fMtlFormat;
Timothy Liang4e85e802018-06-28 16:37:18 -0400179 }
Brian Salomond4764a12019-08-08 12:08:24 -0400180 // MTLPixelFormatInvalid == 0
181 return GrMTLPixelFormat(0);
Timothy Liang4e85e802018-06-28 16:37:18 -0400182}
183#endif
184
Jim Van Verthc86c83c2020-02-27 15:48:24 -0500185#ifdef SK_DIRECT3D
186GrBackendFormat::GrBackendFormat(DXGI_FORMAT dxgiFormat)
187 : fBackend(GrBackendApi::kDirect3D)
188 , fValid(true)
189 , fDxgiFormat(dxgiFormat)
190 , fTextureType(GrTextureType::k2D) {
191}
192
193bool 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 Phillipsa27d6252019-12-10 14:48:36 -0500202GrBackendFormat::GrBackendFormat(GrColorType colorType, SkImage::CompressionType compression)
Greg Danielbdf12ad2018-10-12 09:31:11 -0400203 : fBackend(GrBackendApi::kMock)
Robert Phillipsfc711a22018-02-13 17:03:00 -0500204 , fValid(true)
Greg Daniel4065d452018-11-16 15:43:41 -0500205 , fTextureType(GrTextureType::k2D) {
Robert Phillipsa27d6252019-12-10 14:48:36 -0500206 fMock.fColorType = colorType;
207 fMock.fCompressionType = compression;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500208}
209
Brian Salomondc8fcdb2020-03-26 16:45:05 -0400210uint32_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 Salomond4764a12019-08-08 12:08:24 -0400243GrColorType GrBackendFormat::asMockColorType() const {
Greg Danielbdf12ad2018-10-12 09:31:11 -0400244 if (this->isValid() && GrBackendApi::kMock == fBackend) {
Robert Phillipsa27d6252019-12-10 14:48:36 -0500245 SkASSERT(fMock.fCompressionType == SkImage::CompressionType::kNone ||
246 fMock.fColorType == GrColorType::kUnknown);
247
248 return fMock.fColorType;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500249 }
Robert Phillipsa27d6252019-12-10 14:48:36 -0500250
Brian Salomond4764a12019-08-08 12:08:24 -0400251 return GrColorType::kUnknown;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500252}
253
Robert Phillipsa27d6252019-12-10 14:48:36 -0500254SkImage::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 Daniel4065d452018-11-16 15:43:41 -0500266GrBackendFormat GrBackendFormat::makeTexture2D() const {
Greg Daniel4065d452018-11-16 15:43:41 -0500267 GrBackendFormat copy = *this;
Greg Daniel387ec9a2019-03-07 16:44:54 -0500268 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 Daniel4065d452018-11-16 15:43:41 -0500277 copy.fTextureType = GrTextureType::k2D;
278 return copy;
279}
280
Robert Phillipsa27d6252019-12-10 14:48:36 -0500281GrBackendFormat GrBackendFormat::MakeMock(GrColorType colorType,
282 SkImage::CompressionType compression) {
283 return GrBackendFormat(colorType, compression);
284}
285
Greg Daniel45723ac2018-11-30 10:12:43 -0500286bool 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 Rosascoa9b348f2019-11-08 13:18:15 -0800297#ifdef SK_GL
Greg Daniel45723ac2018-11-30 10:12:43 -0500298 case GrBackendApi::kOpenGL:
299 return fGLFormat == that.fGLFormat;
John Rosascoa9b348f2019-11-08 13:18:15 -0800300 break;
301#endif
Robert Phillips0efc01d2019-11-06 17:19:30 +0000302#ifdef SK_VULKAN
John Rosascoa9b348f2019-11-08 13:18:15 -0800303 case GrBackendApi::kVulkan:
Greg Daniel45723ac2018-11-30 10:12:43 -0500304 return fVk.fFormat == that.fVk.fFormat &&
305 fVk.fYcbcrConversionInfo == that.fVk.fYcbcrConversionInfo;
Robert Phillips0efc01d2019-11-06 17:19:30 +0000306 break;
John Rosascoa9b348f2019-11-08 13:18:15 -0800307#endif
Greg Daniel45723ac2018-11-30 10:12:43 -0500308#ifdef SK_METAL
309 case GrBackendApi::kMetal:
310 return fMtlFormat == that.fMtlFormat;
Robert Phillips0efc01d2019-11-06 17:19:30 +0000311 break;
John Rosascoa9b348f2019-11-08 13:18:15 -0800312#endif
Robert Phillips0efc01d2019-11-06 17:19:30 +0000313#ifdef SK_DAWN
John Rosascoa9b348f2019-11-08 13:18:15 -0800314 case GrBackendApi::kDawn:
Stephen White985741a2019-07-18 11:43:45 -0400315 return fDawnFormat == that.fDawnFormat;
Robert Phillips0efc01d2019-11-06 17:19:30 +0000316 break;
John Rosascoa9b348f2019-11-08 13:18:15 -0800317#endif
Greg Daniel45723ac2018-11-30 10:12:43 -0500318 case GrBackendApi::kMock:
Robert Phillipsa27d6252019-12-10 14:48:36 -0500319 return fMock.fColorType == that.fMock.fColorType &&
320 fMock.fCompressionType == that.fMock.fCompressionType;
Greg Daniel85da3362020-03-09 15:18:35 -0400321#ifdef SK_DIRECT3D
322 case GrBackendApi::kDirect3D:
323 return fDxgiFormat == that.fDxgiFormat;
324#endif
Greg Daniel45723ac2018-11-30 10:12:43 -0500325 default:
326 SK_ABORT("Unknown GrBackend");
327 }
328 return false;
329}
330
Robert Phillips8e54a6e2020-08-17 14:31:02 -0400331#if defined(SK_DEBUG) || GR_TEST_UTILS
Robert Phillipsbac46722019-08-01 15:09:17 -0400332#include "include/core/SkString.h"
Robert Phillipsbac46722019-08-01 15:09:17 -0400333
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
341SkString 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 Verthb01e12b2020-02-18 14:34:38 -0500367 case GrBackendApi::kDirect3D:
368#ifdef SK_DIRECT3D
Jim Van Verth05d09192020-03-20 11:23:39 -0400369 str.append(GrDxgiFormatToStr(fDxgiFormat));
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500370#endif
371 break;
Robert Phillipsbac46722019-08-01 15:09:17 -0400372 case GrBackendApi::kDawn:
373#ifdef SK_DAWN
Stephen Whited7325182019-08-02 17:22:59 -0400374 str.append(GrDawnFormatToStr(fDawnFormat));
Robert Phillipsbac46722019-08-01 15:09:17 -0400375#endif
376 break;
377 case GrBackendApi::kMock:
Robert Phillipsa27d6252019-12-10 14:48:36 -0500378 str.append(GrColorTypeToStr(fMock.fColorType));
379 str.appendf("-");
380 str.append(GrCompressionTypeToStr(fMock.fCompressionType));
Robert Phillipsbac46722019-08-01 15:09:17 -0400381 break;
382 }
383
384 return str;
385}
386#endif
387
388///////////////////////////////////////////////////////////////////////////////////////////////////
Greg Daniel6c6caf42020-05-29 12:11:05 -0400389GrBackendTexture::GrBackendTexture() : fIsValid(false) {}
390
Stephen White985741a2019-07-18 11:43:45 -0400391#ifdef SK_DAWN
392GrBackendTexture::GrBackendTexture(int width,
393 int height,
Stephen Whitef03c1162020-01-28 12:39:45 -0500394 const GrDawnTextureInfo& dawnInfo)
Stephen White985741a2019-07-18 11:43:45 -0400395 : fIsValid(true)
396 , fWidth(width)
397 , fHeight(height)
Brian Salomon40a40622020-07-21 10:32:07 -0400398 , fMipmapped(GrMipmapped(dawnInfo.fLevelCount > 1))
Stephen White985741a2019-07-18 11:43:45 -0400399 , fBackend(GrBackendApi::kDawn)
400 , fDawnInfo(dawnInfo) {}
401#endif
402
Greg Danielb4d89562018-10-03 18:44:49 +0000403#ifdef SK_VULKAN
Greg Daniel6c6caf42020-05-29 12:11:05 -0400404GrBackendTexture::GrBackendTexture(int width, int height, const GrVkImageInfo& vkInfo)
Brian Salomon4456a0d2019-07-18 15:05:11 -0400405 : GrBackendTexture(width, height, vkInfo,
Greg Daniel6c6caf42020-05-29 12:11:05 -0400406 sk_sp<GrBackendSurfaceMutableStateImpl>(
407 new GrBackendSurfaceMutableStateImpl(
408 vkInfo.fImageLayout, vkInfo.fCurrentQueueFamily))) {}
409
Greg Daniel7b62dca2020-08-21 11:26:12 -0400410static 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.
415static const VkImageUsageFlags kDefaultTexRTUsageFlags =
416 kDefaultUsageFlags | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
417
418static 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 Daniel6c6caf42020-05-29 12:11:05 -0400428GrBackendTexture::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 Salomon40a40622020-07-21 10:32:07 -0400435 , fMipmapped(GrMipmapped(vkInfo.fLevelCount > 1))
Greg Daniel6c6caf42020-05-29 12:11:05 -0400436 , fBackend(GrBackendApi::kVulkan)
Greg Daniel7b62dca2020-08-21 11:26:12 -0400437 , fVkInfo(apply_default_usage_flags(vkInfo, kDefaultTexRTUsageFlags))
Greg Daniel6c6caf42020-05-29 12:11:05 -0400438 , fMutableState(std::move(mutableState)) {}
Greg Danielb4d89562018-10-03 18:44:49 +0000439#endif
Greg Daniel52e16d92018-04-10 09:34:07 -0400440
Brian Salomone2826ab2019-06-04 15:58:31 -0400441#ifdef SK_GL
442GrBackendTexture::GrBackendTexture(int width,
443 int height,
Brian Salomon40a40622020-07-21 10:32:07 -0400444 GrMipmapped mipmapped,
Brian Salomone2826ab2019-06-04 15:58:31 -0400445 const GrGLTextureInfo glInfo,
446 sk_sp<GrGLTextureParameters> params)
447 : fIsValid(true)
448 , fWidth(width)
449 , fHeight(height)
Brian Salomon40a40622020-07-21 10:32:07 -0400450 , fMipmapped(mipmapped)
Brian Salomone2826ab2019-06-04 15:58:31 -0400451 , fBackend(GrBackendApi::kOpenGL)
452 , fGLInfo(glInfo, params.release()) {}
453
454sk_sp<GrGLTextureParameters> GrBackendTexture::getGLTextureParams() const {
455 if (fBackend != GrBackendApi::kOpenGL) {
456 return nullptr;
457 }
458 return fGLInfo.refParameters();
459}
460#endif
461
Timothy Liang4e85e802018-06-28 16:37:18 -0400462#ifdef SK_METAL
463GrBackendTexture::GrBackendTexture(int width,
464 int height,
Brian Salomon40a40622020-07-21 10:32:07 -0400465 GrMipmapped mipmapped,
Timothy Liang4e85e802018-06-28 16:37:18 -0400466 const GrMtlTextureInfo& mtlInfo)
467 : fIsValid(true)
468 , fWidth(width)
469 , fHeight(height)
Brian Salomon40a40622020-07-21 10:32:07 -0400470 , fMipmapped(mipmapped)
Greg Danielbdf12ad2018-10-12 09:31:11 -0400471 , fBackend(GrBackendApi::kMetal)
Timothy Liang4e85e802018-06-28 16:37:18 -0400472 , fMtlInfo(mtlInfo) {}
473#endif
474
Jim Van Verth05d09192020-03-20 11:23:39 -0400475#ifdef SK_DIRECT3D
Jim Van Verth6ec56882020-03-26 11:47:26 -0400476GrBackendTexture::GrBackendTexture(int width, int height, const GrD3DTextureResourceInfo& d3dInfo)
Jim Van Verth05d09192020-03-20 11:23:39 -0400477 : GrBackendTexture(
478 width, height, d3dInfo,
479 sk_sp<GrD3DResourceState>(new GrD3DResourceState(
480 static_cast<D3D12_RESOURCE_STATES>(d3dInfo.fResourceState)))) {}
481
482GrBackendTexture::GrBackendTexture(int width,
483 int height,
Jim Van Verth6ec56882020-03-26 11:47:26 -0400484 const GrD3DTextureResourceInfo& d3dInfo,
Jim Van Verth05d09192020-03-20 11:23:39 -0400485 sk_sp<GrD3DResourceState> state)
486 : fIsValid(true)
487 , fWidth(width)
488 , fHeight(height)
Brian Salomon40a40622020-07-21 10:32:07 -0400489 , fMipmapped(GrMipmapped(d3dInfo.fLevelCount > 1))
Jim Van Verth05d09192020-03-20 11:23:39 -0400490 , fBackend(GrBackendApi::kDirect3D)
491 , fD3DInfo(d3dInfo, state.release()) {}
492#endif
493
John Rosascoa9b348f2019-11-08 13:18:15 -0800494#ifdef SK_GL
Brian Salomon8fe24272017-07-07 12:56:11 -0400495GrBackendTexture::GrBackendTexture(int width,
496 int height,
Brian Salomon40a40622020-07-21 10:32:07 -0400497 GrMipmapped mipmapped,
Greg Daniele7d8da42017-12-04 11:23:19 -0500498 const GrGLTextureInfo& glInfo)
Brian Salomon40a40622020-07-21 10:32:07 -0400499 : GrBackendTexture(width, height, mipmapped, glInfo, sk_make_sp<GrGLTextureParameters>()) {
Brian Salomone2826ab2019-06-04 15:58:31 -0400500 // Make no assumptions about client's texture's parameters.
501 this->glTextureParametersModified();
502}
John Rosascoa9b348f2019-11-08 13:18:15 -0800503#endif
Greg Daniele7d8da42017-12-04 11:23:19 -0500504
505GrBackendTexture::GrBackendTexture(int width,
506 int height,
Brian Salomon40a40622020-07-21 10:32:07 -0400507 GrMipmapped mipmapped,
Greg Daniel177e6952017-10-12 12:27:11 -0400508 const GrMockTextureInfo& mockInfo)
Greg Daniel9ca30652018-04-06 09:27:20 -0400509 : fIsValid(true)
510 , fWidth(width)
Brian Salomon8fe24272017-07-07 12:56:11 -0400511 , fHeight(height)
Brian Salomon40a40622020-07-21 10:32:07 -0400512 , fMipmapped(mipmapped)
Greg Danielbdf12ad2018-10-12 09:31:11 -0400513 , fBackend(GrBackendApi::kMock)
Brian Salomon8fe24272017-07-07 12:56:11 -0400514 , fMockInfo(mockInfo) {}
515
Greg Daniel52e16d92018-04-10 09:34:07 -0400516GrBackendTexture::~GrBackendTexture() {
517 this->cleanup();
518}
519
520void GrBackendTexture::cleanup() {
Brian Salomone2826ab2019-06-04 15:58:31 -0400521#ifdef SK_GL
522 if (this->isValid() && GrBackendApi::kOpenGL == fBackend) {
523 fGLInfo.cleanup();
524 }
525#endif
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000526#ifdef SK_VULKAN
Greg Danielbdf12ad2018-10-12 09:31:11 -0400527 if (this->isValid() && GrBackendApi::kVulkan == fBackend) {
Greg Daniel52e16d92018-04-10 09:34:07 -0400528 fVkInfo.cleanup();
529 }
530#endif
Jim Van Verth05d09192020-03-20 11:23:39 -0400531#ifdef SK_DIRECT3D
532 if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
533 fD3DInfo.cleanup();
534 }
535#endif
Greg Daniel52e16d92018-04-10 09:34:07 -0400536}
537
538GrBackendTexture::GrBackendTexture(const GrBackendTexture& that) : fIsValid(false) {
539 *this = that;
540}
541
542GrBackendTexture& GrBackendTexture::operator=(const GrBackendTexture& that) {
543 if (!that.isValid()) {
544 this->cleanup();
545 fIsValid = false;
546 return *this;
Ben Wagnera797cc92019-06-05 23:59:46 -0400547 } else if (fIsValid && this->fBackend != that.fBackend) {
Brian Salomone2826ab2019-06-04 15:58:31 -0400548 this->cleanup();
549 fIsValid = false;
Greg Daniel52e16d92018-04-10 09:34:07 -0400550 }
551 fWidth = that.fWidth;
552 fHeight = that.fHeight;
Brian Salomon40a40622020-07-21 10:32:07 -0400553 fMipmapped = that.fMipmapped;
Greg Daniel52e16d92018-04-10 09:34:07 -0400554 fBackend = that.fBackend;
555
556 switch (that.fBackend) {
Brian Salomone2826ab2019-06-04 15:58:31 -0400557#ifdef SK_GL
Greg Danielbdf12ad2018-10-12 09:31:11 -0400558 case GrBackendApi::kOpenGL:
Brian Salomone2826ab2019-06-04 15:58:31 -0400559 fGLInfo.assign(that.fGLInfo, this->isValid());
Greg Daniel52e16d92018-04-10 09:34:07 -0400560 break;
Mike Kleina55e2142018-10-03 16:34:11 +0000561#endif
Brian Salomone2826ab2019-06-04 15:58:31 -0400562#ifdef SK_VULKAN
563 case GrBackendApi::kVulkan:
564 fVkInfo.assign(that.fVkInfo, this->isValid());
Greg Danielb4d89562018-10-03 18:44:49 +0000565 break;
Brian Salomone2826ab2019-06-04 15:58:31 -0400566#endif
Greg Daniel52e16d92018-04-10 09:34:07 -0400567#ifdef SK_METAL
Greg Danielbdf12ad2018-10-12 09:31:11 -0400568 case GrBackendApi::kMetal:
Jim Van Verth7730d7c2019-05-28 03:03:45 +0000569 fMtlInfo = that.fMtlInfo;
Greg Daniel52e16d92018-04-10 09:34:07 -0400570 break;
571#endif
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500572#ifdef SK_DIRECT3D
573 case GrBackendApi::kDirect3D:
Jim Van Verth05d09192020-03-20 11:23:39 -0400574 fD3DInfo.assign(that.fD3DInfo, this->isValid());
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500575 break;
576#endif
Stephen White985741a2019-07-18 11:43:45 -0400577#ifdef SK_DAWN
578 case GrBackendApi::kDawn:
579 fDawnInfo = that.fDawnInfo;
580 break;
581#endif
Greg Danielbdf12ad2018-10-12 09:31:11 -0400582 case GrBackendApi::kMock:
Greg Daniel52e16d92018-04-10 09:34:07 -0400583 fMockInfo = that.fMockInfo;
584 break;
585 default:
586 SK_ABORT("Unknown GrBackend");
587 }
Greg Daniel6c6caf42020-05-29 12:11:05 -0400588 fMutableState = that.fMutableState;
Brian Salomone2826ab2019-06-04 15:58:31 -0400589 fIsValid = true;
Greg Daniel52e16d92018-04-10 09:34:07 -0400590 return *this;
591}
592
Greg Daniel6c6caf42020-05-29 12:11:05 -0400593sk_sp<GrBackendSurfaceMutableStateImpl> GrBackendTexture::getMutableState() const {
594 return fMutableState;
595}
596
Stephen White985741a2019-07-18 11:43:45 -0400597#ifdef SK_DAWN
Stephen Whitef03c1162020-01-28 12:39:45 -0500598bool GrBackendTexture::getDawnTextureInfo(GrDawnTextureInfo* outInfo) const {
Stephen White985741a2019-07-18 11:43:45 -0400599 if (this->isValid() && GrBackendApi::kDawn == fBackend) {
600 *outInfo = fDawnInfo;
601 return true;
602 }
603 return false;
604}
605#endif
606
Greg Daniel6c6caf42020-05-29 12:11:05 -0400607bool GrBackendTexture::getVkImageInfo(GrVkImageInfo* outInfo) const {
Greg Danielcc7ec242020-05-29 14:43:36 -0400608#ifdef SK_VULKAN
Greg Danielbdf12ad2018-10-12 09:31:11 -0400609 if (this->isValid() && GrBackendApi::kVulkan == fBackend) {
Greg Daniel6c6caf42020-05-29 12:11:05 -0400610 *outInfo = fVkInfo.snapImageInfo(fMutableState.get());
Greg Daniel52e16d92018-04-10 09:34:07 -0400611 return true;
612 }
Greg Danielcc7ec242020-05-29 14:43:36 -0400613#endif
Greg Daniel52e16d92018-04-10 09:34:07 -0400614 return false;
615}
616
617void GrBackendTexture::setVkImageLayout(VkImageLayout layout) {
Greg Danielcc7ec242020-05-29 14:43:36 -0400618#ifdef SK_VULKAN
Greg Danielbdf12ad2018-10-12 09:31:11 -0400619 if (this->isValid() && GrBackendApi::kVulkan == fBackend) {
Greg Daniel6c6caf42020-05-29 12:11:05 -0400620 fMutableState->setImageLayout(layout);
Greg Daniel52e16d92018-04-10 09:34:07 -0400621 }
Brian Salomone2826ab2019-06-04 15:58:31 -0400622#endif
Greg Danielcc7ec242020-05-29 14:43:36 -0400623}
Greg Daniel94403452017-04-18 15:52:36 -0400624
Timothy Liang4e85e802018-06-28 16:37:18 -0400625#ifdef SK_METAL
626bool GrBackendTexture::getMtlTextureInfo(GrMtlTextureInfo* outInfo) const {
Greg Danielbdf12ad2018-10-12 09:31:11 -0400627 if (this->isValid() && GrBackendApi::kMetal == fBackend) {
Jim Van Verth7730d7c2019-05-28 03:03:45 +0000628 *outInfo = fMtlInfo;
Timothy Liang4e85e802018-06-28 16:37:18 -0400629 return true;
630 }
631 return false;
632}
633#endif
634
Jim Van Verth05d09192020-03-20 11:23:39 -0400635#ifdef SK_DIRECT3D
Jim Van Verth6ec56882020-03-26 11:47:26 -0400636bool GrBackendTexture::getD3DTextureResourceInfo(GrD3DTextureResourceInfo* outInfo) const {
Jim Van Verth05d09192020-03-20 11:23:39 -0400637 if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
Jim Van Verth6ec56882020-03-26 11:47:26 -0400638 *outInfo = fD3DInfo.snapTextureResourceInfo();
Jim Van Verth05d09192020-03-20 11:23:39 -0400639 return true;
640 }
641 return false;
642}
643
644void GrBackendTexture::setD3DResourceState(GrD3DResourceStateEnum state) {
645 if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
646 fD3DInfo.setResourceState(state);
647 }
648}
649
650sk_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 Daniel52e16d92018-04-10 09:34:07 -0400658bool GrBackendTexture::getGLTextureInfo(GrGLTextureInfo* outInfo) const {
Brian Salomone2826ab2019-06-04 15:58:31 -0400659#ifdef SK_GL
Greg Danielbdf12ad2018-10-12 09:31:11 -0400660 if (this->isValid() && GrBackendApi::kOpenGL == fBackend) {
Brian Salomone2826ab2019-06-04 15:58:31 -0400661 *outInfo = fGLInfo.info();
Greg Daniel52e16d92018-04-10 09:34:07 -0400662 return true;
Brian Osmana7ef3a02019-03-27 15:54:14 -0400663 } 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 Phillipsa27d6252019-12-10 14:48:36 -0500668 static_cast<GrGLuint>(fMockInfo.id()),
Brian Osmana7ef3a02019-03-27 15:54:14 -0400669 GR_GL_RGBA8 };
670 return true;
Greg Daniel94403452017-04-18 15:52:36 -0400671 }
Brian Salomone2826ab2019-06-04 15:58:31 -0400672#endif
Greg Daniel52e16d92018-04-10 09:34:07 -0400673 return false;
Greg Daniel94403452017-04-18 15:52:36 -0400674}
675
Brian Salomone2826ab2019-06-04 15:58:31 -0400676void GrBackendTexture::glTextureParametersModified() {
677#ifdef SK_GL
678 if (this->isValid() && fBackend == GrBackendApi::kOpenGL) {
679 fGLInfo.parameters()->invalidate();
680 }
681#endif
682}
683
Greg Daniel52e16d92018-04-10 09:34:07 -0400684bool GrBackendTexture::getMockTextureInfo(GrMockTextureInfo* outInfo) const {
Greg Danielbdf12ad2018-10-12 09:31:11 -0400685 if (this->isValid() && GrBackendApi::kMock == fBackend) {
Greg Daniel52e16d92018-04-10 09:34:07 -0400686 *outInfo = fMockInfo;
687 return true;
Brian Salomon8fe24272017-07-07 12:56:11 -0400688 }
Greg Daniel52e16d92018-04-10 09:34:07 -0400689 return false;
Brian Salomon8fe24272017-07-07 12:56:11 -0400690}
691
Greg Daniel6c6caf42020-05-29 12:11:05 -0400692void GrBackendTexture::setMutableState(const GrBackendSurfaceMutableState& state) {
693 fMutableState->set(state);
694}
695
Brian Salomon4456a0d2019-07-18 15:05:11 -0400696bool GrBackendTexture::isProtected() const {
697 if (!this->isValid() || this->backend() != GrBackendApi::kVulkan) {
698 return false;
699 }
700 return fVkInfo.isProtected();
701}
702
Brian Salomonaad83152019-05-24 10:16:35 -0400703bool 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 Salomone2826ab2019-06-04 15:58:31 -0400711#ifdef SK_GL
Brian Salomonaad83152019-05-24 10:16:35 -0400712 case GrBackendApi::kOpenGL:
Brian Salomone2826ab2019-06-04 15:58:31 -0400713 return fGLInfo.info().fID == that.fGLInfo.info().fID;
714#endif
Brian Salomonaad83152019-05-24 10:16:35 -0400715#ifdef SK_VULKAN
716 case GrBackendApi::kVulkan:
Greg Daniel6c6caf42020-05-29 12:11:05 -0400717 return fVkInfo.snapImageInfo(fMutableState.get()).fImage ==
718 that.fVkInfo.snapImageInfo(that.fMutableState.get()).fImage;
Brian Salomonaad83152019-05-24 10:16:35 -0400719#endif
720#ifdef SK_METAL
721 case GrBackendApi::kMetal:
Jim Van Verth7730d7c2019-05-28 03:03:45 +0000722 return this->fMtlInfo.fTexture == that.fMtlInfo.fTexture;
Brian Salomonaad83152019-05-24 10:16:35 -0400723#endif
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500724#ifdef SK_DIRECT3D
725 case GrBackendApi::kDirect3D:
Jim Van Verthde175ab2020-06-10 16:12:25 -0400726 return fD3DInfo.snapTextureResourceInfo().fResource ==
727 that.fD3DInfo.snapTextureResourceInfo().fResource;
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500728#endif
Stephen Whited4b8bf92020-06-08 15:38:29 -0400729#ifdef SK_DAWN
730 case GrBackendApi::kDawn: {
731 return this->fDawnInfo.fTexture.Get() == that.fDawnInfo.fTexture.Get();
732 }
733#endif
Brian Salomonaad83152019-05-24 10:16:35 -0400734 case GrBackendApi::kMock:
Robert Phillipsa27d6252019-12-10 14:48:36 -0500735 return fMockInfo.id() == that.fMockInfo.id();
Brian Salomonaad83152019-05-24 10:16:35 -0400736 default:
737 return false;
738 }
739}
740
Brian Salomonf391d0f2018-12-14 09:18:50 -0500741GrBackendFormat GrBackendTexture::getBackendFormat() const {
742 if (!this->isValid()) {
743 return GrBackendFormat();
744 }
745 switch (fBackend) {
Brian Salomone2826ab2019-06-04 15:58:31 -0400746#ifdef SK_GL
Brian Salomonf391d0f2018-12-14 09:18:50 -0500747 case GrBackendApi::kOpenGL:
Brian Salomone2826ab2019-06-04 15:58:31 -0400748 return GrBackendFormat::MakeGL(fGLInfo.info().fFormat, fGLInfo.info().fTarget);
749#endif
Brian Salomonf391d0f2018-12-14 09:18:50 -0500750#ifdef SK_VULKAN
751 case GrBackendApi::kVulkan: {
Greg Daniel6c6caf42020-05-29 12:11:05 -0400752 auto info = fVkInfo.snapImageInfo(fMutableState.get());
Brian Salomonf391d0f2018-12-14 09:18:50 -0500753 if (info.fYcbcrConversionInfo.isValid()) {
Sergey Ulanov2739fd22019-08-11 22:46:33 -0700754 SkASSERT(info.fFormat == info.fYcbcrConversionInfo.fFormat);
Brian Salomonf391d0f2018-12-14 09:18:50 -0500755 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 Verthb01e12b2020-02-18 14:34:38 -0500767#ifdef SK_DIRECT3D
768 case GrBackendApi::kDirect3D: {
Jim Van Verth6ec56882020-03-26 11:47:26 -0400769 auto d3dInfo = fD3DInfo.snapTextureResourceInfo();
Jim Van Verth05d09192020-03-20 11:23:39 -0400770 return GrBackendFormat::MakeDxgi(d3dInfo.fFormat);
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500771 }
772#endif
773#ifdef SK_DAWN
774 case GrBackendApi::kDawn: {
775 return GrBackendFormat::MakeDawn(fDawnInfo.fFormat);
776 }
777#endif
Brian Salomonf391d0f2018-12-14 09:18:50 -0500778 case GrBackendApi::kMock:
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400779 return fMockInfo.getBackendFormat();
Brian Salomonf391d0f2018-12-14 09:18:50 -0500780 default:
781 return GrBackendFormat();
782 }
783}
784
Robert Phillipsc5509952018-04-04 15:54:55 -0400785#if GR_TEST_UTILS
786bool 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 Salomon40a40622020-07-21 10:32:07 -0400793 t0.fMipmapped != t1.fMipmapped ||
Robert Phillipsc5509952018-04-04 15:54:55 -0400794 t0.fBackend != t1.fBackend) {
795 return false;
796 }
797
Greg Daniel7f3408b2020-06-03 13:31:00 -0400798 // 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 Phillipsc5509952018-04-04 15:54:55 -0400804 switch (t0.fBackend) {
Brian Salomone2826ab2019-06-04 15:58:31 -0400805#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 Phillipsc5509952018-04-04 15:54:55 -0400811#ifdef SK_VULKAN
Brian Salomone2826ab2019-06-04 15:58:31 -0400812 case GrBackendApi::kVulkan:
813 return t0.fVkInfo == t1.fVkInfo;
Robert Phillipsc5509952018-04-04 15:54:55 -0400814#endif
Timothy Liang4e85e802018-06-28 16:37:18 -0400815#ifdef SK_METAL
Brian Salomone2826ab2019-06-04 15:58:31 -0400816 case GrBackendApi::kMetal:
817 return t0.fMtlInfo == t1.fMtlInfo;
Timothy Liang4e85e802018-06-28 16:37:18 -0400818#endif
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500819#ifdef SK_DIRECT3D
820 case GrBackendApi::kDirect3D:
Jim Van Verth05d09192020-03-20 11:23:39 -0400821 return t0.fD3DInfo == t1.fD3DInfo;
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500822#endif
Stephen White985741a2019-07-18 11:43:45 -0400823#ifdef SK_DAWN
824 case GrBackendApi::kDawn:
825 return t0.fDawnInfo == t1.fDawnInfo;
826#endif
Brian Salomone2826ab2019-06-04 15:58:31 -0400827 default:
828 return false;
Robert Phillipsc5509952018-04-04 15:54:55 -0400829 }
Robert Phillipsc5509952018-04-04 15:54:55 -0400830}
831#endif
832
Greg Daniel94403452017-04-18 15:52:36 -0400833////////////////////////////////////////////////////////////////////////////////////////////////////
834
Greg Daniel6c6caf42020-05-29 12:11:05 -0400835GrBackendRenderTarget::GrBackendRenderTarget() : fIsValid(false) {}
836
837
Stephen White985741a2019-07-18 11:43:45 -0400838#ifdef SK_DAWN
839GrBackendRenderTarget::GrBackendRenderTarget(int width,
840 int height,
841 int sampleCnt,
842 int stencilBits,
Stephen Whitef03c1162020-01-28 12:39:45 -0500843 const GrDawnRenderTargetInfo& dawnInfo)
Stephen White985741a2019-07-18 11:43:45 -0400844 : fIsValid(true)
Stephen White3c0a50f2020-01-16 18:19:54 -0500845 , fFramebufferOnly(true)
Stephen White985741a2019-07-18 11:43:45 -0400846 , fWidth(width)
847 , fHeight(height)
848 , fSampleCnt(sampleCnt)
849 , fStencilBits(stencilBits)
Stephen White985741a2019-07-18 11:43:45 -0400850 , fBackend(GrBackendApi::kDawn)
851 , fDawnInfo(dawnInfo) {}
852#endif
853
Greg Daniel6c6caf42020-05-29 12:11:05 -0400854#ifdef SK_VULKAN
Brian Salomon57fd9232020-09-28 17:02:49 -0400855static 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 Daniel94403452017-04-18 15:52:36 -0400863GrBackendRenderTarget::GrBackendRenderTarget(int width,
864 int height,
865 int sampleCnt,
Brian Salomonafdc6b12018-03-09 12:02:32 -0500866 const GrVkImageInfo& vkInfo)
Brian Salomon57fd9232020-09-28 17:02:49 -0400867 : GrBackendRenderTarget(width, height, resolve_vkii_sample_count(vkInfo, sampleCnt)) {}
868
869GrBackendRenderTarget::GrBackendRenderTarget(int width,
870 int height,
871 const GrVkImageInfo& vkInfo)
872 : GrBackendRenderTarget(width, height, vkInfo,
Greg Daniel6c6caf42020-05-29 12:11:05 -0400873 sk_sp<GrBackendSurfaceMutableStateImpl>(
874 new GrBackendSurfaceMutableStateImpl(
Brian Salomon57fd9232020-09-28 17:02:49 -0400875 vkInfo.fImageLayout, vkInfo.fCurrentQueueFamily))) {}
Greg Daniel323fbcf2018-04-10 13:46:30 -0400876
Greg Daniel7b62dca2020-08-21 11:26:12 -0400877static const VkImageUsageFlags kDefaultRTUsageFlags =
878 kDefaultUsageFlags | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
879
Greg Daniel323fbcf2018-04-10 13:46:30 -0400880GrBackendRenderTarget::GrBackendRenderTarget(int width,
881 int height,
Greg Daniel323fbcf2018-04-10 13:46:30 -0400882 const GrVkImageInfo& vkInfo,
Greg Daniel6c6caf42020-05-29 12:11:05 -0400883 sk_sp<GrBackendSurfaceMutableStateImpl> mutableState)
Greg Daniel9ca30652018-04-06 09:27:20 -0400884 : fIsValid(true)
885 , fWidth(width)
Greg Daniel94403452017-04-18 15:52:36 -0400886 , fHeight(height)
Brian Salomon57fd9232020-09-28 17:02:49 -0400887 , fSampleCnt(std::max(1U, vkInfo.fSampleCount))
Brian Salomonafdc6b12018-03-09 12:02:32 -0500888 , fStencilBits(0) // We always create stencil buffers internally for vulkan
Greg Danielbdf12ad2018-10-12 09:31:11 -0400889 , fBackend(GrBackendApi::kVulkan)
Greg Daniel7b62dca2020-08-21 11:26:12 -0400890 , fVkInfo(apply_default_usage_flags(vkInfo, kDefaultRTUsageFlags))
Brian Salomon57fd9232020-09-28 17:02:49 -0400891 , fMutableState(mutableState) {}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000892#endif
Greg Daniel94403452017-04-18 15:52:36 -0400893
Timothy Liang4e85e802018-06-28 16:37:18 -0400894#ifdef SK_METAL
895GrBackendRenderTarget::GrBackendRenderTarget(int width,
896 int height,
897 int sampleCnt,
898 const GrMtlTextureInfo& mtlInfo)
899 : fIsValid(true)
Stephen White3c0a50f2020-01-16 18:19:54 -0500900 , fFramebufferOnly(false) // TODO: set this from mtlInfo.fTexture->framebufferOnly
Timothy Liang4e85e802018-06-28 16:37:18 -0400901 , fWidth(width)
902 , fHeight(height)
Brian Osman788b9162020-02-07 10:36:46 -0500903 , fSampleCnt(std::max(1, sampleCnt))
Timothy Liang4e85e802018-06-28 16:37:18 -0400904 , fStencilBits(0)
Greg Danielbdf12ad2018-10-12 09:31:11 -0400905 , fBackend(GrBackendApi::kMetal)
Timothy Liang4e85e802018-06-28 16:37:18 -0400906 , fMtlInfo(mtlInfo) {}
907#endif
908
Jim Van Verth05d09192020-03-20 11:23:39 -0400909#ifdef SK_DIRECT3D
910GrBackendRenderTarget::GrBackendRenderTarget(int width, int height, int sampleCnt,
Jim Van Verth6ec56882020-03-26 11:47:26 -0400911 const GrD3DTextureResourceInfo& d3dInfo)
Jim Van Verth05d09192020-03-20 11:23:39 -0400912 : GrBackendRenderTarget(
913 width, height, sampleCnt, d3dInfo,
914 sk_sp<GrD3DResourceState>(new GrD3DResourceState(
915 static_cast<D3D12_RESOURCE_STATES>(d3dInfo.fResourceState)))) {}
916
917GrBackendRenderTarget::GrBackendRenderTarget(int width,
918 int height,
919 int sampleCnt,
Jim Van Verth6ec56882020-03-26 11:47:26 -0400920 const GrD3DTextureResourceInfo& d3dInfo,
Jim Van Verth05d09192020-03-20 11:23:39 -0400921 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 Rosascoa9b348f2019-11-08 13:18:15 -0800930#ifdef SK_GL
Greg Danielfaa095e2017-12-19 13:15:02 -0500931GrBackendRenderTarget::GrBackendRenderTarget(int width,
932 int height,
933 int sampleCnt,
934 int stencilBits,
935 const GrGLFramebufferInfo& glInfo)
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500936 : fWidth(width)
Greg Danielfaa095e2017-12-19 13:15:02 -0500937 , fHeight(height)
Brian Osman788b9162020-02-07 10:36:46 -0500938 , fSampleCnt(std::max(1, sampleCnt))
Greg Danielfaa095e2017-12-19 13:15:02 -0500939 , fStencilBits(stencilBits)
Greg Danielbdf12ad2018-10-12 09:31:11 -0400940 , fBackend(GrBackendApi::kOpenGL)
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500941 , fGLInfo(glInfo) {
942 fIsValid = SkToBool(glInfo.fFormat); // the glInfo must have a valid format
943}
John Rosascoa9b348f2019-11-08 13:18:15 -0800944#endif
Greg Danielfaa095e2017-12-19 13:15:02 -0500945
Brian Salomon0c51eea2018-03-09 17:02:09 -0500946GrBackendRenderTarget::GrBackendRenderTarget(int width,
947 int height,
948 int sampleCnt,
949 int stencilBits,
950 const GrMockRenderTargetInfo& mockInfo)
Greg Daniel9ca30652018-04-06 09:27:20 -0400951 : fIsValid(true)
952 , fWidth(width)
Brian Salomon0c51eea2018-03-09 17:02:09 -0500953 , fHeight(height)
Brian Osman788b9162020-02-07 10:36:46 -0500954 , fSampleCnt(std::max(1, sampleCnt))
Brian Salomon0c51eea2018-03-09 17:02:09 -0500955 , fStencilBits(stencilBits)
Brian Salomon0c51eea2018-03-09 17:02:09 -0500956 , fMockInfo(mockInfo) {}
957
Greg Daniel323fbcf2018-04-10 13:46:30 -0400958GrBackendRenderTarget::~GrBackendRenderTarget() {
959 this->cleanup();
960}
961
962void GrBackendRenderTarget::cleanup() {
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000963#ifdef SK_VULKAN
Greg Danielbdf12ad2018-10-12 09:31:11 -0400964 if (this->isValid() && GrBackendApi::kVulkan == fBackend) {
Greg Daniel323fbcf2018-04-10 13:46:30 -0400965 fVkInfo.cleanup();
966 }
967#endif
Jim Van Verth682a2f42020-05-13 16:54:09 -0400968#ifdef SK_DIRECT3D
969 if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
970 fD3DInfo.cleanup();
971 }
972#endif
Greg Daniel323fbcf2018-04-10 13:46:30 -0400973}
974
975GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTarget& that) : fIsValid(false) {
976 *this = that;
977}
978
979GrBackendRenderTarget& GrBackendRenderTarget::operator=(const GrBackendRenderTarget& that) {
980 if (!that.isValid()) {
981 this->cleanup();
982 fIsValid = false;
983 return *this;
Ben Wagnera797cc92019-06-05 23:59:46 -0400984 } else if (fIsValid && this->fBackend != that.fBackend) {
Brian Salomone2826ab2019-06-04 15:58:31 -0400985 this->cleanup();
986 fIsValid = false;
Greg Daniel323fbcf2018-04-10 13:46:30 -0400987 }
988 fWidth = that.fWidth;
989 fHeight = that.fHeight;
990 fSampleCnt = that.fSampleCnt;
991 fStencilBits = that.fStencilBits;
Greg Daniel323fbcf2018-04-10 13:46:30 -0400992 fBackend = that.fBackend;
993
994 switch (that.fBackend) {
John Rosascoa9b348f2019-11-08 13:18:15 -0800995#ifdef SK_GL
Greg Danielbdf12ad2018-10-12 09:31:11 -0400996 case GrBackendApi::kOpenGL:
Greg Daniel323fbcf2018-04-10 13:46:30 -0400997 fGLInfo = that.fGLInfo;
998 break;
John Rosasco078cf3e2019-10-31 16:21:39 -0700999#endif
John Rosascoa9b348f2019-11-08 13:18:15 -08001000#ifdef SK_VULKAN
1001 case GrBackendApi::kVulkan:
1002 fVkInfo.assign(that.fVkInfo, this->isValid());
Robert Phillips0efc01d2019-11-06 17:19:30 +00001003 break;
John Rosascoa9b348f2019-11-08 13:18:15 -08001004#endif
Greg Daniel323fbcf2018-04-10 13:46:30 -04001005#ifdef SK_METAL
Greg Danielbdf12ad2018-10-12 09:31:11 -04001006 case GrBackendApi::kMetal:
Jim Van Verth7730d7c2019-05-28 03:03:45 +00001007 fMtlInfo = that.fMtlInfo;
Greg Daniel323fbcf2018-04-10 13:46:30 -04001008 break;
1009#endif
Jim Van Verthb01e12b2020-02-18 14:34:38 -05001010#ifdef SK_DIRECT3D
1011 case GrBackendApi::kDirect3D:
Jim Van Verth05d09192020-03-20 11:23:39 -04001012 fD3DInfo.assign(that.fD3DInfo, this->isValid());
Jim Van Verthb01e12b2020-02-18 14:34:38 -05001013 break;
1014#endif
1015#ifdef SK_DAWN
1016 case GrBackendApi::kDawn:
1017 fDawnInfo = that.fDawnInfo;
1018 break;
1019#endif
Greg Danielbdf12ad2018-10-12 09:31:11 -04001020 case GrBackendApi::kMock:
Greg Daniel323fbcf2018-04-10 13:46:30 -04001021 fMockInfo = that.fMockInfo;
1022 break;
1023 default:
1024 SK_ABORT("Unknown GrBackend");
1025 }
Greg Daniel6c6caf42020-05-29 12:11:05 -04001026 fMutableState = that.fMutableState;
Greg Daniel323fbcf2018-04-10 13:46:30 -04001027 fIsValid = that.fIsValid;
1028 return *this;
1029}
1030
Greg Daniel6c6caf42020-05-29 12:11:05 -04001031sk_sp<GrBackendSurfaceMutableStateImpl> GrBackendRenderTarget::getMutableState() const {
1032 return fMutableState;
1033}
1034
Stephen White985741a2019-07-18 11:43:45 -04001035#ifdef SK_DAWN
Stephen Whitef03c1162020-01-28 12:39:45 -05001036bool GrBackendRenderTarget::getDawnRenderTargetInfo(GrDawnRenderTargetInfo* outInfo) const {
Stephen White985741a2019-07-18 11:43:45 -04001037 if (this->isValid() && GrBackendApi::kDawn == fBackend) {
1038 *outInfo = fDawnInfo;
1039 return true;
1040 }
1041 return false;
1042}
1043#endif
1044
Greg Daniel6c6caf42020-05-29 12:11:05 -04001045bool GrBackendRenderTarget::getVkImageInfo(GrVkImageInfo* outInfo) const {
Greg Danielcc7ec242020-05-29 14:43:36 -04001046#ifdef SK_VULKAN
Greg Danielbdf12ad2018-10-12 09:31:11 -04001047 if (this->isValid() && GrBackendApi::kVulkan == fBackend) {
Greg Daniel6c6caf42020-05-29 12:11:05 -04001048 *outInfo = fVkInfo.snapImageInfo(fMutableState.get());
Greg Daniel323fbcf2018-04-10 13:46:30 -04001049 return true;
1050 }
Greg Danielcc7ec242020-05-29 14:43:36 -04001051#endif
Greg Daniel323fbcf2018-04-10 13:46:30 -04001052 return false;
1053}
1054
1055void GrBackendRenderTarget::setVkImageLayout(VkImageLayout layout) {
Greg Danielcc7ec242020-05-29 14:43:36 -04001056#ifdef SK_VULKAN
Greg Danielbdf12ad2018-10-12 09:31:11 -04001057 if (this->isValid() && GrBackendApi::kVulkan == fBackend) {
Greg Daniel6c6caf42020-05-29 12:11:05 -04001058 fMutableState->setImageLayout(layout);
Greg Daniel323fbcf2018-04-10 13:46:30 -04001059 }
Brian Salomone2826ab2019-06-04 15:58:31 -04001060#endif
Greg Danielcc7ec242020-05-29 14:43:36 -04001061}
Greg Daniel94403452017-04-18 15:52:36 -04001062
Timothy Liang4e85e802018-06-28 16:37:18 -04001063#ifdef SK_METAL
1064bool GrBackendRenderTarget::getMtlTextureInfo(GrMtlTextureInfo* outInfo) const {
Greg Danielbdf12ad2018-10-12 09:31:11 -04001065 if (this->isValid() && GrBackendApi::kMetal == fBackend) {
Jim Van Verth7730d7c2019-05-28 03:03:45 +00001066 *outInfo = fMtlInfo;
Timothy Liang4e85e802018-06-28 16:37:18 -04001067 return true;
1068 }
1069 return false;
1070}
1071#endif
1072
Jim Van Verth05d09192020-03-20 11:23:39 -04001073#ifdef SK_DIRECT3D
Jim Van Verthaa90dad2020-03-30 15:00:39 -04001074bool GrBackendRenderTarget::getD3DTextureResourceInfo(GrD3DTextureResourceInfo* outInfo) const {
Jim Van Verth05d09192020-03-20 11:23:39 -04001075 if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
Jim Van Verth6ec56882020-03-26 11:47:26 -04001076 *outInfo = fD3DInfo.snapTextureResourceInfo();
Jim Van Verth05d09192020-03-20 11:23:39 -04001077 return true;
1078 }
1079 return false;
1080}
1081
1082void GrBackendRenderTarget::setD3DResourceState(GrD3DResourceStateEnum state) {
1083 if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
1084 fD3DInfo.setResourceState(state);
1085 }
1086}
1087
1088sk_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 Rosascoa9b348f2019-11-08 13:18:15 -08001096#ifdef SK_GL
Greg Daniel323fbcf2018-04-10 13:46:30 -04001097bool GrBackendRenderTarget::getGLFramebufferInfo(GrGLFramebufferInfo* outInfo) const {
Greg Danielbdf12ad2018-10-12 09:31:11 -04001098 if (this->isValid() && GrBackendApi::kOpenGL == fBackend) {
Greg Daniel323fbcf2018-04-10 13:46:30 -04001099 *outInfo = fGLInfo;
1100 return true;
Greg Daniel94403452017-04-18 15:52:36 -04001101 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04001102 return false;
Greg Daniel94403452017-04-18 15:52:36 -04001103}
John Rosascoa9b348f2019-11-08 13:18:15 -08001104#endif
Greg Daniel94403452017-04-18 15:52:36 -04001105
Robert Phillipsf209e882019-06-25 15:59:50 -04001106GrBackendFormat 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 Daniel6c6caf42020-05-29 12:11:05 -04001117 auto info = fVkInfo.snapImageInfo(fMutableState.get());
Robert Phillipsf209e882019-06-25 15:59:50 -04001118 if (info.fYcbcrConversionInfo.isValid()) {
Sergey Ulanov2739fd22019-08-11 22:46:33 -07001119 SkASSERT(info.fFormat == info.fYcbcrConversionInfo.fFormat);
Robert Phillipsf209e882019-06-25 15:59:50 -04001120 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 Verthb01e12b2020-02-18 14:34:38 -05001132#ifdef SK_DIRECT3D
1133 case GrBackendApi::kDirect3D: {
Jim Van Verth6ec56882020-03-26 11:47:26 -04001134 auto info = fD3DInfo.snapTextureResourceInfo();
Jim Van Verth05d09192020-03-20 11:23:39 -04001135 return GrBackendFormat::MakeDxgi(info.fFormat);
Jim Van Verthb01e12b2020-02-18 14:34:38 -05001136 }
1137#endif
Stephen Whitef03c1162020-01-28 12:39:45 -05001138#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 Phillipsf209e882019-06-25 15:59:50 -04001145 case GrBackendApi::kMock:
Robert Phillipsa5e78be2019-07-09 12:34:38 -04001146 return fMockInfo.getBackendFormat();
Robert Phillipsf209e882019-06-25 15:59:50 -04001147 default:
1148 return GrBackendFormat();
1149 }
1150}
1151
Greg Daniel323fbcf2018-04-10 13:46:30 -04001152bool GrBackendRenderTarget::getMockRenderTargetInfo(GrMockRenderTargetInfo* outInfo) const {
Greg Danielbdf12ad2018-10-12 09:31:11 -04001153 if (this->isValid() && GrBackendApi::kMock == fBackend) {
Greg Daniel323fbcf2018-04-10 13:46:30 -04001154 *outInfo = fMockInfo;
1155 return true;
Brian Salomon0c51eea2018-03-09 17:02:09 -05001156 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04001157 return false;
Brian Salomon0c51eea2018-03-09 17:02:09 -05001158}
Robert Phillips8caf85f2018-04-05 09:30:38 -04001159
Greg Daniel6c6caf42020-05-29 12:11:05 -04001160void GrBackendRenderTarget::setMutableState(const GrBackendSurfaceMutableState& state) {
1161 fMutableState->set(state);
1162}
1163
Brian Salomon4456a0d2019-07-18 15:05:11 -04001164bool GrBackendRenderTarget::isProtected() const {
1165 if (!this->isValid() || this->backend() != GrBackendApi::kVulkan) {
1166 return false;
1167 }
1168 return fVkInfo.isProtected();
1169}
1170
Robert Phillips8caf85f2018-04-05 09:30:38 -04001171#if GR_TEST_UTILS
1172bool 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 Phillips8caf85f2018-04-05 09:30:38 -04001182 r0.fBackend != r1.fBackend) {
1183 return false;
1184 }
1185
1186 switch (r0.fBackend) {
Brian Salomone2826ab2019-06-04 15:58:31 -04001187#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 Phillips8caf85f2018-04-05 09:30:38 -04001193#ifdef SK_VULKAN
Brian Salomone2826ab2019-06-04 15:58:31 -04001194 case GrBackendApi::kVulkan:
1195 return r0.fVkInfo == r1.fVkInfo;
Robert Phillips8caf85f2018-04-05 09:30:38 -04001196#endif
Timothy Liang4e85e802018-06-28 16:37:18 -04001197#ifdef SK_METAL
Brian Salomone2826ab2019-06-04 15:58:31 -04001198 case GrBackendApi::kMetal:
1199 return r0.fMtlInfo == r1.fMtlInfo;
Timothy Liang4e85e802018-06-28 16:37:18 -04001200#endif
Jim Van Verthb01e12b2020-02-18 14:34:38 -05001201#ifdef SK_DIRECT3D
1202 case GrBackendApi::kDirect3D:
Jim Van Verth05d09192020-03-20 11:23:39 -04001203 return r0.fD3DInfo == r1.fD3DInfo;
Jim Van Verthb01e12b2020-02-18 14:34:38 -05001204#endif
Stephen White985741a2019-07-18 11:43:45 -04001205#ifdef SK_DAWN
1206 case GrBackendApi::kDawn:
1207 return r0.fDawnInfo == r1.fDawnInfo;
1208#endif
Brian Salomone2826ab2019-06-04 15:58:31 -04001209 default:
1210 return false;
Robert Phillips8caf85f2018-04-05 09:30:38 -04001211 }
1212
1213 SkASSERT(0);
1214 return false;
1215}
1216#endif