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