GrRenderTarget.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright 2011 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 GrRenderTarget_DEFINED
  8. #define GrRenderTarget_DEFINED
  9. #include "GrSurface.h"
  10. #include "SkRect.h"
  11. class GrCaps;
  12. class GrRenderTargetOpList;
  13. class GrRenderTargetPriv;
  14. class GrStencilAttachment;
  15. class GrBackendRenderTarget;
  16. /**
  17. * GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
  18. * A context's render target is set by setRenderTarget(). Render targets are
  19. * created by a createTexture with the kRenderTarget_SurfaceFlag flag.
  20. * Additionally, GrContext provides methods for creating GrRenderTargets
  21. * that wrap externally created render targets.
  22. */
  23. class GrRenderTarget : virtual public GrSurface {
  24. public:
  25. virtual bool alwaysClearStencil() const { return false; }
  26. // GrSurface overrides
  27. GrRenderTarget* asRenderTarget() override { return this; }
  28. const GrRenderTarget* asRenderTarget() const override { return this; }
  29. // GrRenderTarget
  30. bool isStencilBufferMultisampled() const { return fSampleCnt > 1; }
  31. GrFSAAType fsaaType() const {
  32. SkASSERT(fSampleCnt >= 1);
  33. if (fSampleCnt <= 1) {
  34. SkASSERT(!this->hasMixedSamples());
  35. return GrFSAAType::kNone;
  36. }
  37. return this->hasMixedSamples() ? GrFSAAType::kMixedSamples : GrFSAAType::kUnifiedMSAA;
  38. }
  39. /**
  40. * Returns the number of samples/pixel in the stencil buffer (One if non-MSAA).
  41. */
  42. int numStencilSamples() const { return fSampleCnt; }
  43. /**
  44. * Returns the number of samples/pixel in the color buffer (One if non-MSAA or mixed sampled).
  45. */
  46. int numColorSamples() const {
  47. return GrFSAAType::kMixedSamples == this->fsaaType() ? 1 : fSampleCnt;
  48. }
  49. /**
  50. * Call to indicate the multisample contents were modified such that the
  51. * render target needs to be resolved before it can be used as texture. Gr
  52. * tracks this for its own drawing and thus this only needs to be called
  53. * when the render target has been modified outside of Gr. This has no
  54. * effect on wrapped backend render targets.
  55. *
  56. * @param rect a rect bounding the area needing resolve. NULL indicates
  57. * the whole RT needs resolving.
  58. */
  59. void flagAsNeedingResolve(const SkIRect* rect = nullptr);
  60. /**
  61. * Call to override the region that needs to be resolved.
  62. */
  63. void overrideResolveRect(const SkIRect rect);
  64. /**
  65. * Call to indicate that GrRenderTarget was externally resolved. This may
  66. * allow Gr to skip a redundant resolve step.
  67. */
  68. void flagAsResolved();
  69. /**
  70. * @return true if the GrRenderTarget requires MSAA resolving
  71. */
  72. bool needsResolve() const { return !fResolveRect.isEmpty(); }
  73. /**
  74. * Returns a rect bounding the region needing resolving.
  75. */
  76. const SkIRect& getResolveRect() const { return fResolveRect; }
  77. // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
  78. // 0 in GL), or be unresolvable because the client didn't give us the
  79. // resolve destination.
  80. enum ResolveType {
  81. kCanResolve_ResolveType,
  82. kAutoResolves_ResolveType,
  83. kCantResolve_ResolveType,
  84. };
  85. virtual ResolveType getResolveType() const = 0;
  86. virtual GrBackendRenderTarget getBackendRenderTarget() const = 0;
  87. // Checked when this object is asked to attach a stencil buffer.
  88. virtual bool canAttemptStencilAttachment() const = 0;
  89. // Provides access to functions that aren't part of the public API.
  90. GrRenderTargetPriv renderTargetPriv();
  91. const GrRenderTargetPriv renderTargetPriv() const;
  92. protected:
  93. GrRenderTarget(GrGpu*, const GrSurfaceDesc&, GrStencilAttachment* = nullptr);
  94. ~GrRenderTarget() override;
  95. // override of GrResource
  96. void onAbandon() override;
  97. void onRelease() override;
  98. private:
  99. // Allows the backends to perform any additional work that is required for attaching a
  100. // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto
  101. // the GrRenderTarget. This function must return false if any failures occur when completing the
  102. // stencil attachment.
  103. virtual bool completeStencilAttachment() = 0;
  104. friend class GrRenderTargetPriv;
  105. int fSampleCnt;
  106. sk_sp<GrStencilAttachment> fStencilAttachment;
  107. SkIRect fResolveRect;
  108. typedef GrSurface INHERITED;
  109. };
  110. #endif