android_overlay_config.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_BASE_ANDROID_OVERLAY_CONFIG_H_
  5. #define MEDIA_BASE_ANDROID_OVERLAY_CONFIG_H_
  6. #include "base/callback.h"
  7. #include "media/base/media_export.h"
  8. #include "ui/gfx/geometry/rect.h"
  9. namespace media {
  10. class AndroidOverlay;
  11. // Configuration used to create an overlay.
  12. struct MEDIA_EXPORT AndroidOverlayConfig {
  13. public:
  14. // Called when the overlay is ready for use, via |GetJavaSurface()|.
  15. using ReadyCB = base::OnceCallback<void(AndroidOverlay*)>;
  16. // Called when overlay has failed before |ReadyCB| is called. Will not be
  17. // called after ReadyCB. It will be the last callback for the overlay, except
  18. // for any DeletedCB.
  19. using FailedCB = base::OnceCallback<void(AndroidOverlay*)>;
  20. // Called when the surface has been destroyed. This will not be called unless
  21. // ReadyCB has been called. It will be the last callback for the overlay,
  22. // except for any DeletedCB. In response, the client is expected to quit
  23. // using the surface and delete the overlay object.
  24. using DestroyedCB = base::OnceCallback<void(AndroidOverlay*)>;
  25. // Called when the overlay object has been deleted. This is unrelated to
  26. // any DestroyedCB, which informs us when the surface is no longer usable and
  27. // that we should delete the AndroidOverlay object. DeletedCB is called when
  28. // the AndroidOverlay object is deleted for any reason. It is guaranteed that
  29. // the overlay pointer will still be a valid pointer, but it is not safe to
  30. // access it. It's provided just to make it easier to tell which overlay is
  31. // being deleted.
  32. using DeletedCB = base::OnceCallback<void(AndroidOverlay*)>;
  33. // Optional callback to find out about the power-efficient state of the
  34. // overlay. Called with true if the overlay is power-efficient, and false
  35. // if it isn't. To receive these callbacks, one must set |power_efficient|.
  36. using PowerEfficientCB = base::RepeatingCallback<void(AndroidOverlay*, bool)>;
  37. // Configuration used to create an overlay.
  38. AndroidOverlayConfig();
  39. AndroidOverlayConfig(AndroidOverlayConfig&&);
  40. AndroidOverlayConfig(const AndroidOverlayConfig&) = delete;
  41. ~AndroidOverlayConfig();
  42. // Initial rectangle for the overlay. May be changed via ScheduleLayout().
  43. gfx::Rect rect;
  44. // Require a secure overlay?
  45. bool secure = false;
  46. // Require that the overlay is power efficient? In other words, don't get
  47. // an overlay if it (for example) pushes the device into GLES composition. If
  48. // an overlay is provided, but it later becomes not power efficient, then it
  49. // will not be destroyed. Use PowerEfficientCB to determine that this has
  50. // happened, since that lets the client handle it more gracefully rather than
  51. // looking like the surface was lost.
  52. bool power_efficient = false;
  53. // Convenient helpers since the syntax is weird.
  54. void is_ready(AndroidOverlay* overlay) {
  55. if (ready_cb)
  56. std::move(ready_cb).Run(overlay);
  57. }
  58. void is_failed(AndroidOverlay* overlay) {
  59. if (failed_cb)
  60. std::move(failed_cb).Run(overlay);
  61. }
  62. ReadyCB ready_cb;
  63. FailedCB failed_cb;
  64. // Optional, may be empty.
  65. PowerEfficientCB power_cb;
  66. };
  67. // Common factory type.
  68. using AndroidOverlayFactoryCB =
  69. base::RepeatingCallback<std::unique_ptr<AndroidOverlay>(
  70. AndroidOverlayConfig)>;
  71. } // namespace media
  72. #endif // MEDIA_BASE_ANDROID_OVERLAY_CONFIG_H_