1/*
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
11#include "GrDrawTarget.h"
12#include "GrBatchFlushState.h"
13#include "GrPathRendererChain.h"
14#include "GrPathRenderer.h"
15#include "SkTDArray.h"
16
17class GrContext;
18class GrDrawContext;
19class GrSingleOWner;
20class GrSoftwarePathRenderer;
21
22// The GrDrawingManager allocates a new GrDrawContext for each GrRenderTarget
23// 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; }
32    void freeGpuResources();
33
34    GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps*);
35
36    // The caller automatically gets a ref on the returned drawTarget. It must
37    // be balanced by an unref call.
38    GrDrawTarget* newDrawTarget(GrRenderTarget* rt);
39
40    GrContext* getContext() { return fContext; }
41
42    GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
43                                    bool allowSW,
44                                    GrPathRendererChain::DrawType drawType,
45                                    GrPathRenderer::StencilSupport* stencilSupport = NULL);
46
47    static bool ProgramUnitTest(GrContext* context, int maxStages);
48
49private:
50    GrDrawingManager(GrContext* context, const GrDrawTarget::Options& optionsForDrawTargets,
51                     GrSingleOwner* singleOwner)
52        : fContext(context)
53        , fOptionsForDrawTargets(optionsForDrawTargets)
54        , fSingleOwner(singleOwner)
55        , fAbandoned(false)
56        , fPathRendererChain(nullptr)
57        , fSoftwarePathRenderer(nullptr)
58        , fFlushState(context->getGpu(), context->resourceProvider())
59        , fFlushing(false) {
60    }
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
72    GrContext*                  fContext;
73    GrDrawTarget::Options       fOptionsForDrawTargets;
74
75    // In debug builds we guard against improper thread handling
76    GrSingleOwner*              fSingleOwner;
77
78    bool                        fAbandoned;
79    SkTDArray<GrDrawTarget*>    fDrawTargets;
80
81    GrPathRendererChain*        fPathRendererChain;
82    GrSoftwarePathRenderer*     fSoftwarePathRenderer;
83
84    GrBatchFlushState           fFlushState;
85    bool                        fFlushing;
86};
87
88#endif
89