blob: 28201ae7beee049f4f14d3da826e354e17c8f97d [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 Ludwig28b0c5d2019-12-19 14:51:00 -050056
Michael Ludwig2c316bd2019-12-19 14:50:44 -050057 GrOpMemoryPool* opMemoryPool() { return fContext->arenas().opMemoryPool(); }
58 SkArenaAlloc* recordTimeAllocator() { return fContext->arenas().recordTimeAllocator(); }
Michael Ludwig28b0c5d2019-12-19 14:51:00 -050059 GrRecordingContext::Arenas arenas() { return fContext->arenas(); }
Robert Phillipsd6841482019-02-08 10:29:20 -050060
Herb Derbya00da612019-03-04 17:10:01 -050061 GrStrikeCache* getGrStrikeCache() { return fContext->getGrStrikeCache(); }
Robert Phillips2184fb72019-02-21 16:11:41 -050062 GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); }
63
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 /**
75 * Create a GrContext without a resource cache
76 */
Kevin Lubickb5502b22018-03-12 10:17:06 -040077 static sk_sp<GrContext> MakeDDL(const sk_sp<GrContextThreadSafeProxy>&);
Robert Phillipse42edcc2017-12-13 11:50:22 -050078
Robert Phillips7ee385e2017-03-30 08:02:11 -040079 /**
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040080 * Finalizes all pending reads and writes to the surfaces and also performs an MSAA resolves
81 * if necessary. The GrSurfaceProxy array is treated as a hint. If it is supplied the context
82 * will guarantee that the draws required for those proxies are flushed but it could do more.
83 * If no array is provided then all current work will be flushed.
Robert Phillips7ee385e2017-03-30 08:02:11 -040084 *
85 * It is not necessary to call this before reading the render target via Skia/GrContext.
86 * GrContext will detect when it must perform a resolve before reading pixels back from the
87 * surface or using it as a texture.
88 */
Greg Danielec340812020-02-12 15:27:49 -050089 GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy*[], GrSurfaceOrigin[], int numProxies,
90 const GrFlushInfo&);
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040091
Greg Danielec340812020-02-12 15:27:49 -050092 /** Version of above that flushes for a single proxy and uses a default GrFlushInfo. Null is not
93 * allowed for the proxy. */
94 void flushSurface(GrSurfaceProxy*, GrSurfaceOrigin);
95
96 void flushSurface() {
97 this->flushSurfaces(nullptr, nullptr, 0, {});
98 }
Robert Phillips7ee385e2017-03-30 08:02:11 -040099
Greg Daniel6eb8c242019-06-05 10:22:24 -0400100 /**
101 * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words,
102 * did we find a pair of round-trip preserving conversion effects?
103 */
104 bool validPMUPMConversionExists();
Robert Phillipse78b7252017-04-06 07:59:41 -0400105
106 /**
Greg Daniel6eb8c242019-06-05 10:22:24 -0400107 * These functions create premul <-> unpremul effects, using the specialized round-trip effects
108 * from GrConfigConversionEffect.
Robert Phillipse78b7252017-04-06 07:59:41 -0400109 */
Greg Daniel6eb8c242019-06-05 10:22:24 -0400110 std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>);
111 std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>);
Robert Phillipse78b7252017-04-06 07:59:41 -0400112
Brian Osman51279982017-08-23 10:12:00 -0400113 SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); }
114
Robert Phillips6be756b2018-01-16 15:07:54 -0500115 GrResourceProvider* resourceProvider() { return fContext->fResourceProvider; }
116 const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider; }
117
118 GrResourceCache* getResourceCache() { return fContext->fResourceCache; }
119
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500120 GrGpu* getGpu() { return fContext->fGpu.get(); }
121 const GrGpu* getGpu() const { return fContext->fGpu.get(); }
122
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500123 // This accessor should only ever be called by the GrOpFlushState.
Robert Phillips5a66efb2018-03-07 15:13:18 -0500124 GrAtlasManager* getAtlasManager() {
125 return fContext->onGetAtlasManager();
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500126 }
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500127
Chris Dalton6b498102019-08-01 14:14:52 -0600128 void moveRenderTasksToDDL(SkDeferredDisplayList*);
129 void copyRenderTasksFromDDL(const SkDeferredDisplayList*, GrRenderTargetProxy* newDest);
Robert Phillips62000362018-02-01 09:10:04 -0500130
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500131 GrContextOptions::PersistentCache* getPersistentCache() { return fContext->fPersistentCache; }
Brian Osman5e7fbfd2019-05-03 13:13:35 -0400132 GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const {
133 return fContext->fShaderErrorHandler;
134 }
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500135
Brian Salomon9241a6d2019-10-03 13:26:54 -0400136 GrClientMappedBufferManager* clientMappedBufferManager() {
137 return fContext->fMappedBufferManager.get();
138 }
139
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500140#if GR_TEST_UTILS
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500141 /** Reset GPU stats */
142 void resetGpuStats() const ;
143
144 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */
145 void dumpCacheStats(SkString*) const;
146 void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
147 void printCacheStats() const;
148
149 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */
150 void dumpGpuStats(SkString*) const;
151 void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
152 void printGpuStats() const;
153
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500154 /** Specify the TextBlob cache limit. If the current cache exceeds this limit it will purge.
155 this is for testing only */
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500156 void testingOnly_setTextBlobCacheLimit(size_t bytes);
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500157
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500158 /** Get pointer to atlas texture for given mask format. Note that this wraps an
159 actively mutating texture in an SkImage. This could yield unexpected results
160 if it gets cached or used more generally. */
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500161 sk_sp<SkImage> testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index = 0);
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500162
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500163 /**
164 * Purge all the unlocked resources from the cache.
165 * This entry point is mainly meant for timing texture uploads
166 * and is not defined in normal builds of Skia.
167 */
168 void testingOnly_purgeAllUnlockedResources();
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500169
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500170 void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*);
171#endif
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500172
robertphillips4fd74ae2016-08-03 14:26:53 -0700173private:
174 explicit GrContextPriv(GrContext* context) : fContext(context) {}
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400175 GrContextPriv(const GrContextPriv&); // unimpl
robertphillips4fd74ae2016-08-03 14:26:53 -0700176 GrContextPriv& operator=(const GrContextPriv&); // unimpl
177
178 // No taking addresses of this type.
179 const GrContextPriv* operator&() const;
180 GrContextPriv* operator&();
181
182 GrContext* fContext;
183
184 friend class GrContext; // to construct/copy this type.
185};
186
Robert Phillips9da87e02019-02-04 13:26:26 -0500187inline GrContextPriv GrContext::priv() { return GrContextPriv(this); }
robertphillips4fd74ae2016-08-03 14:26:53 -0700188
Robert Phillips9da87e02019-02-04 13:26:26 -0500189inline const GrContextPriv GrContext::priv() const {
robertphillips4fd74ae2016-08-03 14:26:53 -0700190 return GrContextPriv(const_cast<GrContext*>(this));
191}
192
193#endif