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