blob: 7c39c45d90e789f2a796360afaecd193bd423949 [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 Dalton5ba36ba2018-05-09 01:08:38 -060038 void init(GrProxyProvider* proxyProvider,
39 const SkPath& deviceSpacePath, const SkIRect& accessRect,
40 int rtWidth, int rtHeight);
41
42 void addAccess(const SkIRect& accessRect) {
43 SkASSERT(this->isInitialized());
44 fAccessRect.join(accessRect);
45 }
46 GrTextureProxy* atlasLazyProxy() const {
47 SkASSERT(this->isInitialized());
48 return fAtlasLazyProxy.get();
49 }
50 const SkPath& deviceSpacePath() const {
51 SkASSERT(this->isInitialized());
52 return fDeviceSpacePath;
53 }
54 const SkIRect& pathDevIBounds() const {
55 SkASSERT(this->isInitialized());
56 return fPathDevIBounds;
57 }
58
Chris Dalton42c21152018-06-13 15:28:19 -060059 void accountForOwnPath(GrCCPerFlushResourceSpecs*) const;
Chris Daltondaef06a2018-05-23 17:11:09 -060060 void renderPathInAtlas(GrCCPerFlushResources*, GrOnFlushResourceProvider*);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060061
62 const SkVector& atlasScale() const { SkASSERT(fHasAtlasTransform); return fAtlasScale; }
63 const SkVector& atlasTranslate() const { SkASSERT(fHasAtlasTransform); return fAtlasTranslate; }
64
65private:
66 sk_sp<GrTextureProxy> fAtlasLazyProxy;
67 SkPath fDeviceSpacePath;
68 SkIRect fPathDevIBounds;
69 SkIRect fAccessRect;
70
71 const GrCCAtlas* fAtlas = nullptr;
Chris Dalton9414c962018-06-14 10:14:50 -060072 SkIVector fDevToAtlasOffset; // Translation from device space to location in atlas.
Chris Dalton5ba36ba2018-05-09 01:08:38 -060073 SkDEBUGCODE(bool fHasAtlas = false);
74
75 SkVector fAtlasScale;
76 SkVector fAtlasTranslate;
77 SkDEBUGCODE(bool fHasAtlasTransform = false);
78};
79
80#endif