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 "GrDeferredUpload.h" 12 #include "GrOpFlushState.h" 13 #include "GrResourceProvider.h" 14 #include "SkRefCnt.h" 15 #include "SkTArray.h" 16 17 class GrDrawingManager; 18 class GrOpList; 19 class GrOnFlushResourceProvider; 20 class GrRenderTargetOpList; 21 class GrRenderTargetContext; 22 class GrSurfaceProxy; 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: ~GrOnFlushCallbackObject()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. startTokenForNextFlush can be used to track resources used in the current flush. 47 */ postFlush(GrDeferredUploadToken startTokenForNextFlush,const uint32_t * opListIDs,int numOpListIDs)48 virtual void postFlush(GrDeferredUploadToken startTokenForNextFlush, 49 const uint32_t* opListIDs, int numOpListIDs) {} 50 51 /** 52 * Tells the callback owner to hold onto this object when freeing GPU resources 53 * 54 * In particular, GrDrawingManager::freeGPUResources() deletes all the path renderers. 55 * Any OnFlushCallbackObject associated with a path renderer will need to be deleted. 56 */ retainOnFreeGpuResources()57 virtual bool retainOnFreeGpuResources() { return false; } 58 }; 59 60 /* 61 * This class is a shallow wrapper around the drawing manager. It is passed into the 62 * onFlush callbacks and is intended to limit the functionality available to them. 63 * It should never have additional data members or virtual methods. 64 */ 65 class GrOnFlushResourceProvider { 66 public: GrOnFlushResourceProvider(GrDrawingManager * drawingMgr)67 explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {} 68 69 #if 0 70 sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc&, 71 GrSurfaceOrigin, 72 sk_sp<SkColorSpace>, 73 const SkSurfaceProps*); 74 #endif 75 76 sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>, 77 sk_sp<SkColorSpace>, 78 const SkSurfaceProps*); 79 80 // Proxy unique key management. See GrProxyProvider.h. 81 bool assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*); 82 void removeUniqueKeyFromProxy(GrTextureProxy*); 83 void processInvalidUniqueKey(const GrUniqueKey&); 84 sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&, GrSurfaceOrigin); 85 86 bool instatiateProxy(GrSurfaceProxy*); 87 88 // Creates a GPU buffer with a "dynamic" access pattern. 89 sk_sp<GrBuffer> makeBuffer(GrBufferType, size_t, const void* data = nullptr); 90 91 // Either finds and refs, or creates a static GPU buffer with the given data. 92 sk_sp<const GrBuffer> findOrMakeStaticBuffer(GrBufferType, size_t, const void* data, 93 const GrUniqueKey&); 94 95 uint32_t contextID() const; 96 const GrCaps* caps() const; 97 98 private: 99 GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete; 100 GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete; 101 102 GrDrawingManager* fDrawingMgr; 103 }; 104 105 #endif 106