blob: 5764310aa3ea4b52bbb8eb6a4a50d7b40dfaf0fe [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
Brian Osmana5842bc2021-05-11 13:41:46 -040011#include "include/core/SkSpan.h"
Robert Phillips80bfda82020-11-12 09:23:36 -050012#include "include/core/SkSurface.h"
Robert Phillips4e105e22020-07-16 09:18:50 -040013#include "include/gpu/GrDirectContext.h"
Robert Phillipscc44feb2021-07-06 12:21:37 -040014#include "src/gpu/BaseDevice.h"
Robert Phillipsea3489a2021-08-02 13:10:57 -040015#include "src/gpu/GrRecordingContextPriv.h"
robertphillips4fd74ae2016-08-03 14:26:53 -070016
Robert Phillipse19babf2020-04-06 13:57:30 -040017class GrAtlasManager;
Greg Daniel4065d452018-11-16 15:43:41 -050018class GrBackendFormat;
Greg Danielbcf612b2017-05-01 13:50:58 +000019class GrBackendRenderTarget;
Robert Phillips33bf2b52021-08-02 11:14:38 -040020class GrImageInfo;
Herb Derbye32e1ab2020-10-27 10:29:46 -040021class GrMemoryPool;
Brian Salomond17f6582017-07-19 18:28:58 -040022class GrOnFlushCallbackObject;
Robert Phillipse19babf2020-04-06 13:57:30 -040023class GrRenderTargetProxy;
Greg Danield85f97d2017-03-07 13:37:21 -050024class GrSemaphore;
Robert Phillipse2f7d182016-12-15 09:23:05 -050025class GrSurfaceProxy;
26
Robert Phillips62000362018-02-01 09:10:04 -050027class SkDeferredDisplayList;
Robert Phillipsbc429442019-02-20 08:26:03 -050028class SkTaskGroup;
Robert Phillips62000362018-02-01 09:10:04 -050029
Adlai Hollera0693042020-10-14 11:23:11 -040030/** Class that adds methods to GrDirectContext that are only intended for use internal to Skia.
31 This class is purely a privileged window into GrDirectContext. It should never have additional
robertphillips4fd74ae2016-08-03 14:26:53 -070032 data members or virtual methods. */
Robert Phillipsea3489a2021-08-02 13:10:57 -040033class GrDirectContextPriv : public GrRecordingContextPriv {
robertphillips4fd74ae2016-08-03 14:26:53 -070034public:
Robert Phillipsea3489a2021-08-02 13:10:57 -040035 GrDirectContext* context() { return static_cast<GrDirectContext*>(fContext); }
36 const GrDirectContext* context() const { return static_cast<const GrDirectContext*>(fContext); }
Robert Phillips4217ea72019-01-30 13:08:28 -050037
Robert Phillipsea3489a2021-08-02 13:10:57 -040038 GrStrikeCache* getGrStrikeCache() { return this->context()->fStrikeCache.get(); }
Robert Phillips4217ea72019-01-30 13:08:28 -050039
Robert Phillipse42edcc2017-12-13 11:50:22 -050040 /**
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040041 * Finalizes all pending reads and writes to the surfaces and also performs an MSAA resolves
42 * if necessary. The GrSurfaceProxy array is treated as a hint. If it is supplied the context
43 * will guarantee that the draws required for those proxies are flushed but it could do more.
44 * If no array is provided then all current work will be flushed.
Robert Phillips7ee385e2017-03-30 08:02:11 -040045 *
46 * It is not necessary to call this before reading the render target via Skia/GrContext.
47 * GrContext will detect when it must perform a resolve before reading pixels back from the
48 * surface or using it as a texture.
49 */
Robert Phillips80bfda82020-11-12 09:23:36 -050050 GrSemaphoresSubmitted flushSurfaces(
51 SkSpan<GrSurfaceProxy*>,
52 SkSurface::BackendSurfaceAccess = SkSurface::BackendSurfaceAccess::kNoAccess,
53 const GrFlushInfo& = {},
54 const GrBackendSurfaceMutableState* newState = nullptr);
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040055
Robert Phillips80bfda82020-11-12 09:23:36 -050056 /** Version of above that flushes for a single proxy. Null is allowed. */
57 GrSemaphoresSubmitted flushSurface(
58 GrSurfaceProxy* proxy,
59 SkSurface::BackendSurfaceAccess access = SkSurface::BackendSurfaceAccess::kNoAccess,
60 const GrFlushInfo& info = {},
61 const GrBackendSurfaceMutableState* newState = nullptr) {
62 size_t size = proxy ? 1 : 0;
63 return this->flushSurfaces({&proxy, size}, access, info, newState);
64 }
Robert Phillips7ee385e2017-03-30 08:02:11 -040065
Greg Daniel6eb8c242019-06-05 10:22:24 -040066 /**
67 * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words,
68 * did we find a pair of round-trip preserving conversion effects?
69 */
70 bool validPMUPMConversionExists();
Robert Phillipse78b7252017-04-06 07:59:41 -040071
72 /**
Brian Osman4c886ee2021-07-07 13:34:50 -040073 * These functions create premul <-> unpremul effects, using specialized round-trip effects.
Robert Phillipse78b7252017-04-06 07:59:41 -040074 */
Greg Daniel6eb8c242019-06-05 10:22:24 -040075 std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>);
76 std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>);
Robert Phillipse78b7252017-04-06 07:59:41 -040077
Robert Phillipsea3489a2021-08-02 13:10:57 -040078 SkTaskGroup* getTaskGroup() { return this->context()->fTaskGroup.get(); }
Brian Osman51279982017-08-23 10:12:00 -040079
Robert Phillipsea3489a2021-08-02 13:10:57 -040080 GrResourceProvider* resourceProvider() { return this->context()->fResourceProvider.get(); }
81 const GrResourceProvider* resourceProvider() const {
82 return this->context()->fResourceProvider.get();
83 }
Robert Phillips6be756b2018-01-16 15:07:54 -050084
Robert Phillipsea3489a2021-08-02 13:10:57 -040085 GrResourceCache* getResourceCache() { return this->context()->fResourceCache.get(); }
Robert Phillips6be756b2018-01-16 15:07:54 -050086
Robert Phillipsea3489a2021-08-02 13:10:57 -040087 GrGpu* getGpu() { return this->context()->fGpu.get(); }
88 const GrGpu* getGpu() const { return this->context()->fGpu.get(); }
Robert Phillipsf35fd8d2018-01-22 10:48:15 -050089
Robert Phillipsc4039ea2018-03-01 11:36:45 -050090 // This accessor should only ever be called by the GrOpFlushState.
Robert Phillips5a66efb2018-03-07 15:13:18 -050091 GrAtlasManager* getAtlasManager() {
Robert Phillipsea3489a2021-08-02 13:10:57 -040092 return this->context()->onGetAtlasManager();
Robert Phillipsc4039ea2018-03-01 11:36:45 -050093 }
Robert Phillipsf35fd8d2018-01-22 10:48:15 -050094
Robert Phillips5edf5102020-08-10 16:30:36 -040095 // This accessor should only ever be called by the GrOpFlushState.
Robert Phillipsde60d7a2021-09-13 17:17:45 -040096 skgpu::v1::SmallPathAtlasMgr* getSmallPathAtlasMgr() {
Robert Phillipsea3489a2021-08-02 13:10:57 -040097 return this->context()->onGetSmallPathAtlasMgr();
Robert Phillips5edf5102020-08-10 16:30:36 -040098 }
99
Robert Phillipseb54bb52021-01-08 17:20:18 -0500100 void createDDLTask(sk_sp<const SkDeferredDisplayList>,
101 sk_sp<GrRenderTargetProxy> newDest,
Robert Phillips88b29612020-11-16 15:15:08 -0500102 SkIPoint offset);
Robert Phillips62000362018-02-01 09:10:04 -0500103
Robert Phillips43e7e4f2020-05-06 13:34:45 -0400104 bool compile(const GrProgramDesc&, const GrProgramInfo&);
Robert Phillips979b2232020-02-20 10:47:29 -0500105
Robert Phillipsea3489a2021-08-02 13:10:57 -0400106 GrContextOptions::PersistentCache* getPersistentCache() {
107 return this->context()->fPersistentCache;
Brian Osman5e7fbfd2019-05-03 13:13:35 -0400108 }
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500109
Brian Salomon9241a6d2019-10-03 13:26:54 -0400110 GrClientMappedBufferManager* clientMappedBufferManager() {
Robert Phillipsea3489a2021-08-02 13:10:57 -0400111 return this->context()->fMappedBufferManager.get();
Brian Salomon9241a6d2019-10-03 13:26:54 -0400112 }
113
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500114#if GR_TEST_UTILS
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500115 /** Reset GPU stats */
Robert Phillips273f1072020-05-05 13:03:07 -0400116 void resetGpuStats() const;
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500117
118 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */
119 void dumpCacheStats(SkString*) const;
120 void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
121 void printCacheStats() const;
122
123 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */
124 void dumpGpuStats(SkString*) const;
125 void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
126 void printGpuStats() const;
127
Robert Phillips273f1072020-05-05 13:03:07 -0400128 /** These are only active if GR_GPU_STATS == 1. */
Robert Phillipsea3489a2021-08-02 13:10:57 -0400129 void resetContextStats();
Robert Phillips273f1072020-05-05 13:03:07 -0400130 void dumpContextStats(SkString*) const;
131 void dumpContextStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
132 void printContextStats() const;
133
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500134 /** Get pointer to atlas texture for given mask format. Note that this wraps an
135 actively mutating texture in an SkImage. This could yield unexpected results
136 if it gets cached or used more generally. */
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500137 sk_sp<SkImage> testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index = 0);
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500138
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500139 void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*);
140#endif
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500141
robertphillips4fd74ae2016-08-03 14:26:53 -0700142private:
Robert Phillipsea3489a2021-08-02 13:10:57 -0400143 explicit GrDirectContextPriv(GrDirectContext* dContext) : GrRecordingContextPriv(dContext) {}
Adlai Hollera0693042020-10-14 11:23:11 -0400144 GrDirectContextPriv(const GrDirectContextPriv&) = delete;
145 GrDirectContextPriv& operator=(const GrDirectContextPriv&) = delete;
robertphillips4fd74ae2016-08-03 14:26:53 -0700146
147 // No taking addresses of this type.
Adlai Hollera0693042020-10-14 11:23:11 -0400148 const GrDirectContextPriv* operator&() const;
149 GrDirectContextPriv* operator&();
robertphillips4fd74ae2016-08-03 14:26:53 -0700150
Adlai Holler53cf44c2020-10-13 17:40:21 -0400151 friend class GrDirectContext; // to construct/copy this type.
Robert Phillipsea3489a2021-08-02 13:10:57 -0400152
153 using INHERITED = GrRecordingContextPriv;
robertphillips4fd74ae2016-08-03 14:26:53 -0700154};
155
Adlai Hollera0693042020-10-14 11:23:11 -0400156inline GrDirectContextPriv GrDirectContext::priv() { return GrDirectContextPriv(this); }
robertphillips4fd74ae2016-08-03 14:26:53 -0700157
Adlai Hollera0693042020-10-14 11:23:11 -0400158// NOLINTNEXTLINE(readability-const-return-type)
159inline const GrDirectContextPriv GrDirectContext::priv() const {
160 return GrDirectContextPriv(const_cast<GrDirectContext*>(this));
robertphillips4fd74ae2016-08-03 14:26:53 -0700161}
162
163#endif