blob: 8ea70debab0bf358c4c0e3d14d84b1a2bd95a81f [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"
Chris Daltonfe199b72017-05-05 11:26:15 -040014#include "GrOnFlushResourceProvider.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040015#include "GrRenderTargetOpList.h"
bsalomonb77a9072016-09-07 10:02:04 -070016#include "GrResourceCache.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040017#include "SkTArray.h"
Robert Phillipse3302df2017-04-24 07:31:02 -040018#include "instanced/InstancedRendering.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050019#include "text/GrAtlasTextContext.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040020
robertphillips77a2e522015-10-17 07:43:27 -070021class GrContext;
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>,
45 const SkSurfaceProps*);
Robert Phillips2c862492017-01-18 10:08:39 -050046 sk_sp<GrTextureContext> makeTextureContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>);
robertphillips77a2e522015-10-17 07:43:27 -070047
Robert Phillipsf2361d22016-10-25 14:20:06 -040048 // The caller automatically gets a ref on the returned opList. It must
robertphillips77a2e522015-10-17 07:43:27 -070049 // be balanced by an unref call.
Robert Phillipsb6deea82017-05-11 14:14:30 -040050 sk_sp<GrRenderTargetOpList> newRTOpList(GrRenderTargetProxy* rtp);
51 sk_sp<GrTextureOpList> newTextureOpList(GrTextureProxy* textureProxy);
robertphillips77a2e522015-10-17 07:43:27 -070052
53 GrContext* getContext() { return fContext; }
54
brianosman86e76262016-08-11 12:17:31 -070055 GrAtlasTextContext* getAtlasTextContext();
56
robertphillips68737822015-10-29 12:12:21 -070057 GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
58 bool allowSW,
59 GrPathRendererChain::DrawType drawType,
60 GrPathRenderer::StencilSupport* stencilSupport = NULL);
61
bsalomonb77a9072016-09-07 10:02:04 -070062 void flushIfNecessary() {
63 if (fContext->getResourceCache()->requestsFlush()) {
Robert Phillips7ee385e2017-03-30 08:02:11 -040064 this->internalFlush(nullptr, GrResourceCache::kCacheRequested);
bsalomonb77a9072016-09-07 10:02:04 -070065 } else if (fIsImmediateMode) {
Robert Phillips7ee385e2017-03-30 08:02:11 -040066 this->internalFlush(nullptr, GrResourceCache::kImmediateMode);
bsalomonb77a9072016-09-07 10:02:04 -070067 }
68 }
69
robertphillips0dfa62c2015-11-16 06:23:31 -080070 static bool ProgramUnitTest(GrContext* context, int maxStages);
robertphillipsa13e2022015-11-11 12:01:09 -080071
Robert Phillips7ee385e2017-03-30 08:02:11 -040072 void prepareSurfaceForExternalIO(GrSurfaceProxy*);
bsalomon6a2b1942016-09-08 11:28:59 -070073
Chris Daltonfe199b72017-05-05 11:26:15 -040074 void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
75 void testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject*);
Robert Phillipseb35f4d2017-03-21 07:56:47 -040076
robertphillips77a2e522015-10-17 07:43:27 -070077private:
Robert Phillipsf2361d22016-10-25 14:20:06 -040078 GrDrawingManager(GrContext* context,
bsalomon6b2552f2016-09-15 13:50:26 -070079 const GrPathRendererChain::Options& optionsForPathRendererChain,
bsalomonb77a9072016-09-07 10:02:04 -070080 bool isImmediateMode, GrSingleOwner* singleOwner)
robertphillips77a2e522015-10-17 07:43:27 -070081 : fContext(context)
bsalomon6b2552f2016-09-15 13:50:26 -070082 , fOptionsForPathRendererChain(optionsForPathRendererChain)
joshualittde8dc7e2016-01-08 10:09:13 -080083 , fSingleOwner(singleOwner)
robertphillips77a2e522015-10-17 07:43:27 -070084 , fAbandoned(false)
brianosman86e76262016-08-11 12:17:31 -070085 , fAtlasTextContext(nullptr)
robertphillips68737822015-10-29 12:12:21 -070086 , fPathRendererChain(nullptr)
robertphillipsa13e2022015-11-11 12:01:09 -080087 , fSoftwarePathRenderer(nullptr)
joshualittb8918c42015-12-18 09:59:46 -080088 , fFlushState(context->getGpu(), context->resourceProvider())
bsalomonb77a9072016-09-07 10:02:04 -070089 , fFlushing(false)
90 , fIsImmediateMode(isImmediateMode) {
robertphillips77a2e522015-10-17 07:43:27 -070091 }
92
93 void abandon();
94 void cleanup();
95 void reset();
Robert Phillips7ee385e2017-03-30 08:02:11 -040096 void flush(GrSurfaceProxy* proxy) {
97 this->internalFlush(proxy, GrResourceCache::FlushType::kExternal);
98 }
99 void internalFlush(GrSurfaceProxy*, GrResourceCache::FlushType);
robertphillips77a2e522015-10-17 07:43:27 -0700100
101 friend class GrContext; // for access to: ctor, abandon, reset & flush
Robert Phillips7ee385e2017-03-30 08:02:11 -0400102 friend class GrContextPriv; // access to: flush
Chris Daltonfe199b72017-05-05 11:26:15 -0400103 friend class GrOnFlushResourceProvider; // this is just a shallow wrapper around this class
robertphillips77a2e522015-10-17 07:43:27 -0700104
105 static const int kNumPixelGeometries = 5; // The different pixel geometries
106 static const int kNumDFTOptions = 2; // DFT or no DFT
107
brianosman86e76262016-08-11 12:17:31 -0700108 GrContext* fContext;
bsalomon6b2552f2016-09-15 13:50:26 -0700109 GrPathRendererChain::Options fOptionsForPathRendererChain;
robertphillips77a2e522015-10-17 07:43:27 -0700110
joshualittde8dc7e2016-01-08 10:09:13 -0800111 // In debug builds we guard against improper thread handling
brianosman86e76262016-08-11 12:17:31 -0700112 GrSingleOwner* fSingleOwner;
joshualittde8dc7e2016-01-08 10:09:13 -0800113
brianosman86e76262016-08-11 12:17:31 -0700114 bool fAbandoned;
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400115 SkTArray<sk_sp<GrOpList>> fOpLists;
robertphillips77a2e522015-10-17 07:43:27 -0700116
Ben Wagner145dbcd2016-11-03 14:40:50 -0400117 std::unique_ptr<GrAtlasTextContext> fAtlasTextContext;
robertphillipsa13e2022015-11-11 12:01:09 -0800118
brianosman86e76262016-08-11 12:17:31 -0700119 GrPathRendererChain* fPathRendererChain;
120 GrSoftwarePathRenderer* fSoftwarePathRenderer;
121
Brian Salomon742e31d2016-12-07 17:06:19 -0500122 GrOpFlushState fFlushState;
brianosman86e76262016-08-11 12:17:31 -0700123 bool fFlushing;
bsalomonb77a9072016-09-07 10:02:04 -0700124
125 bool fIsImmediateMode;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400126
Chris Daltonfe199b72017-05-05 11:26:15 -0400127 SkTArray<GrOnFlushCallbackObject*> fOnFlushCBObjects;
Robert Phillipse3302df2017-04-24 07:31:02 -0400128
129 // Lazily allocated
130 std::unique_ptr<gr_instanced::OpAllocator> fInstancingAllocator;
robertphillips77a2e522015-10-17 07:43:27 -0700131};
132
133#endif