GrMtlRenderTarget.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2017 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 GrMtlRenderTarget_DEFINED
  8. #define GrMtlRenderTarget_DEFINED
  9. #include "include/gpu/GrRenderTarget.h"
  10. #include "include/gpu/GrBackendSurface.h"
  11. #import <Metal/Metal.h>
  12. class GrMtlGpu;
  13. class GrMtlRenderTarget: public GrRenderTarget {
  14. public:
  15. static sk_sp<GrMtlRenderTarget> MakeWrappedRenderTarget(GrMtlGpu*,
  16. const GrSurfaceDesc&,
  17. int sampleCnt,
  18. id<MTLTexture>);
  19. ~GrMtlRenderTarget() override;
  20. // override of GrRenderTarget
  21. ResolveType getResolveType() const override {
  22. if (this->numSamples() > 1) {
  23. return kCanResolve_ResolveType;
  24. }
  25. return kAutoResolves_ResolveType;
  26. }
  27. bool canAttemptStencilAttachment() const override {
  28. return true;
  29. }
  30. id<MTLTexture> mtlColorTexture() const { return fColorTexture; }
  31. id<MTLTexture> mtlResolveTexture() const { return fResolveTexture; }
  32. GrBackendRenderTarget getBackendRenderTarget() const override;
  33. GrBackendFormat backendFormat() const override;
  34. protected:
  35. GrMtlRenderTarget(GrMtlGpu* gpu,
  36. const GrSurfaceDesc& desc,
  37. int sampleCnt,
  38. id<MTLTexture> colorTexture,
  39. id<MTLTexture> resolveTexture);
  40. GrMtlRenderTarget(GrMtlGpu* gpu,
  41. const GrSurfaceDesc& desc,
  42. id<MTLTexture> colorTexture);
  43. GrMtlGpu* getMtlGpu() const;
  44. void onAbandon() override;
  45. void onRelease() override;
  46. // This accounts for the texture's memory and any MSAA renderbuffer's memory.
  47. size_t onGpuMemorySize() const override {
  48. int numColorSamples = this->numSamples();
  49. // TODO: When used as render targets certain formats may actually have a larger size than
  50. // the base format size. Check to make sure we are reporting the correct value here.
  51. // The plus 1 is to account for the resolve texture or if not using msaa the RT itself
  52. if (numColorSamples > 1) {
  53. ++numColorSamples;
  54. }
  55. return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
  56. numColorSamples, GrMipMapped::kNo);
  57. }
  58. id<MTLTexture> fColorTexture;
  59. id<MTLTexture> fResolveTexture;
  60. private:
  61. // Extra param to disambiguate from constructor used by subclasses.
  62. enum Wrapped { kWrapped };
  63. GrMtlRenderTarget(GrMtlGpu* gpu,
  64. const GrSurfaceDesc& desc,
  65. int sampleCnt,
  66. id<MTLTexture> colorTexture,
  67. id<MTLTexture> resolveTexture,
  68. Wrapped);
  69. GrMtlRenderTarget(GrMtlGpu* gpu,
  70. const GrSurfaceDesc& desc,
  71. id<MTLTexture> colorTexture,
  72. Wrapped);
  73. bool completeStencilAttachment() override;
  74. typedef GrRenderTarget INHERITED;
  75. };
  76. #endif