GrCCClipPath.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifndef GrCCClipPath_DEFINED
  8. #define GrCCClipPath_DEFINED
  9. #include "include/core/SkPath.h"
  10. #include "src/gpu/GrTextureProxy.h"
  11. #include "src/gpu/ccpr/GrCCAtlas.h"
  12. struct GrCCPerFlushResourceSpecs;
  13. class GrCCPerFlushResources;
  14. class GrOnFlushResourceProvider;
  15. class GrProxyProvider;
  16. /**
  17. * These are keyed by SkPath generation ID, and store which device-space paths are accessed and
  18. * where by clip FPs in a given opList. A single GrCCClipPath can be referenced by multiple FPs. At
  19. * flush time their coverage count masks are packed into atlas(es) alongside normal DrawPathOps.
  20. */
  21. class GrCCClipPath {
  22. public:
  23. GrCCClipPath() = default;
  24. GrCCClipPath(const GrCCClipPath&) = delete;
  25. ~GrCCClipPath() {
  26. // Ensure no clip FP exists with a dangling pointer back into this class. This works because
  27. // a clip FP will have a ref on the proxy if it exists.
  28. //
  29. // This assert also guarantees there won't be a lazy proxy callback with a dangling pointer
  30. // back into this class, since no proxy will exist after we destruct, if the assert passes.
  31. SkASSERT(!fAtlasLazyProxy || fAtlasLazyProxy->unique());
  32. }
  33. bool isInitialized() const { return fAtlasLazyProxy != nullptr; }
  34. void init(const SkPath& deviceSpacePath, const SkIRect& accessRect,
  35. GrCCAtlas::CoverageType atlasCoverageType, const GrCaps&);
  36. void addAccess(const SkIRect& accessRect) {
  37. SkASSERT(this->isInitialized());
  38. fAccessRect.join(accessRect);
  39. }
  40. GrTextureProxy* atlasLazyProxy() const {
  41. SkASSERT(this->isInitialized());
  42. return fAtlasLazyProxy.get();
  43. }
  44. const SkPath& deviceSpacePath() const {
  45. SkASSERT(this->isInitialized());
  46. return fDeviceSpacePath;
  47. }
  48. const SkIRect& pathDevIBounds() const {
  49. SkASSERT(this->isInitialized());
  50. return fPathDevIBounds;
  51. }
  52. void accountForOwnPath(GrCCPerFlushResourceSpecs*) const;
  53. void renderPathInAtlas(GrCCPerFlushResources*, GrOnFlushResourceProvider*);
  54. const SkVector& atlasScale() const { SkASSERT(fHasAtlasTransform); return fAtlasScale; }
  55. const SkVector& atlasTranslate() const { SkASSERT(fHasAtlasTransform); return fAtlasTranslate; }
  56. private:
  57. sk_sp<GrTextureProxy> fAtlasLazyProxy;
  58. SkPath fDeviceSpacePath;
  59. SkIRect fPathDevIBounds;
  60. SkIRect fAccessRect;
  61. const GrCCAtlas* fAtlas = nullptr;
  62. SkIVector fDevToAtlasOffset; // Translation from device space to location in atlas.
  63. SkDEBUGCODE(bool fHasAtlas = false;)
  64. SkVector fAtlasScale;
  65. SkVector fAtlasTranslate;
  66. SkDEBUGCODE(bool fHasAtlasTransform = false;)
  67. };
  68. #endif