GrRenderTargetProxy.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include "src/gpu/GrRenderTargetProxy.h"
  8. #include "src/core/SkMathPriv.h"
  9. #include "src/gpu/GrCaps.h"
  10. #include "src/gpu/GrGpuResourcePriv.h"
  11. #include "src/gpu/GrRenderTargetOpList.h"
  12. #include "src/gpu/GrRenderTargetPriv.h"
  13. #include "src/gpu/GrResourceProvider.h"
  14. #include "src/gpu/GrSurfacePriv.h"
  15. #include "src/gpu/GrTextureRenderTargetProxy.h"
  16. // Deferred version
  17. // TODO: we can probably munge the 'desc' in both the wrapped and deferred
  18. // cases to make the sampleConfig/numSamples stuff more rational.
  19. GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrBackendFormat& format,
  20. const GrSurfaceDesc& desc, int sampleCount,
  21. GrSurfaceOrigin origin, const GrSwizzle& textureSwizzle,
  22. const GrSwizzle& outputSwizzle, SkBackingFit fit,
  23. SkBudgeted budgeted, GrProtected isProtected,
  24. GrInternalSurfaceFlags surfaceFlags)
  25. : INHERITED(format, desc, GrRenderable::kYes, origin, textureSwizzle, fit, budgeted,
  26. isProtected, surfaceFlags)
  27. , fSampleCnt(sampleCount)
  28. , fWrapsVkSecondaryCB(WrapsVkSecondaryCB::kNo)
  29. , fOutputSwizzle(outputSwizzle) {}
  30. // Lazy-callback version
  31. GrRenderTargetProxy::GrRenderTargetProxy(
  32. LazyInstantiateCallback&& callback, LazyInstantiationType lazyType,
  33. const GrBackendFormat& format, const GrSurfaceDesc& desc, int sampleCount,
  34. GrSurfaceOrigin origin, const GrSwizzle& textureSwizzle, const GrSwizzle& outputSwizzle,
  35. SkBackingFit fit, SkBudgeted budgeted, GrProtected isProtected,
  36. GrInternalSurfaceFlags surfaceFlags, WrapsVkSecondaryCB wrapsVkSecondaryCB)
  37. : INHERITED(std::move(callback), lazyType, format, desc, GrRenderable::kYes, origin,
  38. textureSwizzle, fit, budgeted, isProtected, surfaceFlags)
  39. , fSampleCnt(sampleCount)
  40. , fWrapsVkSecondaryCB(wrapsVkSecondaryCB)
  41. , fOutputSwizzle(outputSwizzle) {}
  42. // Wrapped version
  43. GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf, GrSurfaceOrigin origin,
  44. const GrSwizzle& textureSwizzle,
  45. const GrSwizzle& outputSwizzle,
  46. WrapsVkSecondaryCB wrapsVkSecondaryCB)
  47. : INHERITED(std::move(surf), origin, textureSwizzle, SkBackingFit::kExact)
  48. , fSampleCnt(fTarget->asRenderTarget()->numSamples())
  49. , fWrapsVkSecondaryCB(wrapsVkSecondaryCB)
  50. , fOutputSwizzle(outputSwizzle) {
  51. }
  52. int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const {
  53. return this->glRTFBOIDIs0() ? 0 : caps.maxWindowRectangles();
  54. }
  55. bool GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
  56. if (LazyState::kNot != this->lazyInstantiationState()) {
  57. return false;
  58. }
  59. if (!this->instantiateImpl(resourceProvider, fSampleCnt, fNumStencilSamples, GrRenderable::kYes,
  60. GrMipMapped::kNo, nullptr)) {
  61. return false;
  62. }
  63. SkASSERT(this->peekRenderTarget());
  64. SkASSERT(!this->peekTexture());
  65. return true;
  66. }
  67. bool GrRenderTargetProxy::canChangeStencilAttachment() const {
  68. if (!fTarget) {
  69. // If we aren't instantiated, then we definitely are an internal render target. Ganesh is
  70. // free to change stencil attachments on internal render targets.
  71. return true;
  72. }
  73. return fTarget->asRenderTarget()->canAttemptStencilAttachment();
  74. }
  75. sk_sp<GrSurface> GrRenderTargetProxy::createSurface(GrResourceProvider* resourceProvider) const {
  76. sk_sp<GrSurface> surface = this->createSurfaceImpl(
  77. resourceProvider, fSampleCnt, fNumStencilSamples, GrRenderable::kYes, GrMipMapped::kNo);
  78. if (!surface) {
  79. return nullptr;
  80. }
  81. SkASSERT(surface->asRenderTarget());
  82. SkASSERT(!surface->asTexture());
  83. return surface;
  84. }
  85. size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
  86. int colorSamplesPerPixel = this->numSamples();
  87. if (colorSamplesPerPixel > 1) {
  88. // Add one for the resolve buffer.
  89. ++colorSamplesPerPixel;
  90. }
  91. // TODO: do we have enough information to improve this worst case estimate?
  92. return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
  93. colorSamplesPerPixel, GrMipMapped::kNo, !this->priv().isExact());
  94. }
  95. bool GrRenderTargetProxy::refsWrappedObjects() const {
  96. if (!this->isInstantiated()) {
  97. return false;
  98. }
  99. GrSurface* surface = this->peekSurface();
  100. return surface->resourcePriv().refsWrappedObjects();
  101. }
  102. #ifdef SK_DEBUG
  103. void GrRenderTargetProxy::onValidateSurface(const GrSurface* surface) {
  104. // We do not check that surface->asTexture returns null since, when replaying DDLs we
  105. // can fulfill a renderTarget-only proxy w/ a textureRenderTarget.
  106. // Anything that is checked here should be duplicated in GrTextureRenderTargetProxy's version
  107. SkASSERT(surface->asRenderTarget());
  108. SkASSERT(surface->asRenderTarget()->numSamples() == this->numSamples());
  109. GrInternalSurfaceFlags proxyFlags = fSurfaceFlags;
  110. GrInternalSurfaceFlags surfaceFlags = surface->surfacePriv().flags();
  111. SkASSERT((proxyFlags & GrInternalSurfaceFlags::kRenderTargetMask) ==
  112. (surfaceFlags & GrInternalSurfaceFlags::kRenderTargetMask));
  113. }
  114. #endif