bsalomon | add79ef | 2015-08-19 13:26:49 -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 | |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 8 | #ifndef GrDrawPathOp_DEFINED |
| 9 | #define GrDrawPathOp_DEFINED |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 10 | |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 11 | #include "GrDrawOp.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 12 | #include "GrOpFlushState.h" |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 13 | #include "GrPath.h" |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 14 | #include "GrPathProcessor.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 15 | #include "GrPathRendering.h" |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 16 | #include "GrProcessorSet.h" |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 17 | #include "GrStencilSettings.h" |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 18 | |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 19 | #include "SkTLList.h" |
| 20 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 21 | class GrPaint; |
| 22 | |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 23 | class GrDrawPathOpBase : public GrDrawOp { |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 24 | protected: |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 25 | GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&&, |
| 26 | GrPathRendering::FillType, GrAAType); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 27 | FixedFunctionFlags fixedFunctionFlags() const override { |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 28 | if (GrAATypeIsHW(fAAType)) { |
| 29 | return FixedFunctionFlags::kUsesHWAA | FixedFunctionFlags::kUsesStencil; |
| 30 | } |
| 31 | return FixedFunctionFlags::kUsesStencil; |
Brian Salomon | c48af93 | 2017-03-16 19:51:42 +0000 | [diff] [blame] | 32 | } |
Brian Salomon | f86d37b | 2017-06-16 10:04:34 -0400 | [diff] [blame] | 33 | RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override { |
| 34 | return this->doProcessorAnalysis(caps, clip).requiresDstTexture() ? RequiresDstTexture::kYes |
| 35 | : RequiresDstTexture::kNo; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 36 | } |
| 37 | |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 38 | protected: |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 39 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 40 | GrColor color() const { return fInputColor; } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 41 | GrPathRendering::FillType fillType() const { return fFillType; } |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 42 | const GrProcessorSet& processors() const { return fProcessorSet; } |
Brian Salomon | 611572c | 2017-04-28 08:57:12 -0400 | [diff] [blame] | 43 | uint32_t pipelineSRGBFlags() const { return fPipelineSRGBFlags; } |
Brian Salomon | 972b2f6 | 2017-07-31 12:37:02 -0400 | [diff] [blame^] | 44 | inline GrPipeline::InitArgs pipelineInitArgs(const GrOpFlushState&); |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 45 | const GrProcessorSet::Analysis& doProcessorAnalysis(const GrCaps& caps, |
| 46 | const GrAppliedClip* clip) { |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 47 | bool isMixedSamples = GrAAType::kMixedSamples == fAAType; |
| 48 | fAnalysis = fProcessorSet.finalize(fInputColor, GrProcessorAnalysisCoverage::kNone, clip, |
| 49 | isMixedSamples, caps, &fInputColor); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 50 | return fAnalysis; |
| 51 | } |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 52 | const GrProcessorSet::Analysis& processorAnalysis() const { |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 53 | SkASSERT(fAnalysis.isInitialized()); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 54 | return fAnalysis; |
| 55 | } |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 56 | |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 57 | private: |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 58 | void onPrepare(GrOpFlushState*) final {} |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 59 | |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 60 | SkMatrix fViewMatrix; |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 61 | GrColor fInputColor; |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 62 | GrProcessorSet::Analysis fAnalysis; |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 63 | GrPathRendering::FillType fFillType; |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 64 | GrAAType fAAType; |
Brian Salomon | 611572c | 2017-04-28 08:57:12 -0400 | [diff] [blame] | 65 | uint32_t fPipelineSRGBFlags; |
| 66 | GrProcessorSet fProcessorSet; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 67 | |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 68 | typedef GrDrawOp INHERITED; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 71 | class GrDrawPathOp final : public GrDrawPathOpBase { |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 72 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 73 | DEFINE_OP_CLASS_ID |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 74 | |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 75 | static std::unique_ptr<GrDrawOp> Make(const SkMatrix& viewMatrix, GrPaint&& paint, |
| 76 | GrAAType aaType, GrPath* path) { |
| 77 | return std::unique_ptr<GrDrawOp>( |
| 78 | new GrDrawPathOp(viewMatrix, std::move(paint), aaType, path)); |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | const char* name() const override { return "DrawPath"; } |
| 82 | |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 83 | SkString dumpInfo() const override; |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 84 | |
| 85 | private: |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 86 | GrDrawPathOp(const SkMatrix& viewMatrix, GrPaint&& paint, GrAAType aaType, const GrPath* path) |
| 87 | : GrDrawPathOpBase(ClassID(), viewMatrix, std::move(paint), path->getFillType(), aaType) |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 88 | , fPath(path) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 89 | this->setTransformedBounds(path->getBounds(), viewMatrix, HasAABloat::kNo, IsZeroArea::kNo); |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 90 | } |
stephana | 1dc1721 | 2016-04-25 07:01:22 -0700 | [diff] [blame] | 91 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 92 | bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { return false; } |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 93 | |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 94 | void onExecute(GrOpFlushState* state) override; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 95 | |
| 96 | GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
stephana | 1dc1721 | 2016-04-25 07:01:22 -0700 | [diff] [blame] | 97 | |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 98 | typedef GrDrawPathOpBase INHERITED; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 101 | // Template this if we decide to support index types other than 16bit |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 102 | class GrDrawPathRangeOp final : public GrDrawPathOpBase { |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 103 | public: |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 104 | typedef GrPathRendering::PathTransformType TransformType; |
| 105 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 106 | DEFINE_OP_CLASS_ID |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 107 | |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 108 | struct InstanceData : private ::SkNoncopyable { |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 109 | public: |
| 110 | static InstanceData* Alloc(TransformType transformType, int reserveCnt) { |
| 111 | int transformSize = GrPathRendering::PathTransformSize(transformType); |
| 112 | uint8_t* ptr = (uint8_t*)sk_malloc_throw(Align32(sizeof(InstanceData)) + |
| 113 | Align32(reserveCnt * sizeof(uint16_t)) + |
| 114 | reserveCnt * transformSize * sizeof(float)); |
| 115 | InstanceData* instanceData = (InstanceData*)ptr; |
| 116 | instanceData->fIndices = (uint16_t*)&ptr[Align32(sizeof(InstanceData))]; |
| 117 | instanceData->fTransformValues = (float*)&ptr[Align32(sizeof(InstanceData)) + |
| 118 | Align32(reserveCnt * sizeof(uint16_t))]; |
| 119 | instanceData->fTransformType = transformType; |
| 120 | instanceData->fInstanceCount = 0; |
| 121 | instanceData->fRefCnt = 1; |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 122 | SkDEBUGCODE(instanceData->fReserveCnt = reserveCnt); |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 123 | return instanceData; |
| 124 | } |
| 125 | |
| 126 | // Overload this method if we start using other transform types. |
| 127 | void append(uint16_t index, float x, float y) { |
| 128 | SkASSERT(GrPathRendering::kTranslate_PathTransformType == fTransformType); |
| 129 | SkASSERT(fInstanceCount < fReserveCnt); |
| 130 | fIndices[fInstanceCount] = index; |
| 131 | fTransformValues[2 * fInstanceCount] = x; |
| 132 | fTransformValues[2 * fInstanceCount + 1] = y; |
| 133 | ++fInstanceCount; |
| 134 | } |
| 135 | |
| 136 | TransformType transformType() const { return fTransformType; } |
| 137 | int count() const { return fInstanceCount; } |
| 138 | |
| 139 | const uint16_t* indices() const { return fIndices; } |
| 140 | uint16_t* indices() { return fIndices; } |
| 141 | |
| 142 | const float* transformValues() const { return fTransformValues; } |
| 143 | float* transformValues() { return fTransformValues; } |
| 144 | |
| 145 | void ref() const { ++fRefCnt; } |
| 146 | |
| 147 | void unref() const { |
| 148 | if (0 == --fRefCnt) { |
| 149 | sk_free(const_cast<InstanceData*>(this)); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | private: |
| 154 | static int Align32(int sizeInBytes) { return (sizeInBytes + 3) & ~3; } |
| 155 | |
| 156 | InstanceData() {} |
| 157 | ~InstanceData() {} |
| 158 | |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 159 | uint16_t* fIndices; |
| 160 | float* fTransformValues; |
| 161 | TransformType fTransformType; |
| 162 | int fInstanceCount; |
| 163 | mutable int fRefCnt; |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 164 | SkDEBUGCODE(int fReserveCnt;) |
| 165 | }; |
| 166 | |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 167 | static std::unique_ptr<GrDrawOp> Make(const SkMatrix& viewMatrix, SkScalar scale, SkScalar x, |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 168 | SkScalar y, GrPaint&& paint, |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 169 | GrPathRendering::FillType fill, GrAAType aaType, |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 170 | GrPathRange* range, const InstanceData* instanceData, |
| 171 | const SkRect& bounds) { |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 172 | return std::unique_ptr<GrDrawOp>(new GrDrawPathRangeOp(viewMatrix, scale, x, y, |
| 173 | std::move(paint), fill, aaType, |
| 174 | range, instanceData, bounds)); |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 175 | } |
| 176 | |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 177 | const char* name() const override { return "DrawPathRange"; } |
| 178 | |
| 179 | SkString dumpInfo() const override; |
| 180 | |
| 181 | private: |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 182 | GrDrawPathRangeOp(const SkMatrix& viewMatrix, SkScalar scale, SkScalar x, SkScalar y, |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 183 | GrPaint&& paint, GrPathRendering::FillType fill, GrAAType aaType, |
| 184 | GrPathRange* range, const InstanceData* instanceData, const SkRect& bounds); |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 185 | |
| 186 | TransformType transformType() const { return fDraws.head()->fInstanceData->transformType(); } |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 187 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 188 | bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 189 | |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 190 | void onExecute(GrOpFlushState* state) override; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 191 | |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 192 | struct Draw { |
| 193 | void set(const InstanceData* instanceData, SkScalar x, SkScalar y) { |
| 194 | fInstanceData.reset(SkRef(instanceData)); |
| 195 | fX = x; |
| 196 | fY = y; |
| 197 | } |
| 198 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 199 | sk_sp<const InstanceData> fInstanceData; |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 200 | SkScalar fX, fY; |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 201 | }; |
| 202 | |
cdalton | 8585dd2 | 2015-10-08 08:04:09 -0700 | [diff] [blame] | 203 | typedef GrPendingIOResource<const GrPathRange, kRead_GrIOType> PendingPathRange; |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 204 | typedef SkTLList<Draw, 4> DrawList; |
| 205 | |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 206 | PendingPathRange fPathRange; |
| 207 | DrawList fDraws; |
| 208 | int fTotalPathCount; |
| 209 | SkScalar fScale; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 210 | |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 211 | typedef GrDrawPathOpBase INHERITED; |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | #endif |