blob: df6c71a322eb06069815446f794bedac5e90f32a [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 -070021class GrTextContext;
22
23// Currently the DrawingManager creates a separate GrTextContext for each
24// combination of text drawing options (pixel geometry x DFT use)
25// and hands the appropriate one back given the DrawContext's request.
26//
27// It allocates a new GrDrawContext for each GrRenderTarget
28// but all of them still land in the same GrDrawTarget!
29//
30// In the future this class will allocate a new GrDrawContext for
31// each GrRenderTarget/GrDrawTarget and manage the DAG.
32class GrDrawingManager {
33public:
34 ~GrDrawingManager();
35
36 bool abandoned() const { return fAbandoned; }
robertphillips68737822015-10-29 12:12:21 -070037 void freeGpuResources();
robertphillips77a2e522015-10-17 07:43:27 -070038
39 GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps);
40
41 GrTextContext* textContext(const SkSurfaceProps& props, GrRenderTarget* rt);
42
43 // The caller automatically gets a ref on the returned drawTarget. It must
44 // be balanced by an unref call.
45 GrDrawTarget* newDrawTarget(GrRenderTarget* rt);
46
47 GrContext* getContext() { return fContext; }
48
robertphillips68737822015-10-29 12:12:21 -070049 GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
50 bool allowSW,
51 GrPathRendererChain::DrawType drawType,
52 GrPathRenderer::StencilSupport* stencilSupport = NULL);
53
robertphillips0dfa62c2015-11-16 06:23:31 -080054 static bool ProgramUnitTest(GrContext* context, int maxStages);
robertphillipsa13e2022015-11-11 12:01:09 -080055
robertphillips77a2e522015-10-17 07:43:27 -070056private:
joshualittde8dc7e2016-01-08 10:09:13 -080057 GrDrawingManager(GrContext* context, const GrDrawTarget::Options& optionsForDrawTargets,
58 GrSingleOwner* singleOwner)
robertphillips77a2e522015-10-17 07:43:27 -070059 : fContext(context)
bsalomon69cfe952015-11-30 13:27:47 -080060 , fOptionsForDrawTargets(optionsForDrawTargets)
joshualittde8dc7e2016-01-08 10:09:13 -080061 , fSingleOwner(singleOwner)
robertphillips77a2e522015-10-17 07:43:27 -070062 , fAbandoned(false)
robertphillips68737822015-10-29 12:12:21 -070063 , fNVPRTextContext(nullptr)
64 , fPathRendererChain(nullptr)
robertphillipsa13e2022015-11-11 12:01:09 -080065 , fSoftwarePathRenderer(nullptr)
joshualittb8918c42015-12-18 09:59:46 -080066 , fFlushState(context->getGpu(), context->resourceProvider())
67 , fFlushing(false) {
robertphillips77a2e522015-10-17 07:43:27 -070068 sk_bzero(fTextContexts, sizeof(fTextContexts));
69 }
70
71 void abandon();
72 void cleanup();
73 void reset();
74 void flush();
75
76 friend class GrContext; // for access to: ctor, abandon, reset & flush
77
78 static const int kNumPixelGeometries = 5; // The different pixel geometries
79 static const int kNumDFTOptions = 2; // DFT or no DFT
80
bsalomon648c6962015-10-23 09:06:59 -070081 GrContext* fContext;
bsalomon69cfe952015-11-30 13:27:47 -080082 GrDrawTarget::Options fOptionsForDrawTargets;
robertphillips77a2e522015-10-17 07:43:27 -070083
joshualittde8dc7e2016-01-08 10:09:13 -080084 // In debug builds we guard against improper thread handling
85 GrSingleOwner* fSingleOwner;
86
bsalomon648c6962015-10-23 09:06:59 -070087 bool fAbandoned;
88 SkTDArray<GrDrawTarget*> fDrawTargets;
robertphillips77a2e522015-10-17 07:43:27 -070089
bsalomon648c6962015-10-23 09:06:59 -070090 GrTextContext* fNVPRTextContext;
91 GrTextContext* fTextContexts[kNumPixelGeometries][kNumDFTOptions];
robertphillips68737822015-10-29 12:12:21 -070092
93 GrPathRendererChain* fPathRendererChain;
94 GrSoftwarePathRenderer* fSoftwarePathRenderer;
robertphillipsa13e2022015-11-11 12:01:09 -080095
96 GrBatchFlushState fFlushState;
joshualittb8918c42015-12-18 09:59:46 -080097 bool fFlushing;
robertphillips77a2e522015-10-17 07:43:27 -070098};
99
100#endif