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 | |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 131 | // The GrGLTextureInfo must have a valid fFormat. |
| 132 | GrBackendTexture(int width, |
| 133 | int height, |
| 134 | GrMipMapped, |
| 135 | const GrGLTextureInfo& glInfo); |
| 136 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 137 | #ifdef SK_VULKAN |
| 138 | GrBackendTexture(int width, |
| 139 | int height, |
| 140 | const GrVkImageInfo& vkInfo); |
| 141 | #endif |
| 142 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 143 | #ifdef SK_METAL |
| 144 | GrBackendTexture(int width, |
| 145 | int height, |
| 146 | GrMipMapped, |
| 147 | const GrMtlTextureInfo& mtlInfo); |
| 148 | #endif |
| 149 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 150 | GrBackendTexture(int width, |
| 151 | int height, |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 152 | GrMipMapped, |
| 153 | const GrMockTextureInfo& mockInfo); |
| 154 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 155 | GrBackendTexture(const GrBackendTexture& that); |
| 156 | |
| 157 | ~GrBackendTexture(); |
| 158 | |
| 159 | GrBackendTexture& operator=(const GrBackendTexture& that); |
| 160 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 161 | int width() const { return fWidth; } |
| 162 | int height() const { return fHeight; } |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 163 | bool hasMipMaps() const { return GrMipMapped::kYes == fMipMapped; } |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 164 | GrBackend backend() const {return fBackend; } |
| 165 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 166 | // If the backend API is GL, copies a snapshot of the GrGLTextureInfo struct into the passed in |
| 167 | // pointer and returns true. Otherwise returns false if the backend API is not GL. |
| 168 | bool getGLTextureInfo(GrGLTextureInfo*) const; |
Greg Daniel | c0f8e42 | 2017-06-13 13:47:53 -0400 | [diff] [blame] | 169 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 170 | #ifdef SK_VULKAN |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 171 | // 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] | 172 | // in pointer and returns true. This snapshot will set the fImageLayout to the current layout |
| 173 | // state. Otherwise returns false if the backend API is not Vulkan. |
| 174 | bool getVkImageInfo(GrVkImageInfo*) const; |
| 175 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 176 | // Anytime the client changes the VkImageLayout of the VkImage captured by this |
| 177 | // 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] | 178 | void setVkImageLayout(VkImageLayout); |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 179 | #endif |
| 180 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 181 | #ifdef SK_METAL |
| 182 | // If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed |
| 183 | // in pointer and returns true. Otherwise returns false if the backend API is not Metal. |
| 184 | bool getMtlTextureInfo(GrMtlTextureInfo*) const; |
| 185 | #endif |
| 186 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 187 | // If the backend API is Mock, copies a snapshot of the GrMockTextureInfo struct into the passed |
| 188 | // in pointer and returns true. Otherwise returns false if the backend API is not Mock. |
| 189 | bool getMockTextureInfo(GrMockTextureInfo*) const; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 190 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 191 | // Returns true if the backend texture has been initialized. |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 192 | bool isValid() const { return fIsValid; } |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 193 | |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 194 | #if GR_TEST_UTILS |
Greg Daniel | ff2181e | 2018-07-02 16:47:38 -0400 | [diff] [blame^] | 195 | // We can remove the pixelConfig getter and setter once we remove the GrPixelConfig from the |
| 196 | // GrBackendTexture and plumb the GrPixelconfig manually throughout our code (or remove all use |
| 197 | // of GrPixelConfig in general). |
| 198 | GrPixelConfig pixelConfig() const { return fConfig; } |
| 199 | void setPixelConfig(GrPixelConfig config) { fConfig = config; } |
| 200 | |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 201 | static bool TestingOnly_Equals(const GrBackendTexture& , const GrBackendTexture&); |
| 202 | #endif |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 203 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 204 | private: |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 205 | // Friending for access to the GrPixelConfig |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 206 | friend class SkImage; |
Brian Salomon | 6a426c1 | 2018-03-15 12:16:02 -0400 | [diff] [blame] | 207 | friend class SkImage_Gpu; |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 208 | friend class SkSurface; |
Greg Daniel | ff2181e | 2018-07-02 16:47:38 -0400 | [diff] [blame^] | 209 | friend class GrAHardwareBufferImageGenerator; |
Greg Daniel | e728f67 | 2018-01-17 10:52:04 -0500 | [diff] [blame] | 210 | friend class GrBackendTextureImageGenerator; |
Greg Daniel | f2336e4 | 2018-01-23 16:38:14 -0500 | [diff] [blame] | 211 | friend class GrProxyProvider; |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 212 | friend class GrGpu; |
| 213 | friend class GrGLGpu; |
| 214 | friend class GrVkGpu; |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 215 | friend class GrMtlGpu; |
Greg Daniel | 057627f | 2018-03-14 15:51:58 -0400 | [diff] [blame] | 216 | friend class PromiseImageHelper; |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 217 | |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 218 | GrPixelConfig config() const { return fConfig; } |
| 219 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 220 | #ifdef SK_VULKAN |
| 221 | // Requires friending of GrVkGpu (done above already) |
| 222 | sk_sp<GrVkImageLayout> getGrVkImageLayout() const; |
| 223 | |
| 224 | friend class GrVkTexture; |
| 225 | GrBackendTexture(int width, |
| 226 | int height, |
| 227 | const GrVkImageInfo& vkInfo, |
| 228 | sk_sp<GrVkImageLayout> layout); |
| 229 | #endif |
| 230 | |
| 231 | // Free and release and resources being held by the GrBackendTexture. |
| 232 | void cleanup(); |
| 233 | |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 234 | bool fIsValid; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 235 | int fWidth; //<! width in pixels |
| 236 | int fHeight; //<! height in pixels |
| 237 | GrPixelConfig fConfig; |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 238 | GrMipMapped fMipMapped; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 239 | GrBackend fBackend; |
| 240 | |
| 241 | union { |
Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 242 | GrGLTextureInfo fGLInfo; |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 243 | #ifdef SK_VULKAN |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 244 | GrVkBackendSurfaceInfo fVkInfo; |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 245 | #endif |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 246 | #ifdef SK_METAL |
| 247 | GrMtlTextureInfo fMtlInfo; |
| 248 | #endif |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 249 | GrMockTextureInfo fMockInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 250 | }; |
| 251 | }; |
| 252 | |
Brian Salomon | ec045b4 | 2017-07-07 10:34:40 -0400 | [diff] [blame] | 253 | class SK_API GrBackendRenderTarget { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 254 | public: |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 255 | // Creates an invalid backend texture. |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 256 | GrBackendRenderTarget() : fIsValid(false) {} |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 257 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 258 | // The GrGLTextureInfo must have a valid fFormat. |
| 259 | GrBackendRenderTarget(int width, |
| 260 | int height, |
| 261 | int sampleCnt, |
| 262 | int stencilBits, |
| 263 | const GrGLFramebufferInfo& glInfo); |
| 264 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 265 | #ifdef SK_VULKAN |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 266 | /** Deprecated, use version that does not take stencil bits. */ |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 267 | GrBackendRenderTarget(int width, |
| 268 | int height, |
| 269 | int sampleCnt, |
| 270 | int stencilBits, |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 271 | const GrVkImageInfo& vkInfo); |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 272 | GrBackendRenderTarget(int width, int height, int sampleCnt, const GrVkImageInfo& vkInfo); |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 273 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 274 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 275 | #ifdef SK_METAL |
| 276 | GrBackendRenderTarget(int width, |
| 277 | int height, |
| 278 | int sampleCnt, |
| 279 | const GrMtlTextureInfo& mtlInfo); |
| 280 | #endif |
| 281 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 282 | GrBackendRenderTarget(int width, |
| 283 | int height, |
| 284 | int sampleCnt, |
| 285 | int stencilBits, |
| 286 | const GrMockRenderTargetInfo& mockInfo); |
| 287 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 288 | ~GrBackendRenderTarget(); |
| 289 | |
| 290 | GrBackendRenderTarget(const GrBackendRenderTarget& that); |
| 291 | GrBackendRenderTarget& operator=(const GrBackendRenderTarget&); |
| 292 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 293 | int width() const { return fWidth; } |
| 294 | int height() const { return fHeight; } |
| 295 | int sampleCnt() const { return fSampleCnt; } |
| 296 | int stencilBits() const { return fStencilBits; } |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 297 | GrBackend backend() const {return fBackend; } |
| 298 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 299 | // If the backend API is GL, copies a snapshot of the GrGLFramebufferInfo struct into the passed |
| 300 | // in pointer and returns true. Otherwise returns false if the backend API is not GL. |
| 301 | bool getGLFramebufferInfo(GrGLFramebufferInfo*) const; |
Greg Daniel | c0f8e42 | 2017-06-13 13:47:53 -0400 | [diff] [blame] | 302 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 303 | #ifdef SK_VULKAN |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 304 | // If the backend API is Vulkan, copies a snapshot of the GrVkImageInfo struct into the passed |
| 305 | // in pointer and returns true. This snapshot will set the fImageLayout to the current layout |
| 306 | // state. Otherwise returns false if the backend API is not Vulkan. |
| 307 | bool getVkImageInfo(GrVkImageInfo*) const; |
| 308 | |
| 309 | // Anytime the client changes the VkImageLayout of the VkImage captured by this |
| 310 | // GrBackendRenderTarget, they must call this function to notify Skia of the changed layout. |
| 311 | void setVkImageLayout(VkImageLayout); |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 312 | #endif |
| 313 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 314 | #ifdef SK_METAL |
| 315 | // If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed |
| 316 | // in pointer and returns true. Otherwise returns false if the backend API is not Metal. |
| 317 | bool getMtlTextureInfo(GrMtlTextureInfo*) const; |
| 318 | #endif |
| 319 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 320 | // If the backend API is Mock, copies a snapshot of the GrMockTextureInfo struct into the passed |
| 321 | // in pointer and returns true. Otherwise returns false if the backend API is not Mock. |
| 322 | bool getMockRenderTargetInfo(GrMockRenderTargetInfo*) const; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 323 | |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 324 | // Returns true if the backend texture has been initialized. |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 325 | bool isValid() const { return fIsValid; } |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 326 | |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 327 | |
| 328 | #if GR_TEST_UTILS |
Greg Daniel | ff2181e | 2018-07-02 16:47:38 -0400 | [diff] [blame^] | 329 | // We can remove the pixelConfig getter and setter once we remove the pixel config from the |
| 330 | // GrBackendRenderTarget and plumb the pixel config manually throughout our code (or remove all |
| 331 | // use of GrPixelConfig in general). |
| 332 | GrPixelConfig pixelConfig() const { return fConfig; } |
| 333 | void setPixelConfig(GrPixelConfig config) { fConfig = config; } |
| 334 | |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 335 | static bool TestingOnly_Equals(const GrBackendRenderTarget&, const GrBackendRenderTarget&); |
| 336 | #endif |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 337 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 338 | private: |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 339 | // Friending for access to the GrPixelConfig |
| 340 | friend class SkSurface; |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 341 | friend class SkSurface_Gpu; |
| 342 | friend class SkImage_Gpu; |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 343 | friend class GrGpu; |
| 344 | friend class GrGLGpu; |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 345 | friend class GrProxyProvider; |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 346 | friend class GrVkGpu; |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 347 | friend class GrMtlGpu; |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 348 | GrPixelConfig config() const { return fConfig; } |
| 349 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 350 | #ifdef SK_VULKAN |
| 351 | // Requires friending of GrVkGpu (done above already) |
| 352 | sk_sp<GrVkImageLayout> getGrVkImageLayout() const; |
| 353 | |
| 354 | friend class GrVkRenderTarget; |
| 355 | GrBackendRenderTarget(int width, int height, int sampleCnt, const GrVkImageInfo& vkInfo, |
| 356 | sk_sp<GrVkImageLayout> layout); |
| 357 | #endif |
| 358 | |
| 359 | // Free and release and resources being held by the GrBackendTexture. |
| 360 | void cleanup(); |
| 361 | |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 362 | bool fIsValid; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 363 | int fWidth; //<! width in pixels |
| 364 | int fHeight; //<! height in pixels |
| 365 | |
| 366 | int fSampleCnt; |
| 367 | int fStencilBits; |
| 368 | GrPixelConfig fConfig; |
| 369 | |
| 370 | GrBackend fBackend; |
| 371 | |
| 372 | union { |
Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 373 | GrGLFramebufferInfo fGLInfo; |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 374 | #ifdef SK_VULKAN |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 375 | GrVkBackendSurfaceInfo fVkInfo; |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 376 | #endif |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 377 | #ifdef SK_METAL |
| 378 | GrMtlTextureInfo fMtlInfo; |
| 379 | #endif |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 380 | GrMockRenderTargetInfo fMockInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 381 | }; |
| 382 | }; |
| 383 | |
| 384 | #endif |
| 385 | |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 386 | #endif |
| 387 | |