blob: 0143783708c52774ba5fa0a983803e4050a6c74c [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;
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 Phillipse3302df2017-04-24 07:31:02 -040041 gr_instanced::OpAllocator* instancingAllocator();
42
Robert Phillips37430132016-11-09 06:50:43 -050043 sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
Brian Osman11052242016-10-27 14:47:55 -040044 sk_sp<SkColorSpace>,
Robert Phillips941d1442017-06-14 16:37:02 -040045 const SkSurfaceProps*,
46 bool managedOpList = true);
Robert Phillips2c862492017-01-18 10:08:39 -050047 sk_sp<GrTextureContext> makeTextureContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>);
robertphillips77a2e522015-10-17 07:43:27 -070048
Robert Phillipsf2361d22016-10-25 14:20:06 -040049 // The caller automatically gets a ref on the returned opList. It must
robertphillips77a2e522015-10-17 07:43:27 -070050 // be balanced by an unref call.
Robert Phillips941d1442017-06-14 16:37:02 -040051 // 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 Phillipsb6deea82017-05-11 14:14:30 -040054 sk_sp<GrTextureOpList> newTextureOpList(GrTextureProxy* textureProxy);
robertphillips77a2e522015-10-17 07:43:27 -070055
56 GrContext* getContext() { return fContext; }
57
brianosman86e76262016-08-11 12:17:31 -070058 GrAtlasTextContext* getAtlasTextContext();
59
robertphillips68737822015-10-29 12:12:21 -070060 GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
61 bool allowSW,
62 GrPathRendererChain::DrawType drawType,
Ben Wagnera93a14a2017-08-28 10:34:05 -040063 GrPathRenderer::StencilSupport* stencilSupport = nullptr);
robertphillips68737822015-10-29 12:12:21 -070064
bsalomonb77a9072016-09-07 10:02:04 -070065 void flushIfNecessary() {
66 if (fContext->getResourceCache()->requestsFlush()) {
Greg Daniel51316782017-08-02 15:10:09 +000067 this->internalFlush(nullptr, GrResourceCache::kCacheRequested, 0, nullptr);
bsalomonb77a9072016-09-07 10:02:04 -070068 }
69 }
70
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
robertphillips77a2e522015-10-17 07:43:27 -070080private:
Robert Phillipsf2361d22016-10-25 14:20:06 -040081 GrDrawingManager(GrContext* context,
bsalomon6b2552f2016-09-15 13:50:26 -070082 const GrPathRendererChain::Options& optionsForPathRendererChain,
Robert Phillips3ea17982017-06-02 12:43:04 -040083 GrSingleOwner* singleOwner)
robertphillips77a2e522015-10-17 07:43:27 -070084 : fContext(context)
bsalomon6b2552f2016-09-15 13:50:26 -070085 , fOptionsForPathRendererChain(optionsForPathRendererChain)
joshualittde8dc7e2016-01-08 10:09:13 -080086 , fSingleOwner(singleOwner)
robertphillips77a2e522015-10-17 07:43:27 -070087 , fAbandoned(false)
brianosman86e76262016-08-11 12:17:31 -070088 , fAtlasTextContext(nullptr)
robertphillips68737822015-10-29 12:12:21 -070089 , fPathRendererChain(nullptr)
robertphillipsa13e2022015-11-11 12:01:09 -080090 , fSoftwarePathRenderer(nullptr)
joshualittb8918c42015-12-18 09:59:46 -080091 , fFlushState(context->getGpu(), context->resourceProvider())
Robert Phillips3ea17982017-06-02 12:43:04 -040092 , fFlushing(false) {
robertphillips77a2e522015-10-17 07:43:27 -070093 }
94
95 void abandon();
96 void cleanup();
97 void reset();
Greg Daniel51316782017-08-02 15:10:09 +000098 GrSemaphoresSubmitted flush(GrSurfaceProxy* proxy,
99 int numSemaphores = 0,
100 GrBackendSemaphore backendSemaphores[] = nullptr) {
101 return this->internalFlush(proxy, GrResourceCache::FlushType::kExternal,
102 numSemaphores, backendSemaphores);
Robert Phillips7ee385e2017-03-30 08:02:11 -0400103 }
Greg Daniel51316782017-08-02 15:10:09 +0000104 GrSemaphoresSubmitted internalFlush(GrSurfaceProxy*,
105 GrResourceCache::FlushType,
106 int numSemaphores,
107 GrBackendSemaphore backendSemaphores[]);
robertphillips77a2e522015-10-17 07:43:27 -0700108
109 friend class GrContext; // for access to: ctor, abandon, reset & flush
Robert Phillips7ee385e2017-03-30 08:02:11 -0400110 friend class GrContextPriv; // access to: flush
Chris Daltonfe199b72017-05-05 11:26:15 -0400111 friend class GrOnFlushResourceProvider; // this is just a shallow wrapper around this class
robertphillips77a2e522015-10-17 07:43:27 -0700112
113 static const int kNumPixelGeometries = 5; // The different pixel geometries
114 static const int kNumDFTOptions = 2; // DFT or no DFT
115
brianosman86e76262016-08-11 12:17:31 -0700116 GrContext* fContext;
bsalomon6b2552f2016-09-15 13:50:26 -0700117 GrPathRendererChain::Options fOptionsForPathRendererChain;
robertphillips77a2e522015-10-17 07:43:27 -0700118
joshualittde8dc7e2016-01-08 10:09:13 -0800119 // In debug builds we guard against improper thread handling
brianosman86e76262016-08-11 12:17:31 -0700120 GrSingleOwner* fSingleOwner;
joshualittde8dc7e2016-01-08 10:09:13 -0800121
brianosman86e76262016-08-11 12:17:31 -0700122 bool fAbandoned;
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400123 SkTArray<sk_sp<GrOpList>> fOpLists;
robertphillips77a2e522015-10-17 07:43:27 -0700124
Ben Wagner145dbcd2016-11-03 14:40:50 -0400125 std::unique_ptr<GrAtlasTextContext> fAtlasTextContext;
robertphillipsa13e2022015-11-11 12:01:09 -0800126
brianosman86e76262016-08-11 12:17:31 -0700127 GrPathRendererChain* fPathRendererChain;
128 GrSoftwarePathRenderer* fSoftwarePathRenderer;
129
Brian Salomon742e31d2016-12-07 17:06:19 -0500130 GrOpFlushState fFlushState;
brianosman86e76262016-08-11 12:17:31 -0700131 bool fFlushing;
bsalomonb77a9072016-09-07 10:02:04 -0700132
Chris Daltonfe199b72017-05-05 11:26:15 -0400133 SkTArray<GrOnFlushCallbackObject*> fOnFlushCBObjects;
Robert Phillipse3302df2017-04-24 07:31:02 -0400134
135 // Lazily allocated
136 std::unique_ptr<gr_instanced::OpAllocator> fInstancingAllocator;
robertphillips77a2e522015-10-17 07:43:27 -0700137};
138
139#endif