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 | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 12 | #include "SkRefCnt.h" |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 13 | #include "SkTArray.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 14 | |
| 15 | class GrDrawingManager; |
| 16 | class GrOpList; |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 17 | class GrOnFlushResourceProvider; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 18 | class GrRenderTargetOpList; |
| 19 | class GrRenderTargetContext; |
| 20 | class GrSurfaceProxy; |
| 21 | |
| 22 | class SkColorSpace; |
| 23 | class SkSurfaceProps; |
| 24 | |
| 25 | /* |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 26 | * 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] | 27 | * provides the "preFlush" / "postFlush" interface. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 28 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 29 | class GrOnFlushCallbackObject { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 30 | public: |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 31 | virtual ~GrOnFlushCallbackObject() { } |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 32 | |
| 33 | /* |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 34 | * 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] | 35 | * for a specific flush. All the GrOpList IDs required for the flush are passed into the |
| 36 | * callback. The callback should return the render target contexts used to render the atlases |
| 37 | * in 'results'. |
| 38 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 39 | virtual void preFlush(GrOnFlushResourceProvider*, |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 40 | const uint32_t* opListIDs, int numOpListIDs, |
| 41 | SkTArray<sk_sp<GrRenderTargetContext>>* results) = 0; |
| 42 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 43 | /** |
| 44 | * Called once flushing is complete and all ops indicated by preFlush have been executed and |
| 45 | * released. |
| 46 | */ |
| 47 | virtual void postFlush() {} |
| 48 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 49 | private: |
| 50 | typedef SkRefCnt INHERITED; |
| 51 | }; |
| 52 | |
| 53 | /* |
| 54 | * 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] | 55 | * onFlush callbacks and is intended to limit the functionality available to them. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 56 | * It should never have additional data members or virtual methods. |
| 57 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 58 | class GrOnFlushResourceProvider { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 59 | public: |
| 60 | sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc& desc, |
| 61 | sk_sp<SkColorSpace> colorSpace, |
| 62 | const SkSurfaceProps* props); |
| 63 | |
| 64 | // TODO: we only need this entry point as long as we have to pre-allocate the atlas. |
| 65 | // Remove it ASAP. |
| 66 | sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy> proxy, |
| 67 | sk_sp<SkColorSpace> colorSpace, |
| 68 | const SkSurfaceProps* props); |
| 69 | |
| 70 | private: |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 71 | explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {} |
| 72 | GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete; |
| 73 | GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 74 | |
| 75 | GrDrawingManager* fDrawingMgr; |
| 76 | |
| 77 | friend class GrDrawingManager; // to construct this type. |
| 78 | }; |
| 79 | |
| 80 | #endif |