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 "X11CompositorWidget.h"
7 
8 #include "gfxPlatformGtk.h"
9 #include "mozilla/layers/CompositorThread.h"
10 #include "mozilla/widget/InProcessCompositorWidget.h"
11 #include "mozilla/widget/PlatformWidgetTypes.h"
12 #include "nsWindow.h"
13 
14 namespace mozilla {
15 namespace widget {
16 
X11CompositorWidget(const CompositorWidgetInitData & aInitData,nsWindow * aWindow)17 X11CompositorWidget::X11CompositorWidget(const CompositorWidgetInitData& aInitData,
18                                          nsWindow* aWindow)
19       : mWidget(aWindow)
20 {
21   // If we have a nsWindow, then grab the already existing display connection
22   // If we don't, then use the init data to connect to the display
23   if (aWindow) {
24     mXDisplay = aWindow->XDisplay();
25   } else {
26     mXDisplay = XOpenDisplay(aInitData.XDisplayString().get());
27   }
28   mXWindow = (Window)aInitData.XWindow();
29 
30   // Grab the window's visual and depth
31   XWindowAttributes windowAttrs;
32   XGetWindowAttributes(mXDisplay, mXWindow, &windowAttrs);
33 
34   Visual*   visual = windowAttrs.visual;
35   int       depth = windowAttrs.depth;
36 
37   // Initialize the window surface provider
38   mProvider.Initialize(
39     mXDisplay,
40     mXWindow,
41     visual,
42     depth
43     );
44 
45   mClientSize = aInitData.InitialClientSize();
46 }
47 
~X11CompositorWidget()48 X11CompositorWidget::~X11CompositorWidget()
49 {
50   mProvider.CleanupResources();
51 
52   // If we created our own display connection, we need to destroy it
53   if (!mWidget && mXDisplay) {
54     XCloseDisplay(mXDisplay);
55     mXDisplay = nullptr;
56   }
57 }
58 
59 already_AddRefed<gfx::DrawTarget>
StartRemoteDrawing()60 X11CompositorWidget::StartRemoteDrawing()
61 {
62   return nullptr;
63 }
64 void
EndRemoteDrawing()65 X11CompositorWidget::EndRemoteDrawing()
66 {
67 }
68 
69 already_AddRefed<gfx::DrawTarget>
StartRemoteDrawingInRegion(LayoutDeviceIntRegion & aInvalidRegion,layers::BufferMode * aBufferMode)70 X11CompositorWidget::StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion,
71                                                 layers::BufferMode* aBufferMode)
72 {
73   return mProvider.StartRemoteDrawingInRegion(aInvalidRegion,
74                                               aBufferMode);
75 }
76 
EndRemoteDrawingInRegion(gfx::DrawTarget * aDrawTarget,LayoutDeviceIntRegion & aInvalidRegion)77 void X11CompositorWidget::EndRemoteDrawingInRegion(gfx::DrawTarget* aDrawTarget,
78                               LayoutDeviceIntRegion& aInvalidRegion)
79 {
80   mProvider.EndRemoteDrawingInRegion(aDrawTarget,
81                                      aInvalidRegion);
82 }
83 
RealWidget()84 nsIWidget* X11CompositorWidget::RealWidget()
85 {
86   return mWidget;
87 }
88 
89 void
NotifyClientSizeChanged(const LayoutDeviceIntSize & aClientSize)90 X11CompositorWidget::NotifyClientSizeChanged(const LayoutDeviceIntSize& aClientSize)
91 {
92   mClientSize = aClientSize;
93 }
94 
95 LayoutDeviceIntSize
GetClientSize()96 X11CompositorWidget::GetClientSize()
97 {
98   return mClientSize;
99 }
100 
101 uintptr_t
GetWidgetKey()102 X11CompositorWidget::GetWidgetKey()
103 {
104   return reinterpret_cast<uintptr_t>(mWidget);
105 }
106 
107 } // namespace widget
108 } // namespace mozilla
109