blob: 1f951385a80ac4a3af443d992ea2449bf2ea3a40 [file] [log] [blame]
Chris Dalton5ba36ba2018-05-09 01:08:38 -06001/*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrCCDrawPathsOp_DEFINED
9#define GrCCDrawPathsOp_DEFINED
10
Ben Wagner729a23f2019-05-17 16:29:34 -040011#include "src/core/SkTInternalLList.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/ccpr/GrCCPathCache.h"
13#include "src/gpu/ccpr/GrCCSTLList.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040014#include "src/gpu/geometry/GrShape.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/ops/GrDrawOp.h"
Chris Dalton5ba36ba2018-05-09 01:08:38 -060016
Robert Phillips6f0e02f2019-02-13 11:02:28 -050017class GrCCAtlas;
18class GrCCPerFlushResources;
Chris Dalton42c21152018-06-13 15:28:19 -060019struct GrCCPerFlushResourceSpecs;
Chris Daltonb68bcc42018-09-14 00:44:22 -060020struct GrCCPerOpListPaths;
Chris Dalton4da70192018-06-18 09:51:36 -060021class GrOnFlushResourceProvider;
Robert Phillips6f0e02f2019-02-13 11:02:28 -050022class GrRecordingContext;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060023
24/**
25 * This is the Op that draws paths to the actual canvas, using atlases generated by CCPR.
26 */
27class GrCCDrawPathsOp : public GrDrawOp {
28public:
29 DEFINE_OP_CLASS_ID
30 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrCCDrawPathsOp);
31
Robert Phillips6f0e02f2019-02-13 11:02:28 -050032 static std::unique_ptr<GrCCDrawPathsOp> Make(GrRecordingContext*, const SkIRect& clipIBounds,
Chris Dalton09a7bb22018-08-31 19:53:15 +080033 const SkMatrix&, const GrShape&, GrPaint&&);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060034 ~GrCCDrawPathsOp() override;
35
Chris Dalton4da70192018-06-18 09:51:36 -060036 const char* name() const override { return "GrCCDrawPathsOp"; }
Chris Dalton5ba36ba2018-05-09 01:08:38 -060037 FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
Chris Dalton6ce447a2019-06-23 18:07:38 -060038 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
39 bool hasMixedSampledCoverage, GrClampType) override;
Brian Salomon7eae3e02018-08-07 14:02:38 +000040 CombineResult onCombineIfPossible(GrOp*, const GrCaps&) override;
Chris Dalton1706cbf2019-05-21 19:35:29 -060041 void visitProxies(const VisitProxyFunc& fn) const override {
Chris Dalton45f6b3d2019-05-21 12:06:03 -060042 for (const auto& range : fInstanceRanges) {
Chris Dalton7eb5c0f2019-05-23 15:15:47 -060043 fn(range.fAtlasProxy, GrMipMapped::kNo);
Chris Dalton45f6b3d2019-05-21 12:06:03 -060044 }
Brian Salomon7d94bb52018-10-12 14:37:19 -040045 fProcessors.visitProxies(fn);
46 }
Chris Dalton5ba36ba2018-05-09 01:08:38 -060047 void onPrepare(GrOpFlushState*) override {}
48
Brian Salomon348a0372018-10-31 10:42:18 -040049 void addToOwningPerOpListPaths(sk_sp<GrCCPerOpListPaths> owningPerOpListPaths);
Chris Dalton4da70192018-06-18 09:51:36 -060050
51 // Makes decisions about how to draw each path (cached, copied, rendered, etc.), and
Chris Dalton351e80c2019-01-06 22:51:00 -070052 // increments/fills out the corresponding GrCCPerFlushResourceSpecs.
53 void accountForOwnPaths(GrCCPathCache*, GrOnFlushResourceProvider*, GrCCPerFlushResourceSpecs*);
Chris Dalton4da70192018-06-18 09:51:36 -060054
Chris Dalton351e80c2019-01-06 22:51:00 -070055 // Allows the caller to decide whether to actually do the suggested copies from cached 16-bit
56 // coverage count atlases, and into 8-bit literal coverage atlases. Purely to save space.
57 enum class DoCopiesToA8Coverage : bool {
Chris Dalton4da70192018-06-18 09:51:36 -060058 kNo = false,
59 kYes = true
60 };
61
62 // Allocates the GPU resources indicated by accountForOwnPaths(), in preparation for drawing. If
Chris Dalton351e80c2019-01-06 22:51:00 -070063 // DoCopiesToA8Coverage is kNo, the paths slated for copy will instead be left in their 16-bit
64 // coverage count atlases.
Chris Dalton4da70192018-06-18 09:51:36 -060065 //
Chris Dalton351e80c2019-01-06 22:51:00 -070066 // NOTE: If using DoCopiesToA8Coverage::kNo, it is the caller's responsibility to have called
67 // cancelCopies() on the GrCCPerFlushResourceSpecs, prior to making this call.
68 void setupResources(GrCCPathCache*, GrOnFlushResourceProvider*, GrCCPerFlushResources*,
69 DoCopiesToA8Coverage);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060070
Brian Salomon588cec72018-11-14 13:56:37 -050071 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060072
73private:
Robert Phillips7c525e62018-06-12 10:11:12 -040074 friend class GrOpMemoryPool;
75
Robert Phillips6f0e02f2019-02-13 11:02:28 -050076 static std::unique_ptr<GrCCDrawPathsOp> InternalMake(GrRecordingContext*,
77 const SkIRect& clipIBounds,
Chris Dalton09a7bb22018-08-31 19:53:15 +080078 const SkMatrix&, const GrShape&,
79 float strokeDevWidth,
80 const SkRect& conservativeDevBounds,
81 GrPaint&&);
Chris Daltona8429cf2018-06-22 11:43:31 -060082
Chris Dalton09a7bb22018-08-31 19:53:15 +080083 GrCCDrawPathsOp(const SkMatrix&, const GrShape&, float strokeDevWidth,
84 const SkIRect& shapeConservativeIBounds, const SkIRect& maskDevIBounds,
Chris Daltonaaa77c12019-01-07 17:45:36 -070085 const SkRect& conservativeDevBounds, GrPaint&&);
Robert Phillips88a32ef2018-06-07 11:05:56 -040086
Brian Salomon7eae3e02018-08-07 14:02:38 +000087 void recordInstance(GrTextureProxy* atlasProxy, int instanceIdx);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060088
Chris Dalton1c548942018-05-22 13:09:48 -060089 const SkMatrix fViewMatrixIfUsingLocalCoords;
Chris Dalton4bfb50b2018-05-21 09:10:53 -060090
Chris Daltona13078c2019-01-07 09:34:05 -070091 class SingleDraw {
92 public:
Chris Dalton09a7bb22018-08-31 19:53:15 +080093 SingleDraw(const SkMatrix&, const GrShape&, float strokeDevWidth,
94 const SkIRect& shapeConservativeIBounds, const SkIRect& maskDevIBounds,
Chris Daltonaaa77c12019-01-07 17:45:36 -070095 const SkPMColor4f&);
Chris Dalton4da70192018-06-18 09:51:36 -060096
Chris Daltona13078c2019-01-07 09:34:05 -070097 // See the corresponding methods in GrCCDrawPathsOp.
Chris Daltonb8fff0d2019-03-05 10:11:58 -070098 GrProcessorSet::Analysis finalize(
Chris Dalton6ce447a2019-06-23 18:07:38 -060099 const GrCaps&, const GrAppliedClip*, bool hasMixedSampledCoverage, GrClampType,
100 GrProcessorSet*);
Chris Daltona13078c2019-01-07 09:34:05 -0700101 void accountForOwnPath(GrCCPathCache*, GrOnFlushResourceProvider*,
102 GrCCPerFlushResourceSpecs*);
103 void setupResources(GrCCPathCache*, GrOnFlushResourceProvider*, GrCCPerFlushResources*,
104 DoCopiesToA8Coverage, GrCCDrawPathsOp*);
105
106 private:
Chris Daltonaaa77c12019-01-07 17:45:36 -0700107 bool shouldCachePathMask(int maxRenderTargetSize) const;
108
Chris Dalton4bfb50b2018-05-21 09:10:53 -0600109 SkMatrix fMatrix;
Chris Dalton09a7bb22018-08-31 19:53:15 +0800110 GrShape fShape;
111 float fStrokeDevWidth;
112 const SkIRect fShapeConservativeIBounds;
Chris Daltona8429cf2018-06-22 11:43:31 -0600113 SkIRect fMaskDevIBounds;
Brian Osmancf860852018-10-31 14:04:39 -0400114 SkPMColor4f fColor;
Chris Dalton4da70192018-06-18 09:51:36 -0600115
Chris Dalton351e80c2019-01-06 22:51:00 -0700116 GrCCPathCache::OnFlushEntryRef fCacheEntry;
Chris Dalton4da70192018-06-18 09:51:36 -0600117 SkIVector fCachedMaskShift;
Chris Dalton351e80c2019-01-06 22:51:00 -0700118 bool fDoCopyToA8Coverage = false;
Chris Daltonaaa77c12019-01-07 17:45:36 -0700119 bool fDoCachePathMask = false;
Chris Dalton4da70192018-06-18 09:51:36 -0600120
Chris Dalton644341a2018-06-18 19:14:16 -0600121 SingleDraw* fNext = nullptr;
Chris Daltona13078c2019-01-07 09:34:05 -0700122
123 friend class GrCCSTLList<SingleDraw>; // To access fNext.
Chris Dalton4bfb50b2018-05-21 09:10:53 -0600124 };
125
Chris Daltondedf8f22018-09-24 20:23:47 -0600126 // Declare fOwningPerOpListPaths first, before fDraws. The draws use memory allocated by
127 // fOwningPerOpListPaths, so it must not be unreffed until after fDraws is destroyed.
128 sk_sp<GrCCPerOpListPaths> fOwningPerOpListPaths;
129
Chris Dalton4bfb50b2018-05-21 09:10:53 -0600130 GrCCSTLList<SingleDraw> fDraws;
131 SkDEBUGCODE(int fNumDraws = 1);
132
Chris Dalton42c21152018-06-13 15:28:19 -0600133 GrProcessorSet fProcessors;
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600134
Chris Dalton4da70192018-06-18 09:51:36 -0600135 struct InstanceRange {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000136 GrTextureProxy* fAtlasProxy;
Chris Dalton4da70192018-06-18 09:51:36 -0600137 int fEndInstanceIdx;
138 };
139
140 SkSTArray<2, InstanceRange, true> fInstanceRanges;
141 int fBaseInstance SkDEBUGCODE(= -1);
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600142};
143
144#endif