blob: cbb28c494a0cd8c413ff42541b8e72ff9d61e3f3 [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
Brian Salomon742e31d2016-12-07 17:06:19 -050011#include "GrOpFlushState.h"
robertphillips68737822015-10-29 12:12:21 -070012#include "GrPathRenderer.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050013#include "GrPathRendererChain.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040014#include "GrRenderTargetOpList.h"
bsalomonb77a9072016-09-07 10:02:04 -070015#include "GrResourceCache.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040016#include "SkTArray.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050017#include "text/GrAtlasTextContext.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040018
robertphillips77a2e522015-10-17 07:43:27 -070019class GrContext;
Chris Daltonfddb6c02017-11-04 15:22:22 -060020class GrCoverageCountingPathRenderer;
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040021class GrOnFlushCallbackObject;
Brian Osman11052242016-10-27 14:47:55 -040022class GrRenderTargetContext;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040023class GrRenderTargetProxy;
joshualittde8dc7e2016-01-08 10:09:13 -080024class GrSingleOWner;
robertphillips68737822015-10-29 12:12:21 -070025class GrSoftwarePathRenderer;
Brian Osman45580d32016-11-23 09:37:01 -050026class GrTextureContext;
27class GrTextureOpList;
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
brianosman86e76262016-08-11 12:17:31 -070056 GrAtlasTextContext* getAtlasTextContext();
57
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
Chris Daltonfddb6c02017-11-04 15:22:22 -060063 // Returns a direct pointer to the coverage counting path renderer, or null if it is not
64 // supported and turned on.
65 GrCoverageCountingPathRenderer* getCoverageCountingPathRenderer();
66
bsalomonb77a9072016-09-07 10:02:04 -070067 void flushIfNecessary() {
68 if (fContext->getResourceCache()->requestsFlush()) {
Greg Daniel51316782017-08-02 15:10:09 +000069 this->internalFlush(nullptr, GrResourceCache::kCacheRequested, 0, nullptr);
bsalomonb77a9072016-09-07 10:02:04 -070070 }
71 }
72
Greg Daniel78325c12017-06-19 16:39:13 -040073 static bool ProgramUnitTest(GrContext* context, int maxStages, int maxLevels);
robertphillipsa13e2022015-11-11 12:01:09 -080074
Greg Daniel51316782017-08-02 15:10:09 +000075 GrSemaphoresSubmitted prepareSurfaceForExternalIO(GrSurfaceProxy*,
76 int numSemaphores,
77 GrBackendSemaphore backendSemaphores[]);
bsalomon6a2b1942016-09-08 11:28:59 -070078
Chris Daltonfe199b72017-05-05 11:26:15 -040079 void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
80 void testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject*);
Robert Phillipseb35f4d2017-03-21 07:56:47 -040081
robertphillips77a2e522015-10-17 07:43:27 -070082private:
Robert Phillipsf2361d22016-10-25 14:20:06 -040083 GrDrawingManager(GrContext* context,
bsalomon6b2552f2016-09-15 13:50:26 -070084 const GrPathRendererChain::Options& optionsForPathRendererChain,
Brian Salomonaf597482017-11-07 16:23:34 -050085 const GrAtlasTextContext::Options& optionsForAtlasTextContext,
Robert Phillips3ea17982017-06-02 12:43:04 -040086 GrSingleOwner* singleOwner)
Brian Salomonaf597482017-11-07 16:23:34 -050087 : fContext(context)
88 , fOptionsForPathRendererChain(optionsForPathRendererChain)
89 , fOptionsForAtlasTextContext(optionsForAtlasTextContext)
90 , fSingleOwner(singleOwner)
91 , fAbandoned(false)
92 , fAtlasTextContext(nullptr)
93 , fPathRendererChain(nullptr)
94 , fSoftwarePathRenderer(nullptr)
95 , fFlushState(context->getGpu(), context->resourceProvider())
96 , fFlushing(false) {}
robertphillips77a2e522015-10-17 07:43:27 -070097
98 void abandon();
99 void cleanup();
Robert Phillipseafd48a2017-11-16 07:52:08 -0500100
101 // return true if any opLists were actually executed; false otherwise
102 bool executeOpLists(int startIndex, int stopIndex, GrOpFlushState*);
103
Greg Daniel51316782017-08-02 15:10:09 +0000104 GrSemaphoresSubmitted flush(GrSurfaceProxy* proxy,
105 int numSemaphores = 0,
106 GrBackendSemaphore backendSemaphores[] = nullptr) {
107 return this->internalFlush(proxy, GrResourceCache::FlushType::kExternal,
108 numSemaphores, backendSemaphores);
Robert Phillips7ee385e2017-03-30 08:02:11 -0400109 }
Greg Daniel51316782017-08-02 15:10:09 +0000110 GrSemaphoresSubmitted internalFlush(GrSurfaceProxy*,
111 GrResourceCache::FlushType,
112 int numSemaphores,
113 GrBackendSemaphore backendSemaphores[]);
robertphillips77a2e522015-10-17 07:43:27 -0700114
115 friend class GrContext; // for access to: ctor, abandon, reset & flush
Robert Phillips7ee385e2017-03-30 08:02:11 -0400116 friend class GrContextPriv; // access to: flush
Chris Daltonfe199b72017-05-05 11:26:15 -0400117 friend class GrOnFlushResourceProvider; // this is just a shallow wrapper around this class
robertphillips77a2e522015-10-17 07:43:27 -0700118
119 static const int kNumPixelGeometries = 5; // The different pixel geometries
120 static const int kNumDFTOptions = 2; // DFT or no DFT
121
brianosman86e76262016-08-11 12:17:31 -0700122 GrContext* fContext;
bsalomon6b2552f2016-09-15 13:50:26 -0700123 GrPathRendererChain::Options fOptionsForPathRendererChain;
Brian Salomonaf597482017-11-07 16:23:34 -0500124 GrAtlasTextContext::Options fOptionsForAtlasTextContext;
robertphillips77a2e522015-10-17 07:43:27 -0700125
joshualittde8dc7e2016-01-08 10:09:13 -0800126 // In debug builds we guard against improper thread handling
brianosman86e76262016-08-11 12:17:31 -0700127 GrSingleOwner* fSingleOwner;
joshualittde8dc7e2016-01-08 10:09:13 -0800128
brianosman86e76262016-08-11 12:17:31 -0700129 bool fAbandoned;
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400130 SkTArray<sk_sp<GrOpList>> fOpLists;
Chris Dalton3968ff92017-11-27 12:26:31 -0700131 // These are the IDs of the opLists currently being flushed (in internalFlush)
132 SkSTArray<8, uint32_t, true> fFlushingOpListIDs;
133 // These are the new opLists generated by the onFlush CBs
134 SkSTArray<8, sk_sp<GrOpList>> fOnFlushCBOpLists;
robertphillips77a2e522015-10-17 07:43:27 -0700135
Ben Wagner145dbcd2016-11-03 14:40:50 -0400136 std::unique_ptr<GrAtlasTextContext> fAtlasTextContext;
robertphillipsa13e2022015-11-11 12:01:09 -0800137
brianosman86e76262016-08-11 12:17:31 -0700138 GrPathRendererChain* fPathRendererChain;
139 GrSoftwarePathRenderer* fSoftwarePathRenderer;
140
Brian Salomon742e31d2016-12-07 17:06:19 -0500141 GrOpFlushState fFlushState;
brianosman86e76262016-08-11 12:17:31 -0700142 bool fFlushing;
bsalomonb77a9072016-09-07 10:02:04 -0700143
Chris Daltonfe199b72017-05-05 11:26:15 -0400144 SkTArray<GrOnFlushCallbackObject*> fOnFlushCBObjects;
robertphillips77a2e522015-10-17 07:43:27 -0700145};
146
147#endif