bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 GrResourceProvider_DEFINED |
| 9 | #define GrResourceProvider_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrContextOptions.h" |
| 12 | #include "include/private/SkImageInfoPriv.h" |
| 13 | #include "src/core/SkScalerContext.h" |
| 14 | #include "src/gpu/GrGpuBuffer.h" |
| 15 | #include "src/gpu/GrResourceCache.h" |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 16 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 17 | class GrBackendRenderTarget; |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 18 | class GrBackendSemaphore; |
| 19 | class GrBackendTexture; |
Robert Phillips | 009e9af | 2017-06-15 14:01:04 -0400 | [diff] [blame] | 20 | class GrGpu; |
bsalomon | 706f08f | 2015-05-22 07:35:58 -0700 | [diff] [blame] | 21 | class GrPath; |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 22 | class GrRenderTarget; |
Greg Daniel | 8982dc1 | 2018-01-05 12:56:15 -0500 | [diff] [blame] | 23 | class GrResourceProviderPriv; |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 24 | class GrSemaphore; |
joshualitt | 6d0872d | 2016-01-11 08:27:48 -0800 | [diff] [blame] | 25 | class GrSingleOwner; |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 26 | class GrStencilAttachment; |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 27 | class GrTexture; |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 28 | struct GrVkDrawableInfo; |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 29 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 30 | class GrStyle; |
bsalomon | 706f08f | 2015-05-22 07:35:58 -0700 | [diff] [blame] | 31 | class SkDescriptor; |
| 32 | class SkPath; |
| 33 | class SkTypeface; |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 34 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 35 | /** |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 36 | * A factory for arbitrary resource types. |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 37 | */ |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 38 | class GrResourceProvider { |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 39 | public: |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 40 | GrResourceProvider(GrGpu*, GrResourceCache*, GrSingleOwner*); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 41 | |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 42 | /** |
| 43 | * Finds a resource in the cache, based on the specified key. Prior to calling this, the caller |
| 44 | * must be sure that if a resource of exists in the cache with the given unique key then it is |
| 45 | * of type T. |
| 46 | */ |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 47 | template <typename T = GrGpuResource> |
| 48 | typename std::enable_if<std::is_base_of<GrGpuResource, T>::value, sk_sp<T>>::type |
| 49 | findByUniqueKey(const GrUniqueKey& key) { |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 50 | return sk_sp<T>(static_cast<T*>(this->findResourceByUniqueKey(key).release())); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 53 | /////////////////////////////////////////////////////////////////////////// |
| 54 | // Textures |
| 55 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 56 | /** |
| 57 | * Finds a texture that approximately matches the descriptor. Will be at least as large in width |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 58 | * and height as desc specifies. If renderable is kYes then the GrTexture will also be a |
| 59 | * GrRenderTarget. The texture's format and sample count will always match the request. |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 60 | * The contents of the texture are undefined. |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 61 | */ |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 62 | sk_sp<GrTexture> createApproxTexture(const GrSurfaceDesc& desc, |
| 63 | const GrBackendFormat& format, |
| 64 | GrRenderable renderable, |
| 65 | int renderTargetSampleCnt, |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 66 | GrProtected isProtected); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 67 | |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 68 | /** Create an exact fit texture with no initial data to upload. */ |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 69 | sk_sp<GrTexture> createTexture(const GrSurfaceDesc& desc, |
| 70 | const GrBackendFormat& format, |
| 71 | GrRenderable renderable, |
| 72 | int renderTargetSampleCnt, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 73 | GrMipMapped mipMapped, |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 74 | SkBudgeted budgeted, |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 75 | GrProtected isProtected); |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 76 | |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 77 | /** |
| 78 | * Create an exact fit texture with initial data to upload. The color type must be valid |
| 79 | * for the format and also describe the texel data. This will ensure any conversions that |
| 80 | * need to get applied to the data before upload are applied. |
| 81 | */ |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 82 | sk_sp<GrTexture> createTexture(const GrSurfaceDesc& desc, |
| 83 | const GrBackendFormat& format, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 84 | GrColorType colorType, |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 85 | GrRenderable renderable, |
| 86 | int renderTargetSampleCnt, |
| 87 | SkBudgeted budgeted, |
| 88 | GrProtected isProtected, |
| 89 | const GrMipLevel texels[], |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 90 | int mipLevelCount); |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 91 | |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 92 | /** |
| 93 | * Create a potentially loose fit texture with the provided data. The color type must be valid |
| 94 | * for the format and also describe the texel data. This will ensure any conversions that |
| 95 | * need to get applied to the data before upload are applied. |
| 96 | */ |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 97 | sk_sp<GrTexture> createTexture(const GrSurfaceDesc& desc, |
| 98 | const GrBackendFormat& format, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 99 | GrColorType srcColorType, |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 100 | GrRenderable renderable, |
| 101 | int renderTargetSampleCnt, |
| 102 | SkBudgeted budgeted, |
| 103 | SkBackingFit fit, |
| 104 | GrProtected isProtected, |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 105 | const GrMipLevel& mipLevel); |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * Creates a compressed texture. The GrGpu must support the SkImageImage::Compression type. |
| 109 | * This does not currently support MIP maps. It will not be renderable. |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 110 | */ |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 111 | sk_sp<GrTexture> createCompressedTexture(int width, int height, const GrBackendFormat&, |
| 112 | SkImage::CompressionType, SkBudgeted, SkData* data); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 113 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 114 | /////////////////////////////////////////////////////////////////////////// |
| 115 | // Wrapped Backend Surfaces |
| 116 | |
| 117 | /** |
| 118 | * Wraps an existing texture with a GrTexture object. |
| 119 | * |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 120 | * GrIOType must either be kRead or kRW. kRead blocks any operations that would modify the |
| 121 | * pixels (e.g. dst for a copy, regenerating MIP levels, write pixels). |
| 122 | * |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 123 | * OpenGL: if the object is a texture Gr may change its GL texture params |
| 124 | * when it is drawn. |
| 125 | * |
| 126 | * @return GrTexture object or NULL on failure. |
| 127 | */ |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 128 | sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture& tex, GrColorType, GrWrapOwnership, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 129 | GrWrapCacheable, GrIOType); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 130 | |
| 131 | /** |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 132 | * This makes the backend texture be renderable. If sampleCnt is > 1 and the underlying API |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 133 | * uses separate MSAA render buffers then a MSAA render buffer is created that resolves |
| 134 | * to the texture. |
| 135 | */ |
| 136 | sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture& tex, |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 137 | int sampleCnt, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 138 | GrColorType, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 139 | GrWrapOwnership, |
| 140 | GrWrapCacheable); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 141 | |
| 142 | /** |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 143 | * Wraps an existing render target with a GrRenderTarget object. It is |
| 144 | * similar to wrapBackendTexture but can be used to draw into surfaces |
| 145 | * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that |
| 146 | * the client will resolve to a texture). Currently wrapped render targets |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 147 | * always use the kBorrow_GrWrapOwnership and GrWrapCacheable::kNo semantics. |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 148 | * |
| 149 | * @return GrRenderTarget object or NULL on failure. |
| 150 | */ |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 151 | sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&, |
| 152 | GrColorType colorType); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 153 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 154 | sk_sp<GrRenderTarget> wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&, |
| 155 | const GrVkDrawableInfo&); |
| 156 | |
Robert Phillips | 1bfece8 | 2017-06-01 13:56:52 -0400 | [diff] [blame] | 157 | static const uint32_t kMinScratchTextureSize; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 158 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 159 | /** |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 160 | * Either finds and refs, or creates a static buffer with the given parameters and contents. |
| 161 | * |
| 162 | * @param intendedType hint to the graphics subsystem about what the buffer will be used for. |
| 163 | * @param size minimum size of buffer to return. |
| 164 | * @param data optional data with which to initialize the buffer. |
| 165 | * @param key Key to be assigned to the buffer. |
| 166 | * |
| 167 | * @return The buffer if successful, otherwise nullptr. |
| 168 | */ |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 169 | sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType intendedType, size_t size, |
| 170 | const void* data, const GrUniqueKey& key); |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 171 | |
| 172 | /** |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 173 | * Either finds and refs, or creates an index buffer with a repeating pattern for drawing |
| 174 | * contiguous vertices of a repeated mesh. If the return is non-null, the caller owns a ref on |
| 175 | * the returned GrBuffer. |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 176 | * |
| 177 | * @param pattern the pattern of indices to repeat |
| 178 | * @param patternSize size in bytes of the pattern |
| 179 | * @param reps number of times to repeat the pattern |
| 180 | * @param vertCount number of vertices the pattern references |
| 181 | * @param key Key to be assigned to the index buffer. |
| 182 | * |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 183 | * @return The index buffer if successful, otherwise nullptr. |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 184 | */ |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 185 | sk_sp<const GrGpuBuffer> findOrCreatePatternedIndexBuffer(const uint16_t* pattern, |
| 186 | int patternSize, |
| 187 | int reps, |
| 188 | int vertCount, |
| 189 | const GrUniqueKey& key) { |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 190 | if (auto buffer = this->findByUniqueKey<const GrGpuBuffer>(key)) { |
| 191 | return buffer; |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 192 | } |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 193 | return this->createPatternedIndexBuffer(pattern, patternSize, reps, vertCount, &key); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Returns an index buffer that can be used to render quads. |
Brian Salomon | 57caa66 | 2017-10-18 12:21:05 +0000 | [diff] [blame] | 198 | * Six indices per quad: 0, 1, 2, 2, 1, 3, etc. |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 199 | * The max number of quads is the buffer's index capacity divided by 6. |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 200 | * Draw with GrPrimitiveType::kTriangles |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 201 | * @ return the quad index buffer |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 202 | */ |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 203 | sk_sp<const GrGpuBuffer> refQuadIndexBuffer() { |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 204 | if (!fQuadIndexBuffer) { |
| 205 | fQuadIndexBuffer = this->createQuadIndexBuffer(); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 206 | } |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 207 | return fQuadIndexBuffer; |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 210 | static int QuadCountOfQuadBuffer(); |
| 211 | |
bsalomon | 706f08f | 2015-05-22 07:35:58 -0700 | [diff] [blame] | 212 | /** |
Ben Wagner | 3746ac2 | 2018-03-29 11:46:24 -0400 | [diff] [blame] | 213 | * Factories for GrPath objects. It's an error to call these if path rendering |
bsalomon | 706f08f | 2015-05-22 07:35:58 -0700 | [diff] [blame] | 214 | * is not supported. |
| 215 | */ |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 216 | sk_sp<GrPath> createPath(const SkPath&, const GrStyle&); |
bsalomon | 706f08f | 2015-05-22 07:35:58 -0700 | [diff] [blame] | 217 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 218 | /** |
| 219 | * Returns a buffer. |
| 220 | * |
| 221 | * @param size minimum size of buffer to return. |
| 222 | * @param intendedType hint to the graphics subsystem about what the buffer will be used for. |
| 223 | * @param GrAccessPattern hint to the graphics subsystem about how the data will be accessed. |
| 224 | * @param flags see Flags enum. |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 225 | * @param data optional data with which to initialize the buffer. |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 226 | * |
| 227 | * @return the buffer if successful, otherwise nullptr. |
| 228 | */ |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 229 | sk_sp<GrGpuBuffer> createBuffer(size_t size, GrGpuBufferType intendedType, GrAccessPattern, |
| 230 | const void* data = nullptr); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 231 | |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 232 | /** |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 233 | * If passed in render target already has a stencil buffer with at least "numSamples" samples, |
| 234 | * return true. Otherwise attempt to attach one and return true on success. |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 235 | */ |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 236 | bool attachStencilAttachment(GrRenderTarget* rt, int numStencilSamples); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 237 | |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 238 | /** |
| 239 | * Wraps an existing texture with a GrRenderTarget object. This is useful when the provided |
| 240 | * texture has a format that cannot be textured from by Skia, but we want to raster to it. |
| 241 | * |
kkinnunen | 49c4c22 | 2016-04-01 04:50:37 -0700 | [diff] [blame] | 242 | * The texture is wrapped as borrowed. The texture object will not be freed once the |
| 243 | * render target is destroyed. |
| 244 | * |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 245 | * @return GrRenderTarget object or NULL on failure. |
| 246 | */ |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 247 | sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&, |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 248 | int sampleCnt, |
| 249 | GrColorType); |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 250 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 251 | /** |
| 252 | * Assigns a unique key to a resource. If the key is associated with another resource that |
| 253 | * association is removed and replaced by this resource. |
| 254 | */ |
| 255 | void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*); |
| 256 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 257 | sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned = true); |
| 258 | |
Greg Daniel | 17b7c05 | 2018-01-09 13:55:33 -0500 | [diff] [blame] | 259 | enum class SemaphoreWrapType { |
| 260 | kWillSignal, |
| 261 | kWillWait, |
| 262 | }; |
| 263 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 264 | sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&, |
Greg Daniel | 17b7c05 | 2018-01-09 13:55:33 -0500 | [diff] [blame] | 265 | SemaphoreWrapType wrapType, |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 266 | GrWrapOwnership = kBorrow_GrWrapOwnership); |
Greg Daniel | d85f97d | 2017-03-07 13:37:21 -0500 | [diff] [blame] | 267 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 268 | void abandon() { |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 269 | fCache = nullptr; |
| 270 | fGpu = nullptr; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 271 | } |
| 272 | |
Brian Salomon | 238069b | 2018-07-11 15:58:57 -0400 | [diff] [blame] | 273 | uint32_t contextUniqueID() const { return fCache->contextUniqueID(); } |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 274 | const GrCaps* caps() const { return fCaps.get(); } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 275 | bool overBudget() const { return fCache->overBudget(); } |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 276 | |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 277 | static uint32_t MakeApprox(uint32_t value); |
| 278 | |
Greg Daniel | 8982dc1 | 2018-01-05 12:56:15 -0500 | [diff] [blame] | 279 | inline GrResourceProviderPriv priv(); |
| 280 | inline const GrResourceProviderPriv priv() const; |
| 281 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 282 | private: |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 283 | sk_sp<GrGpuResource> findResourceByUniqueKey(const GrUniqueKey&); |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 284 | |
Greg Daniel | 29bf84f | 2017-09-25 12:25:12 -0400 | [diff] [blame] | 285 | // Attempts to find a resource in the cache that exactly matches the GrSurfaceDesc. Failing that |
| 286 | // it returns null. If non-null, the resulting texture is always budgeted. |
Brian Salomon | 14cb413 | 2019-09-16 13:14:47 -0400 | [diff] [blame] | 287 | sk_sp<GrTexture> refScratchTexture(const GrSurfaceDesc&, |
| 288 | const GrBackendFormat&, |
| 289 | GrRenderable, |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 290 | int renderTargetSampleCnt, |
Brian Salomon | 14cb413 | 2019-09-16 13:14:47 -0400 | [diff] [blame] | 291 | GrMipMapped, |
| 292 | GrProtected); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 293 | |
Robert Phillips | 45fdae1 | 2017-04-17 12:57:27 -0400 | [diff] [blame] | 294 | /* |
| 295 | * Try to find an existing scratch texture that exactly matches 'desc'. If successful |
| 296 | * update the budgeting accordingly. |
| 297 | */ |
Brian Salomon | 14cb413 | 2019-09-16 13:14:47 -0400 | [diff] [blame] | 298 | sk_sp<GrTexture> getExactScratch(const GrSurfaceDesc&, |
| 299 | const GrBackendFormat&, |
| 300 | GrRenderable, |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 301 | int renderTargetSampleCnt, |
Brian Salomon | 14cb413 | 2019-09-16 13:14:47 -0400 | [diff] [blame] | 302 | SkBudgeted, |
| 303 | GrMipMapped, |
| 304 | GrProtected); |
Robert Phillips | 45fdae1 | 2017-04-17 12:57:27 -0400 | [diff] [blame] | 305 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 306 | GrResourceCache* cache() { return fCache; } |
| 307 | const GrResourceCache* cache() const { return fCache; } |
| 308 | |
Greg Daniel | 8982dc1 | 2018-01-05 12:56:15 -0500 | [diff] [blame] | 309 | friend class GrResourceProviderPriv; |
| 310 | |
| 311 | // Method made available via GrResourceProviderPriv |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 312 | GrGpu* gpu() { return fGpu; } |
| 313 | const GrGpu* gpu() const { return fGpu; } |
| 314 | |
| 315 | bool isAbandoned() const { |
| 316 | SkASSERT(SkToBool(fGpu) == SkToBool(fCache)); |
| 317 | return !SkToBool(fCache); |
| 318 | } |
| 319 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 320 | sk_sp<const GrGpuBuffer> createPatternedIndexBuffer(const uint16_t* pattern, |
| 321 | int patternSize, |
| 322 | int reps, |
| 323 | int vertCount, |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 324 | const GrUniqueKey* key); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 325 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 326 | sk_sp<const GrGpuBuffer> createQuadIndexBuffer(); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 327 | |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 328 | GrResourceCache* fCache; |
| 329 | GrGpu* fGpu; |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 330 | sk_sp<const GrCaps> fCaps; |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 331 | sk_sp<const GrGpuBuffer> fQuadIndexBuffer; |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 332 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 333 | // In debug builds we guard against improper thread handling |
| 334 | SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;) |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 335 | }; |
| 336 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 337 | #endif |