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" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 12 | #include "GrResourceProvider.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 13 | #include "SkRefCnt.h" |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 14 | #include "SkTArray.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 15 | |
| 16 | class GrDrawingManager; |
| 17 | class GrOpList; |
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 GrRenderTargetOpList; |
| 20 | class GrRenderTargetContext; |
| 21 | class GrSurfaceProxy; |
| 22 | |
| 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: |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -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 |
| 46 | * released. |
| 47 | */ |
| 48 | virtual void postFlush() {} |
| 49 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 50 | private: |
| 51 | typedef SkRefCnt INHERITED; |
| 52 | }; |
| 53 | |
| 54 | /* |
| 55 | * 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] | 56 | * onFlush callbacks and is intended to limit the functionality available to them. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 57 | * It should never have additional data members or virtual methods. |
| 58 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 59 | class GrOnFlushResourceProvider { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 60 | public: |
| 61 | sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc& desc, |
| 62 | sk_sp<SkColorSpace> colorSpace, |
| 63 | const SkSurfaceProps* props); |
| 64 | |
| 65 | // TODO: we only need this entry point as long as we have to pre-allocate the atlas. |
| 66 | // Remove it ASAP. |
| 67 | sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy> proxy, |
| 68 | sk_sp<SkColorSpace> colorSpace, |
| 69 | const SkSurfaceProps* props); |
| 70 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 71 | // Creates a GPU buffer with a "dynamic" access pattern. |
| 72 | sk_sp<GrBuffer> makeBuffer(GrBufferType, size_t, const void* data = nullptr); |
| 73 | |
Chris Dalton | e9e91dd | 2017-07-14 08:48:57 -0600 | [diff] [blame] | 74 | // Either finds and refs, or creates a static GPU buffer with the given data. |
| 75 | sk_sp<GrBuffer> findOrMakeStaticBuffer(const GrUniqueKey&, GrBufferType, |
| 76 | size_t, const void* data); |
| 77 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 78 | const GrCaps* caps() const; |
| 79 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 80 | private: |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 81 | explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {} |
| 82 | GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete; |
| 83 | GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 84 | |
| 85 | GrDrawingManager* fDrawingMgr; |
| 86 | |
| 87 | friend class GrDrawingManager; // to construct this type. |
| 88 | }; |
| 89 | |
| 90 | #endif |