summaryrefslogtreecommitdiff
path: root/mozilla-1468911.patch
blob: d3177ac9c506726d082e88dbb839b741b5583e12 (plain)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
changeset:   465236:be9a6c98a4a7
tag:         tip
user:        Martin Stransky <stransky@redhat.com>
date:        Mon Mar 18 10:42:48 2019 +0100
summary:     tearing

diff --git a/widget/gtk/WindowSurfaceWayland.cpp b/widget/gtk/WindowSurfaceWayland.cpp
--- a/widget/gtk/WindowSurfaceWayland.cpp
+++ b/widget/gtk/WindowSurfaceWayland.cpp
@@ -15,16 +15,32 @@
 #include "nsTArray.h"
 #include "base/message_loop.h"  // for MessageLoop
 #include "base/task.h"          // for NewRunnableMethod, etc
 
 #include <sys/mman.h>
 #include <fcntl.h>
 #include <errno.h>
 
+#undef LOG
+#ifdef MOZ_LOGGING
+
+#  include "mozilla/Logging.h"
+#  include "nsTArray.h"
+#  include "Units.h"
+
+extern mozilla::LazyLogModule gWidgetWaylandLog;
+#  define LOGWAYLAND(args) MOZ_LOG(gWidgetWaylandLog, mozilla::LogLevel::Debug, args)
+
+#else
+
+#  define LOGWAYLAND(args)
+
+#endif /* MOZ_LOGGING */
+
 namespace mozilla {
 namespace widget {
 
 /*
   Wayland multi-thread rendering scheme
 
   Every rendering thread (main thread, compositor thread) contains its own
   nsWaylandDisplay object connected to Wayland compositor (Mutter, Weston, etc.)
@@ -283,23 +299,30 @@ WindowBackBuffer::WindowBackBuffer(nsWay
   Create(aWidth, aHeight);
 }
 
 WindowBackBuffer::~WindowBackBuffer() { Release(); }
 
 bool WindowBackBuffer::Resize(int aWidth, int aHeight) {
   if (aWidth == mWidth && aHeight == mHeight) return true;
 
+  LOGWAYLAND(("WindowBackBuffer::Resize [%p] %d %d\n",
+    (void*)this, aWidth, aHeight));
+
   Release();
   Create(aWidth, aHeight);
+  Clear();
 
   return (mWaylandBuffer != nullptr);
 }
 
 void WindowBackBuffer::Attach(wl_surface* aSurface) {
+  LOGWAYLAND(("WindowBackBuffer::Attach [%p] wl_surface %p\n",
+    (void*)this, (void *)aSurface));
+
   wl_surface_attach(aSurface, mWaylandBuffer, 0, 0);
   wl_surface_commit(aSurface);
   wl_display_flush(mWaylandDisplay->GetDisplay());
   mAttached = true;
 }
 
 void WindowBackBuffer::Detach() { mAttached = false; }
 
@@ -340,17 +363,18 @@ WindowSurfaceWayland::WindowSurfaceWayla
       mFrameCallback(nullptr),
       mLastCommittedSurface(nullptr),
       mDisplayThreadMessageLoop(MessageLoop::current()),
       mDelayedCommitHandle(nullptr),
       mDrawToWaylandBufferDirectly(true),
       mPendingCommit(false),
       mWaylandBufferFullScreenDamage(false),
       mIsMainThread(NS_IsMainThread()),
-      mNeedScaleFactorUpdate(true) {
+      mNeedScaleFactorUpdate(true),
+      mNeedFullScreenUpdate(true) {
   for (int i = 0; i < BACK_BUFFER_NUM; i++) mBackupBuffer[i] = nullptr;
 }
 
 WindowSurfaceWayland::~WindowSurfaceWayland() {
   if (mPendingCommit) {
     NS_WARNING("Deleted WindowSurfaceWayland with a pending commit!");
   }
 
@@ -392,16 +416,17 @@ WindowBackBuffer* WindowSurfaceWayland::
   }
 
   if (!mWaylandBuffer->IsAttached()) {
     if (!mWaylandBuffer->IsMatchingSize(aWidth, aHeight)) {
       mWaylandBuffer->Resize(aWidth, aHeight);
       // There's a chance that scale factor has been changed
       // when buffer size changed
       mNeedScaleFactorUpdate = true;
+      mNeedFullScreenUpdate = true;
     }
     return mWaylandBuffer;
   }
 
   MOZ_ASSERT(!mPendingCommit,
              "Uncommitted buffer switch, screen artifacts ahead.");
 
   // Front buffer is used by compositor, select a back buffer
@@ -490,39 +515,36 @@ already_AddRefed<gfx::DrawTarget> Window
 
   B) Lock() is requested for part(s) of screen. We need to provide temporary
      surface to draw into and copy result (clipped) to target wl_surface.
  */
 already_AddRefed<gfx::DrawTarget> WindowSurfaceWayland::Lock(
     const LayoutDeviceIntRegion& aRegion) {
   MOZ_ASSERT(mIsMainThread == NS_IsMainThread());
 
-  LayoutDeviceIntRect screenRect = mWindow->GetBounds();
-  gfx::IntRect bounds = aRegion.GetBounds().ToUnknownRect();
-  gfx::IntSize lockSize(bounds.XMost(), bounds.YMost());
+  LOGWAYLAND(("WindowSurfaceWayland::Lock [%p]\n", (void*)this));
 
   // Are we asked for entire nsWindow to draw?
-  mDrawToWaylandBufferDirectly =
-      (aRegion.GetNumRects() == 1 && bounds.x == 0 && bounds.y == 0 &&
-       lockSize.width == screenRect.width &&
-       lockSize.height == screenRect.height);
-
+  mDrawToWaylandBufferDirectly = IsFullScreenDraw(aRegion);
   if (mDrawToWaylandBufferDirectly) {
+    LayoutDeviceIntRect screenRect = mWindow->GetBounds();
     RefPtr<gfx::DrawTarget> dt =
         LockWaylandBuffer(screenRect.width, screenRect.height,
                           mWindow->WaylandSurfaceNeedsClear());
     if (dt) {
       return dt.forget();
     }
 
     // We don't have any front buffer available. Try indirect drawing
     // to mImageSurface which is mirrored to front buffer at commit.
     mDrawToWaylandBufferDirectly = false;
   }
 
+  gfx::IntRect bounds = aRegion.GetBounds().ToUnknownRect();
+  gfx::IntSize lockSize(bounds.XMost(), bounds.YMost());
   return LockImageSurface(lockSize);
 }
 
 bool WindowSurfaceWayland::CommitImageSurfaceToWaylandBuffer(
     const LayoutDeviceIntRegion& aRegion) {
   MOZ_ASSERT(!mDrawToWaylandBufferDirectly);
 
   LayoutDeviceIntRect screenRect = mWindow->GetBounds();
@@ -611,31 +633,42 @@ void WindowSurfaceWayland::CommitWayland
     // If our stored wl_surface does not match the actual one it means the frame
     // callback is no longer active and we should release it.
     wl_callback_destroy(mFrameCallback);
     mFrameCallback = nullptr;
     mLastCommittedSurface = nullptr;
   }
 
   if (mWaylandBufferFullScreenDamage) {
+    // We know we can safely redraw whole screen.
     LayoutDeviceIntRect rect = mWindow->GetBounds();
     wl_surface_damage(waylandSurface, 0, 0, rect.width, rect.height);
     mWaylandBufferFullScreenDamage = false;
   } else {
     gint scaleFactor = mWindow->GdkScaleFactor();
     for (auto iter = mWaylandBufferDamage.RectIter(); !iter.Done();
          iter.Next()) {
       const mozilla::LayoutDeviceIntRect& r = iter.Get();
       // We need to remove the scale factor because the wl_surface_damage
       // also multiplies by current  scale factor.
       wl_surface_damage(waylandSurface, r.x / scaleFactor, r.y / scaleFactor,
                         r.width / scaleFactor, r.height / scaleFactor);
     }
+
+    // We have to wait untill whole screen is drawn by Gecko, that happens
+    // when window is created or resized.
+    if (mNeedFullScreenUpdate) {
+      if (!IsFullScreenDraw(mWaylandBufferDamage)) {
+        return;
+      }
+    }
   }
 
+  mNeedFullScreenUpdate = false;
+
   // Clear all back buffer damage as we're committing
   // all requested regions.
   mWaylandBufferDamage.SetEmpty();
 
   mFrameCallback = wl_surface_frame(waylandSurface);
   wl_callback_add_listener(mFrameCallback, &frame_listener, this);
 
   if (mNeedScaleFactorUpdate || mLastCommittedSurface != waylandSurface) {
@@ -648,16 +681,18 @@ void WindowSurfaceWayland::CommitWayland
 
   // There's no pending commit, all changes are sent to compositor.
   mPendingCommit = false;
 }
 
 void WindowSurfaceWayland::Commit(const LayoutDeviceIntRegion& aInvalidRegion) {
   MOZ_ASSERT(mIsMainThread == NS_IsMainThread());
 
+  LOGWAYLAND(("WindowSurfaceWayland::Commit [%p]\n", (void*)this));
+
   // We have new content at mImageSurface - copy data to mWaylandBuffer first.
   if (!mDrawToWaylandBufferDirectly) {
     CommitImageSurfaceToWaylandBuffer(aInvalidRegion);
   }
 
   // If we're not at fullscreen damage add drawing area from aInvalidRegion
   if (!mWaylandBufferFullScreenDamage) {
     mWaylandBufferDamage.OrWith(aInvalidRegion);
@@ -690,10 +725,22 @@ void WindowSurfaceWayland::DelayedCommit
   free(mDelayedCommitHandle);
   mDelayedCommitHandle = nullptr;
 
   if (mPendingCommit) {
     CommitWaylandBuffer();
   }
 }
 
+bool WindowSurfaceWayland::IsFullScreenDraw(
+  const LayoutDeviceIntRegion& aRegion) {
+  LayoutDeviceIntRect screenRect = mWindow->GetBounds();
+  gfx::IntRect bounds = aRegion.GetBounds().ToUnknownRect();
+  gfx::IntSize lockSize(bounds.XMost(), bounds.YMost());
+
+  // Are we asked to update entire nsWindow?
+  return (bounds.x == 0 && bounds.y == 0 &&
+       lockSize.width == screenRect.width &&
+       lockSize.height == screenRect.height);
+}
+
 }  // namespace widget
 }  // namespace mozilla
diff --git a/widget/gtk/WindowSurfaceWayland.h b/widget/gtk/WindowSurfaceWayland.h
--- a/widget/gtk/WindowSurfaceWayland.h
+++ b/widget/gtk/WindowSurfaceWayland.h
@@ -94,16 +94,17 @@ class WindowSurfaceWayland : public Wind
 
  private:
   WindowBackBuffer* GetWaylandBufferToDraw(int aWidth, int aHeight);
 
   already_AddRefed<gfx::DrawTarget> LockWaylandBuffer(int aWidth, int aHeight,
                                                       bool aClearBuffer);
   already_AddRefed<gfx::DrawTarget> LockImageSurface(
       const gfx::IntSize& aLockSize);
+  bool IsFullScreenDraw(const LayoutDeviceIntRegion& aRegion);
   bool CommitImageSurfaceToWaylandBuffer(const LayoutDeviceIntRegion& aRegion);
   void CommitWaylandBuffer();
 
   // TODO: Do we need to hold a reference to nsWindow object?
   nsWindow* mWindow;
   nsWaylandDisplay* mWaylandDisplay;
   WindowBackBuffer* mWaylandBuffer;
   LayoutDeviceIntRegion mWaylandBufferDamage;
@@ -113,14 +114,15 @@ class WindowSurfaceWayland : public Wind
   wl_surface* mLastCommittedSurface;
   MessageLoop* mDisplayThreadMessageLoop;
   WindowSurfaceWayland** mDelayedCommitHandle;
   bool mDrawToWaylandBufferDirectly;
   bool mPendingCommit;
   bool mWaylandBufferFullScreenDamage;
   bool mIsMainThread;
   bool mNeedScaleFactorUpdate;
+  bool mNeedFullScreenUpdate;
 };
 
 }  // namespace widget
 }  // namespace mozilla
 
 #endif  // _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_WAYLAND_H
diff --git a/widget/gtk/nsAppShell.cpp b/widget/gtk/nsAppShell.cpp
--- a/widget/gtk/nsAppShell.cpp
+++ b/widget/gtk/nsAppShell.cpp
@@ -35,16 +35,17 @@ using mozilla::widget::ScreenHelperGTK;
 using mozilla::widget::ScreenManager;
 
 #define NOTIFY_TOKEN 0xFA
 
 LazyLogModule gWidgetLog("Widget");
 LazyLogModule gWidgetFocusLog("WidgetFocus");
 LazyLogModule gWidgetDragLog("WidgetDrag");
 LazyLogModule gWidgetDrawLog("WidgetDraw");
+LazyLogModule gWidgetWaylandLog("WidgetWayland");
 
 static GPollFunc sPollFunc;
 
 // Wrapper function to disable hang monitoring while waiting in poll().
 static gint PollWrapper(GPollFD* ufds, guint nfsd, gint timeout_) {
   mozilla::BackgroundHangMonitor().NotifyWait();
   gint result;
   {

bgstack15