android_video_surface_chooser.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_ANDROID_ANDROID_VIDEO_SURFACE_CHOOSER_H_
  5. #define MEDIA_GPU_ANDROID_ANDROID_VIDEO_SURFACE_CHOOSER_H_
  6. #include "base/bind.h"
  7. #include "base/memory/weak_ptr.h"
  8. #include "media/base/android/android_overlay.h"
  9. #include "media/base/video_transformation.h"
  10. #include "media/gpu/media_gpu_export.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. #include "ui/gfx/geometry/rect.h"
  13. namespace media {
  14. // Manage details of which surface to use for video playback.
  15. class MEDIA_GPU_EXPORT AndroidVideoSurfaceChooser {
  16. public:
  17. // Input state used for choosing the surface type.
  18. struct State {
  19. State();
  20. ~State();
  21. // Is an overlay required?
  22. bool is_required = false;
  23. // Is the player currently in fullscreen?
  24. bool is_fullscreen = false;
  25. // Should the overlay be marked as secure?
  26. bool is_secure = false;
  27. // Is the player's frame hidden / closed?
  28. bool is_frame_hidden = false;
  29. // Is the compositor willing to promote this?
  30. bool is_compositor_promotable = false;
  31. // Are we expecting a relayout soon?
  32. bool is_expecting_relayout = false;
  33. // If true, then we will promote to overlay only if it's required for secure
  34. // video playback.
  35. bool promote_secure_only = false;
  36. // Default orientation for the video.
  37. VideoRotation video_rotation = VIDEO_ROTATION_0;
  38. // Hint to use for the initial position when transitioning to an overlay.
  39. gfx::Rect initial_position;
  40. // Indicates that we should always use a TextureOwner. This is used with
  41. // SurfaceControl where the TextureOwner can be promoted to an overlay
  42. // dynamically by the compositor.
  43. bool always_use_texture_owner = false;
  44. // Is the video persistent (PIP)?
  45. bool is_persistent_video = false;
  46. };
  47. // Notify the client that |overlay| is ready for use. The client may get
  48. // the surface immediately.
  49. using UseOverlayCB =
  50. base::RepeatingCallback<void(std::unique_ptr<AndroidOverlay> overlay)>;
  51. // Notify the client that the most recently provided overlay should be
  52. // discarded. The overlay is still valid, but we recommend against
  53. // using it soon, in favor of a TextureOwner.
  54. using UseTextureOwnerCB = base::RepeatingCallback<void(void)>;
  55. AndroidVideoSurfaceChooser() {}
  56. AndroidVideoSurfaceChooser(const AndroidVideoSurfaceChooser&) = delete;
  57. AndroidVideoSurfaceChooser& operator=(const AndroidVideoSurfaceChooser&) =
  58. delete;
  59. virtual ~AndroidVideoSurfaceChooser() {}
  60. // Sets the client callbacks to be called when a new surface choice is made.
  61. // Must be called before UpdateState();
  62. virtual void SetClientCallbacks(UseOverlayCB use_overlay_cb,
  63. UseTextureOwnerCB use_texture_owner_cb) = 0;
  64. // Updates the current state and makes a new surface choice with the new
  65. // state. If |new_factory| is empty, the factory is left as-is. Otherwise,
  66. // the factory is updated to |*new_factory|.
  67. virtual void UpdateState(absl::optional<AndroidOverlayFactoryCB> new_factory,
  68. const State& new_state) = 0;
  69. };
  70. } // namespace media
  71. #endif // MEDIA_GPU_ANDROID_ANDROID_VIDEO_SURFACE_CHOOSER_H_