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/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. All the GrRenderTask IDs required for the flush are passed into the 30 * callback. 31 */ 32 virtual void preFlush(GrOnFlushResourceProvider*, SkSpan<const uint32_t> renderTaskIDs) = 0; 33 34 /** 35 * Called once flushing is complete and all renderTasks indicated by preFlush have been executed 36 * and released. startTokenForNextFlush can be used to track resources used in the current 37 * flush. 38 */ postFlush(GrDeferredUploadToken startTokenForNextFlush,SkSpan<const uint32_t> renderTaskIDs)39 virtual void postFlush(GrDeferredUploadToken startTokenForNextFlush, 40 SkSpan<const uint32_t> renderTaskIDs) {} 41 42 /** 43 * Tells the callback owner to hold onto this object when freeing GPU resources. 44 */ retainOnFreeGpuResources()45 virtual bool retainOnFreeGpuResources() { return false; } 46 }; 47 48 /* 49 * This class is a shallow wrapper around the drawing manager. It is passed into the 50 * onFlush callbacks and is intended to limit the functionality available to them. 51 * It should never have additional data members or virtual methods. 52 */ 53 class GrOnFlushResourceProvider { 54 public: GrOnFlushResourceProvider(GrDrawingManager * drawingMgr)55 explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {} 56 57 bool instatiateProxy(GrSurfaceProxy*); 58 59 const GrCaps* caps() const; 60 61 private: 62 GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete; 63 GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete; 64 65 GrDrawingManager* fDrawingMgr; 66 }; 67 68 #endif 69