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 | |
| 11 | #include "GrTypes.h" |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 12 | #include "GrDeferredUpload.h" |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 13 | #include "GrOpFlushState.h" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 14 | #include "GrResourceProvider.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 15 | #include "SkRefCnt.h" |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 16 | #include "SkTArray.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 17 | |
| 18 | class GrDrawingManager; |
| 19 | class GrOpList; |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 20 | class GrOnFlushResourceProvider; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 21 | class GrRenderTargetOpList; |
| 22 | class GrRenderTargetContext; |
| 23 | class GrSurfaceProxy; |
| 24 | |
| 25 | class SkColorSpace; |
| 26 | class SkSurfaceProps; |
| 27 | |
| 28 | /* |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 29 | * 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] | 30 | * provides the "preFlush" / "postFlush" interface. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 31 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 32 | class GrOnFlushCallbackObject { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 33 | public: |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 34 | virtual ~GrOnFlushCallbackObject() { } |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 35 | |
| 36 | /* |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 37 | * 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] | 38 | * for a specific flush. All the GrOpList IDs required for the flush are passed into the |
| 39 | * callback. The callback should return the render target contexts used to render the atlases |
| 40 | * in 'results'. |
| 41 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 42 | virtual void preFlush(GrOnFlushResourceProvider*, |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 43 | const uint32_t* opListIDs, int numOpListIDs, |
| 44 | SkTArray<sk_sp<GrRenderTargetContext>>* results) = 0; |
| 45 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 46 | /** |
| 47 | * 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] | 48 | * 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] | 49 | */ |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 50 | virtual void postFlush(GrDeferredUploadToken startTokenForNextFlush, |
| 51 | const uint32_t* opListIDs, int numOpListIDs) {} |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 52 | |
| 53 | /** |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 54 | * Tells the callback owner to hold onto this object when freeing GPU resources |
| 55 | * |
| 56 | * In particular, GrDrawingManager::freeGPUResources() deletes all the path renderers. |
| 57 | * Any OnFlushCallbackObject associated with a path renderer will need to be deleted. |
| 58 | */ |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 59 | virtual bool retainOnFreeGpuResources() { return false; } |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | /* |
| 63 | * 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] | 64 | * onFlush callbacks and is intended to limit the functionality available to them. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 65 | * It should never have additional data members or virtual methods. |
| 66 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 67 | class GrOnFlushResourceProvider { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 68 | public: |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame^] | 69 | explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {} |
| 70 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 71 | sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc&, |
| 72 | sk_sp<SkColorSpace>, |
| 73 | const SkSurfaceProps*); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 74 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 75 | sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>, |
| 76 | sk_sp<SkColorSpace>, |
| 77 | const SkSurfaceProps*); |
| 78 | |
| 79 | bool instatiateProxy(GrSurfaceProxy*); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 80 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 81 | // Creates a GPU buffer with a "dynamic" access pattern. |
| 82 | sk_sp<GrBuffer> makeBuffer(GrBufferType, size_t, const void* data = nullptr); |
| 83 | |
Chris Dalton | e9e91dd | 2017-07-14 08:48:57 -0600 | [diff] [blame] | 84 | // Either finds and refs, or creates a static GPU buffer with the given data. |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 85 | sk_sp<const GrBuffer> findOrMakeStaticBuffer(GrBufferType, size_t, const void* data, |
| 86 | const GrUniqueKey&); |
Chris Dalton | e9e91dd | 2017-07-14 08:48:57 -0600 | [diff] [blame] | 87 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 88 | const GrCaps* caps() const; |
| 89 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 90 | private: |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 91 | GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete; |
| 92 | GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 93 | |
| 94 | GrDrawingManager* fDrawingMgr; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | #endif |