blob: e98f6af2c2c910bead917a0ee6a794f95df2e702 [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
8#ifndef GrBackendSurface_DEFINED
9#define GrBackendSurface_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrTypes.h"
12#include "include/gpu/gl/GrGLTypes.h"
13#include "include/gpu/mock/GrMockTypes.h"
14#include "include/gpu/vk/GrVkTypes.h"
Brian Salomone2826ab2019-06-04 15:58:31 -040015#include "include/private/GrGLTypesPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/private/GrVkTypesPriv.h"
Greg Daniel52e16d92018-04-10 09:34:07 -040017
Stephen White985741a2019-07-18 11:43:45 -040018#ifdef SK_DAWN
19#include "include/gpu/dawn/GrDawnTypes.h"
20#endif
21
Greg Daniel52e16d92018-04-10 09:34:07 -040022class GrVkImageLayout;
Brian Salomone2826ab2019-06-04 15:58:31 -040023class GrGLTextureParameters;
Greg Daniel94403452017-04-18 15:52:36 -040024
Stephen White985741a2019-07-18 11:43:45 -040025#ifdef SK_DAWN
26#include "dawn/dawncpp.h"
27#endif
28
Timothy Liang4e85e802018-06-28 16:37:18 -040029#ifdef SK_METAL
Mike Kleinc0bd9f92019-04-23 12:05:21 -050030#include "include/gpu/mtl/GrMtlTypes.h"
Timothy Liang4e85e802018-06-28 16:37:18 -040031#endif
32
Robert Phillipsbac46722019-08-01 15:09:17 -040033#if GR_TEST_UTILS
34class SkString;
35#endif
36
Robert Phillips8caf85f2018-04-05 09:30:38 -040037#if !SK_SUPPORT_GPU
38
39// SkSurface and SkImage rely on a minimal version of these always being available
40class SK_API GrBackendTexture {
41public:
42 GrBackendTexture() {}
43
44 bool isValid() const { return false; }
45};
46
47class SK_API GrBackendRenderTarget {
48public:
49 GrBackendRenderTarget() {}
50
51 bool isValid() const { return false; }
52};
53#else
54
Brian Salomond4764a12019-08-08 12:08:24 -040055enum class GrGLFormat;
56
Robert Phillipsfc711a22018-02-13 17:03:00 -050057class SK_API GrBackendFormat {
58public:
59 // Creates an invalid backend format.
Robert Phillipsb2adbef2019-07-02 16:33:05 -040060 GrBackendFormat() {}
61
62 GrBackendFormat(const GrBackendFormat& src);
Robert Phillipsfc711a22018-02-13 17:03:00 -050063
64 static GrBackendFormat MakeGL(GrGLenum format, GrGLenum target) {
65 return GrBackendFormat(format, target);
66 }
67
Greg Daniela8d92112018-03-09 12:05:04 -050068 static GrBackendFormat MakeVk(VkFormat format) {
Greg Daniel7e000222018-12-03 10:08:21 -050069 return GrBackendFormat(format, GrVkYcbcrConversionInfo());
Robert Phillipsfc711a22018-02-13 17:03:00 -050070 }
Robert Phillipsfc711a22018-02-13 17:03:00 -050071
Greg Daniel7e000222018-12-03 10:08:21 -050072 static GrBackendFormat MakeVk(const GrVkYcbcrConversionInfo& ycbcrInfo);
73
Stephen White985741a2019-07-18 11:43:45 -040074#ifdef SK_DAWN
75 static GrBackendFormat MakeDawn(dawn::TextureFormat format) {
76 return GrBackendFormat(format);
77 }
78#endif
79
Timothy Liang4e85e802018-06-28 16:37:18 -040080#ifdef SK_METAL
81 static GrBackendFormat MakeMtl(GrMTLPixelFormat format) {
82 return GrBackendFormat(format);
83 }
84#endif
85
Greg Daniele877dce2019-07-11 10:52:43 -040086 static GrBackendFormat MakeMock(GrColorType colorType) {
87 return GrBackendFormat(colorType);
Robert Phillipsfc711a22018-02-13 17:03:00 -050088 }
89
Greg Daniel45723ac2018-11-30 10:12:43 -050090 bool operator==(const GrBackendFormat& that) const;
91 bool operator!=(const GrBackendFormat& that) const { return !(*this == that); }
92
Greg Daniel4065d452018-11-16 15:43:41 -050093 GrBackendApi backend() const { return fBackend; }
94 GrTextureType textureType() const { return fTextureType; }
Robert Phillipsfc711a22018-02-13 17:03:00 -050095
Brian Salomond4764a12019-08-08 12:08:24 -040096 /**
97 * If the backend API is GL this gets the format as a GrGLFormat. Otherwise, returns
98 * GrGLFormat::kUnknown.
99 */
100 GrGLFormat asGLFormat() const;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500101
Brian Salomond4764a12019-08-08 12:08:24 -0400102 /**
103 * If the backend API is Vulkan this gets the format as a VkFormat and returns true. Otherwise,
104 * returns false.
105 */
106 bool asVkFormat(VkFormat*) const;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500107
Greg Daniel7e000222018-12-03 10:08:21 -0500108 const GrVkYcbcrConversionInfo* getVkYcbcrConversionInfo() const;
109
Stephen White985741a2019-07-18 11:43:45 -0400110#ifdef SK_DAWN
Brian Salomond4764a12019-08-08 12:08:24 -0400111 /**
112 * If the backend API is Dawn this gets the format as a dawn::TextureFormat and returns true.
113 * Otherwise, returns false.
114 */
115 bool asDawnFormat(dawn::TextureFormat*) const;
Stephen White985741a2019-07-18 11:43:45 -0400116#endif
117
Timothy Liang4e85e802018-06-28 16:37:18 -0400118#ifdef SK_METAL
Brian Salomond4764a12019-08-08 12:08:24 -0400119 /**
120 * If the backend API is Metal this gets the format as a GrMtlPixelFormat. Otherwise,
121 * Otherwise, returns MTLPixelFormatInvalid.
122 */
123 GrMTLPixelFormat asMtlFormat() const;
Timothy Liang4e85e802018-06-28 16:37:18 -0400124#endif
125
Brian Salomond4764a12019-08-08 12:08:24 -0400126 /**
127 * If the backend API is Mock this gets the format as a GrColorType. Otherwise, returns
128 * GrColorType::kUnknown.
129 */
130 GrColorType asMockColorType() const;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500131
Greg Daniel387ec9a2019-03-07 16:44:54 -0500132 // If possible, copies the GrBackendFormat and forces the texture type to be Texture2D. If the
133 // GrBackendFormat was for Vulkan and it originally had a GrVkYcbcrConversionInfo, we will
134 // remove the conversion and set the format to be VK_FORMAT_R8G8B8A8_UNORM.
Greg Daniel4065d452018-11-16 15:43:41 -0500135 GrBackendFormat makeTexture2D() const;
136
Robert Phillipsfc711a22018-02-13 17:03:00 -0500137 // Returns true if the backend format has been initialized.
138 bool isValid() const { return fValid; }
139
Robert Phillipsbac46722019-08-01 15:09:17 -0400140#if GR_TEST_UTILS
141 SkString toStr() const;
142#endif
143
Robert Phillipsfc711a22018-02-13 17:03:00 -0500144private:
145 GrBackendFormat(GrGLenum format, GrGLenum target);
146
Greg Daniel7e000222018-12-03 10:08:21 -0500147 GrBackendFormat(const VkFormat vkFormat, const GrVkYcbcrConversionInfo&);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500148
Stephen White985741a2019-07-18 11:43:45 -0400149#ifdef SK_DAWN
150 GrBackendFormat(dawn::TextureFormat format);
151#endif
152
Timothy Liang4e85e802018-06-28 16:37:18 -0400153#ifdef SK_METAL
154 GrBackendFormat(const GrMTLPixelFormat mtlFormat);
155#endif
156
Greg Daniele877dce2019-07-11 10:52:43 -0400157 GrBackendFormat(GrColorType colorType);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500158
Robert Phillipsb2adbef2019-07-02 16:33:05 -0400159 GrBackendApi fBackend = GrBackendApi::kMock;
160 bool fValid = false;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500161
162 union {
Greg Daniel4065d452018-11-16 15:43:41 -0500163 GrGLenum fGLFormat; // the sized, internal format of the GL resource
Greg Daniel7e000222018-12-03 10:08:21 -0500164 struct {
165 VkFormat fFormat;
166 GrVkYcbcrConversionInfo fYcbcrConversionInfo;
Robert Phillips9dbcdcc2019-05-13 10:40:06 -0400167 } fVk;
Stephen White985741a2019-07-18 11:43:45 -0400168#ifdef SK_DAWN
169 dawn::TextureFormat fDawnFormat;
170#endif
171
Timothy Liang4e85e802018-06-28 16:37:18 -0400172#ifdef SK_METAL
173 GrMTLPixelFormat fMtlFormat;
174#endif
Greg Daniele877dce2019-07-11 10:52:43 -0400175 GrColorType fMockColorType;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500176 };
Robert Phillipsb2adbef2019-07-02 16:33:05 -0400177 GrTextureType fTextureType = GrTextureType::kNone;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500178};
179
Brian Salomonec045b42017-07-07 10:34:40 -0400180class SK_API GrBackendTexture {
Greg Daniel94403452017-04-18 15:52:36 -0400181public:
Brian Salomon8fe24272017-07-07 12:56:11 -0400182 // Creates an invalid backend texture.
Greg Daniel9ca30652018-04-06 09:27:20 -0400183 GrBackendTexture() : fIsValid(false) {}
Brian Salomon8fe24272017-07-07 12:56:11 -0400184
Greg Daniele7d8da42017-12-04 11:23:19 -0500185 // The GrGLTextureInfo must have a valid fFormat.
186 GrBackendTexture(int width,
187 int height,
188 GrMipMapped,
189 const GrGLTextureInfo& glInfo);
190
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000191 GrBackendTexture(int width,
192 int height,
193 const GrVkImageInfo& vkInfo);
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000194
Timothy Liang4e85e802018-06-28 16:37:18 -0400195#ifdef SK_METAL
196 GrBackendTexture(int width,
197 int height,
198 GrMipMapped,
199 const GrMtlTextureInfo& mtlInfo);
200#endif
201
Stephen White985741a2019-07-18 11:43:45 -0400202#ifdef SK_DAWN
203 GrBackendTexture(int width,
204 int height,
205 const GrDawnImageInfo& dawnInfo);
206#endif
207
Brian Salomon8fe24272017-07-07 12:56:11 -0400208 GrBackendTexture(int width,
209 int height,
Greg Daniel177e6952017-10-12 12:27:11 -0400210 GrMipMapped,
211 const GrMockTextureInfo& mockInfo);
212
Greg Daniel52e16d92018-04-10 09:34:07 -0400213 GrBackendTexture(const GrBackendTexture& that);
214
215 ~GrBackendTexture();
216
217 GrBackendTexture& operator=(const GrBackendTexture& that);
218
Greg Daniel94403452017-04-18 15:52:36 -0400219 int width() const { return fWidth; }
220 int height() const { return fHeight; }
Greg Daniel177e6952017-10-12 12:27:11 -0400221 bool hasMipMaps() const { return GrMipMapped::kYes == fMipMapped; }
Greg Danielbdf12ad2018-10-12 09:31:11 -0400222 GrBackendApi backend() const {return fBackend; }
Greg Daniel94403452017-04-18 15:52:36 -0400223
Greg Daniel52e16d92018-04-10 09:34:07 -0400224 // If the backend API is GL, copies a snapshot of the GrGLTextureInfo struct into the passed in
225 // pointer and returns true. Otherwise returns false if the backend API is not GL.
226 bool getGLTextureInfo(GrGLTextureInfo*) const;
Greg Danielc0f8e422017-06-13 13:47:53 -0400227
Brian Salomone2826ab2019-06-04 15:58:31 -0400228 // Call this to indicate that the texture parameters have been modified in the GL context
229 // externally to GrContext.
230 void glTextureParametersModified();
231
Stephen White985741a2019-07-18 11:43:45 -0400232#ifdef SK_DAWN
233 // If the backend API is Dawn, copies a snapshot of the GrDawnImageInfo struct into the passed
234 // in pointer and returns true. Otherwise returns false if the backend API is not Dawn.
235 bool getDawnImageInfo(GrDawnImageInfo*) const;
236#endif
237
Greg Daniel323fbcf2018-04-10 13:46:30 -0400238 // If the backend API is Vulkan, copies a snapshot of the GrVkImageInfo struct into the passed
Greg Daniel52e16d92018-04-10 09:34:07 -0400239 // in pointer and returns true. This snapshot will set the fImageLayout to the current layout
240 // state. Otherwise returns false if the backend API is not Vulkan.
241 bool getVkImageInfo(GrVkImageInfo*) const;
242
Greg Daniel323fbcf2018-04-10 13:46:30 -0400243 // Anytime the client changes the VkImageLayout of the VkImage captured by this
244 // GrBackendTexture, they must call this function to notify Skia of the changed layout.
Greg Daniel52e16d92018-04-10 09:34:07 -0400245 void setVkImageLayout(VkImageLayout);
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000246
Timothy Liang4e85e802018-06-28 16:37:18 -0400247#ifdef SK_METAL
248 // If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed
249 // in pointer and returns true. Otherwise returns false if the backend API is not Metal.
250 bool getMtlTextureInfo(GrMtlTextureInfo*) const;
251#endif
252
Brian Salomonf391d0f2018-12-14 09:18:50 -0500253 // Get the GrBackendFormat for this texture (or an invalid format if this is not valid).
254 GrBackendFormat getBackendFormat() const;
255
Greg Daniel52e16d92018-04-10 09:34:07 -0400256 // If the backend API is Mock, copies a snapshot of the GrMockTextureInfo struct into the passed
257 // in pointer and returns true. Otherwise returns false if the backend API is not Mock.
258 bool getMockTextureInfo(GrMockTextureInfo*) const;
Brian Salomon8fe24272017-07-07 12:56:11 -0400259
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400260 // Returns true if we are working with protected content.
Brian Salomon4456a0d2019-07-18 15:05:11 -0400261 bool isProtected() const;
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400262
Eric Karl914a36b2017-10-12 12:44:50 -0700263 // Returns true if the backend texture has been initialized.
Greg Daniel9ca30652018-04-06 09:27:20 -0400264 bool isValid() const { return fIsValid; }
Brian Salomon8fe24272017-07-07 12:56:11 -0400265
Brian Salomonaad83152019-05-24 10:16:35 -0400266 // Returns true if both textures are valid and refer to the same API texture.
267 bool isSameTexture(const GrBackendTexture&);
268
Robert Phillipsc5509952018-04-04 15:54:55 -0400269#if GR_TEST_UTILS
Robert Phillipsc5509952018-04-04 15:54:55 -0400270 static bool TestingOnly_Equals(const GrBackendTexture& , const GrBackendTexture&);
271#endif
Greg Daniel2a303902018-02-20 10:25:54 -0500272
Eric Karl914a36b2017-10-12 12:44:50 -0700273private:
Greg Daniel5254ccc2017-11-13 11:05:52 -0500274
Brian Salomone2826ab2019-06-04 15:58:31 -0400275#ifdef SK_GL
276 friend class GrGLTexture;
Robert Phillips62221e72019-07-24 15:07:38 -0400277 friend class GrGLGpu; // for getGLTextureParams
Brian Salomone2826ab2019-06-04 15:58:31 -0400278 GrBackendTexture(int width,
279 int height,
280 GrMipMapped,
281 const GrGLTextureInfo,
282 sk_sp<GrGLTextureParameters>);
283 sk_sp<GrGLTextureParameters> getGLTextureParams() const;
284#endif
Greg Daniel52e16d92018-04-10 09:34:07 -0400285
Greg Danielb4d89562018-10-03 18:44:49 +0000286#ifdef SK_VULKAN
Brian Salomone2826ab2019-06-04 15:58:31 -0400287 friend class GrVkTexture;
Robert Phillips62221e72019-07-24 15:07:38 -0400288 friend class GrVkGpu; // for getGrVkImageLayout
Brian Salomone2826ab2019-06-04 15:58:31 -0400289 GrBackendTexture(int width,
290 int height,
291 const GrVkImageInfo& vkInfo,
292 sk_sp<GrVkImageLayout> layout);
293 sk_sp<GrVkImageLayout> getGrVkImageLayout() const;
Greg Daniel52e16d92018-04-10 09:34:07 -0400294#endif
295
296 // Free and release and resources being held by the GrBackendTexture.
297 void cleanup();
298
Greg Daniel9ca30652018-04-06 09:27:20 -0400299 bool fIsValid;
Greg Daniel94403452017-04-18 15:52:36 -0400300 int fWidth; //<! width in pixels
301 int fHeight; //<! height in pixels
Greg Daniel177e6952017-10-12 12:27:11 -0400302 GrMipMapped fMipMapped;
Greg Danielbdf12ad2018-10-12 09:31:11 -0400303 GrBackendApi fBackend;
Greg Daniel94403452017-04-18 15:52:36 -0400304
305 union {
Brian Salomone2826ab2019-06-04 15:58:31 -0400306#ifdef SK_GL
307 GrGLBackendTextureInfo fGLInfo;
308#endif
Greg Daniel52e16d92018-04-10 09:34:07 -0400309 GrVkBackendSurfaceInfo fVkInfo;
Brian Salomon8fe24272017-07-07 12:56:11 -0400310 GrMockTextureInfo fMockInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400311 };
Jim Van Verthdac1e552019-05-31 09:10:55 -0400312#ifdef SK_METAL
313 GrMtlTextureInfo fMtlInfo;
314#endif
Stephen White985741a2019-07-18 11:43:45 -0400315#ifdef SK_DAWN
316 GrDawnImageInfo fDawnInfo;
317#endif
Greg Daniel94403452017-04-18 15:52:36 -0400318};
319
Brian Salomonec045b42017-07-07 10:34:40 -0400320class SK_API GrBackendRenderTarget {
Greg Daniel94403452017-04-18 15:52:36 -0400321public:
Robert Phillips57e08282017-11-16 14:59:48 -0500322 // Creates an invalid backend texture.
Greg Daniel9ca30652018-04-06 09:27:20 -0400323 GrBackendRenderTarget() : fIsValid(false) {}
Robert Phillips57e08282017-11-16 14:59:48 -0500324
Greg Danielfaa095e2017-12-19 13:15:02 -0500325 // The GrGLTextureInfo must have a valid fFormat.
326 GrBackendRenderTarget(int width,
327 int height,
328 int sampleCnt,
329 int stencilBits,
330 const GrGLFramebufferInfo& glInfo);
331
Stephen White985741a2019-07-18 11:43:45 -0400332#ifdef SK_DAWN
333 GrBackendRenderTarget(int width,
334 int height,
335 int sampleCnt,
336 int stencilBits,
337 const GrDawnImageInfo& dawnInfo);
338#endif
339
Brian Salomonafdc6b12018-03-09 12:02:32 -0500340 /** Deprecated, use version that does not take stencil bits. */
Greg Daniel94403452017-04-18 15:52:36 -0400341 GrBackendRenderTarget(int width,
342 int height,
343 int sampleCnt,
344 int stencilBits,
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000345 const GrVkImageInfo& vkInfo);
Brian Salomonafdc6b12018-03-09 12:02:32 -0500346 GrBackendRenderTarget(int width, int height, int sampleCnt, const GrVkImageInfo& vkInfo);
Greg Daniel94403452017-04-18 15:52:36 -0400347
Timothy Liang4e85e802018-06-28 16:37:18 -0400348#ifdef SK_METAL
349 GrBackendRenderTarget(int width,
350 int height,
351 int sampleCnt,
352 const GrMtlTextureInfo& mtlInfo);
353#endif
354
Brian Salomon0c51eea2018-03-09 17:02:09 -0500355 GrBackendRenderTarget(int width,
356 int height,
357 int sampleCnt,
358 int stencilBits,
359 const GrMockRenderTargetInfo& mockInfo);
360
Greg Daniel323fbcf2018-04-10 13:46:30 -0400361 ~GrBackendRenderTarget();
362
363 GrBackendRenderTarget(const GrBackendRenderTarget& that);
364 GrBackendRenderTarget& operator=(const GrBackendRenderTarget&);
365
Greg Daniel94403452017-04-18 15:52:36 -0400366 int width() const { return fWidth; }
367 int height() const { return fHeight; }
368 int sampleCnt() const { return fSampleCnt; }
369 int stencilBits() const { return fStencilBits; }
Greg Danielbdf12ad2018-10-12 09:31:11 -0400370 GrBackendApi backend() const {return fBackend; }
Greg Daniel94403452017-04-18 15:52:36 -0400371
Greg Daniel323fbcf2018-04-10 13:46:30 -0400372 // If the backend API is GL, copies a snapshot of the GrGLFramebufferInfo struct into the passed
373 // in pointer and returns true. Otherwise returns false if the backend API is not GL.
374 bool getGLFramebufferInfo(GrGLFramebufferInfo*) const;
Greg Danielc0f8e422017-06-13 13:47:53 -0400375
Stephen White985741a2019-07-18 11:43:45 -0400376#ifdef SK_DAWN
377 // If the backend API is Dawn, copies a snapshot of the GrDawnImageInfo struct into the passed
378 // in pointer and returns true. Otherwise returns false if the backend API is not Dawn.
379 bool getDawnImageInfo(GrDawnImageInfo*) const;
380#endif
381
Greg Daniel323fbcf2018-04-10 13:46:30 -0400382 // If the backend API is Vulkan, copies a snapshot of the GrVkImageInfo struct into the passed
383 // in pointer and returns true. This snapshot will set the fImageLayout to the current layout
384 // state. Otherwise returns false if the backend API is not Vulkan.
385 bool getVkImageInfo(GrVkImageInfo*) const;
386
387 // Anytime the client changes the VkImageLayout of the VkImage captured by this
388 // GrBackendRenderTarget, they must call this function to notify Skia of the changed layout.
389 void setVkImageLayout(VkImageLayout);
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000390
Timothy Liang4e85e802018-06-28 16:37:18 -0400391#ifdef SK_METAL
392 // If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed
393 // in pointer and returns true. Otherwise returns false if the backend API is not Metal.
394 bool getMtlTextureInfo(GrMtlTextureInfo*) const;
395#endif
396
Robert Phillipsf209e882019-06-25 15:59:50 -0400397 // Get the GrBackendFormat for this render target (or an invalid format if this is not valid).
398 GrBackendFormat getBackendFormat() const;
399
Greg Daniel323fbcf2018-04-10 13:46:30 -0400400 // If the backend API is Mock, copies a snapshot of the GrMockTextureInfo struct into the passed
401 // in pointer and returns true. Otherwise returns false if the backend API is not Mock.
402 bool getMockRenderTargetInfo(GrMockRenderTargetInfo*) const;
Brian Salomon0c51eea2018-03-09 17:02:09 -0500403
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400404 // Returns true if we are working with protected content.
Brian Salomon4456a0d2019-07-18 15:05:11 -0400405 bool isProtected() const;
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400406
Robert Phillips57e08282017-11-16 14:59:48 -0500407 // Returns true if the backend texture has been initialized.
Greg Daniel9ca30652018-04-06 09:27:20 -0400408 bool isValid() const { return fIsValid; }
Robert Phillips57e08282017-11-16 14:59:48 -0500409
Robert Phillips8caf85f2018-04-05 09:30:38 -0400410
411#if GR_TEST_UTILS
Robert Phillips8caf85f2018-04-05 09:30:38 -0400412 static bool TestingOnly_Equals(const GrBackendRenderTarget&, const GrBackendRenderTarget&);
413#endif
Greg Daniel2a303902018-02-20 10:25:54 -0500414
Greg Daniel94403452017-04-18 15:52:36 -0400415private:
Robert Phillips62221e72019-07-24 15:07:38 -0400416 friend class GrVkGpu; // for getGrVkImageLayout
Brian Salomon4456a0d2019-07-18 15:05:11 -0400417 sk_sp<GrVkImageLayout> getGrVkImageLayout() const;
Greg Daniel323fbcf2018-04-10 13:46:30 -0400418
Brian Salomon4456a0d2019-07-18 15:05:11 -0400419 friend class GrVkRenderTarget;
420 GrBackendRenderTarget(int width, int height, int sampleCnt, const GrVkImageInfo& vkInfo,
421 sk_sp<GrVkImageLayout> layout);
Greg Daniel323fbcf2018-04-10 13:46:30 -0400422
423 // Free and release and resources being held by the GrBackendTexture.
424 void cleanup();
425
Greg Daniel9ca30652018-04-06 09:27:20 -0400426 bool fIsValid;
Greg Daniel94403452017-04-18 15:52:36 -0400427 int fWidth; //<! width in pixels
428 int fHeight; //<! height in pixels
429
430 int fSampleCnt;
431 int fStencilBits;
Jim Van Verth7730d7c2019-05-28 03:03:45 +0000432
Greg Danielbdf12ad2018-10-12 09:31:11 -0400433 GrBackendApi fBackend;
Greg Daniel94403452017-04-18 15:52:36 -0400434
435 union {
Robert Phillipsf209e882019-06-25 15:59:50 -0400436#ifdef SK_GL
Robert Phillipsfad9e3f2017-06-13 22:16:08 +0000437 GrGLFramebufferInfo fGLInfo;
Robert Phillipsf209e882019-06-25 15:59:50 -0400438#endif
Greg Daniel323fbcf2018-04-10 13:46:30 -0400439 GrVkBackendSurfaceInfo fVkInfo;
Brian Salomon0c51eea2018-03-09 17:02:09 -0500440 GrMockRenderTargetInfo fMockInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400441 };
Jim Van Verthdac1e552019-05-31 09:10:55 -0400442#ifdef SK_METAL
443 GrMtlTextureInfo fMtlInfo;
444#endif
Stephen White985741a2019-07-18 11:43:45 -0400445#ifdef SK_DAWN
446 GrDawnImageInfo fDawnInfo;
447#endif
Greg Daniel94403452017-04-18 15:52:36 -0400448};
449
450#endif
451
Robert Phillips8caf85f2018-04-05 09:30:38 -0400452#endif
453