gpu_video_decode_accelerator_helpers.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Copyright 2016 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_GPU_VIDEO_DECODE_ACCELERATOR_HELPERS_H_
  5. #define MEDIA_GPU_GPU_VIDEO_DECODE_ACCELERATOR_HELPERS_H_
  6. #include "base/callback.h"
  7. #include "base/memory/weak_ptr.h"
  8. #include "media/base/supported_video_decoder_config.h"
  9. #include "media/gpu/media_gpu_export.h"
  10. #include "media/video/video_decode_accelerator.h"
  11. namespace gl {
  12. class GLContext;
  13. class GLImage;
  14. }
  15. namespace gpu {
  16. namespace gles2 {
  17. class AbstractTexture;
  18. class ContextGroup;
  19. }
  20. }
  21. namespace media {
  22. // Helpers/defines for specific VideoDecodeAccelerator implementations in GPU
  23. // process. Which callbacks are required depends on the implementation.
  24. //
  25. // Note that these callbacks may be called more than once, and so must own/share
  26. // ownership of any objects bound to them.
  27. //
  28. // Unless specified otherwise, these callbacks must be executed on the GPU Child
  29. // thread (i.e. the thread which the VDAs are initialized on).
  30. // Return current GLContext.
  31. using GetGLContextCallback = base::RepeatingCallback<gl::GLContext*(void)>;
  32. // Make the applicable GL context current. To be called by VDAs before
  33. // executing any GL calls. Return true on success, false otherwise.
  34. using MakeGLContextCurrentCallback = base::RepeatingCallback<bool(void)>;
  35. // Bind |image| to |client_texture_id| given |texture_target|. If
  36. // |can_bind_to_sampler| is true, then the image may be used as a sampler
  37. // directly, otherwise a copy to a staging buffer is required.
  38. // Return true on success, false otherwise.
  39. using BindGLImageCallback =
  40. base::RepeatingCallback<bool(uint32_t client_texture_id,
  41. uint32_t texture_target,
  42. const scoped_refptr<gl::GLImage>& image,
  43. bool can_bind_to_sampler)>;
  44. // Return a ContextGroup*, if one is available.
  45. using GetContextGroupCallback =
  46. base::RepeatingCallback<gpu::gles2::ContextGroup*(void)>;
  47. // Create and return an AbstractTexture, if possible.
  48. using CreateAbstractTextureCallback =
  49. base::RepeatingCallback<std::unique_ptr<gpu::gles2::AbstractTexture>(
  50. unsigned /* GLenum */ target,
  51. unsigned /* GLenum */ internal_format,
  52. int /* GLsizei */ width,
  53. int /* GLsizei */ height,
  54. int /* GLsizei */ depth,
  55. int /* GLint */ border,
  56. unsigned /* GLenum */ format,
  57. unsigned /* GLenum */ type)>;
  58. // OpenGL callbacks made by VideoDecodeAccelerator sub-classes.
  59. struct MEDIA_GPU_EXPORT GpuVideoDecodeGLClient {
  60. GpuVideoDecodeGLClient();
  61. ~GpuVideoDecodeGLClient();
  62. GpuVideoDecodeGLClient(const GpuVideoDecodeGLClient&);
  63. GpuVideoDecodeGLClient& operator=(const GpuVideoDecodeGLClient&);
  64. // Return current GLContext.
  65. using GetGLContextCallback = base::RepeatingCallback<gl::GLContext*(void)>;
  66. // Make the applicable GL context current. To be called by VDAs before
  67. // executing any GL calls. Return true on success, false otherwise.
  68. using MakeGLContextCurrentCallback = base::RepeatingCallback<bool(void)>;
  69. // Bind |image| to |client_texture_id| given |texture_target|. If
  70. // |can_bind_to_sampler| is true, then the image may be used as a sampler
  71. // directly, otherwise a copy to a staging buffer is required.
  72. // Return true on success, false otherwise.
  73. using BindGLImageCallback =
  74. base::RepeatingCallback<bool(uint32_t client_texture_id,
  75. uint32_t texture_target,
  76. const scoped_refptr<gl::GLImage>& image,
  77. bool can_bind_to_sampler)>;
  78. // Return a ContextGroup*, if one is available.
  79. using GetContextGroupCallback =
  80. base::RepeatingCallback<gpu::gles2::ContextGroup*(void)>;
  81. // Callback to return current GLContext, if available.
  82. GetGLContextCallback get_context;
  83. // Callback for making the relevant context current for GL calls.
  84. MakeGLContextCurrentCallback make_context_current;
  85. // Callback to bind a GLImage to a given texture id and target.
  86. BindGLImageCallback bind_image;
  87. // Callback to return a ContextGroup*.
  88. GetContextGroupCallback get_context_group;
  89. // Callback to return a DecoderContext*.
  90. CreateAbstractTextureCallback create_abstract_texture;
  91. // Whether or not the command buffer is passthrough.
  92. bool is_passthrough = false;
  93. // Whether or not ARB_texture_rectangle is present.
  94. bool supports_arb_texture_rectangle = false;
  95. };
  96. // Convert vector of VDA::SupportedProfile to vector of
  97. // SupportedVideoDecoderConfig.
  98. MEDIA_GPU_EXPORT SupportedVideoDecoderConfigs ConvertFromSupportedProfiles(
  99. const VideoDecodeAccelerator::SupportedProfiles& profiles,
  100. bool allow_encrypted);
  101. } // namespace media
  102. #endif // MEDIA_GPU_GPU_VIDEO_DECODE_ACCELERATOR_HELPERS_H_