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 "GtkCompositorWidget.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
GtkCompositorWidget(const GtkCompositorWidgetInitData & aInitData,const layers::CompositorOptions & aOptions,nsWindow * aWindow)17 GtkCompositorWidget::GtkCompositorWidget(
18 const GtkCompositorWidgetInitData& aInitData,
19 const layers::CompositorOptions& aOptions, nsWindow* aWindow)
20 : CompositorWidget(aOptions), mWidget(aWindow) {
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
29 #ifdef MOZ_WAYLAND
30 if (!mXDisplay) {
31 MOZ_RELEASE_ASSERT(
32 aWindow, "We're running on Wayland and but without valid nsWindow.");
33 mProvider.Initialize(aWindow);
34 } else
35 #endif
36 {
37 mXWindow = (Window)aInitData.XWindow();
38
39 // Grab the window's visual and depth
40 XWindowAttributes windowAttrs;
41 XGetWindowAttributes(mXDisplay, mXWindow, &windowAttrs);
42
43 Visual* visual = windowAttrs.visual;
44 int depth = windowAttrs.depth;
45
46 // Initialize the window surface provider
47 mProvider.Initialize(mXDisplay, mXWindow, visual, depth);
48 }
49 mClientSize = aInitData.InitialClientSize();
50 }
51
~GtkCompositorWidget()52 GtkCompositorWidget::~GtkCompositorWidget() {
53 mProvider.CleanupResources();
54
55 // If we created our own display connection, we need to destroy it
56 if (!mWidget && mXDisplay) {
57 XCloseDisplay(mXDisplay);
58 mXDisplay = nullptr;
59 }
60 }
61
StartRemoteDrawing()62 already_AddRefed<gfx::DrawTarget> GtkCompositorWidget::StartRemoteDrawing() {
63 return nullptr;
64 }
EndRemoteDrawing()65 void GtkCompositorWidget::EndRemoteDrawing() {}
66
67 already_AddRefed<gfx::DrawTarget>
StartRemoteDrawingInRegion(LayoutDeviceIntRegion & aInvalidRegion,layers::BufferMode * aBufferMode)68 GtkCompositorWidget::StartRemoteDrawingInRegion(
69 LayoutDeviceIntRegion& aInvalidRegion, layers::BufferMode* aBufferMode) {
70 return mProvider.StartRemoteDrawingInRegion(aInvalidRegion, aBufferMode);
71 }
72
EndRemoteDrawingInRegion(gfx::DrawTarget * aDrawTarget,LayoutDeviceIntRegion & aInvalidRegion)73 void GtkCompositorWidget::EndRemoteDrawingInRegion(
74 gfx::DrawTarget* aDrawTarget, LayoutDeviceIntRegion& aInvalidRegion) {
75 mProvider.EndRemoteDrawingInRegion(aDrawTarget, aInvalidRegion);
76 }
77
RealWidget()78 nsIWidget* GtkCompositorWidget::RealWidget() { return mWidget; }
79
NotifyClientSizeChanged(const LayoutDeviceIntSize & aClientSize)80 void GtkCompositorWidget::NotifyClientSizeChanged(
81 const LayoutDeviceIntSize& aClientSize) {
82 mClientSize = aClientSize;
83 }
84
GetClientSize()85 LayoutDeviceIntSize GtkCompositorWidget::GetClientSize() { return mClientSize; }
86
GetWidgetKey()87 uintptr_t GtkCompositorWidget::GetWidgetKey() {
88 return reinterpret_cast<uintptr_t>(mWidget);
89 }
90
91 } // namespace widget
92 } // namespace mozilla
93