blob: d4ec85a9a1e2d1b49738f72f04c23800f8b77959 [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"
Robert Phillipse3302df2017-04-24 07:31:02 -040017#include "instanced/InstancedRendering.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050018#include "text/GrAtlasTextContext.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040019
robertphillips77a2e522015-10-17 07:43:27 -070020class GrContext;
Chris Daltonfddb6c02017-11-04 15:22:22 -060021class GrCoverageCountingPathRenderer;
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040022class GrOnFlushCallbackObject;
Brian Osman11052242016-10-27 14:47:55 -040023class GrRenderTargetContext;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040024class GrRenderTargetProxy;
joshualittde8dc7e2016-01-08 10:09:13 -080025class GrSingleOWner;
robertphillips68737822015-10-29 12:12:21 -070026class GrSoftwarePathRenderer;
Brian Osman45580d32016-11-23 09:37:01 -050027class GrTextureContext;
28class GrTextureOpList;
robertphillips77a2e522015-10-17 07:43:27 -070029
Brian Osman11052242016-10-27 14:47:55 -040030// The GrDrawingManager allocates a new GrRenderTargetContext for each GrRenderTarget
Robert Phillipsf2361d22016-10-25 14:20:06 -040031// but all of them still land in the same GrOpList!
robertphillips77a2e522015-10-17 07:43:27 -070032//
Brian Osman11052242016-10-27 14:47:55 -040033// In the future this class will allocate a new GrRenderTargetContext for
Robert Phillipsf2361d22016-10-25 14:20:06 -040034// each GrRenderTarget/GrOpList and manage the DAG.
robertphillips77a2e522015-10-17 07:43:27 -070035class GrDrawingManager {
36public:
37 ~GrDrawingManager();
38
robertphillips7761d612016-05-16 09:14:53 -070039 bool wasAbandoned() const { return fAbandoned; }
robertphillips68737822015-10-29 12:12:21 -070040 void freeGpuResources();
robertphillips77a2e522015-10-17 07:43:27 -070041
Robert Phillipse3302df2017-04-24 07:31:02 -040042 gr_instanced::OpAllocator* instancingAllocator();
43
Robert Phillips37430132016-11-09 06:50:43 -050044 sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
Brian Osman11052242016-10-27 14:47:55 -040045 sk_sp<SkColorSpace>,
Robert Phillips941d1442017-06-14 16:37:02 -040046 const SkSurfaceProps*,
47 bool managedOpList = true);
Robert Phillips2c862492017-01-18 10:08:39 -050048 sk_sp<GrTextureContext> makeTextureContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>);
robertphillips77a2e522015-10-17 07:43:27 -070049
Robert Phillipsf2361d22016-10-25 14:20:06 -040050 // The caller automatically gets a ref on the returned opList. It must
robertphillips77a2e522015-10-17 07:43:27 -070051 // be balanced by an unref call.
Robert Phillips941d1442017-06-14 16:37:02 -040052 // A managed opList is controlled by the drawing manager (i.e., sorted & flushed with the
53 // other). An unmanaged one is created and used by the onFlushCallback.
54 sk_sp<GrRenderTargetOpList> newRTOpList(GrRenderTargetProxy* rtp, bool managedOpList);
Robert Phillipsb6deea82017-05-11 14:14:30 -040055 sk_sp<GrTextureOpList> newTextureOpList(GrTextureProxy* textureProxy);
robertphillips77a2e522015-10-17 07:43:27 -070056
57 GrContext* getContext() { return fContext; }
58
brianosman86e76262016-08-11 12:17:31 -070059 GrAtlasTextContext* getAtlasTextContext();
60
robertphillips68737822015-10-29 12:12:21 -070061 GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
62 bool allowSW,
63 GrPathRendererChain::DrawType drawType,
Ben Wagnera93a14a2017-08-28 10:34:05 -040064 GrPathRenderer::StencilSupport* stencilSupport = nullptr);
robertphillips68737822015-10-29 12:12:21 -070065
Chris Daltonfddb6c02017-11-04 15:22:22 -060066 // Returns a direct pointer to the coverage counting path renderer, or null if it is not
67 // supported and turned on.
68 GrCoverageCountingPathRenderer* getCoverageCountingPathRenderer();
69
bsalomonb77a9072016-09-07 10:02:04 -070070 void flushIfNecessary() {
71 if (fContext->getResourceCache()->requestsFlush()) {
Greg Daniel51316782017-08-02 15:10:09 +000072 this->internalFlush(nullptr, GrResourceCache::kCacheRequested, 0, nullptr);
bsalomonb77a9072016-09-07 10:02:04 -070073 }
74 }
75
Greg Daniel78325c12017-06-19 16:39:13 -040076 static bool ProgramUnitTest(GrContext* context, int maxStages, int maxLevels);
robertphillipsa13e2022015-11-11 12:01:09 -080077
Greg Daniel51316782017-08-02 15:10:09 +000078 GrSemaphoresSubmitted prepareSurfaceForExternalIO(GrSurfaceProxy*,
79 int numSemaphores,
80 GrBackendSemaphore backendSemaphores[]);
bsalomon6a2b1942016-09-08 11:28:59 -070081
Chris Daltonfe199b72017-05-05 11:26:15 -040082 void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
83 void testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject*);
Robert Phillipseb35f4d2017-03-21 07:56:47 -040084
robertphillips77a2e522015-10-17 07:43:27 -070085private:
Robert Phillipsf2361d22016-10-25 14:20:06 -040086 GrDrawingManager(GrContext* context,
bsalomon6b2552f2016-09-15 13:50:26 -070087 const GrPathRendererChain::Options& optionsForPathRendererChain,
Brian Salomonaf597482017-11-07 16:23:34 -050088 const GrAtlasTextContext::Options& optionsForAtlasTextContext,
Robert Phillips3ea17982017-06-02 12:43:04 -040089 GrSingleOwner* singleOwner)
Brian Salomonaf597482017-11-07 16:23:34 -050090 : fContext(context)
91 , fOptionsForPathRendererChain(optionsForPathRendererChain)
92 , fOptionsForAtlasTextContext(optionsForAtlasTextContext)
93 , fSingleOwner(singleOwner)
94 , fAbandoned(false)
95 , fAtlasTextContext(nullptr)
96 , fPathRendererChain(nullptr)
97 , fSoftwarePathRenderer(nullptr)
98 , fFlushState(context->getGpu(), context->resourceProvider())
99 , fFlushing(false) {}
robertphillips77a2e522015-10-17 07:43:27 -0700100
101 void abandon();
102 void cleanup();
Greg Daniel51316782017-08-02 15:10:09 +0000103 GrSemaphoresSubmitted flush(GrSurfaceProxy* proxy,
104 int numSemaphores = 0,
105 GrBackendSemaphore backendSemaphores[] = nullptr) {
106 return this->internalFlush(proxy, GrResourceCache::FlushType::kExternal,
107 numSemaphores, backendSemaphores);
Robert Phillips7ee385e2017-03-30 08:02:11 -0400108 }
Greg Daniel51316782017-08-02 15:10:09 +0000109 GrSemaphoresSubmitted internalFlush(GrSurfaceProxy*,
110 GrResourceCache::FlushType,
111 int numSemaphores,
112 GrBackendSemaphore backendSemaphores[]);
robertphillips77a2e522015-10-17 07:43:27 -0700113
114 friend class GrContext; // for access to: ctor, abandon, reset & flush
Robert Phillips7ee385e2017-03-30 08:02:11 -0400115 friend class GrContextPriv; // access to: flush
Chris Daltonfe199b72017-05-05 11:26:15 -0400116 friend class GrOnFlushResourceProvider; // this is just a shallow wrapper around this class
robertphillips77a2e522015-10-17 07:43:27 -0700117
118 static const int kNumPixelGeometries = 5; // The different pixel geometries
119 static const int kNumDFTOptions = 2; // DFT or no DFT
120
brianosman86e76262016-08-11 12:17:31 -0700121 GrContext* fContext;
bsalomon6b2552f2016-09-15 13:50:26 -0700122 GrPathRendererChain::Options fOptionsForPathRendererChain;
Brian Salomonaf597482017-11-07 16:23:34 -0500123 GrAtlasTextContext::Options fOptionsForAtlasTextContext;
robertphillips77a2e522015-10-17 07:43:27 -0700124
joshualittde8dc7e2016-01-08 10:09:13 -0800125 // In debug builds we guard against improper thread handling
brianosman86e76262016-08-11 12:17:31 -0700126 GrSingleOwner* fSingleOwner;
joshualittde8dc7e2016-01-08 10:09:13 -0800127
brianosman86e76262016-08-11 12:17:31 -0700128 bool fAbandoned;
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400129 SkTArray<sk_sp<GrOpList>> fOpLists;
robertphillips77a2e522015-10-17 07:43:27 -0700130
Ben Wagner145dbcd2016-11-03 14:40:50 -0400131 std::unique_ptr<GrAtlasTextContext> fAtlasTextContext;
robertphillipsa13e2022015-11-11 12:01:09 -0800132
brianosman86e76262016-08-11 12:17:31 -0700133 GrPathRendererChain* fPathRendererChain;
134 GrSoftwarePathRenderer* fSoftwarePathRenderer;
135
Brian Salomon742e31d2016-12-07 17:06:19 -0500136 GrOpFlushState fFlushState;
brianosman86e76262016-08-11 12:17:31 -0700137 bool fFlushing;
bsalomonb77a9072016-09-07 10:02:04 -0700138
Chris Daltonfe199b72017-05-05 11:26:15 -0400139 SkTArray<GrOnFlushCallbackObject*> fOnFlushCBObjects;
Robert Phillipse3302df2017-04-24 07:31:02 -0400140
141 // Lazily allocated
142 std::unique_ptr<gr_instanced::OpAllocator> fInstancingAllocator;
robertphillips77a2e522015-10-17 07:43:27 -0700143};
144
145#endif