blob: 9189e5a757ecad785c50bc6ce5b8c9bb96a7c55c [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;
Robert Phillips774168e2018-05-31 12:43:27 -040019class 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:
Chris Dalton5ba36ba2018-05-09 01:08:38 -060051 struct AtlasBatch {
52 const GrCCAtlas* fAtlas;
53 int fEndInstanceIdx;
54 };
55
56 void addAtlasBatch(const GrCCAtlas* atlas, int endInstanceIdx) {
57 SkASSERT(endInstanceIdx > fBaseInstance);
58 SkASSERT(fAtlasBatches.empty() ||
59 endInstanceIdx > fAtlasBatches.back().fEndInstanceIdx);
60 fAtlasBatches.push_back() = {atlas, endInstanceIdx};
61 }
62
Chris Dalton4bfb50b2018-05-21 09:10:53 -060063 const uint32_t fSRGBFlags;
Chris Dalton1c548942018-05-22 13:09:48 -060064 const SkMatrix fViewMatrixIfUsingLocalCoords;
Chris Dalton4bfb50b2018-05-21 09:10:53 -060065
66 struct SingleDraw {
67 SkIRect fClipIBounds;
68 SkMatrix fMatrix;
69 SkPath fPath;
70 GrColor fColor;
71 SingleDraw* fNext;
72 };
73
74 GrCCSTLList<SingleDraw> fDraws;
75 SkDEBUGCODE(int fNumDraws = 1);
76
77 GrProcessorSet fProcessors;
Chris Daltond7e22272018-05-23 10:17:17 -060078 GrCCPerOpListPaths* fOwningPerOpListPaths = nullptr;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060079
Chris Dalton5ba36ba2018-05-09 01:08:38 -060080 int fBaseInstance;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060081 SkSTArray<1, AtlasBatch, true> fAtlasBatches;
Chris Dalton4bfb50b2018-05-21 09:10:53 -060082 SkDEBUGCODE(int fNumSkippedInstances = 0);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060083};
84
85#endif