• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "GrPathRenderer.h"
12 #include "GrPathRendererChain.h"
13 #include "GrRenderTargetOpList.h"
14 #include "GrResourceCache.h"
15 #include "SkTArray.h"
16 #include "text/GrAtlasTextContext.h"
17 
18 class GrContext;
19 class GrCoverageCountingPathRenderer;
20 class GrOnFlushCallbackObject;
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 
wasAbandoned()37     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                                                          bool managedOpList = true);
44     sk_sp<GrTextureContext> makeTextureContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>);
45 
46     // The caller automatically gets a ref on the returned opList. It must
47     // be balanced by an unref call.
48     // A managed opList is controlled by the drawing manager (i.e., sorted & flushed with the
49     // other). An unmanaged one is created and used by the onFlushCallback.
50     sk_sp<GrRenderTargetOpList> newRTOpList(GrRenderTargetProxy* rtp, bool managedOpList);
51     sk_sp<GrTextureOpList> newTextureOpList(GrTextureProxy* textureProxy);
52 
getContext()53     GrContext* getContext() { return fContext; }
54 
55     GrAtlasTextContext* getAtlasTextContext();
56 
57     GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
58                                     bool allowSW,
59                                     GrPathRendererChain::DrawType drawType,
60                                     GrPathRenderer::StencilSupport* stencilSupport = nullptr);
61 
62     // Returns a direct pointer to the coverage counting path renderer, or null if it is not
63     // supported and turned on.
64     GrCoverageCountingPathRenderer* getCoverageCountingPathRenderer();
65 
flushIfNecessary()66     void flushIfNecessary() {
67         GrResourceCache* resourceCache = fContext->contextPriv().getResourceCache();
68         if (resourceCache && resourceCache->requestsFlush()) {
69             this->internalFlush(nullptr, GrResourceCache::kCacheRequested, 0, nullptr);
70         }
71     }
72 
73     static bool ProgramUnitTest(GrContext* context, int maxStages, int maxLevels);
74 
75     GrSemaphoresSubmitted prepareSurfaceForExternalIO(GrSurfaceProxy*,
76                                                       int numSemaphores,
77                                                       GrBackendSemaphore backendSemaphores[]);
78 
79     void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
80     void testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject*);
81 
82     void moveOpListsToDDL(SkDeferredDisplayList* ddl);
83     void copyOpListsFromDDL(const SkDeferredDisplayList*, GrRenderTargetProxy* newDest);
84 
85 private:
GrDrawingManager(GrContext * context,const GrPathRendererChain::Options & optionsForPathRendererChain,const GrAtlasTextContext::Options & optionsForAtlasTextContext,GrSingleOwner * singleOwner)86     GrDrawingManager(GrContext* context,
87                      const GrPathRendererChain::Options& optionsForPathRendererChain,
88                      const GrAtlasTextContext::Options& optionsForAtlasTextContext,
89                      GrSingleOwner* singleOwner)
90             : fContext(context)
91             , fOptionsForPathRendererChain(optionsForPathRendererChain)
92             , fOptionsForAtlasTextContext(optionsForAtlasTextContext)
93             , fSingleOwner(singleOwner)
94             , fAbandoned(false)
95             , fAtlasTextContext(nullptr)
96             , fPathRendererChain(nullptr)
97             , fSoftwarePathRenderer(nullptr)
98             , fFlushing(false) {}
99 
100     void abandon();
101     void cleanup();
102 
103     // return true if any opLists were actually executed; false otherwise
104     bool executeOpLists(int startIndex, int stopIndex, GrOpFlushState*);
105 
106     GrSemaphoresSubmitted flush(GrSurfaceProxy* proxy,
107                                 int numSemaphores = 0,
108                                 GrBackendSemaphore backendSemaphores[] = nullptr) {
109         return this->internalFlush(proxy, GrResourceCache::FlushType::kExternal,
110                                    numSemaphores, backendSemaphores);
111     }
112     GrSemaphoresSubmitted internalFlush(GrSurfaceProxy*,
113                                         GrResourceCache::FlushType,
114                                         int numSemaphores,
115                                         GrBackendSemaphore backendSemaphores[]);
116 
117     friend class GrContext;  // for access to: ctor, abandon, reset & flush
118     friend class GrContextPriv; // access to: flush
119     friend class GrOnFlushResourceProvider; // this is just a shallow wrapper around this class
120 
121     static const int kNumPixelGeometries = 5; // The different pixel geometries
122     static const int kNumDFTOptions = 2;      // DFT or no DFT
123 
124     GrContext*                        fContext;
125     GrPathRendererChain::Options      fOptionsForPathRendererChain;
126     GrAtlasTextContext::Options       fOptionsForAtlasTextContext;
127 
128     // In debug builds we guard against improper thread handling
129     GrSingleOwner*                    fSingleOwner;
130 
131     bool                              fAbandoned;
132     SkTArray<sk_sp<GrOpList>>         fOpLists;
133     // These are the IDs of the opLists currently being flushed (in internalFlush)
134     SkSTArray<8, uint32_t, true>      fFlushingOpListIDs;
135     // These are the new opLists generated by the onFlush CBs
136     SkSTArray<8, sk_sp<GrOpList>>     fOnFlushCBOpLists;
137 
138     std::unique_ptr<GrAtlasTextContext> fAtlasTextContext;
139 
140     GrPathRendererChain*              fPathRendererChain;
141     GrSoftwarePathRenderer*           fSoftwarePathRenderer;
142 
143     GrTokenTracker                    fTokenTracker;
144     bool                              fFlushing;
145 
146     SkTArray<GrOnFlushCallbackObject*> fOnFlushCBObjects;
147 };
148 
149 #endif
150