GrMtlTextureRenderTarget.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2018 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 GrMtlTextureRenderTarget_DEFINED
  8. #define GrMtlTextureRenderTarget_DEFINED
  9. #include "src/gpu/mtl/GrMtlRenderTarget.h"
  10. #include "src/gpu/mtl/GrMtlTexture.h"
  11. class GrMtlTextureRenderTarget: public GrMtlTexture, public GrMtlRenderTarget {
  12. public:
  13. static sk_sp<GrMtlTextureRenderTarget> MakeNewTextureRenderTarget(GrMtlGpu*,
  14. SkBudgeted,
  15. const GrSurfaceDesc&,
  16. int sampleCnt,
  17. MTLTextureDescriptor*,
  18. GrMipMapsStatus);
  19. static sk_sp<GrMtlTextureRenderTarget> MakeWrappedTextureRenderTarget(GrMtlGpu*,
  20. const GrSurfaceDesc&,
  21. int sampleCnt,
  22. id<MTLTexture>,
  23. GrWrapCacheable);
  24. GrBackendFormat backendFormat() const override {
  25. return GrMtlTexture::backendFormat();
  26. }
  27. protected:
  28. void onAbandon() override {
  29. GrMtlRenderTarget::onAbandon();
  30. GrMtlTexture::onAbandon();
  31. }
  32. void onRelease() override {
  33. GrMtlRenderTarget::onRelease();
  34. GrMtlTexture::onRelease();
  35. }
  36. private:
  37. GrMtlTextureRenderTarget(GrMtlGpu* gpu,
  38. SkBudgeted budgeted,
  39. const GrSurfaceDesc& desc,
  40. int sampleCnt,
  41. id<MTLTexture> colorTexture,
  42. id<MTLTexture> resolveTexture,
  43. GrMipMapsStatus);
  44. GrMtlTextureRenderTarget(GrMtlGpu* gpu,
  45. SkBudgeted budgeted,
  46. const GrSurfaceDesc& desc,
  47. id<MTLTexture> colorTexture,
  48. GrMipMapsStatus);
  49. GrMtlTextureRenderTarget(GrMtlGpu* gpu,
  50. const GrSurfaceDesc& desc,
  51. int sampleCnt,
  52. id<MTLTexture> colorTexture,
  53. id<MTLTexture> resolveTexture,
  54. GrMipMapsStatus,
  55. GrWrapCacheable cacheable);
  56. GrMtlTextureRenderTarget(GrMtlGpu* gpu,
  57. const GrSurfaceDesc& desc,
  58. id<MTLTexture> colorTexture,
  59. GrMipMapsStatus,
  60. GrWrapCacheable cacheable);
  61. size_t onGpuMemorySize() const override {
  62. // TODO: When used as render targets certain formats may actually have a larger size than
  63. // the base format size. Check to make sure we are reporting the correct value here.
  64. // The plus 1 is to account for the resolve texture or if not using msaa the RT itself
  65. int numColorSamples = this->numSamples();
  66. if (numColorSamples > 1) {
  67. ++numColorSamples;
  68. }
  69. return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
  70. numColorSamples, GrMipMapped::kNo);
  71. }
  72. };
  73. #endif