| 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 GrOnFlushResourceProvider; |
| 19 | class GrRenderTargetContext; |
| 20 | class GrSurfaceProxy; |
| 21 | class SkColorSpace; |
| 22 | class SkSurfaceProps; |
| 23 | |
| 24 | /* |
| 25 | * This is the base class from which all pre-flush callback objects must be derived. It |
| 26 | * provides the "preFlush" / "postFlush" interface. |
| 27 | */ |
| 28 | class GrOnFlushCallbackObject { |
| 29 | public: |
| 30 | virtual ~GrOnFlushCallbackObject() {} |
| 31 | |
| 32 | /* |
| 33 | * The onFlush callback allows subsystems (e.g., text, path renderers) to create atlases |
| 34 | * for a specific flush. All the GrOpsTask IDs required for the flush are passed into the |
| 35 | * callback. The callback should return the render target contexts used to render the atlases |
| 36 | * in 'results'. |
| 37 | */ |
| 38 | virtual void preFlush(GrOnFlushResourceProvider*, const uint32_t* opsTaskIDs, |
| 39 | int numOpsTaskIDs) = 0; |
| 40 | |
| 41 | /** |
| 42 | * Called once flushing is complete and all ops indicated by preFlush have been executed and |
| 43 | * released. startTokenForNextFlush can be used to track resources used in the current flush. |
| 44 | */ |
| 45 | virtual void postFlush(GrDeferredUploadToken startTokenForNextFlush, |
| 46 | const uint32_t* opsTaskIDs, int numOpsTaskIDs) {} |
| 47 | |
| 48 | /** |
| 49 | * Tells the callback owner to hold onto this object when freeing GPU resources. |
| 50 | */ |
| 51 | virtual bool retainOnFreeGpuResources() { return false; } |
| 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 | using UseAllocator = GrSurfaceProxy::UseAllocator; |
| 62 | |
| 63 | explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {} |
| 64 | |
| 65 | std::unique_ptr<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>, |
| 66 | GrSurfaceOrigin, GrColorType, |
| 67 | sk_sp<SkColorSpace>, |
| 68 | const SkSurfaceProps*); |
| 69 | |
| 70 | void addTextureResolveTask(sk_sp<GrTextureProxy>, GrSurfaceProxy::ResolveFlags); |
| 71 | |
| 72 | // Proxy unique key management. See GrProxyProvider.h. |
| 73 | bool assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*); |
| 74 | void removeUniqueKeyFromProxy(GrTextureProxy*); |
| 75 | void processInvalidUniqueKey(const GrUniqueKey&); |
| 76 | sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&, UseAllocator); |
| 77 | |
| 78 | bool instatiateProxy(GrSurfaceProxy*); |
| 79 | |
| 80 | // Creates a GPU buffer with a "dynamic" access pattern. |
| 81 | sk_sp<GrGpuBuffer> makeBuffer(GrGpuBufferType, size_t, const void* data = nullptr); |
| 82 | |
| 83 | // Either finds and refs, or creates a static GPU buffer with the given data. |
| 84 | sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType, size_t, const void* data, |
| 85 | const GrUniqueKey&); |
| 86 | |
| 87 | uint32_t contextID() const; |
| 88 | const GrCaps* caps() const; |
| 89 | GrOpMemoryPool* opMemoryPool() const; |
| 90 | |
| 91 | void printWarningMessage(const char* msg) const; |
| 92 | |
| 93 | private: |
| 94 | GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete; |
| 95 | GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete; |
| 96 | |
| 97 | GrDrawingManager* fDrawingMgr; |
| 98 | }; |
| 99 | |
| 100 | #endif |
| 101 | |