blob: 9a05215f5b6e909a39e7a89042c4c9733438a33f [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"
robertphillips77a2e522015-10-17 07:43:27 -070016#include "SkTDArray.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;
Brian Osman11052242016-10-27 14:47:55 -040020class GrRenderTargetContext;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040021class GrRenderTargetProxy;
joshualittde8dc7e2016-01-08 10:09:13 -080022class GrSingleOWner;
robertphillips68737822015-10-29 12:12:21 -070023class GrSoftwarePathRenderer;
Brian Osman45580d32016-11-23 09:37:01 -050024class GrTextureContext;
25class GrTextureOpList;
robertphillips77a2e522015-10-17 07:43:27 -070026
Brian Osman11052242016-10-27 14:47:55 -040027// The GrDrawingManager allocates a new GrRenderTargetContext for each GrRenderTarget
Robert Phillipsf2361d22016-10-25 14:20:06 -040028// but all of them still land in the same GrOpList!
robertphillips77a2e522015-10-17 07:43:27 -070029//
Brian Osman11052242016-10-27 14:47:55 -040030// In the future this class will allocate a new GrRenderTargetContext for
Robert Phillipsf2361d22016-10-25 14:20:06 -040031// each GrRenderTarget/GrOpList and manage the DAG.
robertphillips77a2e522015-10-17 07:43:27 -070032class GrDrawingManager {
33public:
34 ~GrDrawingManager();
35
robertphillips7761d612016-05-16 09:14:53 -070036 bool wasAbandoned() const { return fAbandoned; }
robertphillips68737822015-10-29 12:12:21 -070037 void freeGpuResources();
robertphillips77a2e522015-10-17 07:43:27 -070038
Robert Phillips37430132016-11-09 06:50:43 -050039 sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
Brian Osman11052242016-10-27 14:47:55 -040040 sk_sp<SkColorSpace>,
41 const SkSurfaceProps*);
Brian Osman45580d32016-11-23 09:37:01 -050042 sk_sp<GrTextureContext> makeTextureContext(sk_sp<GrSurfaceProxy>);
robertphillips77a2e522015-10-17 07:43:27 -070043
Robert Phillipsf2361d22016-10-25 14:20:06 -040044 // The caller automatically gets a ref on the returned opList. It must
robertphillips77a2e522015-10-17 07:43:27 -070045 // be balanced by an unref call.
Robert Phillipsc7635fa2016-10-28 13:25:24 -040046 GrRenderTargetOpList* newOpList(GrRenderTargetProxy* rtp);
Brian Osman45580d32016-11-23 09:37:01 -050047 GrTextureOpList* newOpList(GrTextureProxy* textureProxy);
robertphillips77a2e522015-10-17 07:43:27 -070048
49 GrContext* getContext() { return fContext; }
50
brianosman86e76262016-08-11 12:17:31 -070051 GrAtlasTextContext* getAtlasTextContext();
52
robertphillips68737822015-10-29 12:12:21 -070053 GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
54 bool allowSW,
55 GrPathRendererChain::DrawType drawType,
56 GrPathRenderer::StencilSupport* stencilSupport = NULL);
57
bsalomonb77a9072016-09-07 10:02:04 -070058 void flushIfNecessary() {
59 if (fContext->getResourceCache()->requestsFlush()) {
60 this->internalFlush(GrResourceCache::kCacheRequested);
61 } else if (fIsImmediateMode) {
62 this->internalFlush(GrResourceCache::kImmediateMode);
63 }
64 }
65
robertphillips0dfa62c2015-11-16 06:23:31 -080066 static bool ProgramUnitTest(GrContext* context, int maxStages);
robertphillipsa13e2022015-11-11 12:01:09 -080067
bsalomon6a2b1942016-09-08 11:28:59 -070068 void prepareSurfaceForExternalIO(GrSurface*);
69
robertphillips77a2e522015-10-17 07:43:27 -070070private:
Robert Phillipsf2361d22016-10-25 14:20:06 -040071 GrDrawingManager(GrContext* context,
72 const GrRenderTargetOpList::Options& optionsForOpLists,
bsalomon6b2552f2016-09-15 13:50:26 -070073 const GrPathRendererChain::Options& optionsForPathRendererChain,
bsalomonb77a9072016-09-07 10:02:04 -070074 bool isImmediateMode, GrSingleOwner* singleOwner)
robertphillips77a2e522015-10-17 07:43:27 -070075 : fContext(context)
Robert Phillipsf2361d22016-10-25 14:20:06 -040076 , fOptionsForOpLists(optionsForOpLists)
bsalomon6b2552f2016-09-15 13:50:26 -070077 , fOptionsForPathRendererChain(optionsForPathRendererChain)
joshualittde8dc7e2016-01-08 10:09:13 -080078 , fSingleOwner(singleOwner)
robertphillips77a2e522015-10-17 07:43:27 -070079 , fAbandoned(false)
brianosman86e76262016-08-11 12:17:31 -070080 , fAtlasTextContext(nullptr)
robertphillips68737822015-10-29 12:12:21 -070081 , fPathRendererChain(nullptr)
robertphillipsa13e2022015-11-11 12:01:09 -080082 , fSoftwarePathRenderer(nullptr)
joshualittb8918c42015-12-18 09:59:46 -080083 , fFlushState(context->getGpu(), context->resourceProvider())
bsalomonb77a9072016-09-07 10:02:04 -070084 , fFlushing(false)
85 , fIsImmediateMode(isImmediateMode) {
robertphillips77a2e522015-10-17 07:43:27 -070086 }
87
88 void abandon();
89 void cleanup();
90 void reset();
bsalomonb77a9072016-09-07 10:02:04 -070091 void flush() { this->internalFlush(GrResourceCache::FlushType::kExternal); }
92 void internalFlush(GrResourceCache::FlushType);
robertphillips77a2e522015-10-17 07:43:27 -070093
94 friend class GrContext; // for access to: ctor, abandon, reset & flush
95
96 static const int kNumPixelGeometries = 5; // The different pixel geometries
97 static const int kNumDFTOptions = 2; // DFT or no DFT
98
brianosman86e76262016-08-11 12:17:31 -070099 GrContext* fContext;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400100 GrRenderTargetOpList::Options fOptionsForOpLists;
bsalomon6b2552f2016-09-15 13:50:26 -0700101 GrPathRendererChain::Options fOptionsForPathRendererChain;
robertphillips77a2e522015-10-17 07:43:27 -0700102
joshualittde8dc7e2016-01-08 10:09:13 -0800103 // In debug builds we guard against improper thread handling
brianosman86e76262016-08-11 12:17:31 -0700104 GrSingleOwner* fSingleOwner;
joshualittde8dc7e2016-01-08 10:09:13 -0800105
brianosman86e76262016-08-11 12:17:31 -0700106 bool fAbandoned;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400107 SkTDArray<GrOpList*> fOpLists;
robertphillips77a2e522015-10-17 07:43:27 -0700108
Ben Wagner145dbcd2016-11-03 14:40:50 -0400109 std::unique_ptr<GrAtlasTextContext> fAtlasTextContext;
robertphillipsa13e2022015-11-11 12:01:09 -0800110
brianosman86e76262016-08-11 12:17:31 -0700111 GrPathRendererChain* fPathRendererChain;
112 GrSoftwarePathRenderer* fSoftwarePathRenderer;
113
Brian Salomon742e31d2016-12-07 17:06:19 -0500114 GrOpFlushState fFlushState;
brianosman86e76262016-08-11 12:17:31 -0700115 bool fFlushing;
bsalomonb77a9072016-09-07 10:02:04 -0700116
117 bool fIsImmediateMode;
robertphillips77a2e522015-10-17 07:43:27 -0700118};
119
120#endif