vaapi_picture.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2014 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. //
  5. // This file contains an interface of output pictures for the Vaapi
  6. // video decoder. This is implemented by different window system
  7. // (X11/Ozone) and used by VaapiVideoDecodeAccelerator to produce
  8. // output pictures.
  9. #ifndef MEDIA_GPU_VAAPI_VAAPI_PICTURE_H_
  10. #define MEDIA_GPU_VAAPI_VAAPI_PICTURE_H_
  11. #include <stdint.h>
  12. #include "base/memory/ref_counted.h"
  13. #include "base/sequence_checker.h"
  14. #include "media/gpu/gpu_video_decode_accelerator_helpers.h"
  15. #include "media/gpu/media_gpu_export.h"
  16. #include "media/gpu/vaapi/vaapi_status.h"
  17. #include "ui/gfx/geometry/size.h"
  18. #include "ui/gfx/gpu_memory_buffer.h"
  19. namespace media {
  20. using VASurfaceID = unsigned int;
  21. class VASurface;
  22. class VaapiWrapper;
  23. // Picture is native pixmap abstraction (X11/Ozone).
  24. class MEDIA_GPU_EXPORT VaapiPicture {
  25. public:
  26. VaapiPicture(const VaapiPicture&) = delete;
  27. VaapiPicture& operator=(const VaapiPicture&) = delete;
  28. virtual ~VaapiPicture();
  29. // Uses the buffer of |format|, pointed to by |gpu_memory_buffer_handle| as
  30. // the backing storage for this picture. This takes ownership of the handle
  31. // and will close it even on failure. Return true on success, false otherwise.
  32. virtual bool ImportGpuMemoryBufferHandle(
  33. gfx::BufferFormat format,
  34. gfx::GpuMemoryBufferHandle gpu_memory_buffer_handle) = 0;
  35. // Allocates a buffer of |format| to use as backing storage for this picture.
  36. virtual VaapiStatus Allocate(gfx::BufferFormat format) = 0;
  37. int32_t picture_buffer_id() const { return picture_buffer_id_; }
  38. virtual bool AllowOverlay() const;
  39. // Downloads |va_surface| into the picture, potentially scaling it if needed.
  40. virtual bool DownloadFromSurface(scoped_refptr<VASurface> va_surface) = 0;
  41. // Returns the associated VASurfaceID, if any, or VA_INVALID_ID.
  42. virtual VASurfaceID va_surface_id() const;
  43. protected:
  44. VaapiPicture(scoped_refptr<VaapiWrapper> vaapi_wrapper,
  45. const MakeGLContextCurrentCallback& make_context_current_cb,
  46. const BindGLImageCallback& bind_image_cb,
  47. int32_t picture_buffer_id,
  48. const gfx::Size& size,
  49. const gfx::Size& visible_size,
  50. uint32_t texture_id,
  51. uint32_t client_texture_id,
  52. uint32_t texture_target);
  53. const scoped_refptr<VaapiWrapper> vaapi_wrapper_;
  54. const MakeGLContextCurrentCallback make_context_current_cb_;
  55. const BindGLImageCallback bind_image_cb_;
  56. const gfx::Size size_;
  57. const gfx::Size visible_size_;
  58. const uint32_t texture_id_;
  59. const uint32_t client_texture_id_;
  60. const uint32_t texture_target_;
  61. SEQUENCE_CHECKER(sequence_checker_);
  62. private:
  63. const int32_t picture_buffer_id_;
  64. };
  65. } // namespace media
  66. #endif // MEDIA_GPU_VAAPI_VAAPI_PICTURE_H_