Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrBackendSurface_DEFINED |
| 9 | #define GrBackendSurface_DEFINED |
| 10 | |
| 11 | #include "GrTypes.h" |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 12 | #include "gl/GrGLTypes.h" |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 13 | #include "mock/GrMockTypes.h" |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 14 | |
| 15 | #ifdef SK_VULKAN |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 16 | #include "vk/GrVkTypes.h" |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 17 | #include "../private/GrVkTypesPriv.h" |
| 18 | |
| 19 | class GrVkImageLayout; |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 20 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 21 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 22 | #ifdef SK_METAL |
| 23 | #include "mtl/GrMtlTypes.h" |
| 24 | #endif |
| 25 | |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 26 | #if !SK_SUPPORT_GPU |
| 27 | |
| 28 | // SkSurface and SkImage rely on a minimal version of these always being available |
| 29 | class SK_API GrBackendTexture { |
| 30 | public: |
| 31 | GrBackendTexture() {} |
| 32 | |
| 33 | bool isValid() const { return false; } |
| 34 | }; |
| 35 | |
| 36 | class SK_API GrBackendRenderTarget { |
| 37 | public: |
| 38 | GrBackendRenderTarget() {} |
| 39 | |
| 40 | bool isValid() const { return false; } |
| 41 | }; |
| 42 | #else |
| 43 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 44 | class SK_API GrBackendFormat { |
| 45 | public: |
| 46 | // Creates an invalid backend format. |
| 47 | GrBackendFormat() : fValid(false) {} |
| 48 | |
| 49 | static GrBackendFormat MakeGL(GrGLenum format, GrGLenum target) { |
| 50 | return GrBackendFormat(format, target); |
| 51 | } |
| 52 | |
| 53 | #ifdef SK_VULKAN |
Greg Daniel | a8d9211 | 2018-03-09 12:05:04 -0500 | [diff] [blame] | 54 | static GrBackendFormat MakeVk(VkFormat format) { |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 55 | return GrBackendFormat(format); |
| 56 | } |
| 57 | #endif |
| 58 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 59 | #ifdef SK_METAL |
| 60 | static GrBackendFormat MakeMtl(GrMTLPixelFormat format) { |
| 61 | return GrBackendFormat(format); |
| 62 | } |
| 63 | #endif |
| 64 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 65 | static GrBackendFormat MakeMock(GrPixelConfig config) { |
| 66 | return GrBackendFormat(config); |
| 67 | } |
| 68 | |
| 69 | GrBackend backend() const {return fBackend; } |
| 70 | |
| 71 | // If the backend API is GL, these return a pointer to the format and target. Otherwise |
| 72 | // it returns nullptr. |
| 73 | const GrGLenum* getGLFormat() const; |
| 74 | const GrGLenum* getGLTarget() const; |
| 75 | |
| 76 | #ifdef SK_VULKAN |
| 77 | // If the backend API is Vulkan, this returns a pointer to a VkFormat. Otherwise |
| 78 | // it returns nullptr |
| 79 | const VkFormat* getVkFormat() const; |
| 80 | #endif |
| 81 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 82 | #ifdef SK_METAL |
| 83 | // If the backend API is Metal, this returns a pointer to a GrMTLPixelFormat. Otherwise |
| 84 | // it returns nullptr |
| 85 | const GrMTLPixelFormat* getMtlFormat() const; |
| 86 | #endif |
| 87 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 88 | // If the backend API is Mock, this returns a pointer to a GrPixelConfig. Otherwise |
| 89 | // it returns nullptr. |
| 90 | const GrPixelConfig* getMockFormat() const; |
| 91 | |
| 92 | // Returns true if the backend format has been initialized. |
| 93 | bool isValid() const { return fValid; } |
| 94 | |
| 95 | private: |
| 96 | GrBackendFormat(GrGLenum format, GrGLenum target); |
| 97 | |
| 98 | #ifdef SK_VULKAN |
| 99 | GrBackendFormat(const VkFormat vkFormat); |
| 100 | #endif |
| 101 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 102 | #ifdef SK_METAL |
| 103 | GrBackendFormat(const GrMTLPixelFormat mtlFormat); |
| 104 | #endif |
| 105 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 106 | GrBackendFormat(const GrPixelConfig config); |
| 107 | |
| 108 | GrBackend fBackend; |
| 109 | bool fValid; |
| 110 | |
| 111 | union { |
| 112 | struct { |
| 113 | GrGLenum fTarget; // GL_TEXTURE_2D, GL_TEXTURE_EXTERNAL or GL_TEXTURE_RECTANGLE |
| 114 | GrGLenum fFormat; // the sized, internal format of the GL resource |
| 115 | } fGL; |
| 116 | #ifdef SK_VULKAN |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 117 | VkFormat fVkFormat; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 118 | #endif |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 119 | #ifdef SK_METAL |
| 120 | GrMTLPixelFormat fMtlFormat; |
| 121 | #endif |
| 122 | GrPixelConfig fMockFormat; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 123 | }; |
| 124 | }; |
| 125 | |
Brian Salomon | ec045b4 | 2017-07-07 10:34:40 -0400 | [diff] [blame] | 126 | class SK_API GrBackendTexture { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 127 | public: |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 128 | // Creates an invalid backend texture. |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 129 | GrBackendTexture() : fIsValid(false) {} |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 130 | |
Ethan Nicholas | 34aa059 | 2018-07-03 16:38:32 +0000 | [diff] [blame^] | 131 | #if GR_TEST_UTILS |
| 132 | // GrGLTextureInfo::fFormat is ignored |
| 133 | // Deprecated: Should use version that does not take a GrPixelConfig instead |
| 134 | GrBackendTexture(int width, |
| 135 | int height, |
| 136 | GrPixelConfig config, |
| 137 | const GrGLTextureInfo& glInfo); |
| 138 | |
| 139 | // GrGLTextureInfo::fFormat is ignored |
| 140 | // Deprecated: Should use version that does not take a GrPixelConfig instead |
| 141 | GrBackendTexture(int width, |
| 142 | int height, |
| 143 | GrPixelConfig config, |
| 144 | GrMipMapped, |
| 145 | const GrGLTextureInfo& glInfo); |
| 146 | #endif |
| 147 | |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 148 | // The GrGLTextureInfo must have a valid fFormat. |
| 149 | GrBackendTexture(int width, |
| 150 | int height, |
| 151 | GrMipMapped, |
| 152 | const GrGLTextureInfo& glInfo); |
| 153 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 154 | #ifdef SK_VULKAN |
| 155 | GrBackendTexture(int width, |
| 156 | int height, |
| 157 | const GrVkImageInfo& vkInfo); |
| 158 | #endif |
| 159 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 160 | #ifdef SK_METAL |
| 161 | GrBackendTexture(int width, |
| 162 | int height, |
| 163 | GrMipMapped, |
| 164 | const GrMtlTextureInfo& mtlInfo); |
| 165 | #endif |
| 166 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 167 | GrBackendTexture(int width, |
| 168 | int height, |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 169 | GrMipMapped, |
| 170 | const GrMockTextureInfo& mockInfo); |
| 171 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 172 | GrBackendTexture(const GrBackendTexture& that); |
| 173 | |
| 174 | ~GrBackendTexture(); |
| 175 | |
| 176 | GrBackendTexture& operator=(const GrBackendTexture& that); |
| 177 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 178 | int width() const { return fWidth; } |
| 179 | int height() const { return fHeight; } |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 180 | bool hasMipMaps() const { return GrMipMapped::kYes == fMipMapped; } |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 181 | GrBackend backend() const {return fBackend; } |
| 182 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 183 | // If the backend API is GL, copies a snapshot of the GrGLTextureInfo struct into the passed in |
| 184 | // pointer and returns true. Otherwise returns false if the backend API is not GL. |
| 185 | bool getGLTextureInfo(GrGLTextureInfo*) const; |
Greg Daniel | c0f8e42 | 2017-06-13 13:47:53 -0400 | [diff] [blame] | 186 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 187 | #ifdef SK_VULKAN |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 188 | // If the backend API is Vulkan, copies a snapshot of the GrVkImageInfo struct into the passed |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 189 | // in pointer and returns true. This snapshot will set the fImageLayout to the current layout |
| 190 | // state. Otherwise returns false if the backend API is not Vulkan. |
| 191 | bool getVkImageInfo(GrVkImageInfo*) const; |
| 192 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 193 | // Anytime the client changes the VkImageLayout of the VkImage captured by this |
| 194 | // GrBackendTexture, they must call this function to notify Skia of the changed layout. |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 195 | void setVkImageLayout(VkImageLayout); |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 196 | #endif |
| 197 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 198 | #ifdef SK_METAL |
| 199 | // If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed |
| 200 | // in pointer and returns true. Otherwise returns false if the backend API is not Metal. |
| 201 | bool getMtlTextureInfo(GrMtlTextureInfo*) const; |
| 202 | #endif |
| 203 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 204 | // If the backend API is Mock, copies a snapshot of the GrMockTextureInfo struct into the passed |
| 205 | // in pointer and returns true. Otherwise returns false if the backend API is not Mock. |
| 206 | bool getMockTextureInfo(GrMockTextureInfo*) const; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 207 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 208 | // Returns true if the backend texture has been initialized. |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 209 | bool isValid() const { return fIsValid; } |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 210 | |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 211 | #if GR_TEST_UTILS |
Ethan Nicholas | 34aa059 | 2018-07-03 16:38:32 +0000 | [diff] [blame^] | 212 | GrPixelConfig testingOnly_getPixelConfig() const; |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 213 | static bool TestingOnly_Equals(const GrBackendTexture& , const GrBackendTexture&); |
| 214 | #endif |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 215 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 216 | private: |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 217 | // Friending for access to the GrPixelConfig |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 218 | friend class SkImage; |
Brian Salomon | 6a426c1 | 2018-03-15 12:16:02 -0400 | [diff] [blame] | 219 | friend class SkImage_Gpu; |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 220 | friend class SkSurface; |
Greg Daniel | e728f67 | 2018-01-17 10:52:04 -0500 | [diff] [blame] | 221 | friend class GrBackendTextureImageGenerator; |
Greg Daniel | f2336e4 | 2018-01-23 16:38:14 -0500 | [diff] [blame] | 222 | friend class GrProxyProvider; |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 223 | friend class GrGpu; |
| 224 | friend class GrGLGpu; |
| 225 | friend class GrVkGpu; |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 226 | friend class GrMtlGpu; |
Greg Daniel | 057627f | 2018-03-14 15:51:58 -0400 | [diff] [blame] | 227 | friend class PromiseImageHelper; |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 228 | |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 229 | GrPixelConfig config() const { return fConfig; } |
| 230 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 231 | #ifdef SK_VULKAN |
| 232 | // Requires friending of GrVkGpu (done above already) |
| 233 | sk_sp<GrVkImageLayout> getGrVkImageLayout() const; |
| 234 | |
| 235 | friend class GrVkTexture; |
| 236 | GrBackendTexture(int width, |
| 237 | int height, |
| 238 | const GrVkImageInfo& vkInfo, |
| 239 | sk_sp<GrVkImageLayout> layout); |
| 240 | #endif |
| 241 | |
| 242 | // Free and release and resources being held by the GrBackendTexture. |
| 243 | void cleanup(); |
| 244 | |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 245 | bool fIsValid; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 246 | int fWidth; //<! width in pixels |
| 247 | int fHeight; //<! height in pixels |
| 248 | GrPixelConfig fConfig; |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 249 | GrMipMapped fMipMapped; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 250 | GrBackend fBackend; |
| 251 | |
| 252 | union { |
Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 253 | GrGLTextureInfo fGLInfo; |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 254 | #ifdef SK_VULKAN |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 255 | GrVkBackendSurfaceInfo fVkInfo; |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 256 | #endif |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 257 | #ifdef SK_METAL |
| 258 | GrMtlTextureInfo fMtlInfo; |
| 259 | #endif |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 260 | GrMockTextureInfo fMockInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 261 | }; |
| 262 | }; |
| 263 | |
Brian Salomon | ec045b4 | 2017-07-07 10:34:40 -0400 | [diff] [blame] | 264 | class SK_API GrBackendRenderTarget { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 265 | public: |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 266 | // Creates an invalid backend texture. |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 267 | GrBackendRenderTarget() : fIsValid(false) {} |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 268 | |
Ethan Nicholas | 34aa059 | 2018-07-03 16:38:32 +0000 | [diff] [blame^] | 269 | #if GR_TEST_UTILS |
| 270 | // GrGLTextureInfo::fFormat is ignored |
| 271 | // Deprecated: Should use version that does not take a GrPixelConfig instead |
| 272 | GrBackendRenderTarget(int width, |
| 273 | int height, |
| 274 | int sampleCnt, |
| 275 | int stencilBits, |
| 276 | GrPixelConfig config, |
| 277 | const GrGLFramebufferInfo& glInfo); |
| 278 | #endif |
| 279 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 280 | // The GrGLTextureInfo must have a valid fFormat. |
| 281 | GrBackendRenderTarget(int width, |
| 282 | int height, |
| 283 | int sampleCnt, |
| 284 | int stencilBits, |
| 285 | const GrGLFramebufferInfo& glInfo); |
| 286 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 287 | #ifdef SK_VULKAN |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 288 | /** Deprecated, use version that does not take stencil bits. */ |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 289 | GrBackendRenderTarget(int width, |
| 290 | int height, |
| 291 | int sampleCnt, |
| 292 | int stencilBits, |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 293 | const GrVkImageInfo& vkInfo); |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 294 | GrBackendRenderTarget(int width, int height, int sampleCnt, const GrVkImageInfo& vkInfo); |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 295 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 296 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 297 | #ifdef SK_METAL |
| 298 | GrBackendRenderTarget(int width, |
| 299 | int height, |
| 300 | int sampleCnt, |
| 301 | const GrMtlTextureInfo& mtlInfo); |
| 302 | #endif |
| 303 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 304 | GrBackendRenderTarget(int width, |
| 305 | int height, |
| 306 | int sampleCnt, |
| 307 | int stencilBits, |
| 308 | const GrMockRenderTargetInfo& mockInfo); |
| 309 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 310 | ~GrBackendRenderTarget(); |
| 311 | |
| 312 | GrBackendRenderTarget(const GrBackendRenderTarget& that); |
| 313 | GrBackendRenderTarget& operator=(const GrBackendRenderTarget&); |
| 314 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 315 | int width() const { return fWidth; } |
| 316 | int height() const { return fHeight; } |
| 317 | int sampleCnt() const { return fSampleCnt; } |
| 318 | int stencilBits() const { return fStencilBits; } |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 319 | GrBackend backend() const {return fBackend; } |
| 320 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 321 | // If the backend API is GL, copies a snapshot of the GrGLFramebufferInfo struct into the passed |
| 322 | // in pointer and returns true. Otherwise returns false if the backend API is not GL. |
| 323 | bool getGLFramebufferInfo(GrGLFramebufferInfo*) const; |
Greg Daniel | c0f8e42 | 2017-06-13 13:47:53 -0400 | [diff] [blame] | 324 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 325 | #ifdef SK_VULKAN |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 326 | // If the backend API is Vulkan, copies a snapshot of the GrVkImageInfo struct into the passed |
| 327 | // in pointer and returns true. This snapshot will set the fImageLayout to the current layout |
| 328 | // state. Otherwise returns false if the backend API is not Vulkan. |
| 329 | bool getVkImageInfo(GrVkImageInfo*) const; |
| 330 | |
| 331 | // Anytime the client changes the VkImageLayout of the VkImage captured by this |
| 332 | // GrBackendRenderTarget, they must call this function to notify Skia of the changed layout. |
| 333 | void setVkImageLayout(VkImageLayout); |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 334 | #endif |
| 335 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 336 | #ifdef SK_METAL |
| 337 | // If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed |
| 338 | // in pointer and returns true. Otherwise returns false if the backend API is not Metal. |
| 339 | bool getMtlTextureInfo(GrMtlTextureInfo*) const; |
| 340 | #endif |
| 341 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 342 | // If the backend API is Mock, copies a snapshot of the GrMockTextureInfo struct into the passed |
| 343 | // in pointer and returns true. Otherwise returns false if the backend API is not Mock. |
| 344 | bool getMockRenderTargetInfo(GrMockRenderTargetInfo*) const; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 345 | |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 346 | // Returns true if the backend texture has been initialized. |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 347 | bool isValid() const { return fIsValid; } |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 348 | |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 349 | |
| 350 | #if GR_TEST_UTILS |
Ethan Nicholas | 34aa059 | 2018-07-03 16:38:32 +0000 | [diff] [blame^] | 351 | GrPixelConfig testingOnly_getPixelConfig() const; |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 352 | static bool TestingOnly_Equals(const GrBackendRenderTarget&, const GrBackendRenderTarget&); |
| 353 | #endif |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 354 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 355 | private: |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 356 | // Friending for access to the GrPixelConfig |
| 357 | friend class SkSurface; |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 358 | friend class SkSurface_Gpu; |
| 359 | friend class SkImage_Gpu; |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 360 | friend class GrGpu; |
| 361 | friend class GrGLGpu; |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 362 | friend class GrProxyProvider; |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 363 | friend class GrVkGpu; |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 364 | friend class GrMtlGpu; |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 365 | GrPixelConfig config() const { return fConfig; } |
| 366 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 367 | #ifdef SK_VULKAN |
| 368 | // Requires friending of GrVkGpu (done above already) |
| 369 | sk_sp<GrVkImageLayout> getGrVkImageLayout() const; |
| 370 | |
| 371 | friend class GrVkRenderTarget; |
| 372 | GrBackendRenderTarget(int width, int height, int sampleCnt, const GrVkImageInfo& vkInfo, |
| 373 | sk_sp<GrVkImageLayout> layout); |
| 374 | #endif |
| 375 | |
| 376 | // Free and release and resources being held by the GrBackendTexture. |
| 377 | void cleanup(); |
| 378 | |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 379 | bool fIsValid; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 380 | int fWidth; //<! width in pixels |
| 381 | int fHeight; //<! height in pixels |
| 382 | |
| 383 | int fSampleCnt; |
| 384 | int fStencilBits; |
| 385 | GrPixelConfig fConfig; |
| 386 | |
| 387 | GrBackend fBackend; |
| 388 | |
| 389 | union { |
Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 390 | GrGLFramebufferInfo fGLInfo; |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 391 | #ifdef SK_VULKAN |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 392 | GrVkBackendSurfaceInfo fVkInfo; |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 393 | #endif |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 394 | #ifdef SK_METAL |
| 395 | GrMtlTextureInfo fMtlInfo; |
| 396 | #endif |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 397 | GrMockRenderTargetInfo fMockInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 398 | }; |
| 399 | }; |
| 400 | |
| 401 | #endif |
| 402 | |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 403 | #endif |
| 404 | |