Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 1 | /* |
| 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 Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 14 | struct GrCCPerFlushResourceSpecs; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 15 | class GrCCAtlas; |
| 16 | class GrCCPerFlushResources; |
| 17 | class GrOnFlushResourceProvider; |
| 18 | class 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 | */ |
| 25 | class GrCCClipPath { |
| 26 | public: |
| 27 | GrCCClipPath() = default; |
| 28 | GrCCClipPath(const GrCCClipPath&) = delete; |
| 29 | |
| 30 | ~GrCCClipPath() { |
Chris Dalton | b68bcc4 | 2018-09-14 00:44:22 -0600 | [diff] [blame^] | 31 | // Ensure no clip FP exists with a dangling pointer back into this class. This works because |
| 32 | // a clip FP will have a ref on the proxy if it exists. |
| 33 | // |
| 34 | // This assert also guarantees there won't be a lazy proxy callback with a dangling pointer |
| 35 | // back into this class, since no proxy will exist after we destruct, if the assert passes. |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 36 | SkASSERT(!fAtlasLazyProxy || fAtlasLazyProxy->isUnique_debugOnly()); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 37 | } |
| 38 | |
Ben Wagner | 5d1adbf | 2018-05-28 13:35:39 -0400 | [diff] [blame] | 39 | bool isInitialized() const { return fAtlasLazyProxy != nullptr; } |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 40 | void init(const SkPath& deviceSpacePath, const SkIRect& accessRect, int rtWidth, int rtHeight, |
| 41 | const GrCaps&); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 42 | |
| 43 | void addAccess(const SkIRect& accessRect) { |
| 44 | SkASSERT(this->isInitialized()); |
| 45 | fAccessRect.join(accessRect); |
| 46 | } |
| 47 | GrTextureProxy* atlasLazyProxy() const { |
| 48 | SkASSERT(this->isInitialized()); |
| 49 | return fAtlasLazyProxy.get(); |
| 50 | } |
| 51 | const SkPath& deviceSpacePath() const { |
| 52 | SkASSERT(this->isInitialized()); |
| 53 | return fDeviceSpacePath; |
| 54 | } |
| 55 | const SkIRect& pathDevIBounds() const { |
| 56 | SkASSERT(this->isInitialized()); |
| 57 | return fPathDevIBounds; |
| 58 | } |
| 59 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 60 | void accountForOwnPath(GrCCPerFlushResourceSpecs*) const; |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame] | 61 | void renderPathInAtlas(GrCCPerFlushResources*, GrOnFlushResourceProvider*); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 62 | |
| 63 | const SkVector& atlasScale() const { SkASSERT(fHasAtlasTransform); return fAtlasScale; } |
| 64 | const SkVector& atlasTranslate() const { SkASSERT(fHasAtlasTransform); return fAtlasTranslate; } |
| 65 | |
| 66 | private: |
| 67 | sk_sp<GrTextureProxy> fAtlasLazyProxy; |
| 68 | SkPath fDeviceSpacePath; |
| 69 | SkIRect fPathDevIBounds; |
| 70 | SkIRect fAccessRect; |
| 71 | |
| 72 | const GrCCAtlas* fAtlas = nullptr; |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 73 | SkIVector fDevToAtlasOffset; // Translation from device space to location in atlas. |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 74 | SkDEBUGCODE(bool fHasAtlas = false); |
| 75 | |
| 76 | SkVector fAtlasScale; |
| 77 | SkVector fAtlasTranslate; |
| 78 | SkDEBUGCODE(bool fHasAtlasTransform = false); |
| 79 | }; |
| 80 | |
| 81 | #endif |