blob: 5406d893f7490e6231daf10c99059dd6d98fc2f1 [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
11#include "SkTInternalLList.h"
Chris Dalton4bfb50b2018-05-21 09:10:53 -060012#include "ccpr/GrCCPathParser.h"
Chris Dalton5ba36ba2018-05-09 01:08:38 -060013#include "ccpr/GrCCPathProcessor.h"
Chris Dalton4bfb50b2018-05-21 09:10:53 -060014#include "ccpr/GrCCSTLList.h"
Chris Dalton5ba36ba2018-05-09 01:08:38 -060015#include "ops/GrDrawOp.h"
16
17class GrCCAtlas;
18class GrCCPerFlushResources;
Chris Daltond7e22272018-05-23 10:17:17 -060019struct GrCCPerOpListPaths;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060020
21/**
22 * This is the Op that draws paths to the actual canvas, using atlases generated by CCPR.
23 */
24class GrCCDrawPathsOp : public GrDrawOp {
25public:
26 DEFINE_OP_CLASS_ID
27 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrCCDrawPathsOp);
28
Chris Daltond7e22272018-05-23 10:17:17 -060029 GrCCDrawPathsOp(GrPaint&&, const SkIRect& clipIBounds, const SkMatrix&, const SkPath&,
30 const SkRect& devBounds);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060031 ~GrCCDrawPathsOp() override;
32
Chris Dalton5ba36ba2018-05-09 01:08:38 -060033 const char* name() const override { return "GrCCDrawOp"; }
34 FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
35 RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*,
36 GrPixelConfigIsClamped) override;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060037 bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override;
38 void visitProxies(const VisitProxyFunc& func) const override {
39 fProcessors.visitProxies(func);
40 }
41 void onPrepare(GrOpFlushState*) override {}
42
Chris Daltond7e22272018-05-23 10:17:17 -060043 void wasRecorded(GrCCPerOpListPaths* owningPerOpListPaths);
Chris Dalton4bfb50b2018-05-21 09:10:53 -060044 int countPaths(GrCCPathParser::PathStats*) const;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060045 void setupResources(GrCCPerFlushResources*, GrOnFlushResourceProvider*);
Chris Dalton4bfb50b2018-05-21 09:10:53 -060046 SkDEBUGCODE(int numSkippedInstances_debugOnly() const { return fNumSkippedInstances; })
Chris Dalton5ba36ba2018-05-09 01:08:38 -060047
48 void onExecute(GrOpFlushState*) override;
49
50private:
51 SkPath::FillType getFillType() const {
Chris Dalton4bfb50b2018-05-21 09:10:53 -060052 SkASSERT(fNumDraws >= 1);
53 return fDraws.head().fPath.getFillType();
Chris Dalton5ba36ba2018-05-09 01:08:38 -060054 }
55
56 struct AtlasBatch {
57 const GrCCAtlas* fAtlas;
58 int fEndInstanceIdx;
59 };
60
61 void addAtlasBatch(const GrCCAtlas* atlas, int endInstanceIdx) {
62 SkASSERT(endInstanceIdx > fBaseInstance);
63 SkASSERT(fAtlasBatches.empty() ||
64 endInstanceIdx > fAtlasBatches.back().fEndInstanceIdx);
65 fAtlasBatches.push_back() = {atlas, endInstanceIdx};
66 }
67
Chris Dalton4bfb50b2018-05-21 09:10:53 -060068 const uint32_t fSRGBFlags;
Chris Dalton1c548942018-05-22 13:09:48 -060069 const SkMatrix fViewMatrixIfUsingLocalCoords;
Chris Dalton4bfb50b2018-05-21 09:10:53 -060070
71 struct SingleDraw {
72 SkIRect fClipIBounds;
73 SkMatrix fMatrix;
74 SkPath fPath;
75 GrColor fColor;
76 SingleDraw* fNext;
77 };
78
79 GrCCSTLList<SingleDraw> fDraws;
80 SkDEBUGCODE(int fNumDraws = 1);
81
82 GrProcessorSet fProcessors;
Chris Daltond7e22272018-05-23 10:17:17 -060083 GrCCPerOpListPaths* fOwningPerOpListPaths = nullptr;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060084
Chris Dalton5ba36ba2018-05-09 01:08:38 -060085 int fBaseInstance;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060086 SkSTArray<1, AtlasBatch, true> fAtlasBatches;
Chris Dalton4bfb50b2018-05-21 09:10:53 -060087 SkDEBUGCODE(int fNumSkippedInstances = 0);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060088};
89
90#endif