blob: cf7543fd5e66a327f00de947b6750784ab0ac0b3 [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 Phillips8caf85f2018-04-05 09:30:38 -040033#if !SK_SUPPORT_GPU
34
35// SkSurface and SkImage rely on a minimal version of these always being available
36class SK_API GrBackendTexture {
37public:
38 GrBackendTexture() {}
39
40 bool isValid() const { return false; }
41};
42
43class SK_API GrBackendRenderTarget {
44public:
45 GrBackendRenderTarget() {}
46
47 bool isValid() const { return false; }
48};
49#else
50
Robert Phillipsfc711a22018-02-13 17:03:00 -050051class SK_API GrBackendFormat {
52public:
53 // Creates an invalid backend format.
Robert Phillipsb2adbef2019-07-02 16:33:05 -040054 GrBackendFormat() {}
55
56 GrBackendFormat(const GrBackendFormat& src);
Robert Phillipsfc711a22018-02-13 17:03:00 -050057
58 static GrBackendFormat MakeGL(GrGLenum format, GrGLenum target) {
59 return GrBackendFormat(format, target);
60 }
61
Greg Daniela8d92112018-03-09 12:05:04 -050062 static GrBackendFormat MakeVk(VkFormat format) {
Greg Daniel7e000222018-12-03 10:08:21 -050063 return GrBackendFormat(format, GrVkYcbcrConversionInfo());
Robert Phillipsfc711a22018-02-13 17:03:00 -050064 }
Robert Phillipsfc711a22018-02-13 17:03:00 -050065
Greg Daniel7e000222018-12-03 10:08:21 -050066 // This is used for external textures and the VkFormat is assumed to be VK_FORMAT_UNDEFINED.
67 // This call is only supported on Android since the GrVkYcbcrConvesionInfo contains an android
68 // external format.
69 static GrBackendFormat MakeVk(const GrVkYcbcrConversionInfo& ycbcrInfo);
70
Stephen White985741a2019-07-18 11:43:45 -040071#ifdef SK_DAWN
72 static GrBackendFormat MakeDawn(dawn::TextureFormat format) {
73 return GrBackendFormat(format);
74 }
75#endif
76
Timothy Liang4e85e802018-06-28 16:37:18 -040077#ifdef SK_METAL
78 static GrBackendFormat MakeMtl(GrMTLPixelFormat format) {
79 return GrBackendFormat(format);
80 }
81#endif
82
Greg Daniele877dce2019-07-11 10:52:43 -040083 static GrBackendFormat MakeMock(GrColorType colorType) {
84 return GrBackendFormat(colorType);
Robert Phillipsfc711a22018-02-13 17:03:00 -050085 }
86
Greg Daniel45723ac2018-11-30 10:12:43 -050087 bool operator==(const GrBackendFormat& that) const;
88 bool operator!=(const GrBackendFormat& that) const { return !(*this == that); }
89
Greg Daniel4065d452018-11-16 15:43:41 -050090 GrBackendApi backend() const { return fBackend; }
91 GrTextureType textureType() const { return fTextureType; }
Robert Phillipsfc711a22018-02-13 17:03:00 -050092
93 // If the backend API is GL, these return a pointer to the format and target. Otherwise
Robert Phillipsa5e78be2019-07-09 12:34:38 -040094 // they return nullptr.
Robert Phillipsfc711a22018-02-13 17:03:00 -050095 const GrGLenum* getGLFormat() const;
96 const GrGLenum* getGLTarget() const;
97
Robert Phillipsfc711a22018-02-13 17:03:00 -050098 // If the backend API is Vulkan, this returns a pointer to a VkFormat. Otherwise
99 // it returns nullptr
100 const VkFormat* getVkFormat() const;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500101
Greg Daniel7e000222018-12-03 10:08:21 -0500102 const GrVkYcbcrConversionInfo* getVkYcbcrConversionInfo() const;
103
Stephen White985741a2019-07-18 11:43:45 -0400104#ifdef SK_DAWN
105 const dawn::TextureFormat* getDawnFormat() const;
106#endif
107
Timothy Liang4e85e802018-06-28 16:37:18 -0400108#ifdef SK_METAL
109 // If the backend API is Metal, this returns a pointer to a GrMTLPixelFormat. Otherwise
110 // it returns nullptr
111 const GrMTLPixelFormat* getMtlFormat() const;
112#endif
113
Greg Daniele877dce2019-07-11 10:52:43 -0400114 // If the backend API is Mock, this returns a pointer to the colorType.
115 // Otherwise it returns nullptr.
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400116 const GrColorType* getMockColorType() const;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500117
Greg Daniel387ec9a2019-03-07 16:44:54 -0500118 // If possible, copies the GrBackendFormat and forces the texture type to be Texture2D. If the
119 // GrBackendFormat was for Vulkan and it originally had a GrVkYcbcrConversionInfo, we will
120 // remove the conversion and set the format to be VK_FORMAT_R8G8B8A8_UNORM.
Greg Daniel4065d452018-11-16 15:43:41 -0500121 GrBackendFormat makeTexture2D() const;
122
Robert Phillipsfc711a22018-02-13 17:03:00 -0500123 // Returns true if the backend format has been initialized.
124 bool isValid() const { return fValid; }
125
126private:
127 GrBackendFormat(GrGLenum format, GrGLenum target);
128
Greg Daniel7e000222018-12-03 10:08:21 -0500129 GrBackendFormat(const VkFormat vkFormat, const GrVkYcbcrConversionInfo&);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500130
Stephen White985741a2019-07-18 11:43:45 -0400131#ifdef SK_DAWN
132 GrBackendFormat(dawn::TextureFormat format);
133#endif
134
Timothy Liang4e85e802018-06-28 16:37:18 -0400135#ifdef SK_METAL
136 GrBackendFormat(const GrMTLPixelFormat mtlFormat);
137#endif
138
Greg Daniele877dce2019-07-11 10:52:43 -0400139 GrBackendFormat(GrColorType colorType);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500140
Robert Phillipsb2adbef2019-07-02 16:33:05 -0400141 GrBackendApi fBackend = GrBackendApi::kMock;
142 bool fValid = false;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500143
144 union {
Greg Daniel4065d452018-11-16 15:43:41 -0500145 GrGLenum fGLFormat; // the sized, internal format of the GL resource
Greg Daniel7e000222018-12-03 10:08:21 -0500146 struct {
147 VkFormat fFormat;
148 GrVkYcbcrConversionInfo fYcbcrConversionInfo;
Robert Phillips9dbcdcc2019-05-13 10:40:06 -0400149 } fVk;
Stephen White985741a2019-07-18 11:43:45 -0400150#ifdef SK_DAWN
151 dawn::TextureFormat fDawnFormat;
152#endif
153
Timothy Liang4e85e802018-06-28 16:37:18 -0400154#ifdef SK_METAL
155 GrMTLPixelFormat fMtlFormat;
156#endif
Greg Daniele877dce2019-07-11 10:52:43 -0400157 GrColorType fMockColorType;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500158 };
Robert Phillipsb2adbef2019-07-02 16:33:05 -0400159 GrTextureType fTextureType = GrTextureType::kNone;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500160};
161
Brian Salomonec045b42017-07-07 10:34:40 -0400162class SK_API GrBackendTexture {
Greg Daniel94403452017-04-18 15:52:36 -0400163public:
Brian Salomon8fe24272017-07-07 12:56:11 -0400164 // Creates an invalid backend texture.
Greg Daniel9ca30652018-04-06 09:27:20 -0400165 GrBackendTexture() : fIsValid(false) {}
Brian Salomon8fe24272017-07-07 12:56:11 -0400166
Greg Daniele7d8da42017-12-04 11:23:19 -0500167 // The GrGLTextureInfo must have a valid fFormat.
168 GrBackendTexture(int width,
169 int height,
170 GrMipMapped,
171 const GrGLTextureInfo& glInfo);
172
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000173 GrBackendTexture(int width,
174 int height,
175 const GrVkImageInfo& vkInfo);
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000176
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400177 GrBackendTexture(int width,
178 int height,
179 GrProtected isProtected,
180 const GrVkImageInfo& vkInfo);
181
Timothy Liang4e85e802018-06-28 16:37:18 -0400182#ifdef SK_METAL
183 GrBackendTexture(int width,
184 int height,
185 GrMipMapped,
186 const GrMtlTextureInfo& mtlInfo);
187#endif
188
Stephen White985741a2019-07-18 11:43:45 -0400189#ifdef SK_DAWN
190 GrBackendTexture(int width,
191 int height,
192 const GrDawnImageInfo& dawnInfo);
193#endif
194
Brian Salomon8fe24272017-07-07 12:56:11 -0400195 GrBackendTexture(int width,
196 int height,
Greg Daniel177e6952017-10-12 12:27:11 -0400197 GrMipMapped,
198 const GrMockTextureInfo& mockInfo);
199
Greg Daniel52e16d92018-04-10 09:34:07 -0400200 GrBackendTexture(const GrBackendTexture& that);
201
202 ~GrBackendTexture();
203
204 GrBackendTexture& operator=(const GrBackendTexture& that);
205
Greg Daniel94403452017-04-18 15:52:36 -0400206 int width() const { return fWidth; }
207 int height() const { return fHeight; }
Greg Daniel177e6952017-10-12 12:27:11 -0400208 bool hasMipMaps() const { return GrMipMapped::kYes == fMipMapped; }
Greg Danielbdf12ad2018-10-12 09:31:11 -0400209 GrBackendApi backend() const {return fBackend; }
Greg Daniel94403452017-04-18 15:52:36 -0400210
Greg Daniel52e16d92018-04-10 09:34:07 -0400211 // If the backend API is GL, copies a snapshot of the GrGLTextureInfo struct into the passed in
212 // pointer and returns true. Otherwise returns false if the backend API is not GL.
213 bool getGLTextureInfo(GrGLTextureInfo*) const;
Greg Danielc0f8e422017-06-13 13:47:53 -0400214
Brian Salomone2826ab2019-06-04 15:58:31 -0400215 // Call this to indicate that the texture parameters have been modified in the GL context
216 // externally to GrContext.
217 void glTextureParametersModified();
218
Stephen White985741a2019-07-18 11:43:45 -0400219#ifdef SK_DAWN
220 // If the backend API is Dawn, copies a snapshot of the GrDawnImageInfo struct into the passed
221 // in pointer and returns true. Otherwise returns false if the backend API is not Dawn.
222 bool getDawnImageInfo(GrDawnImageInfo*) const;
223#endif
224
Greg Daniel323fbcf2018-04-10 13:46:30 -0400225 // If the backend API is Vulkan, copies a snapshot of the GrVkImageInfo struct into the passed
Greg Daniel52e16d92018-04-10 09:34:07 -0400226 // in pointer and returns true. This snapshot will set the fImageLayout to the current layout
227 // state. Otherwise returns false if the backend API is not Vulkan.
228 bool getVkImageInfo(GrVkImageInfo*) const;
229
Greg Daniel323fbcf2018-04-10 13:46:30 -0400230 // Anytime the client changes the VkImageLayout of the VkImage captured by this
231 // GrBackendTexture, they must call this function to notify Skia of the changed layout.
Greg Daniel52e16d92018-04-10 09:34:07 -0400232 void setVkImageLayout(VkImageLayout);
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000233
Timothy Liang4e85e802018-06-28 16:37:18 -0400234#ifdef SK_METAL
235 // If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed
236 // in pointer and returns true. Otherwise returns false if the backend API is not Metal.
237 bool getMtlTextureInfo(GrMtlTextureInfo*) const;
238#endif
239
Brian Salomonf391d0f2018-12-14 09:18:50 -0500240 // Get the GrBackendFormat for this texture (or an invalid format if this is not valid).
241 GrBackendFormat getBackendFormat() const;
242
Greg Daniel52e16d92018-04-10 09:34:07 -0400243 // If the backend API is Mock, copies a snapshot of the GrMockTextureInfo struct into the passed
244 // in pointer and returns true. Otherwise returns false if the backend API is not Mock.
245 bool getMockTextureInfo(GrMockTextureInfo*) const;
Brian Salomon8fe24272017-07-07 12:56:11 -0400246
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400247 // Returns true if we are working with protected content.
248 bool isProtected() const { return fIsProtected == GrProtected::kYes; }
249
Eric Karl914a36b2017-10-12 12:44:50 -0700250 // Returns true if the backend texture has been initialized.
Greg Daniel9ca30652018-04-06 09:27:20 -0400251 bool isValid() const { return fIsValid; }
Brian Salomon8fe24272017-07-07 12:56:11 -0400252
Brian Salomonaad83152019-05-24 10:16:35 -0400253 // Returns true if both textures are valid and refer to the same API texture.
254 bool isSameTexture(const GrBackendTexture&);
255
Robert Phillipsc5509952018-04-04 15:54:55 -0400256#if GR_TEST_UTILS
Robert Phillipsdd399802019-07-18 12:28:00 +0000257 // We can remove the pixelConfig getter and setter once we remove the GrPixelConfig from the
258 // GrBackendTexture and plumb the GrPixelconfig manually throughout our code (or remove all use
Greg Daniel108bb232018-07-03 16:18:29 -0400259 // of GrPixelConfig in general).
Robert Phillipsdd399802019-07-18 12:28:00 +0000260 GrPixelConfig pixelConfig() const { return fConfig; }
Greg Daniel108bb232018-07-03 16:18:29 -0400261 void setPixelConfig(GrPixelConfig config) { fConfig = config; }
262
Robert Phillipsc5509952018-04-04 15:54:55 -0400263 static bool TestingOnly_Equals(const GrBackendTexture& , const GrBackendTexture&);
264#endif
Greg Daniel2a303902018-02-20 10:25:54 -0500265
Eric Karl914a36b2017-10-12 12:44:50 -0700266private:
Greg Daniel5254ccc2017-11-13 11:05:52 -0500267 // Friending for access to the GrPixelConfig
Greg Danielfaa095e2017-12-19 13:15:02 -0500268 friend class SkImage;
Brian Salomon6a426c12018-03-15 12:16:02 -0400269 friend class SkImage_Gpu;
Jim Van Verth8bbce0e2018-10-08 14:34:52 -0400270 friend class SkImage_GpuBase;
Jim Van Verthf49262d2018-10-02 12:07:20 -0400271 friend class SkImage_GpuYUVA;
Jim Van Verth8bbce0e2018-10-08 14:34:52 -0400272 friend class SkPromiseImageHelper;
Greg Daniel5254ccc2017-11-13 11:05:52 -0500273 friend class SkSurface;
Brian Salomonaad83152019-05-24 10:16:35 -0400274 friend class SkSurface_Gpu;
Greg Daniel108bb232018-07-03 16:18:29 -0400275 friend class GrAHardwareBufferImageGenerator;
Greg Daniele728f672018-01-17 10:52:04 -0500276 friend class GrBackendTextureImageGenerator;
Greg Danielf2336e42018-01-23 16:38:14 -0500277 friend class GrProxyProvider;
Greg Daniel5254ccc2017-11-13 11:05:52 -0500278 friend class GrGpu;
279 friend class GrGLGpu;
Stephen White985741a2019-07-18 11:43:45 -0400280 friend class GrDawnGpu;
Greg Daniel5254ccc2017-11-13 11:05:52 -0500281 friend class GrVkGpu;
Timothy Liang4e85e802018-06-28 16:37:18 -0400282 friend class GrMtlGpu;
Greg Daniel057627f2018-03-14 15:51:58 -0400283 friend class PromiseImageHelper;
Robert Phillipsc5509952018-04-04 15:54:55 -0400284
Greg Daniel5254ccc2017-11-13 11:05:52 -0500285 GrPixelConfig config() const { return fConfig; }
286
Brian Salomone2826ab2019-06-04 15:58:31 -0400287#ifdef SK_GL
288 friend class GrGLTexture;
289 GrBackendTexture(int width,
290 int height,
291 GrMipMapped,
292 const GrGLTextureInfo,
293 sk_sp<GrGLTextureParameters>);
294 sk_sp<GrGLTextureParameters> getGLTextureParams() const;
295#endif
Greg Daniel52e16d92018-04-10 09:34:07 -0400296
Greg Danielb4d89562018-10-03 18:44:49 +0000297#ifdef SK_VULKAN
Brian Salomone2826ab2019-06-04 15:58:31 -0400298 friend class GrVkTexture;
299 GrBackendTexture(int width,
300 int height,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400301 GrProtected isProtected,
Brian Salomone2826ab2019-06-04 15:58:31 -0400302 const GrVkImageInfo& vkInfo,
303 sk_sp<GrVkImageLayout> layout);
304 sk_sp<GrVkImageLayout> getGrVkImageLayout() const;
Greg Daniel52e16d92018-04-10 09:34:07 -0400305#endif
306
307 // Free and release and resources being held by the GrBackendTexture.
308 void cleanup();
309
Greg Daniel9ca30652018-04-06 09:27:20 -0400310 bool fIsValid;
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400311 GrProtected fIsProtected = GrProtected::kNo;
Greg Daniel94403452017-04-18 15:52:36 -0400312 int fWidth; //<! width in pixels
313 int fHeight; //<! height in pixels
314 GrPixelConfig fConfig;
Greg Daniel177e6952017-10-12 12:27:11 -0400315 GrMipMapped fMipMapped;
Greg Danielbdf12ad2018-10-12 09:31:11 -0400316 GrBackendApi fBackend;
Greg Daniel94403452017-04-18 15:52:36 -0400317
318 union {
Brian Salomone2826ab2019-06-04 15:58:31 -0400319#ifdef SK_GL
320 GrGLBackendTextureInfo fGLInfo;
321#endif
Greg Daniel52e16d92018-04-10 09:34:07 -0400322 GrVkBackendSurfaceInfo fVkInfo;
Brian Salomon8fe24272017-07-07 12:56:11 -0400323 GrMockTextureInfo fMockInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400324 };
Jim Van Verthdac1e552019-05-31 09:10:55 -0400325#ifdef SK_METAL
326 GrMtlTextureInfo fMtlInfo;
327#endif
Stephen White985741a2019-07-18 11:43:45 -0400328#ifdef SK_DAWN
329 GrDawnImageInfo fDawnInfo;
330#endif
Greg Daniel94403452017-04-18 15:52:36 -0400331};
332
Brian Salomonec045b42017-07-07 10:34:40 -0400333class SK_API GrBackendRenderTarget {
Greg Daniel94403452017-04-18 15:52:36 -0400334public:
Robert Phillips57e08282017-11-16 14:59:48 -0500335 // Creates an invalid backend texture.
Greg Daniel9ca30652018-04-06 09:27:20 -0400336 GrBackendRenderTarget() : fIsValid(false) {}
Robert Phillips57e08282017-11-16 14:59:48 -0500337
Greg Danielfaa095e2017-12-19 13:15:02 -0500338 // The GrGLTextureInfo must have a valid fFormat.
339 GrBackendRenderTarget(int width,
340 int height,
341 int sampleCnt,
342 int stencilBits,
343 const GrGLFramebufferInfo& glInfo);
344
Stephen White985741a2019-07-18 11:43:45 -0400345#ifdef SK_DAWN
346 GrBackendRenderTarget(int width,
347 int height,
348 int sampleCnt,
349 int stencilBits,
350 const GrDawnImageInfo& dawnInfo);
351#endif
352
Brian Salomonafdc6b12018-03-09 12:02:32 -0500353 /** Deprecated, use version that does not take stencil bits. */
Greg Daniel94403452017-04-18 15:52:36 -0400354 GrBackendRenderTarget(int width,
355 int height,
356 int sampleCnt,
357 int stencilBits,
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000358 const GrVkImageInfo& vkInfo);
Brian Salomonafdc6b12018-03-09 12:02:32 -0500359 GrBackendRenderTarget(int width, int height, int sampleCnt, const GrVkImageInfo& vkInfo);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400360 GrBackendRenderTarget(int width,
361 int height,
362 int sampleCnt,
363 GrProtected isProtected,
364 const GrVkImageInfo& vkInfo);
Greg Daniel94403452017-04-18 15:52:36 -0400365
Timothy Liang4e85e802018-06-28 16:37:18 -0400366#ifdef SK_METAL
367 GrBackendRenderTarget(int width,
368 int height,
369 int sampleCnt,
370 const GrMtlTextureInfo& mtlInfo);
371#endif
372
Brian Salomon0c51eea2018-03-09 17:02:09 -0500373 GrBackendRenderTarget(int width,
374 int height,
375 int sampleCnt,
376 int stencilBits,
377 const GrMockRenderTargetInfo& mockInfo);
378
Greg Daniel323fbcf2018-04-10 13:46:30 -0400379 ~GrBackendRenderTarget();
380
381 GrBackendRenderTarget(const GrBackendRenderTarget& that);
382 GrBackendRenderTarget& operator=(const GrBackendRenderTarget&);
383
Greg Daniel94403452017-04-18 15:52:36 -0400384 int width() const { return fWidth; }
385 int height() const { return fHeight; }
386 int sampleCnt() const { return fSampleCnt; }
387 int stencilBits() const { return fStencilBits; }
Greg Danielbdf12ad2018-10-12 09:31:11 -0400388 GrBackendApi backend() const {return fBackend; }
Greg Daniel94403452017-04-18 15:52:36 -0400389
Greg Daniel323fbcf2018-04-10 13:46:30 -0400390 // If the backend API is GL, copies a snapshot of the GrGLFramebufferInfo struct into the passed
391 // in pointer and returns true. Otherwise returns false if the backend API is not GL.
392 bool getGLFramebufferInfo(GrGLFramebufferInfo*) const;
Greg Danielc0f8e422017-06-13 13:47:53 -0400393
Stephen White985741a2019-07-18 11:43:45 -0400394#ifdef SK_DAWN
395 // If the backend API is Dawn, copies a snapshot of the GrDawnImageInfo struct into the passed
396 // in pointer and returns true. Otherwise returns false if the backend API is not Dawn.
397 bool getDawnImageInfo(GrDawnImageInfo*) const;
398#endif
399
Greg Daniel323fbcf2018-04-10 13:46:30 -0400400 // If the backend API is Vulkan, copies a snapshot of the GrVkImageInfo struct into the passed
401 // in pointer and returns true. This snapshot will set the fImageLayout to the current layout
402 // state. Otherwise returns false if the backend API is not Vulkan.
403 bool getVkImageInfo(GrVkImageInfo*) const;
404
405 // Anytime the client changes the VkImageLayout of the VkImage captured by this
406 // GrBackendRenderTarget, they must call this function to notify Skia of the changed layout.
407 void setVkImageLayout(VkImageLayout);
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000408
Timothy Liang4e85e802018-06-28 16:37:18 -0400409#ifdef SK_METAL
410 // If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed
411 // in pointer and returns true. Otherwise returns false if the backend API is not Metal.
412 bool getMtlTextureInfo(GrMtlTextureInfo*) const;
413#endif
414
Robert Phillipsf209e882019-06-25 15:59:50 -0400415 // Get the GrBackendFormat for this render target (or an invalid format if this is not valid).
416 GrBackendFormat getBackendFormat() const;
417
Greg Daniel323fbcf2018-04-10 13:46:30 -0400418 // If the backend API is Mock, copies a snapshot of the GrMockTextureInfo struct into the passed
419 // in pointer and returns true. Otherwise returns false if the backend API is not Mock.
420 bool getMockRenderTargetInfo(GrMockRenderTargetInfo*) const;
Brian Salomon0c51eea2018-03-09 17:02:09 -0500421
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400422 // Returns true if we are working with protected content.
423 bool isProtected() const { return fIsProtected == GrProtected::kYes; }
424
Robert Phillips57e08282017-11-16 14:59:48 -0500425 // Returns true if the backend texture has been initialized.
Greg Daniel9ca30652018-04-06 09:27:20 -0400426 bool isValid() const { return fIsValid; }
Robert Phillips57e08282017-11-16 14:59:48 -0500427
Robert Phillips8caf85f2018-04-05 09:30:38 -0400428
429#if GR_TEST_UTILS
Robert Phillipsdd399802019-07-18 12:28:00 +0000430 // We can remove the pixelConfig getter and setter once we remove the pixel config from the
Greg Daniel108bb232018-07-03 16:18:29 -0400431 // GrBackendRenderTarget and plumb the pixel config manually throughout our code (or remove all
432 // use of GrPixelConfig in general).
Robert Phillipsdd399802019-07-18 12:28:00 +0000433 GrPixelConfig pixelConfig() const { return fConfig; }
Greg Daniel108bb232018-07-03 16:18:29 -0400434 void setPixelConfig(GrPixelConfig config) { fConfig = config; }
435
Robert Phillips8caf85f2018-04-05 09:30:38 -0400436 static bool TestingOnly_Equals(const GrBackendRenderTarget&, const GrBackendRenderTarget&);
437#endif
Greg Daniel2a303902018-02-20 10:25:54 -0500438
Greg Daniel94403452017-04-18 15:52:36 -0400439private:
Greg Daniel5254ccc2017-11-13 11:05:52 -0500440 // Friending for access to the GrPixelConfig
441 friend class SkSurface;
Greg Danielfaa095e2017-12-19 13:15:02 -0500442 friend class SkSurface_Gpu;
443 friend class SkImage_Gpu;
Greg Daniel5254ccc2017-11-13 11:05:52 -0500444 friend class GrGpu;
445 friend class GrGLGpu;
Stephen White985741a2019-07-18 11:43:45 -0400446 friend class GrDawnGpu;
Greg Daniel2a303902018-02-20 10:25:54 -0500447 friend class GrProxyProvider;
Greg Daniel5254ccc2017-11-13 11:05:52 -0500448 friend class GrVkGpu;
Timothy Liang4e85e802018-06-28 16:37:18 -0400449 friend class GrMtlGpu;
Greg Daniel5254ccc2017-11-13 11:05:52 -0500450 GrPixelConfig config() const { return fConfig; }
451
Greg Daniel323fbcf2018-04-10 13:46:30 -0400452 // Requires friending of GrVkGpu (done above already)
453 sk_sp<GrVkImageLayout> getGrVkImageLayout() const;
454
455 friend class GrVkRenderTarget;
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400456 GrBackendRenderTarget(int width, int height, int sampleCnt, GrProtected isProtected,
457 const GrVkImageInfo& vkInfo, sk_sp<GrVkImageLayout> layout);
Greg Daniel323fbcf2018-04-10 13:46:30 -0400458
459 // Free and release and resources being held by the GrBackendTexture.
460 void cleanup();
461
Greg Daniel9ca30652018-04-06 09:27:20 -0400462 bool fIsValid;
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400463 GrProtected fIsProtected = GrProtected::kNo;
Greg Daniel94403452017-04-18 15:52:36 -0400464 int fWidth; //<! width in pixels
465 int fHeight; //<! height in pixels
466
467 int fSampleCnt;
468 int fStencilBits;
469 GrPixelConfig fConfig;
Jim Van Verth7730d7c2019-05-28 03:03:45 +0000470
Greg Danielbdf12ad2018-10-12 09:31:11 -0400471 GrBackendApi fBackend;
Greg Daniel94403452017-04-18 15:52:36 -0400472
473 union {
Robert Phillipsf209e882019-06-25 15:59:50 -0400474#ifdef SK_GL
Robert Phillipsfad9e3f2017-06-13 22:16:08 +0000475 GrGLFramebufferInfo fGLInfo;
Robert Phillipsf209e882019-06-25 15:59:50 -0400476#endif
Greg Daniel323fbcf2018-04-10 13:46:30 -0400477 GrVkBackendSurfaceInfo fVkInfo;
Brian Salomon0c51eea2018-03-09 17:02:09 -0500478 GrMockRenderTargetInfo fMockInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400479 };
Jim Van Verthdac1e552019-05-31 09:10:55 -0400480#ifdef SK_METAL
481 GrMtlTextureInfo fMtlInfo;
482#endif
Stephen White985741a2019-07-18 11:43:45 -0400483#ifdef SK_DAWN
484 GrDawnImageInfo fDawnInfo;
485#endif
Greg Daniel94403452017-04-18 15:52:36 -0400486};
487
488#endif
489
Robert Phillips8caf85f2018-04-05 09:30:38 -0400490#endif
491