GrRenderTargetProxy.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 GrRenderTargetProxy_DEFINED
  8. #define GrRenderTargetProxy_DEFINED
  9. #include "GrSurfaceProxy.h"
  10. #include "GrTypesPriv.h"
  11. class GrResourceProvider;
  12. class GrRenderTargetProxyPriv;
  13. // This class delays the acquisition of RenderTargets until they are actually
  14. // required
  15. // Beware: the uniqueID of the RenderTargetProxy will usually be different than
  16. // the uniqueID of the RenderTarget it represents!
  17. class GrRenderTargetProxy : virtual public GrSurfaceProxy {
  18. public:
  19. GrRenderTargetProxy* asRenderTargetProxy() override { return this; }
  20. const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; }
  21. // Actually instantiate the backing rendertarget, if necessary.
  22. bool instantiate(GrResourceProvider*) override;
  23. GrFSAAType fsaaType() const {
  24. if (fSampleCnt <= 1) {
  25. SkASSERT(!this->hasMixedSamples());
  26. return GrFSAAType::kNone;
  27. }
  28. return this->hasMixedSamples() ? GrFSAAType::kMixedSamples : GrFSAAType::kUnifiedMSAA;
  29. }
  30. /*
  31. * When instantiated does this proxy require a stencil buffer?
  32. */
  33. void setNeedsStencil() { fNeedsStencil = true; }
  34. bool needsStencil() const { return fNeedsStencil; }
  35. /**
  36. * Returns the number of samples/pixel in the stencil buffer (One if non-MSAA).
  37. */
  38. int numStencilSamples() const { return fSampleCnt; }
  39. /**
  40. * Returns the number of samples/pixel in the color buffer (One if non-MSAA or mixed sampled).
  41. */
  42. int numColorSamples() const {
  43. return GrFSAAType::kMixedSamples == this->fsaaType() ? 1 : fSampleCnt;
  44. }
  45. int maxWindowRectangles(const GrCaps& caps) const;
  46. // TODO: move this to a priv class!
  47. bool refsWrappedObjects() const;
  48. // Provides access to special purpose functions.
  49. GrRenderTargetProxyPriv rtPriv();
  50. const GrRenderTargetProxyPriv rtPriv() const;
  51. protected:
  52. friend class GrProxyProvider; // for ctors
  53. friend class GrRenderTargetProxyPriv;
  54. // Deferred version
  55. GrRenderTargetProxy(const GrCaps&, const GrBackendFormat&, const GrSurfaceDesc&,
  56. GrSurfaceOrigin, SkBackingFit, SkBudgeted, GrInternalSurfaceFlags);
  57. // Lazy-callback version
  58. // There are two main use cases for lazily-instantiated proxies:
  59. // basic knowledge - width, height, config, samples, origin are known
  60. // minimal knowledge - only config is known.
  61. //
  62. // The basic knowledge version is used for DDL where we know the type of proxy we are going to
  63. // use, but we don't have access to the GPU yet to instantiate it.
  64. //
  65. // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not
  66. // know the final size until flush time.
  67. GrRenderTargetProxy(LazyInstantiateCallback&&, LazyInstantiationType lazyType,
  68. const GrBackendFormat&, const GrSurfaceDesc&, GrSurfaceOrigin,
  69. SkBackingFit, SkBudgeted, GrInternalSurfaceFlags);
  70. // Wrapped version
  71. GrRenderTargetProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
  72. sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
  73. private:
  74. void setHasMixedSamples() {
  75. fSurfaceFlags |= GrInternalSurfaceFlags::kMixedSampled;
  76. }
  77. bool hasMixedSamples() const { return fSurfaceFlags & GrInternalSurfaceFlags::kMixedSampled; }
  78. void setSupportsWindowRects() {
  79. fSurfaceFlags |= GrInternalSurfaceFlags::kWindowRectsSupport;
  80. }
  81. bool supportsWindowRects() const {
  82. return fSurfaceFlags & GrInternalSurfaceFlags::kWindowRectsSupport;
  83. }
  84. void setGLRTFBOIDIs0() {
  85. fSurfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0;
  86. }
  87. bool glRTFBOIDIs0() const {
  88. return fSurfaceFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0;
  89. }
  90. size_t onUninstantiatedGpuMemorySize() const override;
  91. SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
  92. // WARNING: Be careful when adding or removing fields here. ASAN is likely to trigger warnings
  93. // when instantiating GrTextureRenderTargetProxy. The std::function in GrSurfaceProxy makes
  94. // each class in the diamond require 16 byte alignment. Clang appears to layout the fields for
  95. // each class to achieve the necessary alignment. However, ASAN checks the alignment of 'this'
  96. // in the constructors, and always looks for the full 16 byte alignment, even if the fields in
  97. // that particular class don't require it. Changing the size of this object can move the start
  98. // address of other types, leading to this problem.
  99. int fSampleCnt;
  100. bool fNeedsStencil;
  101. // For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class.
  102. // For deferred proxies that pointer is filled in when we need to instantiate the
  103. // deferred resource.
  104. typedef GrSurfaceProxy INHERITED;
  105. };
  106. #endif