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 
6 #include "HeadlessCompositorWidget.h"
7 #include "HeadlessWidget.h"
8 #include "mozilla/widget/PlatformWidgetTypes.h"
9 
10 #include "InProcessGtkCompositorWidget.h"
11 #include "nsWindow.h"
12 
13 namespace mozilla {
14 namespace widget {
15 
CreateLocal(const CompositorWidgetInitData & aInitData,const layers::CompositorOptions & aOptions,nsIWidget * aWidget)16 /* static */ RefPtr<CompositorWidget> CompositorWidget::CreateLocal(
17     const CompositorWidgetInitData& aInitData,
18     const layers::CompositorOptions& aOptions, nsIWidget* aWidget) {
19   if (aInitData.type() ==
20       CompositorWidgetInitData::THeadlessCompositorWidgetInitData) {
21     return new HeadlessCompositorWidget(
22         aInitData.get_HeadlessCompositorWidgetInitData(), aOptions,
23         static_cast<HeadlessWidget*>(aWidget));
24   } else {
25     return new InProcessGtkCompositorWidget(
26         aInitData.get_GtkCompositorWidgetInitData(), aOptions,
27         static_cast<nsWindow*>(aWidget));
28   }
29 }
30 
InProcessGtkCompositorWidget(const GtkCompositorWidgetInitData & aInitData,const layers::CompositorOptions & aOptions,nsWindow * aWindow)31 InProcessGtkCompositorWidget::InProcessGtkCompositorWidget(
32     const GtkCompositorWidgetInitData& aInitData,
33     const layers::CompositorOptions& aOptions, nsWindow* aWindow)
34     : GtkCompositorWidget(aInitData, aOptions, aWindow) {}
35 
ObserveVsync(VsyncObserver * aObserver)36 void InProcessGtkCompositorWidget::ObserveVsync(VsyncObserver* aObserver) {
37   if (RefPtr<CompositorVsyncDispatcher> cvd =
38           mWidget->GetCompositorVsyncDispatcher()) {
39     cvd->SetCompositorVsyncObserver(aObserver);
40   }
41 }
42 
43 }  // namespace widget
44 }  // namespace mozilla
45