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