VsyncBridgeParent.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  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 "VsyncBridgeParent.h"
  6. #include "mozilla/layers/CompositorThread.h"
  7. #include "mozilla/layers/CompositorBridgeParent.h"
  8. using namespace mozilla::layers;
  9. namespace mozilla {
  10. namespace gfx {
  11. RefPtr<VsyncBridgeParent>
  12. VsyncBridgeParent::Start(Endpoint<PVsyncBridgeParent>&& aEndpoint)
  13. {
  14. RefPtr<VsyncBridgeParent> parent = new VsyncBridgeParent();
  15. RefPtr<Runnable> task = NewRunnableMethod<Endpoint<PVsyncBridgeParent>&&>(
  16. parent, &VsyncBridgeParent::Open, Move(aEndpoint));
  17. CompositorThreadHolder::Loop()->PostTask(task.forget());
  18. return parent;
  19. }
  20. VsyncBridgeParent::VsyncBridgeParent()
  21. : mOpen(false)
  22. {
  23. MOZ_COUNT_CTOR(VsyncBridgeParent);
  24. }
  25. VsyncBridgeParent::~VsyncBridgeParent()
  26. {
  27. MOZ_COUNT_DTOR(VsyncBridgeParent);
  28. }
  29. void
  30. VsyncBridgeParent::Open(Endpoint<PVsyncBridgeParent>&& aEndpoint)
  31. {
  32. if (!aEndpoint.Bind(this)) {
  33. // We can't recover from this.
  34. MOZ_CRASH("Failed to bind VsyncBridgeParent to endpoint");
  35. }
  36. AddRef();
  37. mOpen = true;
  38. }
  39. bool
  40. VsyncBridgeParent::RecvNotifyVsync(const TimeStamp& aTimeStamp, const uint64_t& aLayersId)
  41. {
  42. CompositorBridgeParent::NotifyVsync(aTimeStamp, aLayersId);
  43. return true;
  44. }
  45. void
  46. VsyncBridgeParent::Shutdown()
  47. {
  48. MessageLoop* ccloop = CompositorThreadHolder::Loop();
  49. if (MessageLoop::current() != ccloop) {
  50. ccloop->PostTask(NewRunnableMethod(this, &VsyncBridgeParent::ShutdownImpl));
  51. return;
  52. }
  53. ShutdownImpl();
  54. }
  55. void
  56. VsyncBridgeParent::ShutdownImpl()
  57. {
  58. if (mOpen) {
  59. Close();
  60. mOpen = false;
  61. }
  62. }
  63. void
  64. VsyncBridgeParent::ActorDestroy(ActorDestroyReason aWhy)
  65. {
  66. mOpen = false;
  67. }
  68. void
  69. VsyncBridgeParent::DeallocPVsyncBridgeParent()
  70. {
  71. Release();
  72. }
  73. } // namespace gfx
  74. } // namespace mozilla