robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 1 | /* |
| 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 Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 8 | #ifndef GrDirectContextPriv_DEFINED |
| 9 | #define GrDirectContextPriv_DEFINED |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 10 | |
Brian Osman | a5842bc | 2021-05-11 13:41:46 -0400 | [diff] [blame] | 11 | #include "include/core/SkSpan.h" |
Robert Phillips | 80bfda8 | 2020-11-12 09:23:36 -0500 | [diff] [blame] | 12 | #include "include/core/SkSurface.h" |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 13 | #include "include/gpu/GrDirectContext.h" |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 14 | #include "src/gpu/BaseDevice.h" |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrRecordingContextPriv.h" |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 16 | |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 17 | class GrAtlasManager; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 18 | class GrBackendFormat; |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 19 | class GrBackendRenderTarget; |
Robert Phillips | 33bf2b5 | 2021-08-02 11:14:38 -0400 | [diff] [blame] | 20 | class GrImageInfo; |
Herb Derby | e32e1ab | 2020-10-27 10:29:46 -0400 | [diff] [blame] | 21 | class GrMemoryPool; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 22 | class GrOnFlushCallbackObject; |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 23 | class GrRenderTargetProxy; |
Greg Daniel | d85f97d | 2017-03-07 13:37:21 -0500 | [diff] [blame] | 24 | class GrSemaphore; |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 25 | class GrSurfaceProxy; |
| 26 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 27 | class SkDeferredDisplayList; |
Robert Phillips | bc42944 | 2019-02-20 08:26:03 -0500 | [diff] [blame] | 28 | class SkTaskGroup; |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 29 | |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 30 | /** 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 |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 32 | data members or virtual methods. */ |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 33 | class GrDirectContextPriv : public GrRecordingContextPriv { |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 34 | public: |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 35 | GrDirectContext* context() { return static_cast<GrDirectContext*>(fContext); } |
| 36 | const GrDirectContext* context() const { return static_cast<const GrDirectContext*>(fContext); } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 37 | |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 38 | GrStrikeCache* getGrStrikeCache() { return this->context()->fStrikeCache.get(); } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 39 | |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 40 | /** |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 41 | * 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 Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 45 | * |
| 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 Phillips | 80bfda8 | 2020-11-12 09:23:36 -0500 | [diff] [blame] | 50 | GrSemaphoresSubmitted flushSurfaces( |
| 51 | SkSpan<GrSurfaceProxy*>, |
| 52 | SkSurface::BackendSurfaceAccess = SkSurface::BackendSurfaceAccess::kNoAccess, |
| 53 | const GrFlushInfo& = {}, |
| 54 | const GrBackendSurfaceMutableState* newState = nullptr); |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 55 | |
Robert Phillips | 80bfda8 | 2020-11-12 09:23:36 -0500 | [diff] [blame] | 56 | /** 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 Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 65 | |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 66 | /** |
| 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 Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 71 | |
| 72 | /** |
Brian Osman | 4c886ee | 2021-07-07 13:34:50 -0400 | [diff] [blame] | 73 | * These functions create premul <-> unpremul effects, using specialized round-trip effects. |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 74 | */ |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 75 | std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>); |
| 76 | std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 77 | |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 78 | SkTaskGroup* getTaskGroup() { return this->context()->fTaskGroup.get(); } |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 79 | |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 80 | GrResourceProvider* resourceProvider() { return this->context()->fResourceProvider.get(); } |
| 81 | const GrResourceProvider* resourceProvider() const { |
| 82 | return this->context()->fResourceProvider.get(); |
| 83 | } |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 84 | |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 85 | GrResourceCache* getResourceCache() { return this->context()->fResourceCache.get(); } |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 86 | |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 87 | GrGpu* getGpu() { return this->context()->fGpu.get(); } |
| 88 | const GrGpu* getGpu() const { return this->context()->fGpu.get(); } |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 89 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 90 | // This accessor should only ever be called by the GrOpFlushState. |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 91 | GrAtlasManager* getAtlasManager() { |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 92 | return this->context()->onGetAtlasManager(); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 93 | } |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 94 | |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 95 | // This accessor should only ever be called by the GrOpFlushState. |
Robert Phillips | de60d7a | 2021-09-13 17:17:45 -0400 | [diff] [blame] | 96 | skgpu::v1::SmallPathAtlasMgr* getSmallPathAtlasMgr() { |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 97 | return this->context()->onGetSmallPathAtlasMgr(); |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Robert Phillips | eb54bb5 | 2021-01-08 17:20:18 -0500 | [diff] [blame] | 100 | void createDDLTask(sk_sp<const SkDeferredDisplayList>, |
| 101 | sk_sp<GrRenderTargetProxy> newDest, |
Robert Phillips | 88b2961 | 2020-11-16 15:15:08 -0500 | [diff] [blame] | 102 | SkIPoint offset); |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 103 | |
Robert Phillips | 43e7e4f | 2020-05-06 13:34:45 -0400 | [diff] [blame] | 104 | bool compile(const GrProgramDesc&, const GrProgramInfo&); |
Robert Phillips | 979b223 | 2020-02-20 10:47:29 -0500 | [diff] [blame] | 105 | |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 106 | GrContextOptions::PersistentCache* getPersistentCache() { |
| 107 | return this->context()->fPersistentCache; |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 108 | } |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 109 | |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 110 | GrClientMappedBufferManager* clientMappedBufferManager() { |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 111 | return this->context()->fMappedBufferManager.get(); |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 112 | } |
| 113 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 114 | #if GR_TEST_UTILS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 115 | /** Reset GPU stats */ |
Robert Phillips | 273f107 | 2020-05-05 13:03:07 -0400 | [diff] [blame] | 116 | void resetGpuStats() const; |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 117 | |
| 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 Phillips | 273f107 | 2020-05-05 13:03:07 -0400 | [diff] [blame] | 128 | /** These are only active if GR_GPU_STATS == 1. */ |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 129 | void resetContextStats(); |
Robert Phillips | 273f107 | 2020-05-05 13:03:07 -0400 | [diff] [blame] | 130 | void dumpContextStats(SkString*) const; |
| 131 | void dumpContextStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
| 132 | void printContextStats() const; |
| 133 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 134 | /** 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 Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 137 | sk_sp<SkImage> testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index = 0); |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 138 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 139 | void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*); |
| 140 | #endif |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 141 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 142 | private: |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 143 | explicit GrDirectContextPriv(GrDirectContext* dContext) : GrRecordingContextPriv(dContext) {} |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 144 | GrDirectContextPriv(const GrDirectContextPriv&) = delete; |
| 145 | GrDirectContextPriv& operator=(const GrDirectContextPriv&) = delete; |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 146 | |
| 147 | // No taking addresses of this type. |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 148 | const GrDirectContextPriv* operator&() const; |
| 149 | GrDirectContextPriv* operator&(); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 150 | |
Adlai Holler | 53cf44c | 2020-10-13 17:40:21 -0400 | [diff] [blame] | 151 | friend class GrDirectContext; // to construct/copy this type. |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 152 | |
| 153 | using INHERITED = GrRecordingContextPriv; |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 156 | inline GrDirectContextPriv GrDirectContext::priv() { return GrDirectContextPriv(this); } |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 157 | |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 158 | // NOLINTNEXTLINE(readability-const-return-type) |
| 159 | inline const GrDirectContextPriv GrDirectContext::priv() const { |
| 160 | return GrDirectContextPriv(const_cast<GrDirectContext*>(this)); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | #endif |