blob: 9d6ce28a9e8056e6bd4d0bfac9167340180909c0 [file] [log] [blame]
robertphillips77a2e522015-10-17 07:43:27 -07001/*
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
robertphillips68737822015-10-29 12:12:21 -070011#include "GrPathRenderer.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050012#include "GrPathRendererChain.h"
bsalomonb77a9072016-09-07 10:02:04 -070013#include "GrResourceCache.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040014#include "SkTArray.h"
Herb Derby26cbe512018-05-24 14:39:01 -040015#include "text/GrTextContext.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040016
robertphillips77a2e522015-10-17 07:43:27 -070017class GrContext;
Chris Daltonfddb6c02017-11-04 15:22:22 -060018class GrCoverageCountingPathRenderer;
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040019class GrOnFlushCallbackObject;
Brian Osman11052242016-10-27 14:47:55 -040020class GrRenderTargetContext;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040021class GrRenderTargetProxy;
joshualittde8dc7e2016-01-08 10:09:13 -080022class GrSingleOWner;
Brian Salomon653f42f2018-07-10 10:07:31 -040023class GrRenderTargetOpList;
robertphillips68737822015-10-29 12:12:21 -070024class GrSoftwarePathRenderer;
Brian Osman45580d32016-11-23 09:37:01 -050025class GrTextureContext;
26class GrTextureOpList;
Brian Salomon653f42f2018-07-10 10:07:31 -040027class SkDeferredDisplayList;
robertphillips77a2e522015-10-17 07:43:27 -070028
Brian Osman11052242016-10-27 14:47:55 -040029// The GrDrawingManager allocates a new GrRenderTargetContext for each GrRenderTarget
Robert Phillipsf2361d22016-10-25 14:20:06 -040030// but all of them still land in the same GrOpList!
robertphillips77a2e522015-10-17 07:43:27 -070031//
Brian Osman11052242016-10-27 14:47:55 -040032// In the future this class will allocate a new GrRenderTargetContext for
Robert Phillipsf2361d22016-10-25 14:20:06 -040033// each GrRenderTarget/GrOpList and manage the DAG.
robertphillips77a2e522015-10-17 07:43:27 -070034class GrDrawingManager {
35public:
36 ~GrDrawingManager();
37
robertphillips7761d612016-05-16 09:14:53 -070038 bool wasAbandoned() const { return fAbandoned; }
robertphillips68737822015-10-29 12:12:21 -070039 void freeGpuResources();
robertphillips77a2e522015-10-17 07:43:27 -070040
Robert Phillips37430132016-11-09 06:50:43 -050041 sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
Brian Osman11052242016-10-27 14:47:55 -040042 sk_sp<SkColorSpace>,
Robert Phillips941d1442017-06-14 16:37:02 -040043 const SkSurfaceProps*,
44 bool managedOpList = true);
Robert Phillips2c862492017-01-18 10:08:39 -050045 sk_sp<GrTextureContext> makeTextureContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>);
robertphillips77a2e522015-10-17 07:43:27 -070046
Robert Phillipsf2361d22016-10-25 14:20:06 -040047 // The caller automatically gets a ref on the returned opList. It must
robertphillips77a2e522015-10-17 07:43:27 -070048 // be balanced by an unref call.
Robert Phillips941d1442017-06-14 16:37:02 -040049 // A managed opList is controlled by the drawing manager (i.e., sorted & flushed with the
50 // other). An unmanaged one is created and used by the onFlushCallback.
51 sk_sp<GrRenderTargetOpList> newRTOpList(GrRenderTargetProxy* rtp, bool managedOpList);
Robert Phillipsb6deea82017-05-11 14:14:30 -040052 sk_sp<GrTextureOpList> newTextureOpList(GrTextureProxy* textureProxy);
robertphillips77a2e522015-10-17 07:43:27 -070053
54 GrContext* getContext() { return fContext; }
55
Herb Derby26cbe512018-05-24 14:39:01 -040056 GrTextContext* getTextContext();
brianosman86e76262016-08-11 12:17:31 -070057
robertphillips68737822015-10-29 12:12:21 -070058 GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
59 bool allowSW,
60 GrPathRendererChain::DrawType drawType,
Ben Wagnera93a14a2017-08-28 10:34:05 -040061 GrPathRenderer::StencilSupport* stencilSupport = nullptr);
robertphillips68737822015-10-29 12:12:21 -070062
Brian Salomone7df0bb2018-05-07 14:44:57 -040063 GrPathRenderer* getSoftwarePathRenderer();
64
Chris Daltonfddb6c02017-11-04 15:22:22 -060065 // Returns a direct pointer to the coverage counting path renderer, or null if it is not
66 // supported and turned on.
67 GrCoverageCountingPathRenderer* getCoverageCountingPathRenderer();
68
Brian Salomon653f42f2018-07-10 10:07:31 -040069 void flushIfNecessary();
bsalomonb77a9072016-09-07 10:02:04 -070070
Greg Daniel78325c12017-06-19 16:39:13 -040071 static bool ProgramUnitTest(GrContext* context, int maxStages, int maxLevels);
robertphillipsa13e2022015-11-11 12:01:09 -080072
Greg Daniel51316782017-08-02 15:10:09 +000073 GrSemaphoresSubmitted prepareSurfaceForExternalIO(GrSurfaceProxy*,
74 int numSemaphores,
75 GrBackendSemaphore backendSemaphores[]);
bsalomon6a2b1942016-09-08 11:28:59 -070076
Chris Daltonfe199b72017-05-05 11:26:15 -040077 void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
78 void testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject*);
Robert Phillipseb35f4d2017-03-21 07:56:47 -040079
Robert Phillips62000362018-02-01 09:10:04 -050080 void moveOpListsToDDL(SkDeferredDisplayList* ddl);
81 void copyOpListsFromDDL(const SkDeferredDisplayList*, GrRenderTargetProxy* newDest);
82
robertphillips77a2e522015-10-17 07:43:27 -070083private:
Robert Phillips22310d62018-09-05 11:07:21 -040084 // This class encapsulates maintenance and manipulation of the drawing manager's DAG of opLists.
85 class OpListDAG {
86 public:
87 OpListDAG(bool explicitlyAllocating, GrContextOptions::Enable sortOpLists);
88 ~OpListDAG();
89
90 // Currently, when explicitly allocating resources, this call will topologically sort the
91 // opLists.
92 // MDB TODO: remove once incremental opList sorting is enabled
93 void prepForFlush();
94
95 void closeAll(const GrCaps* caps);
96
97 // A yucky combination of closeAll and reset
98 void cleanup(const GrCaps* caps);
99
100 void gatherIDs(SkSTArray<8, uint32_t, true>* idArray) const;
101
102 void reset();
103
104 // These calls forceably remove an opList from the DAG. They are problematic bc they just
105 // remove the opList but don't cleanup any refering pointers (i.e., dependency pointers
106 // in the DAG). They work right now bc they are only called at flush time, after the
107 // topological sort is complete (so the dangling pointers aren't used).
108 void removeOpList(int index);
109 void removeOpLists(int startIndex, int stopIndex);
110
111 bool empty() const { return fOpLists.empty(); }
112 int numOpLists() const { return fOpLists.count(); }
113
114 GrOpList* opList(int index) { return fOpLists[index].get(); }
115 const GrOpList* opList(int index) const { return fOpLists[index].get(); }
116
117 GrOpList* back() { return fOpLists.back().get(); }
118 const GrOpList* back() const { return fOpLists.back().get(); }
119
120 void add(sk_sp<GrOpList>);
121 void add(const SkTArray<sk_sp<GrOpList>>&);
122
123 void swap(SkTArray<sk_sp<GrOpList>>* opLists);
124
125 private:
126 SkTArray<sk_sp<GrOpList>> fOpLists;
127 bool fSortOpLists;
128 };
129
Robert Phillipsa3f70262018-02-08 10:59:38 -0500130 GrDrawingManager(GrContext*, const GrPathRendererChain::Options&,
Herb Derby26cbe512018-05-24 14:39:01 -0400131 const GrTextContext::Options&, GrSingleOwner*,
Robert Phillips64ecdce2018-04-02 10:26:39 -0400132 bool explicitlyAllocating, GrContextOptions::Enable sortRenderTargets);
robertphillips77a2e522015-10-17 07:43:27 -0700133
134 void abandon();
135 void cleanup();
Robert Phillipseafd48a2017-11-16 07:52:08 -0500136
137 // return true if any opLists were actually executed; false otherwise
138 bool executeOpLists(int startIndex, int stopIndex, GrOpFlushState*);
139
Greg Daniel51316782017-08-02 15:10:09 +0000140 GrSemaphoresSubmitted flush(GrSurfaceProxy* proxy,
141 int numSemaphores = 0,
Brian Salomon57d2bea2018-09-10 09:35:41 -0400142 GrBackendSemaphore backendSemaphores[] = nullptr);
robertphillips77a2e522015-10-17 07:43:27 -0700143
Robert Phillips38d64b02018-09-04 13:23:26 -0400144 SkDEBUGCODE(void validate() const);
145
robertphillips77a2e522015-10-17 07:43:27 -0700146 friend class GrContext; // for access to: ctor, abandon, reset & flush
Robert Phillips7ee385e2017-03-30 08:02:11 -0400147 friend class GrContextPriv; // access to: flush
Chris Daltonfe199b72017-05-05 11:26:15 -0400148 friend class GrOnFlushResourceProvider; // this is just a shallow wrapper around this class
robertphillips77a2e522015-10-17 07:43:27 -0700149
150 static const int kNumPixelGeometries = 5; // The different pixel geometries
151 static const int kNumDFTOptions = 2; // DFT or no DFT
152
brianosman86e76262016-08-11 12:17:31 -0700153 GrContext* fContext;
bsalomon6b2552f2016-09-15 13:50:26 -0700154 GrPathRendererChain::Options fOptionsForPathRendererChain;
Herb Derby26cbe512018-05-24 14:39:01 -0400155 GrTextContext::Options fOptionsForTextContext;
robertphillips77a2e522015-10-17 07:43:27 -0700156
joshualittde8dc7e2016-01-08 10:09:13 -0800157 // In debug builds we guard against improper thread handling
brianosman86e76262016-08-11 12:17:31 -0700158 GrSingleOwner* fSingleOwner;
joshualittde8dc7e2016-01-08 10:09:13 -0800159
brianosman86e76262016-08-11 12:17:31 -0700160 bool fAbandoned;
Robert Phillips22310d62018-09-05 11:07:21 -0400161 OpListDAG fDAG;
Robert Phillips38d64b02018-09-04 13:23:26 -0400162 GrOpList* fActiveOpList = nullptr;
Chris Dalton3968ff92017-11-27 12:26:31 -0700163 // These are the IDs of the opLists currently being flushed (in internalFlush)
164 SkSTArray<8, uint32_t, true> fFlushingOpListIDs;
165 // These are the new opLists generated by the onFlush CBs
166 SkSTArray<8, sk_sp<GrOpList>> fOnFlushCBOpLists;
robertphillips77a2e522015-10-17 07:43:27 -0700167
Herb Derby26cbe512018-05-24 14:39:01 -0400168 std::unique_ptr<GrTextContext> fTextContext;
robertphillipsa13e2022015-11-11 12:01:09 -0800169
Ben Wagner9ec70c62018-07-12 13:30:47 -0400170 std::unique_ptr<GrPathRendererChain> fPathRendererChain;
171 sk_sp<GrSoftwarePathRenderer> fSoftwarePathRenderer;
brianosman86e76262016-08-11 12:17:31 -0700172
Robert Phillips40a29d72018-01-18 12:59:22 -0500173 GrTokenTracker fTokenTracker;
brianosman86e76262016-08-11 12:17:31 -0700174 bool fFlushing;
Robert Phillips4150eea2018-02-07 17:08:21 -0500175 bool fSortRenderTargets;
bsalomonb77a9072016-09-07 10:02:04 -0700176
Chris Daltonfe199b72017-05-05 11:26:15 -0400177 SkTArray<GrOnFlushCallbackObject*> fOnFlushCBObjects;
robertphillips77a2e522015-10-17 07:43:27 -0700178};
179
180#endif