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 "include/core/SkSpan.h" 12 #include "src/gpu/ganesh/GrDeferredUpload.h" 13 14 class GrCaps; 15 class GrDrawingManager; 16 class GrOnFlushResourceProvider; 17 class GrSurfaceProxy; 18 19 /* 20 * This is the base class from which all pre-flush callback objects must be derived. It 21 * provides the "preFlush" / "postFlush" interface. 22 */ 23 class GrOnFlushCallbackObject { 24 public: ~GrOnFlushCallbackObject()25 virtual ~GrOnFlushCallbackObject() {} 26 27 /* 28 * The preFlush callback allows subsystems (e.g., text, path renderers) to create atlases 29 * for a specific flush. 30 * 31 * Returns true on success; false on memory allocation failure 32 */ 33 virtual bool preFlush(GrOnFlushResourceProvider*) = 0; 34 35 /** 36 * Called once flushing is complete. startTokenForNextFlush can be used to track resources 37 * used in the current flush. 38 */ postFlush(skgpu::AtlasToken startTokenForNextFlush)39 virtual void postFlush(skgpu::AtlasToken startTokenForNextFlush) {} 40 41 /** 42 * Tells the callback owner to hold onto this object when freeing GPU resources. 43 */ retainOnFreeGpuResources()44 virtual bool retainOnFreeGpuResources() { return false; } 45 }; 46 47 /* 48 * This class is a shallow wrapper around the drawing manager. It is passed into the 49 * onFlush callbacks and is intended to limit the functionality available to them. 50 * It should never have additional data members or virtual methods. 51 */ 52 class GrOnFlushResourceProvider { 53 public: GrOnFlushResourceProvider(GrDrawingManager * drawingMgr)54 explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {} 55 56 bool SK_WARN_UNUSED_RESULT instantiateProxy(GrSurfaceProxy*); 57 58 const GrCaps* caps() const; 59 60 #if GR_TEST_UTILS 61 bool failFlushTimeCallbacks() const; 62 #endif 63 64 private: 65 GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete; 66 GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete; 67 68 GrDrawingManager* fDrawingMgr; 69 }; 70 71 #endif 72