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