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