Line data Source code
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 "GrOpFlushState.h"
12 : #include "GrPathRenderer.h"
13 : #include "GrPathRendererChain.h"
14 : #include "GrPreFlushResourceProvider.h"
15 : #include "GrRenderTargetOpList.h"
16 : #include "GrResourceCache.h"
17 : #include "SkTArray.h"
18 : #include "text/GrAtlasTextContext.h"
19 :
20 : class GrContext;
21 : class GrRenderTargetContext;
22 : class GrRenderTargetProxy;
23 : class GrSingleOWner;
24 : class GrSoftwarePathRenderer;
25 : class GrTextureContext;
26 : class GrTextureOpList;
27 :
28 : // The GrDrawingManager allocates a new GrRenderTargetContext for each GrRenderTarget
29 : // but all of them still land in the same GrOpList!
30 : //
31 : // In the future this class will allocate a new GrRenderTargetContext for
32 : // each GrRenderTarget/GrOpList and manage the DAG.
33 : class GrDrawingManager {
34 : public:
35 : ~GrDrawingManager();
36 :
37 0 : bool wasAbandoned() const { return fAbandoned; }
38 : void freeGpuResources();
39 :
40 : sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
41 : sk_sp<SkColorSpace>,
42 : const SkSurfaceProps*);
43 : sk_sp<GrTextureContext> makeTextureContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>);
44 :
45 : // The caller automatically gets a ref on the returned opList. It must
46 : // be balanced by an unref call.
47 : GrRenderTargetOpList* newOpList(GrRenderTargetProxy* rtp);
48 : GrTextureOpList* newOpList(GrTextureProxy* textureProxy);
49 :
50 0 : GrContext* getContext() { return fContext; }
51 :
52 : GrAtlasTextContext* getAtlasTextContext();
53 :
54 : GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
55 : bool allowSW,
56 : GrPathRendererChain::DrawType drawType,
57 : GrPathRenderer::StencilSupport* stencilSupport = NULL);
58 :
59 0 : void flushIfNecessary() {
60 0 : if (fContext->getResourceCache()->requestsFlush()) {
61 0 : this->internalFlush(nullptr, GrResourceCache::kCacheRequested);
62 0 : } else if (fIsImmediateMode) {
63 0 : this->internalFlush(nullptr, GrResourceCache::kImmediateMode);
64 : }
65 0 : }
66 :
67 : static bool ProgramUnitTest(GrContext* context, int maxStages);
68 :
69 : void prepareSurfaceForExternalIO(GrSurfaceProxy*);
70 :
71 : void addPreFlushCallbackObject(sk_sp<GrPreFlushCallbackObject> preFlushCBObject);
72 :
73 : private:
74 0 : GrDrawingManager(GrContext* context,
75 : const GrRenderTargetOpList::Options& optionsForOpLists,
76 : const GrPathRendererChain::Options& optionsForPathRendererChain,
77 : bool isImmediateMode, GrSingleOwner* singleOwner)
78 0 : : fContext(context)
79 : , fOptionsForOpLists(optionsForOpLists)
80 : , fOptionsForPathRendererChain(optionsForPathRendererChain)
81 : , fSingleOwner(singleOwner)
82 : , fAbandoned(false)
83 : , fAtlasTextContext(nullptr)
84 : , fPathRendererChain(nullptr)
85 : , fSoftwarePathRenderer(nullptr)
86 : , fFlushState(context->getGpu(), context->resourceProvider())
87 : , fFlushing(false)
88 0 : , fIsImmediateMode(isImmediateMode) {
89 0 : }
90 :
91 : void abandon();
92 : void cleanup();
93 : void reset();
94 0 : void flush(GrSurfaceProxy* proxy) {
95 0 : this->internalFlush(proxy, GrResourceCache::FlushType::kExternal);
96 0 : }
97 : void internalFlush(GrSurfaceProxy*, GrResourceCache::FlushType);
98 :
99 : friend class GrContext; // for access to: ctor, abandon, reset & flush
100 : friend class GrContextPriv; // access to: flush
101 : friend class GrPreFlushResourceProvider; // this is just a shallow wrapper around this class
102 :
103 : static const int kNumPixelGeometries = 5; // The different pixel geometries
104 : static const int kNumDFTOptions = 2; // DFT or no DFT
105 :
106 : GrContext* fContext;
107 : GrRenderTargetOpList::Options fOptionsForOpLists;
108 : GrPathRendererChain::Options fOptionsForPathRendererChain;
109 :
110 : // In debug builds we guard against improper thread handling
111 : GrSingleOwner* fSingleOwner;
112 :
113 : bool fAbandoned;
114 : SkTDArray<GrOpList*> fOpLists;
115 :
116 : std::unique_ptr<GrAtlasTextContext> fAtlasTextContext;
117 :
118 : GrPathRendererChain* fPathRendererChain;
119 : GrSoftwarePathRenderer* fSoftwarePathRenderer;
120 :
121 : GrOpFlushState fFlushState;
122 : bool fFlushing;
123 :
124 : bool fIsImmediateMode;
125 :
126 : SkTArray<sk_sp<GrPreFlushCallbackObject>> fPreFlushCBObjects;
127 : };
128 :
129 : #endif
|