jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
joel.liang | 8cbb424 | 2017-01-09 18:39:43 -0800 | [diff] [blame] | 3 | * Copyright 2017 ARM Ltd. |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/gpu/ops/GrSmallPathRenderer.h" |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkPaint.h" |
| 12 | #include "src/core/SkAutoMalloc.h" |
| 13 | #include "src/core/SkAutoPixmapStorage.h" |
| 14 | #include "src/core/SkDistanceFieldGen.h" |
| 15 | #include "src/core/SkDraw.h" |
Michael Ludwig | fbe2859 | 2020-06-26 16:02:15 -0400 | [diff] [blame] | 16 | #include "src/core/SkMatrixPriv.h" |
Brian Osman | 9aaec36 | 2020-05-08 14:54:37 -0400 | [diff] [blame] | 17 | #include "src/core/SkMatrixProvider.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/core/SkPointPriv.h" |
| 19 | #include "src/core/SkRasterClip.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrBuffer.h" |
| 22 | #include "src/gpu/GrCaps.h" |
| 23 | #include "src/gpu/GrDistanceFieldGenFromVector.h" |
| 24 | #include "src/gpu/GrDrawOpTest.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/GrRenderTargetContext.h" |
| 26 | #include "src/gpu/GrResourceProvider.h" |
| 27 | #include "src/gpu/GrVertexWriter.h" |
| 28 | #include "src/gpu/effects/GrBitmapTextGeoProc.h" |
| 29 | #include "src/gpu/effects/GrDistanceFieldGeoProc.h" |
Michael Ludwig | fd4f4df | 2019-05-29 09:51:09 -0400 | [diff] [blame] | 30 | #include "src/gpu/geometry/GrQuad.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 31 | #include "src/gpu/ops/GrMeshDrawOp.h" |
Robert Phillips | 55f681f | 2020-02-28 08:58:15 -0500 | [diff] [blame] | 32 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelperWithStencil.h" |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 33 | |
Sergey Ulanov | f1b2b42 | 2020-01-24 15:39:32 -0800 | [diff] [blame] | 34 | static constexpr size_t kMaxAtlasTextureBytes = 2048 * 2048; |
| 35 | static constexpr size_t kPlotWidth = 512; |
| 36 | static constexpr size_t kPlotHeight = 256; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 37 | |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 38 | #ifdef DF_PATH_TRACKING |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 39 | static int g_NumCachedShapes = 0; |
| 40 | static int g_NumFreedShapes = 0; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 41 | #endif |
| 42 | |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 43 | // mip levels |
Sergey Ulanov | f1b2b42 | 2020-01-24 15:39:32 -0800 | [diff] [blame] | 44 | static constexpr SkScalar kIdealMinMIP = 12; |
| 45 | static constexpr SkScalar kMaxMIP = 162; |
Jim Van Verth | f9e678d | 2017-02-15 15:46:52 -0500 | [diff] [blame] | 46 | |
Sergey Ulanov | f1b2b42 | 2020-01-24 15:39:32 -0800 | [diff] [blame] | 47 | static constexpr SkScalar kMaxDim = 73; |
| 48 | static constexpr SkScalar kMinSize = SK_ScalarHalf; |
| 49 | static constexpr SkScalar kMaxSize = 2*kMaxMIP; |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 50 | |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 51 | class ShapeDataKey { |
| 52 | public: |
| 53 | ShapeDataKey() {} |
| 54 | ShapeDataKey(const ShapeDataKey& that) { *this = that; } |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 55 | ShapeDataKey(const GrStyledShape& shape, uint32_t dim) { this->set(shape, dim); } |
| 56 | ShapeDataKey(const GrStyledShape& shape, const SkMatrix& ctm) { this->set(shape, ctm); } |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 57 | |
| 58 | ShapeDataKey& operator=(const ShapeDataKey& that) { |
| 59 | fKey.reset(that.fKey.count()); |
| 60 | memcpy(fKey.get(), that.fKey.get(), fKey.count() * sizeof(uint32_t)); |
| 61 | return *this; |
| 62 | } |
| 63 | |
| 64 | // for SDF paths |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 65 | void set(const GrStyledShape& shape, uint32_t dim) { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 66 | // Shapes' keys are for their pre-style geometry, but by now we shouldn't have any |
| 67 | // relevant styling information. |
| 68 | SkASSERT(shape.style().isSimpleFill()); |
| 69 | SkASSERT(shape.hasUnstyledKey()); |
| 70 | int shapeKeySize = shape.unstyledKeySize(); |
| 71 | fKey.reset(1 + shapeKeySize); |
| 72 | fKey[0] = dim; |
| 73 | shape.writeUnstyledKey(&fKey[1]); |
| 74 | } |
| 75 | |
| 76 | // for bitmap paths |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 77 | void set(const GrStyledShape& shape, const SkMatrix& ctm) { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 78 | // Shapes' keys are for their pre-style geometry, but by now we shouldn't have any |
| 79 | // relevant styling information. |
| 80 | SkASSERT(shape.style().isSimpleFill()); |
| 81 | SkASSERT(shape.hasUnstyledKey()); |
| 82 | // We require the upper left 2x2 of the matrix to match exactly for a cache hit. |
| 83 | SkScalar sx = ctm.get(SkMatrix::kMScaleX); |
| 84 | SkScalar sy = ctm.get(SkMatrix::kMScaleY); |
| 85 | SkScalar kx = ctm.get(SkMatrix::kMSkewX); |
| 86 | SkScalar ky = ctm.get(SkMatrix::kMSkewY); |
| 87 | SkScalar tx = ctm.get(SkMatrix::kMTransX); |
| 88 | SkScalar ty = ctm.get(SkMatrix::kMTransY); |
| 89 | // Allow 8 bits each in x and y of subpixel positioning. |
Jim Van Verth | a64a585 | 2018-03-09 14:16:31 -0500 | [diff] [blame] | 90 | tx -= SkScalarFloorToScalar(tx); |
| 91 | ty -= SkScalarFloorToScalar(ty); |
| 92 | SkFixed fracX = SkScalarToFixed(tx) & 0x0000FF00; |
| 93 | SkFixed fracY = SkScalarToFixed(ty) & 0x0000FF00; |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 94 | int shapeKeySize = shape.unstyledKeySize(); |
| 95 | fKey.reset(5 + shapeKeySize); |
| 96 | fKey[0] = SkFloat2Bits(sx); |
| 97 | fKey[1] = SkFloat2Bits(sy); |
| 98 | fKey[2] = SkFloat2Bits(kx); |
| 99 | fKey[3] = SkFloat2Bits(ky); |
| 100 | fKey[4] = fracX | (fracY >> 8); |
| 101 | shape.writeUnstyledKey(&fKey[5]); |
| 102 | } |
| 103 | |
| 104 | bool operator==(const ShapeDataKey& that) const { |
| 105 | return fKey.count() == that.fKey.count() && |
| 106 | 0 == memcmp(fKey.get(), that.fKey.get(), sizeof(uint32_t) * fKey.count()); |
| 107 | } |
| 108 | |
| 109 | int count32() const { return fKey.count(); } |
| 110 | const uint32_t* data() const { return fKey.get(); } |
| 111 | |
| 112 | private: |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 113 | // The key is composed of the GrStyledShape's key, and either the dimensions of the DF |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 114 | // generated for the path (32x32 max, 64x64 max, 128x128 max) if an SDF image or |
| 115 | // the matrix for the path with only fractional translation. |
| 116 | SkAutoSTArray<24, uint32_t> fKey; |
| 117 | }; |
| 118 | |
| 119 | class ShapeData { |
| 120 | public: |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 121 | ShapeDataKey fKey; |
| 122 | SkRect fBounds; |
| 123 | GrDrawOpAtlas::AtlasLocator fAtlasLocator; |
| 124 | |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 125 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(ShapeData); |
| 126 | |
| 127 | static inline const ShapeDataKey& GetKey(const ShapeData& data) { |
| 128 | return data.fKey; |
| 129 | } |
| 130 | |
Kevin Lubick | b5502b2 | 2018-03-12 10:17:06 -0400 | [diff] [blame] | 131 | static inline uint32_t Hash(const ShapeDataKey& key) { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 132 | return SkOpts::hash(key.data(), sizeof(uint32_t) * key.count32()); |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | |
| 137 | |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 138 | // Callback to clear out internal path cache when eviction occurs |
Herb Derby | 4d72171 | 2020-01-24 14:31:16 -0500 | [diff] [blame] | 139 | void GrSmallPathRenderer::evict(GrDrawOpAtlas::PlotLocator plotLocator) { |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 140 | // remove any paths that use this plot |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 141 | ShapeDataList::Iter iter; |
Herb Derby | 1a496c5 | 2020-01-22 17:26:56 -0500 | [diff] [blame] | 142 | iter.init(fShapeList, ShapeDataList::Iter::kHead_IterStart); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 143 | ShapeData* shapeData; |
| 144 | while ((shapeData = iter.get())) { |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 145 | iter.next(); |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 146 | if (plotLocator == shapeData->fAtlasLocator.plotLocator()) { |
Herb Derby | 1a496c5 | 2020-01-22 17:26:56 -0500 | [diff] [blame] | 147 | fShapeCache.remove(shapeData->fKey); |
| 148 | fShapeList.remove(shapeData); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 149 | delete shapeData; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 150 | #ifdef DF_PATH_TRACKING |
| 151 | ++g_NumFreedPaths; |
| 152 | #endif |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 157 | //////////////////////////////////////////////////////////////////////////////// |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 158 | GrSmallPathRenderer::GrSmallPathRenderer() : fAtlas(nullptr) {} |
jvanverth | 6d22eca | 2014-10-28 11:10:48 -0700 | [diff] [blame] | 159 | |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 160 | GrSmallPathRenderer::~GrSmallPathRenderer() { |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 161 | ShapeDataList::Iter iter; |
| 162 | iter.init(fShapeList, ShapeDataList::Iter::kHead_IterStart); |
| 163 | ShapeData* shapeData; |
| 164 | while ((shapeData = iter.get())) { |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 165 | iter.next(); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 166 | delete shapeData; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 167 | } |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 168 | |
| 169 | #ifdef DF_PATH_TRACKING |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 170 | SkDebugf("Cached shapes: %d, freed shapes: %d\n", g_NumCachedShapes, g_NumFreedShapes); |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 171 | #endif |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | //////////////////////////////////////////////////////////////////////////////// |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 175 | GrPathRenderer::CanDrawPath GrSmallPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 176 | if (!args.fCaps->shaderCaps()->shaderDerivativeSupport()) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 177 | return CanDrawPath::kNo; |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 178 | } |
| 179 | // If the shape has no key then we won't get any reuse. |
| 180 | if (!args.fShape->hasUnstyledKey()) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 181 | return CanDrawPath::kNo; |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 182 | } |
| 183 | // This only supports filled paths, however, the caller may apply the style to make a filled |
| 184 | // path and try again. |
| 185 | if (!args.fShape->style().isSimpleFill()) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 186 | return CanDrawPath::kNo; |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 187 | } |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 188 | // This does non-inverse coverage-based antialiased fills. |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 189 | if (GrAAType::kCoverage != args.fAAType) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 190 | return CanDrawPath::kNo; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 191 | } |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 192 | // TODO: Support inverse fill |
bsalomon | db7979a | 2016-06-27 11:08:43 -0700 | [diff] [blame] | 193 | if (args.fShape->inverseFilled()) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 194 | return CanDrawPath::kNo; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 195 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 196 | |
Jim Van Verth | f9e678d | 2017-02-15 15:46:52 -0500 | [diff] [blame] | 197 | // Only support paths with bounds within kMaxDim by kMaxDim, |
| 198 | // scaled to have bounds within kMaxSize by kMaxSize. |
Jim Van Verth | 7704754 | 2017-01-11 14:17:00 -0500 | [diff] [blame] | 199 | // The goal is to accelerate rendering of lots of small paths that may be scaling. |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 200 | SkScalar scaleFactors[2] = { 1, 1 }; |
| 201 | if (!args.fViewMatrix->hasPerspective() && !args.fViewMatrix->getMinMaxScales(scaleFactors)) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 202 | return CanDrawPath::kNo; |
Jim Van Verth | f9e678d | 2017-02-15 15:46:52 -0500 | [diff] [blame] | 203 | } |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 204 | SkRect bounds = args.fShape->styledBounds(); |
Brian Osman | 116b33e | 2020-02-05 13:34:09 -0500 | [diff] [blame] | 205 | SkScalar minDim = std::min(bounds.width(), bounds.height()); |
| 206 | SkScalar maxDim = std::max(bounds.width(), bounds.height()); |
Jim Van Verth | d25cc9b | 2017-02-16 10:01:46 -0500 | [diff] [blame] | 207 | SkScalar minSize = minDim * SkScalarAbs(scaleFactors[0]); |
| 208 | SkScalar maxSize = maxDim * SkScalarAbs(scaleFactors[1]); |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 209 | if (maxDim > kMaxDim || kMinSize > minSize || maxSize > kMaxSize) { |
| 210 | return CanDrawPath::kNo; |
| 211 | } |
bsalomon | 6266dca | 2016-03-11 06:22:00 -0800 | [diff] [blame] | 212 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 213 | return CanDrawPath::kYes; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 214 | } |
| 215 | |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 216 | //////////////////////////////////////////////////////////////////////////////// |
| 217 | |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 218 | // padding around path bounds to allow for antialiased pixels |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 219 | static const int kAntiAliasPad = 1; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 220 | |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 221 | class GrSmallPathRenderer::SmallPathOp final : public GrMeshDrawOp { |
| 222 | private: |
| 223 | using Helper = GrSimpleMeshDrawOpHelperWithStencil; |
| 224 | |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 225 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 226 | DEFINE_OP_CLASS_ID |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 227 | |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 228 | using ShapeCache = SkTDynamicHash<ShapeData, ShapeDataKey>; |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 229 | using ShapeDataList = GrSmallPathRenderer::ShapeDataList; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 230 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 231 | static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 232 | GrPaint&& paint, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 233 | const GrStyledShape& shape, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 234 | const SkMatrix& viewMatrix, |
| 235 | GrDrawOpAtlas* atlas, |
| 236 | ShapeCache* shapeCache, |
| 237 | ShapeDataList* shapeList, |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 238 | bool gammaCorrect, |
| 239 | const GrUserStencilSettings* stencilSettings) { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 240 | return Helper::FactoryHelper<SmallPathOp>(context, std::move(paint), shape, viewMatrix, |
| 241 | atlas, shapeCache, shapeList, gammaCorrect, |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 242 | stencilSettings); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 243 | } |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 244 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 245 | SmallPathOp(Helper::MakeArgs helperArgs, const SkPMColor4f& color, const GrStyledShape& shape, |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 246 | const SkMatrix& viewMatrix, GrDrawOpAtlas* atlas, ShapeCache* shapeCache, |
| 247 | ShapeDataList* shapeList, bool gammaCorrect, |
| 248 | const GrUserStencilSettings* stencilSettings) |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 249 | : INHERITED(ClassID()) |
| 250 | , fHelper(helperArgs, GrAAType::kCoverage, stencilSettings) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 251 | SkASSERT(shape.hasUnstyledKey()); |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 252 | // Compute bounds |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 253 | this->setTransformedBounds(shape.bounds(), viewMatrix, HasAABloat::kYes, IsHairline::kNo); |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 254 | |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 255 | #if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 256 | fUsesDistanceField = true; |
| 257 | #else |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 258 | // only use distance fields on desktop and Android framework to save space in the atlas |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 259 | fUsesDistanceField = this->bounds().width() > kMaxMIP || this->bounds().height() > kMaxMIP; |
| 260 | #endif |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 261 | // always use distance fields if in perspective |
| 262 | fUsesDistanceField = fUsesDistanceField || viewMatrix.hasPerspective(); |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 263 | |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 264 | fShapes.emplace_back(Entry{color, shape, viewMatrix}); |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 265 | |
| 266 | fAtlas = atlas; |
| 267 | fShapeCache = shapeCache; |
| 268 | fShapeList = shapeList; |
| 269 | fGammaCorrect = gammaCorrect; |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 270 | } |
| 271 | |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 272 | const char* name() const override { return "SmallPathOp"; } |
| 273 | |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 274 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 275 | fHelper.visitProxies(func); |
| 276 | |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 277 | const GrSurfaceProxyView* views = fAtlas->getViews(); |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 278 | for (uint32_t i = 0; i < fAtlas->numActivePages(); ++i) { |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 279 | SkASSERT(views[i].proxy()); |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 280 | func(views[i].proxy(), GrMipmapped::kNo); |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 284 | #ifdef SK_DEBUG |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 285 | SkString dumpInfo() const override { |
| 286 | SkString string; |
| 287 | for (const auto& geo : fShapes) { |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 288 | string.appendf("Color: 0x%08x\n", geo.fColor.toBytes_RGBA()); |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 289 | } |
| 290 | string += fHelper.dumpInfo(); |
| 291 | string += INHERITED::dumpInfo(); |
| 292 | return string; |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 293 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 294 | #endif |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 295 | |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 296 | FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); } |
| 297 | |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 298 | GrProcessorSet::Analysis finalize( |
| 299 | const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage, |
| 300 | GrClampType clampType) override { |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 301 | return fHelper.finalizeProcessors( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 302 | caps, clip, hasMixedSampledCoverage, clampType, |
| 303 | GrProcessorAnalysisCoverage::kSingleChannel, &fShapes.front().fColor, &fWideColor); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 306 | private: |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 307 | struct FlushInfo { |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 308 | sk_sp<const GrBuffer> fVertexBuffer; |
| 309 | sk_sp<const GrBuffer> fIndexBuffer; |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 310 | GrGeometryProcessor* fGeometryProcessor; |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 311 | const GrSurfaceProxy** fPrimProcProxies; |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 312 | int fVertexOffset; |
| 313 | int fInstancesToFlush; |
| 314 | }; |
| 315 | |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 316 | GrProgramInfo* programInfo() override { |
| 317 | // TODO [PI]: implement |
| 318 | return nullptr; |
| 319 | } |
| 320 | |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 321 | void onCreateProgramInfo(const GrCaps*, |
| 322 | SkArenaAlloc*, |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 323 | const GrSurfaceProxyView* writeView, |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 324 | GrAppliedClip&&, |
| 325 | const GrXferProcessor::DstProxyView&) override { |
| 326 | // TODO [PI]: implement |
| 327 | } |
| 328 | |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 329 | void onPrePrepareDraws(GrRecordingContext*, |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 330 | const GrSurfaceProxyView* writeView, |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 331 | GrAppliedClip*, |
| 332 | const GrXferProcessor::DstProxyView&) override { |
| 333 | // TODO [PI]: implement |
| 334 | } |
| 335 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 336 | void onPrepareDraws(Target* target) override { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 337 | int instanceCount = fShapes.count(); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 338 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 339 | static constexpr int kMaxTextures = GrDistanceFieldPathGeoProc::kMaxTextures; |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 340 | static_assert(GrBitmapTextGeoProc::kMaxTextures == kMaxTextures); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 341 | |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 342 | FlushInfo flushInfo; |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 343 | flushInfo.fPrimProcProxies = target->allocPrimProcProxyPtrs(kMaxTextures); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 344 | int numActiveProxies = fAtlas->numActivePages(); |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 345 | const auto views = fAtlas->getViews(); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 346 | for (int i = 0; i < numActiveProxies; ++i) { |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 347 | // This op does not know its atlas proxies when it is added to a GrOpsTasks, so the |
| 348 | // proxies don't get added during the visitProxies call. Thus we add them here. |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 349 | flushInfo.fPrimProcProxies[i] = views[i].proxy(); |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 350 | target->sampledProxyArray()->push_back(views[i].proxy()); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 351 | } |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 352 | |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 353 | // Setup GrGeometryProcessor |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 354 | const SkMatrix& ctm = fShapes[0].fViewMatrix; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 355 | if (fUsesDistanceField) { |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 356 | uint32_t flags = 0; |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 357 | // Still need to key off of ctm to pick the right shader for the transformed quad |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 358 | flags |= ctm.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0; |
| 359 | flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
| 360 | flags |= fGammaCorrect ? kGammaCorrect_DistanceFieldEffectFlag : 0; |
| 361 | |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 362 | const SkMatrix* matrix; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 363 | SkMatrix invert; |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 364 | if (ctm.hasPerspective()) { |
| 365 | matrix = &ctm; |
| 366 | } else if (fHelper.usesLocalCoords()) { |
| 367 | if (!ctm.invert(&invert)) { |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 368 | return; |
| 369 | } |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 370 | matrix = &invert; |
| 371 | } else { |
| 372 | matrix = &SkMatrix::I(); |
| 373 | } |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 374 | flushInfo.fGeometryProcessor = GrDistanceFieldPathGeoProc::Make( |
| 375 | target->allocator(), *target->caps().shaderCaps(), *matrix, fWideColor, |
Brian Salomon | a3b02f5 | 2020-07-15 16:02:01 -0400 | [diff] [blame] | 376 | fAtlas->getViews(), fAtlas->numActivePages(), GrSamplerState::Filter::kLinear, |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 377 | flags); |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 378 | } else { |
| 379 | SkMatrix invert; |
| 380 | if (fHelper.usesLocalCoords()) { |
| 381 | if (!ctm.invert(&invert)) { |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 382 | return; |
| 383 | } |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 384 | } |
| 385 | |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 386 | flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make( |
| 387 | target->allocator(), *target->caps().shaderCaps(), this->color(), fWideColor, |
| 388 | fAtlas->getViews(), fAtlas->numActivePages(), GrSamplerState::Filter::kNearest, |
| 389 | kA8_GrMaskFormat, invert, false); |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 390 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 391 | |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 392 | // allocate vertices |
Brian Osman | 0dd4302 | 2018-11-16 15:53:26 -0500 | [diff] [blame] | 393 | const size_t kVertexStride = flushInfo.fGeometryProcessor->vertexStride(); |
Greg Daniel | d5b4593 | 2018-06-07 13:15:10 -0400 | [diff] [blame] | 394 | |
| 395 | // We need to make sure we don't overflow a 32 bit int when we request space in the |
| 396 | // makeVertexSpace call below. |
Robert Phillips | ee08d52 | 2019-10-28 16:34:44 -0400 | [diff] [blame] | 397 | if (instanceCount > SK_MaxS32 / GrResourceProvider::NumVertsPerNonAAQuad()) { |
Greg Daniel | d5b4593 | 2018-06-07 13:15:10 -0400 | [diff] [blame] | 398 | return; |
| 399 | } |
Robert Phillips | ee08d52 | 2019-10-28 16:34:44 -0400 | [diff] [blame] | 400 | GrVertexWriter vertices{ target->makeVertexSpace( |
| 401 | kVertexStride, GrResourceProvider::NumVertsPerNonAAQuad() * instanceCount, |
| 402 | &flushInfo.fVertexBuffer, &flushInfo.fVertexOffset)}; |
| 403 | |
| 404 | flushInfo.fIndexBuffer = target->resourceProvider()->refNonAAQuadIndexBuffer(); |
Brian Osman | 0dd4302 | 2018-11-16 15:53:26 -0500 | [diff] [blame] | 405 | if (!vertices.fPtr || !flushInfo.fIndexBuffer) { |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 406 | SkDebugf("Could not allocate vertices\n"); |
| 407 | return; |
| 408 | } |
| 409 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 410 | flushInfo.fInstancesToFlush = 0; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 411 | for (int i = 0; i < instanceCount; i++) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 412 | const Entry& args = fShapes[i]; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 413 | |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 414 | ShapeData* shapeData; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 415 | if (fUsesDistanceField) { |
| 416 | // get mip level |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 417 | SkScalar maxScale; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 418 | const SkRect& bounds = args.fShape.bounds(); |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 419 | if (args.fViewMatrix.hasPerspective()) { |
| 420 | // approximate the scale since we can't get it from the matrix |
| 421 | SkRect xformedBounds; |
| 422 | args.fViewMatrix.mapRect(&xformedBounds, bounds); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 423 | maxScale = SkScalarAbs(std::max(xformedBounds.width() / bounds.width(), |
Jim Van Verth | 5124593 | 2017-10-12 11:07:29 -0400 | [diff] [blame] | 424 | xformedBounds.height() / bounds.height())); |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 425 | } else { |
| 426 | maxScale = SkScalarAbs(args.fViewMatrix.getMaxScale()); |
| 427 | } |
Brian Osman | 116b33e | 2020-02-05 13:34:09 -0500 | [diff] [blame] | 428 | SkScalar maxDim = std::max(bounds.width(), bounds.height()); |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 429 | // We try to create the DF at a 2^n scaled path resolution (1/2, 1, 2, 4, etc.) |
| 430 | // In the majority of cases this will yield a crisper rendering. |
| 431 | SkScalar mipScale = 1.0f; |
| 432 | // Our mipscale is the maxScale clamped to the next highest power of 2 |
| 433 | if (maxScale <= SK_ScalarHalf) { |
| 434 | SkScalar log = SkScalarFloorToScalar(SkScalarLog2(SkScalarInvert(maxScale))); |
| 435 | mipScale = SkScalarPow(2, -log); |
| 436 | } else if (maxScale > SK_Scalar1) { |
| 437 | SkScalar log = SkScalarCeilToScalar(SkScalarLog2(maxScale)); |
| 438 | mipScale = SkScalarPow(2, log); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 439 | } |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 440 | SkASSERT(maxScale <= mipScale); |
Jim Van Verth | ecdb686 | 2016-12-13 18:17:47 -0500 | [diff] [blame] | 441 | |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 442 | SkScalar mipSize = mipScale*SkScalarAbs(maxDim); |
| 443 | // For sizes less than kIdealMinMIP we want to use as large a distance field as we can |
| 444 | // so we can preserve as much detail as possible. However, we can't scale down more |
| 445 | // than a 1/4 of the size without artifacts. So the idea is that we pick the mipsize |
| 446 | // just bigger than the ideal, and then scale down until we are no more than 4x the |
| 447 | // original mipsize. |
| 448 | if (mipSize < kIdealMinMIP) { |
| 449 | SkScalar newMipSize = mipSize; |
| 450 | do { |
| 451 | newMipSize *= 2; |
| 452 | } while (newMipSize < kIdealMinMIP); |
| 453 | while (newMipSize > 4 * mipSize) { |
| 454 | newMipSize *= 0.25f; |
| 455 | } |
| 456 | mipSize = newMipSize; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 457 | } |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 458 | SkScalar desiredDimension = std::min(mipSize, kMaxMIP); |
Jim Van Verth | c0bc1bb | 2017-02-27 18:21:16 -0500 | [diff] [blame] | 459 | |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 460 | // check to see if df path is cached |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 461 | ShapeDataKey key(args.fShape, SkScalarCeilToInt(desiredDimension)); |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 462 | shapeData = fShapeCache->find(key); |
Robert Phillips | bf5bf74 | 2020-04-13 09:29:08 -0400 | [diff] [blame] | 463 | if (!shapeData || !fAtlas->hasID(shapeData->fAtlasLocator.plotLocator())) { |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 464 | // Remove the stale cache entry |
| 465 | if (shapeData) { |
| 466 | fShapeCache->remove(shapeData->fKey); |
| 467 | fShapeList->remove(shapeData); |
| 468 | delete shapeData; |
| 469 | } |
| 470 | SkScalar scale = desiredDimension / maxDim; |
| 471 | |
| 472 | shapeData = new ShapeData; |
| 473 | if (!this->addDFPathToAtlas(target, |
| 474 | &flushInfo, |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 475 | fAtlas, |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 476 | shapeData, |
| 477 | args.fShape, |
| 478 | SkScalarCeilToInt(desiredDimension), |
| 479 | scale)) { |
| 480 | delete shapeData; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 481 | continue; |
| 482 | } |
Jim Van Verth | c0bc1bb | 2017-02-27 18:21:16 -0500 | [diff] [blame] | 483 | } |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 484 | } else { |
| 485 | // check to see if bitmap path is cached |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 486 | ShapeDataKey key(args.fShape, args.fViewMatrix); |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 487 | shapeData = fShapeCache->find(key); |
Robert Phillips | bf5bf74 | 2020-04-13 09:29:08 -0400 | [diff] [blame] | 488 | if (!shapeData || !fAtlas->hasID(shapeData->fAtlasLocator.plotLocator())) { |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 489 | // Remove the stale cache entry |
| 490 | if (shapeData) { |
| 491 | fShapeCache->remove(shapeData->fKey); |
| 492 | fShapeList->remove(shapeData); |
| 493 | delete shapeData; |
| 494 | } |
| 495 | |
| 496 | shapeData = new ShapeData; |
| 497 | if (!this->addBMPathToAtlas(target, |
Robert Phillips | 8296e75 | 2017-08-25 08:45:21 -0400 | [diff] [blame] | 498 | &flushInfo, |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 499 | fAtlas, |
Robert Phillips | 8296e75 | 2017-08-25 08:45:21 -0400 | [diff] [blame] | 500 | shapeData, |
| 501 | args.fShape, |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 502 | args.fViewMatrix)) { |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 503 | delete shapeData; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 504 | continue; |
| 505 | } |
| 506 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 509 | auto uploadTarget = target->deferredUploadTarget(); |
Herb Derby | 4d72171 | 2020-01-24 14:31:16 -0500 | [diff] [blame] | 510 | fAtlas->setLastUseToken( |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 511 | shapeData->fAtlasLocator, uploadTarget->tokenTracker()->nextDrawToken()); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 512 | |
Brian Osman | c906d25 | 2018-12-04 11:17:46 -0500 | [diff] [blame] | 513 | this->writePathVertices(fAtlas, vertices, GrVertexColor(args.fColor, fWideColor), |
| 514 | args.fViewMatrix, shapeData); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 515 | flushInfo.fInstancesToFlush++; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 516 | } |
| 517 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 518 | this->flush(target, &flushInfo); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 521 | bool addToAtlas(GrMeshDrawOp::Target* target, FlushInfo* flushInfo, GrDrawOpAtlas* atlas, |
| 522 | int width, int height, const void* image, |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 523 | GrDrawOpAtlas::AtlasLocator* atlasLocator) const { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 524 | auto resourceProvider = target->resourceProvider(); |
| 525 | auto uploadTarget = target->deferredUploadTarget(); |
| 526 | |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 527 | GrDrawOpAtlas::ErrorCode code = atlas->addToAtlas(resourceProvider, uploadTarget, |
| 528 | width, height, image, atlasLocator); |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 529 | if (GrDrawOpAtlas::ErrorCode::kError == code) { |
| 530 | return false; |
| 531 | } |
| 532 | |
| 533 | if (GrDrawOpAtlas::ErrorCode::kTryAgain == code) { |
| 534 | this->flush(target, flushInfo); |
| 535 | |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 536 | code = atlas->addToAtlas(resourceProvider, uploadTarget, width, height, |
| 537 | image, atlasLocator); |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | return GrDrawOpAtlas::ErrorCode::kSucceeded == code; |
| 541 | } |
| 542 | |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 543 | bool addDFPathToAtlas(GrMeshDrawOp::Target* target, FlushInfo* flushInfo, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 544 | GrDrawOpAtlas* atlas, ShapeData* shapeData, const GrStyledShape& shape, |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 545 | uint32_t dimension, SkScalar scale) const { |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 546 | |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 547 | const SkRect& bounds = shape.bounds(); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 548 | |
| 549 | // generate bounding rect for bitmap draw |
| 550 | SkRect scaledBounds = bounds; |
| 551 | // scale to mip level size |
| 552 | scaledBounds.fLeft *= scale; |
| 553 | scaledBounds.fTop *= scale; |
| 554 | scaledBounds.fRight *= scale; |
| 555 | scaledBounds.fBottom *= scale; |
Jim Van Verth | ecdb686 | 2016-12-13 18:17:47 -0500 | [diff] [blame] | 556 | // subtract out integer portion of origin |
| 557 | // (SDF created will be placed with fractional offset burnt in) |
Jim Van Verth | 07b6ad0 | 2016-12-20 10:23:09 -0500 | [diff] [blame] | 558 | SkScalar dx = SkScalarFloorToScalar(scaledBounds.fLeft); |
| 559 | SkScalar dy = SkScalarFloorToScalar(scaledBounds.fTop); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 560 | scaledBounds.offset(-dx, -dy); |
| 561 | // get integer boundary |
| 562 | SkIRect devPathBounds; |
| 563 | scaledBounds.roundOut(&devPathBounds); |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 564 | // place devBounds at origin with padding to allow room for antialiasing |
| 565 | int width = devPathBounds.width() + 2 * kAntiAliasPad; |
| 566 | int height = devPathBounds.height() + 2 * kAntiAliasPad; |
Jim Van Verth | ecdb686 | 2016-12-13 18:17:47 -0500 | [diff] [blame] | 567 | devPathBounds = SkIRect::MakeWH(width, height); |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 568 | SkScalar translateX = kAntiAliasPad - dx; |
| 569 | SkScalar translateY = kAntiAliasPad - dy; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 570 | |
| 571 | // draw path to bitmap |
| 572 | SkMatrix drawMatrix; |
Jim Van Verth | ecdb686 | 2016-12-13 18:17:47 -0500 | [diff] [blame] | 573 | drawMatrix.setScale(scale, scale); |
Robert Phillips | 3cf781d | 2017-08-22 18:25:11 -0400 | [diff] [blame] | 574 | drawMatrix.postTranslate(translateX, translateY); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 575 | |
jvanverth | 512e437 | 2015-11-23 11:50:02 -0800 | [diff] [blame] | 576 | SkASSERT(devPathBounds.fLeft == 0); |
| 577 | SkASSERT(devPathBounds.fTop == 0); |
Jim Van Verth | 25b8ca1 | 2017-02-17 14:02:13 -0500 | [diff] [blame] | 578 | SkASSERT(devPathBounds.width() > 0); |
| 579 | SkASSERT(devPathBounds.height() > 0); |
bsalomon | f93f515 | 2016-10-26 08:00:00 -0700 | [diff] [blame] | 580 | |
joel.liang | 8cbb424 | 2017-01-09 18:39:43 -0800 | [diff] [blame] | 581 | // setup signed distance field storage |
| 582 | SkIRect dfBounds = devPathBounds.makeOutset(SK_DistanceFieldPad, SK_DistanceFieldPad); |
| 583 | width = dfBounds.width(); |
| 584 | height = dfBounds.height(); |
rmistry | 4784225 | 2016-12-21 04:25:18 -0800 | [diff] [blame] | 585 | // TODO We should really generate this directly into the plot somehow |
| 586 | SkAutoSMalloc<1024> dfStorage(width * height * sizeof(unsigned char)); |
joel.liang | 6d2f73c | 2016-12-20 18:58:53 -0800 | [diff] [blame] | 587 | |
joel.liang | 8cbb424 | 2017-01-09 18:39:43 -0800 | [diff] [blame] | 588 | SkPath path; |
| 589 | shape.asPath(&path); |
joel.liang | 8cbb424 | 2017-01-09 18:39:43 -0800 | [diff] [blame] | 590 | // Generate signed distance field directly from SkPath |
| 591 | bool succeed = GrGenerateDistanceFieldFromPath((unsigned char*)dfStorage.get(), |
| 592 | path, drawMatrix, |
| 593 | width, height, width * sizeof(unsigned char)); |
| 594 | if (!succeed) { |
joel.liang | 8cbb424 | 2017-01-09 18:39:43 -0800 | [diff] [blame] | 595 | // setup bitmap backing |
| 596 | SkAutoPixmapStorage dst; |
| 597 | if (!dst.tryAlloc(SkImageInfo::MakeA8(devPathBounds.width(), |
| 598 | devPathBounds.height()))) { |
| 599 | return false; |
| 600 | } |
Mike Reed | f0ffb89 | 2017-10-03 14:47:21 -0400 | [diff] [blame] | 601 | sk_bzero(dst.writable_addr(), dst.computeByteSize()); |
joel.liang | 8cbb424 | 2017-01-09 18:39:43 -0800 | [diff] [blame] | 602 | |
| 603 | // rasterize path |
| 604 | SkPaint paint; |
| 605 | paint.setStyle(SkPaint::kFill_Style); |
| 606 | paint.setAntiAlias(true); |
| 607 | |
| 608 | SkDraw draw; |
joel.liang | 8cbb424 | 2017-01-09 18:39:43 -0800 | [diff] [blame] | 609 | |
| 610 | SkRasterClip rasterClip; |
| 611 | rasterClip.setRect(devPathBounds); |
| 612 | draw.fRC = &rasterClip; |
Brian Osman | 9aaec36 | 2020-05-08 14:54:37 -0400 | [diff] [blame] | 613 | SkSimpleMatrixProvider matrixProvider(drawMatrix); |
| 614 | draw.fMatrixProvider = &matrixProvider; |
joel.liang | 8cbb424 | 2017-01-09 18:39:43 -0800 | [diff] [blame] | 615 | draw.fDst = dst; |
| 616 | |
| 617 | draw.drawPathCoverage(path, paint); |
| 618 | |
| 619 | // Generate signed distance field |
| 620 | SkGenerateDistanceFieldFromA8Image((unsigned char*)dfStorage.get(), |
| 621 | (const unsigned char*)dst.addr(), |
| 622 | dst.width(), dst.height(), dst.rowBytes()); |
joel.liang | 8cbb424 | 2017-01-09 18:39:43 -0800 | [diff] [blame] | 623 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 624 | |
| 625 | // add to atlas |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 626 | if (!this->addToAtlas(target, flushInfo, atlas, width, height, dfStorage.get(), |
| 627 | &shapeData->fAtlasLocator)) { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 628 | return false; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | // add to cache |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 632 | shapeData->fKey.set(shape, dimension); |
Jim Van Verth | ecdb686 | 2016-12-13 18:17:47 -0500 | [diff] [blame] | 633 | |
Robert Phillips | 3cf781d | 2017-08-22 18:25:11 -0400 | [diff] [blame] | 634 | shapeData->fBounds = SkRect::Make(devPathBounds); |
| 635 | shapeData->fBounds.offset(-translateX, -translateY); |
| 636 | shapeData->fBounds.fLeft /= scale; |
| 637 | shapeData->fBounds.fTop /= scale; |
| 638 | shapeData->fBounds.fRight /= scale; |
| 639 | shapeData->fBounds.fBottom /= scale; |
Jim Van Verth | ecdb686 | 2016-12-13 18:17:47 -0500 | [diff] [blame] | 640 | |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 641 | fShapeCache->add(shapeData); |
| 642 | fShapeList->addToTail(shapeData); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 643 | #ifdef DF_PATH_TRACKING |
| 644 | ++g_NumCachedPaths; |
| 645 | #endif |
| 646 | return true; |
| 647 | } |
| 648 | |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 649 | bool addBMPathToAtlas(GrMeshDrawOp::Target* target, FlushInfo* flushInfo, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 650 | GrDrawOpAtlas* atlas, ShapeData* shapeData, const GrStyledShape& shape, |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 651 | const SkMatrix& ctm) const { |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 652 | const SkRect& bounds = shape.bounds(); |
| 653 | if (bounds.isEmpty()) { |
| 654 | return false; |
| 655 | } |
| 656 | SkMatrix drawMatrix(ctm); |
Jim Van Verth | a64a585 | 2018-03-09 14:16:31 -0500 | [diff] [blame] | 657 | SkScalar tx = ctm.getTranslateX(); |
| 658 | SkScalar ty = ctm.getTranslateY(); |
| 659 | tx -= SkScalarFloorToScalar(tx); |
| 660 | ty -= SkScalarFloorToScalar(ty); |
| 661 | drawMatrix.set(SkMatrix::kMTransX, tx); |
| 662 | drawMatrix.set(SkMatrix::kMTransY, ty); |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 663 | SkRect shapeDevBounds; |
| 664 | drawMatrix.mapRect(&shapeDevBounds, bounds); |
| 665 | SkScalar dx = SkScalarFloorToScalar(shapeDevBounds.fLeft); |
| 666 | SkScalar dy = SkScalarFloorToScalar(shapeDevBounds.fTop); |
| 667 | |
| 668 | // get integer boundary |
| 669 | SkIRect devPathBounds; |
| 670 | shapeDevBounds.roundOut(&devPathBounds); |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 671 | // place devBounds at origin with padding to allow room for antialiasing |
| 672 | int width = devPathBounds.width() + 2 * kAntiAliasPad; |
| 673 | int height = devPathBounds.height() + 2 * kAntiAliasPad; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 674 | devPathBounds = SkIRect::MakeWH(width, height); |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 675 | SkScalar translateX = kAntiAliasPad - dx; |
| 676 | SkScalar translateY = kAntiAliasPad - dy; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 677 | |
| 678 | SkASSERT(devPathBounds.fLeft == 0); |
| 679 | SkASSERT(devPathBounds.fTop == 0); |
| 680 | SkASSERT(devPathBounds.width() > 0); |
| 681 | SkASSERT(devPathBounds.height() > 0); |
| 682 | |
| 683 | SkPath path; |
| 684 | shape.asPath(&path); |
| 685 | // setup bitmap backing |
| 686 | SkAutoPixmapStorage dst; |
| 687 | if (!dst.tryAlloc(SkImageInfo::MakeA8(devPathBounds.width(), |
| 688 | devPathBounds.height()))) { |
| 689 | return false; |
| 690 | } |
Mike Reed | f0ffb89 | 2017-10-03 14:47:21 -0400 | [diff] [blame] | 691 | sk_bzero(dst.writable_addr(), dst.computeByteSize()); |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 692 | |
| 693 | // rasterize path |
| 694 | SkPaint paint; |
| 695 | paint.setStyle(SkPaint::kFill_Style); |
| 696 | paint.setAntiAlias(true); |
| 697 | |
| 698 | SkDraw draw; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 699 | |
| 700 | SkRasterClip rasterClip; |
| 701 | rasterClip.setRect(devPathBounds); |
| 702 | draw.fRC = &rasterClip; |
| 703 | drawMatrix.postTranslate(translateX, translateY); |
Brian Osman | 9aaec36 | 2020-05-08 14:54:37 -0400 | [diff] [blame] | 704 | SkSimpleMatrixProvider matrixProvider(drawMatrix); |
| 705 | draw.fMatrixProvider = &matrixProvider; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 706 | draw.fDst = dst; |
| 707 | |
| 708 | draw.drawPathCoverage(path, paint); |
| 709 | |
| 710 | // add to atlas |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 711 | if (!this->addToAtlas(target, flushInfo, atlas, dst.width(), dst.height(), dst.addr(), |
| 712 | &shapeData->fAtlasLocator)) { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 713 | return false; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | // add to cache |
| 717 | shapeData->fKey.set(shape, ctm); |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 718 | |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 719 | shapeData->fBounds = SkRect::Make(devPathBounds); |
| 720 | shapeData->fBounds.offset(-translateX, -translateY); |
| 721 | |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 722 | fShapeCache->add(shapeData); |
| 723 | fShapeList->addToTail(shapeData); |
| 724 | #ifdef DF_PATH_TRACKING |
| 725 | ++g_NumCachedPaths; |
| 726 | #endif |
| 727 | return true; |
| 728 | } |
| 729 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 730 | void writePathVertices(GrDrawOpAtlas* atlas, |
Brian Osman | 0dd4302 | 2018-11-16 15:53:26 -0500 | [diff] [blame] | 731 | GrVertexWriter& vertices, |
Brian Osman | c906d25 | 2018-12-04 11:17:46 -0500 | [diff] [blame] | 732 | const GrVertexColor& color, |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 733 | const SkMatrix& ctm, |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 734 | const ShapeData* shapeData) const { |
Brian Osman | 0dd4302 | 2018-11-16 15:53:26 -0500 | [diff] [blame] | 735 | SkRect translatedBounds(shapeData->fBounds); |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 736 | if (!fUsesDistanceField) { |
Jim Van Verth | a64a585 | 2018-03-09 14:16:31 -0500 | [diff] [blame] | 737 | translatedBounds.offset(SkScalarFloorToScalar(ctm.get(SkMatrix::kMTransX)), |
| 738 | SkScalarFloorToScalar(ctm.get(SkMatrix::kMTransY))); |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 739 | } |
Jim Van Verth | 7704754 | 2017-01-11 14:17:00 -0500 | [diff] [blame] | 740 | |
Brian Osman | 0dd4302 | 2018-11-16 15:53:26 -0500 | [diff] [blame] | 741 | // set up texture coordinates |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 742 | auto texCoords = GrVertexWriter::TriStripFromUVs(shapeData->fAtlasLocator.getUVs( |
| 743 | fUsesDistanceField ? SK_DistanceFieldPad : 0)); |
Brian Osman | 0dd4302 | 2018-11-16 15:53:26 -0500 | [diff] [blame] | 744 | |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 745 | if (fUsesDistanceField && !ctm.hasPerspective()) { |
Michael Ludwig | e9c57d3 | 2019-02-13 13:39:39 -0500 | [diff] [blame] | 746 | vertices.writeQuad(GrQuad::MakeFromRect(translatedBounds, ctm), |
Brian Osman | 0dd4302 | 2018-11-16 15:53:26 -0500 | [diff] [blame] | 747 | color, |
| 748 | texCoords); |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 749 | } else { |
Brian Osman | 0dd4302 | 2018-11-16 15:53:26 -0500 | [diff] [blame] | 750 | vertices.writeQuad(GrVertexWriter::TriStripFromRect(translatedBounds), |
| 751 | color, |
| 752 | texCoords); |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 753 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 756 | void flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const { |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 757 | GrGeometryProcessor* gp = flushInfo->fGeometryProcessor; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 758 | int numAtlasTextures = SkToInt(fAtlas->numActivePages()); |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 759 | const auto views = fAtlas->getViews(); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 760 | if (gp->numTextureSamplers() != numAtlasTextures) { |
| 761 | for (int i = gp->numTextureSamplers(); i < numAtlasTextures; ++i) { |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 762 | flushInfo->fPrimProcProxies[i] = views[i].proxy(); |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 763 | // This op does not know its atlas proxies when it is added to a GrOpsTasks, so the |
| 764 | // proxies don't get added during the visitProxies call. Thus we add them here. |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 765 | target->sampledProxyArray()->push_back(views[i].proxy()); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 766 | } |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 767 | // During preparation the number of atlas pages has increased. |
| 768 | // Update the proxies used in the GP to match. |
| 769 | if (fUsesDistanceField) { |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 770 | reinterpret_cast<GrDistanceFieldPathGeoProc*>(gp)->addNewViews( |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 771 | fAtlas->getViews(), fAtlas->numActivePages(), |
Brian Salomon | a3b02f5 | 2020-07-15 16:02:01 -0400 | [diff] [blame] | 772 | GrSamplerState::Filter::kLinear); |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 773 | } else { |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 774 | reinterpret_cast<GrBitmapTextGeoProc*>(gp)->addNewViews( |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 775 | fAtlas->getViews(), fAtlas->numActivePages(), |
| 776 | GrSamplerState::Filter::kNearest); |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 780 | if (flushInfo->fInstancesToFlush) { |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 781 | GrSimpleMesh* mesh = target->allocMesh(); |
Robert Phillips | ee08d52 | 2019-10-28 16:34:44 -0400 | [diff] [blame] | 782 | mesh->setIndexedPatterned(flushInfo->fIndexBuffer, |
| 783 | GrResourceProvider::NumIndicesPerNonAAQuad(), |
Robert Phillips | ee08d52 | 2019-10-28 16:34:44 -0400 | [diff] [blame] | 784 | flushInfo->fInstancesToFlush, |
Chris Dalton | 37c7bdd | 2020-03-13 09:21:12 -0600 | [diff] [blame] | 785 | GrResourceProvider::MaxNumNonAAQuads(), |
| 786 | flushInfo->fVertexBuffer, |
| 787 | GrResourceProvider::NumVertsPerNonAAQuad(), |
| 788 | flushInfo->fVertexOffset); |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 789 | target->recordDraw(flushInfo->fGeometryProcessor, mesh, 1, flushInfo->fPrimProcProxies, |
| 790 | GrPrimitiveType::kTriangles); |
Robert Phillips | ee08d52 | 2019-10-28 16:34:44 -0400 | [diff] [blame] | 791 | flushInfo->fVertexOffset += GrResourceProvider::NumVertsPerNonAAQuad() * |
| 792 | flushInfo->fInstancesToFlush; |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 793 | flushInfo->fInstancesToFlush = 0; |
| 794 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 795 | } |
| 796 | |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 797 | void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { |
Robert Phillips | 6c59fe4 | 2020-02-27 09:30:37 -0500 | [diff] [blame] | 798 | auto pipeline = fHelper.createPipelineWithStencil(flushState); |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 799 | |
| 800 | flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 803 | const SkPMColor4f& color() const { return fShapes[0].fColor; } |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 804 | bool usesDistanceField() const { return fUsesDistanceField; } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 805 | |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 806 | CombineResult onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*, |
| 807 | const GrCaps& caps) override { |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 808 | SmallPathOp* that = t->cast<SmallPathOp>(); |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 809 | if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 810 | return CombineResult::kCannotCombine; |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 813 | if (this->usesDistanceField() != that->usesDistanceField()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 814 | return CombineResult::kCannotCombine; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 815 | } |
| 816 | |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 817 | const SkMatrix& thisCtm = this->fShapes[0].fViewMatrix; |
| 818 | const SkMatrix& thatCtm = that->fShapes[0].fViewMatrix; |
| 819 | |
| 820 | if (thisCtm.hasPerspective() != thatCtm.hasPerspective()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 821 | return CombineResult::kCannotCombine; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 824 | // We can position on the cpu unless we're in perspective, |
| 825 | // but also need to make sure local matrices are identical |
| 826 | if ((thisCtm.hasPerspective() || fHelper.usesLocalCoords()) && |
Mike Reed | 2c38315 | 2019-12-18 16:47:47 -0500 | [diff] [blame] | 827 | !SkMatrixPriv::CheapEqual(thisCtm, thatCtm)) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 828 | return CombineResult::kCannotCombine; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 829 | } |
| 830 | |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 831 | // Depending on the ctm we may have a different shader for SDF paths |
| 832 | if (this->usesDistanceField()) { |
| 833 | if (thisCtm.isScaleTranslate() != thatCtm.isScaleTranslate() || |
| 834 | thisCtm.isSimilarity() != thatCtm.isSimilarity()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 835 | return CombineResult::kCannotCombine; |
Jim Van Verth | 5698c8a | 2017-10-12 10:18:44 -0400 | [diff] [blame] | 836 | } |
| 837 | } |
| 838 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 839 | fShapes.push_back_n(that->fShapes.count(), that->fShapes.begin()); |
Brian Osman | c906d25 | 2018-12-04 11:17:46 -0500 | [diff] [blame] | 840 | fWideColor |= that->fWideColor; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 841 | return CombineResult::kMerged; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 844 | bool fUsesDistanceField; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 845 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 846 | struct Entry { |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 847 | SkPMColor4f fColor; |
| 848 | GrStyledShape fShape; |
| 849 | SkMatrix fViewMatrix; |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 850 | }; |
| 851 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 852 | SkSTArray<1, Entry> fShapes; |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 853 | Helper fHelper; |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 854 | GrDrawOpAtlas* fAtlas; |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 855 | ShapeCache* fShapeCache; |
| 856 | ShapeDataList* fShapeList; |
brianosman | 0e3c554 | 2016-04-13 13:56:21 -0700 | [diff] [blame] | 857 | bool fGammaCorrect; |
Brian Osman | c906d25 | 2018-12-04 11:17:46 -0500 | [diff] [blame] | 858 | bool fWideColor; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 859 | |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 860 | typedef GrMeshDrawOp INHERITED; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 861 | }; |
| 862 | |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 863 | bool GrSmallPathRenderer::onDrawPath(const DrawPathArgs& args) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 864 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 865 | "GrSmallPathRenderer::onDrawPath"); |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 866 | |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 867 | // we've already bailed on inverse filled paths, so this is safe |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 868 | SkASSERT(!args.fShape->isEmpty()); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 869 | SkASSERT(args.fShape->hasUnstyledKey()); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 870 | if (!fAtlas) { |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 871 | const GrBackendFormat format = args.fContext->priv().caps()->getDefaultBackendFormat( |
| 872 | GrColorType::kAlpha_8, GrRenderable::kNo); |
Sergey Ulanov | f1b2b42 | 2020-01-24 15:39:32 -0800 | [diff] [blame] | 873 | |
| 874 | GrDrawOpAtlasConfig atlasConfig(args.fContext->priv().caps()->maxTextureSize(), |
| 875 | kMaxAtlasTextureBytes); |
| 876 | SkISize size = atlasConfig.atlasDimensions(kA8_GrMaskFormat); |
| 877 | fAtlas = GrDrawOpAtlas::Make(args.fContext->priv().proxyProvider(), format, |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 878 | GrColorType::kAlpha_8, size.width(), size.height(), |
| 879 | kPlotWidth, kPlotHeight, this, |
| 880 | GrDrawOpAtlas::AllowMultitexturing::kYes, this); |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 881 | if (!fAtlas) { |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 882 | return false; |
| 883 | } |
| 884 | } |
| 885 | |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 886 | std::unique_ptr<GrDrawOp> op = SmallPathOp::Make( |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 887 | args.fContext, std::move(args.fPaint), *args.fShape, *args.fViewMatrix, fAtlas.get(), |
| 888 | &fShapeCache, &fShapeList, args.fGammaCorrect, args.fUserStencilSettings); |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 889 | args.fRenderTargetContext->addDrawOp(args.fClip, std::move(op)); |
joshualitt | 9491f7f | 2015-02-11 11:33:38 -0800 | [diff] [blame] | 890 | |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 891 | return true; |
| 892 | } |
| 893 | |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 894 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 895 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 896 | #if GR_TEST_UTILS |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 897 | |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 898 | struct GrSmallPathRenderer::PathTestStruct : public GrDrawOpAtlas::EvictionCallback, |
| 899 | public GrDrawOpAtlas::GenerationCounter { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 900 | PathTestStruct() : fContextID(SK_InvalidGenID), fAtlas(nullptr) {} |
Herb Derby | 1a496c5 | 2020-01-22 17:26:56 -0500 | [diff] [blame] | 901 | ~PathTestStruct() override { this->reset(); } |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 902 | |
| 903 | void reset() { |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 904 | ShapeDataList::Iter iter; |
| 905 | iter.init(fShapeList, ShapeDataList::Iter::kHead_IterStart); |
| 906 | ShapeData* shapeData; |
| 907 | while ((shapeData = iter.get())) { |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 908 | iter.next(); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 909 | fShapeList.remove(shapeData); |
| 910 | delete shapeData; |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 911 | } |
Ben Wagner | 594f9ed | 2016-11-08 14:13:39 -0500 | [diff] [blame] | 912 | fAtlas = nullptr; |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 913 | fShapeCache.reset(); |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Herb Derby | 4d72171 | 2020-01-24 14:31:16 -0500 | [diff] [blame] | 916 | void evict(GrDrawOpAtlas::PlotLocator plotLocator) override { |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 917 | // remove any paths that use this plot |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 918 | ShapeDataList::Iter iter; |
Herb Derby | 1a496c5 | 2020-01-22 17:26:56 -0500 | [diff] [blame] | 919 | iter.init(fShapeList, ShapeDataList::Iter::kHead_IterStart); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 920 | ShapeData* shapeData; |
| 921 | while ((shapeData = iter.get())) { |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 922 | iter.next(); |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 923 | if (plotLocator == shapeData->fAtlasLocator.plotLocator()) { |
Herb Derby | 1a496c5 | 2020-01-22 17:26:56 -0500 | [diff] [blame] | 924 | fShapeCache.remove(shapeData->fKey); |
| 925 | fShapeList.remove(shapeData); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 926 | delete shapeData; |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | uint32_t fContextID; |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 932 | std::unique_ptr<GrDrawOpAtlas> fAtlas; |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 933 | ShapeCache fShapeCache; |
| 934 | ShapeDataList fShapeList; |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 935 | }; |
| 936 | |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 937 | std::unique_ptr<GrDrawOp> GrSmallPathRenderer::createOp_TestingOnly( |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 938 | GrRecordingContext* context, |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 939 | GrPaint&& paint, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 940 | const GrStyledShape& shape, |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 941 | const SkMatrix& viewMatrix, |
| 942 | GrDrawOpAtlas* atlas, |
| 943 | ShapeCache* shapeCache, |
| 944 | ShapeDataList* shapeList, |
| 945 | bool gammaCorrect, |
| 946 | const GrUserStencilSettings* stencil) { |
| 947 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 948 | return GrSmallPathRenderer::SmallPathOp::Make(context, std::move(paint), shape, viewMatrix, |
| 949 | atlas, shapeCache, shapeList, gammaCorrect, |
| 950 | stencil); |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 951 | |
| 952 | } |
| 953 | |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 954 | GR_DRAW_OP_TEST_DEFINE(SmallPathOp) { |
| 955 | using PathTestStruct = GrSmallPathRenderer::PathTestStruct; |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 956 | static PathTestStruct gTestStruct; |
| 957 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 958 | if (context->priv().contextID() != gTestStruct.fContextID) { |
| 959 | gTestStruct.fContextID = context->priv().contextID(); |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 960 | gTestStruct.reset(); |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 961 | const GrBackendFormat format = context->priv().caps()->getDefaultBackendFormat( |
| 962 | GrColorType::kAlpha_8, GrRenderable::kNo); |
Sergey Ulanov | f1b2b42 | 2020-01-24 15:39:32 -0800 | [diff] [blame] | 963 | GrDrawOpAtlasConfig atlasConfig(context->priv().caps()->maxTextureSize(), |
| 964 | kMaxAtlasTextureBytes); |
| 965 | SkISize size = atlasConfig.atlasDimensions(kA8_GrMaskFormat); |
| 966 | gTestStruct.fAtlas = |
| 967 | GrDrawOpAtlas::Make(context->priv().proxyProvider(), format, GrColorType::kAlpha_8, |
| 968 | size.width(), size.height(), kPlotWidth, kPlotHeight, |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 969 | &gTestStruct, |
Sergey Ulanov | f1b2b42 | 2020-01-24 15:39:32 -0800 | [diff] [blame] | 970 | GrDrawOpAtlas::AllowMultitexturing::kYes, &gTestStruct); |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | SkMatrix viewMatrix = GrTest::TestMatrix(random); |
brianosman | 0e3c554 | 2016-04-13 13:56:21 -0700 | [diff] [blame] | 974 | bool gammaCorrect = random->nextBool(); |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 975 | |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 976 | // This path renderer only allows fill styles. |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 977 | GrStyledShape shape(GrTest::TestPath(random), GrStyle::SimpleFill()); |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 978 | return GrSmallPathRenderer::createOp_TestingOnly( |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 979 | context, |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 980 | std::move(paint), shape, viewMatrix, |
| 981 | gTestStruct.fAtlas.get(), |
| 982 | &gTestStruct.fShapeCache, |
| 983 | &gTestStruct.fShapeList, |
| 984 | gammaCorrect, |
| 985 | GrGetRandomStencil(random, context)); |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | #endif |