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