blob: 3a4ea565faada664f2e6ebb0acbc6a1fc0693ed3 [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 GrCCClipPath_DEFINED
9#define GrCCClipPath_DEFINED
10
11#include "GrTextureProxy.h"
12#include "SkPath.h"
13
Chris Dalton42c21152018-06-13 15:28:19 -060014struct GrCCPerFlushResourceSpecs;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060015class GrCCAtlas;
16class GrCCPerFlushResources;
17class GrOnFlushResourceProvider;
18class GrProxyProvider;
19
20/**
21 * These are keyed by SkPath generation ID, and store which device-space paths are accessed and
22 * where by clip FPs in a given opList. A single GrCCClipPath can be referenced by multiple FPs. At
23 * flush time their coverage count masks are packed into atlas(es) alongside normal DrawPathOps.
24 */
25class GrCCClipPath {
26public:
27 GrCCClipPath() = default;
28 GrCCClipPath(const GrCCClipPath&) = delete;
29
30 ~GrCCClipPath() {
31 // Ensure no clip FPs exist with a dangling pointer back into this class.
32 SkASSERT(!fAtlasLazyProxy || fAtlasLazyProxy->isUnique_debugOnly());
33 // Ensure no lazy proxy callbacks exist with a dangling pointer back into this class.
34 SkASSERT(fHasAtlasTransform);
35 }
36
Ben Wagner5d1adbf2018-05-28 13:35:39 -040037 bool isInitialized() const { return fAtlasLazyProxy != nullptr; }
Chris Dalton4c458b12018-06-16 17:22:59 -060038 void init(const SkPath& deviceSpacePath, const SkIRect& accessRect, int rtWidth, int rtHeight,
39 const GrCaps&);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060040
41 void addAccess(const SkIRect& accessRect) {
42 SkASSERT(this->isInitialized());
43 fAccessRect.join(accessRect);
44 }
45 GrTextureProxy* atlasLazyProxy() const {
46 SkASSERT(this->isInitialized());
47 return fAtlasLazyProxy.get();
48 }
49 const SkPath& deviceSpacePath() const {
50 SkASSERT(this->isInitialized());
51 return fDeviceSpacePath;
52 }
53 const SkIRect& pathDevIBounds() const {
54 SkASSERT(this->isInitialized());
55 return fPathDevIBounds;
56 }
57
Chris Dalton42c21152018-06-13 15:28:19 -060058 void accountForOwnPath(GrCCPerFlushResourceSpecs*) const;
Chris Daltondaef06a2018-05-23 17:11:09 -060059 void renderPathInAtlas(GrCCPerFlushResources*, GrOnFlushResourceProvider*);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060060
61 const SkVector& atlasScale() const { SkASSERT(fHasAtlasTransform); return fAtlasScale; }
62 const SkVector& atlasTranslate() const { SkASSERT(fHasAtlasTransform); return fAtlasTranslate; }
63
64private:
65 sk_sp<GrTextureProxy> fAtlasLazyProxy;
66 SkPath fDeviceSpacePath;
67 SkIRect fPathDevIBounds;
68 SkIRect fAccessRect;
69
70 const GrCCAtlas* fAtlas = nullptr;
Chris Dalton9414c962018-06-14 10:14:50 -060071 SkIVector fDevToAtlasOffset; // Translation from device space to location in atlas.
Chris Dalton5ba36ba2018-05-09 01:08:38 -060072 SkDEBUGCODE(bool fHasAtlas = false);
73
74 SkVector fAtlasScale;
75 SkVector fAtlasTranslate;
76 SkDEBUGCODE(bool fHasAtlasTransform = false);
77};
78
79#endif