blob: 3ac7be295fa982a927f8d81bea38c8f42a7c8d2d [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
Robert Phillips4e105e22020-07-16 09:18:50 -040011#include "include/gpu/GrDirectContext.h"
robertphillips4fd74ae2016-08-03 14:26:53 -070012
Robert Phillipse19babf2020-04-06 13:57:30 -040013class GrAtlasManager;
Greg Daniel4065d452018-11-16 15:43:41 -050014class GrBackendFormat;
Greg Danielbcf612b2017-05-01 13:50:58 +000015class GrBackendRenderTarget;
Robert Phillipsc994a932018-06-19 13:09:54 -040016class GrOpMemoryPool;
Brian Salomond17f6582017-07-19 18:28:58 -040017class GrOnFlushCallbackObject;
Robert Phillipse19babf2020-04-06 13:57:30 -040018class GrRenderTargetProxy;
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(); }
Robert Phillipsa41c6852019-02-07 10:44:10 -050043
Robert Phillips4217ea72019-01-30 13:08:28 -050044 // from GrImageContext
Robert Phillipsa41c6852019-02-07 10:44:10 -050045 GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); }
46 const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); }
47
48 /** This is only useful for debug purposes */
49 SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
Robert Phillips4217ea72019-01-30 13:08:28 -050050
51 // from GrRecordingContext
Robert Phillips6f0e02f2019-02-13 11:02:28 -050052 GrDrawingManager* drawingManager() { return fContext->drawingManager(); }
Michael Ludwig28b0c5d2019-12-19 14:51:00 -050053
Michael Ludwig2c316bd2019-12-19 14:50:44 -050054 GrOpMemoryPool* opMemoryPool() { return fContext->arenas().opMemoryPool(); }
55 SkArenaAlloc* recordTimeAllocator() { return fContext->arenas().recordTimeAllocator(); }
Michael Ludwig28b0c5d2019-12-19 14:51:00 -050056 GrRecordingContext::Arenas arenas() { return fContext->arenas(); }
Robert Phillipsd6841482019-02-08 10:29:20 -050057
Robert Phillips4d932d12020-04-09 08:58:52 -040058 GrStrikeCache* getGrStrikeCache() { return fContext->fStrikeCache.get(); }
Robert Phillips2184fb72019-02-21 16:11:41 -050059 GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); }
60
Robert Phillips12d06a32020-09-16 12:31:34 -040061 GrThreadSafeUniquelyKeyedProxyViewCache* threadSafeViewCache() {
62 return fContext->threadSafeViewCache();
63 }
64
Robert Phillipsc5058a62019-02-15 12:52:59 -050065 /**
66 * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
67 *
68 * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
69 * ensure its lifetime is tied to that of the context.
70 */
71 void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
72
Robert Phillipsd6841482019-02-08 10:29:20 -050073 GrAuditTrail* auditTrail() { return fContext->auditTrail(); }
Robert Phillips4217ea72019-01-30 13:08:28 -050074
Robert Phillipse42edcc2017-12-13 11:50:22 -050075 /**
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040076 * Finalizes all pending reads and writes to the surfaces and also performs an MSAA resolves
77 * if necessary. The GrSurfaceProxy array is treated as a hint. If it is supplied the context
78 * will guarantee that the draws required for those proxies are flushed but it could do more.
79 * If no array is provided then all current work will be flushed.
Robert Phillips7ee385e2017-03-30 08:02:11 -040080 *
81 * It is not necessary to call this before reading the render target via Skia/GrContext.
82 * GrContext will detect when it must perform a resolve before reading pixels back from the
83 * surface or using it as a texture.
84 */
Greg Daniel55f040b2020-02-13 15:38:32 +000085 GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy*[], int numProxies, const GrFlushInfo&);
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040086
Greg Daniel55f040b2020-02-13 15:38:32 +000087 /** Version of above that flushes for a single proxy and uses a default GrFlushInfo. Null is
88 * allowed. */
89 void flushSurface(GrSurfaceProxy*);
Robert Phillips7ee385e2017-03-30 08:02:11 -040090
Greg Daniel6eb8c242019-06-05 10:22:24 -040091 /**
92 * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words,
93 * did we find a pair of round-trip preserving conversion effects?
94 */
95 bool validPMUPMConversionExists();
Robert Phillipse78b7252017-04-06 07:59:41 -040096
97 /**
Greg Daniel6eb8c242019-06-05 10:22:24 -040098 * These functions create premul <-> unpremul effects, using the specialized round-trip effects
99 * from GrConfigConversionEffect.
Robert Phillipse78b7252017-04-06 07:59:41 -0400100 */
Greg Daniel6eb8c242019-06-05 10:22:24 -0400101 std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>);
102 std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>);
Robert Phillipse78b7252017-04-06 07:59:41 -0400103
Brian Osman51279982017-08-23 10:12:00 -0400104 SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); }
105
Robert Phillips6be756b2018-01-16 15:07:54 -0500106 GrResourceProvider* resourceProvider() { return fContext->fResourceProvider; }
107 const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider; }
108
109 GrResourceCache* getResourceCache() { return fContext->fResourceCache; }
110
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500111 GrGpu* getGpu() { return fContext->fGpu.get(); }
112 const GrGpu* getGpu() const { return fContext->fGpu.get(); }
113
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500114 // This accessor should only ever be called by the GrOpFlushState.
Robert Phillips5a66efb2018-03-07 15:13:18 -0500115 GrAtlasManager* getAtlasManager() {
116 return fContext->onGetAtlasManager();
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500117 }
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500118
Robert Phillips5edf5102020-08-10 16:30:36 -0400119 // This accessor should only ever be called by the GrOpFlushState.
120 GrSmallPathAtlasMgr* getSmallPathAtlasMgr() {
121 return fContext->onGetSmallPathAtlasMgr();
122 }
123
Adlai Holler7580ad42020-06-24 13:45:25 -0400124 void copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList>, GrRenderTargetProxy* newDest);
Robert Phillips62000362018-02-01 09:10:04 -0500125
Robert Phillips43e7e4f2020-05-06 13:34:45 -0400126 bool compile(const GrProgramDesc&, const GrProgramInfo&);
Robert Phillips979b2232020-02-20 10:47:29 -0500127
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500128 GrContextOptions::PersistentCache* getPersistentCache() { return fContext->fPersistentCache; }
Brian Osman5e7fbfd2019-05-03 13:13:35 -0400129 GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const {
130 return fContext->fShaderErrorHandler;
131 }
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500132
Brian Salomon9241a6d2019-10-03 13:26:54 -0400133 GrClientMappedBufferManager* clientMappedBufferManager() {
134 return fContext->fMappedBufferManager.get();
135 }
136
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500137#if GR_TEST_UTILS
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500138 /** Reset GPU stats */
Robert Phillips273f1072020-05-05 13:03:07 -0400139 void resetGpuStats() const;
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500140
141 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */
142 void dumpCacheStats(SkString*) const;
143 void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
144 void printCacheStats() const;
145
146 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */
147 void dumpGpuStats(SkString*) const;
148 void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
149 void printGpuStats() const;
150
Robert Phillips273f1072020-05-05 13:03:07 -0400151 /** These are only active if GR_GPU_STATS == 1. */
152 void resetContextStats() const;
153 void dumpContextStats(SkString*) const;
154 void dumpContextStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
155 void printContextStats() const;
156
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500157 /** Get pointer to atlas texture for given mask format. Note that this wraps an
158 actively mutating texture in an SkImage. This could yield unexpected results
159 if it gets cached or used more generally. */
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500160 sk_sp<SkImage> testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index = 0);
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500161
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500162 /**
163 * Purge all the unlocked resources from the cache.
164 * This entry point is mainly meant for timing texture uploads
165 * and is not defined in normal builds of Skia.
166 */
167 void testingOnly_purgeAllUnlockedResources();
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500168
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500169 void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*);
170#endif
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500171
robertphillips4fd74ae2016-08-03 14:26:53 -0700172private:
173 explicit GrContextPriv(GrContext* context) : fContext(context) {}
John Stilesb35c3b82020-08-06 19:58:52 -0400174 GrContextPriv(const GrContextPriv&) = delete;
175 GrContextPriv& operator=(const GrContextPriv&) = delete;
robertphillips4fd74ae2016-08-03 14:26:53 -0700176
177 // No taking addresses of this type.
178 const GrContextPriv* operator&() const;
179 GrContextPriv* operator&();
180
181 GrContext* fContext;
182
183 friend class GrContext; // to construct/copy this type.
184};
185
Robert Phillips9da87e02019-02-04 13:26:26 -0500186inline GrContextPriv GrContext::priv() { return GrContextPriv(this); }
robertphillips4fd74ae2016-08-03 14:26:53 -0700187
John Stilesec9b4aa2020-08-07 13:05:14 -0400188inline const GrContextPriv GrContext::priv() const { // NOLINT(readability-const-return-type)
robertphillips4fd74ae2016-08-03 14:26:53 -0700189 return GrContextPriv(const_cast<GrContext*>(this));
190}
191
192#endif