blob: 5d2e8fab81874e9bc1d153bb4dba0e1d8bf96ce1 [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;
Greg Daniel5d0330e2020-10-12 16:05:21 -040021class GrMSAAAttachment;
bsalomon706f08f2015-05-22 07:35:58 -070022class GrPath;
egdanielec00d942015-09-14 12:56:10 -070023class GrRenderTarget;
Greg Daniel8982dc12018-01-05 12:56:15 -050024class GrResourceProviderPriv;
Robert Phillips646e4292017-06-13 12:44:56 -040025class GrSemaphore;
joshualitt6d0872d2016-01-11 08:27:48 -080026class GrSingleOwner;
Greg Danielc0d69152020-10-08 14:59:00 -040027class GrAttachment;
Robert Phillips646e4292017-06-13 12:44:56 -040028class GrTexture;
Greg Danielb46add82019-01-02 14:51:29 -050029struct GrVkDrawableInfo;
Robert Phillips646e4292017-06-13 12:44:56 -040030
bsalomon6663acf2016-05-10 09:14:17 -070031class GrStyle;
bsalomon706f08f2015-05-22 07:35:58 -070032class SkDescriptor;
33class SkPath;
34class SkTypeface;
bsalomoned0bcad2015-05-04 10:36:42 -070035
bsalomond309e7a2015-04-30 14:18:54 -070036/**
Robert Phillipsaee18c92019-09-06 11:48:27 -040037 * A factory for arbitrary resource types.
bsalomond309e7a2015-04-30 14:18:54 -070038 */
Brian Osman32342f02017-03-04 08:12:46 -050039class GrResourceProvider {
bsalomond309e7a2015-04-30 14:18:54 -070040public:
Robert Phillips12c46292019-04-23 07:36:17 -040041 GrResourceProvider(GrGpu*, GrResourceCache*, GrSingleOwner*);
bsalomoned0bcad2015-05-04 10:36:42 -070042
Brian Salomond28a79d2017-10-16 13:01:07 -040043 /**
44 * Finds a resource in the cache, based on the specified key. Prior to calling this, the caller
45 * must be sure that if a resource of exists in the cache with the given unique key then it is
46 * of type T.
47 */
Brian Salomondbf70722019-02-07 11:31:24 -050048 template <typename T = GrGpuResource>
49 typename std::enable_if<std::is_base_of<GrGpuResource, T>::value, sk_sp<T>>::type
50 findByUniqueKey(const GrUniqueKey& key) {
Brian Salomond28a79d2017-10-16 13:01:07 -040051 return sk_sp<T>(static_cast<T*>(this->findResourceByUniqueKey(key).release()));
bsalomoned0bcad2015-05-04 10:36:42 -070052 }
53
Brian Osman32342f02017-03-04 08:12:46 -050054 ///////////////////////////////////////////////////////////////////////////
55 // Textures
56
Brian Osman32342f02017-03-04 08:12:46 -050057 /**
58 * Finds a texture that approximately matches the descriptor. Will be at least as large in width
Brian Salomonf2c2ba92019-07-17 09:59:59 -040059 * and height as desc specifies. If renderable is kYes then the GrTexture will also be a
60 * GrRenderTarget. The texture's format and sample count will always match the request.
Robert Phillips67d52cf2017-06-05 13:38:13 -040061 * The contents of the texture are undefined.
Brian Osman32342f02017-03-04 08:12:46 -050062 */
Brian Salomona56a7462020-02-07 14:17:25 -050063 sk_sp<GrTexture> createApproxTexture(SkISize dimensions,
Brian Salomon4eb38b72019-08-05 12:58:39 -040064 const GrBackendFormat& format,
65 GrRenderable renderable,
66 int renderTargetSampleCnt,
Robert Phillipsaee18c92019-09-06 11:48:27 -040067 GrProtected isProtected);
Brian Osman32342f02017-03-04 08:12:46 -050068
Brian Salomonf2c2ba92019-07-17 09:59:59 -040069 /** Create an exact fit texture with no initial data to upload. */
Brian Salomona56a7462020-02-07 14:17:25 -050070 sk_sp<GrTexture> createTexture(SkISize dimensions,
Brian Salomon4eb38b72019-08-05 12:58:39 -040071 const GrBackendFormat& format,
72 GrRenderable renderable,
73 int renderTargetSampleCnt,
Brian Salomon7e67dca2020-07-21 09:27:25 -040074 GrMipmapped mipMapped,
Brian Salomon4eb38b72019-08-05 12:58:39 -040075 SkBudgeted budgeted,
Robert Phillipsaee18c92019-09-06 11:48:27 -040076 GrProtected isProtected);
Brian Salomonf2c2ba92019-07-17 09:59:59 -040077
Brian Salomona90382f2019-09-17 09:01:56 -040078 /**
79 * Create an exact fit texture with initial data to upload. The color type must be valid
80 * for the format and also describe the texel data. This will ensure any conversions that
81 * need to get applied to the data before upload are applied.
82 */
Brian Salomona56a7462020-02-07 14:17:25 -050083 sk_sp<GrTexture> createTexture(SkISize dimensions,
Brian Salomon4eb38b72019-08-05 12:58:39 -040084 const GrBackendFormat& format,
Brian Salomona90382f2019-09-17 09:01:56 -040085 GrColorType colorType,
Brian Salomon4eb38b72019-08-05 12:58:39 -040086 GrRenderable renderable,
87 int renderTargetSampleCnt,
88 SkBudgeted budgeted,
Robert Phillips6c706612020-12-07 12:12:05 -050089 GrMipMapped mipMapped,
Brian Salomon4eb38b72019-08-05 12:58:39 -040090 GrProtected isProtected,
Robert Phillips6c706612020-12-07 12:12:05 -050091 const GrMipLevel texels[]);
Brian Salomonf2c2ba92019-07-17 09:59:59 -040092
Brian Salomona90382f2019-09-17 09:01:56 -040093 /**
94 * Create a potentially loose fit texture with the provided data. The color type must be valid
95 * for the format and also describe the texel data. This will ensure any conversions that
96 * need to get applied to the data before upload are applied.
97 */
Brian Salomona56a7462020-02-07 14:17:25 -050098 sk_sp<GrTexture> createTexture(SkISize dimensions,
Robert Phillips3a833922020-01-21 15:25:58 -050099 const GrBackendFormat&,
Brian Salomona90382f2019-09-17 09:01:56 -0400100 GrColorType srcColorType,
Robert Phillips3a833922020-01-21 15:25:58 -0500101 GrRenderable,
Brian Salomon4eb38b72019-08-05 12:58:39 -0400102 int renderTargetSampleCnt,
Robert Phillips3a833922020-01-21 15:25:58 -0500103 SkBudgeted,
104 SkBackingFit,
105 GrProtected,
Robert Phillipsaee18c92019-09-06 11:48:27 -0400106 const GrMipLevel& mipLevel);
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400107
108 /**
109 * Creates a compressed texture. The GrGpu must support the SkImageImage::Compression type.
Robert Phillipse4720c62020-01-14 14:33:24 -0500110 * It will not be renderable.
Robert Phillipse78b7252017-04-06 07:59:41 -0400111 */
Robert Phillips3a833922020-01-21 15:25:58 -0500112 sk_sp<GrTexture> createCompressedTexture(SkISize dimensions,
113 const GrBackendFormat&,
114 SkBudgeted,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400115 GrMipmapped,
Robert Phillips3a833922020-01-21 15:25:58 -0500116 GrProtected,
117 SkData* data);
Brian Salomonbb8dde82019-06-27 10:52:13 -0400118
Brian Osman32342f02017-03-04 08:12:46 -0500119 ///////////////////////////////////////////////////////////////////////////
120 // Wrapped Backend Surfaces
121
122 /**
123 * Wraps an existing texture with a GrTexture object.
124 *
Brian Salomonc67c31c2018-12-06 10:00:03 -0500125 * GrIOType must either be kRead or kRW. kRead blocks any operations that would modify the
126 * pixels (e.g. dst for a copy, regenerating MIP levels, write pixels).
127 *
Brian Osman32342f02017-03-04 08:12:46 -0500128 * OpenGL: if the object is a texture Gr may change its GL texture params
129 * when it is drawn.
130 *
131 * @return GrTexture object or NULL on failure.
132 */
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400133 sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture& tex,
134 GrWrapOwnership,
135 GrWrapCacheable,
136 GrIOType);
Brian Osman32342f02017-03-04 08:12:46 -0500137
Robert Phillipsead321b2019-12-19 10:16:32 -0500138 sk_sp<GrTexture> wrapCompressedBackendTexture(const GrBackendTexture& tex,
139 GrWrapOwnership,
140 GrWrapCacheable);
141
Brian Osman32342f02017-03-04 08:12:46 -0500142 /**
Brian Salomonbdecacf2018-02-02 20:32:49 -0500143 * This makes the backend texture be renderable. If sampleCnt is > 1 and the underlying API
Brian Salomond17f6582017-07-19 18:28:58 -0400144 * uses separate MSAA render buffers then a MSAA render buffer is created that resolves
145 * to the texture.
146 */
147 sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture& tex,
Brian Salomond17f6582017-07-19 18:28:58 -0400148 int sampleCnt,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500149 GrWrapOwnership,
150 GrWrapCacheable);
Brian Salomond17f6582017-07-19 18:28:58 -0400151
152 /**
Brian Osman32342f02017-03-04 08:12:46 -0500153 * Wraps an existing render target with a GrRenderTarget object. It is
154 * similar to wrapBackendTexture but can be used to draw into surfaces
155 * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that
156 * the client will resolve to a texture). Currently wrapped render targets
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500157 * always use the kBorrow_GrWrapOwnership and GrWrapCacheable::kNo semantics.
Brian Osman32342f02017-03-04 08:12:46 -0500158 *
159 * @return GrRenderTarget object or NULL on failure.
160 */
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400161 sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&);
Brian Osman32342f02017-03-04 08:12:46 -0500162
Greg Danielb46add82019-01-02 14:51:29 -0500163 sk_sp<GrRenderTarget> wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
164 const GrVkDrawableInfo&);
165
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400166 static const int kMinScratchTextureSize;
Brian Osman32342f02017-03-04 08:12:46 -0500167
bsalomoned0bcad2015-05-04 10:36:42 -0700168 /**
Chris Dalton5d2de082017-12-19 10:40:23 -0700169 * Either finds and refs, or creates a static buffer with the given parameters and contents.
170 *
171 * @param intendedType hint to the graphics subsystem about what the buffer will be used for.
172 * @param size minimum size of buffer to return.
173 * @param data optional data with which to initialize the buffer.
174 * @param key Key to be assigned to the buffer.
175 *
176 * @return The buffer if successful, otherwise nullptr.
177 */
Brian Salomondbf70722019-02-07 11:31:24 -0500178 sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType intendedType, size_t size,
179 const void* data, const GrUniqueKey& key);
Chris Dalton5d2de082017-12-19 10:40:23 -0700180
181 /**
Chris Daltonff926502017-05-03 14:36:54 -0400182 * Either finds and refs, or creates an index buffer with a repeating pattern for drawing
183 * contiguous vertices of a repeated mesh. If the return is non-null, the caller owns a ref on
184 * the returned GrBuffer.
bsalomoned0bcad2015-05-04 10:36:42 -0700185 *
186 * @param pattern the pattern of indices to repeat
187 * @param patternSize size in bytes of the pattern
188 * @param reps number of times to repeat the pattern
189 * @param vertCount number of vertices the pattern references
190 * @param key Key to be assigned to the index buffer.
191 *
halcanary96fcdcc2015-08-27 07:41:13 -0700192 * @return The index buffer if successful, otherwise nullptr.
bsalomoned0bcad2015-05-04 10:36:42 -0700193 */
Brian Salomondbf70722019-02-07 11:31:24 -0500194 sk_sp<const GrGpuBuffer> findOrCreatePatternedIndexBuffer(const uint16_t* pattern,
195 int patternSize,
196 int reps,
197 int vertCount,
198 const GrUniqueKey& key) {
Brian Salomona29dd9d2019-02-07 13:27:18 -0500199 if (auto buffer = this->findByUniqueKey<const GrGpuBuffer>(key)) {
200 return buffer;
bsalomoned0bcad2015-05-04 10:36:42 -0700201 }
Brian Salomona29dd9d2019-02-07 13:27:18 -0500202 return this->createPatternedIndexBuffer(pattern, patternSize, reps, vertCount, &key);
bsalomoned0bcad2015-05-04 10:36:42 -0700203 }
204
205 /**
Robert Phillipsee08d522019-10-28 16:34:44 -0400206 * Returns an index buffer that can be used to render non-antialiased quads.
207 * Each quad consumes 6 indices (0, 1, 2, 2, 1, 3) and 4 vertices.
208 * Call MaxNumNonAAQuads to get the max allowed number of non-AA quads.
Chris Dalton3809bab2017-06-13 10:55:06 -0600209 * Draw with GrPrimitiveType::kTriangles
Robert Phillipsee08d522019-10-28 16:34:44 -0400210 * @ return the non-AA quad index buffer
bsalomoned0bcad2015-05-04 10:36:42 -0700211 */
Robert Phillipsee08d522019-10-28 16:34:44 -0400212 sk_sp<const GrGpuBuffer> refNonAAQuadIndexBuffer() {
213 if (!fNonAAQuadIndexBuffer) {
214 fNonAAQuadIndexBuffer = this->createNonAAQuadIndexBuffer();
bsalomoned0bcad2015-05-04 10:36:42 -0700215 }
Robert Phillipsee08d522019-10-28 16:34:44 -0400216 return fNonAAQuadIndexBuffer;
bsalomoned0bcad2015-05-04 10:36:42 -0700217 }
218
Robert Phillipsee08d522019-10-28 16:34:44 -0400219 static int MaxNumNonAAQuads();
220 static int NumVertsPerNonAAQuad();
221 static int NumIndicesPerNonAAQuad();
222
223 /**
224 * Returns an index buffer that can be used to render antialiased quads.
225 * Each quad consumes 30 indices and 8 vertices.
226 * Call MaxNumAAQuads to get the max allowed number of AA quads.
227 * Draw with GrPrimitiveType::kTriangles
228 * @ return the AA quad index buffer
229 */
230 sk_sp<const GrGpuBuffer> refAAQuadIndexBuffer() {
231 if (!fAAQuadIndexBuffer) {
232 fAAQuadIndexBuffer = this->createAAQuadIndexBuffer();
233 }
234 return fAAQuadIndexBuffer;
235 }
236
237 static int MaxNumAAQuads();
238 static int NumVertsPerAAQuad();
239 static int NumIndicesPerAAQuad();
Brian Salomon34169692017-08-28 15:32:01 -0400240
bsalomon706f08f2015-05-22 07:35:58 -0700241 /**
Ben Wagner3746ac22018-03-29 11:46:24 -0400242 * Factories for GrPath objects. It's an error to call these if path rendering
bsalomon706f08f2015-05-22 07:35:58 -0700243 * is not supported.
244 */
Robert Phillips67d52cf2017-06-05 13:38:13 -0400245 sk_sp<GrPath> createPath(const SkPath&, const GrStyle&);
bsalomon706f08f2015-05-22 07:35:58 -0700246
cdaltone2e71c22016-04-07 18:13:29 -0700247 /**
248 * Returns a buffer.
249 *
250 * @param size minimum size of buffer to return.
251 * @param intendedType hint to the graphics subsystem about what the buffer will be used for.
252 * @param GrAccessPattern hint to the graphics subsystem about how the data will be accessed.
253 * @param flags see Flags enum.
cdalton1bf3e712016-04-19 10:00:02 -0700254 * @param data optional data with which to initialize the buffer.
cdaltone2e71c22016-04-07 18:13:29 -0700255 *
256 * @return the buffer if successful, otherwise nullptr.
257 */
Greg Daniel2e967df2021-02-08 10:38:31 -0500258 sk_sp<GrGpuBuffer> createBuffer(size_t size,
259 GrGpuBufferType intendedType,
260 GrAccessPattern,
Brian Salomondbf70722019-02-07 11:31:24 -0500261 const void* data = nullptr);
robertphillips1b8e1b52015-06-24 06:54:10 -0700262
Brian Salomon2ee084e2016-12-16 18:59:19 -0500263 /**
Chris Daltoneffee202019-07-01 22:28:03 -0600264 * If passed in render target already has a stencil buffer with at least "numSamples" samples,
265 * return true. Otherwise attempt to attach one and return true on success.
egdanielec00d942015-09-14 12:56:10 -0700266 */
Chris Daltoneffee202019-07-01 22:28:03 -0600267 bool attachStencilAttachment(GrRenderTarget* rt, int numStencilSamples);
egdanielec00d942015-09-14 12:56:10 -0700268
Greg Daniel5d0330e2020-10-12 16:05:21 -0400269 sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
270 const GrBackendFormat& format,
271 int sampleCnt,
272 GrProtected isProtected);
273
Brian Osman32342f02017-03-04 08:12:46 -0500274 /**
275 * Assigns a unique key to a resource. If the key is associated with another resource that
276 * association is removed and replaced by this resource.
277 */
278 void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*);
279
Greg Daniel301015c2019-11-18 14:06:46 -0500280 std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned = true);
Greg Daniela5cb7812017-06-16 09:45:32 -0400281
Greg Daniel17b7c052018-01-09 13:55:33 -0500282 enum class SemaphoreWrapType {
283 kWillSignal,
284 kWillWait,
285 };
286
Greg Daniel301015c2019-11-18 14:06:46 -0500287 std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&,
288 SemaphoreWrapType wrapType,
289 GrWrapOwnership = kBorrow_GrWrapOwnership);
Greg Danield85f97d2017-03-07 13:37:21 -0500290
Brian Osman32342f02017-03-04 08:12:46 -0500291 void abandon() {
Robert Phillips26c90e02017-03-14 14:39:29 -0400292 fCache = nullptr;
293 fGpu = nullptr;
Brian Osman32342f02017-03-04 08:12:46 -0500294 }
295
Brian Salomon238069b2018-07-11 15:58:57 -0400296 uint32_t contextUniqueID() const { return fCache->contextUniqueID(); }
Robert Phillips26c90e02017-03-14 14:39:29 -0400297 const GrCaps* caps() const { return fCaps.get(); }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500298 bool overBudget() const { return fCache->overBudget(); }
Robert Phillips26c90e02017-03-14 14:39:29 -0400299
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400300 static SkISize MakeApprox(SkISize);
Robert Phillipsf9fcf7f2019-07-11 09:03:27 -0400301
Greg Daniel8982dc12018-01-05 12:56:15 -0500302 inline GrResourceProviderPriv priv();
John Stilesec9b4aa2020-08-07 13:05:14 -0400303 inline const GrResourceProviderPriv priv() const; // NOLINT(readability-const-return-type)
Greg Daniel8982dc12018-01-05 12:56:15 -0500304
bsalomoned0bcad2015-05-04 10:36:42 -0700305private:
Brian Salomond28a79d2017-10-16 13:01:07 -0400306 sk_sp<GrGpuResource> findResourceByUniqueKey(const GrUniqueKey&);
Robert Phillips3798c862017-03-27 11:08:16 -0400307
Brian Salomona56a7462020-02-07 14:17:25 -0500308 // Attempts to find a resource in the cache that exactly matches the SkISize. Failing that
Greg Daniel29bf84f2017-09-25 12:25:12 -0400309 // it returns null. If non-null, the resulting texture is always budgeted.
Brian Salomona56a7462020-02-07 14:17:25 -0500310 sk_sp<GrTexture> refScratchTexture(SkISize dimensions,
Brian Salomon14cb4132019-09-16 13:14:47 -0400311 const GrBackendFormat&,
312 GrRenderable,
Brian Salomon4eb38b72019-08-05 12:58:39 -0400313 int renderTargetSampleCnt,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400314 GrMipmapped,
Brian Salomon14cb4132019-09-16 13:14:47 -0400315 GrProtected);
Brian Osman32342f02017-03-04 08:12:46 -0500316
Robert Phillips45fdae12017-04-17 12:57:27 -0400317 /*
318 * Try to find an existing scratch texture that exactly matches 'desc'. If successful
319 * update the budgeting accordingly.
320 */
Brian Salomona56a7462020-02-07 14:17:25 -0500321 sk_sp<GrTexture> getExactScratch(SkISize dimensions,
Brian Salomon14cb4132019-09-16 13:14:47 -0400322 const GrBackendFormat&,
323 GrRenderable,
Brian Salomon4eb38b72019-08-05 12:58:39 -0400324 int renderTargetSampleCnt,
Brian Salomon14cb4132019-09-16 13:14:47 -0400325 SkBudgeted,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400326 GrMipmapped,
Brian Salomon14cb4132019-09-16 13:14:47 -0400327 GrProtected);
Robert Phillips45fdae12017-04-17 12:57:27 -0400328
Greg Daniel5d0330e2020-10-12 16:05:21 -0400329 // Attempts to find a resource in the cache that exactly matches the SkISize. Failing that
330 // it returns null. If non-null, the resulting msaa attachment is always budgeted.
331 sk_sp<GrAttachment> refScratchMSAAAttachment(SkISize dimensions,
332 const GrBackendFormat&,
333 int sampleCnt,
334 GrProtected);
335
Brian Salomon8660eb02019-09-20 13:04:13 -0400336 // Used to perform any conversions necessary to texel data before creating a texture with
337 // existing data or uploading to a scratch texture.
338 using TempLevels = SkAutoSTMalloc<14, GrMipLevel>;
339 using TempLevelDatas = SkAutoSTArray<14, std::unique_ptr<char[]>>;
340 GrColorType prepareLevels(const GrBackendFormat& format,
341 GrColorType,
Brian Salomona56a7462020-02-07 14:17:25 -0500342 SkISize baseSize,
Brian Salomon8660eb02019-09-20 13:04:13 -0400343 const GrMipLevel texels[],
344 int mipLevelCount,
345 TempLevels*,
346 TempLevelDatas*) const;
347
348 // GrResourceProvider may be asked to "create" a new texture with initial pixel data to populate
349 // it. In implementation it may pull an existing texture from GrResourceCache and then write the
350 // pixel data to the texture. It takes a width/height for the base level because we may be
351 // using an approximate-sized scratch texture. On success the texture is returned and nullptr
352 // on failure.
353 sk_sp<GrTexture> writePixels(sk_sp<GrTexture> texture,
354 GrColorType colorType,
Brian Salomona56a7462020-02-07 14:17:25 -0500355 SkISize baseSize,
Brian Salomon8660eb02019-09-20 13:04:13 -0400356 const GrMipLevel texels[],
357 int mipLevelCount) const;
358
Brian Osman32342f02017-03-04 08:12:46 -0500359 GrResourceCache* cache() { return fCache; }
360 const GrResourceCache* cache() const { return fCache; }
361
Greg Daniel8982dc12018-01-05 12:56:15 -0500362 friend class GrResourceProviderPriv;
363
364 // Method made available via GrResourceProviderPriv
Brian Osman32342f02017-03-04 08:12:46 -0500365 GrGpu* gpu() { return fGpu; }
366 const GrGpu* gpu() const { return fGpu; }
367
368 bool isAbandoned() const {
369 SkASSERT(SkToBool(fGpu) == SkToBool(fCache));
370 return !SkToBool(fCache);
371 }
372
Brian Salomondbf70722019-02-07 11:31:24 -0500373 sk_sp<const GrGpuBuffer> createPatternedIndexBuffer(const uint16_t* pattern,
374 int patternSize,
375 int reps,
376 int vertCount,
Brian Salomona29dd9d2019-02-07 13:27:18 -0500377 const GrUniqueKey* key);
bsalomoned0bcad2015-05-04 10:36:42 -0700378
Robert Phillipsee08d522019-10-28 16:34:44 -0400379 sk_sp<const GrGpuBuffer> createNonAAQuadIndexBuffer();
380 sk_sp<const GrGpuBuffer> createAAQuadIndexBuffer();
bsalomoned0bcad2015-05-04 10:36:42 -0700381
Brian Salomona29dd9d2019-02-07 13:27:18 -0500382 GrResourceCache* fCache;
383 GrGpu* fGpu;
Robert Phillips26c90e02017-03-14 14:39:29 -0400384 sk_sp<const GrCaps> fCaps;
Robert Phillipsee08d522019-10-28 16:34:44 -0400385 sk_sp<const GrGpuBuffer> fNonAAQuadIndexBuffer;
386 sk_sp<const GrGpuBuffer> fAAQuadIndexBuffer;
bsalomoned0bcad2015-05-04 10:36:42 -0700387
Brian Osman32342f02017-03-04 08:12:46 -0500388 // In debug builds we guard against improper thread handling
389 SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;)
bsalomond309e7a2015-04-30 14:18:54 -0700390};
391
bsalomond309e7a2015-04-30 14:18:54 -0700392#endif