blob: c72dad976bd184b7b88c48a143d8c40ef5c96507 [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;
robertphillips68737822015-10-29 12:12:21 -070019class GrSoftwarePathRenderer;
robertphillips77a2e522015-10-17 07:43:27 -070020class GrTextContext;
21
22// Currently the DrawingManager creates a separate GrTextContext for each
23// combination of text drawing options (pixel geometry x DFT use)
24// and hands the appropriate one back given the DrawContext's request.
25//
26// It allocates a new GrDrawContext for each GrRenderTarget
27// but all of them still land in the same GrDrawTarget!
28//
29// In the future this class will allocate a new GrDrawContext for
30// each GrRenderTarget/GrDrawTarget and manage the DAG.
31class GrDrawingManager {
32public:
33 ~GrDrawingManager();
34
35 bool abandoned() const { return fAbandoned; }
robertphillips68737822015-10-29 12:12:21 -070036 void freeGpuResources();
robertphillips77a2e522015-10-17 07:43:27 -070037
38 GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps);
39
40 GrTextContext* textContext(const SkSurfaceProps& props, GrRenderTarget* rt);
41
42 // The caller automatically gets a ref on the returned drawTarget. It must
43 // be balanced by an unref call.
44 GrDrawTarget* newDrawTarget(GrRenderTarget* rt);
45
46 GrContext* getContext() { return fContext; }
47
robertphillips68737822015-10-29 12:12:21 -070048 GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
49 bool allowSW,
50 GrPathRendererChain::DrawType drawType,
51 GrPathRenderer::StencilSupport* stencilSupport = NULL);
52
robertphillips0dfa62c2015-11-16 06:23:31 -080053 static bool ProgramUnitTest(GrContext* context, int maxStages);
robertphillipsa13e2022015-11-11 12:01:09 -080054
robertphillips77a2e522015-10-17 07:43:27 -070055private:
joshualitt94da2922016-01-07 13:22:24 -080056 GrDrawingManager(GrContext* context, const GrDrawTarget::Options& optionsForDrawTargets)
robertphillips77a2e522015-10-17 07:43:27 -070057 : fContext(context)
bsalomon69cfe952015-11-30 13:27:47 -080058 , fOptionsForDrawTargets(optionsForDrawTargets)
robertphillips77a2e522015-10-17 07:43:27 -070059 , fAbandoned(false)
robertphillips68737822015-10-29 12:12:21 -070060 , fNVPRTextContext(nullptr)
61 , fPathRendererChain(nullptr)
robertphillipsa13e2022015-11-11 12:01:09 -080062 , fSoftwarePathRenderer(nullptr)
joshualittb8918c42015-12-18 09:59:46 -080063 , fFlushState(context->getGpu(), context->resourceProvider())
64 , fFlushing(false) {
robertphillips77a2e522015-10-17 07:43:27 -070065 sk_bzero(fTextContexts, sizeof(fTextContexts));
66 }
67
68 void abandon();
69 void cleanup();
70 void reset();
71 void flush();
72
73 friend class GrContext; // for access to: ctor, abandon, reset & flush
74
75 static const int kNumPixelGeometries = 5; // The different pixel geometries
76 static const int kNumDFTOptions = 2; // DFT or no DFT
77
bsalomon648c6962015-10-23 09:06:59 -070078 GrContext* fContext;
bsalomon69cfe952015-11-30 13:27:47 -080079 GrDrawTarget::Options fOptionsForDrawTargets;
robertphillips77a2e522015-10-17 07:43:27 -070080
bsalomon648c6962015-10-23 09:06:59 -070081 bool fAbandoned;
82 SkTDArray<GrDrawTarget*> fDrawTargets;
robertphillips77a2e522015-10-17 07:43:27 -070083
bsalomon648c6962015-10-23 09:06:59 -070084 GrTextContext* fNVPRTextContext;
85 GrTextContext* fTextContexts[kNumPixelGeometries][kNumDFTOptions];
robertphillips68737822015-10-29 12:12:21 -070086
87 GrPathRendererChain* fPathRendererChain;
88 GrSoftwarePathRenderer* fSoftwarePathRenderer;
robertphillipsa13e2022015-11-11 12:01:09 -080089
90 GrBatchFlushState fFlushState;
joshualittb8918c42015-12-18 09:59:46 -080091 bool fFlushing;
robertphillips77a2e522015-10-17 07:43:27 -070092};
93
94#endif