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 | |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 11 | #include "GrDrawTarget.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" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 15 | #include "SkTDArray.h" |
| 16 | |
| 17 | class GrContext; |
| 18 | class GrDrawContext; |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 19 | class GrSingleOWner; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 20 | class GrSoftwarePathRenderer; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 21 | |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 22 | // The GrDrawingManager allocates a new GrDrawContext for each GrRenderTarget |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 23 | // but all of them still land in the same GrDrawTarget! |
| 24 | // |
| 25 | // In the future this class will allocate a new GrDrawContext for |
| 26 | // each GrRenderTarget/GrDrawTarget and manage the DAG. |
| 27 | class GrDrawingManager { |
| 28 | public: |
| 29 | ~GrDrawingManager(); |
| 30 | |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame^] | 31 | bool wasAbandoned() const { return fAbandoned; } |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 32 | void freeGpuResources(); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 33 | |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 34 | sk_sp<GrDrawContext> drawContext(sk_sp<GrRenderTarget> rt, const SkSurfaceProps*); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 35 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 36 | // The caller automatically gets a ref on the returned drawTarget. It must |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 37 | // be balanced by an unref call. |
| 38 | GrDrawTarget* newDrawTarget(GrRenderTarget* rt); |
| 39 | |
| 40 | GrContext* getContext() { return fContext; } |
| 41 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 42 | GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
| 43 | bool allowSW, |
| 44 | GrPathRendererChain::DrawType drawType, |
| 45 | GrPathRenderer::StencilSupport* stencilSupport = NULL); |
| 46 | |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 47 | static bool ProgramUnitTest(GrContext* context, int maxStages); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 48 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 49 | private: |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 50 | GrDrawingManager(GrContext* context, const GrDrawTarget::Options& optionsForDrawTargets, |
| 51 | GrSingleOwner* singleOwner) |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 52 | : fContext(context) |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 53 | , fOptionsForDrawTargets(optionsForDrawTargets) |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 54 | , fSingleOwner(singleOwner) |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 55 | , fAbandoned(false) |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 56 | , fPathRendererChain(nullptr) |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 57 | , fSoftwarePathRenderer(nullptr) |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 58 | , fFlushState(context->getGpu(), context->resourceProvider()) |
| 59 | , fFlushing(false) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void abandon(); |
| 63 | void cleanup(); |
| 64 | void reset(); |
| 65 | void flush(); |
| 66 | |
| 67 | friend class GrContext; // for access to: ctor, abandon, reset & flush |
| 68 | |
| 69 | static const int kNumPixelGeometries = 5; // The different pixel geometries |
| 70 | static const int kNumDFTOptions = 2; // DFT or no DFT |
| 71 | |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 72 | GrContext* fContext; |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 73 | GrDrawTarget::Options fOptionsForDrawTargets; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 74 | |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 75 | // In debug builds we guard against improper thread handling |
| 76 | GrSingleOwner* fSingleOwner; |
| 77 | |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 78 | bool fAbandoned; |
| 79 | SkTDArray<GrDrawTarget*> fDrawTargets; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 80 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 81 | GrPathRendererChain* fPathRendererChain; |
| 82 | GrSoftwarePathRenderer* fSoftwarePathRenderer; |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 83 | |
| 84 | GrBatchFlushState fFlushState; |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 85 | bool fFlushing; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | #endif |