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