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 | |
Herb Derby | dc214c2 | 2018-11-08 13:31:39 -0500 | [diff] [blame] | 11 | #include "GrDeferredUpload.h" |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 12 | #include "GrPathRenderer.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 13 | #include "GrPathRendererChain.h" |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 14 | #include "GrResourceCache.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 15 | #include "SkTArray.h" |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 16 | #include "text/GrTextContext.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 17 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 18 | class GrContext; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 19 | class GrCoverageCountingPathRenderer; |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 20 | class GrOnFlushCallbackObject; |
Herb Derby | dc214c2 | 2018-11-08 13:31:39 -0500 | [diff] [blame] | 21 | class GrOpFlushState; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 22 | class GrRenderTargetContext; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 23 | class GrRenderTargetProxy; |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 24 | class GrSingleOWner; |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 25 | class GrRenderTargetOpList; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 26 | class GrSoftwarePathRenderer; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 27 | class GrTextureContext; |
| 28 | class GrTextureOpList; |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 29 | class SkDeferredDisplayList; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 30 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 31 | // The GrDrawingManager allocates a new GrRenderTargetContext for each GrRenderTarget |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 32 | // but all of them still land in the same GrOpList! |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 33 | // |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 34 | // In the future this class will allocate a new GrRenderTargetContext for |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 35 | // each GrRenderTarget/GrOpList and manage the DAG. |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 36 | class GrDrawingManager { |
| 37 | public: |
| 38 | ~GrDrawingManager(); |
| 39 | |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 40 | bool wasAbandoned() const { return fAbandoned; } |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 41 | void freeGpuResources(); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 42 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 43 | sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 44 | sk_sp<SkColorSpace>, |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 45 | const SkSurfaceProps*, |
| 46 | bool managedOpList = true); |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 47 | sk_sp<GrTextureContext> makeTextureContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 48 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 49 | // The caller automatically gets a ref on the returned opList. It must |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 50 | // be balanced by an unref call. |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 51 | // A managed opList is controlled by the drawing manager (i.e., sorted & flushed with the |
| 52 | // other). An unmanaged one is created and used by the onFlushCallback. |
| 53 | sk_sp<GrRenderTargetOpList> newRTOpList(GrRenderTargetProxy* rtp, bool managedOpList); |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 54 | sk_sp<GrTextureOpList> newTextureOpList(GrTextureProxy* textureProxy); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 55 | |
| 56 | GrContext* getContext() { return fContext; } |
| 57 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 58 | GrTextContext* getTextContext(); |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 59 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 60 | GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
| 61 | bool allowSW, |
| 62 | GrPathRendererChain::DrawType drawType, |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 63 | GrPathRenderer::StencilSupport* stencilSupport = nullptr); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 64 | |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 65 | GrPathRenderer* getSoftwarePathRenderer(); |
| 66 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 67 | // Returns a direct pointer to the coverage counting path renderer, or null if it is not |
| 68 | // supported and turned on. |
| 69 | GrCoverageCountingPathRenderer* getCoverageCountingPathRenderer(); |
| 70 | |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 71 | void flushIfNecessary(); |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 72 | |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 73 | static bool ProgramUnitTest(GrContext* context, int maxStages, int maxLevels); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 74 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 75 | GrSemaphoresSubmitted prepareSurfaceForExternalIO(GrSurfaceProxy*, |
| 76 | int numSemaphores, |
| 77 | GrBackendSemaphore backendSemaphores[]); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 78 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 79 | void addOnFlushCallbackObject(GrOnFlushCallbackObject*); |
| 80 | void testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject*); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 81 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 82 | void moveOpListsToDDL(SkDeferredDisplayList* ddl); |
| 83 | void copyOpListsFromDDL(const SkDeferredDisplayList*, GrRenderTargetProxy* newDest); |
| 84 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 85 | private: |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 86 | // This class encapsulates maintenance and manipulation of the drawing manager's DAG of opLists. |
| 87 | class OpListDAG { |
| 88 | public: |
| 89 | OpListDAG(bool explicitlyAllocating, GrContextOptions::Enable sortOpLists); |
| 90 | ~OpListDAG(); |
| 91 | |
| 92 | // Currently, when explicitly allocating resources, this call will topologically sort the |
| 93 | // opLists. |
| 94 | // MDB TODO: remove once incremental opList sorting is enabled |
| 95 | void prepForFlush(); |
| 96 | |
| 97 | void closeAll(const GrCaps* caps); |
| 98 | |
| 99 | // A yucky combination of closeAll and reset |
| 100 | void cleanup(const GrCaps* caps); |
| 101 | |
| 102 | void gatherIDs(SkSTArray<8, uint32_t, true>* idArray) const; |
| 103 | |
| 104 | void reset(); |
| 105 | |
| 106 | // These calls forceably remove an opList from the DAG. They are problematic bc they just |
| 107 | // remove the opList but don't cleanup any refering pointers (i.e., dependency pointers |
| 108 | // in the DAG). They work right now bc they are only called at flush time, after the |
| 109 | // topological sort is complete (so the dangling pointers aren't used). |
| 110 | void removeOpList(int index); |
| 111 | void removeOpLists(int startIndex, int stopIndex); |
| 112 | |
| 113 | bool empty() const { return fOpLists.empty(); } |
| 114 | int numOpLists() const { return fOpLists.count(); } |
| 115 | |
| 116 | GrOpList* opList(int index) { return fOpLists[index].get(); } |
| 117 | const GrOpList* opList(int index) const { return fOpLists[index].get(); } |
| 118 | |
| 119 | GrOpList* back() { return fOpLists.back().get(); } |
| 120 | const GrOpList* back() const { return fOpLists.back().get(); } |
| 121 | |
| 122 | void add(sk_sp<GrOpList>); |
| 123 | void add(const SkTArray<sk_sp<GrOpList>>&); |
| 124 | |
| 125 | void swap(SkTArray<sk_sp<GrOpList>>* opLists); |
| 126 | |
Robert Phillips | 46acf9d | 2018-10-09 09:31:40 -0400 | [diff] [blame] | 127 | bool sortingOpLists() const { return fSortOpLists; } |
| 128 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 129 | private: |
| 130 | SkTArray<sk_sp<GrOpList>> fOpLists; |
| 131 | bool fSortOpLists; |
| 132 | }; |
| 133 | |
Robert Phillips | a3f7026 | 2018-02-08 10:59:38 -0500 | [diff] [blame] | 134 | GrDrawingManager(GrContext*, const GrPathRendererChain::Options&, |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 135 | const GrTextContext::Options&, GrSingleOwner*, |
Robert Phillips | 46acf9d | 2018-10-09 09:31:40 -0400 | [diff] [blame] | 136 | bool explicitlyAllocating, GrContextOptions::Enable sortRenderTargets, |
| 137 | GrContextOptions::Enable reduceOpListSplitting); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 138 | |
| 139 | void abandon(); |
| 140 | void cleanup(); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 141 | |
| 142 | // return true if any opLists were actually executed; false otherwise |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 143 | bool executeOpLists(int startIndex, int stopIndex, GrOpFlushState*, int* numOpListsExecuted); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 144 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 145 | GrSemaphoresSubmitted flush(GrSurfaceProxy* proxy, |
| 146 | int numSemaphores = 0, |
Brian Salomon | 57d2bea | 2018-09-10 09:35:41 -0400 | [diff] [blame] | 147 | GrBackendSemaphore backendSemaphores[] = nullptr); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 148 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 149 | SkDEBUGCODE(void validate() const); |
| 150 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 151 | friend class GrContext; // for access to: ctor, abandon, reset & flush |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 152 | friend class GrContextPriv; // access to: flush |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 153 | friend class GrOnFlushResourceProvider; // this is just a shallow wrapper around this class |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 154 | |
| 155 | static const int kNumPixelGeometries = 5; // The different pixel geometries |
| 156 | static const int kNumDFTOptions = 2; // DFT or no DFT |
| 157 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 158 | GrContext* fContext; |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 159 | GrPathRendererChain::Options fOptionsForPathRendererChain; |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 160 | GrTextContext::Options fOptionsForTextContext; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 161 | |
Brian Salomon | 58f153c | 2018-10-18 21:51:15 -0400 | [diff] [blame] | 162 | std::unique_ptr<char[]> fVertexBufferSpace; |
| 163 | std::unique_ptr<char[]> fIndexBufferSpace; |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 164 | // In debug builds we guard against improper thread handling |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 165 | GrSingleOwner* fSingleOwner; |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 166 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 167 | bool fAbandoned; |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 168 | OpListDAG fDAG; |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 169 | GrOpList* fActiveOpList = nullptr; |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 170 | // These are the IDs of the opLists currently being flushed (in internalFlush) |
| 171 | SkSTArray<8, uint32_t, true> fFlushingOpListIDs; |
| 172 | // These are the new opLists generated by the onFlush CBs |
| 173 | SkSTArray<8, sk_sp<GrOpList>> fOnFlushCBOpLists; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 174 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 175 | std::unique_ptr<GrTextContext> fTextContext; |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 176 | |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 177 | std::unique_ptr<GrPathRendererChain> fPathRendererChain; |
| 178 | sk_sp<GrSoftwarePathRenderer> fSoftwarePathRenderer; |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 179 | |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 180 | GrTokenTracker fTokenTracker; |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 181 | bool fFlushing; |
Robert Phillips | 46acf9d | 2018-10-09 09:31:40 -0400 | [diff] [blame] | 182 | bool fReduceOpListSplitting; |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 183 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 184 | SkTArray<GrOnFlushCallbackObject*> fOnFlushCBObjects; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | #endif |