bsalomon | 16b9913 | 2015-08-13 14:55:50 -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 GrDrawBatch_DEFINED |
| 9 | #define GrDrawBatch_DEFINED |
| 10 | |
| 11 | #include "GrBatch.h" |
| 12 | #include "GrPipeline.h" |
| 13 | |
| 14 | struct GrInitInvariantOutput; |
| 15 | |
| 16 | /** |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 17 | * GrDrawBatches are flushed in two phases (preDraw, and draw). In preDraw uploads to GrGpuResources |
| 18 | * and draws are determined and scheduled. They are issued in the draw phase. GrBatchToken is used |
| 19 | * to sequence the uploads relative to each other and to draws. |
| 20 | **/ |
| 21 | |
| 22 | typedef uint64_t GrBatchToken; |
| 23 | |
| 24 | class GrBatchUploader : public SkRefCnt { |
| 25 | public: |
| 26 | class TextureUploader; |
| 27 | |
| 28 | GrBatchUploader(GrBatchToken lastUploadToken) : fLastUploadToken(lastUploadToken) {} |
| 29 | GrBatchToken lastUploadToken() const { return fLastUploadToken; } |
| 30 | virtual void upload(TextureUploader*)=0; |
| 31 | |
| 32 | private: |
| 33 | GrBatchToken fLastUploadToken; |
| 34 | }; |
| 35 | |
| 36 | /** |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 37 | * Base class for GrBatches that draw. These batches have a GrPipeline installed by GrDrawTarget. |
| 38 | */ |
| 39 | class GrDrawBatch : public GrBatch { |
| 40 | public: |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 41 | class Target; |
| 42 | |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 43 | GrDrawBatch(uint32_t classID); |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 44 | ~GrDrawBatch() override; |
| 45 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 46 | /** |
| 47 | * Fills in a structure informing the XP of overrides to its normal behavior. |
| 48 | */ |
| 49 | void getPipelineOptimizations(GrPipelineOptimizations* override) const; |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 50 | |
| 51 | const GrPipeline* pipeline() const { |
| 52 | SkASSERT(fPipelineInstalled); |
| 53 | return reinterpret_cast<const GrPipeline*>(fPipelineStorage.get()); |
| 54 | } |
| 55 | |
| 56 | bool installPipeline(const GrPipeline::CreateArgs&); |
| 57 | |
| 58 | // TODO no GrPrimitiveProcessors yet read fragment position |
| 59 | bool willReadFragmentPosition() const { return false; } |
| 60 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 61 | uint32_t renderTargetUniqueID() const final { |
| 62 | SkASSERT(fPipelineInstalled); |
| 63 | return this->pipeline()->getRenderTarget()->getUniqueID(); |
| 64 | } |
| 65 | |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 66 | GrRenderTarget* renderTarget() const final { |
| 67 | SkASSERT(fPipelineInstalled); |
| 68 | return this->pipeline()->getRenderTarget(); |
| 69 | } |
| 70 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 71 | SkString dumpInfo() const override { |
| 72 | SkString string; |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 73 | string.appendf("RT: %d\n", this->renderTargetUniqueID()); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 74 | string.append("ColorStages:\n"); |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 75 | for (int i = 0; i < this->pipeline()->numColorFragmentProcessors(); i++) { |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 76 | string.appendf("\t\t%s\n\t\t%s\n", |
| 77 | this->pipeline()->getColorFragmentProcessor(i).name(), |
| 78 | this->pipeline()->getColorFragmentProcessor(i).dumpInfo().c_str()); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 79 | } |
| 80 | string.append("CoverageStages:\n"); |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 81 | for (int i = 0; i < this->pipeline()->numCoverageFragmentProcessors(); i++) { |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 82 | string.appendf("\t\t%s\n\t\t%s\n", |
| 83 | this->pipeline()->getCoverageFragmentProcessor(i).name(), |
| 84 | this->pipeline()->getCoverageFragmentProcessor(i).dumpInfo().c_str()); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 85 | } |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 86 | string.appendf("XP: %s\n", this->pipeline()->getXferProcessor().name()); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 87 | return string; |
| 88 | } |
| 89 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 90 | protected: |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame^] | 91 | virtual void computePipelineOptimizations(GrInitInvariantOutput* color, |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 92 | GrInitInvariantOutput* coverage, |
| 93 | GrBatchToXPOverrides* overrides) const = 0; |
| 94 | |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 95 | private: |
| 96 | /** |
| 97 | * initBatchTracker is a hook for the some additional overrides / optimization possibilities |
| 98 | * from the GrXferProcessor. |
| 99 | */ |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 100 | virtual void initBatchTracker(const GrXPOverridesForBatch&) = 0; |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 101 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 102 | protected: |
| 103 | SkTArray<SkAutoTUnref<GrBatchUploader>, true> fInlineUploads; |
| 104 | |
| 105 | private: |
| 106 | SkAlignedSTStorage<1, GrPipeline> fPipelineStorage; |
| 107 | bool fPipelineInstalled; |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 108 | typedef GrBatch INHERITED; |
| 109 | }; |
| 110 | |
| 111 | #endif |