robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 GrDrawingManager_DEFINED |
| 9 | #define GrDrawingManager_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkSurface.h" |
| 12 | #include "include/private/SkTArray.h" |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 13 | #include "include/private/SkTHash.h" |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 14 | #include "src/core/SkSpan.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrBufferAllocPool.h" |
| 16 | #include "src/gpu/GrDeferredUpload.h" |
Robert Phillips | c7ed7e6 | 2020-06-29 20:04:57 +0000 | [diff] [blame] | 17 | #include "src/gpu/GrHashMapWithCache.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrPathRenderer.h" |
| 19 | #include "src/gpu/GrPathRendererChain.h" |
| 20 | #include "src/gpu/GrResourceCache.h" |
Herb Derby | 082232b | 2020-06-10 15:08:18 -0400 | [diff] [blame] | 21 | #include "src/gpu/GrSurfaceProxy.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 22 | |
Robert Phillips | d81379d | 2020-04-21 10:39:02 -0400 | [diff] [blame] | 23 | // Enabling this will print out which path renderers are being chosen |
| 24 | #define GR_PATH_RENDERER_SPEW 0 |
| 25 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 26 | class GrCoverageCountingPathRenderer; |
Herb Derby | 082232b | 2020-06-10 15:08:18 -0400 | [diff] [blame] | 27 | class GrGpuBuffer; |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 28 | class GrOnFlushCallbackObject; |
Herb Derby | dc214c2 | 2018-11-08 13:31:39 -0500 | [diff] [blame] | 29 | class GrOpFlushState; |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 30 | class GrOpsTask; |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 31 | class GrRecordingContext; |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 32 | class GrSurfaceDrawContext; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 33 | class GrRenderTargetProxy; |
Herb Derby | 082232b | 2020-06-10 15:08:18 -0400 | [diff] [blame] | 34 | class GrRenderTask; |
| 35 | class GrSemaphore; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 36 | class GrSoftwarePathRenderer; |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 37 | class GrSurfaceContext; |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 38 | class GrSurfaceProxyView; |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 39 | class GrTextureResolveRenderTask; |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 40 | class SkDeferredDisplayList; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 41 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 42 | class GrDrawingManager { |
| 43 | public: |
| 44 | ~GrDrawingManager(); |
| 45 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 46 | void freeGpuResources(); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 47 | |
Robert Phillips | 1900665 | 2020-11-19 14:20:57 -0500 | [diff] [blame] | 48 | // OpsTasks created at flush time are stored and handled different from the others. |
| 49 | sk_sp<GrOpsTask> newOpsTask(GrSurfaceProxyView, bool flushTimeOpsTask); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 50 | |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 51 | // Create a render task that can resolve MSAA and/or regenerate mipmap levels on proxies. This |
| 52 | // method will only add the new render task to the list. It is up to the caller to call |
| 53 | // addProxy() on the returned object. |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 54 | GrTextureResolveRenderTask* newTextureResolveRenderTask(const GrCaps&); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 55 | |
Greg Daniel | c30f1a9 | 2019-09-06 15:28:58 -0400 | [diff] [blame] | 56 | // Create a new render task that will cause the gpu to wait on semaphores before executing any |
| 57 | // more RenderTasks that target proxy. It is possible for this wait to also block additional |
| 58 | // work (even to other proxies) that has already been recorded or will be recorded later. The |
| 59 | // only guarantee is that future work to the passed in proxy will wait on the semaphores to be |
| 60 | // signaled. |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 61 | void newWaitRenderTask(sk_sp<GrSurfaceProxy> proxy, |
| 62 | std::unique_ptr<std::unique_ptr<GrSemaphore>[]>, |
Greg Daniel | c30f1a9 | 2019-09-06 15:28:58 -0400 | [diff] [blame] | 63 | int numSemaphores); |
| 64 | |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 65 | // Create a new render task which copies the pixels from the srcProxy into the dstBuffer. This |
| 66 | // is used to support the asynchronous readback API. The srcRect is the region of the srcProxy |
| 67 | // to be copied. The surfaceColorType says how we should interpret the data when reading back |
| 68 | // from the source. DstColorType describes how the data should be stored in the dstBuffer. |
| 69 | // DstOffset is the offset into the dstBuffer where we will start writing data. |
| 70 | void newTransferFromRenderTask(sk_sp<GrSurfaceProxy> srcProxy, const SkIRect& srcRect, |
| 71 | GrColorType surfaceColorType, GrColorType dstColorType, |
| 72 | sk_sp<GrGpuBuffer> dstBuffer, size_t dstOffset); |
| 73 | |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 74 | // Creates a new render task which copies a pixel rectangle from srcView into dstView. The src |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 75 | // pixels copied are specified by srcRect. They are copied to a rect of the same size in |
| 76 | // dstProxy with top left at dstPoint. If the src rect is clipped by the src bounds then pixel |
| 77 | // values in the dst rect corresponding to the area clipped by the src rect are not overwritten. |
| 78 | // This method is not guaranteed to succeed depending on the type of surface, formats, etc, and |
| 79 | // the backend-specific limitations. |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 80 | bool newCopyRenderTask(sk_sp<GrSurfaceProxy> src, |
| 81 | SkIRect srcRect, |
| 82 | sk_sp<GrSurfaceProxy> dst, |
Brian Salomon | 0f9f800 | 2021-01-22 16:30:50 -0500 | [diff] [blame] | 83 | SkIPoint dstPoint, |
| 84 | GrSurfaceOrigin); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 85 | |
Brian Salomon | be1084b | 2021-01-26 13:29:30 -0500 | [diff] [blame] | 86 | // Adds a task that writes the data from the passed GrMipLevels to dst. The lifetime of the |
| 87 | // pixel data in the levels should be tied to the passed SkData. srcColorType is the color |
| 88 | // type of the GrMipLevels. dstColorType is the color type being used with dst and must |
| 89 | // be compatible with dst's format according to GrCaps::areColorTypeAndFormatCompatible(). |
| 90 | bool newWritePixelsTask(sk_sp<GrSurfaceProxy> dst, |
| 91 | SkIRect rect, |
| 92 | GrColorType srcColorType, |
| 93 | GrColorType dstColorType, |
| 94 | const GrMipLevel[], |
| 95 | int levelCount, |
| 96 | sk_sp<SkData> storage); |
| 97 | |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 98 | GrRecordingContext* getContext() { return fContext; } |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 99 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 100 | GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
| 101 | bool allowSW, |
| 102 | GrPathRendererChain::DrawType drawType, |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 103 | GrPathRenderer::StencilSupport* stencilSupport = nullptr); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 104 | |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 105 | GrPathRenderer* getSoftwarePathRenderer(); |
| 106 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 107 | // Returns a direct pointer to the coverage counting path renderer, or null if it is not |
| 108 | // supported and turned on. |
| 109 | GrCoverageCountingPathRenderer* getCoverageCountingPathRenderer(); |
| 110 | |
Chris Dalton | e6ae476 | 2021-02-05 14:56:21 -0700 | [diff] [blame] | 111 | // Returns a direct pointer to the tessellation path renderer, or null if it is not supported |
| 112 | // and turned on. |
| 113 | GrPathRenderer* getTessellationPathRenderer(); |
| 114 | |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 115 | void flushIfNecessary(); |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 116 | |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 117 | static bool ProgramUnitTest(GrDirectContext*, int maxStages, int maxLevels); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 118 | |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 119 | GrSemaphoresSubmitted flushSurfaces(SkSpan<GrSurfaceProxy*>, |
| 120 | SkSurface::BackendSurfaceAccess, |
| 121 | const GrFlushInfo&, |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 122 | const GrBackendSurfaceMutableState* newState); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 123 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 124 | void addOnFlushCallbackObject(GrOnFlushCallbackObject*); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 125 | |
| 126 | #if GR_TEST_UTILS |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 127 | void testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject*); |
Chris Dalton | 3163428 | 2020-09-17 12:16:54 -0600 | [diff] [blame] | 128 | GrPathRendererChain::Options testingOnly_getOptionsForPathRendererChain() { |
| 129 | return fOptionsForPathRendererChain; |
| 130 | } |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 131 | #endif |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 132 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 133 | GrRenderTask* getLastRenderTask(const GrSurfaceProxy*) const; |
| 134 | GrOpsTask* getLastOpsTask(const GrSurfaceProxy*) const; |
| 135 | void setLastRenderTask(const GrSurfaceProxy*, GrRenderTask*); |
| 136 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 137 | void moveRenderTasksToDDL(SkDeferredDisplayList* ddl); |
Robert Phillips | eb54bb5 | 2021-01-08 17:20:18 -0500 | [diff] [blame] | 138 | void createDDLTask(sk_sp<const SkDeferredDisplayList>, |
| 139 | sk_sp<GrRenderTargetProxy> newDest, |
Robert Phillips | 88b2961 | 2020-11-16 15:15:08 -0500 | [diff] [blame] | 140 | SkIPoint offset); |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 141 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 142 | private: |
Herb Derby | 082232b | 2020-06-10 15:08:18 -0400 | [diff] [blame] | 143 | GrDrawingManager(GrRecordingContext*, |
| 144 | const GrPathRendererChain::Options&, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 145 | bool reduceOpsTaskSplitting); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 146 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 147 | bool wasAbandoned() const; |
| 148 | |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 149 | void closeActiveOpsTask(); |
Chris Dalton | 5fe9977 | 2019-08-06 11:57:39 -0600 | [diff] [blame] | 150 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 151 | // return true if any GrRenderTasks were actually executed; false otherwise |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 152 | bool executeRenderTasks(int startIndex, int stopIndex, GrOpFlushState*, |
| 153 | int* numRenderTasksExecuted); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 154 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 155 | void removeRenderTasks(int startIndex, int stopIndex); |
| 156 | |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 157 | void sortTasks(); |
Adlai Holler | 7803608 | 2021-01-07 11:41:33 -0500 | [diff] [blame] | 158 | void reorderTasks(); |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 159 | |
| 160 | void closeAllTasks(); |
| 161 | |
| 162 | GrRenderTask* appendTask(sk_sp<GrRenderTask>); |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 163 | GrRenderTask* insertTaskBeforeLast(sk_sp<GrRenderTask>); |
| 164 | |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 165 | bool flush(SkSpan<GrSurfaceProxy*> proxies, |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 166 | SkSurface::BackendSurfaceAccess access, |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 167 | const GrFlushInfo&, |
| 168 | const GrBackendSurfaceMutableState* newState); |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 169 | |
| 170 | bool submitToGpu(bool syncToCpu); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 171 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 172 | SkDEBUGCODE(void validate() const); |
| 173 | |
Adlai Holler | 3acc69a | 2020-10-13 08:20:51 -0400 | [diff] [blame] | 174 | friend class GrDirectContext; // access to: flush & cleanup |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 175 | friend class GrDirectContextPriv; // access to: flush |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 176 | friend class GrOnFlushResourceProvider; // this is just a shallow wrapper around this class |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 177 | friend class GrRecordingContext; // access to: ctor |
Greg Daniel | b6c15ba | 2019-03-04 13:08:25 -0500 | [diff] [blame] | 178 | friend class SkImage; // for access to: flush |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 179 | |
| 180 | static const int kNumPixelGeometries = 5; // The different pixel geometries |
| 181 | static const int kNumDFTOptions = 2; // DFT or no DFT |
| 182 | |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 183 | GrRecordingContext* fContext; |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 184 | GrPathRendererChain::Options fOptionsForPathRendererChain; |
Herb Derby | 082232b | 2020-06-10 15:08:18 -0400 | [diff] [blame] | 185 | |
Brian Salomon | 601ac80 | 2019-02-07 13:37:16 -0500 | [diff] [blame] | 186 | // This cache is used by both the vertex and index pools. It reuses memory across multiple |
| 187 | // flushes. |
| 188 | sk_sp<GrBufferAllocPool::CpuBufferCache> fCpuBufferCache; |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 189 | |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 190 | SkTArray<sk_sp<GrRenderTask>> fDAG; |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 191 | GrOpsTask* fActiveOpsTask = nullptr; |
Robert Phillips | 07f675d | 2020-11-16 13:44:01 -0500 | [diff] [blame] | 192 | // These are the IDs of the opsTask currently being flushed (in internalFlush). They are |
| 193 | // only stored here to prevent memory thrashing. |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 194 | SkSTArray<8, uint32_t, true> fFlushingRenderTaskIDs; |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 195 | // These are the new renderTasks generated by the onFlush CBs |
| 196 | SkSTArray<4, sk_sp<GrRenderTask>> fOnFlushRenderTasks; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 197 | |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 198 | std::unique_ptr<GrPathRendererChain> fPathRendererChain; |
| 199 | sk_sp<GrSoftwarePathRenderer> fSoftwarePathRenderer; |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 200 | |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 201 | GrTokenTracker fTokenTracker; |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 202 | bool fFlushing; |
Adlai Holler | 245c59a | 2020-12-30 16:20:25 +0000 | [diff] [blame] | 203 | const bool fReduceOpsTaskSplitting; |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 204 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 205 | SkTArray<GrOnFlushCallbackObject*> fOnFlushCBObjects; |
Robert Phillips | 15c9142 | 2019-05-07 16:54:48 -0400 | [diff] [blame] | 206 | |
Robert Phillips | c7ed7e6 | 2020-06-29 20:04:57 +0000 | [diff] [blame] | 207 | struct SurfaceIDKeyTraits { |
| 208 | static uint32_t GetInvalidKey() { |
| 209 | return GrSurfaceProxy::UniqueID::InvalidID().asUInt(); |
Adlai Holler | 1bdbe55 | 2020-06-12 11:28:15 -0400 | [diff] [blame] | 210 | } |
| 211 | }; |
| 212 | |
Robert Phillips | c7ed7e6 | 2020-06-29 20:04:57 +0000 | [diff] [blame] | 213 | GrHashMapWithCache<uint32_t, GrRenderTask*, SurfaceIDKeyTraits, GrCheapHash> fLastRenderTasks; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | #endif |