Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 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 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 8 | #ifndef GrOnFlushResourceProvider_DEFINED |
| 9 | #define GrOnFlushResourceProvider_DEFINED |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 16 | |
| 17 | class GrDrawingManager; |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 18 | class GrOnFlushResourceProvider; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 19 | class GrRenderTargetContext; |
| 20 | class GrSurfaceProxy; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 21 | class SkColorSpace; |
| 22 | class SkSurfaceProps; |
| 23 | |
| 24 | /* |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 25 | * This is the base class from which all pre-flush callback objects must be derived. It |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 26 | * provides the "preFlush" / "postFlush" interface. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 27 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 28 | class GrOnFlushCallbackObject { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 29 | public: |
Brian Salomon | 238069b | 2018-07-11 15:58:57 -0400 | [diff] [blame] | 30 | virtual ~GrOnFlushCallbackObject() {} |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 31 | |
| 32 | /* |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 33 | * The onFlush callback allows subsystems (e.g., text, path renderers) to create atlases |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 34 | * for a specific flush. All the GrOpsTask IDs required for the flush are passed into the |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 35 | * callback. The callback should return the render target contexts used to render the atlases |
| 36 | * in 'results'. |
| 37 | */ |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 38 | virtual void preFlush(GrOnFlushResourceProvider*, const uint32_t* opsTaskIDs, |
| 39 | int numOpsTaskIDs) = 0; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 40 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 41 | /** |
| 42 | * Called once flushing is complete and all ops indicated by preFlush have been executed and |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 43 | * released. startTokenForNextFlush can be used to track resources used in the current flush. |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 44 | */ |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 45 | virtual void postFlush(GrDeferredUploadToken startTokenForNextFlush, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 46 | const uint32_t* opsTaskIDs, int numOpsTaskIDs) {} |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 47 | |
| 48 | /** |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 49 | * Tells the callback owner to hold onto this object when freeing GPU resources |
| 50 | * |
| 51 | * In particular, GrDrawingManager::freeGPUResources() deletes all the path renderers. |
| 52 | * Any OnFlushCallbackObject associated with a path renderer will need to be deleted. |
| 53 | */ |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 54 | virtual bool retainOnFreeGpuResources() { return false; } |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | /* |
| 58 | * This class is a shallow wrapper around the drawing manager. It is passed into the |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 59 | * onFlush callbacks and is intended to limit the functionality available to them. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 60 | * It should never have additional data members or virtual methods. |
| 61 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 62 | class GrOnFlushResourceProvider { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 63 | public: |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 64 | using UseAllocator = GrSurfaceProxy::UseAllocator; |
| 65 | |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 66 | explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {} |
| 67 | |
Greg Daniel | d11ae2e | 2020-02-10 16:36:07 -0500 | [diff] [blame] | 68 | std::unique_ptr<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>, |
| 69 | GrSurfaceOrigin, GrColorType, |
| 70 | sk_sp<SkColorSpace>, |
| 71 | const SkSurfaceProps*); |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 72 | |
| 73 | void addTextureResolveTask(sk_sp<GrTextureProxy>, GrSurfaceProxy::ResolveFlags); |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 74 | |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 75 | // Proxy unique key management. See GrProxyProvider.h. |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 76 | bool assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*); |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 77 | void removeUniqueKeyFromProxy(GrTextureProxy*); |
| 78 | void processInvalidUniqueKey(const GrUniqueKey&); |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 79 | sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&, UseAllocator); |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 80 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 81 | bool instatiateProxy(GrSurfaceProxy*); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 82 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 83 | // Creates a GPU buffer with a "dynamic" access pattern. |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 84 | sk_sp<GrGpuBuffer> makeBuffer(GrGpuBufferType, size_t, const void* data = nullptr); |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 85 | |
Chris Dalton | e9e91dd | 2017-07-14 08:48:57 -0600 | [diff] [blame] | 86 | // Either finds and refs, or creates a static GPU buffer with the given data. |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 87 | sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType, size_t, const void* data, |
| 88 | const GrUniqueKey&); |
Chris Dalton | e9e91dd | 2017-07-14 08:48:57 -0600 | [diff] [blame] | 89 | |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 90 | uint32_t contextID() const; |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 91 | const GrCaps* caps() const; |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 92 | GrOpMemoryPool* opMemoryPool() const; |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 93 | |
Chris Dalton | 5a5fe79 | 2020-02-15 11:41:30 -0700 | [diff] [blame] | 94 | void printWarningMessage(const char* msg) const; |
Chris Dalton | a378b45 | 2019-12-11 13:24:11 -0500 | [diff] [blame] | 95 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 96 | private: |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 97 | GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete; |
| 98 | GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 99 | |
| 100 | GrDrawingManager* fDrawingMgr; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | #endif |