blob: e1d354d33383879503e2833f58d8502e87ff1536 [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
Chris Dalton4da70192018-06-18 09:51:36 -060011#include "GrShape.h"
Chris Dalton5ba36ba2018-05-09 01:08:38 -060012#include "SkTInternalLList.h"
Chris Dalton4bfb50b2018-05-21 09:10:53 -060013#include "ccpr/GrCCSTLList.h"
Chris Dalton5ba36ba2018-05-09 01:08:38 -060014#include "ops/GrDrawOp.h"
15
Chris Dalton42c21152018-06-13 15:28:19 -060016struct GrCCPerFlushResourceSpecs;
Chris Daltonb68bcc42018-09-14 00:44:22 -060017struct GrCCPerOpListPaths;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060018class GrCCAtlas;
Chris Dalton4da70192018-06-18 09:51:36 -060019class GrOnFlushResourceProvider;
20class GrCCPathCache;
21class GrCCPathCacheEntry;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060022class GrCCPerFlushResources;
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
Chris Dalton42c21152018-06-13 15:28:19 -060032 static std::unique_ptr<GrCCDrawPathsOp> Make(GrContext*, 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; }
Brian Osman532b3f92018-07-11 10:02:07 -040038 RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override;
Brian Salomon7eae3e02018-08-07 14:02:38 +000039 CombineResult onCombineIfPossible(GrOp*, const GrCaps&) override;
Chris Dalton4da70192018-06-18 09:51:36 -060040 void visitProxies(const VisitProxyFunc& fn) const override { fProcessors.visitProxies(fn); }
Chris Dalton5ba36ba2018-05-09 01:08:38 -060041 void onPrepare(GrOpFlushState*) override {}
42
Chris Daltonb68bcc42018-09-14 00:44:22 -060043 void wasRecorded(sk_sp<GrCCPerOpListPaths> owningPerOpListPaths);
Chris Dalton4da70192018-06-18 09:51:36 -060044
45 // Makes decisions about how to draw each path (cached, copied, rendered, etc.), and
46 // increments/fills out the corresponding GrCCPerFlushResourceSpecs. 'stashedAtlasKey', if
47 // valid, references the mainline coverage count atlas from the previous flush. Paths found in
48 // this atlas will be copied to more permanent atlases in the resource cache.
49 void accountForOwnPaths(GrCCPathCache*, GrOnFlushResourceProvider*,
50 const GrUniqueKey& stashedAtlasKey, GrCCPerFlushResourceSpecs*);
51
52 // Allows the caller to decide whether to copy paths out of the stashed atlas and into the
53 // resource cache, or to just re-render the paths from scratch. If there aren't many copies or
54 // the copies would only fill a small atlas, it's probably best to just re-render.
55 enum class DoCopiesToCache : bool {
56 kNo = false,
57 kYes = true
58 };
59
60 // Allocates the GPU resources indicated by accountForOwnPaths(), in preparation for drawing. If
61 // DoCopiesToCache is kNo, the paths slated for copy will instead be re-rendered from scratch.
62 //
63 // NOTE: If using DoCopiesToCache::kNo, it is the caller's responsibility to call
64 // convertCopiesToRenders() on the GrCCPerFlushResourceSpecs.
65 void setupResources(GrOnFlushResourceProvider*, GrCCPerFlushResources*, DoCopiesToCache);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060066
67 void onExecute(GrOpFlushState*) override;
68
69private:
Robert Phillips7c525e62018-06-12 10:11:12 -040070 friend class GrOpMemoryPool;
71
Chris Dalton09a7bb22018-08-31 19:53:15 +080072 static std::unique_ptr<GrCCDrawPathsOp> InternalMake(GrContext*, const SkIRect& clipIBounds,
73 const SkMatrix&, const GrShape&,
74 float strokeDevWidth,
75 const SkRect& conservativeDevBounds,
76 GrPaint&&);
Chris Daltona8429cf2018-06-22 11:43:31 -060077 enum class Visibility {
78 kPartial,
79 kMostlyComplete, // (i.e., can we cache the whole path mask if we think it will be reused?)
80 kComplete
81 };
82
Chris Dalton09a7bb22018-08-31 19:53:15 +080083 GrCCDrawPathsOp(const SkMatrix&, const GrShape&, float strokeDevWidth,
84 const SkIRect& shapeConservativeIBounds, const SkIRect& maskDevIBounds,
85 Visibility maskVisibility, 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
91 struct SingleDraw {
Chris Dalton09a7bb22018-08-31 19:53:15 +080092 SingleDraw(const SkMatrix&, const GrShape&, float strokeDevWidth,
93 const SkIRect& shapeConservativeIBounds, const SkIRect& maskDevIBounds,
94 Visibility maskVisibility, GrColor);
Chris Dalton4da70192018-06-18 09:51:36 -060095 ~SingleDraw();
96
Chris Dalton4bfb50b2018-05-21 09:10:53 -060097 SkMatrix fMatrix;
Chris Dalton09a7bb22018-08-31 19:53:15 +080098 GrShape fShape;
99 float fStrokeDevWidth;
100 const SkIRect fShapeConservativeIBounds;
Chris Daltona8429cf2018-06-22 11:43:31 -0600101 SkIRect fMaskDevIBounds;
102 Visibility fMaskVisibility;
Chris Dalton4bfb50b2018-05-21 09:10:53 -0600103 GrColor fColor;
Chris Dalton4da70192018-06-18 09:51:36 -0600104
105 sk_sp<GrCCPathCacheEntry> fCacheEntry;
106 sk_sp<GrTextureProxy> fCachedAtlasProxy;
107 SkIVector fCachedMaskShift;
108
Chris Dalton644341a2018-06-18 19:14:16 -0600109 SingleDraw* fNext = nullptr;
Chris Dalton4bfb50b2018-05-21 09:10:53 -0600110 };
111
112 GrCCSTLList<SingleDraw> fDraws;
113 SkDEBUGCODE(int fNumDraws = 1);
114
Chris Daltonb68bcc42018-09-14 00:44:22 -0600115 sk_sp<GrCCPerOpListPaths> fOwningPerOpListPaths;
Chris Dalton42c21152018-06-13 15:28:19 -0600116 GrProcessorSet fProcessors;
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600117
Chris Dalton4da70192018-06-18 09:51:36 -0600118 struct InstanceRange {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000119 GrTextureProxy* fAtlasProxy;
Chris Dalton4da70192018-06-18 09:51:36 -0600120 int fEndInstanceIdx;
121 };
122
123 SkSTArray<2, InstanceRange, true> fInstanceRanges;
124 int fBaseInstance SkDEBUGCODE(= -1);
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600125};
126
127#endif