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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
|
diff --git a/widget/gtk/WindowSurfaceWayland.h b/widget/gtk/WindowSurfaceWayland.h
--- a/widget/gtk/WindowSurfaceWayland.h
+++ b/widget/gtk/WindowSurfaceWayland.h
@@ -177,12 +177,9 @@
private:
WindowBackBuffer* CreateWaylandBuffer(int aWidth, int aHeight);
- WindowBackBuffer* GetWaylandBufferToDraw(int aWidth, int aHeight,
- bool aFullScreenUpdate);
+ WindowBackBuffer* GetWaylandBufferToDraw(bool aCanSwitchBuffer);
- already_AddRefed<gfx::DrawTarget> LockWaylandBuffer(int aWidth, int aHeight,
- bool aClearBuffer,
- bool aFullScreenUpdate);
+ already_AddRefed<gfx::DrawTarget> LockWaylandBuffer(bool aCanSwitchBuffer);
void UnlockWaylandBuffer();
already_AddRefed<gfx::DrawTarget> LockImageSurface(
@@ -198,7 +195,10 @@
// TODO: Do we need to hold a reference to nsWindow object?
nsWindow* mWindow;
- LayoutDeviceIntRect mLastScreenRect;
+ // Buffer screen rects helps us understand if we operate on
+ // the same window size as we're called on WindowSurfaceWayland::Lock().
+ // mBufferScreenRect is window size when our wayland buffer was allocated.
+ LayoutDeviceIntRect mBufferScreenRect;
nsWaylandDisplay* mWaylandDisplay;
WindowBackBuffer* mWaylandBuffer;
LayoutDeviceIntRegion mWaylandBufferDamage;
@@ -211,7 +211,8 @@
AutoTArray<WindowImageSurface, 30> mDelayedImageCommits;
bool mDrawToWaylandBufferDirectly;
bool mPendingCommit;
- bool mWaylandBufferFullScreenDamage;
+ bool mWholeWindowBufferDamage;
+ bool mBufferNeedsClear;
bool mIsMainThread;
bool mNeedScaleFactorUpdate;
diff --git a/widget/gtk/WindowSurfaceWayland.cpp b/widget/gtk/WindowSurfaceWayland.cpp
--- a/widget/gtk/WindowSurfaceWayland.cpp
+++ b/widget/gtk/WindowSurfaceWayland.cpp
@@ -499,7 +499,8 @@
mDelayedCommitHandle(nullptr),
mDrawToWaylandBufferDirectly(true),
mPendingCommit(false),
- mWaylandBufferFullScreenDamage(false),
+ mWholeWindowBufferDamage(false),
+ mBufferNeedsClear(false),
mIsMainThread(NS_IsMainThread()),
mNeedScaleFactorUpdate(true) {
for (int i = 0; i < BACK_BUFFER_NUM; i++) mBackupBuffer[i] = nullptr;
@@ -565,18 +566,20 @@
}
WindowBackBuffer* WindowSurfaceWayland::GetWaylandBufferToDraw(
- int aWidth, int aHeight, bool aFullScreenUpdate) {
+ bool aCanSwitchBuffer) {
LOGWAYLAND(("%s [%p] Requested buffer [%d x %d]\n", __PRETTY_FUNCTION__,
- (void*)this, aWidth, aHeight));
+ (void*)this, mBufferScreenRect.width, mBufferScreenRect.height));
// There's no buffer created yet, create a new one.
if (!mWaylandBuffer) {
- MOZ_ASSERT(aFullScreenUpdate, "Created new buffer for partial drawing!");
+ MOZ_ASSERT(aCanSwitchBuffer && mWholeWindowBufferDamage,
+ "Created new buffer for partial drawing!");
LOGWAYLAND(("%s [%p] Created new buffer [%d x %d]\n", __PRETTY_FUNCTION__,
- (void*)this, aWidth, aHeight));
+ (void*)this, mBufferScreenRect.width,
+ mBufferScreenRect.height));
- mWaylandBuffer = CreateWaylandBuffer(aWidth, aHeight);
- mWaylandBufferFullScreenDamage = true;
+ mWaylandBuffer =
+ CreateWaylandBuffer(mBufferScreenRect.width, mBufferScreenRect.height);
mNeedScaleFactorUpdate = true;
return mWaylandBuffer;
}
@@ -593,29 +596,31 @@
LOGWAYLAND(
("%s [%p] Use recent buffer.\n", __PRETTY_FUNCTION__, (void*)this));
- if (mWaylandBuffer->IsMatchingSize(aWidth, aHeight)) {
+ if (mWaylandBuffer->IsMatchingSize(mBufferScreenRect.width,
+ mBufferScreenRect.height)) {
LOGWAYLAND(("%s [%p] Size is ok, use the buffer [%d x %d]\n",
- __PRETTY_FUNCTION__, (void*)this, aWidth, aHeight));
+ __PRETTY_FUNCTION__, (void*)this, mBufferScreenRect.width,
+ mBufferScreenRect.height));
return mWaylandBuffer;
}
- if (!aFullScreenUpdate) {
+ if (!aCanSwitchBuffer) {
NS_WARNING("We can't resize Wayland buffer for non-fullscreen updates!");
return nullptr;
}
LOGWAYLAND(("%s [%p] Reuse buffer with resize [%d x %d]\n",
- __PRETTY_FUNCTION__, (void*)this, aWidth, aHeight));
+ __PRETTY_FUNCTION__, (void*)this, mBufferScreenRect.width,
+ mBufferScreenRect.height));
- mWaylandBuffer->Resize(aWidth, aHeight);
+ mWaylandBuffer->Resize(mBufferScreenRect.width, mBufferScreenRect.height);
// There's a chance that scale factor has been changed
// when buffer size changed
- mWaylandBufferFullScreenDamage = true;
mNeedScaleFactorUpdate = true;
return mWaylandBuffer;
}
- if (!aFullScreenUpdate) {
+ if (!aCanSwitchBuffer) {
return nullptr;
}
@@ -625,8 +630,10 @@
availableBuffer++) {
if (!mBackupBuffer[availableBuffer]) {
LOGWAYLAND(("%s [%p] Created new buffer [%d x %d]\n", __PRETTY_FUNCTION__,
- (void*)this, aWidth, aHeight));
- mBackupBuffer[availableBuffer] = CreateWaylandBuffer(aWidth, aHeight);
+ (void*)this, mBufferScreenRect.width,
+ mBufferScreenRect.height));
+ mBackupBuffer[availableBuffer] = CreateWaylandBuffer(
+ mBufferScreenRect.width, mBufferScreenRect.height);
break;
}
@@ -650,23 +657,23 @@
__PRETTY_FUNCTION__, (void*)this, (void*)lastWaylandBuffer,
(void*)mWaylandBuffer));
- mWaylandBufferFullScreenDamage = true;
mNeedScaleFactorUpdate = true;
- bool bufferNeedsResize = !mWaylandBuffer->IsMatchingSize(aWidth, aHeight);
+ bool bufferNeedsResize = !mWaylandBuffer->IsMatchingSize(
+ mBufferScreenRect.width, mBufferScreenRect.height);
if (bufferNeedsResize) {
LOGWAYLAND(("%s [%p] Resize buffer to [%d x %d]\n", __PRETTY_FUNCTION__,
- (void*)this, aWidth, aHeight));
- mWaylandBuffer->Resize(aWidth, aHeight);
+ (void*)this, mBufferScreenRect.width,
+ mBufferScreenRect.height));
+ mWaylandBuffer->Resize(mBufferScreenRect.width, mBufferScreenRect.height);
}
return mWaylandBuffer;
}
already_AddRefed<gfx::DrawTarget> WindowSurfaceWayland::LockWaylandBuffer(
- int aWidth, int aHeight, bool aClearBuffer, bool aFullScreenUpdate) {
- WindowBackBuffer* buffer =
- GetWaylandBufferToDraw(aWidth, aHeight, aFullScreenUpdate);
+ bool aCanSwitchBuffer) {
+ WindowBackBuffer* buffer = GetWaylandBufferToDraw(aCanSwitchBuffer);
LOGWAYLAND(("%s [%p] Got buffer %p\n", __PRETTY_FUNCTION__, (void*)this,
(void*)buffer));
@@ -675,8 +682,9 @@
return nullptr;
}
- if (aClearBuffer) {
+ if (mBufferNeedsClear && mWholeWindowBufferDamage) {
buffer->Clear();
+ mBufferNeedsClear = false;
}
return buffer->Lock();
@@ -744,7 +752,7 @@
const LayoutDeviceIntRegion& aRegion) {
MOZ_ASSERT(mIsMainThread == NS_IsMainThread());
- LayoutDeviceIntRect screenRect = mWindow->GetBounds();
+ LayoutDeviceIntRect lockedScreenRect = mWindow->GetBounds();
gfx::IntRect bounds = aRegion.GetBounds().ToUnknownRect();
gfx::IntSize lockSize(bounds.XMost(), bounds.YMost());
@@ -753,54 +761,77 @@
mWindow->IsWaylandPopup() &&
(eTransparencyTransparent == mWindow->GetTransparencyMode());
- mDrawToWaylandBufferDirectly =
- isTransparentPopup ? IsPopupFullScreenUpdate(screenRect, aRegion)
- : IsWindowFullScreenUpdate(screenRect, aRegion);
+ // We have request to lock whole buffer/window.
+ mWholeWindowBufferDamage =
+ isTransparentPopup ? IsPopupFullScreenUpdate(lockedScreenRect, aRegion)
+ : IsWindowFullScreenUpdate(lockedScreenRect, aRegion);
- bool needsClear = mWindow->WaylandSurfaceNeedsClear() ||
- (isTransparentPopup && mDrawToWaylandBufferDirectly);
+ // Clear buffer when we (re)draw new transparent popup window,
+ // otherwise leave it as-is, mBufferNeedsClear can be set from previous
+ // (already pending) commits which are cached now.
+ if (mWholeWindowBufferDamage) {
+ mBufferNeedsClear =
+ mWindow->WaylandSurfaceNeedsClear() || isTransparentPopup;
+ }
LOGWAYLAND(("%s [%p] lockSize [%d x %d] windowSize [%d x %d]\n",
__PRETTY_FUNCTION__, (void*)this, lockSize.width, lockSize.height,
- screenRect.width, screenRect.height));
+ lockedScreenRect.width, lockedScreenRect.height));
LOGWAYLAND((" nsWindow = %p\n", mWindow));
LOGWAYLAND((" isPopup = %d\n", mWindow->IsWaylandPopup()));
LOGWAYLAND((" isTransparentPopup = %d\n", isTransparentPopup));
LOGWAYLAND((" IsPopupFullScreenUpdate = %d\n",
- IsPopupFullScreenUpdate(screenRect, aRegion)));
+ IsPopupFullScreenUpdate(lockedScreenRect, aRegion)));
LOGWAYLAND((" IsWindowFullScreenUpdate = %d\n",
- IsWindowFullScreenUpdate(screenRect, aRegion)));
- LOGWAYLAND((" needsClear = %d\n", needsClear));
- LOGWAYLAND(
- (" mDrawToWaylandBufferDirectly = %d\n", mDrawToWaylandBufferDirectly));
+ IsWindowFullScreenUpdate(lockedScreenRect, aRegion)));
+ LOGWAYLAND((" mBufferNeedsClear = %d\n", mBufferNeedsClear));
+ LOGWAYLAND((" mWholeWindowBufferDamage = %d\n", mWholeWindowBufferDamage));
+
+#if DEBUG
+ if (!(mBufferScreenRect == lockedScreenRect)) {
+ LOGWAYLAND((" screen size changed\n"));
+ }
+#endif
- // Allow full screen allocation and clear
- // when window size changed.
- bool bufferRedraw = !(screenRect == mLastScreenRect);
- if (bufferRedraw) {
- mDrawToWaylandBufferDirectly = true;
- needsClear = true;
+ if (!(mBufferScreenRect == lockedScreenRect)) {
+ // Screen (window) size changed and we still have some painting pending
+ // for the last window size. That can happen when window is resized.
+ // We can't commit them any more as they're for former window size, so
+ // scratch them.
+ mDelayedImageCommits.Clear();
+
+ if (!mWholeWindowBufferDamage) {
+ NS_WARNING("Partial screen update when window is resized!");
+ // This should not happen. Screen size changed but we got only
+ // partal screen update instead of whole screen. Discard this painting
+ // as it produces artifacts.
+ return nullptr;
+ }
+ mBufferScreenRect = lockedScreenRect;
}
- if (mDrawToWaylandBufferDirectly) {
+ if (mWholeWindowBufferDamage) {
+ // We can lock/commit entire buffer direcly.
+ mDrawToWaylandBufferDirectly = true;
+
// If there's any pending image commit scratch them as we're going
// to redraw the whole sceen anyway.
mDelayedImageCommits.Clear();
- RefPtr<gfx::DrawTarget> dt =
- LockWaylandBuffer(screenRect.width, screenRect.height, needsClear,
- /* aFullScreenUpdate */ true);
+ RefPtr<gfx::DrawTarget> dt = LockWaylandBuffer(
+ /* aCanSwitchBuffer */ mWholeWindowBufferDamage);
if (dt) {
- if (bufferRedraw) {
- mLastScreenRect = screenRect;
- }
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;
- }
+ // We do indirect drawing due to:
+ //
+ // 1) We don't have any front buffer available. Try indirect drawing
+ // to mImageSurface which is mirrored to front buffer at commit.
+ // 2) Only part of the screen is locked. We can't lock entire screen for
+ // such drawing as it produces visible artifacts.
+ mDrawToWaylandBufferDirectly = false;
LOGWAYLAND((" Indirect drawing.\n"));
return LockImageSurface(lockSize);
@@ -851,16 +882,14 @@
LayoutDeviceIntRegion& aWaylandBufferDamage) {
MOZ_ASSERT(!mDrawToWaylandBufferDirectly);
- LayoutDeviceIntRect screenRect = mWindow->GetBounds();
+#ifdef DEBUG
gfx::IntRect bounds = aRegion.GetBounds().ToUnknownRect();
-
gfx::Rect rect(bounds);
- if (rect.IsEmpty()) {
- return false;
- }
+ MOZ_ASSERT(!rect.IsEmpty(), "Empty drawing?");
+#endif
LOGWAYLAND(("%s [%p] screenSize [%d x %d]\n", __PRETTY_FUNCTION__,
- (void*)this, screenRect.width, screenRect.height));
+ (void*)this, mBufferScreenRect.width, mBufferScreenRect.height));
RefPtr<gfx::SourceSurface> surf =
gfx::Factory::CreateSourceSurfaceForCairoSurface(
@@ -871,13 +900,8 @@
return false;
}
- // Allow full screen allocation and clear
- // when window size changed.
- bool bufferRedraw = !(screenRect == mLastScreenRect);
- RefPtr<gfx::DrawTarget> dt =
- LockWaylandBuffer(screenRect.width, screenRect.height,
- /* needs clear*/ bufferRedraw,
- /* aFullScreenUpdate */ bufferRedraw);
+ RefPtr<gfx::DrawTarget> dt = LockWaylandBuffer(
+ /* aCanSwitchBuffer */ mWholeWindowBufferDamage);
if (dt) {
LOGWAYLAND(
(" Flushing %ld cached WindowImageSurfaces to Wayland buffer\n",
@@ -885,14 +909,11 @@
// Draw any delayed image commits first
DrawDelayedImageCommits(dt, aWaylandBufferDamage);
+ // Draw image from recent WindowSurfaceWayland::Lock().
WindowImageSurface::Draw(surf, dt, aRegion);
// Submit all drawing to final Wayland buffer upload
aWaylandBufferDamage.OrWith(aRegion);
UnlockWaylandBuffer();
-
- if (bufferRedraw) {
- mLastScreenRect = screenRect;
- }
} else {
mDelayedImageCommits.AppendElement(WindowImageSurface(surf, aRegion));
LOGWAYLAND((" Added WindowImageSurfaces, cached surfaces %ld\n",
@@ -930,29 +951,25 @@
LOGWAYLAND(("%s [%p]\n", __PRETTY_FUNCTION__, (void*)this));
LOGWAYLAND(
(" mDrawToWaylandBufferDirectly = %d\n", mDrawToWaylandBufferDirectly));
- LOGWAYLAND((" mWaylandBufferFullScreenDamage = %d\n",
- mWaylandBufferFullScreenDamage));
+ LOGWAYLAND((" mWholeWindowBufferDamage = %d\n", mWholeWindowBufferDamage));
LOGWAYLAND((" mDelayedCommitHandle = %p\n", mDelayedCommitHandle));
LOGWAYLAND((" mFrameCallback = %p\n", mFrameCallback));
LOGWAYLAND((" mLastCommittedSurface = %p\n", mLastCommittedSurface));
if (!mDrawToWaylandBufferDirectly) {
+ MOZ_ASSERT(mDelayedImageCommits.Length(),
+ "Indirect drawing without any image?");
+
// There's some cached drawings - try to flush them now.
- LayoutDeviceIntRect screenRect = mWindow->GetBounds();
- bool bufferRedraw = !(screenRect == mLastScreenRect);
- RefPtr<gfx::DrawTarget> dt =
- LockWaylandBuffer(screenRect.width, screenRect.height,
- /* needsClear */ bufferRedraw,
- /* full screen update */ bufferRedraw);
+ RefPtr<gfx::DrawTarget> dt = LockWaylandBuffer(
+ /* aCanSwitchBuffer */ mWholeWindowBufferDamage);
+
if (dt) {
LOGWAYLAND(("%s [%p] flushed indirect drawing\n", __PRETTY_FUNCTION__,
(void*)this));
DrawDelayedImageCommits(dt, mWaylandBufferDamage);
UnlockWaylandBuffer();
mDrawToWaylandBufferDirectly = true;
- if (bufferRedraw) {
- mLastScreenRect = screenRect;
- }
}
}
@@ -1000,10 +1017,10 @@
mLastCommittedSurface = nullptr;
}
- if (mWaylandBufferFullScreenDamage) {
- LayoutDeviceIntRect rect = mWindow->GetBounds();
- wl_surface_damage(waylandSurface, 0, 0, rect.width, rect.height);
- mWaylandBufferFullScreenDamage = false;
+ if (mWholeWindowBufferDamage) {
+ wl_surface_damage(waylandSurface, 0, 0, mBufferScreenRect.width,
+ mBufferScreenRect.height);
+ mWholeWindowBufferDamage = false;
mNeedScaleFactorUpdate = true;
} else {
gint scaleFactor = mWindow->GdkScaleFactor();
@@ -1043,24 +1060,24 @@
#ifdef DEBUG
{
- LayoutDeviceIntRect screenRect = mWindow->GetBounds();
gfx::IntRect bounds = aInvalidRegion.GetBounds().ToUnknownRect();
gfx::IntSize lockSize(bounds.XMost(), bounds.YMost());
LOGWAYLAND(("%s [%p] lockSize [%d x %d] screenSize [%d x %d]\n",
__PRETTY_FUNCTION__, (void*)this, lockSize.width,
- lockSize.height, screenRect.width, screenRect.height));
+ lockSize.height, mBufferScreenRect.width,
+ mBufferScreenRect.height));
LOGWAYLAND((" mDrawToWaylandBufferDirectly = %d\n",
mDrawToWaylandBufferDirectly));
- LOGWAYLAND((" mWaylandBufferFullScreenDamage = %d\n",
- mWaylandBufferFullScreenDamage));
+ LOGWAYLAND(
+ (" mWholeWindowBufferDamage = %d\n", mWholeWindowBufferDamage));
}
#endif
if (mDrawToWaylandBufferDirectly) {
MOZ_ASSERT(mWaylandBuffer->IsLocked());
// If we're not at fullscreen damage add drawing area from aInvalidRegion
- if (!mWaylandBufferFullScreenDamage) {
+ if (!mWholeWindowBufferDamage) {
mWaylandBufferDamage.OrWith(aInvalidRegion);
}
UnlockWaylandBuffer();
|