blob: ab22bafac1e30d264452d07f57f7de796f16169c [file] [log] [blame]
robertphillips4fd74ae2016-08-03 14:26:53 -07001/*
2 * Copyright 2016 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 GrContextPriv_DEFINED
9#define GrContextPriv_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrContext.h"
12#include "src/gpu/GrSurfaceContext.h"
13#include "src/gpu/text/GrAtlasManager.h"
robertphillips4fd74ae2016-08-03 14:26:53 -070014
Greg Daniel4065d452018-11-16 15:43:41 -050015class GrBackendFormat;
Greg Danielbcf612b2017-05-01 13:50:58 +000016class GrBackendRenderTarget;
Robert Phillipsc994a932018-06-19 13:09:54 -040017class GrOpMemoryPool;
Brian Salomond17f6582017-07-19 18:28:58 -040018class GrOnFlushCallbackObject;
Greg Danield85f97d2017-03-07 13:37:21 -050019class GrSemaphore;
Robert Phillipse2f7d182016-12-15 09:23:05 -050020class GrSurfaceProxy;
21
Robert Phillips62000362018-02-01 09:10:04 -050022class SkDeferredDisplayList;
Robert Phillipsbc429442019-02-20 08:26:03 -050023class SkTaskGroup;
Robert Phillips62000362018-02-01 09:10:04 -050024
robertphillips4fd74ae2016-08-03 14:26:53 -070025/** Class that adds methods to GrContext that are only intended for use internal to Skia.
26 This class is purely a privileged window into GrContext. It should never have additional
27 data members or virtual methods. */
28class GrContextPriv {
29public:
Robert Phillips4217ea72019-01-30 13:08:28 -050030
31 // from GrContext_Base
Robert Phillipsfd0d9702019-02-01 10:19:42 -050032 uint32_t contextID() const { return fContext->contextID(); }
Robert Phillips4217ea72019-01-30 13:08:28 -050033
Robert Phillipsfe0963c2019-02-07 13:25:07 -050034 bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); }
35
Robert Phillipsc1541ae2019-02-04 12:05:37 -050036 const GrContextOptions& options() const { return fContext->options(); }
37
Robert Phillipsbb606772019-02-04 17:50:57 -050038 const GrCaps* caps() const { return fContext->caps(); }
Robert Phillipsa41c6852019-02-07 10:44:10 -050039 sk_sp<const GrCaps> refCaps() const;
Robert Phillipsbb606772019-02-04 17:50:57 -050040
Robert Phillipsa41c6852019-02-07 10:44:10 -050041 GrImageContext* asImageContext() { return fContext->asImageContext(); }
42 GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); }
43 GrContext* asDirectContext() { return fContext->asDirectContext(); }
44
Robert Phillips4217ea72019-01-30 13:08:28 -050045 // from GrImageContext
Robert Phillipsa41c6852019-02-07 10:44:10 -050046 GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); }
47 const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); }
48
Robert Phillips6a6de562019-02-15 15:19:15 -050049 bool abandoned() const { return fContext->abandoned(); }
50
Robert Phillipsa41c6852019-02-07 10:44:10 -050051 /** This is only useful for debug purposes */
52 SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
Robert Phillips4217ea72019-01-30 13:08:28 -050053
54 // from GrRecordingContext
Robert Phillips6f0e02f2019-02-13 11:02:28 -050055 GrDrawingManager* drawingManager() { return fContext->drawingManager(); }
Michael Ludwig2c316bd2019-12-19 14:50:44 -050056 GrOpMemoryPool* opMemoryPool() { return fContext->arenas().opMemoryPool(); }
57 SkArenaAlloc* recordTimeAllocator() { return fContext->arenas().recordTimeAllocator(); }
Robert Phillipsd6841482019-02-08 10:29:20 -050058
Herb Derbya00da612019-03-04 17:10:01 -050059 GrStrikeCache* getGrStrikeCache() { return fContext->getGrStrikeCache(); }
Robert Phillips2184fb72019-02-21 16:11:41 -050060 GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); }
61
Robert Phillipsc5058a62019-02-15 12:52:59 -050062 /**
63 * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
64 *
65 * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
66 * ensure its lifetime is tied to that of the context.
67 */
68 void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
69
Robert Phillipsb97da532019-02-12 15:24:12 -050070 /*
71 * Create a new render target context backed by a deferred-style
72 * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for
73 * renderTargetContexts created via this entry point.
74 */
Brian Salomonbf6b9792019-08-21 09:38:10 -040075 std::unique_ptr<GrRenderTargetContext> makeDeferredRenderTargetContext(
Brian Salomond6287472019-06-24 15:50:07 -040076 SkBackingFit fit,
77 int width,
78 int height,
Brian Salomond6287472019-06-24 15:50:07 -040079 GrColorType,
80 sk_sp<SkColorSpace> colorSpace,
81 int sampleCnt = 1,
82 GrMipMapped = GrMipMapped::kNo,
83 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
84 const SkSurfaceProps* surfaceProps = nullptr,
85 SkBudgeted = SkBudgeted::kYes,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040086 GrProtected isProtected = GrProtected::kNo);
Robert Phillipsb97da532019-02-12 15:24:12 -050087
Robert Phillips6f0e02f2019-02-13 11:02:28 -050088 /*
89 * This method will attempt to create a renderTargetContext that has, at least, the number of
90 * channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be
91 * converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA).
92 * SRGB-ness will be preserved.
93 */
Brian Salomonbf6b9792019-08-21 09:38:10 -040094 std::unique_ptr<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback(
Brian Salomond6287472019-06-24 15:50:07 -040095 SkBackingFit fit,
96 int width,
97 int height,
Brian Salomond6287472019-06-24 15:50:07 -040098 GrColorType,
99 sk_sp<SkColorSpace> colorSpace,
100 int sampleCnt = 1,
101 GrMipMapped = GrMipMapped::kNo,
102 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
103 const SkSurfaceProps* surfaceProps = nullptr,
Brian Osmanc2486592019-09-20 13:32:51 -0400104 SkBudgeted budgeted = SkBudgeted::kYes,
105 GrProtected isProtected = GrProtected::kNo);
Robert Phillips6f0e02f2019-02-13 11:02:28 -0500106
Robert Phillipsd6841482019-02-08 10:29:20 -0500107 GrAuditTrail* auditTrail() { return fContext->auditTrail(); }
Robert Phillips4217ea72019-01-30 13:08:28 -0500108
Robert Phillipse42edcc2017-12-13 11:50:22 -0500109 /**
110 * Create a GrContext without a resource cache
111 */
Kevin Lubickb5502b22018-03-12 10:17:06 -0400112 static sk_sp<GrContext> MakeDDL(const sk_sp<GrContextThreadSafeProxy>&);
Robert Phillipse42edcc2017-12-13 11:50:22 -0500113
Greg Daniel8ce79912019-02-05 10:08:43 -0500114 // These match the definitions in SkSurface & GrSurface.h, for whence they came
115 typedef void* ReleaseContext;
116 typedef void (*ReleaseProc)(ReleaseContext);
117
Brian Salomonbf6b9792019-08-21 09:38:10 -0400118 std::unique_ptr<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
Brian Salomond6287472019-06-24 15:50:07 -0400119 const GrBackendTexture& tex,
120 GrSurfaceOrigin origin,
121 int sampleCnt,
122 GrColorType,
123 sk_sp<SkColorSpace> colorSpace,
124 const SkSurfaceProps* = nullptr,
125 ReleaseProc = nullptr,
126 ReleaseContext = nullptr);
robertphillips4fd74ae2016-08-03 14:26:53 -0700127
Brian Salomonbf6b9792019-08-21 09:38:10 -0400128 std::unique_ptr<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext(
Brian Salomond6287472019-06-24 15:50:07 -0400129 const GrBackendRenderTarget&,
130 GrSurfaceOrigin origin,
131 GrColorType,
132 sk_sp<SkColorSpace> colorSpace,
133 const SkSurfaceProps* = nullptr,
134 ReleaseProc = nullptr,
135 ReleaseContext = nullptr);
robertphillips4fd74ae2016-08-03 14:26:53 -0700136
Brian Salomonbf6b9792019-08-21 09:38:10 -0400137 std::unique_ptr<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext(
Brian Salomond6287472019-06-24 15:50:07 -0400138 const GrBackendTexture& tex,
139 GrSurfaceOrigin origin,
140 int sampleCnt,
141 GrColorType,
142 sk_sp<SkColorSpace> colorSpace,
143 const SkSurfaceProps* = nullptr);
robertphillips4fd74ae2016-08-03 14:26:53 -0700144
Brian Salomonbf6b9792019-08-21 09:38:10 -0400145 std::unique_ptr<GrRenderTargetContext> makeVulkanSecondaryCBRenderTargetContext(
Greg Danielb46add82019-01-02 14:51:29 -0500146 const SkImageInfo&, const GrVkDrawableInfo&, const SkSurfaceProps* = nullptr);
147
Robert Phillips7ee385e2017-03-30 08:02:11 -0400148 /**
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400149 * Finalizes all pending reads and writes to the surfaces and also performs an MSAA resolves
150 * if necessary. The GrSurfaceProxy array is treated as a hint. If it is supplied the context
151 * will guarantee that the draws required for those proxies are flushed but it could do more.
152 * If no array is provided then all current work will be flushed.
Robert Phillips7ee385e2017-03-30 08:02:11 -0400153 *
154 * It is not necessary to call this before reading the render target via Skia/GrContext.
155 * GrContext will detect when it must perform a resolve before reading pixels back from the
156 * surface or using it as a texture.
157 */
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400158 GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy*[], int numProxies, const GrFlushInfo&);
159
160 /** Version of above that flushes for a single proxy and uses a default GrFlushInfo. Null is
161 * allowed. */
Greg Daniel4aa13e72019-04-15 14:42:20 -0400162 void flushSurface(GrSurfaceProxy*);
Robert Phillips7ee385e2017-03-30 08:02:11 -0400163
Greg Daniel6eb8c242019-06-05 10:22:24 -0400164 /**
165 * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words,
166 * did we find a pair of round-trip preserving conversion effects?
167 */
168 bool validPMUPMConversionExists();
Robert Phillipse78b7252017-04-06 07:59:41 -0400169
170 /**
Greg Daniel6eb8c242019-06-05 10:22:24 -0400171 * These functions create premul <-> unpremul effects, using the specialized round-trip effects
172 * from GrConfigConversionEffect.
Robert Phillipse78b7252017-04-06 07:59:41 -0400173 */
Greg Daniel6eb8c242019-06-05 10:22:24 -0400174 std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>);
175 std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>);
Robert Phillipse78b7252017-04-06 07:59:41 -0400176
Brian Osman51279982017-08-23 10:12:00 -0400177 SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); }
178
Robert Phillips6be756b2018-01-16 15:07:54 -0500179 GrResourceProvider* resourceProvider() { return fContext->fResourceProvider; }
180 const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider; }
181
182 GrResourceCache* getResourceCache() { return fContext->fResourceCache; }
183
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500184 GrGpu* getGpu() { return fContext->fGpu.get(); }
185 const GrGpu* getGpu() const { return fContext->fGpu.get(); }
186
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500187 // This accessor should only ever be called by the GrOpFlushState.
Robert Phillips5a66efb2018-03-07 15:13:18 -0500188 GrAtlasManager* getAtlasManager() {
189 return fContext->onGetAtlasManager();
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500190 }
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500191
Chris Dalton6b498102019-08-01 14:14:52 -0600192 void moveRenderTasksToDDL(SkDeferredDisplayList*);
193 void copyRenderTasksFromDDL(const SkDeferredDisplayList*, GrRenderTargetProxy* newDest);
Robert Phillips62000362018-02-01 09:10:04 -0500194
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500195 GrContextOptions::PersistentCache* getPersistentCache() { return fContext->fPersistentCache; }
Brian Osman5e7fbfd2019-05-03 13:13:35 -0400196 GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const {
197 return fContext->fShaderErrorHandler;
198 }
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500199
Brian Salomon9241a6d2019-10-03 13:26:54 -0400200 GrClientMappedBufferManager* clientMappedBufferManager() {
201 return fContext->fMappedBufferManager.get();
202 }
203
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500204#if GR_TEST_UTILS
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500205 /** Reset GPU stats */
206 void resetGpuStats() const ;
207
208 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */
209 void dumpCacheStats(SkString*) const;
210 void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
211 void printCacheStats() const;
212
213 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */
214 void dumpGpuStats(SkString*) const;
215 void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
216 void printGpuStats() const;
217
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500218 /** Specify the TextBlob cache limit. If the current cache exceeds this limit it will purge.
219 this is for testing only */
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500220 void testingOnly_setTextBlobCacheLimit(size_t bytes);
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500221
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500222 /** Get pointer to atlas texture for given mask format. Note that this wraps an
223 actively mutating texture in an SkImage. This could yield unexpected results
224 if it gets cached or used more generally. */
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500225 sk_sp<SkImage> testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index = 0);
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500226
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500227 /**
228 * Purge all the unlocked resources from the cache.
229 * This entry point is mainly meant for timing texture uploads
230 * and is not defined in normal builds of Skia.
231 */
232 void testingOnly_purgeAllUnlockedResources();
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500233
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500234 void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*);
235#endif
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500236
robertphillips4fd74ae2016-08-03 14:26:53 -0700237private:
238 explicit GrContextPriv(GrContext* context) : fContext(context) {}
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400239 GrContextPriv(const GrContextPriv&); // unimpl
robertphillips4fd74ae2016-08-03 14:26:53 -0700240 GrContextPriv& operator=(const GrContextPriv&); // unimpl
241
242 // No taking addresses of this type.
243 const GrContextPriv* operator&() const;
244 GrContextPriv* operator&();
245
246 GrContext* fContext;
247
248 friend class GrContext; // to construct/copy this type.
249};
250
Robert Phillips9da87e02019-02-04 13:26:26 -0500251inline GrContextPriv GrContext::priv() { return GrContextPriv(this); }
robertphillips4fd74ae2016-08-03 14:26:53 -0700252
Robert Phillips9da87e02019-02-04 13:26:26 -0500253inline const GrContextPriv GrContext::priv() const {
robertphillips4fd74ae2016-08-03 14:26:53 -0700254 return GrContextPriv(const_cast<GrContext*>(this));
255}
256
257#endif