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