1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GtkCompositorWidget.h"
#include "gfxPlatformGtk.h"
#include "mozilla/layers/CompositorThread.h"
#include "mozilla/widget/InProcessCompositorWidget.h"
#include "mozilla/widget/PlatformWidgetTypes.h"
#include "nsWindow.h"
namespace mozilla {
namespace widget {
GtkCompositorWidget::GtkCompositorWidget(
const GtkCompositorWidgetInitData& aInitData,
const layers::CompositorOptions& aOptions, nsWindow* aWindow)
: CompositorWidget(aOptions),
mWidget(aWindow),
mClientSize("GtkCompositorWidget::mClientSize") {
#if defined(MOZ_WAYLAND)
if (!aInitData.IsX11Display()) {
if (!aWindow) {
NS_WARNING("GtkCompositorWidget: We're missing nsWindow!");
}
mProvider.Initialize(aWindow);
}
#endif
#if defined(MOZ_X11)
if (aInitData.IsX11Display()) {
// If we have a nsWindow, then grab the already existing display connection
// If we don't, then use the init data to connect to the display
if (aWindow) {
mXDisplay = aWindow->XDisplay();
} else {
mXDisplay = XOpenDisplay(aInitData.XDisplayString().get());
}
mXWindow = (Window)aInitData.XWindow();
// Grab the window's visual and depth
XWindowAttributes windowAttrs;
if (!XGetWindowAttributes(mXDisplay, mXWindow, &windowAttrs)) {
NS_WARNING("GtkCompositorWidget(): XGetWindowAttributes() failed!");
}
Visual* visual = windowAttrs.visual;
mDepth = windowAttrs.depth;
// Initialize the window surface provider
mProvider.Initialize(mXDisplay, mXWindow, visual, mDepth,
aInitData.Shaped());
}
#endif
auto size = mClientSize.Lock();
*size = aInitData.InitialClientSize();
}
GtkCompositorWidget::~GtkCompositorWidget() {
mProvider.CleanupResources();
#if defined(MOZ_X11)
// If we created our own display connection, we need to destroy it
if (!mWidget && mXDisplay) {
XCloseDisplay(mXDisplay);
mXDisplay = nullptr;
}
#endif
}
already_AddRefed<gfx::DrawTarget> GtkCompositorWidget::StartRemoteDrawing() {
return nullptr;
}
void GtkCompositorWidget::EndRemoteDrawing() {}
already_AddRefed<gfx::DrawTarget>
GtkCompositorWidget::StartRemoteDrawingInRegion(
LayoutDeviceIntRegion& aInvalidRegion, layers::BufferMode* aBufferMode) {
return mProvider.StartRemoteDrawingInRegion(aInvalidRegion, aBufferMode);
}
void GtkCompositorWidget::EndRemoteDrawingInRegion(
gfx::DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
mProvider.EndRemoteDrawingInRegion(aDrawTarget, aInvalidRegion);
}
nsIWidget* GtkCompositorWidget::RealWidget() { return mWidget; }
void GtkCompositorWidget::NotifyClientSizeChanged(
const LayoutDeviceIntSize& aClientSize) {
auto size = mClientSize.Lock();
*size = aClientSize;
}
LayoutDeviceIntSize GtkCompositorWidget::GetClientSize() {
auto size = mClientSize.Lock();
return *size;
}
uintptr_t GtkCompositorWidget::GetWidgetKey() {
return reinterpret_cast<uintptr_t>(mWidget);
}
EGLNativeWindowType GtkCompositorWidget::GetEGLNativeWindow() {
if (mWidget) {
return (EGLNativeWindowType)mWidget->GetNativeData(NS_NATIVE_EGL_WINDOW);
}
#if defined(MOZ_X11)
if (mXWindow) {
return (EGLNativeWindowType)mXWindow;
}
#endif
return nullptr;
}
int32_t GtkCompositorWidget::GetDepth() { return mDepth; }
#if defined(MOZ_WAYLAND)
void GtkCompositorWidget::SetEGLNativeWindowSize(
const LayoutDeviceIntSize& aEGLWindowSize) {
if (mWidget) {
mWidget->SetEGLNativeWindowSize(aEGLWindowSize);
}
}
#endif
void GtkCompositorWidget::ClearBeforePaint(
RefPtr<gfx::DrawTarget> aTarget, const LayoutDeviceIntRegion& aRegion) {
// We need to clear target buffer alpha values of popup windows as
// SW-WR paints with alpha blending (see Bug 1674473).
if (mWidget->IsPopup()) {
for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) {
aTarget->ClearRect(gfx::Rect(iter.Get().ToUnknownRect()));
}
}
// Clear background of titlebar area to render titlebar
// transparent corners correctly.
gfx::Rect rect;
if (mWidget->GetTitlebarRect(rect)) {
aTarget->ClearRect(rect);
}
}
} // namespace widget
} // namespace mozilla
|