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/GrSurfaceProxyPriv.h" 13 #include "src/gpu/GrTextureProxy.h" 14 #include "src/gpu/ccpr/GrCCAtlas.h" 15 16 struct GrCCPerFlushResourceSpecs; 17 class GrCCPerFlushResources; 18 class GrOnFlushResourceProvider; 19 class GrProxyProvider; 20 21 /** 22 * These are keyed by SkPath generation ID, and store which device-space paths are accessed and 23 * where by clip FPs in a given opsTask. A single GrCCClipPath can be referenced by multiple FPs. At 24 * flush time their coverage count masks are packed into atlas(es) alongside normal DrawPathOps. 25 */ 26 class GrCCClipPath : public SkRefCnt { 27 public: 28 GrCCClipPath(const SkPath& deviceSpacePath, const SkIRect&, const GrCaps&); 29 GrCCClipPath(const GrCCClipPath&) = delete; 30 addAccess(const SkIRect & accessRect)31 void addAccess(const SkIRect& accessRect) { fAccessRect.join(accessRect); } atlasLazyProxy()32 GrTextureProxy* atlasLazyProxy() const { return fAtlasLazyProxy.get(); } deviceSpacePath()33 const SkPath& deviceSpacePath() const { return fDeviceSpacePath; } pathDevIBounds()34 const SkIRect& pathDevIBounds() const { return fPathDevIBounds; } 35 36 void accountForOwnPath(GrCCAtlas::Specs*) const; 37 38 // Allocates our clip path in an atlas and records the offset. 39 // 40 // If the return value is non-null, it means the given path did not fit in the then-current 41 // atlas, so it was retired and a new one was added to the stack. The return value is the 42 // newly-retired atlas. (*NOT* the atlas this path will reside in.) The caller must call 43 // assignAtlasTexture on all prior GrCCClipPaths that will use the retired atlas. 44 std::unique_ptr<GrCCAtlas> renderPathInAtlas(GrCCPerFlushResources*, 45 GrOnFlushResourceProvider*); 46 atlasTranslate()47 const SkIVector& atlasTranslate() const { 48 SkASSERT(fHasAtlas); 49 return fDevToAtlasOffset; 50 } 51 assignAtlasTexture(sk_sp<GrTexture> atlasTexture)52 void assignAtlasTexture(sk_sp<GrTexture> atlasTexture) { 53 fAtlasLazyProxy->priv().assign(std::move(atlasTexture)); 54 } 55 56 private: 57 SkPath fDeviceSpacePath; 58 SkIRect fPathDevIBounds; 59 SkIRect fAccessRect; 60 sk_sp<GrTextureProxy> fAtlasLazyProxy; 61 62 SkIVector fDevToAtlasOffset; // Translation from device space to location in atlas. 63 SkDEBUGCODE(bool fHasAtlas = false;) 64 }; 65 66 #endif 67