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 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 11 | #include "text/GrAtlasTextContext.h" |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 12 | #include "GrBatchFlushState.h" |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 13 | #include "GrPathRendererChain.h" |
| 14 | #include "GrPathRenderer.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 15 | #include "GrRenderTargetOpList.h" |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 16 | #include "GrResourceCache.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 17 | #include "SkTDArray.h" |
| 18 | |
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; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 21 | class GrRenderTargetContext; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 22 | class GrRenderTargetProxy; |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 23 | class GrSingleOWner; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 24 | class GrSoftwarePathRenderer; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 25 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 26 | // The GrDrawingManager allocates a new GrRenderTargetContext for each GrRenderTarget |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 27 | // but all of them still land in the same GrOpList! |
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 | // In the future this class will allocate a new GrRenderTargetContext for |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 30 | // each GrRenderTarget/GrOpList and manage the DAG. |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 31 | class GrDrawingManager { |
| 32 | public: |
| 33 | ~GrDrawingManager(); |
| 34 | |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 35 | bool wasAbandoned() const { return fAbandoned; } |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 36 | void freeGpuResources(); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 37 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 38 | sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 39 | sk_sp<SkColorSpace>, |
| 40 | const SkSurfaceProps*); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 41 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 42 | // The caller automatically gets a ref on the returned opList. It must |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 43 | // be balanced by an unref call. |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 44 | GrRenderTargetOpList* newOpList(GrRenderTargetProxy* rtp); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 45 | |
| 46 | GrContext* getContext() { return fContext; } |
| 47 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 48 | GrAtlasTextContext* getAtlasTextContext(); |
| 49 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 50 | GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
| 51 | bool allowSW, |
| 52 | GrPathRendererChain::DrawType drawType, |
| 53 | GrPathRenderer::StencilSupport* stencilSupport = NULL); |
| 54 | |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 55 | void flushIfNecessary() { |
| 56 | if (fContext->getResourceCache()->requestsFlush()) { |
| 57 | this->internalFlush(GrResourceCache::kCacheRequested); |
| 58 | } else if (fIsImmediateMode) { |
| 59 | this->internalFlush(GrResourceCache::kImmediateMode); |
| 60 | } |
| 61 | } |
| 62 | |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 63 | static bool ProgramUnitTest(GrContext* context, int maxStages); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 64 | |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 65 | void prepareSurfaceForExternalIO(GrSurface*); |
| 66 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 67 | private: |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 68 | GrDrawingManager(GrContext* context, |
| 69 | const GrRenderTargetOpList::Options& optionsForOpLists, |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 70 | const GrPathRendererChain::Options& optionsForPathRendererChain, |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 71 | bool isImmediateMode, GrSingleOwner* singleOwner) |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 72 | : fContext(context) |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 73 | , fOptionsForOpLists(optionsForOpLists) |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 74 | , fOptionsForPathRendererChain(optionsForPathRendererChain) |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 75 | , fSingleOwner(singleOwner) |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 76 | , fAbandoned(false) |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 77 | , fAtlasTextContext(nullptr) |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 78 | , fPathRendererChain(nullptr) |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 79 | , fSoftwarePathRenderer(nullptr) |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 80 | , fFlushState(context->getGpu(), context->resourceProvider()) |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 81 | , fFlushing(false) |
| 82 | , fIsImmediateMode(isImmediateMode) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void abandon(); |
| 86 | void cleanup(); |
| 87 | void reset(); |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 88 | void flush() { this->internalFlush(GrResourceCache::FlushType::kExternal); } |
| 89 | void internalFlush(GrResourceCache::FlushType); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 90 | |
| 91 | friend class GrContext; // for access to: ctor, abandon, reset & flush |
| 92 | |
| 93 | static const int kNumPixelGeometries = 5; // The different pixel geometries |
| 94 | static const int kNumDFTOptions = 2; // DFT or no DFT |
| 95 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 96 | GrContext* fContext; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 97 | GrRenderTargetOpList::Options fOptionsForOpLists; |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 98 | GrPathRendererChain::Options fOptionsForPathRendererChain; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 99 | |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 100 | // In debug builds we guard against improper thread handling |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 101 | GrSingleOwner* fSingleOwner; |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 102 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 103 | bool fAbandoned; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 104 | SkTDArray<GrOpList*> fOpLists; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 105 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 106 | std::unique_ptr<GrAtlasTextContext> fAtlasTextContext; |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 107 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 108 | GrPathRendererChain* fPathRendererChain; |
| 109 | GrSoftwarePathRenderer* fSoftwarePathRenderer; |
| 110 | |
| 111 | GrBatchFlushState fFlushState; |
| 112 | bool fFlushing; |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 113 | |
| 114 | bool fIsImmediateMode; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | #endif |