d3d11_picture_buffer.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_GPU_WINDOWS_D3D11_PICTURE_BUFFER_H_
  5. #define MEDIA_GPU_WINDOWS_D3D11_PICTURE_BUFFER_H_
  6. #include <d3d11.h>
  7. #include <wrl/client.h>
  8. #include <memory>
  9. #include <vector>
  10. #include "base/memory/ref_counted_delete_on_sequence.h"
  11. #include "base/time/time.h"
  12. #include "gpu/command_buffer/service/mailbox_manager.h"
  13. #include "gpu/command_buffer/service/texture_manager.h"
  14. #include "gpu/ipc/service/command_buffer_stub.h"
  15. #include "media/base/media_log.h"
  16. #include "media/base/video_frame.h"
  17. #include "media/gpu/command_buffer_helper.h"
  18. #include "media/gpu/media_gpu_export.h"
  19. #include "media/gpu/windows/d3d11_status.h"
  20. #include "media/gpu/windows/d3d11_texture_wrapper.h"
  21. #include "media/video/picture.h"
  22. #include "third_party/angle/include/EGL/egl.h"
  23. #include "third_party/angle/include/EGL/eglext.h"
  24. namespace media {
  25. class Texture2DWrapper;
  26. // PictureBuffer that owns Chrome Textures to display it, and keep a reference
  27. // to the D3D texture that backs the image.
  28. //
  29. // This is created and owned on the decoder thread. While currently that's the
  30. // gpu main thread, we still keep the decoder parts separate from the chrome GL
  31. // parts, in case that changes.
  32. //
  33. // This is refcounted so that VideoFrame can hold onto it indirectly. While
  34. // the chrome Texture is sufficient to keep the pictures renderable, we still
  35. // need to guarantee that the client has time to use the mailbox. Once it
  36. // does so, it would be fine if this were destroyed. Technically, only the
  37. // GpuResources have to be retained until the mailbox is used, but we just
  38. // retain the whole thing.
  39. class MEDIA_GPU_EXPORT D3D11PictureBuffer
  40. : public base::RefCountedDeleteOnSequence<D3D11PictureBuffer> {
  41. public:
  42. // |texture_wrapper| is responsible for controlling mailbox access to
  43. // the ID3D11Texture2D,
  44. // |array_slice| is the picturebuffer index inside the Array-type
  45. // ID3D11Texture2D. |picture_index| is a unique id used to identify this
  46. // picture to the decoder. If a texture array is used, then it might as well
  47. // be equal to the texture array index. Otherwise, any 0-based index is
  48. // probably okay, though sequential makes sense.
  49. D3D11PictureBuffer(
  50. scoped_refptr<base::SequencedTaskRunner> delete_task_runner,
  51. ComD3D11Texture2D texture,
  52. size_t array_slice,
  53. std::unique_ptr<Texture2DWrapper> texture_wrapper,
  54. gfx::Size size,
  55. size_t picture_index);
  56. D3D11Status Init(scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner,
  57. GetCommandBufferHelperCB get_helper_cb,
  58. ComD3D11VideoDevice video_device,
  59. const GUID& decoder_guid,
  60. std::unique_ptr<MediaLog> media_log);
  61. D3D11PictureBuffer(const D3D11PictureBuffer&) = delete;
  62. D3D11PictureBuffer& operator=(const D3D11PictureBuffer&) = delete;
  63. // Set the contents of a mailbox holder array, return true if successful.
  64. // |input_color_space| is the color space of our input texture, and
  65. // |output_color_space| will be set, on success, to the color space that the
  66. // processed texture has.
  67. D3D11Status ProcessTexture(const gfx::ColorSpace& input_color_space,
  68. MailboxHolderArray* mailbox_dest,
  69. gfx::ColorSpace* output_color_space);
  70. ComD3D11Texture2D Texture() const;
  71. D3D11Status::Or<ID3D11VideoDecoderOutputView*> AcquireOutputView() const;
  72. const gfx::Size& size() const { return size_; }
  73. size_t picture_index() const { return picture_index_; }
  74. // Is this PictureBuffer backing a VideoFrame right now?
  75. bool in_client_use() const { return in_client_use_ > 0; }
  76. // Is this PictureBuffer holding an image that's in use by the decoder?
  77. bool in_picture_use() const { return in_picture_use_; }
  78. void add_client_use() {
  79. in_client_use_++;
  80. DCHECK_GT(in_client_use_, 0);
  81. }
  82. void remove_client_use() {
  83. DCHECK_GT(in_client_use_, 0);
  84. in_client_use_--;
  85. }
  86. void set_in_picture_use(bool use) { in_picture_use_ = use; }
  87. Texture2DWrapper* texture_wrapper() const { return texture_wrapper_.get(); }
  88. // Shouldn't be here, but simpler for now.
  89. base::TimeDelta timestamp_;
  90. private:
  91. ~D3D11PictureBuffer();
  92. friend class base::RefCountedDeleteOnSequence<D3D11PictureBuffer>;
  93. friend class base::DeleteHelper<D3D11PictureBuffer>;
  94. ComD3D11Texture2D texture_;
  95. uint32_t array_slice_;
  96. std::unique_ptr<MediaLog> media_log_;
  97. std::unique_ptr<Texture2DWrapper> texture_wrapper_;
  98. gfx::Size size_;
  99. bool in_picture_use_ = false;
  100. int in_client_use_ = 0;
  101. size_t picture_index_;
  102. ComD3D11VideoDecoderOutputView output_view_;
  103. };
  104. } // namespace media
  105. #endif // MEDIA_GPU_WINDOWS_D3D11_PICTURE_BUFFER_H_