GrRenderTargetContextPriv.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright 2016 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 GrRenderTargetContextPriv_DEFINED
  8. #define GrRenderTargetContextPriv_DEFINED
  9. #include "src/gpu/GrPathRendering.h"
  10. #include "src/gpu/GrRenderTargetContext.h"
  11. #include "src/gpu/GrRenderTargetOpList.h"
  12. class GrFixedClip;
  13. class GrHardClip;
  14. class GrPath;
  15. class GrRenderTargetPriv;
  16. struct GrUserStencilSettings;
  17. /** Class that adds methods to GrRenderTargetContext that are only intended for use internal to
  18. Skia. This class is purely a privileged window into GrRenderTargetContext. It should never have
  19. additional data members or virtual methods. */
  20. class GrRenderTargetContextPriv {
  21. public:
  22. // called to note the last clip drawn to the stencil buffer.
  23. // TODO: remove after clipping overhaul.
  24. void setLastClip(uint32_t clipStackGenID, const SkIRect& devClipBounds,
  25. int numClipAnalyticFPs) {
  26. GrRenderTargetOpList* opList = fRenderTargetContext->getRTOpList();
  27. opList->fLastClipStackGenID = clipStackGenID;
  28. opList->fLastDevClipBounds = devClipBounds;
  29. opList->fLastClipNumAnalyticFPs = numClipAnalyticFPs;
  30. }
  31. // called to determine if we have to render the clip into SB.
  32. // TODO: remove after clipping overhaul.
  33. bool mustRenderClip(uint32_t clipStackGenID, const SkIRect& devClipBounds,
  34. int numClipAnalyticFPs) const {
  35. GrRenderTargetOpList* opList = fRenderTargetContext->getRTOpList();
  36. return opList->fLastClipStackGenID != clipStackGenID ||
  37. !opList->fLastDevClipBounds.contains(devClipBounds) ||
  38. opList->fLastClipNumAnalyticFPs != numClipAnalyticFPs;
  39. }
  40. using CanClearFullscreen = GrRenderTargetContext::CanClearFullscreen;
  41. void clear(const GrFixedClip&, const SkPMColor4f&, CanClearFullscreen);
  42. void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
  43. /*
  44. * Some portions of the code, which use approximate-match rendertargets (i.e., ImageFilters),
  45. * rely on clears that lie outside of the content region to still have an effect.
  46. * For example, when sampling a decimated blurred image back up to full size, the GaussianBlur
  47. * code draws 1-pixel rects along the left and bottom edges to be able to use bilerp for
  48. * upsampling. The "absClear" entry point ignores the content bounds but does use the
  49. * worst case (instantiated) bounds.
  50. *
  51. * @param rect if (!null) the rect to clear, otherwise it is a full screen clear
  52. * @param color the color to clear to
  53. */
  54. void absClear(const SkIRect* rect, const SkPMColor4f& color);
  55. // While this can take a general clip, since GrReducedClip relies on this function, it must take
  56. // care to only provide hard clips or we could get stuck in a loop. The general clip is needed
  57. // so that path renderers can use this function.
  58. void stencilRect(
  59. const GrClip& clip, const GrUserStencilSettings* ss, GrPaint&& paint,
  60. GrAA doStencilMSAA, const SkMatrix& viewMatrix, const SkRect& rect,
  61. const SkMatrix* localMatrix = nullptr) {
  62. // Since this provides stencil settings to drawFilledQuad, it performs a different AA type
  63. // resolution compared to regular rect draws, which is the main reason it remains separate.
  64. GrQuad localQuad = localMatrix ? GrQuad::MakeFromRect(rect, *localMatrix) : GrQuad(rect);
  65. fRenderTargetContext->drawFilledQuad(
  66. clip, std::move(paint), doStencilMSAA, GrQuadAAFlags::kNone,
  67. GrQuad::MakeFromRect(rect, viewMatrix), localQuad, ss);
  68. }
  69. void stencilPath(
  70. const GrHardClip&, GrAA doStencilMSAA, const SkMatrix& viewMatrix, const GrPath*);
  71. /**
  72. * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings
  73. * for each color sample written.
  74. */
  75. bool drawAndStencilPath(const GrHardClip&,
  76. const GrUserStencilSettings*,
  77. SkRegion::Op op,
  78. bool invert,
  79. GrAA doStencilMSAA,
  80. const SkMatrix& viewMatrix,
  81. const SkPath&);
  82. SkBudgeted isBudgeted() const;
  83. int maxWindowRectangles() const;
  84. /*
  85. * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_
  86. * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
  87. */
  88. GrSurfaceProxy::UniqueID uniqueID() const {
  89. return fRenderTargetContext->fRenderTargetProxy->uniqueID();
  90. }
  91. uint32_t testingOnly_getOpListID();
  92. using WillAddOpFn = GrRenderTargetContext::WillAddOpFn;
  93. void testingOnly_addDrawOp(std::unique_ptr<GrDrawOp>);
  94. void testingOnly_addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>,
  95. const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
  96. bool refsWrappedObjects() const {
  97. return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
  98. }
  99. private:
  100. explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
  101. : fRenderTargetContext(renderTargetContext) {}
  102. GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
  103. GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
  104. // No taking addresses of this type.
  105. const GrRenderTargetContextPriv* operator&() const;
  106. GrRenderTargetContextPriv* operator&();
  107. GrRenderTargetContext* fRenderTargetContext;
  108. friend class GrRenderTargetContext; // to construct/copy this type.
  109. };
  110. inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
  111. return GrRenderTargetContextPriv(this);
  112. }
  113. inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
  114. return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
  115. }
  116. #endif