GpuMemoryBufferPool.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include <list>
  3. #include <system_wrappers/include/clock.h>
  4. #include "GpuMemoryBuffer.h"
  5. #include "Size.h"
  6. #include "VideoFrame.h"
  7. namespace unity
  8. {
  9. namespace webrtc
  10. {
  11. class GpuMemoryBufferPool
  12. {
  13. public:
  14. GpuMemoryBufferPool(IGraphicsDevice* device, Clock* clock);
  15. GpuMemoryBufferPool(const GpuMemoryBufferPool&) = delete;
  16. GpuMemoryBufferPool& operator=(const GpuMemoryBufferPool&) = delete;
  17. virtual ~GpuMemoryBufferPool();
  18. rtc::scoped_refptr<VideoFrame>
  19. CreateFrame(NativeTexPtr ptr, const Size& size, UnityRenderingExtTextureFormat format, Timestamp timestamp);
  20. void ReleaseStaleBuffers(Timestamp timestamp);
  21. size_t bufferCount() { return resourcesPool_.size(); }
  22. private:
  23. struct FrameResources
  24. {
  25. FrameResources(rtc::scoped_refptr<GpuMemoryBufferInterface> buffer)
  26. : buffer_(std::move(buffer))
  27. , lastUsetime_(Timestamp::Zero())
  28. {
  29. }
  30. rtc::scoped_refptr<GpuMemoryBufferInterface> buffer_;
  31. bool IsUsed() { return isUsed_; }
  32. void MarkUsed(Timestamp timestamp)
  33. {
  34. isUsed_ = true;
  35. lastUsetime_ = timestamp;
  36. }
  37. void MarkUnused(Timestamp timestamp)
  38. {
  39. isUsed_ = false;
  40. lastUsetime_ = timestamp;
  41. }
  42. Timestamp lastUseTime() { return lastUsetime_; }
  43. bool isUsed_;
  44. Timestamp lastUsetime_;
  45. };
  46. rtc::scoped_refptr<GpuMemoryBufferInterface>
  47. GetOrCreateFrameResources(NativeTexPtr ptr, const Size& size, UnityRenderingExtTextureFormat format);
  48. void OnReturnBuffer(rtc::scoped_refptr<GpuMemoryBufferInterface> buffer);
  49. static bool AreFrameResourcesCompatible(
  50. const FrameResources* resources, const Size& size, UnityRenderingExtTextureFormat format);
  51. IGraphicsDevice* device_;
  52. std::list<std::unique_ptr<FrameResources>> resourcesPool_;
  53. Clock* const clock_;
  54. };
  55. }
  56. }