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