blob: 3816868c7568ffe62d92bb99e15611448010970a [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
brianosman86e76262016-08-11 12:17:31 -070011#include "text/GrAtlasTextContext.h"
robertphillipsa13e2022015-11-11 12:01:09 -080012#include "GrBatchFlushState.h"
robertphillips68737822015-10-29 12:12:21 -070013#include "GrPathRendererChain.h"
14#include "GrPathRenderer.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040015#include "GrRenderTargetOpList.h"
bsalomonb77a9072016-09-07 10:02:04 -070016#include "GrResourceCache.h"
robertphillips77a2e522015-10-17 07:43:27 -070017#include "SkTDArray.h"
18
Robert Phillipsf2361d22016-10-25 14:20:06 -040019
robertphillips77a2e522015-10-17 07:43:27 -070020class GrContext;
Brian Osman11052242016-10-27 14:47:55 -040021class GrRenderTargetContext;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040022class GrRenderTargetProxy;
joshualittde8dc7e2016-01-08 10:09:13 -080023class GrSingleOWner;
robertphillips68737822015-10-29 12:12:21 -070024class GrSoftwarePathRenderer;
robertphillips77a2e522015-10-17 07:43:27 -070025
Brian Osman11052242016-10-27 14:47:55 -040026// The GrDrawingManager allocates a new GrRenderTargetContext for each GrRenderTarget
Robert Phillipsf2361d22016-10-25 14:20:06 -040027// but all of them still land in the same GrOpList!
robertphillips77a2e522015-10-17 07:43:27 -070028//
Brian Osman11052242016-10-27 14:47:55 -040029// In the future this class will allocate a new GrRenderTargetContext for
Robert Phillipsf2361d22016-10-25 14:20:06 -040030// each GrRenderTarget/GrOpList and manage the DAG.
robertphillips77a2e522015-10-17 07:43:27 -070031class GrDrawingManager {
32public:
33 ~GrDrawingManager();
34
robertphillips7761d612016-05-16 09:14:53 -070035 bool wasAbandoned() const { return fAbandoned; }
robertphillips68737822015-10-29 12:12:21 -070036 void freeGpuResources();
robertphillips77a2e522015-10-17 07:43:27 -070037
Robert Phillips37430132016-11-09 06:50:43 -050038 sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
Brian Osman11052242016-10-27 14:47:55 -040039 sk_sp<SkColorSpace>,
40 const SkSurfaceProps*);
robertphillips77a2e522015-10-17 07:43:27 -070041
Robert Phillipsf2361d22016-10-25 14:20:06 -040042 // The caller automatically gets a ref on the returned opList. It must
robertphillips77a2e522015-10-17 07:43:27 -070043 // be balanced by an unref call.
Robert Phillipsc7635fa2016-10-28 13:25:24 -040044 GrRenderTargetOpList* newOpList(GrRenderTargetProxy* rtp);
robertphillips77a2e522015-10-17 07:43:27 -070045
46 GrContext* getContext() { return fContext; }
47
brianosman86e76262016-08-11 12:17:31 -070048 GrAtlasTextContext* getAtlasTextContext();
49
robertphillips68737822015-10-29 12:12:21 -070050 GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
51 bool allowSW,
52 GrPathRendererChain::DrawType drawType,
53 GrPathRenderer::StencilSupport* stencilSupport = NULL);
54
bsalomonb77a9072016-09-07 10:02:04 -070055 void flushIfNecessary() {
56 if (fContext->getResourceCache()->requestsFlush()) {
57 this->internalFlush(GrResourceCache::kCacheRequested);
58 } else if (fIsImmediateMode) {
59 this->internalFlush(GrResourceCache::kImmediateMode);
60 }
61 }
62
robertphillips0dfa62c2015-11-16 06:23:31 -080063 static bool ProgramUnitTest(GrContext* context, int maxStages);
robertphillipsa13e2022015-11-11 12:01:09 -080064
bsalomon6a2b1942016-09-08 11:28:59 -070065 void prepareSurfaceForExternalIO(GrSurface*);
66
robertphillips77a2e522015-10-17 07:43:27 -070067private:
Robert Phillipsf2361d22016-10-25 14:20:06 -040068 GrDrawingManager(GrContext* context,
69 const GrRenderTargetOpList::Options& optionsForOpLists,
bsalomon6b2552f2016-09-15 13:50:26 -070070 const GrPathRendererChain::Options& optionsForPathRendererChain,
bsalomonb77a9072016-09-07 10:02:04 -070071 bool isImmediateMode, GrSingleOwner* singleOwner)
robertphillips77a2e522015-10-17 07:43:27 -070072 : fContext(context)
Robert Phillipsf2361d22016-10-25 14:20:06 -040073 , fOptionsForOpLists(optionsForOpLists)
bsalomon6b2552f2016-09-15 13:50:26 -070074 , fOptionsForPathRendererChain(optionsForPathRendererChain)
joshualittde8dc7e2016-01-08 10:09:13 -080075 , fSingleOwner(singleOwner)
robertphillips77a2e522015-10-17 07:43:27 -070076 , fAbandoned(false)
brianosman86e76262016-08-11 12:17:31 -070077 , fAtlasTextContext(nullptr)
robertphillips68737822015-10-29 12:12:21 -070078 , fPathRendererChain(nullptr)
robertphillipsa13e2022015-11-11 12:01:09 -080079 , fSoftwarePathRenderer(nullptr)
joshualittb8918c42015-12-18 09:59:46 -080080 , fFlushState(context->getGpu(), context->resourceProvider())
bsalomonb77a9072016-09-07 10:02:04 -070081 , fFlushing(false)
82 , fIsImmediateMode(isImmediateMode) {
robertphillips77a2e522015-10-17 07:43:27 -070083 }
84
85 void abandon();
86 void cleanup();
87 void reset();
bsalomonb77a9072016-09-07 10:02:04 -070088 void flush() { this->internalFlush(GrResourceCache::FlushType::kExternal); }
89 void internalFlush(GrResourceCache::FlushType);
robertphillips77a2e522015-10-17 07:43:27 -070090
91 friend class GrContext; // for access to: ctor, abandon, reset & flush
92
93 static const int kNumPixelGeometries = 5; // The different pixel geometries
94 static const int kNumDFTOptions = 2; // DFT or no DFT
95
brianosman86e76262016-08-11 12:17:31 -070096 GrContext* fContext;
Robert Phillipsf2361d22016-10-25 14:20:06 -040097 GrRenderTargetOpList::Options fOptionsForOpLists;
bsalomon6b2552f2016-09-15 13:50:26 -070098 GrPathRendererChain::Options fOptionsForPathRendererChain;
robertphillips77a2e522015-10-17 07:43:27 -070099
joshualittde8dc7e2016-01-08 10:09:13 -0800100 // In debug builds we guard against improper thread handling
brianosman86e76262016-08-11 12:17:31 -0700101 GrSingleOwner* fSingleOwner;
joshualittde8dc7e2016-01-08 10:09:13 -0800102
brianosman86e76262016-08-11 12:17:31 -0700103 bool fAbandoned;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400104 SkTDArray<GrOpList*> fOpLists;
robertphillips77a2e522015-10-17 07:43:27 -0700105
Ben Wagner145dbcd2016-11-03 14:40:50 -0400106 std::unique_ptr<GrAtlasTextContext> fAtlasTextContext;
robertphillipsa13e2022015-11-11 12:01:09 -0800107
brianosman86e76262016-08-11 12:17:31 -0700108 GrPathRendererChain* fPathRendererChain;
109 GrSoftwarePathRenderer* fSoftwarePathRenderer;
110
111 GrBatchFlushState fFlushState;
112 bool fFlushing;
bsalomonb77a9072016-09-07 10:02:04 -0700113
114 bool fIsImmediateMode;
robertphillips77a2e522015-10-17 07:43:27 -0700115};
116
117#endif