cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 8 | #include "GrGpu.h" |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 9 | #include "GrPathRendering.h" |
| 10 | #include "SkDescriptor.h" |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 11 | #include "SkScalerContext.h" |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 12 | #include "SkGlyph.h" |
| 13 | #include "SkMatrix.h" |
| 14 | #include "SkTypeface.h" |
| 15 | #include "GrPathRange.h" |
| 16 | |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 17 | const GrUserStencilSettings& GrPathRendering::GetStencilPassSettings(FillType fill) { |
| 18 | switch (fill) { |
| 19 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 20 | SK_ABORT("Unexpected path fill."); |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 21 | case GrPathRendering::kWinding_FillType: { |
| 22 | constexpr static GrUserStencilSettings kWindingStencilPass( |
| 23 | GrUserStencilSettings::StaticInit< |
| 24 | 0xffff, |
| 25 | GrUserStencilTest::kAlwaysIfInClip, |
| 26 | 0xffff, |
| 27 | GrUserStencilOp::kIncWrap, |
| 28 | GrUserStencilOp::kIncWrap, |
| 29 | 0xffff>() |
| 30 | ); |
| 31 | return kWindingStencilPass; |
| 32 | } |
| 33 | case GrPathRendering::kEvenOdd_FillType: { |
| 34 | constexpr static GrUserStencilSettings kEvenOddStencilPass( |
| 35 | GrUserStencilSettings::StaticInit< |
| 36 | 0xffff, |
| 37 | GrUserStencilTest::kAlwaysIfInClip, |
| 38 | 0xffff, |
| 39 | GrUserStencilOp::kInvert, |
| 40 | GrUserStencilOp::kInvert, |
| 41 | 0xffff>() |
| 42 | ); |
| 43 | return kEvenOddStencilPass; |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 48 | class GlyphGenerator : public GrPathRange::PathGenerator { |
| 49 | public: |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 50 | GlyphGenerator(const SkTypeface& typeface, const SkScalerContextEffects& effects, |
| 51 | const SkDescriptor& desc) |
| 52 | : fScalerContext(typeface.createScalerContext(effects, &desc)) |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 53 | #ifdef SK_DEBUG |
| 54 | , fDesc(desc.copy()) |
| 55 | #endif |
cdalton | 7d5c950 | 2015-10-03 13:28:35 -0700 | [diff] [blame] | 56 | {} |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 57 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 58 | int getNumPaths() override { |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 59 | return fScalerContext->getGlyphCount(); |
| 60 | } |
| 61 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 62 | void generatePath(int glyphID, SkPath* out) override { |
Ben Wagner | 6e9ac12 | 2016-11-11 14:31:06 -0500 | [diff] [blame] | 63 | fScalerContext->getPath(glyphID, out); |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 64 | } |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 65 | #ifdef SK_DEBUG |
bsalomon | c5d07fa | 2016-05-17 10:17:45 -0700 | [diff] [blame] | 66 | bool isEqualTo(const SkDescriptor& desc) const override { return *fDesc == desc; } |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 67 | #endif |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 68 | private: |
bungeman | 7cfd46a | 2016-10-20 16:06:52 -0400 | [diff] [blame] | 69 | const std::unique_ptr<SkScalerContext> fScalerContext; |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 70 | #ifdef SK_DEBUG |
bungeman | 520ced6 | 2016-10-18 08:03:42 -0400 | [diff] [blame] | 71 | const std::unique_ptr<SkDescriptor> fDesc; |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 72 | #endif |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 75 | void GrPathRendering::stencilPath(const StencilPathArgs& args, const GrPath* path) { |
| 76 | fGpu->handleDirtyContext(); |
| 77 | this->onStencilPath(args, path); |
| 78 | } |
| 79 | |
| 80 | void GrPathRendering::drawPath(const GrPipeline& pipeline, |
| 81 | const GrPrimitiveProcessor& primProc, |
| 82 | // Cover pass settings in pipeline. |
| 83 | const GrStencilSettings& stencilPassSettings, |
| 84 | const GrPath* path) { |
| 85 | fGpu->handleDirtyContext(); |
| 86 | if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*fGpu->caps())) { |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 87 | fGpu->xferBarrier(pipeline.renderTarget(), barrierType); |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 88 | } |
| 89 | this->onDrawPath(pipeline, primProc, stencilPassSettings, path); |
| 90 | } |
| 91 | |
| 92 | void GrPathRendering::drawPaths(const GrPipeline& pipeline, |
| 93 | const GrPrimitiveProcessor& primProc, |
| 94 | // Cover pass settings in pipeline. |
| 95 | const GrStencilSettings& stencilPassSettings, |
| 96 | const GrPathRange* pathRange, |
| 97 | const void* indices, |
| 98 | PathIndexType indexType, |
| 99 | const float transformValues[], |
| 100 | PathTransformType transformType, |
| 101 | int count) { |
| 102 | fGpu->handleDirtyContext(); |
| 103 | if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*fGpu->caps())) { |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 104 | fGpu->xferBarrier(pipeline.renderTarget(), barrierType); |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 105 | } |
| 106 | #ifdef SK_DEBUG |
| 107 | pathRange->assertPathsLoaded(indices, indexType, count); |
| 108 | #endif |
| 109 | this->onDrawPaths(pipeline, primProc, stencilPassSettings, pathRange, indices, indexType, |
| 110 | transformValues, transformType, count); |
| 111 | } |