Home | History | Annotate | Download | only in gpu
      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     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     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     void flushIfNecessary() {
     60         if (fContext->getResourceCache()->requestsFlush()) {
     61             this->internalFlush(GrResourceCache::kCacheRequested);
     62         } else if (fIsImmediateMode) {
     63             this->internalFlush(GrResourceCache::kImmediateMode);
     64         }
     65     }
     66 
     67     static bool ProgramUnitTest(GrContext* context, int maxStages);
     68 
     69     void prepareSurfaceForExternalIO(GrSurface*);
     70 
     71     void addPreFlushCallbackObject(sk_sp<GrPreFlushCallbackObject> preFlushCBObject);
     72 
     73 private:
     74     GrDrawingManager(GrContext* context,
     75                      const GrRenderTargetOpList::Options& optionsForOpLists,
     76                      const GrPathRendererChain::Options& optionsForPathRendererChain,
     77                      bool isImmediateMode, GrSingleOwner* singleOwner)
     78         : 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         , fIsImmediateMode(isImmediateMode) {
     89     }
     90 
     91     void abandon();
     92     void cleanup();
     93     void reset();
     94     void flush() { this->internalFlush(GrResourceCache::FlushType::kExternal); }
     95     void internalFlush(GrResourceCache::FlushType);
     96 
     97     friend class GrContext;  // for access to: ctor, abandon, reset & flush
     98     friend class GrPreFlushResourceProvider; // this is just a shallow wrapper around this class
     99 
    100     static const int kNumPixelGeometries = 5; // The different pixel geometries
    101     static const int kNumDFTOptions = 2;      // DFT or no DFT
    102 
    103     GrContext*                        fContext;
    104     GrRenderTargetOpList::Options     fOptionsForOpLists;
    105     GrPathRendererChain::Options      fOptionsForPathRendererChain;
    106 
    107     // In debug builds we guard against improper thread handling
    108     GrSingleOwner*                    fSingleOwner;
    109 
    110     bool                              fAbandoned;
    111     SkTDArray<GrOpList*>              fOpLists;
    112 
    113     std::unique_ptr<GrAtlasTextContext> fAtlasTextContext;
    114 
    115     GrPathRendererChain*              fPathRendererChain;
    116     GrSoftwarePathRenderer*           fSoftwarePathRenderer;
    117 
    118     GrOpFlushState                    fFlushState;
    119     bool                              fFlushing;
    120 
    121     bool                              fIsImmediateMode;
    122 
    123     SkTArray<sk_sp<GrPreFlushCallbackObject>> fPreFlushCBObjects;
    124 };
    125 
    126 #endif
    127