GrRenderTarget.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "include/core/SkRect.h"
  10. #include "include/gpu/GrSurface.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. /**
  30. * Returns the number of samples/pixel in the color buffer (One if non-MSAA).
  31. */
  32. int numSamples() const { return fSampleCnt; }
  33. /**
  34. * Call to indicate the multisample contents were modified such that the
  35. * render target needs to be resolved before it can be used as texture. Gr
  36. * tracks this for its own drawing and thus this only needs to be called
  37. * when the render target has been modified outside of Gr. This has no
  38. * effect on wrapped backend render targets.
  39. *
  40. * @param rect a rect bounding the area needing resolve. NULL indicates
  41. * the whole RT needs resolving.
  42. */
  43. void flagAsNeedingResolve(const SkIRect* rect = nullptr);
  44. /**
  45. * Call to indicate that GrRenderTarget was externally resolved. This may
  46. * allow Gr to skip a redundant resolve step.
  47. */
  48. void flagAsResolved();
  49. /**
  50. * @return true if the GrRenderTarget requires MSAA resolving
  51. */
  52. bool needsResolve() const { return !fResolveRect.isEmpty(); }
  53. /**
  54. * Returns a rect bounding the region needing resolving.
  55. */
  56. const SkIRect& getResolveRect() const { return fResolveRect; }
  57. // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
  58. // 0 in GL), or be unresolvable because the client didn't give us the
  59. // resolve destination.
  60. enum ResolveType {
  61. kCanResolve_ResolveType,
  62. kAutoResolves_ResolveType,
  63. kCantResolve_ResolveType,
  64. };
  65. virtual ResolveType getResolveType() const = 0;
  66. virtual GrBackendRenderTarget getBackendRenderTarget() const = 0;
  67. // Checked when this object is asked to attach a stencil buffer.
  68. virtual bool canAttemptStencilAttachment() const = 0;
  69. // Provides access to functions that aren't part of the public API.
  70. GrRenderTargetPriv renderTargetPriv();
  71. const GrRenderTargetPriv renderTargetPriv() const;
  72. protected:
  73. GrRenderTarget(GrGpu*, const GrSurfaceDesc&, int sampleCount, GrProtected,
  74. GrStencilAttachment* = nullptr);
  75. ~GrRenderTarget() override;
  76. // override of GrResource
  77. void onAbandon() override;
  78. void onRelease() override;
  79. private:
  80. // Allows the backends to perform any additional work that is required for attaching a
  81. // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto
  82. // the GrRenderTarget. This function must return false if any failures occur when completing the
  83. // stencil attachment.
  84. virtual bool completeStencilAttachment() = 0;
  85. friend class GrRenderTargetPriv;
  86. int fSampleCnt;
  87. int fSamplePatternKey;
  88. sk_sp<GrStencilAttachment> fStencilAttachment;
  89. SkIRect fResolveRect;
  90. typedef GrSurface INHERITED;
  91. };
  92. #endif