Home | History | Annotate | Download | only in gpu
      1 /*
      2  * Copyright 2017 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 GrOnFlushResourceProvider_DEFINED
      9 #define GrOnFlushResourceProvider_DEFINED
     10 
     11 #include "GrTypes.h"
     12 #include "GrResourceProvider.h"
     13 #include "SkRefCnt.h"
     14 #include "SkTArray.h"
     15 
     16 class GrDrawingManager;
     17 class GrOpList;
     18 class GrOnFlushResourceProvider;
     19 class GrRenderTargetOpList;
     20 class GrRenderTargetContext;
     21 class GrSurfaceProxy;
     22 
     23 class SkColorSpace;
     24 class SkSurfaceProps;
     25 
     26 /*
     27  * This is the base class from which all pre-flush callback objects must be derived. It
     28  * provides the "preFlush" / "postFlush" interface.
     29  */
     30 class GrOnFlushCallbackObject {
     31 public:
     32     virtual ~GrOnFlushCallbackObject() { }
     33 
     34     /*
     35      * The onFlush callback allows subsystems (e.g., text, path renderers) to create atlases
     36      * for a specific flush. All the GrOpList IDs required for the flush are passed into the
     37      * callback. The callback should return the render target contexts used to render the atlases
     38      * in 'results'.
     39      */
     40     virtual void preFlush(GrOnFlushResourceProvider*,
     41                           const uint32_t* opListIDs, int numOpListIDs,
     42                           SkTArray<sk_sp<GrRenderTargetContext>>* results) = 0;
     43 
     44     /**
     45      * Called once flushing is complete and all ops indicated by preFlush have been executed and
     46      * released.
     47      */
     48     virtual void postFlush() {}
     49 
     50 private:
     51     typedef SkRefCnt INHERITED;
     52 };
     53 
     54 /*
     55  * This class is a shallow wrapper around the drawing manager. It is passed into the
     56  * onFlush callbacks and is intended to limit the functionality available to them.
     57  * It should never have additional data members or virtual methods.
     58  */
     59 class GrOnFlushResourceProvider {
     60 public:
     61     sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc& desc,
     62                                                          sk_sp<SkColorSpace> colorSpace,
     63                                                          const SkSurfaceProps* props);
     64 
     65     // TODO: we only need this entry point as long as we have to pre-allocate the atlas.
     66     // Remove it ASAP.
     67     sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy> proxy,
     68                                                          sk_sp<SkColorSpace> colorSpace,
     69                                                          const SkSurfaceProps* props);
     70 
     71     // Creates a GPU buffer with a "dynamic" access pattern.
     72     sk_sp<GrBuffer> makeBuffer(GrBufferType, size_t, const void* data = nullptr);
     73 
     74     // Either finds and refs, or creates a static GPU buffer with the given data.
     75     sk_sp<GrBuffer> findOrMakeStaticBuffer(const GrUniqueKey&, GrBufferType,
     76                                            size_t, const void* data);
     77 
     78     const GrCaps* caps() const;
     79 
     80 private:
     81     explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {}
     82     GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete;
     83     GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete;
     84 
     85     GrDrawingManager* fDrawingMgr;
     86 
     87     friend class GrDrawingManager; // to construct this type.
     88 };
     89 
     90 #endif
     91