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; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 19 | class GrSoftwarePathRenderer; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 20 | class GrTextContext; |
| 21 | |
| 22 | // Currently the DrawingManager creates a separate GrTextContext for each |
| 23 | // combination of text drawing options (pixel geometry x DFT use) |
| 24 | // and hands the appropriate one back given the DrawContext's request. |
| 25 | // |
| 26 | // It allocates a new GrDrawContext for each GrRenderTarget |
| 27 | // but all of them still land in the same GrDrawTarget! |
| 28 | // |
| 29 | // In the future this class will allocate a new GrDrawContext for |
| 30 | // each GrRenderTarget/GrDrawTarget and manage the DAG. |
| 31 | class GrDrawingManager { |
| 32 | public: |
| 33 | ~GrDrawingManager(); |
| 34 | |
| 35 | bool abandoned() 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 | |
| 38 | GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps); |
| 39 | |
| 40 | GrTextContext* textContext(const SkSurfaceProps& props, GrRenderTarget* rt); |
| 41 | |
| 42 | // The caller automatically gets a ref on the returned drawTarget. It must |
| 43 | // be balanced by an unref call. |
| 44 | GrDrawTarget* newDrawTarget(GrRenderTarget* rt); |
| 45 | |
| 46 | GrContext* getContext() { return fContext; } |
| 47 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 48 | GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
| 49 | bool allowSW, |
| 50 | GrPathRendererChain::DrawType drawType, |
| 51 | GrPathRenderer::StencilSupport* stencilSupport = NULL); |
| 52 | |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 53 | static bool ProgramUnitTest(GrContext* context, int maxStages); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 54 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 55 | private: |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 56 | GrDrawingManager(GrContext* context, const GrDrawTarget::Options& optionsForDrawTargets) |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 57 | : fContext(context) |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 58 | , fOptionsForDrawTargets(optionsForDrawTargets) |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 59 | , fAbandoned(false) |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 60 | , fNVPRTextContext(nullptr) |
| 61 | , fPathRendererChain(nullptr) |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 62 | , fSoftwarePathRenderer(nullptr) |
| 63 | , fFlushState(context->getGpu(), context->resourceProvider()) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 64 | sk_bzero(fTextContexts, sizeof(fTextContexts)); |
| 65 | } |
| 66 | |
| 67 | void abandon(); |
| 68 | void cleanup(); |
| 69 | void reset(); |
| 70 | void flush(); |
| 71 | |
| 72 | friend class GrContext; // for access to: ctor, abandon, reset & flush |
| 73 | |
| 74 | static const int kNumPixelGeometries = 5; // The different pixel geometries |
| 75 | static const int kNumDFTOptions = 2; // DFT or no DFT |
| 76 | |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 77 | GrContext* fContext; |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 78 | GrDrawTarget::Options fOptionsForDrawTargets; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 79 | |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 80 | bool fAbandoned; |
| 81 | SkTDArray<GrDrawTarget*> fDrawTargets; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 82 | |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 83 | GrTextContext* fNVPRTextContext; |
| 84 | GrTextContext* fTextContexts[kNumPixelGeometries][kNumDFTOptions]; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 85 | |
| 86 | GrPathRendererChain* fPathRendererChain; |
| 87 | GrSoftwarePathRenderer* fSoftwarePathRenderer; |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 88 | |
| 89 | GrBatchFlushState fFlushState; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | #endif |