blob: 79b61b1188e7a6f887f76ada2df54e2d189c8c33 [file] [log] [blame]
bsalomond309e7a2015-04-30 14:18:54 -07001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#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"
bsalomond309e7a2015-04-30 14:18:54 -070016
Greg Danielbcf612b2017-05-01 13:50:58 +000017class GrBackendRenderTarget;
Greg Daniela5cb7812017-06-16 09:45:32 -040018class GrBackendSemaphore;
19class GrBackendTexture;
Robert Phillips009e9af2017-06-15 14:01:04 -040020class GrGpu;
bsalomon706f08f2015-05-22 07:35:58 -070021class GrPath;
egdanielec00d942015-09-14 12:56:10 -070022class GrRenderTarget;
Greg Daniel8982dc12018-01-05 12:56:15 -050023class GrResourceProviderPriv;
Robert Phillips646e4292017-06-13 12:44:56 -040024class GrSemaphore;
joshualitt6d0872d2016-01-11 08:27:48 -080025class GrSingleOwner;
egdanielec00d942015-09-14 12:56:10 -070026class GrStencilAttachment;
Robert Phillips646e4292017-06-13 12:44:56 -040027class GrTexture;
Greg Danielb46add82019-01-02 14:51:29 -050028struct GrVkDrawableInfo;
Robert Phillips646e4292017-06-13 12:44:56 -040029
bsalomon6663acf2016-05-10 09:14:17 -070030class GrStyle;
bsalomon706f08f2015-05-22 07:35:58 -070031class SkDescriptor;
32class SkPath;
33class SkTypeface;
bsalomoned0bcad2015-05-04 10:36:42 -070034
bsalomond309e7a2015-04-30 14:18:54 -070035/**
Robert Phillipsaee18c92019-09-06 11:48:27 -040036 * A factory for arbitrary resource types.
bsalomond309e7a2015-04-30 14:18:54 -070037 */
Brian Osman32342f02017-03-04 08:12:46 -050038class GrResourceProvider {
bsalomond309e7a2015-04-30 14:18:54 -070039public:
Robert Phillips12c46292019-04-23 07:36:17 -040040 GrResourceProvider(GrGpu*, GrResourceCache*, GrSingleOwner*);
bsalomoned0bcad2015-05-04 10:36:42 -070041
Brian Salomond28a79d2017-10-16 13:01:07 -040042 /**
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 Salomondbf70722019-02-07 11:31:24 -050047 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 Salomond28a79d2017-10-16 13:01:07 -040050 return sk_sp<T>(static_cast<T*>(this->findResourceByUniqueKey(key).release()));
bsalomoned0bcad2015-05-04 10:36:42 -070051 }
52
Brian Osman32342f02017-03-04 08:12:46 -050053 ///////////////////////////////////////////////////////////////////////////
54 // Textures
55
Brian Osman32342f02017-03-04 08:12:46 -050056 /**
57 * Finds a texture that approximately matches the descriptor. Will be at least as large in width
Brian Salomonf2c2ba92019-07-17 09:59:59 -040058 * 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 Phillips67d52cf2017-06-05 13:38:13 -040060 * The contents of the texture are undefined.
Brian Osman32342f02017-03-04 08:12:46 -050061 */
Brian Salomona56a7462020-02-07 14:17:25 -050062 sk_sp<GrTexture> createApproxTexture(SkISize dimensions,
Brian Salomon4eb38b72019-08-05 12:58:39 -040063 const GrBackendFormat& format,
64 GrRenderable renderable,
65 int renderTargetSampleCnt,
Robert Phillipsaee18c92019-09-06 11:48:27 -040066 GrProtected isProtected);
Brian Osman32342f02017-03-04 08:12:46 -050067
Brian Salomonf2c2ba92019-07-17 09:59:59 -040068 /** Create an exact fit texture with no initial data to upload. */
Brian Salomona56a7462020-02-07 14:17:25 -050069 sk_sp<GrTexture> createTexture(SkISize dimensions,
Brian Salomon4eb38b72019-08-05 12:58:39 -040070 const GrBackendFormat& format,
71 GrRenderable renderable,
72 int renderTargetSampleCnt,
Brian Salomon7e67dca2020-07-21 09:27:25 -040073 GrMipmapped mipMapped,
Brian Salomon4eb38b72019-08-05 12:58:39 -040074 SkBudgeted budgeted,
Robert Phillipsaee18c92019-09-06 11:48:27 -040075 GrProtected isProtected);
Brian Salomonf2c2ba92019-07-17 09:59:59 -040076
Brian Salomona90382f2019-09-17 09:01:56 -040077 /**
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 Salomona56a7462020-02-07 14:17:25 -050082 sk_sp<GrTexture> createTexture(SkISize dimensions,
Brian Salomon4eb38b72019-08-05 12:58:39 -040083 const GrBackendFormat& format,
Brian Salomona90382f2019-09-17 09:01:56 -040084 GrColorType colorType,
Brian Salomon4eb38b72019-08-05 12:58:39 -040085 GrRenderable renderable,
86 int renderTargetSampleCnt,
87 SkBudgeted budgeted,
88 GrProtected isProtected,
89 const GrMipLevel texels[],
Brian Salomon27b4d8d2019-07-22 14:23:45 -040090 int mipLevelCount);
Brian Salomonf2c2ba92019-07-17 09:59:59 -040091
Brian Salomona90382f2019-09-17 09:01:56 -040092 /**
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 Salomona56a7462020-02-07 14:17:25 -050097 sk_sp<GrTexture> createTexture(SkISize dimensions,
Robert Phillips3a833922020-01-21 15:25:58 -050098 const GrBackendFormat&,
Brian Salomona90382f2019-09-17 09:01:56 -040099 GrColorType srcColorType,
Robert Phillips3a833922020-01-21 15:25:58 -0500100 GrRenderable,
Brian Salomon4eb38b72019-08-05 12:58:39 -0400101 int renderTargetSampleCnt,
Robert Phillips3a833922020-01-21 15:25:58 -0500102 SkBudgeted,
103 SkBackingFit,
104 GrProtected,
Robert Phillipsaee18c92019-09-06 11:48:27 -0400105 const GrMipLevel& mipLevel);
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400106
107 /**
108 * Creates a compressed texture. The GrGpu must support the SkImageImage::Compression type.
Robert Phillipse4720c62020-01-14 14:33:24 -0500109 * It will not be renderable.
Robert Phillipse78b7252017-04-06 07:59:41 -0400110 */
Robert Phillips3a833922020-01-21 15:25:58 -0500111 sk_sp<GrTexture> createCompressedTexture(SkISize dimensions,
112 const GrBackendFormat&,
113 SkBudgeted,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400114 GrMipmapped,
Robert Phillips3a833922020-01-21 15:25:58 -0500115 GrProtected,
116 SkData* data);
Brian Salomonbb8dde82019-06-27 10:52:13 -0400117
Brian Osman32342f02017-03-04 08:12:46 -0500118 ///////////////////////////////////////////////////////////////////////////
119 // Wrapped Backend Surfaces
120
121 /**
122 * Wraps an existing texture with a GrTexture object.
123 *
Brian Salomonc67c31c2018-12-06 10:00:03 -0500124 * GrIOType must either be kRead or kRW. kRead blocks any operations that would modify the
125 * pixels (e.g. dst for a copy, regenerating MIP levels, write pixels).
126 *
Brian Osman32342f02017-03-04 08:12:46 -0500127 * OpenGL: if the object is a texture Gr may change its GL texture params
128 * when it is drawn.
129 *
130 * @return GrTexture object or NULL on failure.
131 */
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400132 sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture& tex,
133 GrWrapOwnership,
134 GrWrapCacheable,
135 GrIOType);
Brian Osman32342f02017-03-04 08:12:46 -0500136
Robert Phillipsead321b2019-12-19 10:16:32 -0500137 sk_sp<GrTexture> wrapCompressedBackendTexture(const GrBackendTexture& tex,
138 GrWrapOwnership,
139 GrWrapCacheable);
140
Brian Osman32342f02017-03-04 08:12:46 -0500141 /**
Brian Salomonbdecacf2018-02-02 20:32:49 -0500142 * This makes the backend texture be renderable. If sampleCnt is > 1 and the underlying API
Brian Salomond17f6582017-07-19 18:28:58 -0400143 * uses separate MSAA render buffers then a MSAA render buffer is created that resolves
144 * to the texture.
145 */
146 sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture& tex,
Brian Salomond17f6582017-07-19 18:28:58 -0400147 int sampleCnt,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500148 GrWrapOwnership,
149 GrWrapCacheable);
Brian Salomond17f6582017-07-19 18:28:58 -0400150
151 /**
Brian Osman32342f02017-03-04 08:12:46 -0500152 * Wraps an existing render target with a GrRenderTarget object. It is
153 * similar to wrapBackendTexture but can be used to draw into surfaces
154 * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that
155 * the client will resolve to a texture). Currently wrapped render targets
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500156 * always use the kBorrow_GrWrapOwnership and GrWrapCacheable::kNo semantics.
Brian Osman32342f02017-03-04 08:12:46 -0500157 *
158 * @return GrRenderTarget object or NULL on failure.
159 */
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400160 sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&);
Brian Osman32342f02017-03-04 08:12:46 -0500161
Greg Danielb46add82019-01-02 14:51:29 -0500162 sk_sp<GrRenderTarget> wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
163 const GrVkDrawableInfo&);
164
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400165 static const int kMinScratchTextureSize;
Brian Osman32342f02017-03-04 08:12:46 -0500166
bsalomoned0bcad2015-05-04 10:36:42 -0700167 /**
Chris Dalton5d2de082017-12-19 10:40:23 -0700168 * Either finds and refs, or creates a static buffer with the given parameters and contents.
169 *
170 * @param intendedType hint to the graphics subsystem about what the buffer will be used for.
171 * @param size minimum size of buffer to return.
172 * @param data optional data with which to initialize the buffer.
173 * @param key Key to be assigned to the buffer.
174 *
175 * @return The buffer if successful, otherwise nullptr.
176 */
Brian Salomondbf70722019-02-07 11:31:24 -0500177 sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType intendedType, size_t size,
178 const void* data, const GrUniqueKey& key);
Chris Dalton5d2de082017-12-19 10:40:23 -0700179
180 /**
Chris Daltonff926502017-05-03 14:36:54 -0400181 * Either finds and refs, or creates an index buffer with a repeating pattern for drawing
182 * contiguous vertices of a repeated mesh. If the return is non-null, the caller owns a ref on
183 * the returned GrBuffer.
bsalomoned0bcad2015-05-04 10:36:42 -0700184 *
185 * @param pattern the pattern of indices to repeat
186 * @param patternSize size in bytes of the pattern
187 * @param reps number of times to repeat the pattern
188 * @param vertCount number of vertices the pattern references
189 * @param key Key to be assigned to the index buffer.
190 *
halcanary96fcdcc2015-08-27 07:41:13 -0700191 * @return The index buffer if successful, otherwise nullptr.
bsalomoned0bcad2015-05-04 10:36:42 -0700192 */
Brian Salomondbf70722019-02-07 11:31:24 -0500193 sk_sp<const GrGpuBuffer> findOrCreatePatternedIndexBuffer(const uint16_t* pattern,
194 int patternSize,
195 int reps,
196 int vertCount,
197 const GrUniqueKey& key) {
Brian Salomona29dd9d2019-02-07 13:27:18 -0500198 if (auto buffer = this->findByUniqueKey<const GrGpuBuffer>(key)) {
199 return buffer;
bsalomoned0bcad2015-05-04 10:36:42 -0700200 }
Brian Salomona29dd9d2019-02-07 13:27:18 -0500201 return this->createPatternedIndexBuffer(pattern, patternSize, reps, vertCount, &key);
bsalomoned0bcad2015-05-04 10:36:42 -0700202 }
203
204 /**
Robert Phillipsee08d522019-10-28 16:34:44 -0400205 * Returns an index buffer that can be used to render non-antialiased quads.
206 * Each quad consumes 6 indices (0, 1, 2, 2, 1, 3) and 4 vertices.
207 * Call MaxNumNonAAQuads to get the max allowed number of non-AA quads.
Chris Dalton3809bab2017-06-13 10:55:06 -0600208 * Draw with GrPrimitiveType::kTriangles
Robert Phillipsee08d522019-10-28 16:34:44 -0400209 * @ return the non-AA quad index buffer
bsalomoned0bcad2015-05-04 10:36:42 -0700210 */
Robert Phillipsee08d522019-10-28 16:34:44 -0400211 sk_sp<const GrGpuBuffer> refNonAAQuadIndexBuffer() {
212 if (!fNonAAQuadIndexBuffer) {
213 fNonAAQuadIndexBuffer = this->createNonAAQuadIndexBuffer();
bsalomoned0bcad2015-05-04 10:36:42 -0700214 }
Robert Phillipsee08d522019-10-28 16:34:44 -0400215 return fNonAAQuadIndexBuffer;
bsalomoned0bcad2015-05-04 10:36:42 -0700216 }
217
Robert Phillipsee08d522019-10-28 16:34:44 -0400218 static int MaxNumNonAAQuads();
219 static int NumVertsPerNonAAQuad();
220 static int NumIndicesPerNonAAQuad();
221
222 /**
223 * Returns an index buffer that can be used to render antialiased quads.
224 * Each quad consumes 30 indices and 8 vertices.
225 * Call MaxNumAAQuads to get the max allowed number of AA quads.
226 * Draw with GrPrimitiveType::kTriangles
227 * @ return the AA quad index buffer
228 */
229 sk_sp<const GrGpuBuffer> refAAQuadIndexBuffer() {
230 if (!fAAQuadIndexBuffer) {
231 fAAQuadIndexBuffer = this->createAAQuadIndexBuffer();
232 }
233 return fAAQuadIndexBuffer;
234 }
235
236 static int MaxNumAAQuads();
237 static int NumVertsPerAAQuad();
238 static int NumIndicesPerAAQuad();
Brian Salomon34169692017-08-28 15:32:01 -0400239
bsalomon706f08f2015-05-22 07:35:58 -0700240 /**
Ben Wagner3746ac22018-03-29 11:46:24 -0400241 * Factories for GrPath objects. It's an error to call these if path rendering
bsalomon706f08f2015-05-22 07:35:58 -0700242 * is not supported.
243 */
Robert Phillips67d52cf2017-06-05 13:38:13 -0400244 sk_sp<GrPath> createPath(const SkPath&, const GrStyle&);
bsalomon706f08f2015-05-22 07:35:58 -0700245
cdaltone2e71c22016-04-07 18:13:29 -0700246 /**
247 * Returns a buffer.
248 *
249 * @param size minimum size of buffer to return.
250 * @param intendedType hint to the graphics subsystem about what the buffer will be used for.
251 * @param GrAccessPattern hint to the graphics subsystem about how the data will be accessed.
252 * @param flags see Flags enum.
cdalton1bf3e712016-04-19 10:00:02 -0700253 * @param data optional data with which to initialize the buffer.
cdaltone2e71c22016-04-07 18:13:29 -0700254 *
255 * @return the buffer if successful, otherwise nullptr.
256 */
Brian Salomondbf70722019-02-07 11:31:24 -0500257 sk_sp<GrGpuBuffer> createBuffer(size_t size, GrGpuBufferType intendedType, GrAccessPattern,
258 const void* data = nullptr);
robertphillips1b8e1b52015-06-24 06:54:10 -0700259
Brian Salomon2ee084e2016-12-16 18:59:19 -0500260 /**
Chris Daltoneffee202019-07-01 22:28:03 -0600261 * If passed in render target already has a stencil buffer with at least "numSamples" samples,
262 * return true. Otherwise attempt to attach one and return true on success.
egdanielec00d942015-09-14 12:56:10 -0700263 */
Chris Daltoneffee202019-07-01 22:28:03 -0600264 bool attachStencilAttachment(GrRenderTarget* rt, int numStencilSamples);
egdanielec00d942015-09-14 12:56:10 -0700265
ericrkf7b8b8a2016-02-24 14:49:51 -0800266 /**
267 * Wraps an existing texture with a GrRenderTarget object. This is useful when the provided
268 * texture has a format that cannot be textured from by Skia, but we want to raster to it.
269 *
kkinnunen49c4c222016-04-01 04:50:37 -0700270 * The texture is wrapped as borrowed. The texture object will not be freed once the
271 * render target is destroyed.
272 *
ericrkf7b8b8a2016-02-24 14:49:51 -0800273 * @return GrRenderTarget object or NULL on failure.
274 */
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400275 sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&, int sampleCnt);
ericrkf7b8b8a2016-02-24 14:49:51 -0800276
Brian Osman32342f02017-03-04 08:12:46 -0500277 /**
278 * Assigns a unique key to a resource. If the key is associated with another resource that
279 * association is removed and replaced by this resource.
280 */
281 void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*);
282
Greg Daniel301015c2019-11-18 14:06:46 -0500283 std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned = true);
Greg Daniela5cb7812017-06-16 09:45:32 -0400284
Greg Daniel17b7c052018-01-09 13:55:33 -0500285 enum class SemaphoreWrapType {
286 kWillSignal,
287 kWillWait,
288 };
289
Greg Daniel301015c2019-11-18 14:06:46 -0500290 std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&,
291 SemaphoreWrapType wrapType,
292 GrWrapOwnership = kBorrow_GrWrapOwnership);
Greg Danield85f97d2017-03-07 13:37:21 -0500293
Brian Osman32342f02017-03-04 08:12:46 -0500294 void abandon() {
Robert Phillips26c90e02017-03-14 14:39:29 -0400295 fCache = nullptr;
296 fGpu = nullptr;
Brian Osman32342f02017-03-04 08:12:46 -0500297 }
298
Brian Salomon238069b2018-07-11 15:58:57 -0400299 uint32_t contextUniqueID() const { return fCache->contextUniqueID(); }
Robert Phillips26c90e02017-03-14 14:39:29 -0400300 const GrCaps* caps() const { return fCaps.get(); }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500301 bool overBudget() const { return fCache->overBudget(); }
Robert Phillips26c90e02017-03-14 14:39:29 -0400302
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400303 static SkISize MakeApprox(SkISize);
Robert Phillipsf9fcf7f2019-07-11 09:03:27 -0400304
Greg Daniel8982dc12018-01-05 12:56:15 -0500305 inline GrResourceProviderPriv priv();
John Stilesec9b4aa2020-08-07 13:05:14 -0400306 inline const GrResourceProviderPriv priv() const; // NOLINT(readability-const-return-type)
Greg Daniel8982dc12018-01-05 12:56:15 -0500307
bsalomoned0bcad2015-05-04 10:36:42 -0700308private:
Brian Salomond28a79d2017-10-16 13:01:07 -0400309 sk_sp<GrGpuResource> findResourceByUniqueKey(const GrUniqueKey&);
Robert Phillips3798c862017-03-27 11:08:16 -0400310
Brian Salomona56a7462020-02-07 14:17:25 -0500311 // Attempts to find a resource in the cache that exactly matches the SkISize. Failing that
Greg Daniel29bf84f2017-09-25 12:25:12 -0400312 // it returns null. If non-null, the resulting texture is always budgeted.
Brian Salomona56a7462020-02-07 14:17:25 -0500313 sk_sp<GrTexture> refScratchTexture(SkISize dimensions,
Brian Salomon14cb4132019-09-16 13:14:47 -0400314 const GrBackendFormat&,
315 GrRenderable,
Brian Salomon4eb38b72019-08-05 12:58:39 -0400316 int renderTargetSampleCnt,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400317 GrMipmapped,
Brian Salomon14cb4132019-09-16 13:14:47 -0400318 GrProtected);
Brian Osman32342f02017-03-04 08:12:46 -0500319
Robert Phillips45fdae12017-04-17 12:57:27 -0400320 /*
321 * Try to find an existing scratch texture that exactly matches 'desc'. If successful
322 * update the budgeting accordingly.
323 */
Brian Salomona56a7462020-02-07 14:17:25 -0500324 sk_sp<GrTexture> getExactScratch(SkISize dimensions,
Brian Salomon14cb4132019-09-16 13:14:47 -0400325 const GrBackendFormat&,
326 GrRenderable,
Brian Salomon4eb38b72019-08-05 12:58:39 -0400327 int renderTargetSampleCnt,
Brian Salomon14cb4132019-09-16 13:14:47 -0400328 SkBudgeted,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400329 GrMipmapped,
Brian Salomon14cb4132019-09-16 13:14:47 -0400330 GrProtected);
Robert Phillips45fdae12017-04-17 12:57:27 -0400331
Brian Salomon8660eb02019-09-20 13:04:13 -0400332 // Used to perform any conversions necessary to texel data before creating a texture with
333 // existing data or uploading to a scratch texture.
334 using TempLevels = SkAutoSTMalloc<14, GrMipLevel>;
335 using TempLevelDatas = SkAutoSTArray<14, std::unique_ptr<char[]>>;
336 GrColorType prepareLevels(const GrBackendFormat& format,
337 GrColorType,
Brian Salomona56a7462020-02-07 14:17:25 -0500338 SkISize baseSize,
Brian Salomon8660eb02019-09-20 13:04:13 -0400339 const GrMipLevel texels[],
340 int mipLevelCount,
341 TempLevels*,
342 TempLevelDatas*) const;
343
344 // GrResourceProvider may be asked to "create" a new texture with initial pixel data to populate
345 // it. In implementation it may pull an existing texture from GrResourceCache and then write the
346 // pixel data to the texture. It takes a width/height for the base level because we may be
347 // using an approximate-sized scratch texture. On success the texture is returned and nullptr
348 // on failure.
349 sk_sp<GrTexture> writePixels(sk_sp<GrTexture> texture,
350 GrColorType colorType,
Brian Salomona56a7462020-02-07 14:17:25 -0500351 SkISize baseSize,
Brian Salomon8660eb02019-09-20 13:04:13 -0400352 const GrMipLevel texels[],
353 int mipLevelCount) const;
354
Brian Osman32342f02017-03-04 08:12:46 -0500355 GrResourceCache* cache() { return fCache; }
356 const GrResourceCache* cache() const { return fCache; }
357
Greg Daniel8982dc12018-01-05 12:56:15 -0500358 friend class GrResourceProviderPriv;
359
360 // Method made available via GrResourceProviderPriv
Brian Osman32342f02017-03-04 08:12:46 -0500361 GrGpu* gpu() { return fGpu; }
362 const GrGpu* gpu() const { return fGpu; }
363
364 bool isAbandoned() const {
365 SkASSERT(SkToBool(fGpu) == SkToBool(fCache));
366 return !SkToBool(fCache);
367 }
368
Brian Salomondbf70722019-02-07 11:31:24 -0500369 sk_sp<const GrGpuBuffer> createPatternedIndexBuffer(const uint16_t* pattern,
370 int patternSize,
371 int reps,
372 int vertCount,
Brian Salomona29dd9d2019-02-07 13:27:18 -0500373 const GrUniqueKey* key);
bsalomoned0bcad2015-05-04 10:36:42 -0700374
Robert Phillipsee08d522019-10-28 16:34:44 -0400375 sk_sp<const GrGpuBuffer> createNonAAQuadIndexBuffer();
376 sk_sp<const GrGpuBuffer> createAAQuadIndexBuffer();
bsalomoned0bcad2015-05-04 10:36:42 -0700377
Brian Salomona29dd9d2019-02-07 13:27:18 -0500378 GrResourceCache* fCache;
379 GrGpu* fGpu;
Robert Phillips26c90e02017-03-14 14:39:29 -0400380 sk_sp<const GrCaps> fCaps;
Robert Phillipsee08d522019-10-28 16:34:44 -0400381 sk_sp<const GrGpuBuffer> fNonAAQuadIndexBuffer;
382 sk_sp<const GrGpuBuffer> fAAQuadIndexBuffer;
bsalomoned0bcad2015-05-04 10:36:42 -0700383
Brian Osman32342f02017-03-04 08:12:46 -0500384 // In debug builds we guard against improper thread handling
385 SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;)
bsalomond309e7a2015-04-30 14:18:54 -0700386};
387
bsalomond309e7a2015-04-30 14:18:54 -0700388#endif