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 | |
Robert Phillips | a3f7026 | 2018-02-08 10:59:38 -0500 | [diff] [blame] | 11 | #include "GrContextOptions.h" |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 12 | #include "GrGpuBuffer.h" |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 13 | #include "GrResourceCache.h" |
Cary Clark | 65e409f | 2018-02-28 15:01:05 -0500 | [diff] [blame] | 14 | #include "SkImageInfoPriv.h" |
Robert Phillips | 009e9af | 2017-06-15 14:01:04 -0400 | [diff] [blame] | 15 | #include "SkScalerContext.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 | /** |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 36 | * A factory for arbitrary resource types. This class is intended for use within the Gr code base. |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 37 | * |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 38 | * Some members force callers to make a flags (pendingIO) decision. This can be relaxed once |
| 39 | * https://bug.skia.org/4156 is fixed. |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 40 | */ |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 41 | class GrResourceProvider { |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 42 | public: |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 43 | /** These flags govern which scratch resources we are allowed to return */ |
| 44 | enum class Flags { |
| 45 | kNone = 0x0, |
| 46 | |
| 47 | /** If the caller intends to do direct reads/writes to/from the CPU then this flag must be |
| 48 | * set when accessing resources during a GrOpList flush. This includes the execution of |
| 49 | * GrOp objects. The reason is that these memory operations are done immediately and |
| 50 | * will occur out of order WRT the operations being flushed. |
| 51 | * Make this automatic: https://bug.skia.org/4156 |
| 52 | */ |
| 53 | kNoPendingIO = 0x1, |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 54 | }; |
| 55 | |
Robert Phillips | a3f7026 | 2018-02-08 10:59:38 -0500 | [diff] [blame] | 56 | GrResourceProvider(GrGpu*, GrResourceCache*, GrSingleOwner*, |
| 57 | GrContextOptions::Enable explicitlyAllocateGPUResources); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 58 | |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 59 | /** |
| 60 | * Finds a resource in the cache, based on the specified key. Prior to calling this, the caller |
| 61 | * must be sure that if a resource of exists in the cache with the given unique key then it is |
| 62 | * of type T. |
| 63 | */ |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 64 | template <typename T = GrGpuResource> |
| 65 | typename std::enable_if<std::is_base_of<GrGpuResource, T>::value, sk_sp<T>>::type |
| 66 | findByUniqueKey(const GrUniqueKey& key) { |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 67 | return sk_sp<T>(static_cast<T*>(this->findResourceByUniqueKey(key).release())); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 70 | /////////////////////////////////////////////////////////////////////////// |
| 71 | // Textures |
| 72 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 73 | /** |
| 74 | * Finds a texture that approximately matches the descriptor. Will be at least as large in width |
| 75 | * and height as desc specifies. If desc specifies that the texture should be a render target |
| 76 | * then result will be a render target. Format and sample count will always match the request. |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 77 | * The contents of the texture are undefined. |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 78 | */ |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 79 | sk_sp<GrTexture> createApproxTexture(const GrSurfaceDesc&, Flags); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 80 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 81 | /** Create an exact fit texture with no initial data to upload. |
| 82 | */ |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 83 | sk_sp<GrTexture> createTexture(const GrSurfaceDesc&, SkBudgeted, Flags = Flags::kNone); |
Robert Phillips | 45fdae1 | 2017-04-17 12:57:27 -0400 | [diff] [blame] | 84 | |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 85 | sk_sp<GrTexture> createTexture(const GrSurfaceDesc&, SkBudgeted, const GrMipLevel texels[], |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 86 | int mipLevelCount); |
Robert Phillips | 8e8c755 | 2017-07-10 12:06:05 -0400 | [diff] [blame] | 87 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 88 | // Create a potentially loose fit texture with the provided data |
Greg Daniel | fb3abcd | 2018-02-02 15:48:33 -0500 | [diff] [blame] | 89 | sk_sp<GrTexture> createTexture(const GrSurfaceDesc&, SkBudgeted, SkBackingFit, |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 90 | const GrMipLevel&, Flags); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 91 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 92 | /////////////////////////////////////////////////////////////////////////// |
| 93 | // Wrapped Backend Surfaces |
| 94 | |
| 95 | /** |
| 96 | * Wraps an existing texture with a GrTexture object. |
| 97 | * |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 98 | * GrIOType must either be kRead or kRW. kRead blocks any operations that would modify the |
| 99 | * pixels (e.g. dst for a copy, regenerating MIP levels, write pixels). |
| 100 | * |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 101 | * OpenGL: if the object is a texture Gr may change its GL texture params |
| 102 | * when it is drawn. |
| 103 | * |
| 104 | * @return GrTexture object or NULL on failure. |
| 105 | */ |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 106 | sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture& tex, GrWrapOwnership, |
| 107 | GrWrapCacheable, GrIOType); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 108 | |
| 109 | /** |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 110 | * 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] | 111 | * uses separate MSAA render buffers then a MSAA render buffer is created that resolves |
| 112 | * to the texture. |
| 113 | */ |
| 114 | sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture& tex, |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 115 | int sampleCnt, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 116 | GrWrapOwnership, |
| 117 | GrWrapCacheable); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 118 | |
| 119 | /** |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 120 | * Wraps an existing render target with a GrRenderTarget object. It is |
| 121 | * similar to wrapBackendTexture but can be used to draw into surfaces |
| 122 | * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that |
| 123 | * the client will resolve to a texture). Currently wrapped render targets |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 124 | * always use the kBorrow_GrWrapOwnership and GrWrapCacheable::kNo semantics. |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 125 | * |
| 126 | * @return GrRenderTarget object or NULL on failure. |
| 127 | */ |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 128 | sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 129 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 130 | sk_sp<GrRenderTarget> wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&, |
| 131 | const GrVkDrawableInfo&); |
| 132 | |
Robert Phillips | 1bfece8 | 2017-06-01 13:56:52 -0400 | [diff] [blame] | 133 | static const uint32_t kMinScratchTextureSize; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 134 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 135 | /** |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 136 | * Either finds and refs, or creates a static buffer with the given parameters and contents. |
| 137 | * |
| 138 | * @param intendedType hint to the graphics subsystem about what the buffer will be used for. |
| 139 | * @param size minimum size of buffer to return. |
| 140 | * @param data optional data with which to initialize the buffer. |
| 141 | * @param key Key to be assigned to the buffer. |
| 142 | * |
| 143 | * @return The buffer if successful, otherwise nullptr. |
| 144 | */ |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 145 | sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType intendedType, size_t size, |
| 146 | const void* data, const GrUniqueKey& key); |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 147 | |
| 148 | /** |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 149 | * Either finds and refs, or creates an index buffer with a repeating pattern for drawing |
| 150 | * contiguous vertices of a repeated mesh. If the return is non-null, the caller owns a ref on |
| 151 | * the returned GrBuffer. |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 152 | * |
| 153 | * @param pattern the pattern of indices to repeat |
| 154 | * @param patternSize size in bytes of the pattern |
| 155 | * @param reps number of times to repeat the pattern |
| 156 | * @param vertCount number of vertices the pattern references |
| 157 | * @param key Key to be assigned to the index buffer. |
| 158 | * |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 159 | * @return The index buffer if successful, otherwise nullptr. |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 160 | */ |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 161 | sk_sp<const GrGpuBuffer> findOrCreatePatternedIndexBuffer(const uint16_t* pattern, |
| 162 | int patternSize, |
| 163 | int reps, |
| 164 | int vertCount, |
| 165 | const GrUniqueKey& key) { |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 166 | if (auto buffer = this->findByUniqueKey<const GrGpuBuffer>(key)) { |
| 167 | return buffer; |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 168 | } |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 169 | return this->createPatternedIndexBuffer(pattern, patternSize, reps, vertCount, &key); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Returns an index buffer that can be used to render quads. |
Brian Salomon | 57caa66 | 2017-10-18 12:21:05 +0000 | [diff] [blame] | 174 | * Six indices per quad: 0, 1, 2, 2, 1, 3, etc. |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 175 | * 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] | 176 | * Draw with GrPrimitiveType::kTriangles |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 177 | * @ return the quad index buffer |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 178 | */ |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 179 | sk_sp<const GrGpuBuffer> refQuadIndexBuffer() { |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 180 | if (!fQuadIndexBuffer) { |
| 181 | fQuadIndexBuffer = this->createQuadIndexBuffer(); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 182 | } |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 183 | return fQuadIndexBuffer; |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 186 | static int QuadCountOfQuadBuffer(); |
| 187 | |
bsalomon | 706f08f | 2015-05-22 07:35:58 -0700 | [diff] [blame] | 188 | /** |
Ben Wagner | 3746ac2 | 2018-03-29 11:46:24 -0400 | [diff] [blame] | 189 | * 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] | 190 | * is not supported. |
| 191 | */ |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 192 | sk_sp<GrPath> createPath(const SkPath&, const GrStyle&); |
bsalomon | 706f08f | 2015-05-22 07:35:58 -0700 | [diff] [blame] | 193 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 194 | /** |
| 195 | * Returns a buffer. |
| 196 | * |
| 197 | * @param size minimum size of buffer to return. |
| 198 | * @param intendedType hint to the graphics subsystem about what the buffer will be used for. |
| 199 | * @param GrAccessPattern hint to the graphics subsystem about how the data will be accessed. |
| 200 | * @param flags see Flags enum. |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 201 | * @param data optional data with which to initialize the buffer. |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 202 | * |
| 203 | * @return the buffer if successful, otherwise nullptr. |
| 204 | */ |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 205 | sk_sp<GrGpuBuffer> createBuffer(size_t size, GrGpuBufferType intendedType, GrAccessPattern, |
| 206 | const void* data = nullptr); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 207 | |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 208 | /** |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 209 | * If passed in render target already has a stencil buffer, return true. Otherwise attempt to |
| 210 | * attach one and return true on success. |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 211 | */ |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 212 | bool attachStencilAttachment(GrRenderTarget* rt); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 213 | |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 214 | /** |
| 215 | * Wraps an existing texture with a GrRenderTarget object. This is useful when the provided |
| 216 | * texture has a format that cannot be textured from by Skia, but we want to raster to it. |
| 217 | * |
kkinnunen | 49c4c22 | 2016-04-01 04:50:37 -0700 | [diff] [blame] | 218 | * The texture is wrapped as borrowed. The texture object will not be freed once the |
| 219 | * render target is destroyed. |
| 220 | * |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 221 | * @return GrRenderTarget object or NULL on failure. |
| 222 | */ |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 223 | sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 224 | int sampleCnt); |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 225 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 226 | /** |
| 227 | * Assigns a unique key to a resource. If the key is associated with another resource that |
| 228 | * association is removed and replaced by this resource. |
| 229 | */ |
| 230 | void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*); |
| 231 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 232 | sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned = true); |
| 233 | |
Greg Daniel | 17b7c05 | 2018-01-09 13:55:33 -0500 | [diff] [blame] | 234 | enum class SemaphoreWrapType { |
| 235 | kWillSignal, |
| 236 | kWillWait, |
| 237 | }; |
| 238 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 239 | sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&, |
Greg Daniel | 17b7c05 | 2018-01-09 13:55:33 -0500 | [diff] [blame] | 240 | SemaphoreWrapType wrapType, |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 241 | GrWrapOwnership = kBorrow_GrWrapOwnership); |
Greg Daniel | d85f97d | 2017-03-07 13:37:21 -0500 | [diff] [blame] | 242 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 243 | void abandon() { |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 244 | fCache = nullptr; |
| 245 | fGpu = nullptr; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 246 | } |
| 247 | |
Brian Salomon | 238069b | 2018-07-11 15:58:57 -0400 | [diff] [blame] | 248 | uint32_t contextUniqueID() const { return fCache->contextUniqueID(); } |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 249 | const GrCaps* caps() const { return fCaps.get(); } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 250 | bool overBudget() const { return fCache->overBudget(); } |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 251 | |
Greg Daniel | 8982dc1 | 2018-01-05 12:56:15 -0500 | [diff] [blame] | 252 | inline GrResourceProviderPriv priv(); |
| 253 | inline const GrResourceProviderPriv priv() const; |
| 254 | |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 255 | bool explicitlyAllocateGPUResources() const { return fExplicitlyAllocateGPUResources; } |
| 256 | |
| 257 | bool testingOnly_setExplicitlyAllocateGPUResources(bool newValue); |
| 258 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 259 | private: |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 260 | sk_sp<GrGpuResource> findResourceByUniqueKey(const GrUniqueKey&); |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 261 | |
Greg Daniel | 29bf84f | 2017-09-25 12:25:12 -0400 | [diff] [blame] | 262 | // Attempts to find a resource in the cache that exactly matches the GrSurfaceDesc. Failing that |
| 263 | // it returns null. If non-null, the resulting texture is always budgeted. |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 264 | sk_sp<GrTexture> refScratchTexture(const GrSurfaceDesc&, Flags); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 265 | |
Robert Phillips | 45fdae1 | 2017-04-17 12:57:27 -0400 | [diff] [blame] | 266 | /* |
| 267 | * Try to find an existing scratch texture that exactly matches 'desc'. If successful |
| 268 | * update the budgeting accordingly. |
| 269 | */ |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 270 | sk_sp<GrTexture> getExactScratch(const GrSurfaceDesc&, SkBudgeted, Flags); |
Robert Phillips | 45fdae1 | 2017-04-17 12:57:27 -0400 | [diff] [blame] | 271 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 272 | GrResourceCache* cache() { return fCache; } |
| 273 | const GrResourceCache* cache() const { return fCache; } |
| 274 | |
Greg Daniel | 8982dc1 | 2018-01-05 12:56:15 -0500 | [diff] [blame] | 275 | friend class GrResourceProviderPriv; |
| 276 | |
| 277 | // Method made available via GrResourceProviderPriv |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 278 | GrGpu* gpu() { return fGpu; } |
| 279 | const GrGpu* gpu() const { return fGpu; } |
| 280 | |
| 281 | bool isAbandoned() const { |
| 282 | SkASSERT(SkToBool(fGpu) == SkToBool(fCache)); |
| 283 | return !SkToBool(fCache); |
| 284 | } |
| 285 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 286 | sk_sp<const GrGpuBuffer> createPatternedIndexBuffer(const uint16_t* pattern, |
| 287 | int patternSize, |
| 288 | int reps, |
| 289 | int vertCount, |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 290 | const GrUniqueKey* key); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 291 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 292 | sk_sp<const GrGpuBuffer> createQuadIndexBuffer(); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 293 | |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 294 | GrResourceCache* fCache; |
| 295 | GrGpu* fGpu; |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 296 | sk_sp<const GrCaps> fCaps; |
Brian Salomon | a29dd9d | 2019-02-07 13:27:18 -0500 | [diff] [blame] | 297 | sk_sp<const GrGpuBuffer> fQuadIndexBuffer; |
| 298 | bool fExplicitlyAllocateGPUResources; |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 299 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 300 | // In debug builds we guard against improper thread handling |
| 301 | SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;) |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 304 | GR_MAKE_BITFIELD_CLASS_OPS(GrResourceProvider::Flags); |
| 305 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 306 | #endif |