VsyncChild.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "VsyncChild.h"
  6. #include "mozilla/VsyncDispatcher.h"
  7. #include "nsThreadUtils.h"
  8. namespace mozilla {
  9. namespace layout {
  10. VsyncChild::VsyncChild()
  11. : mObservingVsync(false)
  12. , mIsShutdown(false)
  13. , mVsyncRate(TimeDuration::Forever())
  14. {
  15. MOZ_ASSERT(NS_IsMainThread());
  16. }
  17. VsyncChild::~VsyncChild()
  18. {
  19. MOZ_ASSERT(NS_IsMainThread());
  20. }
  21. bool
  22. VsyncChild::SendObserve()
  23. {
  24. MOZ_ASSERT(NS_IsMainThread());
  25. if (!mObservingVsync && !mIsShutdown) {
  26. mObservingVsync = true;
  27. PVsyncChild::SendObserve();
  28. }
  29. return true;
  30. }
  31. bool
  32. VsyncChild::SendUnobserve()
  33. {
  34. MOZ_ASSERT(NS_IsMainThread());
  35. if (mObservingVsync && !mIsShutdown) {
  36. mObservingVsync = false;
  37. PVsyncChild::SendUnobserve();
  38. }
  39. return true;
  40. }
  41. void
  42. VsyncChild::ActorDestroy(ActorDestroyReason aActorDestroyReason)
  43. {
  44. MOZ_ASSERT(NS_IsMainThread());
  45. MOZ_ASSERT(!mIsShutdown);
  46. mIsShutdown = true;
  47. mObserver = nullptr;
  48. }
  49. bool
  50. VsyncChild::RecvNotify(const TimeStamp& aVsyncTimestamp)
  51. {
  52. MOZ_ASSERT(NS_IsMainThread());
  53. MOZ_ASSERT(!mIsShutdown);
  54. if (mObservingVsync && mObserver) {
  55. mObserver->NotifyVsync(aVsyncTimestamp);
  56. }
  57. return true;
  58. }
  59. void
  60. VsyncChild::SetVsyncObserver(VsyncObserver* aVsyncObserver)
  61. {
  62. MOZ_ASSERT(NS_IsMainThread());
  63. mObserver = aVsyncObserver;
  64. }
  65. TimeDuration
  66. VsyncChild::GetVsyncRate()
  67. {
  68. if (mVsyncRate == TimeDuration::Forever()) {
  69. PVsyncChild::SendRequestVsyncRate();
  70. }
  71. return mVsyncRate;
  72. }
  73. bool
  74. VsyncChild::RecvVsyncRate(const float& aVsyncRate)
  75. {
  76. mVsyncRate = TimeDuration::FromMilliseconds(aVsyncRate);
  77. return true;
  78. }
  79. } // namespace layout
  80. } // namespace mozilla