robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
| 8 | #ifndef GrDrawingManager_DEFINED |
| 9 | #define GrDrawingManager_DEFINED |
| 10 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 11 | #include "GrOpFlushState.h" |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 12 | #include "GrPathRenderer.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 13 | #include "GrPathRendererChain.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 14 | #include "GrRenderTargetOpList.h" |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 15 | #include "GrResourceCache.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 16 | #include "SkTArray.h" |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 17 | #include "instanced/InstancedRendering.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 18 | #include "text/GrAtlasTextContext.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 19 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 20 | class GrContext; |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 21 | class GrOnFlushCallbackObject; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 22 | class GrRenderTargetContext; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 23 | class GrRenderTargetProxy; |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 24 | class GrSingleOWner; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 25 | class GrSoftwarePathRenderer; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 26 | class GrTextureContext; |
| 27 | class GrTextureOpList; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 28 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 29 | // The GrDrawingManager allocates a new GrRenderTargetContext for each GrRenderTarget |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 30 | // but all of them still land in the same GrOpList! |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 31 | // |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 32 | // In the future this class will allocate a new GrRenderTargetContext for |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 33 | // each GrRenderTarget/GrOpList and manage the DAG. |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 34 | class GrDrawingManager { |
| 35 | public: |
| 36 | ~GrDrawingManager(); |
| 37 | |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 38 | bool wasAbandoned() const { return fAbandoned; } |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 39 | void freeGpuResources(); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 40 | |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 41 | gr_instanced::OpAllocator* instancingAllocator(); |
| 42 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 43 | sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 44 | sk_sp<SkColorSpace>, |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 45 | const SkSurfaceProps*, |
| 46 | bool managedOpList = true); |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 47 | sk_sp<GrTextureContext> makeTextureContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 48 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 49 | // The caller automatically gets a ref on the returned opList. It must |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 50 | // be balanced by an unref call. |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 51 | // A managed opList is controlled by the drawing manager (i.e., sorted & flushed with the |
| 52 | // other). An unmanaged one is created and used by the onFlushCallback. |
| 53 | sk_sp<GrRenderTargetOpList> newRTOpList(GrRenderTargetProxy* rtp, bool managedOpList); |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 54 | sk_sp<GrTextureOpList> newTextureOpList(GrTextureProxy* textureProxy); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 55 | |
| 56 | GrContext* getContext() { return fContext; } |
| 57 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 58 | GrAtlasTextContext* getAtlasTextContext(); |
| 59 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 60 | GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
| 61 | bool allowSW, |
| 62 | GrPathRendererChain::DrawType drawType, |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 63 | GrPathRenderer::StencilSupport* stencilSupport = nullptr); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 64 | |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 65 | void flushIfNecessary() { |
| 66 | if (fContext->getResourceCache()->requestsFlush()) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 67 | this->internalFlush(nullptr, GrResourceCache::kCacheRequested, 0, nullptr); |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 71 | static bool ProgramUnitTest(GrContext* context, int maxStages, int maxLevels); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 72 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 73 | GrSemaphoresSubmitted prepareSurfaceForExternalIO(GrSurfaceProxy*, |
| 74 | int numSemaphores, |
| 75 | GrBackendSemaphore backendSemaphores[]); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 76 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 77 | void addOnFlushCallbackObject(GrOnFlushCallbackObject*); |
| 78 | void testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject*); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 79 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 80 | private: |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 81 | GrDrawingManager(GrContext* context, |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 82 | const GrPathRendererChain::Options& optionsForPathRendererChain, |
Robert Phillips | 3ea1798 | 2017-06-02 12:43:04 -0400 | [diff] [blame] | 83 | GrSingleOwner* singleOwner) |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 84 | : fContext(context) |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 85 | , fOptionsForPathRendererChain(optionsForPathRendererChain) |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 86 | , fSingleOwner(singleOwner) |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 87 | , fAbandoned(false) |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 88 | , fAtlasTextContext(nullptr) |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 89 | , fPathRendererChain(nullptr) |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 90 | , fSoftwarePathRenderer(nullptr) |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 91 | , fFlushState(context->getGpu(), context->resourceProvider()) |
Robert Phillips | 3ea1798 | 2017-06-02 12:43:04 -0400 | [diff] [blame] | 92 | , fFlushing(false) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void abandon(); |
| 96 | void cleanup(); |
| 97 | void reset(); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 98 | GrSemaphoresSubmitted flush(GrSurfaceProxy* proxy, |
| 99 | int numSemaphores = 0, |
| 100 | GrBackendSemaphore backendSemaphores[] = nullptr) { |
| 101 | return this->internalFlush(proxy, GrResourceCache::FlushType::kExternal, |
| 102 | numSemaphores, backendSemaphores); |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 103 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 104 | GrSemaphoresSubmitted internalFlush(GrSurfaceProxy*, |
| 105 | GrResourceCache::FlushType, |
| 106 | int numSemaphores, |
| 107 | GrBackendSemaphore backendSemaphores[]); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 108 | |
| 109 | friend class GrContext; // for access to: ctor, abandon, reset & flush |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 110 | friend class GrContextPriv; // access to: flush |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 111 | friend class GrOnFlushResourceProvider; // this is just a shallow wrapper around this class |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 112 | |
| 113 | static const int kNumPixelGeometries = 5; // The different pixel geometries |
| 114 | static const int kNumDFTOptions = 2; // DFT or no DFT |
| 115 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 116 | GrContext* fContext; |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 117 | GrPathRendererChain::Options fOptionsForPathRendererChain; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 118 | |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 119 | // In debug builds we guard against improper thread handling |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 120 | GrSingleOwner* fSingleOwner; |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 121 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 122 | bool fAbandoned; |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 123 | SkTArray<sk_sp<GrOpList>> fOpLists; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 124 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 125 | std::unique_ptr<GrAtlasTextContext> fAtlasTextContext; |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 126 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 127 | GrPathRendererChain* fPathRendererChain; |
| 128 | GrSoftwarePathRenderer* fSoftwarePathRenderer; |
| 129 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 130 | GrOpFlushState fFlushState; |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 131 | bool fFlushing; |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 132 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 133 | SkTArray<GrOnFlushCallbackObject*> fOnFlushCBObjects; |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 134 | |
| 135 | // Lazily allocated |
| 136 | std::unique_ptr<gr_instanced::OpAllocator> fInstancingAllocator; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | #endif |