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 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 18 | #ifdef SK_DAWN |
| 19 | #include "include/gpu/dawn/GrDawnTypes.h" |
| 20 | #endif |
| 21 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 22 | class GrVkImageLayout; |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 23 | class GrGLTextureParameters; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 24 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 25 | #ifdef SK_DAWN |
| 26 | #include "dawn/dawncpp.h" |
| 27 | #endif |
| 28 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 29 | #ifdef SK_METAL |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 30 | #include "include/gpu/mtl/GrMtlTypes.h" |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 31 | #endif |
| 32 | |
Robert Phillips | bac4672 | 2019-08-01 15:09:17 -0400 | [diff] [blame] | 33 | #if GR_TEST_UTILS |
| 34 | class SkString; |
| 35 | #endif |
| 36 | |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 37 | #if !SK_SUPPORT_GPU |
| 38 | |
| 39 | // SkSurface and SkImage rely on a minimal version of these always being available |
| 40 | class SK_API GrBackendTexture { |
| 41 | public: |
| 42 | GrBackendTexture() {} |
| 43 | |
| 44 | bool isValid() const { return false; } |
| 45 | }; |
| 46 | |
| 47 | class SK_API GrBackendRenderTarget { |
| 48 | public: |
| 49 | GrBackendRenderTarget() {} |
| 50 | |
| 51 | bool isValid() const { return false; } |
| 52 | }; |
| 53 | #else |
| 54 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame^] | 55 | enum class GrGLFormat; |
| 56 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 57 | class SK_API GrBackendFormat { |
| 58 | public: |
| 59 | // Creates an invalid backend format. |
Robert Phillips | b2adbef | 2019-07-02 16:33:05 -0400 | [diff] [blame] | 60 | GrBackendFormat() {} |
| 61 | |
| 62 | GrBackendFormat(const GrBackendFormat& src); |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 63 | |
| 64 | static GrBackendFormat MakeGL(GrGLenum format, GrGLenum target) { |
| 65 | return GrBackendFormat(format, target); |
| 66 | } |
| 67 | |
Greg Daniel | a8d9211 | 2018-03-09 12:05:04 -0500 | [diff] [blame] | 68 | static GrBackendFormat MakeVk(VkFormat format) { |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 69 | return GrBackendFormat(format, GrVkYcbcrConversionInfo()); |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 70 | } |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 71 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 72 | // This is used for external textures and the VkFormat is assumed to be VK_FORMAT_UNDEFINED. |
| 73 | // This call is only supported on Android since the GrVkYcbcrConvesionInfo contains an android |
| 74 | // external format. |
| 75 | static GrBackendFormat MakeVk(const GrVkYcbcrConversionInfo& ycbcrInfo); |
| 76 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 77 | #ifdef SK_DAWN |
| 78 | static GrBackendFormat MakeDawn(dawn::TextureFormat format) { |
| 79 | return GrBackendFormat(format); |
| 80 | } |
| 81 | #endif |
| 82 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 83 | #ifdef SK_METAL |
| 84 | static GrBackendFormat MakeMtl(GrMTLPixelFormat format) { |
| 85 | return GrBackendFormat(format); |
| 86 | } |
| 87 | #endif |
| 88 | |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 89 | static GrBackendFormat MakeMock(GrColorType colorType) { |
| 90 | return GrBackendFormat(colorType); |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 91 | } |
| 92 | |
Greg Daniel | 45723ac | 2018-11-30 10:12:43 -0500 | [diff] [blame] | 93 | bool operator==(const GrBackendFormat& that) const; |
| 94 | bool operator!=(const GrBackendFormat& that) const { return !(*this == that); } |
| 95 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 96 | GrBackendApi backend() const { return fBackend; } |
| 97 | GrTextureType textureType() const { return fTextureType; } |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 98 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame^] | 99 | /** |
| 100 | * If the backend API is GL this gets the format as a GrGLFormat. Otherwise, returns |
| 101 | * GrGLFormat::kUnknown. |
| 102 | */ |
| 103 | GrGLFormat asGLFormat() const; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 104 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame^] | 105 | /** |
| 106 | * If the backend API is Vulkan this gets the format as a VkFormat and returns true. Otherwise, |
| 107 | * returns false. |
| 108 | */ |
| 109 | bool asVkFormat(VkFormat*) const; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 110 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 111 | const GrVkYcbcrConversionInfo* getVkYcbcrConversionInfo() const; |
| 112 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 113 | #ifdef SK_DAWN |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame^] | 114 | /** |
| 115 | * If the backend API is Dawn this gets the format as a dawn::TextureFormat and returns true. |
| 116 | * Otherwise, returns false. |
| 117 | */ |
| 118 | bool asDawnFormat(dawn::TextureFormat*) const; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 119 | #endif |
| 120 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 121 | #ifdef SK_METAL |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame^] | 122 | /** |
| 123 | * If the backend API is Metal this gets the format as a GrMtlPixelFormat. Otherwise, |
| 124 | * Otherwise, returns MTLPixelFormatInvalid. |
| 125 | */ |
| 126 | GrMTLPixelFormat asMtlFormat() const; |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 127 | #endif |
| 128 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame^] | 129 | /** |
| 130 | * If the backend API is Mock this gets the format as a GrColorType. Otherwise, returns |
| 131 | * GrColorType::kUnknown. |
| 132 | */ |
| 133 | GrColorType asMockColorType() const; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 134 | |
Greg Daniel | 387ec9a | 2019-03-07 16:44:54 -0500 | [diff] [blame] | 135 | // If possible, copies the GrBackendFormat and forces the texture type to be Texture2D. If the |
| 136 | // GrBackendFormat was for Vulkan and it originally had a GrVkYcbcrConversionInfo, we will |
| 137 | // 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] | 138 | GrBackendFormat makeTexture2D() const; |
| 139 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 140 | // Returns true if the backend format has been initialized. |
| 141 | bool isValid() const { return fValid; } |
| 142 | |
Robert Phillips | bac4672 | 2019-08-01 15:09:17 -0400 | [diff] [blame] | 143 | #if GR_TEST_UTILS |
| 144 | SkString toStr() const; |
| 145 | #endif |
| 146 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 147 | private: |
| 148 | GrBackendFormat(GrGLenum format, GrGLenum target); |
| 149 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 150 | GrBackendFormat(const VkFormat vkFormat, const GrVkYcbcrConversionInfo&); |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 151 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 152 | #ifdef SK_DAWN |
| 153 | GrBackendFormat(dawn::TextureFormat format); |
| 154 | #endif |
| 155 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 156 | #ifdef SK_METAL |
| 157 | GrBackendFormat(const GrMTLPixelFormat mtlFormat); |
| 158 | #endif |
| 159 | |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 160 | GrBackendFormat(GrColorType colorType); |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 161 | |
Robert Phillips | b2adbef | 2019-07-02 16:33:05 -0400 | [diff] [blame] | 162 | GrBackendApi fBackend = GrBackendApi::kMock; |
| 163 | bool fValid = false; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 164 | |
| 165 | union { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 166 | GrGLenum fGLFormat; // the sized, internal format of the GL resource |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 167 | struct { |
| 168 | VkFormat fFormat; |
| 169 | GrVkYcbcrConversionInfo fYcbcrConversionInfo; |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 170 | } fVk; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 171 | #ifdef SK_DAWN |
| 172 | dawn::TextureFormat fDawnFormat; |
| 173 | #endif |
| 174 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 175 | #ifdef SK_METAL |
| 176 | GrMTLPixelFormat fMtlFormat; |
| 177 | #endif |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 178 | GrColorType fMockColorType; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 179 | }; |
Robert Phillips | b2adbef | 2019-07-02 16:33:05 -0400 | [diff] [blame] | 180 | GrTextureType fTextureType = GrTextureType::kNone; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 181 | }; |
| 182 | |
Brian Salomon | ec045b4 | 2017-07-07 10:34:40 -0400 | [diff] [blame] | 183 | class SK_API GrBackendTexture { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 184 | public: |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 185 | // Creates an invalid backend texture. |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 186 | GrBackendTexture() : fIsValid(false) {} |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 187 | |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 188 | // The GrGLTextureInfo must have a valid fFormat. |
| 189 | GrBackendTexture(int width, |
| 190 | int height, |
| 191 | GrMipMapped, |
| 192 | const GrGLTextureInfo& glInfo); |
| 193 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 194 | GrBackendTexture(int width, |
| 195 | int height, |
| 196 | const GrVkImageInfo& vkInfo); |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 197 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 198 | #ifdef SK_METAL |
| 199 | GrBackendTexture(int width, |
| 200 | int height, |
| 201 | GrMipMapped, |
| 202 | const GrMtlTextureInfo& mtlInfo); |
| 203 | #endif |
| 204 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 205 | #ifdef SK_DAWN |
| 206 | GrBackendTexture(int width, |
| 207 | int height, |
| 208 | const GrDawnImageInfo& dawnInfo); |
| 209 | #endif |
| 210 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 211 | GrBackendTexture(int width, |
| 212 | int height, |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 213 | GrMipMapped, |
| 214 | const GrMockTextureInfo& mockInfo); |
| 215 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 216 | GrBackendTexture(const GrBackendTexture& that); |
| 217 | |
| 218 | ~GrBackendTexture(); |
| 219 | |
| 220 | GrBackendTexture& operator=(const GrBackendTexture& that); |
| 221 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 222 | int width() const { return fWidth; } |
| 223 | int height() const { return fHeight; } |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 224 | bool hasMipMaps() const { return GrMipMapped::kYes == fMipMapped; } |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 225 | GrBackendApi backend() const {return fBackend; } |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 226 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 227 | // If the backend API is GL, copies a snapshot of the GrGLTextureInfo struct into the passed in |
| 228 | // pointer and returns true. Otherwise returns false if the backend API is not GL. |
| 229 | bool getGLTextureInfo(GrGLTextureInfo*) const; |
Greg Daniel | c0f8e42 | 2017-06-13 13:47:53 -0400 | [diff] [blame] | 230 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 231 | // Call this to indicate that the texture parameters have been modified in the GL context |
| 232 | // externally to GrContext. |
| 233 | void glTextureParametersModified(); |
| 234 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 235 | #ifdef SK_DAWN |
| 236 | // If the backend API is Dawn, copies a snapshot of the GrDawnImageInfo struct into the passed |
| 237 | // in pointer and returns true. Otherwise returns false if the backend API is not Dawn. |
| 238 | bool getDawnImageInfo(GrDawnImageInfo*) const; |
| 239 | #endif |
| 240 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 241 | // 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] | 242 | // in pointer and returns true. This snapshot will set the fImageLayout to the current layout |
| 243 | // state. Otherwise returns false if the backend API is not Vulkan. |
| 244 | bool getVkImageInfo(GrVkImageInfo*) const; |
| 245 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 246 | // Anytime the client changes the VkImageLayout of the VkImage captured by this |
| 247 | // 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] | 248 | void setVkImageLayout(VkImageLayout); |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 249 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 250 | #ifdef SK_METAL |
| 251 | // If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed |
| 252 | // in pointer and returns true. Otherwise returns false if the backend API is not Metal. |
| 253 | bool getMtlTextureInfo(GrMtlTextureInfo*) const; |
| 254 | #endif |
| 255 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 256 | // Get the GrBackendFormat for this texture (or an invalid format if this is not valid). |
| 257 | GrBackendFormat getBackendFormat() const; |
| 258 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 259 | // If the backend API is Mock, copies a snapshot of the GrMockTextureInfo struct into the passed |
| 260 | // in pointer and returns true. Otherwise returns false if the backend API is not Mock. |
| 261 | bool getMockTextureInfo(GrMockTextureInfo*) const; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 262 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 263 | // Returns true if we are working with protected content. |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 264 | bool isProtected() const; |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 265 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 266 | // Returns true if the backend texture has been initialized. |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 267 | bool isValid() const { return fIsValid; } |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 268 | |
Brian Salomon | aad8315 | 2019-05-24 10:16:35 -0400 | [diff] [blame] | 269 | // Returns true if both textures are valid and refer to the same API texture. |
| 270 | bool isSameTexture(const GrBackendTexture&); |
| 271 | |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 272 | #if GR_TEST_UTILS |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 273 | static bool TestingOnly_Equals(const GrBackendTexture& , const GrBackendTexture&); |
| 274 | #endif |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 275 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 276 | private: |
Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 277 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 278 | #ifdef SK_GL |
| 279 | friend class GrGLTexture; |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 280 | friend class GrGLGpu; // for getGLTextureParams |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 281 | GrBackendTexture(int width, |
| 282 | int height, |
| 283 | GrMipMapped, |
| 284 | const GrGLTextureInfo, |
| 285 | sk_sp<GrGLTextureParameters>); |
| 286 | sk_sp<GrGLTextureParameters> getGLTextureParams() const; |
| 287 | #endif |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 288 | |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 289 | #ifdef SK_VULKAN |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 290 | friend class GrVkTexture; |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 291 | friend class GrVkGpu; // for getGrVkImageLayout |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 292 | GrBackendTexture(int width, |
| 293 | int height, |
| 294 | const GrVkImageInfo& vkInfo, |
| 295 | sk_sp<GrVkImageLayout> layout); |
| 296 | sk_sp<GrVkImageLayout> getGrVkImageLayout() const; |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 297 | #endif |
| 298 | |
| 299 | // Free and release and resources being held by the GrBackendTexture. |
| 300 | void cleanup(); |
| 301 | |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 302 | bool fIsValid; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 303 | int fWidth; //<! width in pixels |
| 304 | int fHeight; //<! height in pixels |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 305 | GrMipMapped fMipMapped; |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 306 | GrBackendApi fBackend; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 307 | |
| 308 | union { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 309 | #ifdef SK_GL |
| 310 | GrGLBackendTextureInfo fGLInfo; |
| 311 | #endif |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 312 | GrVkBackendSurfaceInfo fVkInfo; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 313 | GrMockTextureInfo fMockInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 314 | }; |
Jim Van Verth | dac1e55 | 2019-05-31 09:10:55 -0400 | [diff] [blame] | 315 | #ifdef SK_METAL |
| 316 | GrMtlTextureInfo fMtlInfo; |
| 317 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 318 | #ifdef SK_DAWN |
| 319 | GrDawnImageInfo fDawnInfo; |
| 320 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 321 | }; |
| 322 | |
Brian Salomon | ec045b4 | 2017-07-07 10:34:40 -0400 | [diff] [blame] | 323 | class SK_API GrBackendRenderTarget { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 324 | public: |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 325 | // Creates an invalid backend texture. |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 326 | GrBackendRenderTarget() : fIsValid(false) {} |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 327 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 328 | // The GrGLTextureInfo must have a valid fFormat. |
| 329 | GrBackendRenderTarget(int width, |
| 330 | int height, |
| 331 | int sampleCnt, |
| 332 | int stencilBits, |
| 333 | const GrGLFramebufferInfo& glInfo); |
| 334 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 335 | #ifdef SK_DAWN |
| 336 | GrBackendRenderTarget(int width, |
| 337 | int height, |
| 338 | int sampleCnt, |
| 339 | int stencilBits, |
| 340 | const GrDawnImageInfo& dawnInfo); |
| 341 | #endif |
| 342 | |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 343 | /** Deprecated, use version that does not take stencil bits. */ |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 344 | GrBackendRenderTarget(int width, |
| 345 | int height, |
| 346 | int sampleCnt, |
| 347 | int stencilBits, |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 348 | const GrVkImageInfo& vkInfo); |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 349 | GrBackendRenderTarget(int width, int height, int sampleCnt, const GrVkImageInfo& vkInfo); |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 350 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 351 | #ifdef SK_METAL |
| 352 | GrBackendRenderTarget(int width, |
| 353 | int height, |
| 354 | int sampleCnt, |
| 355 | const GrMtlTextureInfo& mtlInfo); |
| 356 | #endif |
| 357 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 358 | GrBackendRenderTarget(int width, |
| 359 | int height, |
| 360 | int sampleCnt, |
| 361 | int stencilBits, |
| 362 | const GrMockRenderTargetInfo& mockInfo); |
| 363 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 364 | ~GrBackendRenderTarget(); |
| 365 | |
| 366 | GrBackendRenderTarget(const GrBackendRenderTarget& that); |
| 367 | GrBackendRenderTarget& operator=(const GrBackendRenderTarget&); |
| 368 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 369 | int width() const { return fWidth; } |
| 370 | int height() const { return fHeight; } |
| 371 | int sampleCnt() const { return fSampleCnt; } |
| 372 | int stencilBits() const { return fStencilBits; } |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 373 | GrBackendApi backend() const {return fBackend; } |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 374 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 375 | // If the backend API is GL, copies a snapshot of the GrGLFramebufferInfo struct into the passed |
| 376 | // in pointer and returns true. Otherwise returns false if the backend API is not GL. |
| 377 | bool getGLFramebufferInfo(GrGLFramebufferInfo*) const; |
Greg Daniel | c0f8e42 | 2017-06-13 13:47:53 -0400 | [diff] [blame] | 378 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 379 | #ifdef SK_DAWN |
| 380 | // If the backend API is Dawn, copies a snapshot of the GrDawnImageInfo struct into the passed |
| 381 | // in pointer and returns true. Otherwise returns false if the backend API is not Dawn. |
| 382 | bool getDawnImageInfo(GrDawnImageInfo*) const; |
| 383 | #endif |
| 384 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 385 | // If the backend API is Vulkan, copies a snapshot of the GrVkImageInfo struct into the passed |
| 386 | // in pointer and returns true. This snapshot will set the fImageLayout to the current layout |
| 387 | // state. Otherwise returns false if the backend API is not Vulkan. |
| 388 | bool getVkImageInfo(GrVkImageInfo*) const; |
| 389 | |
| 390 | // Anytime the client changes the VkImageLayout of the VkImage captured by this |
| 391 | // GrBackendRenderTarget, they must call this function to notify Skia of the changed layout. |
| 392 | void setVkImageLayout(VkImageLayout); |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 393 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 394 | #ifdef SK_METAL |
| 395 | // If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed |
| 396 | // in pointer and returns true. Otherwise returns false if the backend API is not Metal. |
| 397 | bool getMtlTextureInfo(GrMtlTextureInfo*) const; |
| 398 | #endif |
| 399 | |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 400 | // Get the GrBackendFormat for this render target (or an invalid format if this is not valid). |
| 401 | GrBackendFormat getBackendFormat() const; |
| 402 | |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 403 | // If the backend API is Mock, copies a snapshot of the GrMockTextureInfo struct into the passed |
| 404 | // in pointer and returns true. Otherwise returns false if the backend API is not Mock. |
| 405 | bool getMockRenderTargetInfo(GrMockRenderTargetInfo*) const; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 406 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 407 | // Returns true if we are working with protected content. |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 408 | bool isProtected() const; |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 409 | |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 410 | // Returns true if the backend texture has been initialized. |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 411 | bool isValid() const { return fIsValid; } |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 412 | |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 413 | |
| 414 | #if GR_TEST_UTILS |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 415 | static bool TestingOnly_Equals(const GrBackendRenderTarget&, const GrBackendRenderTarget&); |
| 416 | #endif |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 417 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 418 | private: |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 419 | friend class GrVkGpu; // for getGrVkImageLayout |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 420 | sk_sp<GrVkImageLayout> getGrVkImageLayout() const; |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 421 | |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 422 | friend class GrVkRenderTarget; |
| 423 | GrBackendRenderTarget(int width, int height, int sampleCnt, const GrVkImageInfo& vkInfo, |
| 424 | sk_sp<GrVkImageLayout> layout); |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 425 | |
| 426 | // Free and release and resources being held by the GrBackendTexture. |
| 427 | void cleanup(); |
| 428 | |
Greg Daniel | 9ca3065 | 2018-04-06 09:27:20 -0400 | [diff] [blame] | 429 | bool fIsValid; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 430 | int fWidth; //<! width in pixels |
| 431 | int fHeight; //<! height in pixels |
| 432 | |
| 433 | int fSampleCnt; |
| 434 | int fStencilBits; |
Jim Van Verth | 7730d7c | 2019-05-28 03:03:45 +0000 | [diff] [blame] | 435 | |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 436 | GrBackendApi fBackend; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 437 | |
| 438 | union { |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 439 | #ifdef SK_GL |
Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 440 | GrGLFramebufferInfo fGLInfo; |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 441 | #endif |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 442 | GrVkBackendSurfaceInfo fVkInfo; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 443 | GrMockRenderTargetInfo fMockInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 444 | }; |
Jim Van Verth | dac1e55 | 2019-05-31 09:10:55 -0400 | [diff] [blame] | 445 | #ifdef SK_METAL |
| 446 | GrMtlTextureInfo fMtlInfo; |
| 447 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 448 | #ifdef SK_DAWN |
| 449 | GrDawnImageInfo fDawnInfo; |
| 450 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 451 | }; |
| 452 | |
| 453 | #endif |
| 454 | |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 455 | #endif |
| 456 | |