blob: 91d1629348f9a837abf24f005ae41222f62d3801 [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 Phillipsa3f70262018-02-08 10:59:38 -050084 GrDrawingManager(GrContext*, const GrPathRendererChain::Options&,
Herb Derby26cbe512018-05-24 14:39:01 -040085 const GrTextContext::Options&, GrSingleOwner*,
Robert Phillips64ecdce2018-04-02 10:26:39 -040086 bool explicitlyAllocating, GrContextOptions::Enable sortRenderTargets);
robertphillips77a2e522015-10-17 07:43:27 -070087
88 void abandon();
89 void cleanup();
Robert Phillipseafd48a2017-11-16 07:52:08 -050090
91 // return true if any opLists were actually executed; false otherwise
92 bool executeOpLists(int startIndex, int stopIndex, GrOpFlushState*);
93
Greg Daniel51316782017-08-02 15:10:09 +000094 GrSemaphoresSubmitted flush(GrSurfaceProxy* proxy,
95 int numSemaphores = 0,
96 GrBackendSemaphore backendSemaphores[] = nullptr) {
97 return this->internalFlush(proxy, GrResourceCache::FlushType::kExternal,
98 numSemaphores, backendSemaphores);
Robert Phillips7ee385e2017-03-30 08:02:11 -040099 }
Greg Daniel51316782017-08-02 15:10:09 +0000100 GrSemaphoresSubmitted internalFlush(GrSurfaceProxy*,
101 GrResourceCache::FlushType,
102 int numSemaphores,
103 GrBackendSemaphore backendSemaphores[]);
robertphillips77a2e522015-10-17 07:43:27 -0700104
105 friend class GrContext; // for access to: ctor, abandon, reset & flush
Robert Phillips7ee385e2017-03-30 08:02:11 -0400106 friend class GrContextPriv; // access to: flush
Chris Daltonfe199b72017-05-05 11:26:15 -0400107 friend class GrOnFlushResourceProvider; // this is just a shallow wrapper around this class
robertphillips77a2e522015-10-17 07:43:27 -0700108
109 static const int kNumPixelGeometries = 5; // The different pixel geometries
110 static const int kNumDFTOptions = 2; // DFT or no DFT
111
brianosman86e76262016-08-11 12:17:31 -0700112 GrContext* fContext;
bsalomon6b2552f2016-09-15 13:50:26 -0700113 GrPathRendererChain::Options fOptionsForPathRendererChain;
Herb Derby26cbe512018-05-24 14:39:01 -0400114 GrTextContext::Options fOptionsForTextContext;
robertphillips77a2e522015-10-17 07:43:27 -0700115
joshualittde8dc7e2016-01-08 10:09:13 -0800116 // In debug builds we guard against improper thread handling
brianosman86e76262016-08-11 12:17:31 -0700117 GrSingleOwner* fSingleOwner;
joshualittde8dc7e2016-01-08 10:09:13 -0800118
brianosman86e76262016-08-11 12:17:31 -0700119 bool fAbandoned;
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400120 SkTArray<sk_sp<GrOpList>> fOpLists;
Chris Dalton3968ff92017-11-27 12:26:31 -0700121 // These are the IDs of the opLists currently being flushed (in internalFlush)
122 SkSTArray<8, uint32_t, true> fFlushingOpListIDs;
123 // These are the new opLists generated by the onFlush CBs
124 SkSTArray<8, sk_sp<GrOpList>> fOnFlushCBOpLists;
robertphillips77a2e522015-10-17 07:43:27 -0700125
Herb Derby26cbe512018-05-24 14:39:01 -0400126 std::unique_ptr<GrTextContext> fTextContext;
robertphillipsa13e2022015-11-11 12:01:09 -0800127
brianosman86e76262016-08-11 12:17:31 -0700128 GrPathRendererChain* fPathRendererChain;
129 GrSoftwarePathRenderer* fSoftwarePathRenderer;
130
Robert Phillips40a29d72018-01-18 12:59:22 -0500131 GrTokenTracker fTokenTracker;
brianosman86e76262016-08-11 12:17:31 -0700132 bool fFlushing;
Robert Phillips4150eea2018-02-07 17:08:21 -0500133 bool fSortRenderTargets;
bsalomonb77a9072016-09-07 10:02:04 -0700134
Chris Daltonfe199b72017-05-05 11:26:15 -0400135 SkTArray<GrOnFlushCallbackObject*> fOnFlushCBObjects;
robertphillips77a2e522015-10-17 07:43:27 -0700136};
137
138#endif