blob: 72db2aec6eb88bcc103ab109eaeb8481d760b2e0 [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
bsalomon648c6962015-10-23 09:06:59 -070011#include "GrDrawTarget.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"
robertphillips77a2e522015-10-17 07:43:27 -070015#include "SkTDArray.h"
16
17class GrContext;
18class GrDrawContext;
joshualittde8dc7e2016-01-08 10:09:13 -080019class GrSingleOWner;
robertphillips68737822015-10-29 12:12:21 -070020class GrSoftwarePathRenderer;
robertphillips77a2e522015-10-17 07:43:27 -070021
joshualitt8e84a1e2016-02-16 11:09:25 -080022// The GrDrawingManager allocates a new GrDrawContext for each GrRenderTarget
robertphillips77a2e522015-10-17 07:43:27 -070023// but all of them still land in the same GrDrawTarget!
24//
25// In the future this class will allocate a new GrDrawContext for
26// each GrRenderTarget/GrDrawTarget and manage the DAG.
27class GrDrawingManager {
28public:
29 ~GrDrawingManager();
30
31 bool abandoned() const { return fAbandoned; }
robertphillips68737822015-10-29 12:12:21 -070032 void freeGpuResources();
robertphillips77a2e522015-10-17 07:43:27 -070033
robertphillips6c7e3252016-04-27 10:47:51 -070034 sk_sp<GrDrawContext> drawContext(sk_sp<GrRenderTarget> rt, const SkSurfaceProps*);
robertphillips77a2e522015-10-17 07:43:27 -070035
halcanary9d524f22016-03-29 09:03:52 -070036 // The caller automatically gets a ref on the returned drawTarget. It must
robertphillips77a2e522015-10-17 07:43:27 -070037 // be balanced by an unref call.
38 GrDrawTarget* newDrawTarget(GrRenderTarget* rt);
39
40 GrContext* getContext() { return fContext; }
41
robertphillips68737822015-10-29 12:12:21 -070042 GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
43 bool allowSW,
44 GrPathRendererChain::DrawType drawType,
45 GrPathRenderer::StencilSupport* stencilSupport = NULL);
46
robertphillips0dfa62c2015-11-16 06:23:31 -080047 static bool ProgramUnitTest(GrContext* context, int maxStages);
robertphillipsa13e2022015-11-11 12:01:09 -080048
robertphillips77a2e522015-10-17 07:43:27 -070049private:
joshualittde8dc7e2016-01-08 10:09:13 -080050 GrDrawingManager(GrContext* context, const GrDrawTarget::Options& optionsForDrawTargets,
51 GrSingleOwner* singleOwner)
robertphillips77a2e522015-10-17 07:43:27 -070052 : fContext(context)
bsalomon69cfe952015-11-30 13:27:47 -080053 , fOptionsForDrawTargets(optionsForDrawTargets)
joshualittde8dc7e2016-01-08 10:09:13 -080054 , fSingleOwner(singleOwner)
robertphillips77a2e522015-10-17 07:43:27 -070055 , fAbandoned(false)
robertphillips68737822015-10-29 12:12:21 -070056 , fPathRendererChain(nullptr)
robertphillipsa13e2022015-11-11 12:01:09 -080057 , fSoftwarePathRenderer(nullptr)
joshualittb8918c42015-12-18 09:59:46 -080058 , fFlushState(context->getGpu(), context->resourceProvider())
59 , fFlushing(false) {
robertphillips77a2e522015-10-17 07:43:27 -070060 }
61
62 void abandon();
63 void cleanup();
64 void reset();
65 void flush();
66
67 friend class GrContext; // for access to: ctor, abandon, reset & flush
68
69 static const int kNumPixelGeometries = 5; // The different pixel geometries
70 static const int kNumDFTOptions = 2; // DFT or no DFT
71
bsalomon648c6962015-10-23 09:06:59 -070072 GrContext* fContext;
bsalomon69cfe952015-11-30 13:27:47 -080073 GrDrawTarget::Options fOptionsForDrawTargets;
robertphillips77a2e522015-10-17 07:43:27 -070074
joshualittde8dc7e2016-01-08 10:09:13 -080075 // In debug builds we guard against improper thread handling
76 GrSingleOwner* fSingleOwner;
77
bsalomon648c6962015-10-23 09:06:59 -070078 bool fAbandoned;
79 SkTDArray<GrDrawTarget*> fDrawTargets;
robertphillips77a2e522015-10-17 07:43:27 -070080
robertphillips68737822015-10-29 12:12:21 -070081 GrPathRendererChain* fPathRendererChain;
82 GrSoftwarePathRenderer* fSoftwarePathRenderer;
robertphillipsa13e2022015-11-11 12:01:09 -080083
84 GrBatchFlushState fFlushState;
joshualittb8918c42015-12-18 09:59:46 -080085 bool fFlushing;
robertphillips77a2e522015-10-17 07:43:27 -070086};
87
88#endif