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/SkRefCnt.h" 12 #include "include/private/SkTArray.h" 13 #include "src/gpu/GrDeferredUpload.h" 14 #include "src/gpu/GrOpFlushState.h" 15 #include "src/gpu/GrResourceProvider.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 sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>, 70 GrColorType, 71 sk_sp<SkColorSpace>, 72 const SkSurfaceProps*); 73 74 // Proxy unique key management. See GrProxyProvider.h. 75 bool assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*); 76 void removeUniqueKeyFromProxy(GrTextureProxy*); 77 void processInvalidUniqueKey(const GrUniqueKey&); 78 // GrColorType is necessary to set the proxy's texture swizzle. 79 sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&, GrColorType, 80 GrSurfaceOrigin); 81 82 bool instatiateProxy(GrSurfaceProxy*); 83 84 // Creates a GPU buffer with a "dynamic" access pattern. 85 sk_sp<GrGpuBuffer> makeBuffer(GrGpuBufferType, size_t, const void* data = nullptr); 86 87 // Either finds and refs, or creates a static GPU buffer with the given data. 88 sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType, size_t, const void* data, 89 const GrUniqueKey&); 90 91 uint32_t contextID() const; 92 const GrCaps* caps() const; 93 94 private: 95 GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete; 96 GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete; 97 98 GrDrawingManager* fDrawingMgr; 99 }; 100 101 #endif 102