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 | |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 11 | #include "GrDeferredUpload.h" |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 12 | #include "GrOpFlushState.h" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 13 | #include "GrResourceProvider.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 14 | #include "SkRefCnt.h" |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 15 | #include "SkTArray.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 16 | |
| 17 | class GrDrawingManager; |
| 18 | class GrOpList; |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 19 | class GrOnFlushResourceProvider; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 20 | class GrRenderTargetOpList; |
| 21 | class GrRenderTargetContext; |
| 22 | class GrSurfaceProxy; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 23 | class SkColorSpace; |
| 24 | class SkSurfaceProps; |
| 25 | |
| 26 | /* |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 27 | * 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] | 28 | * provides the "preFlush" / "postFlush" interface. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 29 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 30 | class GrOnFlushCallbackObject { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 31 | public: |
Brian Salomon | 238069b | 2018-07-11 15:58:57 -0400 | [diff] [blame] | 32 | virtual ~GrOnFlushCallbackObject() {} |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 33 | |
| 34 | /* |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 35 | * The onFlush callback allows subsystems (e.g., text, path renderers) to create atlases |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 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 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 40 | virtual void preFlush(GrOnFlushResourceProvider*, |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 41 | const uint32_t* opListIDs, int numOpListIDs, |
| 42 | SkTArray<sk_sp<GrRenderTargetContext>>* results) = 0; |
| 43 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 44 | /** |
| 45 | * 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] | 46 | * 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] | 47 | */ |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 48 | virtual void postFlush(GrDeferredUploadToken startTokenForNextFlush, |
| 49 | const uint32_t* opListIDs, int numOpListIDs) {} |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 50 | |
| 51 | /** |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 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 | */ |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 57 | virtual bool retainOnFreeGpuResources() { return false; } |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | /* |
| 61 | * 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] | 62 | * onFlush callbacks and is intended to limit the functionality available to them. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 63 | * It should never have additional data members or virtual methods. |
| 64 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 65 | class GrOnFlushResourceProvider { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 66 | public: |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 67 | explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {} |
| 68 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 69 | #if 0 |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 70 | sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc&, |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 71 | GrSurfaceOrigin, |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 72 | sk_sp<SkColorSpace>, |
| 73 | const SkSurfaceProps*); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 74 | #endif |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 75 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 76 | sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>, |
| 77 | sk_sp<SkColorSpace>, |
| 78 | const SkSurfaceProps*); |
| 79 | |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 80 | // Proxy unique key management. See GrProxyProvider.h. |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 81 | bool assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*); |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 82 | void removeUniqueKeyFromProxy(GrTextureProxy*); |
| 83 | void processInvalidUniqueKey(const GrUniqueKey&); |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 84 | sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&, GrSurfaceOrigin); |
| 85 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 86 | bool instatiateProxy(GrSurfaceProxy*); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 87 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 88 | // Creates a GPU buffer with a "dynamic" access pattern. |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 89 | sk_sp<GrGpuBuffer> makeBuffer(GrGpuBufferType, size_t, const void* data = nullptr); |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 90 | |
Chris Dalton | e9e91dd | 2017-07-14 08:48:57 -0600 | [diff] [blame] | 91 | // 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] | 92 | sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType, size_t, const void* data, |
| 93 | const GrUniqueKey&); |
Chris Dalton | e9e91dd | 2017-07-14 08:48:57 -0600 | [diff] [blame] | 94 | |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 95 | uint32_t contextID() const; |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 96 | const GrCaps* caps() const; |
| 97 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 98 | private: |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 99 | GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete; |
| 100 | GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 101 | |
| 102 | GrDrawingManager* fDrawingMgr; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | #endif |