| 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 "include/core/SkPath.h" |
| 12 | #include "src/gpu/GrTextureProxy.h" |
| 13 | #include "src/gpu/ccpr/GrCCAtlas.h" |
| 14 | |
| 15 | struct GrCCPerFlushResourceSpecs; |
| 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 opsTask. 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() { |
| 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. |
| 36 | SkASSERT(!fAtlasLazyProxy || fAtlasLazyProxy->unique()); |
| 37 | } |
| 38 | |
| 39 | bool isInitialized() const { return fAtlasLazyProxy != nullptr; } |
| 40 | void init(const SkPath& deviceSpacePath, |
| 41 | const SkIRect& desc, |
| 42 | GrCCAtlas::CoverageType atlasCoverageType, |
| 43 | const GrCaps&); |
| 44 | |
| 45 | void addAccess(const SkIRect& accessRect) { |
| 46 | SkASSERT(this->isInitialized()); |
| 47 | fAccessRect.join(accessRect); |
| 48 | } |
| 49 | GrTextureProxy* atlasLazyProxy() const { |
| 50 | SkASSERT(this->isInitialized()); |
| 51 | return fAtlasLazyProxy.get(); |
| 52 | } |
| 53 | const SkPath& deviceSpacePath() const { |
| 54 | SkASSERT(this->isInitialized()); |
| 55 | return fDeviceSpacePath; |
| 56 | } |
| 57 | const SkIRect& pathDevIBounds() const { |
| 58 | SkASSERT(this->isInitialized()); |
| 59 | return fPathDevIBounds; |
| 60 | } |
| 61 | |
| 62 | void accountForOwnPath(GrCCPerFlushResourceSpecs*) const; |
| 63 | void renderPathInAtlas(GrCCPerFlushResources*, GrOnFlushResourceProvider*); |
| 64 | |
| 65 | const SkIVector& atlasTranslate() const { |
| 66 | SkASSERT(fHasAtlasTranslate); |
| 67 | return fDevToAtlasOffset; |
| 68 | } |
| 69 | |
| 70 | private: |
| 71 | sk_sp<GrTextureProxy> fAtlasLazyProxy; |
| 72 | SkPath fDeviceSpacePath; |
| 73 | SkIRect fPathDevIBounds; |
| 74 | SkIRect fAccessRect; |
| 75 | |
| 76 | const GrCCAtlas* fAtlas = nullptr; |
| 77 | SkIVector fDevToAtlasOffset; // Translation from device space to location in atlas. |
| 78 | SkDEBUGCODE(bool fHasAtlas = false;) |
| 79 | SkDEBUGCODE(bool fHasAtlasTranslate = false;) |
| 80 | }; |
| 81 | |
| 82 | #endif |
| 83 |