blob: 119df845b7a392aa2fd35976cef9d682f075ccc4 [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
Adlai Hollera0693042020-10-14 11:23:11 -04008#ifndef GrDirectContextPriv_DEFINED
9#define GrDirectContextPriv_DEFINED
robertphillips4fd74ae2016-08-03 14:26:53 -070010
Robert Phillips4e105e22020-07-16 09:18:50 -040011#include "include/gpu/GrDirectContext.h"
Adlai Hollerc2bfcff2020-11-06 15:39:36 -050012#include "src/core/SkSpan.h"
robertphillips4fd74ae2016-08-03 14:26:53 -070013
Robert Phillipse19babf2020-04-06 13:57:30 -040014class GrAtlasManager;
Greg Daniel4065d452018-11-16 15:43:41 -050015class GrBackendFormat;
Greg Danielbcf612b2017-05-01 13:50:58 +000016class GrBackendRenderTarget;
Herb Derbye32e1ab2020-10-27 10:29:46 -040017class GrMemoryPool;
Brian Salomond17f6582017-07-19 18:28:58 -040018class GrOnFlushCallbackObject;
Robert Phillipse19babf2020-04-06 13:57:30 -040019class GrRenderTargetProxy;
Greg Danield85f97d2017-03-07 13:37:21 -050020class GrSemaphore;
Robert Phillipse2f7d182016-12-15 09:23:05 -050021class GrSurfaceProxy;
22
Robert Phillips62000362018-02-01 09:10:04 -050023class SkDeferredDisplayList;
Robert Phillipsbc429442019-02-20 08:26:03 -050024class SkTaskGroup;
Robert Phillips62000362018-02-01 09:10:04 -050025
Adlai Hollera0693042020-10-14 11:23:11 -040026/** Class that adds methods to GrDirectContext that are only intended for use internal to Skia.
27 This class is purely a privileged window into GrDirectContext. It should never have additional
robertphillips4fd74ae2016-08-03 14:26:53 -070028 data members or virtual methods. */
Adlai Hollera0693042020-10-14 11:23:11 -040029class GrDirectContextPriv {
robertphillips4fd74ae2016-08-03 14:26:53 -070030public:
Robert Phillips4217ea72019-01-30 13:08:28 -050031
32 // from GrContext_Base
Robert Phillipsfd0d9702019-02-01 10:19:42 -050033 uint32_t contextID() const { return fContext->contextID(); }
Robert Phillips4217ea72019-01-30 13:08:28 -050034
Robert Phillipsfe0963c2019-02-07 13:25:07 -050035 bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); }
36
Robert Phillipsc1541ae2019-02-04 12:05:37 -050037 const GrContextOptions& options() const { return fContext->options(); }
38
Robert Phillipsbb606772019-02-04 17:50:57 -050039 const GrCaps* caps() const { return fContext->caps(); }
Robert Phillipsa41c6852019-02-07 10:44:10 -050040 sk_sp<const GrCaps> refCaps() const;
Robert Phillipsbb606772019-02-04 17:50:57 -050041
Robert Phillipsa41c6852019-02-07 10:44:10 -050042 GrImageContext* asImageContext() { return fContext->asImageContext(); }
43 GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); }
Robert Phillipsa41c6852019-02-07 10:44:10 -050044
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
49 /** This is only useful for debug purposes */
50 SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
Robert Phillips4217ea72019-01-30 13:08:28 -050051
52 // from GrRecordingContext
Robert Phillips6f0e02f2019-02-13 11:02:28 -050053 GrDrawingManager* drawingManager() { return fContext->drawingManager(); }
Michael Ludwig28b0c5d2019-12-19 14:51:00 -050054
Herb Derbye32e1ab2020-10-27 10:29:46 -040055 GrMemoryPool* opMemoryPool() { return fContext->arenas().opMemoryPool(); }
Michael Ludwig2c316bd2019-12-19 14:50:44 -050056 SkArenaAlloc* recordTimeAllocator() { return fContext->arenas().recordTimeAllocator(); }
Michael Ludwig28b0c5d2019-12-19 14:51:00 -050057 GrRecordingContext::Arenas arenas() { return fContext->arenas(); }
Robert Phillipsd6841482019-02-08 10:29:20 -050058
Robert Phillips4d932d12020-04-09 08:58:52 -040059 GrStrikeCache* getGrStrikeCache() { return fContext->fStrikeCache.get(); }
Robert Phillips2184fb72019-02-21 16:11:41 -050060 GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); }
61
Robert Phillipsd464feb2020-10-08 11:00:02 -040062 GrThreadSafeCache* threadSafeCache() { return fContext->threadSafeCache(); }
Robert Phillips12d06a32020-09-16 12:31:34 -040063
Robert Phillipsc5058a62019-02-15 12:52:59 -050064 /**
65 * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
66 *
67 * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
68 * ensure its lifetime is tied to that of the context.
69 */
70 void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
71
Robert Phillipsd6841482019-02-08 10:29:20 -050072 GrAuditTrail* auditTrail() { return fContext->auditTrail(); }
Robert Phillips4217ea72019-01-30 13:08:28 -050073
Robert Phillipse42edcc2017-12-13 11:50:22 -050074 /**
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040075 * Finalizes all pending reads and writes to the surfaces and also performs an MSAA resolves
76 * if necessary. The GrSurfaceProxy array is treated as a hint. If it is supplied the context
77 * will guarantee that the draws required for those proxies are flushed but it could do more.
78 * If no array is provided then all current work will be flushed.
Robert Phillips7ee385e2017-03-30 08:02:11 -040079 *
80 * It is not necessary to call this before reading the render target via Skia/GrContext.
81 * GrContext will detect when it must perform a resolve before reading pixels back from the
82 * surface or using it as a texture.
83 */
Adlai Hollerc2bfcff2020-11-06 15:39:36 -050084 GrSemaphoresSubmitted flushSurfaces(SkSpan<GrSurfaceProxy*>, const GrFlushInfo&);
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040085
Greg Daniel55f040b2020-02-13 15:38:32 +000086 /** Version of above that flushes for a single proxy and uses a default GrFlushInfo. Null is
87 * allowed. */
88 void flushSurface(GrSurfaceProxy*);
Robert Phillips7ee385e2017-03-30 08:02:11 -040089
Greg Daniel6eb8c242019-06-05 10:22:24 -040090 /**
91 * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words,
92 * did we find a pair of round-trip preserving conversion effects?
93 */
94 bool validPMUPMConversionExists();
Robert Phillipse78b7252017-04-06 07:59:41 -040095
96 /**
Greg Daniel6eb8c242019-06-05 10:22:24 -040097 * These functions create premul <-> unpremul effects, using the specialized round-trip effects
98 * from GrConfigConversionEffect.
Robert Phillipse78b7252017-04-06 07:59:41 -040099 */
Greg Daniel6eb8c242019-06-05 10:22:24 -0400100 std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>);
101 std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>);
Robert Phillipse78b7252017-04-06 07:59:41 -0400102
Brian Osman51279982017-08-23 10:12:00 -0400103 SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); }
104
Adlai Holler9555f292020-10-09 09:41:14 -0400105 GrResourceProvider* resourceProvider() { return fContext->fResourceProvider.get(); }
106 const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider.get(); }
Robert Phillips6be756b2018-01-16 15:07:54 -0500107
Adlai Holler9555f292020-10-09 09:41:14 -0400108 GrResourceCache* getResourceCache() { return fContext->fResourceCache.get(); }
Robert Phillips6be756b2018-01-16 15:07:54 -0500109
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500110 GrGpu* getGpu() { return fContext->fGpu.get(); }
111 const GrGpu* getGpu() const { return fContext->fGpu.get(); }
112
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500113 // This accessor should only ever be called by the GrOpFlushState.
Robert Phillips5a66efb2018-03-07 15:13:18 -0500114 GrAtlasManager* getAtlasManager() {
115 return fContext->onGetAtlasManager();
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500116 }
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500117
Robert Phillips5edf5102020-08-10 16:30:36 -0400118 // This accessor should only ever be called by the GrOpFlushState.
119 GrSmallPathAtlasMgr* getSmallPathAtlasMgr() {
120 return fContext->onGetSmallPathAtlasMgr();
121 }
122
Robert Phillipsa0e248d2020-11-11 09:39:27 -0500123 void copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList>, GrRenderTargetProxy* newDest);
Robert Phillips62000362018-02-01 09:10:04 -0500124
Robert Phillips43e7e4f2020-05-06 13:34:45 -0400125 bool compile(const GrProgramDesc&, const GrProgramInfo&);
Robert Phillips979b2232020-02-20 10:47:29 -0500126
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500127 GrContextOptions::PersistentCache* getPersistentCache() { return fContext->fPersistentCache; }
Brian Osman5e7fbfd2019-05-03 13:13:35 -0400128 GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const {
129 return fContext->fShaderErrorHandler;
130 }
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500131
Brian Salomon9241a6d2019-10-03 13:26:54 -0400132 GrClientMappedBufferManager* clientMappedBufferManager() {
133 return fContext->fMappedBufferManager.get();
134 }
135
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500136#if GR_TEST_UTILS
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500137 /** Reset GPU stats */
Robert Phillips273f1072020-05-05 13:03:07 -0400138 void resetGpuStats() const;
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500139
140 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */
141 void dumpCacheStats(SkString*) const;
142 void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
143 void printCacheStats() const;
144
145 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */
146 void dumpGpuStats(SkString*) const;
147 void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
148 void printGpuStats() const;
149
Robert Phillips273f1072020-05-05 13:03:07 -0400150 /** These are only active if GR_GPU_STATS == 1. */
151 void resetContextStats() const;
152 void dumpContextStats(SkString*) const;
153 void dumpContextStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
154 void printContextStats() const;
155
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500156 /** Get pointer to atlas texture for given mask format. Note that this wraps an
157 actively mutating texture in an SkImage. This could yield unexpected results
158 if it gets cached or used more generally. */
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500159 sk_sp<SkImage> testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index = 0);
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500160
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500161 /**
162 * Purge all the unlocked resources from the cache.
163 * This entry point is mainly meant for timing texture uploads
164 * and is not defined in normal builds of Skia.
165 */
166 void testingOnly_purgeAllUnlockedResources();
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500167
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500168 void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*);
169#endif
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500170
robertphillips4fd74ae2016-08-03 14:26:53 -0700171private:
Adlai Hollera0693042020-10-14 11:23:11 -0400172 explicit GrDirectContextPriv(GrDirectContext* context) : fContext(context) {}
173 GrDirectContextPriv(const GrDirectContextPriv&) = delete;
174 GrDirectContextPriv& operator=(const GrDirectContextPriv&) = delete;
robertphillips4fd74ae2016-08-03 14:26:53 -0700175
176 // No taking addresses of this type.
Adlai Hollera0693042020-10-14 11:23:11 -0400177 const GrDirectContextPriv* operator&() const;
178 GrDirectContextPriv* operator&();
robertphillips4fd74ae2016-08-03 14:26:53 -0700179
Adlai Holler53cf44c2020-10-13 17:40:21 -0400180 GrDirectContext* fContext;
robertphillips4fd74ae2016-08-03 14:26:53 -0700181
Adlai Holler53cf44c2020-10-13 17:40:21 -0400182 friend class GrDirectContext; // to construct/copy this type.
robertphillips4fd74ae2016-08-03 14:26:53 -0700183};
184
Adlai Hollera0693042020-10-14 11:23:11 -0400185inline GrDirectContextPriv GrDirectContext::priv() { return GrDirectContextPriv(this); }
robertphillips4fd74ae2016-08-03 14:26:53 -0700186
Adlai Hollera0693042020-10-14 11:23:11 -0400187// NOLINTNEXTLINE(readability-const-return-type)
188inline const GrDirectContextPriv GrDirectContext::priv() const {
189 return GrDirectContextPriv(const_cast<GrDirectContext*>(this));
robertphillips4fd74ae2016-08-03 14:26:53 -0700190}
191
192#endif