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 | |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 43 | GrDrawBatch(); |
| 44 | ~GrDrawBatch() override; |
| 45 | |
| 46 | virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; |
| 47 | virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0; |
| 48 | |
| 49 | const GrPipeline* pipeline() const { |
| 50 | SkASSERT(fPipelineInstalled); |
| 51 | return reinterpret_cast<const GrPipeline*>(fPipelineStorage.get()); |
| 52 | } |
| 53 | |
| 54 | bool installPipeline(const GrPipeline::CreateArgs&); |
| 55 | |
| 56 | // TODO no GrPrimitiveProcessors yet read fragment position |
| 57 | bool willReadFragmentPosition() const { return false; } |
| 58 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame^] | 59 | uint32_t renderTargetUniqueID() const final { |
| 60 | SkASSERT(fPipelineInstalled); |
| 61 | return this->pipeline()->getRenderTarget()->getUniqueID(); |
| 62 | } |
| 63 | |
| 64 | SkString dumpInfo() const override { |
| 65 | SkString string; |
| 66 | string.append("ColorStages:\n"); |
| 67 | for (int i = 0; i < this->pipeline()->numColorFragmentStages(); i++) { |
| 68 | string.appendf("\t\t%s\n", this->pipeline()->getColorStage(i).processor()->name()); |
| 69 | } |
| 70 | string.append("CoverageStages:\n"); |
| 71 | for (int i = 0; i < this->pipeline()->numCoverageFragmentStages(); i++) { |
| 72 | string.appendf("\t%s\n", this->pipeline()->getCoverageStage(i).processor()->name()); |
| 73 | } |
| 74 | string.appendf("XP: %s\n", this->pipeline()->getXferProcessor()->name()); |
| 75 | return string; |
| 76 | } |
| 77 | |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 78 | private: |
| 79 | /** |
| 80 | * initBatchTracker is a hook for the some additional overrides / optimization possibilities |
| 81 | * from the GrXferProcessor. |
| 82 | */ |
| 83 | virtual void initBatchTracker(const GrPipelineOptimizations&) = 0; |
| 84 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 85 | protected: |
| 86 | SkTArray<SkAutoTUnref<GrBatchUploader>, true> fInlineUploads; |
| 87 | |
| 88 | private: |
| 89 | SkAlignedSTStorage<1, GrPipeline> fPipelineStorage; |
| 90 | bool fPipelineInstalled; |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 91 | typedef GrBatch INHERITED; |
| 92 | }; |
| 93 | |
| 94 | #endif |